@atlaskit/tokens 1.13.2 → 1.14.0

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
+ ## 1.14.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`d9d7c284713`](https://bitbucket.org/atlassian/atlassian-frontend/commits/d9d7c284713) - Add custom theming support to `ThemeObjectToString` and `ThemeStringToObject` functions.
8
+
3
9
  ## 1.13.2
4
10
 
5
11
  ### Patch Changes
@@ -8,7 +8,7 @@ exports.default = void 0;
8
8
  var _warnOnce = _interopRequireDefault(require("@atlaskit/ds-lib/warn-once"));
9
9
  var _tokenNames = _interopRequireDefault(require("./artifacts/token-names"));
10
10
  var name = "@atlaskit/tokens";
11
- var version = "1.13.2";
11
+ var version = "1.14.0";
12
12
  /**
13
13
  * Takes a dot-separated token name and and an optional fallback, and returns the current computed CSS value for the
14
14
  * resulting CSS Custom Property.
@@ -9,7 +9,7 @@ var _warnOnce = _interopRequireDefault(require("@atlaskit/ds-lib/warn-once"));
9
9
  var _tokenNames = _interopRequireDefault(require("./artifacts/token-names"));
10
10
  var _constants = require("./constants");
11
11
  var name = "@atlaskit/tokens";
12
- var version = "1.13.2";
12
+ var version = "1.14.0";
13
13
  /**
14
14
  * Takes a dot-separated token name and an optional fallback, and returns the CSS custom property for the corresponding token.
15
15
  * This should be used to implement design decisions throughout your application.
@@ -5,9 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.themeStringToObject = exports.themeObjectToString = void 0;
8
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
8
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
10
  var _themeConfig = require("./theme-config");
10
11
  var themeKinds = ['light', 'dark', 'spacing', 'typography', 'shape'];
12
+ var customThemeOptions = 'UNSAFE_themeOptions';
11
13
  var isThemeKind = function isThemeKind(themeKind) {
12
14
  return themeKinds.find(function (kind) {
13
15
  return kind === themeKind;
@@ -35,7 +37,7 @@ var isColorMode = function isColorMode(modeId) {
35
37
  */
36
38
  var themeStringToObject = function themeStringToObject(themeState) {
37
39
  return themeState.split(' ').map(function (theme) {
38
- return theme.split(':');
40
+ return theme.split(/:([\s\S]*)/);
39
41
  }).reduce(function (themeObject, _ref) {
40
42
  var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
41
43
  kind = _ref2[0],
@@ -47,6 +49,13 @@ var themeStringToObject = function themeStringToObject(themeState) {
47
49
  // @ts-expect-error FIXME - this is a valid ts error
48
50
  themeObject[kind] = id;
49
51
  }
52
+ if (kind === customThemeOptions) {
53
+ try {
54
+ themeObject[customThemeOptions] = JSON.parse(id);
55
+ } catch (e) {
56
+ new Error('Invalid custom theme string');
57
+ }
58
+ }
50
59
  return themeObject;
51
60
  }, {});
52
61
  };
@@ -68,7 +77,16 @@ var themeObjectToString = function themeObjectToString(themeState) {
68
77
  var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
69
78
  kind = _ref4[0],
70
79
  id = _ref4[1];
71
- return (kind === 'colorMode' || isThemeKind(kind)) && typeof id === 'string' && (isThemeIds(id) || isColorMode(id)) ? themeString + "".concat(themeString ? ' ' : '') + "".concat(kind, ":").concat(id) : themeString;
80
+ if (
81
+ // colorMode theme state
82
+ kind === 'colorMode' && typeof id === 'string' && isColorMode(id) ||
83
+ // custom theme state
84
+ kind === customThemeOptions && (0, _typeof2.default)(id) === 'object' ||
85
+ // other theme states
86
+ isThemeKind(kind) && typeof id === 'string' && isThemeIds(id)) {
87
+ return themeString + "".concat(themeString ? ' ' : '') + "".concat(kind, ":").concat((0, _typeof2.default)(id) === 'object' ? JSON.stringify(id) : id);
88
+ }
89
+ return themeString;
72
90
  }, '');
