@atlaskit/tokens 0.13.0 → 0.13.1

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/tokens
2
2
 
3
+ ## 0.13.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [`a5eed85fe2e`](https://bitbucket.org/atlassian/atlassian-frontend/commits/a5eed85fe2e) - Added a new `getTokenValue()` API - it accepts a dot-separated token name and a fallback value, and returns the current computed CSS value for the resulting CSS Custom Property. This should be used when the CSS cascade isn't available, eg. `<canvas>` elements, JS charting libraries, etc.
8
+
3
9
  ## 0.13.0
4
10
 
5
11
  ### Minor Changes
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _warnOnce = _interopRequireDefault(require("@atlaskit/ds-lib/warn-once"));
11
+
12
+ var _tokenNames = _interopRequireDefault(require("./artifacts/token-names"));
13
+
14
+ var name = "@atlaskit/tokens";
15
+ var version = "0.13.1";
16
+
17
+ /**
18
+ * Takes a dot-separated token name and and an optional fallback, and returns the current computed CSS value for the
19
+ * resulting CSS Custom Property.
20
+ * This should be used for when the CSS cascade isn't available, eg. `<canvas>` elements, JS charting libraries, etc.
21
+ *
22
+ * Note: these values change depending on the theme so consider pairing them with `useThemeObserver` in React, or the
23
+ * `ThemeMutationObserver` class elsewhere.
24
+ *
25
+ * @param {string} path - A dot-separated token name (example: `'color.background.brand'` or `'spacing.scale.100'`).
26
+ * @param {string} [fallback] - The fallback value that should render when token CSS is not present in your app.
27
+ *
28
+ * @example
29
+ * ```
30
+ * const theme = useThemeObserver();
31
+ *
32
+ * useEffect(() => {
33
+ * const lineColor = getTokenValue('color.background.accent.blue.subtle', B400);
34
+ * }, [theme]);
35
+ * ```
36
+ *
37
+ */
38
+ function getTokenValue(tokenId) {
39
+ var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
40
+ var token = _tokenNames.default[tokenId];
41
+ var tokenValue = fallback;
42
+
43
+ if (process.env.NODE_ENV !== 'production' && !token) {
44
+ (0, _warnOnce.default)("Unknown token id at path: ".concat(tokenId, " for ").concat(name, "@").concat(version));
45
+ }
46
+
47
+ if (typeof window === 'undefined') {
48
+ return tokenValue;
49
+ }
50
+
51
+ tokenValue = window.getComputedStyle(document.documentElement).getPropertyValue(token);
52
+ tokenValue = tokenValue || fallback;
53
+ return tokenValue;
54
+ }
55
+
56
+ var _default = getTokenValue;
57
+ exports.default = _default;
@@ -14,7 +14,7 @@ var _tokenNames = _interopRequireDefault(require("./artifacts/token-names"));
14
14
  var _constants = require("./constants");
15
15
 
16
16
  var name = "@atlaskit/tokens";
17
- var version = "0.13.0";
17
+ var version = "0.13.1";
18
18
 
19
19
  /**
20
20
  * Takes a dot-separated token name and an optional fallback, and returns the CSS custom property for the corresponding token.
package/dist/cjs/index.js CHANGED
@@ -11,6 +11,12 @@ Object.defineProperty(exports, "ThemeMutationObserver", {
11
11
  return _themeChangeObserver.ThemeMutationObserver;
12
12
  }
13
13
  });
14
+ Object.defineProperty(exports, "getTokenValue", {
15
+ enumerable: true,
16
+ get: function get() {
17
+ return _getTokenValue.default;
18
+ }
19
+ });
14
20
  Object.defineProperty(exports, "setGlobalTheme", {
15
21
  enumerable: true,
16
22
  get: function get() {
@@ -38,6 +44,8 @@ Object.defineProperty(exports, "useThemeObserver", {
38
44
 
39
45
  var _getToken = _interopRequireDefault(require("./get-token"));
40
46
 
47
+ var _getTokenValue = _interopRequireDefault(require("./get-token-value"));
48
+
41
49
  var _setGlobalTheme = _interopRequireDefault(require("./set-global-theme"));
42
50
 
43
51
  var _themeConfig = _interopRequireDefault(require("./theme-config"));
@@ -20,7 +20,7 @@ var _react = require("react");
20
20
  var _constants = require("./constants");
21
21
 
22
22
  var getGlobalTheme = function getGlobalTheme() {
23
- return typeof document !== 'undefined' ? document.documentElement.getAttribute(_constants.COLOR_MODE_ATTRIBUTE) : null;
23
+ return typeof document !== 'undefined' ? document.documentElement.getAttribute(_constants.THEME_DATA_ATTRIBUTE) : null;
24
24
  };
25
25
  /**
26
26
  * A MutationObserver which watches the `<html>` element for changes to the theme.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/tokens",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "sideEffects": [
5
5
  "**/*.css"
