diff --git a/packages/documentation/.storybook/preview.ts b/packages/documentation/.storybook/preview.ts index 5b5f7ab405..cbe5eebdea 100644 --- a/packages/documentation/.storybook/preview.ts +++ b/packages/documentation/.storybook/preview.ts @@ -13,6 +13,8 @@ import scss from 'react-syntax-highlighter/dist/esm/languages/prism/scss'; SyntaxHighlighter.registerLanguage('scss', scss); +export const SourceDarkMode = true; + const preview: Preview = { parameters: { options: { @@ -56,6 +58,7 @@ const preview: Preview = { }, source: { excludeDecorators: true, + dark: SourceDarkMode, transform: (snippet: string) => format(snippet, prettierOptions), }, components: resetComponents, diff --git a/packages/documentation/src/shared/styles-package-import-individual.sample.ts b/packages/documentation/src/shared/styles-package-import-individual.sample.ts new file mode 100644 index 0000000000..74e983a968 --- /dev/null +++ b/packages/documentation/src/shared/styles-package-import-individual.sample.ts @@ -0,0 +1,25 @@ +interface Props { + components: string[]; + required?: { icons: boolean; floatingLabel: boolean; formFeedback: boolean }; +} + +const requiredLabels: { [key: string]: string } = { + 'icons': 'required if you use icons', + 'floating-label': 'required if you use floating-labels', + 'form-feedback': 'required if you use validation feedbacks', +}; + +export function getStylesPackageImportIndividual(props: Props) { + const basics = `@use '@swisspost/design-system-styles/basics.scss';`; + const generateComponentLine = (name: string) => + `@use '@swisspost/design-system-styles/components/${name}.scss';`; + const components = props.components.map(generateComponentLine).join('\n'); + + const required = Object.keys(props?.required || {}).reduce( + (acc: string, curr: string) => + `${acc}\n// ${requiredLabels[curr]}\n${generateComponentLine(curr)}`, + '', + ); + + return `${basics}\n${components}\n${required}`; +} diff --git a/packages/documentation/src/shared/styles-package-import.mdx b/packages/documentation/src/shared/styles-package-import.mdx new file mode 100644 index 0000000000..2b03422dc4 --- /dev/null +++ b/packages/documentation/src/shared/styles-package-import.mdx @@ -0,0 +1,20 @@ +import { Source } from '@storybook/blocks'; +import { getStylesPackageImportIndividual } from './styles-package-import-individual.sample'; + +## SCSS Imports + +To import all styles from the design-system-styles package: + + + +To import only the styles required for this component: + + diff --git a/packages/documentation/src/stories/components/alert/alert.docs.mdx b/packages/documentation/src/stories/components/alert/alert.docs.mdx index e037c041aa..571d0a110a 100644 --- a/packages/documentation/src/stories/components/alert/alert.docs.mdx +++ b/packages/documentation/src/stories/components/alert/alert.docs.mdx @@ -1,5 +1,6 @@ import { Canvas, Controls, Meta } from '@storybook/blocks'; import * as AlertStories from './alert.stories'; +import StylesPackageImport from '../../../shared/styles-package-import.mdx'; @@ -16,20 +17,7 @@ By default, alerts are rendered with a contextually appropriate icon. -## SCSS Imports - -To import all styles from the design-system-styles package: - -```scss -@use '@swisspost/design-system-styles/index.scss'; -``` - -To import only the styles required for this component: - -```scss -@use '@swisspost/design-system-styles/basics.scss'; -@use '@swisspost/design-system-styles/components/alert.scss'; -``` + ## Specific examples of application diff --git a/packages/documentation/src/stories/components/badge/badge.docs.mdx b/packages/documentation/src/stories/components/badge/badge.docs.mdx index 92fb95f735..0dd744831d 100644 --- a/packages/documentation/src/stories/components/badge/badge.docs.mdx +++ b/packages/documentation/src/stories/components/badge/badge.docs.mdx @@ -1,5 +1,6 @@ -import { Meta, Canvas, Controls } from '@storybook/blocks'; +import { Canvas, Controls, Meta } from '@storybook/blocks'; import * as badgeStories from './badge.stories'; +import StylesPackageImport from '../../../shared/styles-package-import.mdx'; @@ -14,20 +15,7 @@ import * as badgeStories from './badge.stories'; -## SCSS Imports - -To import all styles from the design-system-styles package: - -```scss -@use '@swisspost/design-system-styles/index.scss'; -``` - -To import only the styles required for this component: - -```scss -@use '@swisspost/design-system-styles/basics.scss'; -@use '@swisspost/design-system-styles/components/badge.scss'; -``` + ## Examples diff --git a/packages/documentation/src/stories/components/blockquote/blockquote.docs.mdx b/packages/documentation/src/stories/components/blockquote/blockquote.docs.mdx index 7a32ef7d88..bb51e8707e 100644 --- a/packages/documentation/src/stories/components/blockquote/blockquote.docs.mdx +++ b/packages/documentation/src/stories/components/blockquote/blockquote.docs.mdx @@ -1,13 +1,15 @@ -import { Meta, Canvas, Controls } from '@storybook/blocks'; +import { Canvas, Controls, Meta } from '@storybook/blocks'; import * as BlockquoteStories from './blockquote.stories.ts'; +import StylesPackageImport from '../../../shared/styles-package-import.mdx'; # Blockquote
- For quoting blocks of content from another source within your document. Wrap `
` around any HTML as the quote. + For quoting blocks of content from another source within your document. Wrap ` +
` around any HTML as the quote.
@@ -16,20 +18,7 @@ import * as BlockquoteStories from './blockquote.stories.ts'; -## SCSS Imports - -To import all styles from the design-system-styles package: - -```scss -@use '@swisspost/design-system-styles/index.scss'; -``` - -To import only the styles required for this component: - -```scss -@use '@swisspost/design-system-styles/basics.scss'; -@use '@swisspost/design-system-styles/components/blockquote.scss'; -``` + ## Concrete Examples of Application @@ -37,6 +26,7 @@ The following examples show the different characteristics of the component. Thes ### Nested -To add simple quote characters around any nested text within your blockquote, you can wrap it with a <q> tag. +To add simple quote characters around any nested text within your blockquote, you can wrap it with a +<q> tag. diff --git a/packages/documentation/src/stories/components/button-group/button-group.docs.mdx b/packages/documentation/src/stories/components/button-group/button-group.docs.mdx index fce158e002..9387e0206f 100644 --- a/packages/documentation/src/stories/components/button-group/button-group.docs.mdx +++ b/packages/documentation/src/stories/components/button-group/button-group.docs.mdx @@ -1,5 +1,6 @@ import { Canvas, Controls, Meta } from '@storybook/blocks'; import * as ButtonGroupStories from './button-group.stories'; +import StylesPackageImport from '../../../shared/styles-package-import.mdx'; @@ -14,20 +15,7 @@ import * as ButtonGroupStories from './button-group.stories'; -## SCSS Imports - -To import all styles from the design-system-styles package: - -```scss -@use '@swisspost/design-system-styles/index.scss'; -``` - -To import only the styles required for this component: - -```scss -@use '@swisspost/design-system-styles/basics.scss'; -@use '@swisspost/design-system-styles/components/badge.scss'; -``` + ## Concrete Examples of Application diff --git a/packages/documentation/src/stories/components/button/button.docs.mdx b/packages/documentation/src/stories/components/button/button.docs.mdx index 613d91d1ee..e146b17c05 100644 --- a/packages/documentation/src/stories/components/button/button.docs.mdx +++ b/packages/documentation/src/stories/components/button/button.docs.mdx @@ -1,6 +1,7 @@ -import { Meta, Canvas, Controls } from '@storybook/blocks'; +import { Canvas, Controls, Meta } from '@storybook/blocks'; import LinkTo from '@storybook/addon-links/react'; import * as ButtonStories from './button.stories'; +import StylesPackageImport from '../../../shared/styles-package-import.mdx'; @@ -16,23 +17,7 @@ import * as ButtonStories from './button.stories'; -## SCSS Imports - -To import all styles from the design-system-styles package: - -```scss -@use '@swisspost/design-system-styles/index.scss'; -``` - -To import only the styles required for this component: - -```scss -@use '@swisspost/design-system-styles/basics.scss'; -@use '@swisspost/design-system-styles/components/button.scss'; - -// required if you use icons -@use '@swisspost/design-system-styles/components/icons.scss'; -``` + ## Concrete Examples of Application @@ -40,7 +25,9 @@ The following examples show the different characteristics of the component. Thes ### Inverted -Inverted buttons don't need special classes anymore, just use any of the background classes to set the background and you're done for the day. +Inverted buttons don't need special classes anymore, just use any of the +background + classes to set the background and you're done for the day. diff --git a/packages/documentation/src/stories/components/card/card.docs.mdx b/packages/documentation/src/stories/components/card/card.docs.mdx index 3a4283b0c3..67ad1b5c3a 100644 --- a/packages/documentation/src/stories/components/card/card.docs.mdx +++ b/packages/documentation/src/stories/components/card/card.docs.mdx @@ -1,6 +1,7 @@ -import { Meta, Canvas, Controls } from '@storybook/blocks'; -import LinkTo from '@storybook/addon-links/react'; +import { Canvas, Controls, Meta } from '@storybook/blocks'; import * as CardStories from './card.stories'; +import StylesPackageImport from '../../../shared/styles-package-import.mdx'; +import LinkTo from '@storybook/addon-links/react'; @@ -14,27 +15,15 @@ Built with flexbox, they offer easy alignment and mix well with other components They have no fixed width to start, so they’ll naturally fill the full width of its parent element. This is easily customizable using the grid for example, -for more details read our layout docs. +for more details read our +layout docs. - +
-## SCSS Imports - -To import all styles from the design-system-styles package: - -```scss -@use '@swisspost/design-system-styles/index.scss'; -``` - -To import only the styles required for this component: - -```scss -@use '@swisspost/design-system-styles/basics.scss'; -@use '@swisspost/design-system-styles/components/card.scss'; -``` + ## Examples @@ -60,7 +49,8 @@ Use card groups to render cards as a single, attached element with equal width a ### Bad example
- Never use text with a background image because you can't ensure it is readable by everyone for all languages and browser sizes. + Never use text with a background image because you can't ensure it is readable by everyone for all languages and + browser sizes.
diff --git a/packages/documentation/src/stories/components/checkbox/checkbox.docs.mdx b/packages/documentation/src/stories/components/checkbox/checkbox.docs.mdx index f5bb6aed38..4b57853df7 100644 --- a/packages/documentation/src/stories/components/checkbox/checkbox.docs.mdx +++ b/packages/documentation/src/stories/components/checkbox/checkbox.docs.mdx @@ -1,6 +1,7 @@ -import { Meta, Canvas, Controls } from '@storybook/blocks'; +import { Canvas, Controls, Meta, Source } from '@storybook/blocks'; import LinkTo from '@storybook/addon-links/react'; import * as checkboxStories from './checkbox.stories'; +import StylesPackageImport from '../../../shared/styles-package-import.mdx'; @@ -17,23 +18,7 @@ Our checkboxes use custom icons to indicate checked or indeterminate states. -## SCSS Imports - -To import all styles from the design-system-styles package: - -```css -@use '@swisspost/design-system-styles/index.scss'; -``` - -To import only the styles required for this component: - -```css -@use '@swisspost/design-system-styles/basics.scss'; -@use '@swisspost/design-system-styles/components/form-check.scss'; - -// required if you use validation feedbacks -@use '@swisspost/design-system-styles/components/form-feedback.scss'; -``` + ## Examples @@ -53,9 +38,10 @@ visit [Accessible Web Designs indeterminate checkbox](http://www.barrierefreies- The indeterminate state can only be set via JavaScript and is styled using the `:indeterminate` pseudo-class. -```javascript -document.querySelector('input[type="checkbox"]').indeterminate = true; -``` + ### Inline diff --git a/packages/documentation/src/stories/components/choice-card/checkbox-card.docs.mdx b/packages/documentation/src/stories/components/choice-card/checkbox-card.docs.mdx index e5c009f011..0e7fa6d090 100644 --- a/packages/documentation/src/stories/components/choice-card/checkbox-card.docs.mdx +++ b/packages/documentation/src/stories/components/choice-card/checkbox-card.docs.mdx @@ -1,5 +1,6 @@ -import { Meta, Canvas, Controls } from '@storybook/blocks'; +import { Canvas, Controls, Meta } from '@storybook/blocks'; import * as CheckboxCardStories from './checkbox-card.stories'; +import StylesPackageImport from '../../../shared/styles-package-import.mdx'; @@ -13,8 +14,8 @@ import * as CheckboxCardStories from './checkbox-card.stories';

Firefox fallback classes

Firefox currently does not support - the new CSS :has pseudo-selector - . As a fallback, the following states have to be mirrored on the top level element in the form + the new CSS :has pseudo-selector +. As a fallback, the following states have to be mirrored on the top level element in the form of classes:
  • @@ -47,17 +48,4 @@ Checkbox cards can be grouped together. Use a `fieldset`/`legend` combination to
-## SCSS Imports - -To import all styles from the design-system-styles package: - -```scss -@use '@swisspost/design-system-styles/index.scss'; -``` - -To import only the styles required for this component: - -```scss -@use '@swisspost/design-system-styles/basics.scss'; -@use '@swisspost/design-system-styles/components/choice-control-card.scss'; -``` + diff --git a/packages/documentation/src/stories/components/choice-card/radiobutton-card.docs.mdx b/packages/documentation/src/stories/components/choice-card/radiobutton-card.docs.mdx index 6d9a0e93c3..ef12565fe6 100644 --- a/packages/documentation/src/stories/components/choice-card/radiobutton-card.docs.mdx +++ b/packages/documentation/src/stories/components/choice-card/radiobutton-card.docs.mdx @@ -1,5 +1,6 @@ -import { Meta, Canvas, Controls } from '@storybook/blocks'; +import { Canvas, Controls, Meta } from '@storybook/blocks'; import * as RadiobuttonCardStories from './radiobutton-card.stories'; +import StylesPackageImport from '../../../shared/styles-package-import.mdx'; @@ -13,8 +14,8 @@ import * as RadiobuttonCardStories from './radiobutton-card.stories';

Firefox fallback classes

Firefox currently does not support - the new CSS :has pseudo-selector - . As a fallback, the following states have to be mirrored on the top level element in the form + the new CSS :has pseudo-selector +. As a fallback, the following states have to be mirrored on the top level element in the form of classes:
  • @@ -47,17 +48,4 @@ Radiobutton cards can be grouped together. Use a `fieldset`/`legend` combination
-## SCSS Imports - -To import all styles from the design-system-styles package: - -```scss -@use '@swisspost/design-system-styles/index.scss'; -``` - -To import only the styles required for this component: - -```scss -@use '@swisspost/design-system-styles/basics.scss'; -@use '@swisspost/design-system-styles/components/choice-control-card.scss'; -``` + diff --git a/packages/documentation/src/stories/components/collapsible/collapsible-custom-trigger.sample.ts b/packages/documentation/src/stories/components/collapsible/collapsible-custom-trigger.sample.ts new file mode 100644 index 0000000000..dfa6e16e3d --- /dev/null +++ b/packages/documentation/src/stories/components/collapsible/collapsible-custom-trigger.sample.ts @@ -0,0 +1,2 @@ +const collapsible = document.querySelector('#collapsibleId') as HTMLPostCollapsibleElement; +collapsible.toggle(/* open: boolean */).then((/* isOpen: boolean */) => {}); diff --git a/packages/documentation/src/stories/components/collapsible/collapsible.docs.mdx b/packages/documentation/src/stories/components/collapsible/collapsible.docs.mdx index ee036ee7cb..56f2ded42d 100644 --- a/packages/documentation/src/stories/components/collapsible/collapsible.docs.mdx +++ b/packages/documentation/src/stories/components/collapsible/collapsible.docs.mdx @@ -1,5 +1,6 @@ -import { Canvas, Controls, Meta } from '@storybook/blocks'; +import { Canvas, Controls, Meta, Source } from '@storybook/blocks'; import * as CollapsibleStories from './collapsible.stories'; +import SampleCustomTrigger from './collapsible-custom-trigger.sample?raw'; @@ -44,10 +45,11 @@ The `` component exposes a `.toggle()` method that allows to t This method is asynchronous and returns a promise that resolves with the current open state. It optionally takes a boolean parameter that forces open when `true` or close when `false`. -```typescript -const collapsible = document.querySelector('#collapsibleId') as HTMLPostCollapsibleElement; -collapsible.toggle(/* open: boolean */).then((/* isOpen: boolean */) => {}); -``` + + A header is then not mandatory and can be replaced by an external control. diff --git a/packages/documentation/src/stories/components/collapsible/collapsible.snapshot.stories.tsx b/packages/documentation/src/stories/components/collapsible/collapsible.snapshot.stories.ts similarity index 100% rename from packages/documentation/src/stories/components/collapsible/collapsible.snapshot.stories.tsx rename to packages/documentation/src/stories/components/collapsible/collapsible.snapshot.stories.ts diff --git a/packages/documentation/src/stories/components/heading/heading.docs.mdx b/packages/documentation/src/stories/components/heading/heading.docs.mdx index 0f901b96d2..bcb6b2cdb7 100644 --- a/packages/documentation/src/stories/components/heading/heading.docs.mdx +++ b/packages/documentation/src/stories/components/heading/heading.docs.mdx @@ -1,6 +1,7 @@ -import { Meta, Canvas, Controls } from '@storybook/blocks'; -import LinkTo from '@storybook/addon-links/react'; +import { Canvas, Controls, Meta } from '@storybook/blocks'; import * as HeadingStories from './heading.stories'; +import StylesPackageImport from '../../../shared/styles-package-import.mdx'; +import LinkTo from '@storybook/addon-links/react'; @@ -12,24 +13,13 @@ import * as HeadingStories from './heading.stories'; All HTML headings are available, from `h1` the highest section level to `h6` the lowest.
If you need to match the font styling of a heading but cannot use the associated HTML element, -check out heading utilities. +check out +heading utilities.
-## SCSS Imports - -To import all styles from the design-system-styles package: - -```css dark -@use '@swisspost/design-system-styles/index.scss'; -``` - -To import only the styles required for this component: + -```css dark -@use '@swisspost/design-system-styles/basics.scss'; -@use '@swisspost/design-system-styles/components/type.scss'; -``` diff --git a/packages/documentation/src/stories/components/input/input.docs.mdx b/packages/documentation/src/stories/components/input/input.docs.mdx index f16f22f279..1610f2ca25 100644 --- a/packages/documentation/src/stories/components/input/input.docs.mdx +++ b/packages/documentation/src/stories/components/input/input.docs.mdx @@ -1,5 +1,6 @@ import { Canvas, Controls, Meta } from '@storybook/blocks'; import * as InputStories from './input.stories'; +import StylesPackageImport from '../../../shared/styles-package-import.mdx'; @@ -17,26 +18,7 @@ Custom input elements need only the class `.form-control` to trigger the custom -## SCSS Imports - -To import all styles from the design-system-styles package: - -```scss -@use '@swisspost/design-system-styles/index.scss'; -``` - -To import only the styles required for this component: - -```scss -@use '@swisspost/design-system-styles/basics.scss'; -@use '@swisspost/design-system-styles/components/forms.scss'; - -// required if you use floating-labels -@use '@swisspost/design-system-styles/components/floating-label.scss'; - -// required if you use validation feedbacks -@use '@swisspost/design-system-styles/components/form-feedback.scss'; -``` + ## Concrete Examples of Application @@ -47,7 +29,7 @@ The following examples show the different characteristics of the component. Thes Wrap a pair of `` and `