73
91
  };
74
92
  exports.themeObjectToString = themeObjectToString;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/tokens",
3
- "version": "1.13.2",
3
+ "version": "1.14.0",
4
4
  "sideEffects": [
5
5
  "**/*.css"
6
6
  ]
@@ -1,7 +1,7 @@
1
1
  import warnOnce from '@atlaskit/ds-lib/warn-once';
2
2
  import tokens from './artifacts/token-names';
3
3
  const name = "@atlaskit/tokens";
4
- const version = "1.13.2";
4
+ const version = "1.14.0";
5
5
  /**
6
6
  * Takes a dot-separated token name and and an optional fallback, and returns the current computed CSS value for the
7
7
  * resulting CSS Custom Property.
@@ -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 = "1.13.2";
5
+ const version = "1.14.0";
6
6
  /**
7
7
  * Takes a dot-separated token name and an optional fallback, and returns the CSS custom property for the corresponding token.
8
8
  * This should be used to implement design decisions throughout your application.
@@ -1,5 +1,6 @@
1
1
  import { themeIds } from './theme-config';
2
2
  const themeKinds = ['light', 'dark', 'spacing', 'typography', 'shape'];
3
+ const customThemeOptions = 'UNSAFE_themeOptions';
3
4
  const isThemeKind = themeKind => {
4
5
  return themeKinds.find(kind => kind === themeKind) !== undefined;
5
6
  };
@@ -22,7 +23,7 @@ const isColorMode = modeId => {
22
23
  * ```
23
24
  */
