@fluentui/web-components 3.0.0-beta.52 → 3.0.0-beta.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -2
- package/dist/dts/theme/set-theme.d.ts +12 -2
- package/dist/esm/theme/set-theme.js +23 -10
- package/dist/esm/theme/set-theme.js.map +1 -1
- package/dist/web-components.d.ts +12 -2
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,12 +1,21 @@
|
|
|
1
1
|
# Change Log - @fluentui/web-components
|
|
2
2
|
|
|
3
|
-
This log was last generated on
|
|
3
|
+
This log was last generated on Mon, 05 Aug 2024 04:08:29 GMT and should not be manually modified.
|
|
4
4
|
|
|
5
5
|
<!-- Start content -->
|
|
6
6
|
|
|
7
|
+
## [3.0.0-beta.53](https://github.com/microsoft/fluentui/tree/@fluentui/web-components_v3.0.0-beta.53)
|
|
8
|
+
|
|
9
|
+
Mon, 05 Aug 2024 04:08:29 GMT
|
|
10
|
+
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/web-components_v3.0.0-beta.52..@fluentui/web-components_v3.0.0-beta.53)
|
|
11
|
+
|
|
12
|
+
### Changes
|
|
13
|
+
|
|
14
|
+
- fix(web-components): detach design tokens from existing themes ([PR #32130](https://github.com/microsoft/fluentui/pull/32130) by machi@microsoft.com)
|
|
15
|
+
|
|
7
16
|
## [3.0.0-beta.52](https://github.com/microsoft/fluentui/tree/@fluentui/web-components_v3.0.0-beta.52)
|
|
8
17
|
|
|
9
|
-
Fri, 02 Aug 2024 04:07:
|
|
18
|
+
Fri, 02 Aug 2024 04:07:54 GMT
|
|
10
19
|
[Compare changes](https://github.com/microsoft/fluentui/compare/@fluentui/web-components_v3.0.0-beta.51..@fluentui/web-components_v3.0.0-beta.52)
|
|
11
20
|
|
|
12
21
|
### Changes
|
|
@@ -5,8 +5,18 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export type Theme = Record<string, string | number>;
|
|
7
7
|
/**
|
|
8
|
-
* Sets the theme tokens
|
|
9
|
-
*
|
|
8
|
+
* Sets the theme tokens as CSS Custom Properties. The Custom Properties are
|
|
9
|
+
* set in a constructed stylesheet on `document.adoptedStyleSheets` if
|
|
10
|
+
* supported, and on `document.documentElement.style` as a fallback.
|
|
11
|
+
*
|
|
12
|
+
* @param theme - Flat object of theme tokens. Each object entry must follow
|
|
13
|
+
* these rules: the key is the name of the token, usually in camel case, it
|
|
14
|
+
* must be a valid CSS Custom Property name WITHOUT the starting two dashes
|
|
15
|
+
* (`--`), the two dashes are added inside the function; the value must be
|
|
16
|
+
* a valid CSS value, e.g. it cannot contain semicolons (`;`).
|
|
17
|
+
* Note that this argument is not limited to existing theme objects (from
|
|
18
|
+
* `@fluentui/tokens`), you can pass in an arbitrary theme object as long
|
|
19
|
+
* as each entry’s value is either a string or a number.
|
|
10
20
|
* @internal
|
|
11
21
|
*/
|
|
12
22
|
export declare const setTheme: (theme: Theme) => void;
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import * as tokens from './design-tokens.js';
|
|
2
|
-
const tokenNames = Object.keys(tokens);
|
|
3
1
|
const SUPPORTS_REGISTER_PROPERTY = 'registerProperty' in CSS;
|
|
4
2
|
const SUPPORTS_ADOPTED_STYLE_SHEETS = 'adoptedStyleSheets' in document;
|
|
5
3
|
const themeStyleSheet = new CSSStyleSheet();
|
|
6
4
|
const themeStyleTextMap = new Map();
|
|
7
5
|
/**
|
|
8
|
-
* Sets the theme tokens
|
|
9
|
-
*
|
|
6
|
+
* Sets the theme tokens as CSS Custom Properties. The Custom Properties are
|
|
7
|
+
* set in a constructed stylesheet on `document.adoptedStyleSheets` if
|
|
8
|
+
* supported, and on `document.documentElement.style` as a fallback.
|
|
9
|
+
*
|
|
10
|
+
* @param theme - Flat object of theme tokens. Each object entry must follow
|
|
11
|
+
* these rules: the key is the name of the token, usually in camel case, it
|
|
12
|
+
* must be a valid CSS Custom Property name WITHOUT the starting two dashes
|
|
13
|
+
* (`--`), the two dashes are added inside the function; the value must be
|
|
14
|
+
* a valid CSS value, e.g. it cannot contain semicolons (`;`).
|
|
15
|
+
* Note that this argument is not limited to existing theme objects (from
|
|
16
|
+
* `@fluentui/tokens`), you can pass in an arbitrary theme object as long
|
|
17
|
+
* as each entry’s value is either a string or a number.
|
|
10
18
|
* @internal
|
|
11
19
|
*/
|
|
12
20
|
export const setTheme = (theme) => {
|
|
@@ -20,18 +28,23 @@ export const setTheme = (theme) => {
|
|
|
20
28
|
}
|
|
21
29
|
if (!themeStyleTextMap.has(theme)) {
|
|
22
30
|
const tokenDeclarations = [];
|
|
23
|
-
for (const
|
|
31
|
+
for (const [tokenName, tokenValue] of Object.entries(theme)) {
|
|
32
|
+
if (typeof tokenValue !== 'string' && Number.isNaN(tokenValue)) {
|
|
33
|
+
throw new Error(`"${tokenName}" must be a string or a number.`);
|
|
34
|
+
}
|
|
35
|
+
const name = `--${tokenName}`;
|
|
36
|
+
const initialValue = tokenValue.toString();
|
|
24
37
|
if (SUPPORTS_REGISTER_PROPERTY) {
|
|
25
38
|
try {
|
|
26
39
|
CSS.registerProperty({
|
|
27
|
-
name
|
|
40
|
+
name,
|
|
41
|
+
initialValue,
|
|
28
42
|
inherits: true,
|
|
29
|
-
initialValue: theme[t],
|
|
30
43
|
});
|
|
31
44
|
}
|
|
32
45
|
catch { }
|
|
33
46
|
}
|
|
34
|
-
tokenDeclarations.push(
|
|
47
|
+
tokenDeclarations.push(`${name}:${initialValue};`);
|
|
35
48
|
}
|
|
36
49
|
themeStyleTextMap.set(theme, `html{${tokenDeclarations.join('')}}`);
|
|
37
50
|
}
|
|
@@ -46,8 +59,8 @@ export const setTheme = (theme) => {
|
|
|
46
59
|
* @internal
|
|
47
60
|
*/
|
|
48
61
|
export const setThemeFor = (element, theme) => {
|
|
49
|
-
for (const
|
|
50
|
-
element.style.setProperty(`--${
|
|
62
|
+
for (const [tokenName, tokenValue] of Object.entries(theme)) {
|
|
63
|
+
element.style.setProperty(`--${tokenName}`, tokenValue.toString());
|
|
51
64
|
}
|
|
52
65
|
};
|
|
53
66
|
//# sourceMappingURL=set-theme.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"set-theme.js","sourceRoot":"","sources":["../../../src/theme/set-theme.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"set-theme.js","sourceRoot":"","sources":["../../../src/theme/set-theme.ts"],"names":[],"mappings":"AAOA,MAAM,0BAA0B,GAAG,kBAAkB,IAAI,GAAG,CAAC;AAC7D,MAAM,6BAA6B,GAAG,oBAAoB,IAAI,QAAQ,CAAC;AACvE,MAAM,eAAe,GAAG,IAAI,aAAa,EAAE,CAAC;AAC5C,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAiB,CAAC;AAEnD;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAY,EAAE,EAAE;IACvC,4EAA4E;IAC5E,yEAAyE;IACzE,2EAA2E;IAC3E,oBAAoB;IACpB,IAAI,CAAC,6BAA6B,EAAE;QAClC,WAAW,CAAC,QAAQ,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC;QAC7C,OAAO;KACR;IAED,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;QACjC,MAAM,iBAAiB,GAAa,EAAE,CAAC;QAEvC,KAAK,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YAC3D,IAAI,OAAO,UAAU,KAAK,QAAQ,IAAI,MAAM,CAAC,KAAK,CAAC,UAAU,CAAC,EAAE;gBAC9D,MAAM,IAAI,KAAK,CAAC,IAAI,SAAS,iCAAiC,CAAC,CAAC;aACjE;YAED,MAAM,IAAI,GAAG,KAAK,SAAS,EAAE,CAAC;YAC9B,MAAM,YAAY,GAAG,UAAU,CAAC,QAAQ,EAAE,CAAC;YAC3C,IAAI,0BAA0B,EAAE;gBAC9B,IAAI;oBACF,GAAG,CAAC,gBAAgB,CAAC;wBACnB,IAAI;wBACJ,YAAY;wBACZ,QAAQ,EAAE,IAAI;qBACf,CAAC,CAAC;iBACJ;gBAAC,MAAM,GAAE;aACX;YACD,iBAAiB,CAAC,IAAI,CAAC,GAAG,IAAI,IAAI,YAAY,GAAG,CAAC,CAAC;SACpD;QAED,iBAAiB,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,iBAAiB,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;KACrE;IAED,8CAA8C;IAC9C,eAAe,CAAC,WAAW,CAAC,iBAAiB,CAAC,GAAG,CAAC,KAAK,CAAE,CAAC,CAAC;IAE3D,gEAAgE;IAChE,IAAI,CAAC,QAAQ,CAAC,kBAAkB,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE;QAC1D,QAAQ,CAAC,kBAAkB,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;KACnD;AACH,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,OAAoB,EAAE,KAAY,EAAE,EAAE;IAChE,KAAK,MAAM,CAAC,SAAS,EAAE,UAAU,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;QAC3D,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,KAAK,SAAS,EAAE,EAAE,UAAU,CAAC,QAAQ,EAAE,CAAC,CAAC;KACpE;AACH,CAAC,CAAC"}
|
package/dist/web-components.d.ts
CHANGED
|
@@ -7519,8 +7519,18 @@ export declare const roleForMenuItem: {
|
|
|
7519
7519
|
};
|
|
7520
7520
|
|
|
7521
7521
|
/**
|
|
7522
|
-
* Sets the theme tokens
|
|
7523
|
-
*
|
|
7522
|
+
* Sets the theme tokens as CSS Custom Properties. The Custom Properties are
|
|
7523
|
+
* set in a constructed stylesheet on `document.adoptedStyleSheets` if
|
|
7524
|
+
* supported, and on `document.documentElement.style` as a fallback.
|
|
7525
|
+
*
|
|
7526
|
+
* @param theme - Flat object of theme tokens. Each object entry must follow
|
|
7527
|
+
* these rules: the key is the name of the token, usually in camel case, it
|
|
7528
|
+
* must be a valid CSS Custom Property name WITHOUT the starting two dashes
|
|
7529
|
+
* (`--`), the two dashes are added inside the function; the value must be
|
|
7530
|
+
* a valid CSS value, e.g. it cannot contain semicolons (`;`).
|
|
7531
|
+
* Note that this argument is not limited to existing theme objects (from
|
|
7532
|
+
* `@fluentui/tokens`), you can pass in an arbitrary theme object as long
|
|
7533
|
+
* as each entry’s value is either a string or a number.
|
|
7524
7534
|
* @internal
|
|
7525
7535
|
*/
|
|
7526
7536
|
export declare const setTheme: (theme: Theme) => void;
|