diff --git a/.changeset/eight-singers-add.md b/.changeset/eight-singers-add.md new file mode 100644 index 0000000000..a2bf5073b9 --- /dev/null +++ b/.changeset/eight-singers-add.md @@ -0,0 +1,5 @@ +--- +'@swisspost/design-system-styles': patch +--- + +Updated the grid gutters and margins. diff --git a/.changeset/orange-cups-join.md b/.changeset/orange-cups-join.md new file mode 100644 index 0000000000..3c445c96b5 --- /dev/null +++ b/.changeset/orange-cups-join.md @@ -0,0 +1,5 @@ +--- +'@swisspost/design-system-documentation': patch +--- + +Updated the layout containers, grid and columns documentation pages. diff --git a/packages/documentation/src/stories/foundation/layout/columns/columns.docs.mdx b/packages/documentation/src/stories/foundation/layout/columns/columns.docs.mdx index d5d154b512..8b69787347 100644 --- a/packages/documentation/src/stories/foundation/layout/columns/columns.docs.mdx +++ b/packages/documentation/src/stories/foundation/layout/columns/columns.docs.mdx @@ -1,4 +1,4 @@ -import { Meta, Canvas, Source, Controls } from '@storybook/blocks'; +import { Meta, Canvas, Controls } from '@storybook/blocks'; import * as ColumnStories from './columns.stories'; import './columns.styles.scss'; diff --git a/packages/documentation/src/stories/foundation/layout/columns/columns.stories.ts b/packages/documentation/src/stories/foundation/layout/columns/columns.stories.ts index 5bfb236ab5..c334705a50 100644 --- a/packages/documentation/src/stories/foundation/layout/columns/columns.stories.ts +++ b/packages/documentation/src/stories/foundation/layout/columns/columns.stories.ts @@ -9,8 +9,8 @@ const meta: MetaExtended = { badges: [], }, decorators: [ - (story: StoryFn, { args, context }: StoryContext) => html` -
${story(args, context)}
+ (story: StoryFn, context: StoryContext) => html` +
${story(context.args, context)}
`, ], args: { @@ -19,7 +19,7 @@ const meta: MetaExtended = { justifyContent: 'justify-content-start', offsetItem: 'offset-1', renderBreakingElement: true, - ColumnOneOrder: 'no order', + ColumnOneOrder: 'no order class', ColumnTwoOrder: 'order-5', ColumnThreeOrder: 'order-1', ColumnWidth: 'col-4', @@ -141,9 +141,14 @@ export const VerticalExample: Story = { include: ['Align Items', 'Align Item 1'], }, }, + decorators: [ + (story: StoryFn, context: StoryContext) => html` +
${story(context.args, context)}
+ `, + ], render: (args: Args) => html`
-
+
Item 1
@@ -250,8 +255,8 @@ export const ColumnBreakExample: Story = { export const ResetOffsetExample: Story = { decorators: [ - (story: StoryFn, { args, context }: StoryContext) => html` - ${story(args, context)} + (story: StoryFn, context: StoryContext) => html` + ${story(context.args, context)}

Resize the browser window to see changes.

`, ], diff --git a/packages/documentation/src/stories/foundation/layout/columns/columns.styles.scss b/packages/documentation/src/stories/foundation/layout/columns/columns.styles.scss index 6946909b68..db3b56abd9 100644 --- a/packages/documentation/src/stories/foundation/layout/columns/columns.styles.scss +++ b/packages/documentation/src/stories/foundation/layout/columns/columns.styles.scss @@ -1,25 +1,22 @@ @use '@swisspost/design-system-styles/core' as post; +@use '../shared.styles' as *; .column-example { font-size: post.$font-size-sm; .row > *:not(.w-100) { - padding-block: 0.75rem; - background-color: lighten(post.$nightblue-bright, 55%); - border: 1px solid lighten(post.$nightblue-dark, 45%); + @include column-styles; } .row { - background-color: lighten(post.$nightblue-bright, 61.5%); + background-color: lighten(post.$petrol-dark, 75%); } - .row-height { + .row-height .row { min-height: 10rem; } - .standalone-columns > *:not(p){ - padding-block: 0.75rem; - background-color: lighten(post.$nightblue-bright, 55%); - border: 1px solid lighten(post.$nightblue-dark, 45%); + .standalone-columns > *:not(p) { + @include column-styles; } -} \ No newline at end of file +} diff --git a/packages/documentation/src/stories/foundation/layout/containers/containers.blocks.tsx b/packages/documentation/src/stories/foundation/layout/containers/containers.blocks.tsx deleted file mode 100644 index 7e0fc7d6ab..0000000000 --- a/packages/documentation/src/stories/foundation/layout/containers/containers.blocks.tsx +++ /dev/null @@ -1,37 +0,0 @@ -import { parse } from '@/utils/sass-export'; -import { forEach } from '@/utils/react'; -import { SpecTable } from '@/stories/foundation/layout/shared.blocks'; -import scss from './containers.module.scss'; - -/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ -export const SCSS_VARIABLES: any = parse(scss); - -export const ContainersTable = () => ( - - - - Container max-width - - {forEach(SCSS_VARIABLES.container, ({ key, value }) => ( - {value['max-width']} - ))} - - - - Container padding - - {forEach(SCSS_VARIABLES.container, ({ key, value }) => ( - {value.padding} - ))} - - - - - Container-Fluid padding - - {forEach(SCSS_VARIABLES.container, ({ key, value }) => ( - {value.fluid.padding} - ))} - - -); diff --git a/packages/documentation/src/stories/foundation/layout/containers/containers.docs.mdx b/packages/documentation/src/stories/foundation/layout/containers/containers.docs.mdx index d2852c96ea..065b53701d 100644 --- a/packages/documentation/src/stories/foundation/layout/containers/containers.docs.mdx +++ b/packages/documentation/src/stories/foundation/layout/containers/containers.docs.mdx @@ -1,47 +1,34 @@ 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'; # Containers -

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.

+
+ Containers are essential layout elements ensuring content is aligned and properly padded across all devices and viewports. +
-We can distinguish between two different container types: +
+ Containers are required when using the grid system. +
-- .container, which defines a max-width on some breakpoints. -- .container-fluid, which is width: 100% at all breakpoints. +There is two types of containers: - +## Container -## Default container - -Our default `.container` class is a responsive, fixed-width container. +The `.container` adapts its width based on the viewport size, but it will not exceed 1280px. +This ensures content stays centered and does not stretch too wide on large screens. - +
`} language="scss"/> -## Fluid containers +## Fluid Container -Use `.container-fluid` for a full width container, spanning the entire width of the viewport on every breakpoint. +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. - +
`} language="scss"/> - -## CSS - -When using our source Sass files, you have the option of using Sass variables for customization (not recommended). - -### Sass variables - - `$${key}: ${formatAsMap(value)};`) - .join('\n')} -> diff --git a/packages/documentation/src/stories/foundation/layout/containers/containers.module.scss b/packages/documentation/src/stories/foundation/layout/containers/containers.module.scss index 4c578c2f7f..0ffb682d47 100644 --- a/packages/documentation/src/stories/foundation/layout/containers/containers.module.scss +++ b/packages/documentation/src/stories/foundation/layout/containers/containers.module.scss @@ -3,7 +3,6 @@ @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); @@ -12,19 +11,4 @@ $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; - } } diff --git a/packages/documentation/src/stories/foundation/layout/grid/grid-scss-mixins.sample.scss b/packages/documentation/src/stories/foundation/layout/grid/grid-scss-mixins.sample.scss deleted file mode 100644 index 947e459731..0000000000 --- a/packages/documentation/src/stories/foundation/layout/grid/grid-scss-mixins.sample.scss +++ /dev/null @@ -1,14 +0,0 @@ -@use '@swisspost/design-system-styles/core' as post; - -// Creates a wrapper for a series of columns -@include post.make-row(); - -// Make the column element grid-ready (applying everything but the width) -@include post.make-col-ready(); - -// Without optional size values, the mixin will create equal columns (similar to using .col) -@include post.make-col(); -@include post.make-col($size, $columns: post.$grid-columns); - -// Offset with margins -@include post.make-col-offset($size, $columns: post.$grid-columns); diff --git a/packages/documentation/src/stories/foundation/layout/grid/grid.blocks.tsx b/packages/documentation/src/stories/foundation/layout/grid/grid.blocks.tsx deleted file mode 100644 index 2af6b4102a..0000000000 --- a/packages/documentation/src/stories/foundation/layout/grid/grid.blocks.tsx +++ /dev/null @@ -1,54 +0,0 @@ -import { parse } from '@/utils/sass-export'; -import { forEach } from '@/utils/react'; -import { SpecTable } from '@/stories/foundation/layout/shared.blocks'; -import scss from './grid.module.scss'; - -/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ -export const SCSS_VARIABLES: any = parse(scss); -export const GridTable = () => ( - - - Class prefix - {forEach(SCSS_VARIABLES.breakpoint, ({ key, value }) => ( - - .col-{value.infix === 'none' ? '' : `${value.infix}-`} - - ))} - - - - Gutter width - {forEach(SCSS_VARIABLES.grid, ({ key, value }) => ( - {value['gutter-width']} - ))} - - - - Amount of columns - {SCSS_VARIABLES['grid-columns']} - - - - Custom gutters - - - yes - - - - - Nestable - - - yes - - - - - Column ordering - - yes - - - -); diff --git a/packages/documentation/src/stories/foundation/layout/grid/grid.docs.mdx b/packages/documentation/src/stories/foundation/layout/grid/grid.docs.mdx index afeaae780f..3ac9b81297 100644 --- a/packages/documentation/src/stories/foundation/layout/grid/grid.docs.mdx +++ b/packages/documentation/src/stories/foundation/layout/grid/grid.docs.mdx @@ -1,10 +1,10 @@ import { Canvas, Meta, Source } from '@storybook/blocks'; -import { formatAsMap } from '@/utils/sass-export'; -import { GridTable, SCSS_VARIABLES } from './grid.blocks'; -import * as GridStories from './grid.stories'; -import './grid.styles.scss'; +import { parse } from '@/utils/sass-export'; +import scss from '../shared.module.scss'; import SampleContainer from './grid-container.sample.html?raw'; -import SampleScssMixins from './grid-scss-mixins.sample.scss?raw'; +import * as GridStories from './grid.stories'; + +export const BREAKPOINT_COUNT = parse(scss)['breakpoint-count']; @@ -12,7 +12,7 @@ import SampleScssMixins from './grid-scss-mixins.sample.scss?raw';
Use our powerful mobile-first flexbox grid to build layouts of all shapes and sizes thanks to a - twelve column system, {SCSS_VARIABLES['breakpoint-count']} default responsive tiers, + twelve column system, {BREAKPOINT_COUNT} default responsive tiers, Sass variables and mixins, and dozens of predefined classes.
@@ -35,7 +35,7 @@ The above example creates three equal-width columns across all devices and viewp Breaking it down, here’s how the grid system comes together: -- **Our grid supports {SCSS_VARIABLES['breakpoint-count']} responsive breakpoints.** Breakpoints are based on `min-width` media queries, meaning they affect that breakpoint and all those above it. This means you can control container and column sizing and behavior by each breakpoint. +- **Our grid supports {BREAKPOINT_COUNT} responsive breakpoints.** Breakpoints are based on `min-width` media queries, meaning they affect that breakpoint and all those above it. This means you can control container and column sizing and behavior by each breakpoint. - **Container (e.g. `.container`) center and horizontally pad your content.**
Don't nest `.containers`, but use them (for example) as a wrapper for your content area: @@ -44,13 +44,6 @@ Breaking it down, here’s how the grid system comes together: - **Gutters are also responsive and customizable.** Gutter classes are available across all breakpoints, with all the same sizes as our `margin` and `padding` spacing. Change horizontal gutters with `.gx-*` classes, vertical gutters with `.gy-*`, or all gutters with `.g-*` classes. `.g-0` is also available to remove gutters. - **Sass variables, maps, and mixins power the grid.** If you don’t want to use the predefined grid classes, you can use the grid’s source Sass to create your own with more semantic markup. We also include some CSS custom properties to consume these Sass variables for even greater flexibility for you. -## Grid options - -Our grid system can adapt across all {SCSS_VARIABLES['breakpoint-count']} breakpoints. -Each of these breakpoints have their own specifications, a unique class prefix, and some modifiers. - - - ## Auto-layout columns Utilize breakpoint-specific column classes for easy column sizing without an explicit numbered class like `.col-sm-6`. @@ -75,7 +68,7 @@ Use `.col-{breakpoint}-auto` classes to size columns based on the natural width ## Responsive classes -Our grid includes {SCSS_VARIABLES['breakpoint-count']} tiers of predefined classes for building complex responsive layouts. +Our grid includes {BREAKPOINT_COUNT} tiers of predefined classes for building complex responsive layouts. ### All breakpoints @@ -116,25 +109,3 @@ To nest your content with the default grid, add a new `.row` and set of `.col-*` Note: the style in this example is applied to the column to visually better understand nesting. However, it's recommended to apply the style on a child element of the column. - -## CSS - -When using our source Sass files, you have the option of using Sass variables and mixins to create custom, semantic, and responsive page layouts. Our predefined grid classes use these same variables and mixins to provide a whole suite of ready-to-use classes for fast responsive layouts. - -### Sass variables - -Variables and maps determine the number of columns, the gutter width, and the media query point at which to begin floating columns. We use these to generate the predefined grid classes documented above, as well as for the custom mixins listed below. - - `$${key}: ${formatAsMap(value)};`) - .join('\n')} -> - -### Sass mixins - -Mixins are used in conjunction with the grid variables to generate semantic CSS for individual grid columns. - - diff --git a/packages/documentation/src/stories/foundation/layout/grid/grid.module.scss b/packages/documentation/src/stories/foundation/layout/grid/grid.module.scss deleted file mode 100644 index cd9c6968b0..0000000000 --- a/packages/documentation/src/stories/foundation/layout/grid/grid.module.scss +++ /dev/null @@ -1,21 +0,0 @@ -@use 'sass:list'; -@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) - grid-columns: post.$grid-columns; - - @each $breakpoint, $value in post.$grid-breakpoints { - grid_#{$breakpoint}_gutter-width: map.get(post.$grid-gutter-x, $breakpoint); - } - - // Variables to expose under sass variables section - variables_grid-columns: post.$grid-columns; - variables_grid-row-columns: post.$grid-row-columns; - - @each $breakpoint, $value in post.$grid-breakpoints { - variables_grid-gutter-x_#{$breakpoint}: map.get(post.$grid-gutter-x, $breakpoint); - } -} diff --git a/packages/documentation/src/stories/foundation/layout/grid/grid.stories.ts b/packages/documentation/src/stories/foundation/layout/grid/grid.stories.ts index c930e97aef..8d9e7dcd47 100644 --- a/packages/documentation/src/stories/foundation/layout/grid/grid.stories.ts +++ b/packages/documentation/src/stories/foundation/layout/grid/grid.stories.ts @@ -1,6 +1,7 @@ import { StoryContext, StoryFn, StoryObj } from '@storybook/web-components'; import { html } from 'lit'; import { MetaExtended } from '@root/types'; +import './grid.styles.scss'; const meta: MetaExtended = { id: '7240f2ef-216a-490e-9bd8-c0cef19f7b31', @@ -9,9 +10,9 @@ const meta: MetaExtended = { badges: [], }, decorators: [ - (story: StoryFn, { args, context }: StoryContext) => html` -
- ${story(args, context)} + (story: StoryFn, context: StoryContext) => html` +
+ ${story(context.args, context)}
`, ], @@ -25,15 +26,9 @@ export const Basis: Story = { render: () => html`
-
-
Column
-
-
-
Column
-
-
-
Column
-
+
Column
+
Column
+
Column
`, @@ -43,18 +38,9 @@ export const SingleColumnOnly: Story = { render: () => html`
-
-
Don't do this!
-
+
Don't do this!
-
-
-
-
Nor this!
-
-
-
-

Instead, your content should go here!

+

Instead, your content should go here!

`, }; @@ -62,24 +48,14 @@ export const SingleColumnOnly: Story = { export const EqualWidth: Story = { render: () => html`
-
-
-
1 of 2
-
-
-
2 of 2
-
+
+
1 of 2
+
2 of 2
-
-
-
1 of 3
-
-
-
2 of 3
-
-
-
3 of 3
-
+
+
1 of 3
+
2 of 3
+
3 of 3
`, @@ -88,27 +64,15 @@ export const EqualWidth: Story = { export const SettingOneColumnWidth: Story = { render: () => html`
-
-
-
1 of 3
-
-
-
2 of 3 (wider)
-
-
-
3 of 3
-
+
+
1 of 3
+
2 of 3 (wider)
+
3 of 3
-
-
-
1 of 3
-
-
-
2 of 3 (wider)
-
-
-
3 of 3
-
+
+
1 of 3
+
2 of 3 (wider)
+
3 of 3
`, @@ -117,27 +81,15 @@ export const SettingOneColumnWidth: Story = { export const VariableWidthContent: Story = { render: () => html`
-
-
-
1 of 3
-
-
-
Variable width content
-
-
-
3 of 3
-
+
+
1 of 3
+
Variable width content
+
3 of 3
-
-
-
1 of 3
-
-
-
Variable width content
-
-
-
3 of 3
-
+
+
1 of 3
+
Variable width content
+
3 of 3
`, @@ -146,27 +98,15 @@ export const VariableWidthContent: Story = { export const AllBreakpoints: Story = { render: () => html`
-
-
-
col
-
-
-
col
-
-
-
col
-
-
-
col
-
+
+
col
+
col
+
col
+
col
-
-
-
col-8
-
-
-
col-4
-
+
+
col-8
+
col-4
`, @@ -175,24 +115,14 @@ export const AllBreakpoints: Story = { export const StackedToHorizontal: Story = { render: () => html`
-
-
-
col-md-8
-
-
-
col-md-4
-
+
+
col-md-8
+
col-md-4
-
-
-
col-md
-
-
-
col-md
-
-
-
col-md
-
+
+
col-md
+
col-md
+
col-md
`, @@ -202,36 +132,22 @@ export const MixAndMatch: Story = { render: () => html`
-
-
-
.col-md-8
-
-
-
.col-6 .col-md-4
-
+
+
.col-md-8
+
.col-6 .col-md-4
-
-
-
.col-6 .col-md-4
-
-
-
.col-6 .col-md-4
-
-
-
.col-6 .col-md-4
-
+
+
.col-6 .col-md-4
+
.col-6 .col-md-4
+
.col-6 .col-md-4
-
-
-
.col-4
-
-
-
.col-8
-
+
+
.col-4
+
.col-8
`, @@ -240,77 +156,39 @@ export const MixAndMatch: Story = { export const RowColumns: Story = { render: () => html`
-
-
-
Column
-
-
-
Column
-
-
-
Column
-
-
-
Column
-
+
+
Column
+
Column
+
Column
+
Column

-
-
-
Column
-
-
-
Column
-
-
-
Column
-
-
-
Column
-
+
+
Column
+
Column
+
Column
+
Column

-
-
-
Column
-
-
-
Column
-
-
-
Column
-
-
-
Column
-
+
+
Column
+
Column
+
Column
+
Column

-
-
-
Column
-
-
-
Column
-
+
+
Column
+
Column
Column
-
-
Column
-
+
Column

-
-
-
Column
-
-
-
Column
-
-
-
Column
-
-
-
Column
-
+
+
Column
+
Column
+
Column
+
Column
`, @@ -319,19 +197,11 @@ export const RowColumns: Story = { export const Gutters: Story = { render: () => html`
-
-
-
Column
-
-
-
Column
-
-
-
Column
-
-
-
Column
-
+
+
Column
+
Column
+
Column
+
Column
`, @@ -343,10 +213,10 @@ export const Nested: Story = { }, render: () => html`
-
+
Level 1: .col-md-3
-
+
Level 2: .col-8 .col-md-6
Level 2: .col-4 .col-md-6
diff --git a/packages/documentation/src/stories/foundation/layout/grid/grid.styles.scss b/packages/documentation/src/stories/foundation/layout/grid/grid.styles.scss index 8f1ef67556..a002eee884 100644 --- a/packages/documentation/src/stories/foundation/layout/grid/grid.styles.scss +++ b/packages/documentation/src/stories/foundation/layout/grid/grid.styles.scss @@ -1,12 +1,14 @@ @use '@swisspost/design-system-styles/core' as post; +@use '../shared.styles' as *; .grid-example { font-size: post.$font-size-sm; - &.grid-nested-example [class^="col"], - &:not(.grid-nested-example) .my-col-content-style { - padding: 0.75rem; - background-color: lighten(post.$nightblue-bright, 60%); - border: 1px solid lighten(post.$nightblue-dark, 60%); + [class^="col"] { + @include column-styles; + } + + &.grid-nested-example [class^="col"] [class^="col"] { + margin-block: 0.75rem; } } diff --git a/packages/documentation/src/stories/foundation/layout/shared.styles.scss b/packages/documentation/src/stories/foundation/layout/shared.styles.scss new file mode 100644 index 0000000000..ff5483ad74 --- /dev/null +++ b/packages/documentation/src/stories/foundation/layout/shared.styles.scss @@ -0,0 +1,8 @@ +@use '@swisspost/design-system-styles/core' as post; + +@mixin column-styles { + background: linear-gradient(lighten(post.$nightblue-bright, 60%), lighten(post.$nightblue-bright, 60%)), linear-gradient(lighten(post.$nightblue-bright, 65%), lighten(post.$nightblue-bright, 65%)); + background-clip: content-box, border-box; + border: 1px solid lighten(post.$nightblue-dark, 60%); + line-height: 3; +} diff --git a/packages/internet-header/src/components/post-internet-breadcrumbs/post-internet-breadcrumbs.scss b/packages/internet-header/src/components/post-internet-breadcrumbs/post-internet-breadcrumbs.scss index bf667a9588..36fd76e9de 100644 --- a/packages/internet-header/src/components/post-internet-breadcrumbs/post-internet-breadcrumbs.scss +++ b/packages/internet-header/src/components/post-internet-breadcrumbs/post-internet-breadcrumbs.scss @@ -1,6 +1,6 @@ @use '@swisspost/design-system-styles/placeholders/color' as color-ph; @use '@swisspost/design-system-styles/components/button'; -@use '@swisspost/design-system-styles/components/grid'; +@use '@swisspost/design-system-styles/layout'; @use '@swisspost/design-system-styles/components/spinner'; @use '@swisspost/design-system-styles/variables/color'; @use '@swisspost/design-system-styles/functions'; diff --git a/packages/internet-header/src/components/post-internet-footer/post-internet-footer.scss b/packages/internet-header/src/components/post-internet-footer/post-internet-footer.scss index 521dc67631..598d9ec38e 100644 --- a/packages/internet-header/src/components/post-internet-footer/post-internet-footer.scss +++ b/packages/internet-header/src/components/post-internet-footer/post-internet-footer.scss @@ -1,4 +1,4 @@ -@use '@swisspost/design-system-styles/components/grid'; +@use '@swisspost/design-system-styles/layout'; @use '@swisspost/design-system-styles/variables/color'; @use '@swisspost/design-system-styles/placeholders/text'; @use '@swisspost/design-system-styles/placeholders/color' as color-ph; diff --git a/packages/internet-header/src/components/post-search/post-search.scss b/packages/internet-header/src/components/post-search/post-search.scss index 4bf64dd6fe..7d3227f1c1 100644 --- a/packages/internet-header/src/components/post-search/post-search.scss +++ b/packages/internet-header/src/components/post-search/post-search.scss @@ -2,7 +2,7 @@ @use '@swisspost/design-system-styles/variables/color'; @use '@swisspost/design-system-styles/components/forms'; @use '@swisspost/design-system-styles/components/floating-label'; -@use '@swisspost/design-system-styles/components/grid'; +@use '@swisspost/design-system-styles/layout'; @use '../../utils/utils.scss'; @use '../../utils/mixins.scss'; diff --git a/packages/styles/src/basics.scss b/packages/styles/src/basics.scss index b89c93e1f3..b0dbf41c2b 100644 --- a/packages/styles/src/basics.scss +++ b/packages/styles/src/basics.scss @@ -5,4 +5,3 @@ @use 'components/elevation'; @use 'components/sizing'; -@use 'components/grid'; diff --git a/packages/styles/src/components/_index.scss b/packages/styles/src/components/_index.scss index 46f8dcf59c..38f87a637c 100644 --- a/packages/styles/src/components/_index.scss +++ b/packages/styles/src/components/_index.scss @@ -19,7 +19,6 @@ @use 'datatable'; @use 'form-check'; @use 'forms'; -@use 'grid'; @use 'icons'; @use 'lead'; @use 'list-group'; diff --git a/packages/styles/src/components/grid.scss b/packages/styles/src/components/grid.scss deleted file mode 100644 index 7d3a29e3c2..0000000000 --- a/packages/styles/src/components/grid.scss +++ /dev/null @@ -1,170 +0,0 @@ -@forward './../variables/options'; - -@use 'sass:map'; - -@use './../themes/bootstrap/core' as *; -@use './../themes/bootstrap/grid' as bg; -@use './../themes/bootstrap/containers' as bc; - -@use './../variables/commons'; -@use './../variables/spacing'; -@use './../variables/grid'; - -$container-padding-x-cache: 0; -$container-fluid-padding-x-cache: 0; -$gutter-x-cache: 0; - -.container { - padding-inline: var(--post-container-padding-x); -} - -.container-fluid { - padding-inline: var(--post-container-fluid-padding-x); -} - -@each $breakpoint in grid.$grid-breakpoints-list { - $container-padding-x: map.get(grid.$grid-container-padding, $breakpoint); - $container-fluid-padding-x: map.get(grid.$grid-container-fluid-padding, $breakpoint); - $gutter-x: map.get(grid.$grid-gutter-x, $breakpoint); - - @if ($container-padding-x-cache != $container-padding-x) { - .container { - @if $breakpoint == 'xs' { - --post-container-padding-x: #{$container-padding-x}; - } @else { - @include media-breakpoint-up($breakpoint) { - --post-container-padding-x: #{$container-padding-x}; - } - } - } - } - - @if ($container-fluid-padding-x-cache != $container-fluid-padding-x) { - .container-fluid { - @if $breakpoint == 'xs' { - --post-container-fluid-padding-x: #{$container-fluid-padding-x}; - } @else { - @include media-breakpoint-up($breakpoint) { - --post-container-fluid-padding-x: #{$container-fluid-padding-x}; - } - } - } - } - - @if ($gutter-x-cache != $gutter-x) { - .row { - @if $breakpoint == 'xs' { - --bs-gutter-x: #{$gutter-x}; - } @else { - @include media-breakpoint-up($breakpoint) { - --bs-gutter-x: #{$gutter-x}; - } - } - } - } - - $container-padding-x-cache: $container-padding-x; - $container-fluid-padding-x-cache: $container-fluid-padding-x; - $gutter-x-cache: $gutter-x; -} - -// redefine gutter-utilities, to override the custom gutter-width above -@each $infix in grid.$grid-breakpoints-list { - @each $postfix, $gutter in $gutters { - @if $infix == 'xs' { - .g-#{$postfix}, - .gx-#{$postfix} { - --bs-gutter-x: #{$gutter}; - } - } @else { - @include media-breakpoint-up($infix) { - .g-#{$infix}-#{$postfix}, - .gx-#{$infix}-#{$postfix} { - --bs-gutter-x: #{$gutter}; - } - } - } - } -} - -//the following classes are all deprecated and wil be removed in next major version - -//deprecated -.vertical-gutters { - margin-bottom: grid.$grid-gutter-width * -1; - - > .col, - > [class*='col-'] { - padding-bottom: grid.$grid-gutter-width; - } -} - -//deprecated -// border-gutters class is used to manipulate border collapse -.row.border-gutters { - margin-right: -(commons.$border-width); - margin-bottom: -(commons.$border-width); - margin-left: 0; - - > .col, - > [class*='col-'] { - padding-right: commons.$border-width; - padding-bottom: commons.$border-width; - padding-left: 0; - } -} - -//deprecated -$container-cache: 0; - -//deprecated -@each $breakpoint in grid.$grid-breakpoints-list { - $container-padding: map.get(grid.$grid-container-padding, $breakpoint); - - // Ensure this breakpoint is only overwritten when the padding differs from the last breakpoint - @if ($container-cache != $container-padding) { - .container-reset { - @if $breakpoint == 'xs' { - margin-right: -($container-padding); - margin-left: -($container-padding); - } @else { - @include media-breakpoint-up($breakpoint) { - margin-right: -($container-padding); - margin-left: -($container-padding); - } - } - } - - .container-reset-left { - @if $breakpoint== 'xs' { - margin-left: -($container-padding); - } @else { - @include media-breakpoint-up($breakpoint) { - margin-left: -($container-padding); - } - } - } - - .container-reset-right { - @if $breakpoint== 'xs' { - margin-right: -($container-padding); - } @else { - @include media-breakpoint-up($breakpoint) { - margin-right: -($container-padding); - } - } - } - } - - //deprecated - // Container fluid responsive needs to be written every time - .container-fluid-#{$breakpoint} { - @include media-breakpoint-only($breakpoint) { - padding-right: spacing.$spacer; - padding-left: spacing.$spacer; - } - } - - //deprecated - $container-cache: $container-padding; -} diff --git a/packages/styles/src/index.scss b/packages/styles/src/index.scss index fd78bce402..97fa256ba6 100644 --- a/packages/styles/src/index.scss +++ b/packages/styles/src/index.scss @@ -1,5 +1,6 @@ @forward './variables/options'; +@use './layout'; @use './utilities'; @use './elements'; @use './components'; diff --git a/packages/styles/src/intranet.scss b/packages/styles/src/intranet.scss index 5738064522..56feb1c95b 100644 --- a/packages/styles/src/intranet.scss +++ b/packages/styles/src/intranet.scss @@ -1,5 +1,6 @@ @forward './variables/options'; +@use 'layout'; @use 'utilities'; @use 'elements'; @use 'components'; diff --git a/packages/styles/src/layout/_constants.scss b/packages/styles/src/layout/_constants.scss new file mode 100644 index 0000000000..d81a28bb03 --- /dev/null +++ b/packages/styles/src/layout/_constants.scss @@ -0,0 +1,2 @@ +$grid-columns: 12; +$grid-row-columns: 6; diff --git a/packages/styles/src/layout/_mixins.scss b/packages/styles/src/layout/_mixins.scss new file mode 100644 index 0000000000..f8c814538c --- /dev/null +++ b/packages/styles/src/layout/_mixins.scss @@ -0,0 +1,28 @@ +@use 'sass:math'; + +@mixin make-col($size: false, $columns) { + @if $size { + flex: 0 0 auto; + width: math.percentage(math.div($size, $columns)); + } @else { + flex: 1 1 0; + max-width: 100%; + } +} + +@mixin make-col-auto() { + flex: 0 0 auto; + width: auto; +} + +@mixin row-cols($count) { + > * { + flex: 0 0 auto; + width: math.percentage(math.div(1, $count)); + } +} + +@mixin make-col-offset($size, $columns) { + $num: math.div($size, $columns); + margin-left: if($num == 0, 0, math.percentage($num)); +} diff --git a/packages/styles/src/layout/index.scss b/packages/styles/src/layout/index.scss new file mode 100644 index 0000000000..49fb665174 --- /dev/null +++ b/packages/styles/src/layout/index.scss @@ -0,0 +1,79 @@ +@use 'sass:map'; +@use 'sass:math'; + +@use '../functions/tokens'; +@use '../mixins/media'; +@use '../variables/breakpoints'; +@use './temp/tokens' as layout; + +@use './constants' as const; +@use './mixins' as mx; + +tokens.$default-map: layout.$post-grid; + +.container, +.container-fluid { + width: 100%; + padding-inline: tokens.get('grid', 'container-padding-inline'); + margin-inline: auto; +} + +.container { + max-width: tokens.get('grid', 'container-max-width'); +} + +.row { + --post-grid-gutter-x: #{tokens.get('grid', 'gutter')}; + --post-grid-gutter-y: 0; + + display: flex; + flex-wrap: wrap; + margin-block-start: calc(-1 * var(--post-grid-gutter-y)); + margin-inline: calc(-0.5 * var(--post-grid-gutter-x)); + + > * { + flex-shrink: 0; + width: 100%; + max-width: 100%; + margin-block-start: var(--post-grid-gutter-y); + padding-inline: calc(var(--post-grid-gutter-x) * 0.5); + } +} + +@each $breakpoint, $device-size in breakpoints.$grid-breakpoints { + @include media.min($device-size) { + $infix: if($device-size == 0, '', '-#{$breakpoint}'); + + .col#{$infix} { + flex: 1 0 0%; + } + + .row-cols#{$infix}-auto > * { + @include mx.make-col-auto(); + } + + @for $i from 1 through const.$grid-row-columns { + .row-cols#{$infix}-#{$i} { + @include mx.row-cols($i); + } + } + + .col#{$infix}-auto { + @include mx.make-col-auto(); + } + + @for $i from 1 through const.$grid-columns { + .col#{$infix}-#{$i} { + @include mx.make-col($i, const.$grid-columns); + } + } + + @for $i from 0 through (const.$grid-columns - 1) { + @if not($infix == '' and $i == 0) { + .offset#{$infix}-#{$i} { + @include mx.make-col-offset($i, const.$grid-columns); + } + } + } + } +} diff --git a/packages/styles/src/layout/temp/_tokens.scss b/packages/styles/src/layout/temp/_tokens.scss new file mode 100644 index 0000000000..936a1bd3bb --- /dev/null +++ b/packages/styles/src/layout/temp/_tokens.scss @@ -0,0 +1,40 @@ +@use '../../mixins/media'; +@use '../../mixins/tokens'; + +$_post-grid-mobile: ( + post-grid-gutter: 16px, + post-grid-container-max-width: none, + post-grid-container-padding-inline: 16px, +); + +$_post-grid-tablet: ( + post-grid-gutter: 16px, + post-grid-container-max-width: 1280px, + post-grid-container-padding-inline: 24px, +); + +$_post-grid-desktop: ( + post-grid-gutter: 24px, + post-grid-container-max-width: 1280px, + post-grid-container-padding-inline: 40px, +); + +:root { + @include media.max(600px) { + @include tokens.from($_post-grid-mobile); + } + + @include media.between(600px, 1024px) { + @include tokens.from($_post-grid-tablet); + } + + @include media.min(1024px) { + @include tokens.from($_post-grid-desktop); + } +} + +$post-grid: ( + post-grid-gutter: var(--post-grid-gutter), + post-grid-container-max-width: var(--post-grid-container-max-width), + post-grid-container-padding-inline: var(--post-grid-container-padding-inline), +); diff --git a/packages/styles/src/layouts/portal/_grid.scss b/packages/styles/src/layouts/portal/_grid.scss deleted file mode 100644 index 08cec5b241..0000000000 --- a/packages/styles/src/layouts/portal/_grid.scss +++ /dev/null @@ -1,85 +0,0 @@ -@use 'sass:map'; - -@use './../../themes/bootstrap/core' as *; - -@use './../../variables/grid'; -@use './../../variables/commons'; -@use './variables' as portal-variables; - -.container-fluid { - max-width: map.get(grid.$container-max-widths, xs); - padding-right: 0; - padding-left: 0; - - &:not(.allow-overflow) { - overflow: hidden; // hides scrollbar - } -} - -//deprecated -// px-gutters class is used to manipulate border collapse in product-cards -.row.px-gutters { - margin-right: -(commons.$border-width); - margin-bottom: -(commons.$border-width); - margin-left: 0; - - > .col, - > [class*='col-'] { - padding-right: commons.$border-width; - padding-bottom: commons.$border-width; - padding-left: 0; - } -} - -// Overwrites gutter on rg-sized screens and bigger -@include media-breakpoint-up(rg) { - .col, - [class*='col-'] { - padding-right: portal-variables.$grid-gutter-width-rg * 0.5; - padding-left: portal-variables.$grid-gutter-width-rg * 0.5; - } - - .row { - margin-right: -(portal-variables.$grid-gutter-width-rg * 0.5); - margin-left: -(portal-variables.$grid-gutter-width-rg * 0.5); - - &.no-gutters { - margin-right: 0; - margin-left: 0; - } - } - - //deprecated - .vertical-gutters { - margin-bottom: -(portal-variables.$grid-gutter-width-rg); - - > .col, - > [class*='col-'] { - padding-bottom: portal-variables.$grid-gutter-width-rg; - } - } -} - -//deprecated -@each $breakpoint in grid.$grid-breakpoints-list { - .container-fluid-#{$breakpoint} { - @include media-breakpoint-only($breakpoint) { - padding-right: 0; - padding-left: 0; - } - } -} - -//deprecated -.container-reset-right-rg-up { - @include media-breakpoint-up(rg) { - margin-left: 0; - } -} - -//deprecated -.container-reset-left-rg-up { - @include media-breakpoint-up(rg) { - margin-right: 0; - } -} diff --git a/packages/styles/src/layouts/portal/index.scss b/packages/styles/src/layouts/portal/index.scss index 41ae37c888..c067e7178e 100644 --- a/packages/styles/src/layouts/portal/index.scss +++ b/packages/styles/src/layouts/portal/index.scss @@ -1,2 +1 @@ -@use './grid'; @use './subnavigation'; diff --git a/packages/styles/src/post-external.scss b/packages/styles/src/post-external.scss index 87f2a3fa55..9ef9de2f66 100644 --- a/packages/styles/src/post-external.scss +++ b/packages/styles/src/post-external.scss @@ -1,4 +1,5 @@ @use './post-tokens-external'; +@use './layout'; @use './utilities'; @use './elements'; @use './components'; diff --git a/packages/styles/src/post-internal.scss b/packages/styles/src/post-internal.scss index 834c79f621..c0c5820c6c 100644 --- a/packages/styles/src/post-internal.scss +++ b/packages/styles/src/post-internal.scss @@ -1,4 +1,5 @@ @use './post-tokens-internal'; +@use './layout'; @use './utilities'; @use './elements'; @use './components'; diff --git a/packages/styles/src/themes/bootstrap/_containers.scss b/packages/styles/src/themes/bootstrap/_containers.scss deleted file mode 100644 index 2f52471490..0000000000 --- a/packages/styles/src/themes/bootstrap/_containers.scss +++ /dev/null @@ -1,2 +0,0 @@ -@use './core' as *; -@import 'bootstrap/scss/containers'; diff --git a/packages/styles/src/themes/bootstrap/_grid.scss b/packages/styles/src/themes/bootstrap/_grid.scss deleted file mode 100644 index 1581478a7f..0000000000 --- a/packages/styles/src/themes/bootstrap/_grid.scss +++ /dev/null @@ -1,2 +0,0 @@ -@use './core' as *; -@import 'bootstrap/scss/grid'; diff --git a/packages/styles/src/utilities/_variables.scss b/packages/styles/src/utilities/_variables.scss index d7c1bca0e7..68d19e60f3 100644 --- a/packages/styles/src/utilities/_variables.scss +++ b/packages/styles/src/utilities/_variables.scss @@ -78,6 +78,9 @@ $utilities: ( gap: gap, row-gap: row-gap, column-gap: column-gap, + g: --post-grid-gutter-x --post-grid-gutter-y, + gx: --post-grid-gutter-x, + gy: --post-grid-gutter-y, ), ), ), diff --git a/packages/styles/src/variables/components/_stepper.scss b/packages/styles/src/variables/components/_stepper.scss index 7dc24521ad..60bab4b596 100644 --- a/packages/styles/src/variables/components/_stepper.scss +++ b/packages/styles/src/variables/components/_stepper.scss @@ -35,4 +35,3 @@ $stepper-link-color: var(--post-gray-60); $stepper-link-current-color: var(--post-gray-80); $stepper-link-current-font-weight: type.$font-weight-bold; - diff --git a/packages/styles/tests/components/grid.test.scss b/packages/styles/tests/components/grid.test.scss deleted file mode 100644 index 9c7ba9a296..0000000000 --- a/packages/styles/tests/components/grid.test.scss +++ /dev/null @@ -1,7 +0,0 @@ -@use 'sass:map'; -@use 'sass:meta'; -@use 'tests/jest'; -@use 'src/components/grid'; - -// Check if component forwards options -@include jest.true(map.has-key(meta.module-variables('grid'), 'font-base-path'));