@atlaskit/tokens 1.13.1 → 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 +12 -0
- package/dist/cjs/custom-theme.js +17 -13
- package/dist/cjs/get-global-theme.js +4 -3
- package/dist/cjs/get-ssr-auto-script.js +21 -0
- package/dist/cjs/get-theme-html-attrs.js +76 -0
- package/dist/cjs/get-theme-styles.js +139 -0
- package/dist/cjs/get-token-value.js +1 -1
- package/dist/cjs/get-token.js +1 -1
- package/dist/cjs/index.js +15 -15
- package/dist/cjs/set-global-theme.js +9 -242
- package/dist/cjs/theme-config.js +23 -1
- package/dist/cjs/theme-mutation-observer.js +4 -4
- package/dist/cjs/{utils/theme-state-transformer.js → theme-state-transformer.js} +21 -3
- package/dist/cjs/use-theme-observer.js +7 -6
- package/dist/cjs/utils/get-theme-preferences.js +35 -0
- package/dist/cjs/utils/theme-loading.js +4 -2
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/custom-theme.js +10 -10
- package/dist/es2019/get-global-theme.js +4 -3
- package/dist/es2019/get-ssr-auto-script.js +23 -0
- package/dist/es2019/get-theme-html-attrs.js +62 -0
- package/dist/es2019/get-theme-styles.js +72 -0
- package/dist/es2019/get-token-value.js +1 -1
- package/dist/es2019/get-token.js +1 -1
- package/dist/es2019/index.js +9 -6
- package/dist/es2019/set-global-theme.js +5 -185
- package/dist/es2019/theme-config.js +21 -0
- package/dist/es2019/theme-mutation-observer.js +2 -2
- package/dist/es2019/{utils/theme-state-transformer.js → theme-state-transformer.js} +22 -5
- package/dist/es2019/use-theme-observer.js +5 -4
- package/dist/es2019/utils/get-theme-preferences.js +28 -0
- package/dist/es2019/utils/theme-loading.js +2 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/custom-theme.js +15 -11
- package/dist/esm/get-global-theme.js +4 -3
- package/dist/esm/get-ssr-auto-script.js +15 -0
- package/dist/esm/get-theme-html-attrs.js +68 -0
- package/dist/esm/get-theme-styles.js +126 -0
- package/dist/esm/get-token-value.js +1 -1
- package/dist/esm/get-token.js +1 -1
- package/dist/esm/index.js +9 -6
- package/dist/esm/set-global-theme.js +6 -233
- package/dist/esm/theme-config.js +21 -0
- package/dist/esm/theme-mutation-observer.js +4 -3
- package/dist/esm/{utils/theme-state-transformer.js → theme-state-transformer.js} +21 -3
- package/dist/esm/use-theme-observer.js +5 -4
- package/dist/esm/utils/get-theme-preferences.js +27 -0
- package/dist/esm/utils/theme-loading.js +2 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/custom-theme.d.ts +4 -9
- package/dist/types/get-global-theme.d.ts +2 -1
- package/dist/types/get-ssr-auto-script.d.ts +11 -0
- package/dist/types/get-theme-html-attrs.d.ts +17 -0
- package/dist/types/get-theme-styles.d.ts +24 -0
- package/dist/types/index.d.ts +10 -9
- package/dist/types/set-global-theme.d.ts +1 -58
- package/dist/types/theme-config.d.ts +24 -0
- package/dist/types/theme-mutation-observer.d.ts +1 -1
- package/dist/{types-ts4.5/utils → types}/theme-state-transformer.d.ts +1 -1
- package/dist/types/use-theme-observer.d.ts +2 -1
- package/dist/types/utils/custom-theme-loading-utils.d.ts +2 -3
- package/dist/types/utils/generate-custom-color-ramp.d.ts +1 -2
- package/dist/types/utils/get-theme-preferences.d.ts +2 -0
- package/dist/types/utils/theme-loading.d.ts +1 -0
- package/dist/types-ts4.5/custom-theme.d.ts +4 -9
- package/dist/types-ts4.5/get-global-theme.d.ts +2 -1
- package/dist/types-ts4.5/get-ssr-auto-script.d.ts +11 -0
- package/dist/types-ts4.5/get-theme-html-attrs.d.ts +17 -0
- package/dist/types-ts4.5/get-theme-styles.d.ts +24 -0
- package/dist/types-ts4.5/index.d.ts +10 -9
- package/dist/types-ts4.5/set-global-theme.d.ts +1 -58
- package/dist/types-ts4.5/theme-config.d.ts +24 -0
- package/dist/types-ts4.5/theme-mutation-observer.d.ts +1 -1
- package/dist/{types/utils → types-ts4.5}/theme-state-transformer.d.ts +1 -1
- package/dist/types-ts4.5/use-theme-observer.d.ts +2 -1
- package/dist/types-ts4.5/utils/custom-theme-loading-utils.d.ts +2 -3
- package/dist/types-ts4.5/utils/generate-custom-color-ramp.d.ts +1 -2
- package/dist/types-ts4.5/utils/get-theme-preferences.d.ts +2 -0
- package/dist/types-ts4.5/utils/theme-loading.d.ts +1 -0
- package/package.json +1 -1
- package/report.api.md +8 -8
- package/tmp/api-report-tmp.d.ts +1158 -0
package/dist/esm/version.json
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ThemeStyles } from './get-theme-styles';
|
|
2
|
+
import { ThemeOptionsSchema, ThemeState } from './theme-config';
|
|
2
3
|
export declare const CUSTOM_STYLE_ELEMENTS_SIZE_THRESHOLD = 10;
|
|
3
|
-
type HEX = `#${string}`;
|
|
4
|
-
export type CSSColor = HEX;
|
|
5
|
-
export interface CustomBrandSchema {
|
|
6
|
-
brandColor: CSSColor;
|
|
7
|
-
}
|
|
8
4
|
/**
|
|
9
5
|
*
|
|
10
6
|
* @param themeSchema The schema of available themes
|
|
@@ -22,9 +18,8 @@ export interface CustomBrandSchema {
|
|
|
22
18
|
* If an error is encountered while loading themes, the themes array will be empty.
|
|
23
19
|
*/
|
|
24
20
|
export declare function getCustomThemeStyles(themeState: Partial<ThemeState> & {
|
|
25
|
-
UNSAFE_themeOptions:
|
|
21
|
+
UNSAFE_themeOptions: ThemeOptionsSchema;
|
|
26
22
|
}): Promise<ThemeStyles[]>;
|
|
27
23
|
export declare function loadAndAppendCustomThemeCss(themeState: Partial<ThemeState> & {
|
|
28
|
-
UNSAFE_themeOptions:
|
|
24
|
+
UNSAFE_themeOptions: ThemeOptionsSchema;
|
|
29
25
|
}): Promise<void>;
|
|
30
|
-
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ThemeState } from './theme-config';
|
|
2
|
+
/**
|
|
3
|
+
* Provides a script that, when executed before paint, sets the `data-color-mode` attribute based on the current system theme,
|
|
4
|
+
* to enable SSR support for automatic theme switching, avoid a flash of un-themed content on first paint.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
|
|
7
|
+
*
|
|
8
|
+
* @returns {string} A string to be added to the innerHTML of a script tag in the document head
|
|
9
|
+
*/
|
|
10
|
+
declare const getSSRAutoScript: (colorMode: ThemeState['colorMode']) => string | undefined;
|
|
11
|
+
export default getSSRAutoScript;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ThemeState } from './theme-config';
|
|
2
|
+
/**
|
|
3
|
+
* Server-side rendering utility. Generates the valid HTML attributes for a given theme.
|
|
4
|
+
* Note: this utility does not handle automatic theme switching.
|
|
5
|
+
*
|
|
6
|
+
* @param {Object<string, string>} themeOptions - Theme options object
|
|
7
|
+
* @param {string} themeState.colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
|
|
8
|
+
* @param {string} themeState.dark The color theme to be applied when the color mode resolves to 'dark'.
|
|
9
|
+
* @param {string} themeState.light The color theme to be applied when the color mode resolves to 'light'.
|
|
10
|
+
* @param {string} themeState.spacing The spacing theme to be applied.
|
|
11
|
+
* @param {string} themeState.typography The typography theme to be applied.
|
|
12
|
+
* @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
|
|
13
|
+
*
|
|
14
|
+
* @returns {Object} Object of HTML attributes to be applied to the document root
|
|
15
|
+
*/
|
|
16
|
+
declare const getThemeHtmlAttrs: ({ colorMode, dark, light, shape, spacing, typography, UNSAFE_themeOptions, }?: Partial<ThemeState>) => Record<string, string>;
|
|
17
|
+
export default getThemeHtmlAttrs;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ThemeIdsWithOverrides, ThemeState } from './theme-config';
|
|
2
|
+
export interface ThemeStyles {
|
|
3
|
+
id: ThemeIdsWithOverrides;
|
|
4
|
+
attrs: Record<string, string>;
|
|
5
|
+
css: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Takes an object containing theme preferences, and returns an array of objects for use in applying styles to the document head.
|
|
9
|
+
* Only supplies the color themes necessary for initial render, based on the current themeState. I.e. if in light mode, dark mode themes are not returned.
|
|
10
|
+
*
|
|
11
|
+
* @param {Object<string, string>} themeState The themes and color mode that should be applied.
|
|
12
|
+
* @param {string} themeState.colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
|
|
13
|
+
* @param {string} themeState.dark The color theme to be applied when the color mode resolves to 'dark'.
|
|
14
|
+
* @param {string} themeState.light The color theme to be applied when the color mode resolves to 'light'.
|
|
15
|
+
* @param {string} themeState.shape The shape theme to be applied.
|
|
16
|
+
* @param {string} themeState.spacing The spacing theme to be applied.
|
|
17
|
+
* @param {string} themeState.typography The typography theme to be applied.
|
|
18
|
+
* @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
|
|
19
|
+
*
|
|
20
|
+
* @returns A Promise of an object array, containing theme IDs, data-attributes to attach to the theme, and the theme CSS.
|
|
21
|
+
* If an error is encountered while loading themes, the themes array will be empty.
|
|
22
|
+
*/
|
|
23
|
+
declare const getThemeStyles: (preferences?: Partial<ThemeState> | 'all') => Promise<ThemeStyles[]>;
|
|
24
|
+
export default getThemeStyles;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
export { default as themeConfig } from './theme-config';
|
|
1
2
|
export { default as token } from './get-token';
|
|
2
3
|
export { default as getTokenValue } from './get-token-value';
|
|
3
|
-
export { default as setGlobalTheme
|
|
4
|
-
export
|
|
4
|
+
export { default as setGlobalTheme } from './set-global-theme';
|
|
5
|
+
export { default as getThemeStyles } from './get-theme-styles';
|
|
6
|
+
export { default as getThemeHtmlAttrs } from './get-theme-html-attrs';
|
|
7
|
+
export { default as getSSRAutoScript } from './get-ssr-auto-script';
|
|
8
|
+
export { default as useThemeObserver } from './use-theme-observer';
|
|
9
|
+
export { default as ThemeMutationObserver } from './theme-mutation-observer';
|
|
10
|
+
export { default as getGlobalTheme } from './get-global-theme';
|
|
11
|
+
export { themeStringToObject, themeObjectToString, } from './theme-state-transformer';
|
|
5
12
|
export type { CSSToken } from './artifacts/token-names';
|
|
6
13
|
export type { ActiveTokens } from './artifacts/types';
|
|
7
|
-
export type { ThemeColorModes, Themes, ThemeIds } from './theme-config';
|
|
14
|
+
export type { ThemeColorModes, Themes, ThemeIds, ThemeOptionsSchema, ThemeState, } from './theme-config';
|
|
8
15
|
export type { Groups, OpacityToken, PaintToken, RawToken, ShadowToken, SpacingToken, ShapeToken, } from './types';
|
|
9
|
-
export type { CustomBrandSchema } from './custom-theme';
|
|
10
|
-
export { default as themeConfig } from './theme-config';
|
|
11
|
-
export { useThemeObserver } from './use-theme-observer';
|
|
12
|
-
export { ThemeMutationObserver } from './theme-mutation-observer';
|
|
13
|
-
export { getGlobalTheme } from './get-global-theme';
|
|
14
|
-
export { themeStringToObject, themeObjectToString, } from './utils/theme-state-transformer';
|
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
import { UnbindFn } from 'bind-event-listener';
|
|
2
|
-
import {
|
|
3
|
-
import { ThemeColorModes, ThemeIds, ThemeIdsWithOverrides } from './theme-config';
|
|
4
|
-
export interface ThemeState {
|
|
5
|
-
light: Extract<ThemeIds, 'light' | 'dark' | 'legacy-dark' | 'legacy-light'>;
|
|
6
|
-
dark: Extract<ThemeIds, 'light' | 'dark' | 'legacy-dark' | 'legacy-light'>;
|
|
7
|
-
colorMode: ThemeColorModes;
|
|
8
|
-
shape?: Extract<ThemeIds, 'shape'>;
|
|
9
|
-
spacing?: Extract<ThemeIds, 'spacing'>;
|
|
10
|
-
typography?: Extract<ThemeIds, 'typography'>;
|
|
11
|
-
UNSAFE_themeOptions?: CustomBrandSchema;
|
|
12
|
-
}
|
|
2
|
+
import { ThemeColorModes, ThemeIdsWithOverrides, ThemeState } from './theme-config';
|
|
13
3
|
export interface ActiveThemeState extends ThemeState {
|
|
14
4
|
colorMode: Exclude<ThemeColorModes, 'auto'>;
|
|
15
5
|
}
|
|
16
|
-
export declare const themeStateDefaults: ThemeState;
|
|
17
6
|
/**
|
|
18
7
|
* Sets the theme globally at runtime. This updates the `data-theme` and `data-color-mode` attributes on your page's <html> tag.
|
|
19
8
|
*
|
|
@@ -35,50 +24,4 @@ export declare const themeStateDefaults: ThemeState;
|
|
|
35
24
|
* ```
|
|
36
25
|
*/
|
|
37
26
|
declare const setGlobalTheme: ({ colorMode, dark, light, shape, spacing, typography, UNSAFE_themeOptions, }?: Partial<ThemeState>, themeLoader?: ((id: ThemeIdsWithOverrides) => void | Promise<void>) | undefined) => Promise<UnbindFn>;
|
|
38
|
-
export interface ThemeStyles {
|
|
39
|
-
id: ThemeIdsWithOverrides;
|
|
40
|
-
attrs: Record<string, string>;
|
|
41
|
-
css: string;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Takes an object containing theme preferences, and returns an array of objects for use in applying styles to the document head.
|
|
45
|
-
* Only supplies the color themes necessary for initial render, based on the current themeState. I.e. if in light mode, dark mode themes are not returned.
|
|
46
|
-
*
|
|
47
|
-
* @param {Object<string, string>} themeState The themes and color mode that should be applied.
|
|
48
|
-
* @param {string} themeState.colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
|
|
49
|
-
* @param {string} themeState.dark The color theme to be applied when the color mode resolves to 'dark'.
|
|
50
|
-
* @param {string} themeState.light The color theme to be applied when the color mode resolves to 'light'.
|
|
51
|
-
* @param {string} themeState.shape The shape theme to be applied.
|
|
52
|
-
* @param {string} themeState.spacing The spacing theme to be applied.
|
|
53
|
-
* @param {string} themeState.typography The typography theme to be applied.
|
|
54
|
-
* @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
|
|
55
|
-
*
|
|
56
|
-
* @returns A Promise of an object array, containing theme IDs, data-attributes to attach to the theme, and the theme CSS.
|
|
57
|
-
* If an error is encountered while loading themes, the themes array will be empty.
|
|
58
|
-
*/
|
|
59
|
-
export declare const getThemeStyles: (preferences?: Partial<ThemeState> | 'all') => Promise<ThemeStyles[]>;
|
|
60
|
-
/**
|
|
61
|
-
* Server-side rendering utility. Generates the valid HTML attributes for a given theme.
|
|
62
|
-
* Note: this utility does not handle automatic theme switching.
|
|
63
|
-
*
|
|
64
|
-
* @param {Object<string, string>} themeOptions - Theme options object
|
|
65
|
-
* @param {string} themeState.colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
|
|
66
|
-
* @param {string} themeState.dark The color theme to be applied when the color mode resolves to 'dark'.
|
|
67
|
-
* @param {string} themeState.light The color theme to be applied when the color mode resolves to 'light'.
|
|
68
|
-
* @param {string} themeState.spacing The spacing theme to be applied.
|
|
69
|
-
* @param {string} themeState.typography The typography theme to be applied.
|
|
70
|
-
* @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
|
|
71
|
-
*
|
|
72
|
-
* @returns {Object} Object of HTML attributes to be applied to the document root
|
|
73
|
-
*/
|
|
74
|
-
export declare const getThemeHtmlAttrs: ({ colorMode, dark, light, shape, spacing, typography, UNSAFE_themeOptions, }?: Partial<ThemeState>) => Record<string, string>;
|
|
75
|
-
/**
|
|
76
|
-
* Provides a script that, when executed before paint, sets the `data-color-mode` attribute based on the current system theme,
|
|
77
|
-
* to enable SSR support for automatic theme switching, avoid a flash of un-themed content on first paint.
|
|
78
|
-
*
|
|
79
|
-
* @param {string} colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
|
|
80
|
-
*
|
|
81
|
-
* @returns {string} A string to be added to the innerHTML of a script tag in the document head
|
|
82
|
-
*/
|
|
83
|
-
export declare const getSSRAutoScript: (colorMode: ThemeState['colorMode']) => string | undefined;
|
|
84
27
|
export default setGlobalTheme;
|
|
@@ -77,4 +77,28 @@ interface ThemeConfig {
|
|
|
77
77
|
override?: ThemeIds;
|
|
78
78
|
}
|
|
79
79
|
declare const themeConfig: Record<Themes | ThemeOverrides, ThemeConfig>;
|
|
80
|
+
type HEX = `#${string}`;
|
|
81
|
+
export type CSSColor = HEX;
|
|
82
|
+
/**
|
|
83
|
+
* ThemeOptionsSchema: additional configuration options used to customize Atlassian's themes
|
|
84
|
+
*/
|
|
85
|
+
export interface ThemeOptionsSchema {
|
|
86
|
+
brandColor: CSSColor;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* ThemeState: the standard representation of an app's current theme and preferences
|
|
90
|
+
*/
|
|
91
|
+
export interface ThemeState {
|
|
92
|
+
light: Extract<ThemeIds, 'light' | 'dark' | 'legacy-dark' | 'legacy-light'>;
|
|
93
|
+
dark: Extract<ThemeIds, 'light' | 'dark' | 'legacy-dark' | 'legacy-light'>;
|
|
94
|
+
colorMode: ThemeColorModes;
|
|
95
|
+
shape?: Extract<ThemeIds, 'shape'>;
|
|
96
|
+
spacing?: Extract<ThemeIds, 'spacing'>;
|
|
97
|
+
typography?: Extract<ThemeIds, 'typography'>;
|
|
98
|
+
UNSAFE_themeOptions?: ThemeOptionsSchema;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* themeStateDefaults: the default values for ThemeState used by theming utilities
|
|
102
|
+
*/
|
|
103
|
+
export declare const themeStateDefaults: ThemeState;
|
|
80
104
|
export default themeConfig;
|
|
@@ -12,7 +12,7 @@ import { ActiveThemeState } from './set-global-theme';
|
|
|
12
12
|
* observer.observe();
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export default class ThemeMutationObserver {
|
|
16
16
|
private callback;
|
|
17
17
|
observer: MutationObserver | null;
|
|
18
18
|
mediaObserver: any;
|
|
@@ -12,4 +12,5 @@ import { ActiveThemeState } from './set-global-theme';
|
|
|
12
12
|
* }, [theme.colorMode]);
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
declare const useThemeObserver: () => Partial<ActiveThemeState>;
|
|
16
|
+
export default useThemeObserver;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import tokens from '../artifacts/token-names';
|
|
2
|
-
import {
|
|
3
|
-
import { ThemeColorModes } from '../theme-config';
|
|
2
|
+
import { ThemeColorModes, ThemeOptionsSchema } from '../theme-config';
|
|
4
3
|
type Token = keyof typeof tokens;
|
|
5
4
|
type ThemeAttributeId = 'light' | 'dark';
|
|
6
|
-
export declare function findMissingCustomStyleElements(UNSAFE_themeOptions:
|
|
5
|
+
export declare function findMissingCustomStyleElements(UNSAFE_themeOptions: ThemeOptionsSchema, mode: ThemeColorModes): ThemeAttributeId[];
|
|
7
6
|
export declare function limitSizeOfCustomStyleElements(sizeThreshold: number): void;
|
|
8
7
|
export declare function reduceTokenMap(tokenMap: {
|
|
9
8
|
[key in Token]?: number;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import tokens from '../artifacts/token-names';
|
|
2
|
-
import { CSSColor } from '../
|
|
3
|
-
import { ThemeColorModes } from '../theme-config';
|
|
2
|
+
import { CSSColor, ThemeColorModes } from '../theme-config';
|
|
4
3
|
type Token = keyof typeof tokens;
|
|
5
4
|
type TokenMap = {
|
|
6
5
|
[key in Token]?: number;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { ThemeIdsWithOverrides } from '../theme-config';
|
|
2
2
|
export declare const loadAndAppendThemeCss: (themeId: ThemeIdsWithOverrides) => Promise<void>;
|
|
3
3
|
export declare const loadThemeCss: (themeId: ThemeIdsWithOverrides) => Promise<string>;
|
|
4
|
+
export declare const darkModeMediaQuery = "(prefers-color-scheme: dark)";
|
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ThemeStyles } from './get-theme-styles';
|
|
2
|
+
import { ThemeOptionsSchema, ThemeState } from './theme-config';
|
|
2
3
|
export declare const CUSTOM_STYLE_ELEMENTS_SIZE_THRESHOLD = 10;
|
|
3
|
-
type HEX = `#${string}`;
|
|
4
|
-
export type CSSColor = HEX;
|
|
5
|
-
export interface CustomBrandSchema {
|
|
6
|
-
brandColor: CSSColor;
|
|
7
|
-
}
|
|
8
4
|
/**
|
|
9
5
|
*
|
|
10
6
|
* @param themeSchema The schema of available themes
|
|
@@ -22,9 +18,8 @@ export interface CustomBrandSchema {
|
|
|
22
18
|
* If an error is encountered while loading themes, the themes array will be empty.
|
|
23
19
|
*/
|
|
24
20
|
export declare function getCustomThemeStyles(themeState: Partial<ThemeState> & {
|
|
25
|
-
UNSAFE_themeOptions:
|
|
21
|
+
UNSAFE_themeOptions: ThemeOptionsSchema;
|
|
26
22
|
}): Promise<ThemeStyles[]>;
|
|
27
23
|
export declare function loadAndAppendCustomThemeCss(themeState: Partial<ThemeState> & {
|
|
28
|
-
UNSAFE_themeOptions:
|
|
24
|
+
UNSAFE_themeOptions: ThemeOptionsSchema;
|
|
29
25
|
}): Promise<void>;
|
|
30
|
-
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { ThemeState } from './theme-config';
|
|
2
|
+
/**
|
|
3
|
+
* Provides a script that, when executed before paint, sets the `data-color-mode` attribute based on the current system theme,
|
|
4
|
+
* to enable SSR support for automatic theme switching, avoid a flash of un-themed content on first paint.
|
|
5
|
+
*
|
|
6
|
+
* @param {string} colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
|
|
7
|
+
*
|
|
8
|
+
* @returns {string} A string to be added to the innerHTML of a script tag in the document head
|
|
9
|
+
*/
|
|
10
|
+
declare const getSSRAutoScript: (colorMode: ThemeState['colorMode']) => string | undefined;
|
|
11
|
+
export default getSSRAutoScript;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ThemeState } from './theme-config';
|
|
2
|
+
/**
|
|
3
|
+
* Server-side rendering utility. Generates the valid HTML attributes for a given theme.
|
|
4
|
+
* Note: this utility does not handle automatic theme switching.
|
|
5
|
+
*
|
|
6
|
+
* @param {Object<string, string>} themeOptions - Theme options object
|
|
7
|
+
* @param {string} themeState.colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
|
|
8
|
+
* @param {string} themeState.dark The color theme to be applied when the color mode resolves to 'dark'.
|
|
9
|
+
* @param {string} themeState.light The color theme to be applied when the color mode resolves to 'light'.
|
|
10
|
+
* @param {string} themeState.spacing The spacing theme to be applied.
|
|
11
|
+
* @param {string} themeState.typography The typography theme to be applied.
|
|
12
|
+
* @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
|
|
13
|
+
*
|
|
14
|
+
* @returns {Object} Object of HTML attributes to be applied to the document root
|
|
15
|
+
*/
|
|
16
|
+
declare const getThemeHtmlAttrs: ({ colorMode, dark, light, shape, spacing, typography, UNSAFE_themeOptions, }?: Partial<ThemeState>) => Record<string, string>;
|
|
17
|
+
export default getThemeHtmlAttrs;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ThemeIdsWithOverrides, ThemeState } from './theme-config';
|
|
2
|
+
export interface ThemeStyles {
|
|
3
|
+
id: ThemeIdsWithOverrides;
|
|
4
|
+
attrs: Record<string, string>;
|
|
5
|
+
css: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Takes an object containing theme preferences, and returns an array of objects for use in applying styles to the document head.
|
|
9
|
+
* Only supplies the color themes necessary for initial render, based on the current themeState. I.e. if in light mode, dark mode themes are not returned.
|
|
10
|
+
*
|
|
11
|
+
* @param {Object<string, string>} themeState The themes and color mode that should be applied.
|
|
12
|
+
* @param {string} themeState.colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
|
|
13
|
+
* @param {string} themeState.dark The color theme to be applied when the color mode resolves to 'dark'.
|
|
14
|
+
* @param {string} themeState.light The color theme to be applied when the color mode resolves to 'light'.
|
|
15
|
+
* @param {string} themeState.shape The shape theme to be applied.
|
|
16
|
+
* @param {string} themeState.spacing The spacing theme to be applied.
|
|
17
|
+
* @param {string} themeState.typography The typography theme to be applied.
|
|
18
|
+
* @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
|
|
19
|
+
*
|
|
20
|
+
* @returns A Promise of an object array, containing theme IDs, data-attributes to attach to the theme, and the theme CSS.
|
|
21
|
+
* If an error is encountered while loading themes, the themes array will be empty.
|
|
22
|
+
*/
|
|
23
|
+
declare const getThemeStyles: (preferences?: Partial<ThemeState> | 'all') => Promise<ThemeStyles[]>;
|
|
24
|
+
export default getThemeStyles;
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
export { default as themeConfig } from './theme-config';
|
|
1
2
|
export { default as token } from './get-token';
|
|
2
3
|
export { default as getTokenValue } from './get-token-value';
|
|
3
|
-
export { default as setGlobalTheme
|
|
4
|
-
export
|
|
4
|
+
export { default as setGlobalTheme } from './set-global-theme';
|
|
5
|
+
export { default as getThemeStyles } from './get-theme-styles';
|
|
6
|
+
export { default as getThemeHtmlAttrs } from './get-theme-html-attrs';
|
|
7
|
+
export { default as getSSRAutoScript } from './get-ssr-auto-script';
|
|
8
|
+
export { default as useThemeObserver } from './use-theme-observer';
|
|
9
|
+
export { default as ThemeMutationObserver } from './theme-mutation-observer';
|
|
10
|
+
export { default as getGlobalTheme } from './get-global-theme';
|
|
11
|
+
export { themeStringToObject, themeObjectToString, } from './theme-state-transformer';
|
|
5
12
|
export type { CSSToken } from './artifacts/token-names';
|
|
6
13
|
export type { ActiveTokens } from './artifacts/types';
|
|
7
|
-
export type { ThemeColorModes, Themes, ThemeIds } from './theme-config';
|
|
14
|
+
export type { ThemeColorModes, Themes, ThemeIds, ThemeOptionsSchema, ThemeState, } from './theme-config';
|
|
8
15
|
export type { Groups, OpacityToken, PaintToken, RawToken, ShadowToken, SpacingToken, ShapeToken, } from './types';
|
|
9
|
-
export type { CustomBrandSchema } from './custom-theme';
|
|
10
|
-
export { default as themeConfig } from './theme-config';
|
|
11
|
-
export { useThemeObserver } from './use-theme-observer';
|
|
12
|
-
export { ThemeMutationObserver } from './theme-mutation-observer';
|
|
13
|
-
export { getGlobalTheme } from './get-global-theme';
|
|
14
|
-
export { themeStringToObject, themeObjectToString, } from './utils/theme-state-transformer';
|
|
@@ -1,19 +1,8 @@
|
|
|
1
1
|
import { UnbindFn } from 'bind-event-listener';
|
|
2
|
-
import {
|
|
3
|
-
import { ThemeColorModes, ThemeIds, ThemeIdsWithOverrides } from './theme-config';
|
|
4
|
-
export interface ThemeState {
|
|
5
|
-
light: Extract<ThemeIds, 'light' | 'dark' | 'legacy-dark' | 'legacy-light'>;
|
|
6
|
-
dark: Extract<ThemeIds, 'light' | 'dark' | 'legacy-dark' | 'legacy-light'>;
|
|
7
|
-
colorMode: ThemeColorModes;
|
|
8
|
-
shape?: Extract<ThemeIds, 'shape'>;
|
|
9
|
-
spacing?: Extract<ThemeIds, 'spacing'>;
|
|
10
|
-
typography?: Extract<ThemeIds, 'typography'>;
|
|
11
|
-
UNSAFE_themeOptions?: CustomBrandSchema;
|
|
12
|
-
}
|
|
2
|
+
import { ThemeColorModes, ThemeIdsWithOverrides, ThemeState } from './theme-config';
|
|
13
3
|
export interface ActiveThemeState extends ThemeState {
|
|
14
4
|
colorMode: Exclude<ThemeColorModes, 'auto'>;
|
|
15
5
|
}
|
|
16
|
-
export declare const themeStateDefaults: ThemeState;
|
|
17
6
|
/**
|
|
18
7
|
* Sets the theme globally at runtime. This updates the `data-theme` and `data-color-mode` attributes on your page's <html> tag.
|
|
19
8
|
*
|
|
@@ -35,50 +24,4 @@ export declare const themeStateDefaults: ThemeState;
|
|
|
35
24
|
* ```
|
|
36
25
|
*/
|
|
37
26
|
declare const setGlobalTheme: ({ colorMode, dark, light, shape, spacing, typography, UNSAFE_themeOptions, }?: Partial<ThemeState>, themeLoader?: ((id: ThemeIdsWithOverrides) => void | Promise<void>) | undefined) => Promise<UnbindFn>;
|
|
38
|
-
export interface ThemeStyles {
|
|
39
|
-
id: ThemeIdsWithOverrides;
|
|
40
|
-
attrs: Record<string, string>;
|
|
41
|
-
css: string;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Takes an object containing theme preferences, and returns an array of objects for use in applying styles to the document head.
|
|
45
|
-
* Only supplies the color themes necessary for initial render, based on the current themeState. I.e. if in light mode, dark mode themes are not returned.
|
|
46
|
-
*
|
|
47
|
-
* @param {Object<string, string>} themeState The themes and color mode that should be applied.
|
|
48
|
-
* @param {string} themeState.colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
|
|
49
|
-
* @param {string} themeState.dark The color theme to be applied when the color mode resolves to 'dark'.
|
|
50
|
-
* @param {string} themeState.light The color theme to be applied when the color mode resolves to 'light'.
|
|
51
|
-
* @param {string} themeState.shape The shape theme to be applied.
|
|
52
|
-
* @param {string} themeState.spacing The spacing theme to be applied.
|
|
53
|
-
* @param {string} themeState.typography The typography theme to be applied.
|
|
54
|
-
* @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
|
|
55
|
-
*
|
|
56
|
-
* @returns A Promise of an object array, containing theme IDs, data-attributes to attach to the theme, and the theme CSS.
|
|
57
|
-
* If an error is encountered while loading themes, the themes array will be empty.
|
|
58
|
-
*/
|
|
59
|
-
export declare const getThemeStyles: (preferences?: Partial<ThemeState> | 'all') => Promise<ThemeStyles[]>;
|
|
60
|
-
/**
|
|
61
|
-
* Server-side rendering utility. Generates the valid HTML attributes for a given theme.
|
|
62
|
-
* Note: this utility does not handle automatic theme switching.
|
|
63
|
-
*
|
|
64
|
-
* @param {Object<string, string>} themeOptions - Theme options object
|
|
65
|
-
* @param {string} themeState.colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
|
|
66
|
-
* @param {string} themeState.dark The color theme to be applied when the color mode resolves to 'dark'.
|
|
67
|
-
* @param {string} themeState.light The color theme to be applied when the color mode resolves to 'light'.
|
|
68
|
-
* @param {string} themeState.spacing The spacing theme to be applied.
|
|
69
|
-
* @param {string} themeState.typography The typography theme to be applied.
|
|
70
|
-
* @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
|
|
71
|
-
*
|
|
72
|
-
* @returns {Object} Object of HTML attributes to be applied to the document root
|
|
73
|
-
*/
|
|
74
|
-
export declare const getThemeHtmlAttrs: ({ colorMode, dark, light, shape, spacing, typography, UNSAFE_themeOptions, }?: Partial<ThemeState>) => Record<string, string>;
|
|
75
|
-
/**
|
|
76
|
-
* Provides a script that, when executed before paint, sets the `data-color-mode` attribute based on the current system theme,
|
|
77
|
-
* to enable SSR support for automatic theme switching, avoid a flash of un-themed content on first paint.
|
|
78
|
-
*
|
|
79
|
-
* @param {string} colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
|
|
80
|
-
*
|
|
81
|
-
* @returns {string} A string to be added to the innerHTML of a script tag in the document head
|
|
82
|
-
*/
|
|
83
|
-
export declare const getSSRAutoScript: (colorMode: ThemeState['colorMode']) => string | undefined;
|
|
84
27
|
export default setGlobalTheme;
|
|
@@ -102,4 +102,28 @@ interface ThemeConfig {
|
|
|
102
102
|
override?: ThemeIds;
|
|
103
103
|
}
|
|
104
104
|
declare const themeConfig: Record<Themes | ThemeOverrides, ThemeConfig>;
|
|
105
|
+
type HEX = `#${string}`;
|
|
106
|
+
export type CSSColor = HEX;
|
|
107
|
+
/**
|
|
108
|
+
* ThemeOptionsSchema: additional configuration options used to customize Atlassian's themes
|
|
109
|
+
*/
|
|
110
|
+
export interface ThemeOptionsSchema {
|
|
111
|
+
brandColor: CSSColor;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* ThemeState: the standard representation of an app's current theme and preferences
|
|
115
|
+
*/
|
|
116
|
+
export interface ThemeState {
|
|
117
|
+
light: Extract<ThemeIds, 'light' | 'dark' | 'legacy-dark' | 'legacy-light'>;
|
|
118
|
+
dark: Extract<ThemeIds, 'light' | 'dark' | 'legacy-dark' | 'legacy-light'>;
|
|
119
|
+
colorMode: ThemeColorModes;
|
|
120
|
+
shape?: Extract<ThemeIds, 'shape'>;
|
|
121
|
+
spacing?: Extract<ThemeIds, 'spacing'>;
|
|
122
|
+
typography?: Extract<ThemeIds, 'typography'>;
|
|
123
|
+
UNSAFE_themeOptions?: ThemeOptionsSchema;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* themeStateDefaults: the default values for ThemeState used by theming utilities
|
|
127
|
+
*/
|
|
128
|
+
export declare const themeStateDefaults: ThemeState;
|
|
105
129
|
export default themeConfig;
|
|
@@ -12,7 +12,7 @@ import { ActiveThemeState } from './set-global-theme';
|
|
|
12
12
|
* observer.observe();
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export default class ThemeMutationObserver {
|
|
16
16
|
private callback;
|
|
17
17
|
observer: MutationObserver | null;
|
|
18
18
|
mediaObserver: any;
|
|
@@ -12,4 +12,5 @@ import { ActiveThemeState } from './set-global-theme';
|
|
|
12
12
|
* }, [theme.colorMode]);
|
|
13
13
|
* ```
|
|
14
14
|
*/
|
|
15
|
-
|
|
15
|
+
declare const useThemeObserver: () => Partial<ActiveThemeState>;
|
|
16
|
+
export default useThemeObserver;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import tokens from '../artifacts/token-names';
|
|
2
|
-
import {
|
|
3
|
-
import { ThemeColorModes } from '../theme-config';
|
|
2
|
+
import { ThemeColorModes, ThemeOptionsSchema } from '../theme-config';
|
|
4
3
|
type Token = keyof typeof tokens;
|
|
5
4
|
type ThemeAttributeId = 'light' | 'dark';
|
|
6
|
-
export declare function findMissingCustomStyleElements(UNSAFE_themeOptions:
|
|
5
|
+
export declare function findMissingCustomStyleElements(UNSAFE_themeOptions: ThemeOptionsSchema, mode: ThemeColorModes): ThemeAttributeId[];
|
|
7
6
|
export declare function limitSizeOfCustomStyleElements(sizeThreshold: number): void;
|
|
8
7
|
export declare function reduceTokenMap(tokenMap: {
|
|
9
8
|
[key in Token]?: number;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import tokens from '../artifacts/token-names';
|
|
2
|
-
import { CSSColor } from '../
|
|
3
|
-
import { ThemeColorModes } from '../theme-config';
|
|
2
|
+
import { CSSColor, ThemeColorModes } from '../theme-config';
|
|
4
3
|
type Token = keyof typeof tokens;
|
|
5
4
|
type TokenMap = {
|
|
6
5
|
[key in Token]?: number;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import { ThemeIdsWithOverrides } from '../theme-config';
|
|
2
2
|
export declare const loadAndAppendThemeCss: (themeId: ThemeIdsWithOverrides) => Promise<void>;
|
|
3
3
|
export declare const loadThemeCss: (themeId: ThemeIdsWithOverrides) => Promise<string>;
|
|
4
|
+
export declare const darkModeMediaQuery = "(prefers-color-scheme: dark)";
|
package/package.json
CHANGED
package/report.api.md
CHANGED
|
@@ -902,12 +902,6 @@ type CSSTokenMap = {
|
|
|
902
902
|
'font.lineHeight.600': 'var(--ds-font-lineHeight-600)';
|
|
903
903
|
};
|
|
904
904
|
|
|
905
|
-
// @public (undocumented)
|
|
906
|
-
export interface CustomBrandSchema {
|
|
907
|
-
// (undocumented)
|
|
908
|
-
brandColor: CSSColor;
|
|
909
|
-
}
|
|
910
|
-
|
|
911
905
|
// @public (undocumented)
|
|
912
906
|
type DataColorModes = Exclude<ThemeColorModes, 'auto'>;
|
|
913
907
|
|
|
@@ -1512,6 +1506,12 @@ export class ThemeMutationObserver {
|
|
|
1512
1506
|
// @public
|
|
1513
1507
|
export const themeObjectToString: (themeState: Partial<ThemeState>) => string;
|
|
1514
1508
|
|
|
1509
|
+
// @public
|
|
1510
|
+
export interface ThemeOptionsSchema {
|
|
1511
|
+
// (undocumented)
|
|
1512
|
+
brandColor: CSSColor;
|
|
1513
|
+
}
|
|
1514
|
+
|
|
1515
1515
|
// @public (undocumented)
|
|
1516
1516
|
type ThemeOverrideIds = (typeof themeOverrideIds)[number];
|
|
1517
1517
|
|
|
@@ -1536,7 +1536,7 @@ export type Themes =
|
|
|
1536
1536
|
| 'atlassian-spacing'
|
|
1537
1537
|
| 'atlassian-typography';
|
|
1538
1538
|
|
|
1539
|
-
// @public
|
|
1539
|
+
// @public
|
|
1540
1540
|
export interface ThemeState {
|
|
1541
1541
|
// (undocumented)
|
|
1542
1542
|
colorMode: ThemeColorModes;
|
|
@@ -1551,7 +1551,7 @@ export interface ThemeState {
|
|
|
1551
1551
|
// (undocumented)
|
|
1552
1552
|
typography?: Extract<ThemeIds, 'typography'>;
|
|
1553
1553
|
// (undocumented)
|
|
1554
|
-
UNSAFE_themeOptions?:
|
|
1554
|
+
UNSAFE_themeOptions?: ThemeOptionsSchema;
|
|
1555
1555
|
}
|
|
1556
1556
|
|
|
1557
1557
|
// @public
|