@atlaskit/tokens 0.10.1 → 0.10.2
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 +9 -0
- package/dist/cjs/constants.js +5 -3
- package/dist/cjs/get-token.js +1 -1
- package/dist/cjs/index.js +15 -1
- package/dist/cjs/set-global-theme.js +4 -3
- package/dist/cjs/theme-change-observer.js +105 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/constants.js +2 -1
- package/dist/es2019/get-token.js +1 -1
- package/dist/es2019/index.js +2 -1
- package/dist/es2019/set-global-theme.js +4 -3
- package/dist/es2019/theme-change-observer.js +67 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/constants.js +2 -1
- package/dist/esm/get-token.js +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/set-global-theme.js +4 -3
- package/dist/esm/theme-change-observer.js +89 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/constants.d.ts +3 -2
- package/dist/types/index.d.ts +2 -0
- package/dist/types/set-global-theme.d.ts +2 -1
- package/dist/types/theme-change-observer.d.ts +35 -0
- package/dist/types/types.d.ts +2 -0
- package/package.json +7 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
# @atlaskit/tokens
|
|
2
2
|
|
|
3
|
+
## 0.10.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`5b8212f08b0`](https://bitbucket.org/atlassian/atlassian-frontend/commits/5b8212f08b0) - The current theme can now be accessed and monitored for changes using new exports.
|
|
8
|
+
|
|
9
|
+
- `useThemeObserver` React hook
|
|
10
|
+
- `ThemeMutationObserver` Mutation Observer
|
|
11
|
+
|
|
3
12
|
## 0.10.1
|
|
4
13
|
|
|
5
14
|
### Patch Changes
|
package/dist/cjs/constants.js
CHANGED
|
@@ -3,9 +3,11 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
7
|
-
var
|
|
8
|
-
exports.
|
|
6
|
+
exports.THEME_DATA_ATTRIBUTE = exports.THEMES = exports.LONG_SHORT_MAPPING = exports.DEFAULT_THEME = exports.CSS_PREFIX = void 0;
|
|
7
|
+
var THEMES = ['light', 'dark'];
|
|
8
|
+
exports.THEMES = THEMES;
|
|
9
|
+
var THEME_DATA_ATTRIBUTE = 'data-theme';
|
|
10
|
+
exports.THEME_DATA_ATTRIBUTE = THEME_DATA_ATTRIBUTE;
|
|
9
11
|
var DEFAULT_THEME = 'light';
|
|
10
12
|
exports.DEFAULT_THEME = DEFAULT_THEME;
|
|
11
13
|
var CSS_PREFIX = 'ds'; // Maps the longer theme name to a shorthand used in css/code
|
package/dist/cjs/get-token.js
CHANGED
|
@@ -12,7 +12,7 @@ var _warnOnce = _interopRequireDefault(require("@atlaskit/ds-lib/warn-once"));
|
|
|
12
12
|
var _tokenNames = _interopRequireDefault(require("./artifacts/token-names"));
|
|
13
13
|
|
|
14
14
|
var name = "@atlaskit/tokens";
|
|
15
|
-
var version = "0.10.
|
|
15
|
+
var version = "0.10.2";
|
|
16
16
|
|
|
17
17
|
function token(path, fallback) {
|
|
18
18
|
var token = _tokenNames.default[path];
|
package/dist/cjs/index.js
CHANGED
|
@@ -5,6 +5,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
+
Object.defineProperty(exports, "ThemeMutationObserver", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return _themeChangeObserver.ThemeMutationObserver;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
8
14
|
Object.defineProperty(exports, "setGlobalTheme", {
|
|
9
15
|
enumerable: true,
|
|
10
16
|
get: function get() {
|
|
@@ -17,7 +23,15 @@ Object.defineProperty(exports, "token", {
|
|
|
17
23
|
return _getToken.default;
|
|
18
24
|
}
|
|
19
25
|
});
|
|
26
|
+
Object.defineProperty(exports, "useThemeObserver", {
|
|
27
|
+
enumerable: true,
|
|
28
|
+
get: function get() {
|
|
29
|
+
return _themeChangeObserver.useThemeObserver;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
20
32
|
|
|
21
33
|
var _getToken = _interopRequireDefault(require("./get-token"));
|
|
22
34
|
|
|
23
|
-
var _setGlobalTheme = _interopRequireDefault(require("./set-global-theme"));
|
|
35
|
+
var _setGlobalTheme = _interopRequireDefault(require("./set-global-theme"));
|
|
36
|
+
|
|
37
|
+
var _themeChangeObserver = require("./theme-change-observer");
|
|
@@ -5,11 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _constants = require("./constants");
|
|
9
|
+
|
|
8
10
|
var setGlobalTheme = function setGlobalTheme(theme) {
|
|
9
11
|
if (process.env.NODE_ENV !== 'production') {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
throw new Error("setGlobalTheme only accepts 'light' or 'dark' themes");
|
|
12
|
+
if (!_constants.THEMES.includes(theme)) {
|
|
13
|
+
throw new Error("setGlobalTheme only accepts themes: ".concat(_constants.THEMES.join(', ')));
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.useThemeObserver = exports.ThemeMutationObserver = void 0;
|
|
9
|
+
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
|
|
12
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
13
|
+
|
|
14
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
15
|
+
|
|
16
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
|
+
|
|
18
|
+
var _react = require("react");
|
|
19
|
+
|
|
20
|
+
var _constants = require("./constants");
|
|
21
|
+
|
|
22
|
+
var getGlobalTheme = function getGlobalTheme() {
|
|
23
|
+
return typeof document !== 'undefined' ? document.documentElement.getAttribute(_constants.THEME_DATA_ATTRIBUTE) : null;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* A MutationObserver which watches the `<html>` element for changes to the theme.
|
|
27
|
+
*
|
|
28
|
+
* In React, use the {@link useThemeObserver `useThemeObserver`} hook instead.
|
|
29
|
+
*
|
|
30
|
+
* @param {function} callback - A callback function which fires when the theme changes.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```
|
|
34
|
+
* const observer = new ThemeMutationObserver((theme) => {});
|
|
35
|
+
* observer.observe();
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
var ThemeMutationObserver = /*#__PURE__*/function () {
|
|
41
|
+
function ThemeMutationObserver(callback) {
|
|
42
|
+
(0, _classCallCheck2.default)(this, ThemeMutationObserver);
|
|
43
|
+
(0, _defineProperty2.default)(this, "observer", null);
|
|
44
|
+
this.callback = callback;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
(0, _createClass2.default)(ThemeMutationObserver, [{
|
|
48
|
+
key: "observe",
|
|
49
|
+
value: function observe() {
|
|
50
|
+
var _this = this;
|
|
51
|
+
|
|
52
|
+
if (!this.observer) {
|
|
53
|
+
this.observer = new MutationObserver(function () {
|
|
54
|
+
_this.callback(getGlobalTheme());
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
this.observer.observe(document.documentElement, {
|
|
59
|
+
attributeFilter: [_constants.THEME_DATA_ATTRIBUTE]
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}, {
|
|
63
|
+
key: "disconnect",
|
|
64
|
+
value: function disconnect() {
|
|
65
|
+
this.observer && this.observer.disconnect();
|
|
66
|
+
}
|
|
67
|
+
}]);
|
|
68
|
+
return ThemeMutationObserver;
|
|
69
|
+
}();
|
|
70
|
+
/**
|
|
71
|
+
* A React hook which returns the current theme set on `<html>`, or `null` if not set.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```
|
|
75
|
+
* const theme = useThemeObserver(); // Returns 'light' or 'dark'
|
|
76
|
+
*
|
|
77
|
+
* // Performing side effects when it changes
|
|
78
|
+
* useEffect(() => {
|
|
79
|
+
* console.log(`The theme has changed to ${theme}`);
|
|
80
|
+
* }, [theme]);
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
exports.ThemeMutationObserver = ThemeMutationObserver;
|
|
86
|
+
|
|
87
|
+
var useThemeObserver = function useThemeObserver() {
|
|
88
|
+
var _useState = (0, _react.useState)(getGlobalTheme()),
|
|
89
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
90
|
+
theme = _useState2[0],
|
|
91
|
+
setTheme = _useState2[1];
|
|
92
|
+
|
|
93
|
+
(0, _react.useEffect)(function () {
|
|
94
|
+
var observer = new ThemeMutationObserver(function (theme) {
|
|
95
|
+
return setTheme(theme);
|
|
96
|
+
});
|
|
97
|
+
observer.observe();
|
|
98
|
+
return function () {
|
|
99
|
+
return observer.disconnect();
|
|
100
|
+
};
|
|
101
|
+
}, []);
|
|
102
|
+
return theme;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
exports.useThemeObserver = useThemeObserver;
|
package/dist/cjs/version.json
CHANGED
package/dist/es2019/constants.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export const
|
|
1
|
+
export const THEMES = ['light', 'dark'];
|
|
2
|
+
export const THEME_DATA_ATTRIBUTE = 'data-theme';
|
|
2
3
|
export const DEFAULT_THEME = 'light';
|
|
3
4
|
export const CSS_PREFIX = 'ds'; // Maps the longer theme name to a shorthand used in css/code
|
|
4
5
|
|
package/dist/es2019/get-token.js
CHANGED
package/dist/es2019/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { THEMES } from './constants';
|
|
2
|
+
|
|
1
3
|
const setGlobalTheme = theme => {
|
|
2
4
|
if (process.env.NODE_ENV !== 'production') {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
throw new Error("setGlobalTheme only accepts 'light' or 'dark' themes");
|
|
5
|
+
if (!THEMES.includes(theme)) {
|
|
6
|
+
throw new Error(`setGlobalTheme only accepts themes: ${THEMES.join(', ')}`);
|
|
6
7
|
}
|
|
7
8
|
}
|
|
8
9
|
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { THEME_DATA_ATTRIBUTE } from './constants';
|
|
4
|
+
|
|
5
|
+
const getGlobalTheme = () => typeof document !== 'undefined' ? document.documentElement.getAttribute(THEME_DATA_ATTRIBUTE) : null;
|
|
6
|
+
/**
|
|
7
|
+
* A MutationObserver which watches the `<html>` element for changes to the theme.
|
|
8
|
+
*
|
|
9
|
+
* In React, use the {@link useThemeObserver `useThemeObserver`} hook instead.
|
|
10
|
+
*
|
|
11
|
+
* @param {function} callback - A callback function which fires when the theme changes.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```
|
|
15
|
+
* const observer = new ThemeMutationObserver((theme) => {});
|
|
16
|
+
* observer.observe();
|
|
17
|
+
* ```
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export class ThemeMutationObserver {
|
|
22
|
+
constructor(callback) {
|
|
23
|
+
_defineProperty(this, "observer", null);
|
|
24
|
+
|
|
25
|
+
this.callback = callback;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
observe() {
|
|
29
|
+
if (!this.observer) {
|
|
30
|
+
this.observer = new MutationObserver(() => {
|
|
31
|
+
this.callback(getGlobalTheme());
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
this.observer.observe(document.documentElement, {
|
|
36
|
+
attributeFilter: [THEME_DATA_ATTRIBUTE]
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
disconnect() {
|
|
41
|
+
this.observer && this.observer.disconnect();
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* A React hook which returns the current theme set on `<html>`, or `null` if not set.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```
|
|
50
|
+
* const theme = useThemeObserver(); // Returns 'light' or 'dark'
|
|
51
|
+
*
|
|
52
|
+
* // Performing side effects when it changes
|
|
53
|
+
* useEffect(() => {
|
|
54
|
+
* console.log(`The theme has changed to ${theme}`);
|
|
55
|
+
* }, [theme]);
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
export const useThemeObserver = () => {
|
|
60
|
+
const [theme, setTheme] = useState(getGlobalTheme());
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
const observer = new ThemeMutationObserver(theme => setTheme(theme));
|
|
63
|
+
observer.observe();
|
|
64
|
+
return () => observer.disconnect();
|
|
65
|
+
}, []);
|
|
66
|
+
return theme;
|
|
67
|
+
};
|
package/dist/es2019/version.json
CHANGED
package/dist/esm/constants.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export var
|
|
1
|
+
export var THEMES = ['light', 'dark'];
|
|
2
|
+
export var THEME_DATA_ATTRIBUTE = 'data-theme';
|
|
2
3
|
export var DEFAULT_THEME = 'light';
|
|
3
4
|
export var CSS_PREFIX = 'ds'; // Maps the longer theme name to a shorthand used in css/code
|
|
4
5
|
|
package/dist/esm/get-token.js
CHANGED
package/dist/esm/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { THEMES } from './constants';
|
|
2
|
+
|
|
1
3
|
var setGlobalTheme = function setGlobalTheme(theme) {
|
|
2
4
|
if (process.env.NODE_ENV !== 'production') {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
throw new Error("setGlobalTheme only accepts 'light' or 'dark' themes");
|
|
5
|
+
if (!THEMES.includes(theme)) {
|
|
6
|
+
throw new Error("setGlobalTheme only accepts themes: ".concat(THEMES.join(', ')));
|
|
6
7
|
}
|
|
7
8
|
}
|
|
8
9
|
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
3
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
4
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
5
|
+
import { useEffect, useState } from 'react';
|
|
6
|
+
import { THEME_DATA_ATTRIBUTE } from './constants';
|
|
7
|
+
|
|
8
|
+
var getGlobalTheme = function getGlobalTheme() {
|
|
9
|
+
return typeof document !== 'undefined' ? document.documentElement.getAttribute(THEME_DATA_ATTRIBUTE) : null;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* A MutationObserver which watches the `<html>` element for changes to the theme.
|
|
13
|
+
*
|
|
14
|
+
* In React, use the {@link useThemeObserver `useThemeObserver`} hook instead.
|
|
15
|
+
*
|
|
16
|
+
* @param {function} callback - A callback function which fires when the theme changes.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```
|
|
20
|
+
* const observer = new ThemeMutationObserver((theme) => {});
|
|
21
|
+
* observer.observe();
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
export var ThemeMutationObserver = /*#__PURE__*/function () {
|
|
27
|
+
function ThemeMutationObserver(callback) {
|
|
28
|
+
_classCallCheck(this, ThemeMutationObserver);
|
|
29
|
+
|
|
30
|
+
_defineProperty(this, "observer", null);
|
|
31
|
+
|
|
32
|
+
this.callback = callback;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
_createClass(ThemeMutationObserver, [{
|
|
36
|
+
key: "observe",
|
|
37
|
+
value: function observe() {
|
|
38
|
+
var _this = this;
|
|
39
|
+
|
|
40
|
+
if (!this.observer) {
|
|
41
|
+
this.observer = new MutationObserver(function () {
|
|
42
|
+
_this.callback(getGlobalTheme());
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
this.observer.observe(document.documentElement, {
|
|
47
|
+
attributeFilter: [THEME_DATA_ATTRIBUTE]
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}, {
|
|
51
|
+
key: "disconnect",
|
|
52
|
+
value: function disconnect() {
|
|
53
|
+
this.observer && this.observer.disconnect();
|
|
54
|
+
}
|
|
55
|
+
}]);
|
|
56
|
+
|
|
57
|
+
return ThemeMutationObserver;
|
|
58
|
+
}();
|
|
59
|
+
/**
|
|
60
|
+
* A React hook which returns the current theme set on `<html>`, or `null` if not set.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```
|
|
64
|
+
* const theme = useThemeObserver(); // Returns 'light' or 'dark'
|
|
65
|
+
*
|
|
66
|
+
* // Performing side effects when it changes
|
|
67
|
+
* useEffect(() => {
|
|
68
|
+
* console.log(`The theme has changed to ${theme}`);
|
|
69
|
+
* }, [theme]);
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
|
|
73
|
+
export var useThemeObserver = function useThemeObserver() {
|
|
74
|
+
var _useState = useState(getGlobalTheme()),
|
|
75
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
76
|
+
theme = _useState2[0],
|
|
77
|
+
setTheme = _useState2[1];
|
|
78
|
+
|
|
79
|
+
useEffect(function () {
|
|
80
|
+
var observer = new ThemeMutationObserver(function (theme) {
|
|
81
|
+
return setTheme(theme);
|
|
82
|
+
});
|
|
83
|
+
observer.observe();
|
|
84
|
+
return function () {
|
|
85
|
+
return observer.disconnect();
|
|
86
|
+
};
|
|
87
|
+
}, []);
|
|
88
|
+
return theme;
|
|
89
|
+
};
|
package/dist/esm/version.json
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const THEMES: readonly ["light", "dark"];
|
|
2
|
+
export declare const THEME_DATA_ATTRIBUTE = "data-theme";
|
|
2
3
|
export declare const DEFAULT_THEME = "light";
|
|
3
4
|
export declare const CSS_PREFIX = "ds";
|
|
4
|
-
export declare const LONG_SHORT_MAPPING: Record<string,
|
|
5
|
+
export declare const LONG_SHORT_MAPPING: Record<string, typeof THEMES[number]>;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { default as token } from './get-token';
|
|
2
2
|
export { default as setGlobalTheme } from './set-global-theme';
|
|
3
3
|
export type { CSSToken } from './artifacts/token-names';
|
|
4
|
+
export type { Themes } from './types';
|
|
5
|
+
export { useThemeObserver, ThemeMutationObserver, } from './theme-change-observer';
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { Themes } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* A MutationObserver which watches the `<html>` element for changes to the theme.
|
|
4
|
+
*
|
|
5
|
+
* In React, use the {@link useThemeObserver `useThemeObserver`} hook instead.
|
|
6
|
+
*
|
|
7
|
+
* @param {function} callback - A callback function which fires when the theme changes.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```
|
|
11
|
+
* const observer = new ThemeMutationObserver((theme) => {});
|
|
12
|
+
* observer.observe();
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export declare class ThemeMutationObserver {
|
|
16
|
+
private callback;
|
|
17
|
+
observer: MutationObserver | null;
|
|
18
|
+
constructor(callback: (theme: Themes | null) => unknown);
|
|
19
|
+
observe(): void;
|
|
20
|
+
disconnect(): void;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A React hook which returns the current theme set on `<html>`, or `null` if not set.
|
|
24
|
+
*
|
|
25
|
+
* @example
|
|
26
|
+
* ```
|
|
27
|
+
* const theme = useThemeObserver(); // Returns 'light' or 'dark'
|
|
28
|
+
*
|
|
29
|
+
* // Performing side effects when it changes
|
|
30
|
+
* useEffect(() => {
|
|
31
|
+
* console.log(`The theme has changed to ${theme}`);
|
|
32
|
+
* }, [theme]);
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const useThemeObserver: () => Themes | null;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { InternalTokenIds } from './artifacts/types-internal';
|
|
2
|
+
import { THEMES } from './constants';
|
|
2
3
|
export declare type Groups = 'raw' | 'paint' | 'shadow' | 'palette';
|
|
3
4
|
export declare type ActiveTokenState = 'active';
|
|
4
5
|
export declare type DeprecatedTokenState = 'deprecated';
|
|
@@ -6,6 +7,7 @@ export declare type DeletedTokenState = 'deleted';
|
|
|
6
7
|
export declare type TokenState = ActiveTokenState | DeprecatedTokenState | DeletedTokenState;
|
|
7
8
|
export declare type Replacement = InternalTokenIds | InternalTokenIds[];
|
|
8
9
|
export declare type PaletteCategory = 'blue' | 'purple' | 'red' | 'magenta' | 'orange' | 'yellow' | 'green' | 'teal' | 'light mode neutral' | 'dark mode neutral';
|
|
10
|
+
export declare type Themes = typeof THEMES[number];
|
|
9
11
|
export interface Token<TValue, Group extends Groups> {
|
|
10
12
|
value: TValue;
|
|
11
13
|
attributes: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/tokens",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.2",
|
|
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",
|
|
@@ -47,6 +47,9 @@
|
|
|
47
47
|
"@babel/traverse": "^7.15.0",
|
|
48
48
|
"@babel/types": "^7.15.0"
|
|
49
49
|
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"react": "^16.8.0"
|
|
52
|
+
},
|
|
50
53
|
"devDependencies": {
|
|
51
54
|
"@af/codegen": "*",
|
|
52
55
|
"@atlaskit/badge": "^15.0.11",
|
|
@@ -69,6 +72,9 @@
|
|
|
69
72
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
|
70
73
|
"@babel/core": "^7.12.3",
|
|
71
74
|
"@emotion/core": "^10.0.9",
|
|
75
|
+
"@testing-library/dom": "^7.7.3",
|
|
76
|
+
"@testing-library/react": "^8.0.1",
|
|
77
|
+
"@testing-library/react-hooks": "^1.0.4",
|
|
72
78
|
"@types/chrome": "^0.0.171",
|
|
73
79
|
"copy-webpack-plugin": "^6.4.0",
|
|
74
80
|
"lodash": "^4.17.21",
|