Skip to content

Commit

Permalink
feat(react-theme-sass): Add Sass variables mapped to CSS variables pr…
Browse files Browse the repository at this point in the history
…ovided by react-theme (microsoft#22964)

* add react-theme-sass package

* add SASS variables

* Change file

* remove spec template

* update yarn.lock after merge

* update yarn.lock after merge

* Replace node-sass with dart-sass, remove unused dependencies

* Update .github/CODEOWNERS

Co-authored-by: Justin Slone <[email protected]>

Co-authored-by: Justin Slone <[email protected]>
  • Loading branch information
2 people authored and marwan38 committed Jun 13, 2022
1 parent dc87d16 commit 2014a44
Show file tree
Hide file tree
Showing 34 changed files with 990 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ packages/react-components/react-toolbar @microsoft/teams-prg @chpalac @ling1726
packages/react-components/react-portal-compat @microsoft/teams-prg
packages/react-components/react-alert @microsoft/teams-prg
packages/react-components/react-portal-compat-context @microsoft/teams-prg
packages/react-components/react-theme-sass @microsoft/teams-prg
packages/react-components/theme-designer @microsoft/cxe-coastal
packages/react-components/global-context @microsoft/teams-prg
packages/react-components/babel-preset-global-context @microsoft/teams-prg
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Add SASS variables mapped to CSS variables provided by react-theme",
"packageName": "@fluentui/react-theme-sass",
"email": "[email protected]",
"dependentChangeType": "patch"
}
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@
"jest-axe": "5.0.1",
"jest-cli": "26.6.3",
"jest-environment-jsdom": "26.6.2",
"jest-environment-node-single-context": "26.2.0",
"jest-snapshot": "26.6.2",
"jest-watch-typeahead": "0.6.5",
"jju": "1.4.0",
Expand Down
3 changes: 3 additions & 0 deletions packages/react-components/react-theme-sass/.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"]
}
4 changes: 4 additions & 0 deletions packages/react-components/react-theme-sass/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": ["plugin:@fluentui/eslint-plugin/node"],
"root": true
}
29 changes: 29 additions & 0 deletions packages/react-components/react-theme-sass/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
.storybook/
.vscode/
bundle-size/
config/
coverage/
e2e/
etc/
node_modules/
src/
dist/types/
temp/
__fixtures__
__mocks__
__tests__

*.api.json
*.log
*.spec.*
*.stories.*
*.test.*
*.yml

# config files
*config.*
*rc.*
.editorconfig
.eslint*
.git*
.prettierignore
15 changes: 15 additions & 0 deletions packages/react-components/react-theme-sass/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@fluentui/react-theme-sass

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
35 changes: 35 additions & 0 deletions packages/react-components/react-theme-sass/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# @fluentui/react-theme-sass

**React Theme Sass for [Fluent UI React](https://developer.microsoft.com/en-us/fluentui)**

SASS variables referencing react-theme design tokens injected to DOM by react-provider.

## Usage

1. Instantiate a `FluentProvider` to inject a Fluent theme into a DOM:

```jsx
import React from 'react';
import ReactDOM from 'react-dom';
import { FluentProvider, teamsLightTheme } from '@fluentui/react-components';
import App from './App';
ReactDOM.render(
<FluentProvider theme={teamsLightTheme}>
<App />
</FluentProvider>,
document.getElementById('root'),
);
```

2. In SCSS styles you can import SCSS variables from `@fluentui/react-theme-sass` and use them in the styles:

```scss
@import '~@fluentui/react-theme-sass';
.brandedElement {
color: $colorBrandForeground1;
background: $colorBrandBackground;
border-radius: $borderRadiusLarge;
}
```

⚠ This package does not export any Javascript code.️
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$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/types/index.d.ts"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"extends": "./api-extractor.json",
"mainEntryPointFilePath": "<projectFolder>/dist/types/packages/react-components/<unscopedPackageName>/src/index.d.ts"
}
1 change: 1 addition & 0 deletions packages/react-components/react-theme-sass/config/tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/** Jest test setup file. */
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## API Report File for "@fluentui/react-theme-sass"

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

// (No @packageDocumentation comment for this package)

```
22 changes: 22 additions & 0 deletions packages/react-components/react-theme-sass/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// @ts-check

/**
* @type {import('@jest/types').Config.InitialOptions}
*/
module.exports = {
displayName: 'react-theme-sass',
preset: '../../../jest.preset.js',
globals: {
'ts-jest': {
tsConfig: '<rootDir>/tsconfig.spec.json',
diagnostics: false,
},
},
testEnvironment: 'jest-environment-node-single-context',
transform: {
'^.+\\.tsx?$': 'ts-jest',
},
coverageDirectory: './coverage',
setupFilesAfterEnv: ['./config/tests.js'],
snapshotSerializers: ['@griffel/jest-serializer'],
};
3 changes: 3 additions & 0 deletions packages/react-components/react-theme-sass/just.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { preset } from '@fluentui/scripts';

preset();
39 changes: 39 additions & 0 deletions packages/react-components/react-theme-sass/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"name": "@fluentui/react-theme-sass",
"version": "9.0.0-alpha.0",
"description": "SASS variables referencing react-theme design tokens injected to DOM by react-provider.",
"main": "lib-commonjs/index.js",
"module": "lib/index.js",
"typings": "dist/index.d.ts",
"style": "sass/tokens.scss",
"sideEffects": false,
"repository": {
"type": "git",
"url": "https://github.com/microsoft/fluentui"
},
"license": "MIT",
"scripts": {
"build": "just-scripts build",
"clean": "just-scripts clean",
"code-style": "just-scripts code-style",
"just": "just-scripts",
"lint": "just-scripts lint",
"start": "yarn storybook",
"test": "jest --passWithNoTests",
"docs": "api-extractor run --config=config/api-extractor.local.json --local",
"build:local": "tsc -p ./tsconfig.lib.json --module esnext --emitDeclarationOnly && node ../../../scripts/typescript/normalize-import --output ./dist/types/packages/react-components/react-theme-sass/src && yarn docs",
"storybook": "node ../../../scripts/storybook/runner",
"type-check": "tsc -b tsconfig.json"
},
"devDependencies": {
"@fluentui/eslint-plugin": "*",
"@fluentui/scripts": "^1.0.0"
},
"beachball": {
"disallowedChangeTypes": [
"major",
"minor",
"patch"
]
}
}
14 changes: 14 additions & 0 deletions packages/react-components/react-theme-sass/sass/Sass.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { compileString } from 'sass';
import { webLightTheme } from '@fluentui/react-theme';

describe('Sass tokens', () => {
// by referencing all react-theme tokens as SCSS variables, verifies that all the variables are exported
it('exist for all theme tokens', () => {
const data = [
'@import "sass/tokens.scss";',
...Object.keys(webLightTheme).map(tokenName => `$expected__${tokenName}: $${tokenName};`),
].join('\n');

compileString(data, { loadPaths: ['.'] });
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$borderRadiusNone: var(--borderRadiusNone);
$borderRadiusSmall: var(--borderRadiusSmall);
$borderRadiusMedium: var(--borderRadiusMedium);
$borderRadiusLarge: var(--borderRadiusLarge);
$borderRadiusXLarge: var(--borderRadiusXLarge);
$borderRadiusCircular: var(--borderRadiusCircular);
Loading

0 comments on commit 2014a44

Please sign in to comment.