diff --git a/.changeset/three-geese-run.md b/.changeset/three-geese-run.md new file mode 100644 index 0000000000..09030b2478 --- /dev/null +++ b/.changeset/three-geese-run.md @@ -0,0 +1,6 @@ +--- +'@swisspost/design-system-documentation': patch +'@swisspost/design-system-styles': patch +--- + +Internalized bootstrap text utilities into the design system. diff --git a/packages/documentation/.storybook/styles/components/typo.scss b/packages/documentation/.storybook/styles/components/typo.scss index 0f6a972b11..b40926d156 100644 --- a/packages/documentation/.storybook/styles/components/typo.scss +++ b/packages/documentation/.storybook/styles/components/typo.scss @@ -33,10 +33,6 @@ body { font-family: tokens.get('body-font-family'); } - .font-sans-serif { - font-family: var(--bs-font-sans-serif) !important; - } - .font-monospace { font-family: var(--bs-font-monospace) !important; } diff --git a/packages/documentation/src/stories/utilities/text/text-color.sample.scss b/packages/documentation/src/stories/utilities/text/text-color.sample.scss deleted file mode 100644 index 9afdd75af0..0000000000 --- a/packages/documentation/src/stories/utilities/text/text-color.sample.scss +++ /dev/null @@ -1,5 +0,0 @@ -@use '@swisspost/design-system-styles/core' as post; - -.my-element { - color: post.$success; -} diff --git a/packages/documentation/src/stories/utilities/text/text-font-size.sample.scss b/packages/documentation/src/stories/utilities/text/text-font-size.sample.scss deleted file mode 100644 index 6593337921..0000000000 --- a/packages/documentation/src/stories/utilities/text/text-font-size.sample.scss +++ /dev/null @@ -1,5 +0,0 @@ -@use '@swisspost/design-system-styles/core' as post; - -.my-element { - font-size: post.$font-size-tiny; -} diff --git a/packages/documentation/src/stories/utilities/text/text.blocks.tsx b/packages/documentation/src/stories/utilities/text/text.blocks.tsx deleted file mode 100644 index 71d6315c27..0000000000 --- a/packages/documentation/src/stories/utilities/text/text.blocks.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import React from 'react'; -import { parse } from '@/utils/sass-export'; -import scss from './text.module.scss'; - -/* eslint-disable-next-line @typescript-eslint/no-explicit-any */ -export const SCSS_VARIABLES: any = parse(scss); - -export const TextUtilityAPI = (props: { - cssPrefix: string; - scssPrefix?: string; - values: string[]; -}) => ( -
-
- {props.cssPrefix && ( - <> -
Class:
-
- {`.${props.cssPrefix}-{value}`} -
- - )} - {props.scssPrefix && ( - <> -
Variable:
-
- {`$${props.scssPrefix}-{value}`} -
- - )} -
Values:
-
- {props.values.map(value => ( - - {value} - - ))} -
-
-
-); diff --git a/packages/documentation/src/stories/utilities/text/text.docs.mdx b/packages/documentation/src/stories/utilities/text/text.docs.mdx index 22dabfe4f2..0b693b3db2 100644 --- a/packages/documentation/src/stories/utilities/text/text.docs.mdx +++ b/packages/documentation/src/stories/utilities/text/text.docs.mdx @@ -1,11 +1,8 @@ import { Canvas, Meta, Source } from '@storybook/blocks'; -import { SCSS_VARIABLES, TextUtilityAPI } from './text.blocks'; import * as TextStories from './text.stories'; import SampleFontFamily from './text-font-family.sample.scss?raw'; -import SampleFontSize from './text-font-size.sample.scss?raw'; import SampleFontWeight from './text-font-weight.sample.scss?raw'; import SampleLineHeight from './text-line-height.sample.scss?raw'; -import SampleColor from './text-color.sample.scss?raw'; import './text.styles.scss'; @@ -20,33 +17,17 @@ import './text.styles.scss'; ### Font Family +Use the class `.font-sans-serif` to set the text as the post sans-serif font-family. + #### Set Font Family in SCSS -#### Possible Values - - - -### Font Size - - - -#### Set Font Size in SCSS - - - -#### Possible Values - - - ### Font Weight -
- The `.bold`, `.regular`, and `.light` classes are deprecated in favor of the `.fw-*` classes. -
+The font weight classes available are `.fw-normal` and `.fw-bold`. @@ -54,21 +35,11 @@ import './text.styles.scss'; -#### Possible Values - - - ### Font Style - - -

- There are no Sass variables for font styles at this time. -

