Skip to content

Commit

Permalink
feat: add semantic layer token machinery (#3349)
Browse files Browse the repository at this point in the history
This PR introduces the core and semantic layer tokens into the styles
package. With this, a couple of new entry files become available as well
as mixins to generate token maps.

New entry files:
```
post-external.scss
post-internal.scss
post-tokens-external.scss
post-tokens-internal.scss
```

New mixins:
```
_media.scss (for min, max, between media queries)
_tokens.scss (for creating token maps from the scss list outputs)
```

- [x] Implementation in documentation is missing due to
pnpm/pnpm#8338
- [x] Use component layer tokens like it's intended

---------

Co-authored-by: Alizé Debray <[email protected]>
  • Loading branch information
gfellerph and alizedebray authored Aug 12, 2024
1 parent 1d2650e commit a767c23
Show file tree
Hide file tree
Showing 19 changed files with 133 additions and 6 deletions.
10 changes: 10 additions & 0 deletions .changeset/large-weeks-tap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
'@swisspost/design-system-styles': minor
---

Added four new entry files that enable working with Design Tokens:

- post-external.(s)css: For portal and other external pages
- post-internal.(s)css: For applications and other internal pages
- post-tokens-external.(s)css: External tokens only
- post-tokens-internal.(s)css: Internal tokens only
3 changes: 1 addition & 2 deletions packages/documentation/.storybook/styles/preview.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// importing the complete styles package scss
// TODO: replace intranet.scss with index.scss as soon as the issues in the portal.scss are fixed
@use '@swisspost/design-system-styles/intranet.scss';
@use '@swisspost/design-system-styles/post-external.scss';
@use '@swisspost/design-system-styles/core.scss' as post;
@use '@swisspost/design-system-styles/mixins/utilities';
@use '@swisspost/internet-header/dist/swisspost-internet-header/swisspost-internet-header.css';
Expand Down
3 changes: 3 additions & 0 deletions packages/styles/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ storybook-static
# Mac OSX Finder files.
**/.DS_Store
.DS_Store

# Temporary files
src/tokens/temp/
20 changes: 16 additions & 4 deletions packages/styles/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ gulp.task('copy', () => {
.pipe(gulp.dest(options.outputDir));
});

/**
* Temporary task to copy token files from tokens package to the styles package since
* pnpm does not correctly install dependencies of dependencies for workspace packages.
* See https://github.com/pnpm/pnpm/issues/8338 for more information and reproduction
*/
gulp.task('temporarily-copy-token-files', () => {
return gulp.src(['../tokens/dist/*.scss']).pipe(gulp.dest('./src/tokens/temp'));
});

/**
* Autoprefix SCSS files
*/
Expand Down Expand Up @@ -168,9 +177,12 @@ gulp.task('sass:tests', () => {
/**
* Watch task for scss development
*/
gulp.task('watch', () => {
return gulp.watch('./src/**/*.scss', gulp.series('copy'));
});
gulp.task(
'watch',
gulp.series('temporarily-copy-token-files', () => {
return gulp.watch('./src/**/*.scss', 'copy');
}),
);

/**
* Run copy and sass task in parallel per default
Expand All @@ -179,7 +191,7 @@ exports.default = gulp.task(
'build',
gulp.parallel(
gulp.series('map-icons', 'copy', 'autoprefixer', 'transform-package-json'),
gulp.series('sass'),
gulp.series('temporarily-copy-token-files', 'sass'),
gulp.series('build-components'),
),
);
1 change: 1 addition & 0 deletions packages/styles/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"bootstrap": "5.3.3"
},
"devDependencies": {
"@swisspost/design-system-tokens": "workspace:*",
"@swisspost/design-system-icons": "workspace:8.1.0",
"@types/node": "20.14.14",
"autoprefixer": "10.4.19",
Expand Down
17 changes: 17 additions & 0 deletions packages/styles/src/mixins/_media.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@mixin min($device-size) {
@media screen and (min-width: $device-size) {
@content;
}
}

@mixin max($device-size) {
@media screen and (max-width: ($device-size - 0.01)) {
@content;
}
}

@mixin between($min-size, $max-size) {
@media screen and (min-width: $min-size) and (max-width: ($max-size - 0.01)) {
@content;
}
}
5 changes: 5 additions & 0 deletions packages/styles/src/mixins/_tokens.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@mixin from($map) {
@each $key, $value in $map {
--#{$key}: #{$value};
}
}
10 changes: 10 additions & 0 deletions packages/styles/src/placeholders/_modes.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@use '../tokens/temp/mode' as mode;
@use './../mixins/tokens';

%color-mode-light {
@include tokens.from(mode.$post-light);
}

%color-mode-dark {
@include tokens.from(mode.$post-dark);
}
2 changes: 2 additions & 0 deletions packages/styles/src/post-external.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@use './post-tokens-external';
@use './components';
2 changes: 2 additions & 0 deletions packages/styles/src/post-internal.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@use './post-tokens-internal';
@use './components';
4 changes: 4 additions & 0 deletions packages/styles/src/post-tokens-external.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@use './tokens/modes';
@use './tokens/device';
@use './tokens/external';
@use './tokens/post-theme';
4 changes: 4 additions & 0 deletions packages/styles/src/post-tokens-internal.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@use './tokens/modes';
@use './tokens/device';
@use './tokens/internal';
@use './tokens/post-theme';
1 change: 1 addition & 0 deletions packages/styles/src/tokens/_core.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@use './temp/core';
19 changes: 19 additions & 0 deletions packages/styles/src/tokens/_device.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
@use './temp/device' as device;

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

:root {
@include media.max(600px) {
@include tokens.from(device.$post-mobile);
}

@include media.between(600px, 1024px) {
@include tokens.from(device.$post-tablet);
}

@include media.min(1024px) {
@include tokens.from(device.$post-desktop);
}
}
8 changes: 8 additions & 0 deletions packages/styles/src/tokens/_external.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@use './temp/channel' as channel;

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

:root {
@include tokens.from(channel.$post-edk);
}
8 changes: 8 additions & 0 deletions packages/styles/src/tokens/_internal.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
@use './temp/channel' as channel;

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

:root {
@include tokens.from(channel.$post-idk);
}
11 changes: 11 additions & 0 deletions packages/styles/src/tokens/_modes.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@use './core';
@use './../placeholders/modes';

:root,
[data-color-mode='light'] {
@extend %color-mode-light;
}

[data-color-mode='dark'] {
@extend %color-mode-dark;
}
8 changes: 8 additions & 0 deletions packages/styles/src/tokens/_post-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-theme);
}
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit a767c23

Please sign in to comment.