-
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
chore(styles): tokenize containers #3982
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0c2f3d2
feat(styles): tokenize the containers
alizedebray b24db09
Merge branch 'main' into 3900-component-container
alizedebray 4701648
Remove the xxl breakpoint
alizedebray 22f663e
Remove the rg breakpoint
alizedebray b5fe0e3
Merge branch '3975-remove-rg-and-xxl-breakpoints' into 3900-component…
alizedebray 69b1d05
update container styles
alizedebray 337f623
Update containers doc
alizedebray e086ced
Add visual regression tests
alizedebray cc100bf
remove unnecessary changes
alizedebray b0a5196
Update containers.styles.scss
alizedebray 2ed59d5
Merge branch 'main' into 3975-remove-rg-and-xxl-breakpoints
alizedebray c179cd5
Merge branch '3975-remove-rg-and-xxl-breakpoints' into 3900-component…
alizedebray 66693a9
Update tokens
alizedebray 4152d1e
Create plenty-taxis-hear.md
alizedebray 1f5a18b
Merge branch 'main' into 3900-component-container
alizedebray e0ca9e1
Merge branch 'main' into 3900-component-container
alizedebray d6ccd7f
Merge branch 'main' into 3900-component-container
alizedebray b795182
Merge branch 'main' into 3900-component-container
alizedebray 3825103
Merge branch 'main' into 3900-component-container
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,26 @@ | ||
--- | ||
'@swisspost/design-system-styles': major | ||
'@swisspost/design-system-documentation': patch | ||
--- | ||
|
||
Removed the `rg` and `xxl` grid breakpoints, reducing the grid to 5 breakpoints instead of the previous 7. This change affects all CSS classes tied to specific breakpoints (e.g., `col-rg-2`, `m-xxl-4`). | ||
|
||
**Previous Breakpoints**: | ||
- `xs: 0px` | ||
- `sm: 400px` | ||
- `rg: 600px` | ||
- `md: 780px` | ||
- `lg: 1024px` | ||
- `xl: 1280px` | ||
- `xxl: 1440px` | ||
|
||
**New Breakpoints**: | ||
- `xs: 0px` | ||
- `sm: 600px` | ||
- `md: 780px` | ||
- `lg: 1024px` | ||
- `xl: 1280px` | ||
|
||
To maintain compatibility with the updated grid system, you need to update your code by replacing any `*-rg-*` classes with `*-sm-*`, and any `*-xxl-*` classes with `*-xl-*`. For example: | ||
- `col-rg-2` → `col-sm-2` | ||
- `m-xxl-4` → `m-xl-4` |
9 changes: 9 additions & 0 deletions
9
packages/documentation/cypress/snapshots/foundation/layout/containers.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,9 @@ | ||
describe('Containers', () => { | ||
it('default', () => { | ||
cy.visit('/iframe.html?id=snapshots--containers'); | ||
cy.get('.container', { timeout: 30000 }).should('be.visible'); | ||
|
||
// takes a screenshot for each breakpoint | ||
cy.percySnapshot('Containers', { widths: [320, 720, 960, 1080, 1440] }); | ||
}); | ||
}); |
50 changes: 17 additions & 33 deletions
50
...ages/documentation/src/stories/foundation/layout/containers/containers.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 |
---|---|---|
@@ -1,47 +1,31 @@ | ||
import { Meta, Source } from '@storybook/blocks'; | ||
import { formatAsMap } from '@/utils/sass-export'; | ||
import { ContainersTable, SCSS_VARIABLES } from './containers.blocks'; | ||
import { Canvas, Meta, Source } from '@storybook/blocks'; | ||
import * as ContainerStories from './containers.stories'; | ||
|
||
<Meta of={ContainerStories} /> | ||
|
||
# Containers | ||
|
||
<p className="lead">Containers are a fundamental building block of our Design-System that contain, pad, and align your content within a given device or viewport. They are required, when using our grid-system. While containers can be nested, most layouts do not require a nested container.</p> | ||
<div className="lead"> | ||
Containers are essential layout elements ensuring content is aligned and properly padded across all devices and viewports. | ||
</div> | ||
|
||
We can distinguish between two different container types: | ||
<div className="alert alert-info my-24"> | ||
Containers are required when using the <a href="/?path=/docs/7240f2ef-216a-490e-9bd8-c0cef19f7b31--docs">grid system</a>. | ||
</div> | ||
|
||
- <code>.container</code>, which defines a <code>max-width</code> on some breakpoints. | ||
- <code>.container-fluid</code>, which is <code>width: 100%</code> at all breakpoints. | ||
There are two types of containers. The only difference between them is how they behave on wider screens. | ||
To see the difference, click the **"View full screen"** button in the examples below. | ||
|
||
<ContainersTable /> | ||
## Container | ||
|
||
## Default container | ||
The `.container` adapts its width based on the viewport size, but it will not exceed 1200px. | ||
This ensures content stays centered and does not stretch too wide on large screens. | ||
|
||
Our default `.container` class is a responsive, fixed-width container. | ||
<Canvas sourceState="shown" of={ContainerStories.Container} /> | ||
|
||
<Source code={`<div class="container"> | ||
<!-- Content here --> | ||
</div>`} language="scss"/> | ||
## Fluid Container | ||
|
||
## Fluid containers | ||
The `.container-fluid` spans the entire width of the viewport, regardless of its size. | ||
Use this for layouts where the content should stretch edge-to-edge, even on large screens. | ||
|
||
Use `.container-fluid` for a full width container, spanning the entire width of the viewport on every breakpoint. | ||
|
||
<Source code={`<div class="container-fluid"> | ||
<!-- Content here --> | ||
</div>`} language="scss"/> | ||
|
||
## CSS | ||
|
||
When using our source Sass files, you have the option of using Sass variables for customization (not recommended). | ||
|
||
### Sass variables | ||
|
||
<Source | ||
language="scss" | ||
dark | ||
code={Object.entries(SCSS_VARIABLES.variables) | ||
.map(([key, value]) => `$${key}: ${formatAsMap(value)};`) | ||
.join('\n')} | ||
></Source> | ||
<Canvas sourceState="shown" of={ContainerStories.ContainerFluid} /> |
26 changes: 26 additions & 0 deletions
26
...ges/documentation/src/stories/foundation/layout/containers/containers.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,26 @@ | ||
import type { Args, StoryContext, StoryObj } from '@storybook/web-components'; | ||
import meta from './containers.stories'; | ||
import { html } from 'lit'; | ||
import { StoryFn } from '@storybook/web-components'; | ||
|
||
const { id, ...metaWithoutId } = meta; | ||
|
||
export default { | ||
...metaWithoutId, | ||
title: 'Snapshots', | ||
}; | ||
|
||
type Story = StoryObj; | ||
|
||
export const Containers: Story = { | ||
render: (_args: Args, context: StoryContext) => { | ||
return html`${['container', 'container-fluid'].map(containerClass => | ||
meta.render({ containerClass }, context), | ||
)}`; | ||
}, | ||
decorators: [ | ||
(story: StoryFn, context: StoryContext) => html` | ||
<div class="container-snapshots">${story(context.args, context)}</div> | ||
`, | ||
], | ||
}; |
30 changes: 25 additions & 5 deletions
30
packages/documentation/src/stories/foundation/layout/containers/containers.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 |
---|---|---|
@@ -1,16 +1,36 @@ | ||
import type { StoryObj } from '@storybook/web-components'; | ||
import type { Args, StoryObj } from '@storybook/web-components'; | ||
import { StoryContext, StoryFn } from '@storybook/web-components'; | ||
import { MetaExtended } from '@root/types'; | ||
import { html } from 'lit'; | ||
import './containers.styles.scss'; | ||
|
||
const meta: MetaExtended = { | ||
id: 'a4ca9660-bb4a-4cc7-adfd-84767382ac03', | ||
title: 'Foundations/Layout/Containers', | ||
parameters: { | ||
badges: [], | ||
}, | ||
render: (args: Args) => html` | ||
<div class=${args.containerClass}> | ||
<!-- Content goes here --> | ||
</div> | ||
`, | ||
decorators: [ | ||
(story: StoryFn, context: StoryContext) => html` | ||
<div class="container-examples">${story(context.args, context)}</div> | ||
`, | ||
], | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj; | ||
|
||
export const Default: Story = {}; | ||
export const Container: Story = { | ||
args: { | ||
containerClass: 'container', | ||
}, | ||
}; | ||
|
||
export const ContainerFluid: Story = { | ||
args: { | ||
containerClass: 'container-fluid', | ||
}, | ||
}; |
39 changes: 39 additions & 0 deletions
39
packages/documentation/src/stories/foundation/layout/containers/containers.styles.scss
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,39 @@ | ||
@use '@swisspost/design-system-styles/core' as post; | ||
|
||
$margin-bg: #F4FFA2; | ||
$padding-bg: #B8E2F3; | ||
$content-bg: #A69CE1; | ||
$content-fg: #59718B; | ||
|
||
.container-examples { | ||
background: $margin-bg; | ||
|
||
&:is(.sb-main-padded *) { | ||
margin-inline: -1rem; | ||
} | ||
|
||
.container, | ||
.container-fluid { | ||
background: linear-gradient($padding-bg, $padding-bg), linear-gradient($content-bg, $content-bg); | ||
background-clip: content-box, border-box; | ||
color: $content-fg; | ||
|
||
&::before { | ||
content: "Content goes here"; | ||
} | ||
} | ||
} | ||
|
||
.container-snapshots { | ||
.container { | ||
&::before { | ||
content: "Container"; | ||
} | ||
} | ||
|
||
.container-fluid { | ||
&::before { | ||
content: "Container fluid"; | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
@forward './variables/options'; | ||
|
||
@use 'layout'; | ||
@use 'elements'; | ||
@use 'utilities'; | ||
|
||
|
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
@forward './variables/options'; | ||
|
||
@use './layout'; | ||
@use './utilities'; | ||
@use './elements'; | ||
@use './components'; | ||
|
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
@forward './variables/options'; | ||
|
||
@use 'layout'; | ||
@use 'utilities'; | ||
@use 'elements'; | ||
@use 'components'; | ||
|
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,32 @@ | ||
@use 'sass:map'; | ||
|
||
@use '../functions/tokens'; | ||
@use '../mixins/media'; | ||
@use '../tokens/components'; | ||
@use '../variables/breakpoints'; | ||
|
||
tokens.$default-map: components.$post-container; | ||
|
||
.container, | ||
.container-fluid { | ||
width: 100%; | ||
margin-inline: auto; | ||
|
||
@each $breakpoint in map.keys(breakpoints.$grid-breakpoints) { | ||
@include media.min($breakpoint) { | ||
$gutter: tokens.get('grid-gutter-#{$breakpoint}'); | ||
$padding: tokens.get('grid-padding-#{$breakpoint}'); | ||
|
||
--post-grid-gutter-x: #{$gutter}; | ||
|
||
// The `.row` has a negative margin equal to half the gutter size. | ||
// To prevent content from overflowing, the container needs to have | ||
// a padding of at least half the gutter size to offset this negative margin. | ||
padding-inline: max(#{$padding}, calc(0.5 * var(--post-grid-gutter-x))); | ||
} | ||
} | ||
} | ||
|
||
.container { | ||
max-width: tokens.get('grid-max-width'); | ||
} |
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 @@ | ||
@forward './containers'; |
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 was deleted.
Oops, something went wrong.
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.
Will these be removed in a separate PR?