Skip to content

Commit

Permalink
feat(docs): add cargo theme (#3993)
Browse files Browse the repository at this point in the history
This PR add style indexes for Cargo internal and external and allows to
use them in the documentation.
  • Loading branch information
alizedebray authored Nov 21, 2024
1 parent bcbd698 commit 3a1aa74
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 17 deletions.
6 changes: 6 additions & 0 deletions .changeset/khaki-cougars-itch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@swisspost/design-system-styles': minor
'@swisspost/design-system-documentation': minor
---

Addes Cargo theme styles.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react';
import { IconButton, WithTooltip } from '@storybook/components';

const THEMES = ['Post'] as const;
const THEMES = ['Post', 'Cargo'] as const;
const CHANNELS = ['External', 'Internal'] as const;
const SCHEMES = ['Light', 'Dark'] as const;

Expand All @@ -15,18 +15,6 @@ const possibleStylesheets = THEMES.flatMap(theme => {
return CHANNELS.map(channel => getStylesheetUrl(theme, channel));
});

/*
* Backgrounds
*/
const backgroundClasses: { [key in (typeof SCHEMES)[number]]: string } = {
Light: 'bg-white',
Dark: 'bg-dark',
};
const getBackgroundClass = (scheme: string) => {
return scheme in backgroundClasses ? backgroundClasses[scheme] : '';
};
const possibleBackgrounds = SCHEMES.map(scheme => getBackgroundClass(scheme));

/*
* Local storage access
*/
Expand Down Expand Up @@ -113,9 +101,8 @@ function StylesSwitcher() {
if (!stories) return;

stories.forEach(story => {
story.classList.remove(...possibleBackgrounds);
story.classList.add(getBackgroundClass(currentScheme));
story.setAttribute('data-color-scheme', currentScheme.toLowerCase());
if (!story.classList.contains('palette-default')) story.classList.add('palette-default');
});
}, [stories, currentScheme]);

Expand Down
2 changes: 2 additions & 0 deletions packages/documentation/.storybook/styles/preview.scss
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ $monospace: SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier

#storybook-root,
#storybook-docs {
background-color: white;

.sbdocs-content .container >,
.sbdocs-content .container > post-tabs > post-tab-panel >,
.sbdocs-content .container > migration-global-state {
Expand Down
7 changes: 7 additions & 0 deletions packages/styles/src/cargo-external.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@use './tokens/schemes';
@use './tokens/device';
@use './tokens/external';
@use './tokens/cargo-theme';
@use './utilities';
@use './elements';
@use './components';
7 changes: 7 additions & 0 deletions packages/styles/src/cargo-internal.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@use './tokens/schemes';
@use './tokens/device';
@use './tokens/internal';
@use './tokens/cargo-theme';
@use './utilities';
@use './elements';
@use './components';
8 changes: 8 additions & 0 deletions packages/styles/src/cargo-tokens-external.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@use 'sass:meta';

@layer design-system {
@include meta.load-css('./tokens/schemes');
@include meta.load-css('./tokens/device');
@include meta.load-css('./tokens/external');
@include meta.load-css('./tokens/cargo-theme');
}
8 changes: 8 additions & 0 deletions packages/styles/src/cargo-tokens-internal.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@use 'sass:meta';

@layer design-system {
@include meta.load-css('./tokens/schemes');
@include meta.load-css('./tokens/device');
@include meta.load-css('./tokens/internal');
@include meta.load-css('./tokens/cargo-theme');
}
5 changes: 4 additions & 1 deletion packages/styles/src/post-external.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@use './post-tokens-external';
@use './tokens/schemes';
@use './tokens/device';
@use './tokens/external';
@use './tokens/post-theme';
@use './utilities';
@use './elements';
@use './components';
5 changes: 4 additions & 1 deletion packages/styles/src/post-internal.scss
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
@use './post-tokens-internal';
@use './tokens/schemes';
@use './tokens/device';
@use './tokens/internal';
@use './tokens/post-theme';
@use './utilities';
@use './elements';
@use './components';
8 changes: 8 additions & 0 deletions packages/styles/src/tokens/_cargo-theme.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@use './temp/theme' as themes;

@use './core';
@use './../mixins/tokens';

:root {
@include tokens.from(themes.$post-cargo);
}

0 comments on commit 3a1aa74

Please sign in to comment.