Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: Provide combined CSS output file for distribution #375

Merged
merged 27 commits into from
Sep 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a1365e7
Use root selector and remove media queries
adrianbruntonsagecom Sep 13, 2024
2b3d3f8
Allow testing typescript unit tests via mocha
adrianbruntonsagecom Sep 13, 2024
f6733cb
Add CSS parser
adrianbruntonsagecom Sep 13, 2024
520f5c2
Rename directory & output all.css
adrianbruntonsagecom Sep 16, 2024
796b878
Add brand tokens toString function
adrianbruntonsagecom Sep 16, 2024
c949453
Rename parameter
adrianbruntonsagecom Sep 16, 2024
a0cff0c
Conditionally add empty line
adrianbruntonsagecom Sep 16, 2024
2cc8d2d
Refactor
adrianbruntonsagecom Sep 16, 2024
80d57ee
Add ConsolidateScreenSizes formatter
adrianbruntonsagecom Sep 16, 2024
65db527
Exclude node_modules
adrianbruntonsagecom Sep 16, 2024
8f3c440
Add comment
adrianbruntonsagecom Sep 16, 2024
b40e8fc
Include comments
adrianbruntonsagecom Sep 16, 2024
aba326c
Add light dark mode formatter
adrianbruntonsagecom Sep 16, 2024
7321538
Merge branch 'beta' into SDSWC-53-combined-css-output
adrianbruntonsagecom Sep 16, 2024
02cce65
Add validate workflow
adrianbruntonsagecom Sep 16, 2024
8cb29a1
Add docs
adrianbruntonsagecom Sep 17, 2024
cea112e
Add default system button class
adrianbruntonsagecom Sep 17, 2024
95aad2f
Remove wildcard
adrianbruntonsagecom Sep 17, 2024
02d4103
Reference postcss
adrianbruntonsagecom Sep 17, 2024
015c318
Fix typo
adrianbruntonsagecom Sep 17, 2024
64821b5
Allow allowUnreachableCode
adrianbruntonsagecom Sep 19, 2024
a4eee62
Parse --breakpoint-min-width
adrianbruntonsagecom Sep 19, 2024
486cb6b
Prevent duplicate tokens in the same file
adrianbruntonsagecom Sep 19, 2024
f4bf4b2
Format files
adrianbruntonsagecom Sep 19, 2024
b988be7
Improve scalability to allow more than two screen sizes
adrianbruntonsagecom Sep 19, 2024
4b280c3
feat(data): adding screensize dependant breakpoint-min-width token
druhill Sep 19, 2024
26e9427
Fix breakpoint name
adrianbruntonsagecom Sep 19, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Validate
on:
pull_request:
branches:
- master
- beta
jobs:
run-unit-tests:
name: Run unit tests
runs-on: ubuntu-latest

steps:
- name: Check out Git repository
uses: actions/checkout@v4

- uses: actions/setup-node@v4
with:
node-version: "20"

- name: Install
run: yarn install --frozen-lockfile

- name: Run tests
run: npm test
10 changes: 10 additions & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module.exports = {
parallel: true,
recursive: true,
require: ["tsx"],
spec: [
"scripts/**/*.spec.ts"
],
extension: ['js', 'cjs', 'mjs', 'ts']
};

