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

Semantic-Tokens: Generate from token JSON export #33931

Draft
wants to merge 37 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
7a48bb0
Stash initial for now
Mitch-At-Work Feb 11, 2025
13424bc
Add initial Link tokens as example
Mitch-At-Work Feb 12, 2025
5badbf8
Add tsconfig for semantic-tokens
Mitch-At-Work Feb 12, 2025
36cc985
Update indexing and add token vars as exports
Mitch-At-Work Feb 14, 2025
88cc6f4
Change files
Mitch-At-Work Feb 18, 2025
6b008bd
Fix version of react-tokens
Mitch-At-Work Feb 18, 2025
8dba624
Update and connect local build artifacts
Mitch-At-Work Feb 18, 2025
4a8db31
Lint and fix exports
Mitch-At-Work Feb 19, 2025
e2aa7f2
Update E2E for semantic tokens to a dummy test (for now)
Mitch-At-Work Feb 20, 2025
96ef49f
Fix up extra bracket and brand ref color
Mitch-At-Work Feb 20, 2025
1d6d672
remove console
Mitch-At-Work Feb 21, 2025
f478839
Alphebetize order
Mitch-At-Work Feb 24, 2025
bb81096
Update tokens so far
Mitch-At-Work Feb 28, 2025
940f605
Add script to generate
Mitch-At-Work Feb 28, 2025
44bfcdf
Initial script gen
Mitch-At-Work Feb 28, 2025
57c7867
Update tokens and script
Mitch-At-Work Feb 28, 2025
81f1e05
Update script to handle duplicated tokens
Mitch-At-Work Feb 28, 2025
6035592
Add strokeWidthThin fallback
Mitch-At-Work Feb 28, 2025
83f6a0a
Set variable path correctly
Mitch-At-Work Mar 1, 2025
e5671d7
Update latest
Mitch-At-Work Mar 3, 2025
0ed592f
Update with better fallback logic
Mitch-At-Work Mar 3, 2025
c81c862
Update script to handle fallbacks and f2 tokens better
Mitch-At-Work Mar 3, 2025
4d4bd3f
Update naming to handle brackets and spacings
Mitch-At-Work Mar 3, 2025
4609e99
Ensure fallbacks work correctly for FST
Mitch-At-Work Mar 3, 2025
9c3a7fe
Simplify script to match design and add custom fluent fallback map
Mitch-At-Work Mar 5, 2025
032d3b7
Add missing imports structure
Mitch-At-Work Mar 5, 2025
a750369
Fix imports
Mitch-At-Work Mar 5, 2025
a55568e
Update script to add exports
Mitch-At-Work Mar 5, 2025
5658e2d
Update script to handle imports/exports
Mitch-At-Work Mar 5, 2025
56e1102
Token script fixed
Mitch-At-Work Mar 5, 2025
e3a0bba
Update tokens and script
Mitch-At-Work Mar 6, 2025
58bac11
Fix token reference fallback
Mitch-At-Work Mar 6, 2025
791a838
Update api
Mitch-At-Work Mar 6, 2025
9c1c981
Fix port
Mitch-At-Work Mar 6, 2025
8884ea1
Lint all files
Mitch-At-Work Mar 6, 2025
a5bb059
Update and remove eslint rule
Mitch-At-Work Mar 6, 2025
c4719f4
Fix up the ESLint rule
Mitch-At-Work Mar 6, 2025
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
Next Next commit
Stash initial for now
  • Loading branch information
Mitch-At-Work committed Feb 24, 2025
commit 7a48bb00157ebbe05a86030fb9e1684b1cf8aee8
3 changes: 3 additions & 0 deletions packages/semantic-tokens/.babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"plugins": ["annotate-pure-calls", "@babel/transform-react-pure-annotations"]
}
12 changes: 12 additions & 0 deletions packages/semantic-tokens/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": ["plugin:@fluentui/eslint-plugin/react"],
"root": true,
"rules": {
"no-restricted-imports": [
"error",
{
"patterns": ["@fluentui/*", "react", "react-dom"]
}
]
}
}
32 changes: 32 additions & 0 deletions packages/semantic-tokens/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"$schema": "https://json.schemastore.org/swcrc",
"exclude": [
"/testing",
"/**/*.cy.ts",
"/**/*.cy.tsx",
"/**/*.spec-e2e.ts",
"/**/*.spec.ts",
"/**/*.spec.tsx",
"/**/*.test.ts",
"/**/*.test.tsx"
],
"jsc": {
"baseUrl": ".",
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": false,
"dynamicImport": false
},
"externalHelpers": true,
"transform": {
"react": {
"runtime": "classic",
"useSpread": true
}
},
"target": "es2019"
},
"minify": false,
"sourceMaps": true
}
4 changes: 4 additions & 0 deletions packages/semantic-tokens/CHANGELOG.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@fluentui/semantic-tokens",
"entries": []
}
5 changes: 5 additions & 0 deletions packages/semantic-tokens/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Change Log - @fluentui/semantic-tokens

