-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(documentation): adds container stories (#2030)
Co-authored-by: Alizé Debray <[email protected]> Co-authored-by: oliverschuerch <[email protected]>
- Loading branch information
1 parent
c72e25a
commit dd0fa86
Showing
23 changed files
with
339 additions
and
244 deletions.
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,5 @@ | ||
--- | ||
'@swisspost/design-system-documentation': minor | ||
--- | ||
|
||
Added a documentation page for the `.container` and `.container-fluid` classes. |
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
5 changes: 0 additions & 5 deletions
5
...documentation/src/stories/foundation/layout/breakpoints/breakpoints-available.sample.scss
This file was deleted.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
...s/documentation/src/stories/foundation/layout/breakpoints/breakpoints-between.sample.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
2 changes: 2 additions & 0 deletions
2
...documentation/src/stories/foundation/layout/breakpoints/breakpoints-max-width.sample.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
2 changes: 2 additions & 0 deletions
2
...documentation/src/stories/foundation/layout/breakpoints/breakpoints-min-width.sample.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
2 changes: 2 additions & 0 deletions
2
...es/documentation/src/stories/foundation/layout/breakpoints/breakpoints-single.sample.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
53 changes: 28 additions & 25 deletions
53
packages/documentation/src/stories/foundation/layout/breakpoints/breakpoints.blocks.tsx
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,33 +1,36 @@ | ||
import { forEach } from '../../../../utils/react'; | ||
import { parse } from '../../../../utils/sass-export'; | ||
import { SpecTable } from '../shared.blocks'; | ||
import scss from './breakpoints.module.scss'; | ||
|
||
export const SCSS_VARIABLES = parse(scss); | ||
|
||
export const BreakpointTable = () => ( | ||
<div className="table-responsive"> | ||
<table className="table"> | ||
<thead> | ||
<tr> | ||
<th></th> | ||
<th>Class infix</th> | ||
<th>Dimensions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{forEach( | ||
SCSS_VARIABLES.breakpoint, | ||
(data: { key: number; value: { name: string; infix: any; dimensions: string } }) => { | ||
return ( | ||
<tr> | ||
<th>{data.value.name}</th> | ||
<td dangerouslySetInnerHTML={{ __html: data.value.infix }}></td> | ||
<td>{data.value.dimensions}</td> | ||
</tr> | ||
); | ||
}, | ||
)} | ||
</tbody> | ||
</table> | ||
</div> | ||
<SpecTable> | ||
<tr> | ||
<th>Name</th> | ||
{forEach(SCSS_VARIABLES.breakpoint, (data: { key: string; value: { name: string } }) => ( | ||
<td key={data.key}> | ||
<small>{data.value.name}</small> | ||
</td> | ||
))} | ||
</tr> | ||
|
||
<tr> | ||
<th>Code name</th> | ||
{forEach(SCSS_VARIABLES.breakpoint, (data: { key: string }) => ( | ||
<td key={data.key}> | ||
<code>{data.key}</code> | ||
</td> | ||
))} | ||
</tr> | ||
<tr> | ||
<th>Class infix</th> | ||
{forEach(SCSS_VARIABLES.breakpoint, (data: { key: string; value: { infix: string } }) => ( | ||
<td key={data.key}> | ||
{data.value.infix === 'none' ? 'none' : <code>-{data.value.infix}-</code>} | ||
</td> | ||
))} | ||
</tr> | ||
</SpecTable> | ||
); |
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
23 changes: 5 additions & 18 deletions
23
packages/documentation/src/stories/foundation/layout/breakpoints/breakpoints.module.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 |
---|---|---|
@@ -1,24 +1,11 @@ | ||
@use 'sass:list'; | ||
@use 'sass:map'; | ||
@use '@swisspost/design-system-styles/core' as post; | ||
@use '../layout.shared' as shared; | ||
@use '../shared.module' as shared; | ||
|
||
:export { | ||
@each $breakpoint, $value in post.$grid-breakpoints { | ||
$i: list.index(post.$grid-breakpoints, $breakpoint $value); | ||
$name: map.get(shared.$breakpointNames, $breakpoint) or $breakpoint; | ||
|
||
breakpoint_#{$breakpoint}_name: $name; | ||
// Variables used in the spec table (some variables used on the page are defined in the shared module) | ||
|
||
@if $i == 1 { | ||
$keys: map.keys(post.$grid-breakpoints); | ||
$nextValue: map.get(post.$grid-breakpoints, list.nth($keys, $i + 1)); | ||
|
||
breakpoint_#{$breakpoint}_infix: none; | ||
breakpoint_#{$breakpoint}_dimensions: #{'<' + $nextValue}; | ||
} @else { | ||
breakpoint_#{$breakpoint}_infix: #{'<code>' + $breakpoint + '</code>'}; | ||
breakpoint_#{$breakpoint}_dimensions: #{'≥' + $value}; | ||
} | ||
// Variables to expose under sass variables section | ||
@each $breakpoint, $value in post.$grid-breakpoints { | ||
variables_grid-breakpoints_#{$breakpoint}: $value; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
packages/documentation/src/stories/foundation/layout/containers/containers.blocks.tsx
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,42 @@ | ||
import { parse } from '../../../../utils/sass-export'; | ||
import { forEach } from '../../../../utils/react'; | ||
import { SpecTable } from '../shared.blocks'; | ||
import scss from './containers.module.scss'; | ||
|
||
export const SCSS_VARIABLES = parse(scss); | ||
|
||
export const ContainersTable = () => ( | ||
<SpecTable> | ||
<tr> | ||
<th> | ||
Container <code>max-width</code> | ||
</th> | ||
{forEach( | ||
SCSS_VARIABLES.container, | ||
(data: { key: string; value: { ['max-width']: string } }) => ( | ||
<td key={data.key}>{data.value['max-width']}</td> | ||
), | ||
)} | ||
</tr> | ||
<tr> | ||
<th> | ||
Container <code>padding</code> | ||
</th> | ||
{forEach(SCSS_VARIABLES.container, (data: { key: string; value: { padding: string } }) => ( | ||
<td key={data.key}>{data.value.padding}</td> | ||
))} | ||
</tr> | ||
|
||
<tr> | ||
<th> | ||
Container-Fluid <code>padding</code> | ||
</th> | ||
{forEach( | ||
SCSS_VARIABLES.container, | ||
(data: { key: string; value: { fluid: { padding: string } } }) => ( | ||
<td key={data.key}>{data.value.fluid.padding}</td> | ||
), | ||
)} | ||
</tr> | ||
</SpecTable> | ||
); |
47 changes: 47 additions & 0 deletions
47
...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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { Meta, Source } from '@storybook/blocks'; | ||
import { formatAsMap } from '../../../../utils/sass-export'; | ||
import { ContainersTable, SCSS_VARIABLES } from './containers.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> | ||
|
||
We can distinguish between two different container types: | ||
|
||
- <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. | ||
|
||
<ContainersTable /> | ||
|
||
## Default container | ||
|
||
Our default `.container` class is a responsive, fixed-width container. | ||
|
||
<Source code={`<div class="container"> | ||
<!-- Content here --> | ||
</div>`} language="scss"/> | ||
|
||
## Fluid containers | ||
|
||
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> |
30 changes: 30 additions & 0 deletions
30
packages/documentation/src/stories/foundation/layout/containers/containers.module.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,30 @@ | ||
@use 'sass:map'; | ||
@use '@swisspost/design-system-styles/core' as post; | ||
@use '../shared.module' as shared; | ||
|
||
:export { | ||
// Variables used in the spec table (some variables used on the page are defined in the shared module) | ||
@each $breakpoint, $value in post.$grid-breakpoints { | ||
container_#{$breakpoint}_max-width: map.get(post.$container-max-widths, $breakpoint) or none; | ||
container_#{$breakpoint}_padding: map.get(post.$grid-container-padding, $breakpoint); | ||
container_#{$breakpoint}_fluid_padding: map.get( | ||
post.$grid-container-fluid-padding, | ||
$breakpoint | ||
); | ||
} | ||
|
||
// Variables to expose under sass variables section | ||
@each $breakpoint, $value in post.$grid-breakpoints { | ||
variables_container-max-widths_#{$breakpoint}: map.get(post.$container-max-widths, $breakpoint); | ||
variables_grid-container-padding_#{$breakpoint}: map.get( | ||
post.$grid-container-padding, | ||
$breakpoint | ||
) or | ||
none; | ||
variables_grid-container-fluid-padding_#{$breakpoint}: map.get( | ||
post.$grid-container-fluid-padding, | ||
$breakpoint | ||
) or | ||
none; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import type { Meta, StoryObj } from '@storybook/web-components'; | ||
import { BADGE } from '../../../../../.storybook/constants'; | ||
|
||
const meta: Meta = { | ||
title: 'Foundations/Layout/Containers', | ||
parameters: { | ||
badges: [BADGE.NEEDS_REVISION], | ||
}, | ||
}; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj; | ||
|
||
export const Default: Story = {}; |
12 changes: 7 additions & 5 deletions
12
packages/documentation/src/stories/foundation/layout/grid/grid-scss-mixins.sample.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 |
---|---|---|
@@ -1,12 +1,14 @@ | ||
@use '@swisspost/design-system-styles/core' as post; | ||
|
||
// Creates a wrapper for a series of columns | ||
@include make-row(); | ||
@include post.make-row(); | ||
|
||
// Make the column element grid-ready (applying everything but the width) | ||
@include make-col-ready(); | ||
@include post.make-col-ready(); | ||
|
||
// Without optional size values, the mixin will create equal columns (similar to using .col) | ||
@include make-col(); | ||
@include make-col($size, $columns: $grid-columns); | ||
@include post.make-col(); | ||
@include post.make-col($size, $columns: post.$grid-columns); | ||
|
||
// Offset with margins | ||
@include make-col-offset($size, $columns: $grid-columns); | ||
@include post.make-col-offset($size, $columns: post.$grid-columns); |
Oops, something went wrong.