6
6
  ]
@@ -0,0 +1,44 @@
1
+ import warnOnce from '@atlaskit/ds-lib/warn-once';
2
+ import tokens from './artifacts/token-names';
3
+ const name = "@atlaskit/tokens";
4
+ const version = "0.13.1";
5
+
6
+ /**
7
+ * Takes a dot-separated token name and and an optional fallback, and returns the current computed CSS value for the
8
+ * resulting CSS Custom Property.
9
+ * This should be used for when the CSS cascade isn't available, eg. `<canvas>` elements, JS charting libraries, etc.
10
+ *
11
+ * Note: these values change depending on the theme so consider pairing them with `useThemeObserver` in React, or the
12
+ * `ThemeMutationObserver` class elsewhere.
13
+ *
14
+ * @param {string} path - A dot-separated token name (example: `'color.background.brand'` or `'spacing.scale.100'`).
15
+ * @param {string} [fallback] - The fallback value that should render when token CSS is not present in your app.
16
+ *
17
+ * @example
18
+ * ```
19
+ * const theme = useThemeObserver();
20
+ *
21
+ * useEffect(() => {
22
+ * const lineColor = getTokenValue('color.background.accent.blue.subtle', B400);
23
+ * }, [theme]);
24
+ * ```
25
+ *
26
+ */
27
+ function getTokenValue(tokenId, fallback = '') {
28
+ let token = tokens[tokenId];
29
+ let tokenValue = fallback;
30
+
31
+ if (process.env.NODE_ENV !== 'production' && !token) {
32
+ warnOnce(`Unknown token id at path: ${tokenId} for ${name}@${version}`);
33
+ }
34
+
35
+ if (typeof window === 'undefined') {
36
+ return tokenValue;
37
+ }
38
+
39
+ tokenValue = window.getComputedStyle(document.documentElement).getPropertyValue(token);
40
+ tokenValue = tokenValue || fallback;
41
+ return tokenValue;
42
+ }
43
+
44
+ export default getTokenValue;
@@ -2,7 +2,7 @@ import warnOnce from '@atlaskit/ds-lib/warn-once';
2
2
  import tokens from './artifacts/token-names';
3
3
  import { TOKEN_NOT_FOUND_CSS_VAR } from './constants';
4
4
  const name = "@atlaskit/tokens";
5
- const version = "0.13.0";
5
+ const version = "0.13.1";
6
6
 
7
7
  /**
8
8
  * Takes a dot-separated token name and an optional fallback, and returns the CSS custom property for the corresponding token.
@@ -1,4 +1,5 @@
1
1
  export { default as token } from './get-token';
2
+ export { default as getTokenValue } from './get-token-value';
2
3
  export { default as setGlobalTheme } from './set-global-theme';
3
4
  export { default as themeConfig } from './theme-config';
4
5
  export { useThemeObserver, ThemeMutationObserver } from './theme-change-observer';
@@ -1,8 +1,8 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import { useEffect, useState } from 'react';
3
- import { COLOR_MODE_ATTRIBUTE, THEME_DATA_ATTRIBUTE } from './constants';
3
+ import { THEME_DATA_ATTRIBUTE } from './constants';
4
4
 
5
- const getGlobalTheme = () => typeof document !== 'undefined' ? document.documentElement.getAttribute(COLOR_MODE_ATTRIBUTE) : null;
5
+ const getGlobalTheme = () => typeof document !== 'undefined' ? document.documentElement.getAttribute(THEME_DATA_ATTRIBUTE) : null;
6
6
  /**
7
7
  * A MutationObserver which watches the `<html>` element for changes to the theme.
8
8
  *
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/tokens",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "sideEffects": [
5
5
  "**/*.css"