30 changes: 0 additions & 30 deletions data/tokens/global/size.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,6 @@
"value": "{primitives.dimension.0}",
"type": "sizing"
},
"breakpoint": {
"none": {
"value": "{primitives.size.breakpoint.0}",
"type": "sizing"
},
"XXS": {
"value": "{primitives.size.breakpoint.320}",
"type": "sizing"
},
"XS": {
"value": "{primitives.size.breakpoint.480}",
"type": "sizing"
},
"S": {
"value": "{primitives.size.breakpoint.768}",
"type": "sizing"
},
"M": {
"value": "{primitives.size.breakpoint.1024}",
"type": "sizing"
},
"L": {
"value": "{primitives.size.breakpoint.1200}",
"type": "sizing"
},
"XL": {
"value": "{primitives.size.breakpoint.1920}",
"type": "sizing"
}
},
"container": {
"M": {
"value": "{primitives.dimension.3600}",
Expand Down
6 changes: 6 additions & 0 deletions data/tokens/screensize/large.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"global": {
"size": {
"breakpoint-min-width": {
"value": "{primitives.size.breakpoint.1200}",
"type": "sizing"
}
},
"space": {
"macroScale": {
"value": "1",
Expand Down
6 changes: 6 additions & 0 deletions data/tokens/screensize/small.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"global": {
"size": {
"breakpoint-min-width": {
"value": "{primitives.size.breakpoint.0}",
"type": "sizing"
}
},
"space": {
"macroScale": {
"value": "0.8",
Expand Down
23 changes: 23 additions & 0 deletions docs/usage/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Usage
The tokens are distributed in a number of different formats:
- android
- css
- ios
- js
- json
- scss

There is also an assets directory distributed for any physical files that are common across any of the above formats.

Most of these formats distribute tokens exactly as provided to the build process and can therefore be used by consuming tools and processes accordingly. Any exceptions to this are listed below.

## CSS
Due to the nature of CSS and the requirement for browsers to consume styles directly an additional all.css file has been exposed in addition to the standard files provided that match other formats. This all.css file provides the following features:

- Media query for large screen tokens
- Consolidation to remove any large screen tokens which are included and unchanged in the default small screen token set
- Formatter to rename light/dark mode token to add a suffix and include the light-dark function where ever used. This will allow consumers to switch to light/dark mode (or device specified) on a page or section level using the [`color-scheme`](https://web.dev/articles/light-dark) css property.

See the associated index.html files provided in each of the distributed brand directories for examples over how these tokens may be consumed.

NOTE: Whilst there is good browser support for the [light-dark function](https://caniuse.com/?search=light-dark), you may want to use the [`postcss-preset-env`](https://www.npmjs.com/package/postcss-preset-env) postcss plugin alongside a [`.browserslistrc`](https://github.com/browserslist/browserslist) file to enhance support to the browsers required.
137 changes: 137 additions & 0 deletions docs/usage/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="./all.css" />

<!-- Component library styles -->
<style>
body {
font: var(--page-typography-p-standard);
background: var(--page-color-standard-bg-default);
color: var(--page-color-standard-text-default);
}

p {
font: var(--page-typography-p-standard);
}

h1 {
font: var(--page-typography-h1);
}

h2 {
font: var(--page-typography-h2);
}

button {
background: var(--button-color-standard-typical-primary-bg-enabled);
padding: var(--button-space-primary-y-m) var(--button-space-primary-x-m);
gap: var(--button-space-primary-xg-m);
border-radius: var(--button-radius-primary-m);
border: none;
color: var(--button-color-standard-destructive-primary-label-enabled);
font: var(--button-typography-adaptive-primary-m);
cursor: pointer;

&.active {
background: var(--button-color-standard-typical-primary-bg-active);
color: var(--button-color-standard-typical-primary-label-active);
}
}

section {
background: var(--container-color-standard-interactive-bg-enabled);
border-radius: var(--container-radius-card-moderate);
box-shadow: var(--container-boxshadow-card-enabled);
padding: var(--container-space-generic-content-y-l)
var(--container-space-generic-content-x-l);

&.inverted {
background: var(--container-color-inverse-bg-default);

button {
background: var(--button-color-inverse-typical-primary-bg-enabled);
color: var(--button-color-inverse-typical-primary-label-enabled);
}
}
}
</style>

<!-- Application styles -->
<style>
body {
color-scheme: light dark; /* Device preference by default */
}

.mode-light,
.mode-dark {
background: var(--page-color-standard-bg-default);
color: var(--page-color-standard-text-default);
}

.mode-light {
color-scheme: only light;
}

.mode-dark {
color-scheme: only dark;
}

section {
+ section {
margin-top: var(--page-space-y-l);
}
}

.inverted {
color: var(--page-color-inverse-text-default);
}
</style>

<script type="text/javascript">
function setMode(event, mode) {
const target = event.target;

document.querySelectorAll("button").forEach((button) => {
button.classList.remove("active");
});
target.classList.add("active");

document.body.classList.remove("mode-system");
document.body.classList.remove("mode-light");
document.body.classList.remove("mode-dark");
document.body.classList.add(mode);
}
</script>
</head>
<body>
<h1>Light/dark mode demonstration</h1>
<section>
<h2>User selection</h2>
<p>This section will change based on user preference.</p>
<button onclick="setMode(event, 'mode-system')" class="active">
System
</button>
<button onclick="setMode(event, 'mode-light')">Light</button>
<button onclick="setMode(event, 'mode-dark')">Dark</button>
</section>

<section class="mode-dark">
<h2>Always dark</h2>
<p>This section will always be dark.</p>
<button>Button</button>
</section>

<section class="mode-light">
<h2>Always light</h2>
<p>This section will always be light.</p>
<button>Button</button>
</section>

<section class="inverted">
<h2>Always inverted</h2>
<p>This section will always be inverted.</p>
<button>Button</button>
</section>
</body>
</html>
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@
"design system"
],
"scripts": {
"build": "node ./scripts/build.js",
"test": "mocha",
"test:watch": "npm test -- --watch",
"build": "node ./scripts/build.js && npm run post-process-css",
"prebuild": "node ./scripts/prebuild.js",
"postbuild": "node ./scripts/postbuild.js",
"post-process-css": "npx ts-node ./scripts/post-process-css",
"dev:docs": "nodemon --watch \"./scripts/*\" --watch \"./templates/**/*\" --exec \"node ./scripts/tokens-documentation.js\"",
"prepublishOnly": "node ./scripts/bump-main-package-version.js",
"lint": "eslint .",
Expand All @@ -37,7 +40,11 @@
"@semantic-release/npm": "^11.0.2",
"@semantic-release/release-notes-generator": "^12.1.0",
"@tokens-studio/sd-transforms": "^0.12.2",
"@tsconfig/strictest": "^2.0.5",
"@types/chai": "^4.3.19",
"@types/glob": "^8.1.0",
"@types/mocha": "^10.0.8",
"chai": "^5.1.1",
"dotenv": "^16.3.1",
"eslint": "^8.56.0",
"eslint-config-standard": "^17.1.0",
Expand All @@ -51,6 +58,7 @@
"glob": "^10.3.10",
"less": "^4.2.0",
"lodash": "^4.17.21",
"mocha": "^10.7.3",
"node-fetch": "^2.7.0",
"nodemon": "^3.0.2",
"scss": "^0.2.4",
Expand All @@ -59,6 +67,8 @@
"stylelint-config-standard": "^36.0.1",
"stylelint-config-standard-scss": "^13.1.0",
"tinycolor2": "^1.6.0",
"ts-node": "^10.9.2",
"tsx": "^4.19.1",
"typescript": "^5.3.3"
}
}
Loading
Loading