Skip to content

Commit

Permalink
Add basic clean-theme support and update card, frame patterns
Browse files Browse the repository at this point in the history
Add a theming mixin to allow other mixins to define rules that should
apply for a given theme.

Add some affordances to the `card` and `frame` molecule patterns for
the `clean` theme and update pattern-library examples.
  • Loading branch information
lyzadanger committed Jun 3, 2021
1 parent 27f98fa commit cd24a16
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/pattern-library/components/patterns/MoleculePatterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ export default function MoleculePatterns() {
<div className="hyp-u-border">Child content in a frame.</div>
</div>
</PatternExample>
<PatternExample details="content in a frame: clean theme">
<div className="theme-clean">
<div className="hyp-frame">
Content within a frame in the clean theme. The frame itself has
no borders when in the clean theme.
</div>
</div>
</PatternExample>
</PatternExamples>
</Pattern>

Expand Down Expand Up @@ -56,6 +64,21 @@ export default function MoleculePatterns() {
</div>
</div>
</PatternExample>
<PatternExample details="Clean theme">
<div className="theme-clean">
<div className="hyp-card">
<div>
This is some text in a card in the clean theme. There are no
borders or box-shadows.
</div>
<div className="hyp-actions">
<IconButton title="User" icon="profile" />
<IconButton title="Edit" icon="edit" />
<IconButton title="Delete" icon="trash" />
</div>
</div>
</div>
</PatternExample>
</PatternExamples>
</Pattern>

Expand Down
11 changes: 11 additions & 0 deletions src/pattern-library/components/patterns/PanelPatterns.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ export default function SharedPanelPatterns() {
This panel has an optional icon in the header.
</Panel>
</PatternExample>
<PatternExample details="A panel in the clean theme">
<div className="theme-clean" style="width:100%">
<Panel
icon="edit"
title="Panel with clean-theme styling"
onClose={() => alert('close clicked')}
>
This panel has an optional icon in the header.
</Panel>
</div>
</PatternExample>
</PatternExamples>
</Pattern>
</PatternPage>
Expand Down
41 changes: 41 additions & 0 deletions styles/mixins/_themes.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/**
* This mixin allows other mixins to declare rules that should only apply
* when a particular theme is active. The only known theme at present is
* the "clean" theme.
*
* The client application provides relatively minimalistic support for a
* "clean" theme by applying a `theme-clean` class to the application container
* element.
*
* For example, let's say that the clean-theme variant of a pattern called
* `banana` should not have any borders applied. Its mixin can be written:
*
* @mixin banana {
* border: 1px solid pink;
* @include theme('clean') {
* border: none;
* }
* }
*
* .hyp-banana {
* @include banana;
* }
*
* This would result in CSS:
*
* .hyp-banana {
* border: 1px solid pink;
* }
*
* .theme-clean .hyp-banana {
* border: none;
* }
*
* Note: As implemented here, theming increases specificity. Rules defined in
* theming cannot be overridden with utility classes as currently structured.
*/
@mixin theme($theme-name) {
.theme-#{$theme-name} & {
@content;
}
}
14 changes: 12 additions & 2 deletions styles/mixins/patterns/_molecules.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

@use '../atoms';
@use '../layout';
@use '../themes';

$-border-radius: var.$border-radius;
$-color-background: var.$color-background;
Expand All @@ -15,13 +16,18 @@ $-space: var.$layout-space;
/**
* Give an element a border, background color and internal vertical spacing
*/
@mixin frame($with-hover: false) {
@mixin frame {
@include atoms.border;
@include layout.vertical-rhythm;

padding: $-space;
border-radius: $-border-radius;
background-color: $-color-background;

@include themes.theme('clean') {
// A frame should not have any borders in the clean theme.
border: none;
}
}

/**
Expand All @@ -39,9 +45,13 @@ $-space: var.$layout-space;
@include atoms.shadow($active: true);
}
}

width: 100%;

// TODO: Add clean-theme affordances
@include themes.theme('clean') {
// A card should have no shadows at all in the clean theme.
box-shadow: none;
}
}

/**
Expand Down

0 comments on commit cd24a16

Please sign in to comment.