6
6
  ]
@@ -0,0 +1,45 @@
1
+ import warnOnce from '@atlaskit/ds-lib/warn-once';
2
+ import tokens from './artifacts/token-names';
3
+ var name = "@atlaskit/tokens";
4
+ var version = "0.13.1";
5
+
6
+ /**
7
+ * Takes a dot-separated token name and and an optional fallback, and returns the current computed CSS value for the
8
+ * resulting CSS Custom Property.
9
+ * This should be used for when the CSS cascade isn't available, eg. `<canvas>` elements, JS charting libraries, etc.
10
+ *
11
+ * Note: these values change depending on the theme so consider pairing them with `useThemeObserver` in React, or the
12
+ * `ThemeMutationObserver` class elsewhere.
13
+ *
14
+ * @param {string} path - A dot-separated token name (example: `'color.background.brand'` or `'spacing.scale.100'`).
15
+ * @param {string} [fallback] - The fallback value that should render when token CSS is not present in your app.
16
+ *
17
+ * @example
18
+ * ```
19
+ * const theme = useThemeObserver();
20
+ *
21
+ * useEffect(() => {
22
+ * const lineColor = getTokenValue('color.background.accent.blue.subtle', B400);
23
+ * }, [theme]);
24
+ * ```
25
+ *
26
+ */
27
+ function getTokenValue(tokenId) {
28
+ var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
29
+ var token = tokens[tokenId];
30
+ var tokenValue = fallback;
31
+
32
+ if (process.env.NODE_ENV !== 'production' && !token) {
33
+ warnOnce("Unknown token id at path: ".concat(tokenId, " for ").concat(name, "@").concat(version));
34
+ }
35
+
36
+ if (typeof window === 'undefined') {
37
+ return tokenValue;
38
+ }
39
+
40
+ tokenValue = window.getComputedStyle(document.documentElement).getPropertyValue(token);
41
+ tokenValue = tokenValue || fallback;
42
+ return tokenValue;
43
+ }
44
+
45
+ export default getTokenValue;
@@ -2,7 +2,7 @@ import warnOnce from '@atlaskit/ds-lib/warn-once';
2
2
  import tokens from './artifacts/token-names';
3
3
  import { TOKEN_NOT_FOUND_CSS_VAR } from './constants';
4
4
  var name = "@atlaskit/tokens";
5
- var version = "0.13.0";
5
+ var version = "0.13.1";
6
6
 
7
7
  /**
8
8
  * Takes a dot-separated token name and an optional fallback, and returns the CSS custom property for the corresponding token.
package/dist/esm/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { default as token } from './get-token';
2
+ export { default as getTokenValue } from './get-token-value';
2
3
  export { default as setGlobalTheme } from './set-global-theme';
3
4
  export { default as themeConfig } from './theme-config';
4
5
  export { useThemeObserver, ThemeMutationObserver } from './theme-change-observer';
@@ -3,10 +3,10 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
3
3
  import _createClass from "@babel/runtime/helpers/createClass";
4
4
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
5
5
  import { useEffect, useState } from 'react';
6
- import { COLOR_MODE_ATTRIBUTE, THEME_DATA_ATTRIBUTE } from './constants';
6
+ import { THEME_DATA_ATTRIBUTE } from './constants';
7
7
 
8
8
  var getGlobalTheme = function getGlobalTheme() {
9
- return typeof document !== 'undefined' ? document.documentElement.getAttribute(COLOR_MODE_ATTRIBUTE) : null;
9
+ return typeof document !== 'undefined' ? document.documentElement.getAttribute(THEME_DATA_ATTRIBUTE) : null;
10
10
  };
11
11
  /**
12
12
  * A MutationObserver which watches the `<html>` element for changes to the theme.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/tokens",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "sideEffects": [
5
5
  "**/*.css"
