Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ packages/react-components/react-virtualizer/stories @microsoft/xc-uxe @Mitch-At-
packages/react-components/react-skeleton/library @microsoft/cxe-prg
packages/react-components/react-skeleton/stories @microsoft/cxe-prg
packages/tokens @microsoft/teams-prg
packages/semantic-tokens @microsoft/xc-uxe
packages/react-components/react-tags/library @microsoft/cxe-prg @microsoft/teams-prg
packages/react-components/react-tags/stories @microsoft/cxe-prg @microsoft/teams-prg
packages/react-components/react-migration-v0-v9/library @microsoft/teams-prg
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "feat: Initial semantic token package scaffolding",
"packageName": "@fluentui/semantic-tokens",
"email": "mifraser@microsoft.com",
"dependentChangeType": "patch"
}
1 change: 1 addition & 0 deletions nx.json
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@
"scripts/**/*",
"packages/eslint-plugin/**",
"packages/tokens/**",
"packages/semantic-tokens/**",
"packages/react-conformance/**",
"packages/react-components/**/*"
]
Expand Down
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
18 changes: 18 additions & 0 deletions packages/semantic-tokens/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# @fluentui/semantic-tokens

**Fluent UI Theme semantic-tokens**

The semantic tokens package provides finely tuneable theme control via generic and component level CSSVars with fallbacks.

This package extends upon the core @fluentui/tokens set in a tree-shakeable and backwards compatible manner.

Control tokens are targeted to specific components with a generic set fallback, as well as their original Fluent 2 theme token as the final fallback if no semantic tokens are set.

**Token generation method**
The token definition data is provided under scripts/tokens.json exported from Figma token definitions.

Semantic tokens are generated via the tokenGen script (`yarn generate-tokens`) under scripts/tokenGen.ts

Legacy tokens are statically generated via `yarn generate-legacy-tokens` - this ensures legacy tokens are flat exported so they remain tree-shakeable

Legacy token overrides are mapped 1:1 with their component use case via scripts/fluentOverrides.ts for backwards compatibility
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. */
9 changes: 9 additions & 0 deletions packages/semantic-tokens/etc/semantic-tokens.api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## API Report File for "@fluentui/semantic-tokens"

> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).

```ts

// (No @packageDocumentation comment for this package)

```
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'],
};
48 changes: 48 additions & 0 deletions packages/semantic-tokens/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"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": "*",
"@fluentui/tokens": ">=1.0.0-alpha"
},
"dependencies": {
"@swc/helpers": "^0.5.1"
},
"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"
],
"scripts": {
"generate-tokens": "npx ts-node scripts/tokenGen.ts",
"generate-legacy-tokens": "npx ts-node scripts/legacyTokens.ts"
}
}
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/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/tokens": "../lib/index.js"
}
}
</script>
<script type="module">
import * as tokens from '@fluentui/tokens';

bootstrap(App());

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

const Colors = Object.entries(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/tokens</code></h1>
<div id="app"></div>
</body>
</html>
1 change: 1 addition & 0 deletions packages/semantic-tokens/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export {};
Loading