This log was last generated on Thurs, 2 Feb 2025 16:26:46 GMT and should not be manually modified.

<!-- Start content -->
15 changes: 15 additions & 0 deletions packages/semantic-tokens/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@fluentui/semantic-tokens

Copyright (c) Microsoft Corporation

All rights reserved.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ""Software""), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note: Usage of the fonts and icons referenced in Fluent UI React is subject to the terms listed at https://aka.ms/fluentui-assets-license
3 changes: 3 additions & 0 deletions packages/semantic-tokens/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @fluentui/semantic-tokens

**Fluent UI Theme semantic-tokens**
6 changes: 6 additions & 0 deletions packages/semantic-tokens/config/api-extractor.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"extends": "@fluentui/scripts-api-extractor/api-extractor.common.v-next.json",

"mainEntryPointFilePath": "<projectFolder>/../../dist/out-tsc/types/packages/<unscopedPackageName>/src/index.d.ts"
}
1 change: 1 addition & 0 deletions packages/semantic-tokens/config/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/** Jest test setup file. */
Empty file.
33 changes: 33 additions & 0 deletions packages/semantic-tokens/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// @ts-check
/* eslint-disable */

const { readFileSync } = require('node:fs');
const { join } = require('node:path');

// Reading the SWC compilation config and remove the "exclude"
// for the test files to be compiled by SWC
const { exclude: _, ...swcJestConfig } = JSON.parse(readFileSync(join(__dirname, '.swcrc'), 'utf-8'));

// disable .swcrc look-up by SWC core because we're passing in swcJestConfig ourselves.
// If we do not disable this, SWC Core will read .swcrc and won't transform our test files due to "exclude"
if (swcJestConfig.swcrc === undefined) {
swcJestConfig.swcrc = false;
}

// Uncomment if using global setup/teardown files being transformed via swc
// https://nx.dev/packages/jest/documents/overview#global-setup/teardown-with-nx-libraries
// jest needs EsModule Interop to find the default exported setup/teardown functions
// swcJestConfig.module.noInterop = false;

/**
* @type {import('@jest/types').Config.InitialOptions}
*/
module.exports = {
displayName: 'semantic-tokens',
preset: '../../jest.preset.js',
transform: {
'^.+\\.tsx?$': ['@swc/jest', swcJestConfig],
},
coverageDirectory: './coverage',
setupFilesAfterEnv: ['./config/tests.js'],
};
44 changes: 44 additions & 0 deletions packages/semantic-tokens/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{
"name": "@fluentui/semantic-tokens",
"version": "0.0.0-alpha.1",
"description": "Fluent UI Theme semantic-tokens",
"main": "lib-commonjs/index.js",
"module": "lib/index.js",
"typings": "./dist/index.d.ts",
"sideEffects": false,
"repository": {
"type": "git",
"url": "https://github.com/microsoft/fluentui"
},
"license": "MIT",
"devDependencies": {
"@fluentui/eslint-plugin": "*",
"@fluentui/scripts-api-extractor": "*"
},
"dependencies": {
"@swc/helpers": "^0.5.1",
"@fluentui/tokens": "^1.0.0-alpha.21"
},
"beachball": {
"disallowedChangeTypes": [
"major",
"minor",
"patch"
]
},
"exports": {
".": {
"types": "./dist/index.d.ts",
"node": "./lib-commonjs/index.js",
"import": "./lib/index.js",
"require": "./lib-commonjs/index.js"
},
"./package.json": "./package.json"
},
"files": [
"*.md",
"dist/*.d.ts",
"lib",
"lib-commonjs"
]
}
41 changes: 41 additions & 0 deletions packages/semantic-tokens/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/* eslint-disable import/no-extraneous-dependencies */
import type { PlaywrightTestConfig } from '@playwright/test';
import { devices } from '@playwright/test';

const config: PlaywrightTestConfig = {
reporter: 'list',
retries: 3,
fullyParallel: process.env.CI ? false : true,
timeout: process.env.CI ? 10000 : 30000,
use: {
baseURL: 'http://localhost:6006',
viewport: {
height: 720,
width: 1280,
},
},
projects: [
{
name: 'chromium',
use: { ...devices['Desktop Chrome'] },
testMatch: /.*\.spec-e2e\.ts$/,
},
// {
// name: 'firefox',
// use: { ...devices['Desktop Firefox'] },
// testMatch: [/set-theme\.spec\.ts$/],
// },
// {
// name: 'webkit',
// use: { ...devices['Desktop Safari'] },
// testMatch: [/set-theme\.spec\.ts$/],
// },
],
webServer: {
command: `node scripts/server.js --port 6006`,
port: 6006,
reuseExistingServer: process.env.CI ? false : true,
},
};