24
25
  export const themeStringToObject = themeState => {
25
- return themeState.split(' ').map(theme => theme.split(':')).reduce((themeObject, [kind, id]) => {
26
+ return themeState.split(' ').map(theme => theme.split(/:(.*)/s)).reduce((themeObject, [kind, id]) => {
26
27
  if (kind === 'colorMode' && isColorMode(id)) {
27
28
  themeObject[kind] = id;
28
29
  }
@@ -30,6 +31,13 @@ export const themeStringToObject = themeState => {
30
31
  // @ts-expect-error FIXME - this is a valid ts error
31
32
  themeObject[kind] = id;
32
33
  }
34
+ if (kind === customThemeOptions) {
35
+ try {
36
+ themeObject[customThemeOptions] = JSON.parse(id);
37
+ } catch (e) {
38
+ new Error('Invalid custom theme string');
39
+ }
40
+ }
33
41
  return themeObject;
34
42
  }, {});
35
43
  };
@@ -45,6 +53,15 @@ export const themeStringToObject = themeState => {
45
53
  * // returns 'dark:dark light:legacy-light spacing:spacing'
46
54
  * ```
47
55
  */
48
- export const themeObjectToString = themeState => {
49
- return Object.entries(themeState).reduce((themeString, [kind, id]) => (kind === 'colorMode' || isThemeKind(kind)) && typeof id === 'string' && (isThemeIds(id) || isColorMode(id)) ? themeString + `${themeString ? ' ' : ''}` + `${kind}:${id}` : themeString, '');
50
- };
56
+ export const themeObjectToString = themeState => Object.entries(themeState).reduce((themeString, [kind, id]) => {
57
+ if (
58
+ // colorMode theme state
59
+ kind === 'colorMode' && typeof id === 'string' && isColorMode(id) ||
60
+ // custom theme state
61
+ kind === customThemeOptions && typeof id === 'object' ||
62
+ // other theme states
63
+ isThemeKind(kind) && typeof id === 'string' && isThemeIds(id)) {
64
+ return themeString + `${themeString ? ' ' : ''}` + `${kind}:${typeof id === 'object' ? JSON.stringify(id) : id}`;
65
+ }
66
+ return themeString;
67
+ }, '');
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/tokens",
3
- "version": "1.13.2",
3
+ "version": "1.14.0",
4
4
  "sideEffects": [
5
5
  "**/*.css"
6
6
  ]
@@ -1,7 +1,7 @@
1
1
  import warnOnce from '@atlaskit/ds-lib/warn-once';
2
2
  import tokens from './artifacts/token-names';
3
3
  var name = "@atlaskit/tokens";
4
- var version = "1.13.2";
4
+ var version = "1.14.0";
5
5
  /**
6
6
  * Takes a dot-separated token name and and an optional fallback, and returns the current computed CSS value for the
7
7
  * resulting CSS Custom Property.
@@ -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 = "1.13.2";
5
+ var version = "1.14.0";
6
6
  /**
7
7
  * Takes a dot-separated token name and an optional fallback, and returns the CSS custom property for the corresponding token.
8
8
  * This should be used to implement design decisions throughout your application.
@@ -1,6 +1,8 @@
1
+ import _typeof from "@babel/runtime/helpers/typeof";
1
2
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
3
  import { themeIds } from './theme-config';
3
4
  var themeKinds = ['light', 'dark', 'spacing', 'typography', 'shape'];
5
+ var customThemeOptions = 'UNSAFE_themeOptions';
4
6
  var isThemeKind = function isThemeKind(themeKind) {
5
7
  return themeKinds.find(function (kind) {
6
8
  return kind === themeKind;
@@ -28,7 +30,7 @@ var isColorMode = function isColorMode(modeId) {
28
30
  */
29
31
  export var themeStringToObject = function themeStringToObject(themeState) {
30
32
  return themeState.split(' ').map(function (theme) {
31
- return theme.split(':');
33
+ return theme.split(/:([\s\S]*)/);
32
34
  }).reduce(function (themeObject, _ref) {
33
35
  var _ref2 = _slicedToArray(_ref, 2),
34
36
  kind = _ref2[0],
@@ -40,6 +42,13 @@ export var themeStringToObject = function themeStringToObject(themeState) {
40
42
  // @ts-expect-error FIXME - this is a valid ts error
41
43
  themeObject[kind] = id;
42
44
  }
45
+ if (kind === customThemeOptions) {
46
+ try {
47
+ themeObject[customThemeOptions] = JSON.parse(id);
48
+ } catch (e) {
49
+ new Error('Invalid custom theme string');
50
+ }
51
+ }
43
52
  return themeObject;
44
53
  }, {});
45
54
  };
@@ -60,6 +69,15 @@ export var themeObjectToString = function themeObjectToString(themeState) {
60
69
  var _ref4 = _slicedToArray(_ref3, 2),
61
70
  kind = _ref4[0],
62
71
  id = _ref4[1];
63
- return (kind === 'colorMode' || isThemeKind(kind)) && typeof id === 'string' && (isThemeIds(id) || isColorMode(id)) ? themeString + "".concat(themeString ? ' ' : '') + "".concat(kind, ":").concat(id) : themeString;
72
+ if (
73
+ // colorMode theme state
74
+ kind === 'colorMode' && typeof id === 'string' && isColorMode(id) ||
75
+ // custom theme state
76
+ kind === customThemeOptions && _typeof(id) === 'object' ||
77
+ // other theme states
78
+ isThemeKind(kind) && typeof id === 'string' && isThemeIds(id)) {
79
+ return themeString + "".concat(themeString ? ' ' : '') + "".concat(kind, ":").concat(_typeof(id) === 'object' ? JSON.stringify(id) : id);
80
+ }
81
+ return themeString;
64
82
  }, '');
65
83
  };
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/tokens",
3
- "version": "1.13.2",
3
+ "version": "1.14.0",
4
4
  "sideEffects": [
5
5
  "**/*.css"
6
6
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/tokens",
3
- "version": "1.13.2",
3
+ "version": "1.14.0",
4
4
  "description": "Design tokens are the single source of truth to name and store design decisions.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"