-
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.
fix(documentation): Convert fenced code snippet to Source and use dar…
…k theme (#1928) After Storybook 7.4.0, the documentation served (and not build) doesn't display code snippet properly: ![Teams_emZES03vNY](https://github.com/swisspost/design-system/assets/12294151/478903b7-4d3d-4e88-a9a5-dbee57136815) This PR convert fenced code snippet to Source element, officially supported. Most code snippets are available in an external file (one code snippet per file) and imported into the Source element. This PR also set dark theme as default for code snippets (and closes #1677). --------- Co-authored-by: Oliver Schürch <[email protected]>
- Loading branch information
1 parent
bd185a0
commit 823948e
Showing
79 changed files
with
896 additions
and
910 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
25 changes: 25 additions & 0 deletions
25
packages/documentation/src/shared/styles-package-import-individual.sample.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,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}`; | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/documentation/src/shared/styles-package-import.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,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: | ||
|
||
<Source | ||
code={` | ||
@use '@swisspost/design-system-styles/index.scss'; | ||
`} | ||
language="scss" | ||
/> | ||
|
||
To import only the styles required for this component: | ||
|
||
<Source | ||
code={getStylesPackageImportIndividual(props)} | ||
language="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
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
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
Oops, something went wrong.