export default config;
19 changes: 19 additions & 0 deletions packages/semantic-tokens/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "semantic-tokens",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"projectType": "library",
"implicitDependencies": [],
"sourceRoot": "packages/semantic-tokens/src",
"tags": ["vNext", "platform:web"],
"targets": {
"e2e": {
"dependsOn": ["build"]
},
"token-pipeline": {
"command": "node -r ../../scripts/ts-node/src/register ../../scripts/generators/src/token-pipeline.ts",
"options": {
"cwd": "{projectRoot}"
}
}
}
}
34 changes: 34 additions & 0 deletions packages/semantic-tokens/scripts/server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// @ts-check

const { parseArgs } = require('node:util');
const path = require('node:path');
const express = require('express');

main();

function main() {
const argv = processArgs();

const app = express();
const port = argv.port;

app.use(express.static(path.join(__dirname)));
app.use('/lib', express.static(path.join(__dirname, '../lib')));

app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});
}

function processArgs() {
const options = /** @type {const} */ ({
port: {
type: 'string',
default: '6006',
},
});

const { values } = parseArgs({ options, allowPositionals: false });

return values;
}
71 changes: 71 additions & 0 deletions packages/semantic-tokens/scripts/test-esm.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>native ESM for @fluentui/semantic-tokens</title>
<style>
* {
box-sizing: border-box;
}
.root {
display: flex;
flex-direction: column;
gap: 0.5rem;
width: 50%;
margin: auto;
}
.color-ramp {
display: flex;
}
.color-ramp > div {
flex: 1;
padding: 0.5em;
}
</style>
<script type="importmap">
{
"imports": {
"@fluentui/semantic-tokens": "../lib/index.js"
}
}
</script>
<script type="module">
import * as semantic-tokens from '@fluentui/semantic-tokens';

bootstrap(App());

function App() {
const Root = document.createElement('section');
Root.classList.add('root');

const Colors = Object.entries(semantic-tokens.webLightTheme)
.map(([key, value]) => {
if (key.startsWith('color')) {
return `<div class="color-ramp" data-id="${key}">
<div>${key}</div>
<div style="background-color:${value}"></div>
</div>`;
}

return;
})
.filter(Boolean)
.join('\n');

Root.innerHTML = Colors;

return Root;
}

function bootstrap(App) {
const mountRoot = document.querySelector('#app');
mountRoot.appendChild(App);
}
</script>
</head>
<body>
<h1>Native ESM / <code>@fluentui/semantic-tokens</code></h1>
<div id="app"></div>
</body>
</html>
Empty file.
5 changes: 5 additions & 0 deletions packages/semantic-tokens/src/components/button/tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { backgroundCtrlBrandRest } from '../../control/tokens';

export const buttonTokens = {
ctrlButtonNeutralBackgroundRest: `var(--ctrlButtonNeutralBackgroundRest,${backgroundCtrlBrandRest}))`,
};
3 changes: 3 additions & 0 deletions packages/semantic-tokens/src/control/tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { tokens } from '@fluentui/react-theme';

export const backgroundCtrlBrandRest = `var(--background-ctrl-brand-rest,${tokens.colorBrandBackground}))`;
3 changes: 3 additions & 0 deletions packages/semantic-tokens/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './control/tokens';
export * from './fallback/tokens';
export * from './components/button/tokens';
7 changes: 7 additions & 0 deletions packages/semantic-tokens/tsconfig.e2e.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"types": ["node"]
},
"include": ["playwright.config.ts", "**/*.spec-e2e.ts"]
}
24 changes: 24 additions & 0 deletions packages/semantic-tokens/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"target": "ES2019",
"noEmit": true,
"isolatedModules": true,
"importHelpers": true,
"noUnusedLocals": true,
"preserveConstEnums": true
},
"include": [],
"files": [],
"references": [
{
"path": "./tsconfig.lib.json"
},
{
"path": "./tsconfig.spec.json"
},
{
"path": "./tsconfig.e2e.json"
}
]
}
14 changes: 14 additions & 0 deletions packages/semantic-tokens/tsconfig.lib.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"noEmit": false,
"lib": ["ES2019", "dom"],
"declaration": true,
"declarationDir": "../../dist/out-tsc/types",
"outDir": "../../dist/out-tsc",
"inlineSources": true,
"types": ["static-assets", "environment"]
},
"exclude": ["**/*.spec.ts", "**/*.test.ts", "**/*.spec-e2e.ts"],
"include": ["./src/**/*.ts"]
}
Loading
Oops, something went wrong.