-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(styles): add palettes #3850
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
597b15b
feat(tokens): export raw palettes
alizedebray 14f0242
feat(docs): add cargo theme
alizedebray 0a7ce54
Merge branch 'export-palette-tokens' into add-cargo-theme
alizedebray c48ee1e
feat(styles): add palette styles
alizedebray 31fead7
feat(docs): add palette stories
alizedebray 60cd2ed
chore: add palette tests
alizedebray 1f925c8
Apply requested changes
alizedebray bc04828
Simplify palette entry files
alizedebray e382e2e
Merge branch 'main' into 3432-helpers-palettes
alizedebray 2479b4b
Update _mixins.scss
alizedebray 698620b
Add back palette utilities
alizedebray File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@swisspost/design-system-documentation': minor | ||
'@swisspost/design-system-styles': minor | ||
--- | ||
|
||
Added color palettes to easily apply colors to a page section using predefined color sets. |
13 changes: 13 additions & 0 deletions
13
packages/documentation/cypress/e2e/components/palette.cy.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
describe('Palette', () => { | ||
describe('Accessibility', () => { | ||
beforeEach(() => { | ||
cy.visit('/iframe.html?id=snapshots--palette'); | ||
cy.get('.palette-default', { timeout: 30000 }).should('be.visible'); | ||
cy.injectAxe(); | ||
}); | ||
|
||
it('Has no detectable a11y violations on load for all variants', () => { | ||
cy.checkA11y('#root-inner'); | ||
}); | ||
}); | ||
}); |
7 changes: 7 additions & 0 deletions
7
packages/documentation/cypress/snapshots/components/palette.snapshot.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
describe('Palette', () => { | ||
it('default', () => { | ||
cy.visit('/iframe.html?id=snapshots--palette'); | ||
cy.get('.palette-default', { timeout: 30000 }).should('be.visible'); | ||
cy.percySnapshot('Palettes', { widths: [1440] }); | ||
}); | ||
}); |
27 changes: 27 additions & 0 deletions
27
packages/documentation/src/stories/foundation/palette/palette.docs.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Canvas, Controls, Meta } from '@storybook/blocks'; | ||
import * as paletteStories from './palette.stories'; | ||
|
||
<Meta of={paletteStories} /> | ||
|
||
<div className="docs-title"> | ||
# Palettes | ||
</div> | ||
|
||
<div className="lead"> | ||
Easily apply colors to a section of your page using predefined color sets. | ||
</div> | ||
|
||
There are four different palettes: | ||
- **Default** - The standard palette used when no other palette is specified. | ||
- **Alternate** - Used to differentiate alternating sections from the body, without strong emphasis or highlighting. | ||
- **Accent** - A complementary color used for highlights and emphasis. | ||
- **Brand** - The primary color for the brand. | ||
|
||
Palettes may also include a specific text color that is different from the body color. | ||
You can apply this text color to any element by using the `.palette-text` class. | ||
|
||
<Canvas sourceState="shown" of={paletteStories.Default} /> | ||
|
||
<div className="hide-col-default"> | ||
<Controls of={paletteStories.Default} /> | ||
</div> |
35 changes: 35 additions & 0 deletions
35
packages/documentation/src/stories/foundation/palette/palette.snapshot.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { StoryObj } from '@storybook/web-components'; | ||
import { html } from 'lit'; | ||
import meta from './palette.stories'; | ||
|
||
const { id, ...metaWithoutId } = meta; | ||
|
||
export default { | ||
...metaWithoutId, | ||
title: 'Snapshots', | ||
}; | ||
|
||
type Story = StoryObj; | ||
|
||
export const Palette: Story = { | ||
render: () => { | ||
return html`${['light', 'dark'].map( | ||
mainScheme => html` | ||
<div class="palette-default p-24 d-flex flex-column gap-48" data-color-scheme=${mainScheme}> | ||
${['', 'light', 'dark'].map( | ||
paletteScheme => html` | ||
<div> | ||
<p class="px-24">Palette scheme: ${paletteScheme || 'none'}</p> | ||
<div class="d-flex"> | ||
${meta.argTypes.palette.options.map(palette => | ||
meta.render({ palette, colorScheme: paletteScheme }), | ||
)} | ||
</div> | ||
</div> | ||
`, | ||
)} | ||
</div> | ||
`, | ||
)}`; | ||
}, | ||
}; |
58 changes: 58 additions & 0 deletions
58
packages/documentation/src/stories/foundation/palette/palette.stories.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { Args, Meta, StoryObj } from '@storybook/web-components'; | ||
import { html, nothing } from 'lit'; | ||
|
||
const meta: Meta = { | ||
id: '43481535-5b39-40b5-a273-478b07dc3b31', | ||
title: 'Foundations/Palettes', | ||
tags: ['package:HTML'], | ||
render: renderPalette, | ||
parameters: { | ||
palettes: [], | ||
design: { | ||
type: 'figma', | ||
url: 'https://www.figma.com/file/xZ0IW0MJO0vnFicmrHiKaY/Components-Post?type=design&node-id=18172-73431&mode=design&t=3lniLiZhl7q9Gqgn-4', | ||
}, | ||
}, | ||
args: { | ||
palette: 'default', | ||
}, | ||
argTypes: { | ||
palette: { | ||
name: 'Palette', | ||
description: 'The set of colors used for a section of the page.', | ||
control: { | ||
type: 'radio', | ||
labels: { | ||
default: 'Default', | ||
alternate: 'Alternate', | ||
brand: 'Brand', | ||
accent: 'Accent', | ||
}, | ||
}, | ||
options: ['default', 'alternate', 'accent', 'brand'], | ||
table: { | ||
category: 'General', | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
// RENDERER | ||
function renderPalette(args: Args) { | ||
return html` | ||
<div class="palette-${args.palette} p-24" data-color-scheme=${args.colorScheme ?? nothing}> | ||
<h2 class="palette-text"> | ||
I use a specific color from the palette (it might be the same as the body color). | ||
</h2> | ||
<p>I use the main body color.</p> | ||
<button class="btn btn-primary">Primary button</button> | ||
</div> | ||
`; | ||
} | ||
|
||
// STORIES | ||
type Story = StoryObj; | ||
|
||
export const Default: Story = {}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
@use 'sass:map'; | ||
@use 'sass:meta'; | ||
|
||
@use '../functions/tokens'; | ||
@use '../placeholders/schemes'; | ||
@use '../tokens/elements'; | ||
@use '../tokens/palettes'; | ||
|
||
@use './variables' as *; | ||
|
||
@forward './utilities'; | ||
|
||
@mixin palettes($theme) { | ||
body { | ||
background-color: var(--post-current-palette-bg) !important; | ||
|
||
&:not([data-color-scheme='dark']) { | ||
@include palette-tokens($default-palette, $theme, 'light'); | ||
} | ||
|
||
&[data-color-scheme='dark'] { | ||
@include palette-tokens($default-palette, $theme, 'dark'); | ||
} | ||
} | ||
|
||
@each $palette in $palettes { | ||
.palette-#{$palette} { | ||
// Redefining the body color is necessary to ensure that the new color scheme is applied correctly. | ||
// Known limitation: body color may be incorrect with nested parent with different `data-color-scheme` values. | ||
color: tokens.get('body-color', elements.$post-body); | ||
background-color: var(--post-current-palette-bg) !important; | ||
|
||
// Light scheme explicitly set on the palette: | ||
&[data-color-scheme='light'], | ||
|
||
// No scheme explicitly set on the palette, but parent has a light scheme: | ||
&:where([data-color-scheme='light'] :not([data-color-scheme='dark'])), | ||
|
||
// No scheme explicitly set on the palette, and no scheme on the parent either: | ||
&:not([data-color-scheme='dark']):not([data-color-scheme='dark'] *) { | ||
@include palette-tokens($palette, $theme, 'light', $override-scheme: true); | ||
} | ||
|
||
// Dark scheme explicitly set on the palette: | ||
&[data-color-scheme='dark'], | ||
|
||
// No scheme explicitly set on the palette, but parent has a dark scheme: | ||
&:where([data-color-scheme='dark'] :not([data-color-scheme='dark'])) { | ||
@include palette-tokens($palette, $theme, 'dark', $override-scheme: true); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@mixin palette-tokens($name, $theme, $scheme, $override-scheme: false) { | ||
$palette: map.get(meta.module-variables(palettes), '#{$theme}-#{$scheme}'); | ||
|
||
@if (not $palette) { | ||
@error 'Palette #{$theme}-#{$scheme} not found.'; | ||
} | ||
|
||
--post-current-palette-fg: #{tokens.get('palettes-color-#{$name}-fg', $palette)}; | ||
--post-current-palette-bg: #{tokens.get('palettes-color-#{$name}-bg', $palette)}; | ||
|
||
@if ($override-scheme == true) { | ||
$bg-scheme: tokens.get('palettes-color-#{$name}-bg-scheme', $palette); | ||
|
||
@if ($bg-scheme == 'light') { | ||
@extend %color-scheme-light; | ||
} @else { | ||
@extend %color-scheme-dark; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.palette-text { | ||
color: var(--post-current-palette-fg); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
$default-palette: 'default'; | ||
$palettes: $default-palette, 'alternate', 'brand', 'accent'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@use 'mixins' as *; | ||
|
||
@include palettes('cargo'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
@use 'mixins' as *; | ||
|
||
@include palettes('post'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@use './temp/palettes/post-light' as post-light; | ||
@use './temp/palettes/post-dark' as post-dark; | ||
@use './temp/palettes/cargo-light' as cargo-light; | ||
@use './temp/palettes/cargo-dark' as cargo-dark; | ||
|
||
$post-light: post-light.$post-palettes; | ||
$post-dark: post-dark.$post-palettes; | ||
$cargo-light: cargo-light.$post-palettes; | ||
$cargo-dark: cargo-dark.$post-palettes; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@use 'src/palettes/cargo-palettes'; | ||
|
||
/* stylelint-disable scss/at-extend-no-missing-placeholder */ | ||
.palettes { | ||
@extend .palette-text; | ||
@extend .palette-default; | ||
@extend .palette-alternate; | ||
@extend .palette-brand; | ||
@extend .palette-accent; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
@use 'src/palettes/post-palettes'; | ||
|
||
/* stylelint-disable scss/at-extend-no-missing-placeholder */ | ||
.palettes { | ||
@extend .palette-text; | ||
@extend .palette-default; | ||
@extend .palette-alternate; | ||
@extend .palette-brand; | ||
@extend .palette-accent; | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm missing documentation for people who'd like to implement palettes, without using an entry file. What files are necessary to just get palettes to work and where can they be found?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I created a separate ticket for that since it requires changes to the StylesPackageImport component: #4025