- -#### Possible Values +The font style classes available are `.fst-normal` and `.fst-italic`. - + ### Line Heights @@ -80,33 +51,19 @@ import './text.styles.scss'; #### Possible Values -##### Relative - For good accessibility, the line height is set to 1.5 for body text and 1.2 for headings. -To make the line height equal to the font size, you can use the `.lh-1` class. -There are no Sass variables for these row heights. - +Available classes are: + +- `.lh-1`: line-height equal to the font-size +- `.lh-base`: default line-height +- `.lh-sm`: small line-height of 1.25 +- `.lh-lg`: large line-height of 2 ## Text Define how text-blocks are displayed. -### Color - -Colorize text with `.text-*` utility classes. -To colorize links, use the `.link-*` classes instead as they also provide styling for the `:hover` and `:focus` states. - - - -#### Set the Color in SCSS - - - -#### Possible Values - - - ### Reset Color Reset a text color with `.text-reset`, so that an element inherits the color from its parent. @@ -146,6 +103,6 @@ Transform text with the following text capitalization classes: `.text-lowercase` ### Decorations -Decorate text with the following text decoration classes.: `.text-decoration-line-through` and `.text-decoration-none`. +Decorate text with the following text decoration classes: `text-decoration-underline`, `.text-decoration-line-through` and `.text-decoration-none`. diff --git a/packages/documentation/src/stories/utilities/text/text.module.scss b/packages/documentation/src/stories/utilities/text/text.module.scss deleted file mode 100644 index a25016a868..0000000000 --- a/packages/documentation/src/stories/utilities/text/text.module.scss +++ /dev/null @@ -1,11 +0,0 @@ -@use 'sass:map'; -@use '@swisspost/design-system-styles/core' as post; - -:export { - fontFamilies: [('sans-serif', 'monospace')]; - fontSizes: [map.keys(post.$font-sizes)]; - fontWeights: [('light', 'normal', 'bold')]; - fontStyles: [('normal', 'italic')]; - relativeLineHeights: [('1', 'base', 'sm', 'lg')]; - colors: [map.keys(post.$theme-colors)]; -} diff --git a/packages/documentation/src/stories/utilities/text/text.snapshot.stories.ts b/packages/documentation/src/stories/utilities/text/text.snapshot.stories.ts new file mode 100644 index 0000000000..422295dabb --- /dev/null +++ b/packages/documentation/src/stories/utilities/text/text.snapshot.stories.ts @@ -0,0 +1,108 @@ +import type { StoryObj } from '@storybook/web-components'; +import { html } from 'lit'; +import { schemes } from '@/shared/snapshots/schemes'; +import meta from './text.stories'; +import './text.styles.scss'; + +const { id, ...metaWithoutId } = meta; + +export default { + ...metaWithoutId, + title: 'Snapshots', + decorators: null, +}; + +type Story = StoryObj; + +function getTextUtility(type: string) { + switch (type) { + case 'Family': + return html`

Font sans-serif

`; + case 'Style': + return html` + ${['normal', 'italic'].map( + (val: string) => html`

Font style ${val}

`, + )} + `; + case 'Weight': + return html` + ${['normal', 'bold'].map( + (val: string) => html`

Font weight ${val}

`, + )} + `; + case 'Line height': + return html` + ${['1', 'base', 'sm', 'lg'].map( + (val: string) => html`

Line height ${val}

`, + )} + `; + case 'Text align': + return html` + ${['start', 'end', 'center'].map( + val => html` +
+

Text align ${val}

+
+ `, + )} + `; + case 'Text decoration': + return html` + ${['none', 'underline', 'line-through'].map( + val => html`

Text decoration ${val}

`, + )} + `; + case 'Text transform': + return html` + ${['lowercase', 'uppercase', 'capitalize'].map( + val => html`

Text transform ${val}

`, + )} + `; + case 'White space': + return html` + ${['wrap', 'nowrap'].map( + val => + html` +

+ White space ${val} White space ${val} White space ${val} White space ${val} +

+ `, + )} + `; + case 'Word wrap break': + return html` + ${['break'].map( + val => + html` +

Averylongwordthatwillbreak

+ `, + )} + `; + } +} + +export const Text: Story = { + render: () => { + return schemes( + () => html`
+

Text utilities

+ ${[ + 'Family', + 'Style', + 'Weight', + 'Line height', + 'Text align', + 'Text decoration', + 'Text transform', + 'White space', + 'Word wrap break', + ].map( + val => html` +

${val}

+
${getTextUtility(val)}
+ `, + )} +
`, + ); + }, +}; diff --git a/packages/documentation/src/stories/utilities/text/text.stories.ts b/packages/documentation/src/stories/utilities/text/text.stories.ts index 2499546b8b..3c76bafbb8 100644 --- a/packages/documentation/src/stories/utilities/text/text.stories.ts +++ b/packages/documentation/src/stories/utilities/text/text.stories.ts @@ -18,10 +18,6 @@ export const FontFamily: Story = { render: () => html`