6
6
  ]
@@ -0,0 +1,25 @@
1
+ import tokens from './artifacts/token-names';
2
+ declare type Tokens = typeof tokens;
3
+ /**
4
+ * Takes a dot-separated token name and and an optional fallback, and returns the current computed CSS value for the
5
+ * resulting CSS Custom Property.
6
+ * This should be used for when the CSS cascade isn't available, eg. `<canvas>` elements, JS charting libraries, etc.
7
+ *
8
+ * Note: these values change depending on the theme so consider pairing them with `useThemeObserver` in React, or the
9
+ * `ThemeMutationObserver` class elsewhere.
10
+ *
11
+ * @param {string} path - A dot-separated token name (example: `'color.background.brand'` or `'spacing.scale.100'`).
12
+ * @param {string} [fallback] - The fallback value that should render when token CSS is not present in your app.
13
+ *
14
+ * @example
15
+ * ```
16
+ * const theme = useThemeObserver();
17
+ *
18
+ * useEffect(() => {
19
+ * const lineColor = getTokenValue('color.background.accent.blue.subtle', B400);
20
+ * }, [theme]);
21
+ * ```
22
+ *
23
+ */
24
+ declare function getTokenValue<T extends keyof Tokens>(tokenId: T, fallback?: string): string;
25
+ export default getTokenValue;
@@ -1,4 +1,5 @@
1
1
  export { default as token } from './get-token';
2
+ export { default as getTokenValue } from './get-token-value';
2
3
  export { default as setGlobalTheme } from './set-global-theme';
3
4
  export type { CSSToken } from './artifacts/token-names';
4
5
  export type { Themes, ThemeIds } from './theme-config';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/tokens",
3
- "version": "0.13.0",
3
+ "version": "0.13.1",
4
4
  "author": "Atlassian Pty Ltd",
5
5
  "description": "Design tokens are the single source of truth to name and store design decisions.",
6
6
  "license": "Apache-2.0",
@@ -99,6 +99,7 @@
99
99
  "prettier": "^2.7.0",
100
100
  "react": "^16.8.0",
101
101
  "react-use-clipboard": "^1.0.0",
102
+ "recharts": "^1.8.5",
102
103
  "style-dictionary": "^3.0.0",
103
104
  "ts-node": "^10.9.1",
104
105
  "typescript": "4.5.5"
package/report.api.md CHANGED
@@ -418,6 +418,12 @@ type CSSTokenMap = {
418
418
  // @public
419
419
  type ExtensionThemeId = ThemeIds;
420
420
 
421
+ // @public
422
+ export function getTokenValue<T extends keyof Tokens_2>(
423
+ tokenId: T,
424
+ fallback?: string,
425
+ ): string;
426
+
421
427
  // @public
422
428
  type Palettes =
423
429
  | 'defaultPalette'
@@ -899,6 +905,9 @@ const tokens: {
899
905
  readonly 'font.lineHeight.600': '--ds-font-lineHeight-600';
900
906
  };
901
907
 
908
+ // @public (undocumented)
909
+ type Tokens_2 = typeof tokens;
910
+
902
911
  // @public
903
912
  export const useThemeObserver: () => ThemeIds | null;
904
913
 
@@ -407,6 +407,9 @@ type CSSTokenMap = {
407
407
  // @public
408
408
  type ExtensionThemeId = ThemeIds;
409
409
 
410
+ // @public
411
+ export function getTokenValue<T extends keyof Tokens_2>(tokenId: T, fallback?: string): string;
412
+
410
413
  // @public
411
414
  type Palettes = 'defaultPalette' | 'legacyPalette' | 'spacingScale' | 'typographyPalette';
412
415
 
@@ -862,6 +865,9 @@ const tokens: {
862
865
  readonly 'font.lineHeight.600': "--ds-font-lineHeight-600";
863
866
  };
864
867
 
868
+ // @public (undocumented)
869
+ type Tokens_2 = typeof tokens;
870
+
865
871
  // @public
866
872
  export const useThemeObserver: () => ThemeIds | null;
867
873