This is sans serif text.

`, }; -export const FontSize: Story = { - render: () => html`

This is tiny text.

`, -}; - export const FontWeight: Story = { render: () => html`

This is bold text.

`, }; @@ -34,18 +30,10 @@ export const LineHeight: Story = { render: () => html`

This text has a line height equal to the font size.

`, }; -export const TextColor: Story = { - decorators: [story => html`
e.preventDefault()}>${story()}
`], - render: () => html` -

This is colored text.

- This is a colored link, it lightens on hover. - `, -}; - export const TextColorReset: Story = { decorators: [story => html`
e.preventDefault()}>${story()}
`], render: () => html` -

+

This is colored text with a link of the same color. @@ -96,6 +84,6 @@ export const TextDecoration: Story = { render: () => html`

This text has a line underneath it.

This text has a line going through it.

- This link has its text decoration removed + This link has its text decoration removed. `, }; diff --git a/packages/documentation/src/stories/utilities/text/text.styles.scss b/packages/documentation/src/stories/utilities/text/text.styles.scss index 509c0b15af..2ff08dd917 100644 --- a/packages/documentation/src/stories/utilities/text/text.styles.scss +++ b/packages/documentation/src/stories/utilities/text/text.styles.scss @@ -3,3 +3,11 @@ .my-container { background-color: post.$info; } + +.text-example-bordered { + border: 1px solid post.$gray-40; +} + +.my-colored-text { + color: post.$error; +} diff --git a/packages/styles/src/themes/bootstrap/_utilities.scss b/packages/styles/src/themes/bootstrap/_utilities.scss index e8d4bde6d1..d39049c3dc 100644 --- a/packages/styles/src/themes/bootstrap/_utilities.scss +++ b/packages/styles/src/themes/bootstrap/_utilities.scss @@ -69,4 +69,15 @@ $utilities: map.remove($utilities, 'overflow'); $utilities: map.remove($utilities, 'overflow-x'); $utilities: map.remove($utilities, 'overflow-y'); +$utilities: map.remove($utilities, 'font-family'); +$utilities: map.remove($utilities, 'font-size'); +$utilities: map.remove($utilities, 'font-style'); +$utilities: map.remove($utilities, 'font-weight'); +$utilities: map.remove($utilities, 'line-height'); +$utilities: map.remove($utilities, 'text-align'); +$utilities: map.remove($utilities, 'text-decoration'); +$utilities: map.remove($utilities, 'text-transform'); +$utilities: map.remove($utilities, 'white-space'); +$utilities: map.remove($utilities, 'word-wrap'); + @import 'bootstrap/scss/utilities/api'; diff --git a/packages/styles/src/utilities/_variables.scss b/packages/styles/src/utilities/_variables.scss index 04b78b2890..dae9454577 100644 --- a/packages/styles/src/utilities/_variables.scss +++ b/packages/styles/src/utilities/_variables.scss @@ -28,6 +28,15 @@ $position-values: ( 100: 100%, ); +$font-family-sans-serif: var(--post-device-font-family-default); + +$font-weight-normal: 400 !default; +$font-weight-bold: 700 !default; + +$line-height-base: 1.5 !default; +$line-height-sm: 1.25 !default; +$line-height-lg: 2 !default; + $utilities: ( 'width': ( responsive: true, @@ -424,5 +433,70 @@ $utilities: ( property: overflow-y, values: auto hidden visible scroll, ), + 'font-family': ( + property: font-family, + class: font, + values: ( + 'sans-serif': $font-family-sans-serif, + ), + ), + 'font-style': ( + property: font-style, + class: fst, + values: italic normal, + ), + 'font-weight': ( + property: font-weight, + class: fw, + values: ( + normal: $font-weight-normal, + bold: $font-weight-bold, + ), + ), + 'line-height': ( + property: line-height, + class: lh, + values: ( + 1: 1, + sm: $line-height-sm, + base: $line-height-base, + lg: $line-height-lg, + ), + ), + 'text-align': ( + responsive: true, + property: text-align, + class: text, + values: ( + start: left, + end: right, + center: center, + ), + ), + 'text-decoration': ( + property: text-decoration, + values: none underline line-through, + ), + 'text-transform': ( + property: text-transform, + class: text, + values: lowercase uppercase capitalize, + ), + 'white-space': ( + property: white-space, + class: text, + values: ( + wrap: normal, + nowrap: nowrap, + ), + ), + 'word-wrap': ( + property: word-wrap word-break, + class: text, + values: ( + break: break-word, + ), + rtl: false, + ), // IMPORTANT: When adding new utilities here, please ensure to remove the corresponding bootstrap utilities in `src/themes/bootstrap/_utilities.scss`. );