@workday/canvas-kit-react 16.0.0-alpha.0499-next.0 → 16.0.0-alpha.0500-next.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/common/lib/CanvasProvider.tsx +156 -324
- package/common/lib/theming/README.md +49 -6
- package/common/lib/theming/brandScope.ts +566 -0
- package/common/lib/theming/index.ts +1 -0
- package/common/lib/theming/sanaTheme.ts +133 -0
- package/common/lib/theming/types.ts +292 -0
- package/dist/commonjs/common/lib/CanvasProvider.d.ts +296 -5
- package/dist/commonjs/common/lib/CanvasProvider.d.ts.map +1 -1
- package/dist/commonjs/common/lib/CanvasProvider.js +105 -287
- package/dist/commonjs/common/lib/theming/brandScope.d.ts +64 -0
- package/dist/commonjs/common/lib/theming/brandScope.d.ts.map +1 -0
- package/dist/commonjs/common/lib/theming/brandScope.js +499 -0
- package/dist/commonjs/common/lib/theming/index.d.ts +1 -0
- package/dist/commonjs/common/lib/theming/index.d.ts.map +1 -1
- package/dist/commonjs/common/lib/theming/index.js +1 -0
- package/dist/commonjs/common/lib/theming/sanaTheme.d.ts +33 -0
- package/dist/commonjs/common/lib/theming/sanaTheme.d.ts.map +1 -0
- package/dist/commonjs/common/lib/theming/sanaTheme.js +130 -0
- package/dist/commonjs/common/lib/theming/types.d.ts +162 -0
- package/dist/commonjs/common/lib/theming/types.d.ts.map +1 -1
- package/dist/commonjs/common/lib/theming/types.js +81 -1
- package/dist/commonjs/pill/lib/Pill.d.ts +2 -2
- package/dist/commonjs/popup/lib/hooks/usePopupStack.d.ts.map +1 -1
- package/dist/commonjs/popup/lib/hooks/usePopupStack.js +18 -16
- package/dist/commonjs/testing/lib/StaticStates.d.ts +2 -2
- package/dist/commonjs/testing/lib/StaticStates.d.ts.map +1 -1
- package/dist/commonjs/testing/lib/StaticStates.js +5 -2
- package/dist/es6/common/lib/CanvasProvider.d.ts +296 -5
- package/dist/es6/common/lib/CanvasProvider.d.ts.map +1 -1
- package/dist/es6/common/lib/CanvasProvider.js +82 -288
- package/dist/es6/common/lib/theming/brandScope.d.ts +64 -0
- package/dist/es6/common/lib/theming/brandScope.d.ts.map +1 -0
- package/dist/es6/common/lib/theming/brandScope.js +483 -0
- package/dist/es6/common/lib/theming/index.d.ts +1 -0
- package/dist/es6/common/lib/theming/index.d.ts.map +1 -1
- package/dist/es6/common/lib/theming/index.js +1 -0
- package/dist/es6/common/lib/theming/sanaTheme.d.ts +33 -0
- package/dist/es6/common/lib/theming/sanaTheme.d.ts.map +1 -0
- package/dist/es6/common/lib/theming/sanaTheme.js +127 -0
- package/dist/es6/common/lib/theming/types.d.ts +162 -0
- package/dist/es6/common/lib/theming/types.d.ts.map +1 -1
- package/dist/es6/common/lib/theming/types.js +78 -0
- package/dist/es6/pill/lib/Pill.d.ts +2 -2
- package/dist/es6/popup/lib/hooks/usePopupStack.d.ts.map +1 -1
- package/dist/es6/popup/lib/hooks/usePopupStack.js +13 -11
- package/dist/es6/testing/lib/StaticStates.d.ts +2 -2
- package/dist/es6/testing/lib/StaticStates.d.ts.map +1 -1
- package/dist/es6/testing/lib/StaticStates.js +6 -3
- package/package.json +4 -4
- package/popup/lib/hooks/usePopupStack.ts +13 -11
- package/testing/lib/StaticStates.tsx +11 -9
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.writeBrandScopeSemantic = exports.writeNumericalTheme = exports.writeSemanticTheme = exports.writeSystemBrandOverrides = exports.writeIndependentBrandTokens = exports.writeSelectedShortcuts = exports.applyNeutralBrandBundle = exports.applyPositiveBrandBundle = exports.applyCautionBrandBundle = exports.applyCriticalBrandBundle = exports.applyPrimaryBrandBundle = exports.writeNumericalBrandRamp = exports.BRAND_SCOPE_INDEPENDENT = exports.BRAND_SCOPE_PRIMARY_BUNDLE = exports.hasExplicitSemanticPalette = void 0;
|
|
4
|
+
const canvas_kit_styling_1 = require("@workday/canvas-kit-styling");
|
|
5
|
+
const canvas_tokens_web_1 = require("@workday/canvas-tokens-web");
|
|
6
|
+
const theme_1 = require("./theme");
|
|
7
|
+
const types_1 = require("./types");
|
|
8
|
+
/** True when a semantic theme intentionally passes a non-empty `canvas.palette`. */
|
|
9
|
+
function hasExplicitSemanticPalette(theme) {
|
|
10
|
+
var _a;
|
|
11
|
+
return (!(0, types_1.isNumericalTheme)(theme) &&
|
|
12
|
+
!!((_a = theme.canvas) === null || _a === void 0 ? void 0 : _a.palette) &&
|
|
13
|
+
Object.keys(theme.canvas.palette).length > 0);
|
|
14
|
+
}
|
|
15
|
+
exports.hasExplicitSemanticPalette = hasExplicitSemanticPalette;
|
|
16
|
+
/** Tokens that change when a consumer sets only their primary brand color. */
|
|
17
|
+
exports.BRAND_SCOPE_PRIMARY_BUNDLE = {
|
|
18
|
+
action: ['base', 'dark', 'darkest', 'accent'],
|
|
19
|
+
accent: ['primary', 'action'],
|
|
20
|
+
selected: {
|
|
21
|
+
fg: canvas_tokens_web_1.system.color.brand.fg.selected,
|
|
22
|
+
surface: canvas_tokens_web_1.system.color.brand.surface.selected,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Independently brandable tokens — writable when explicitly provided,
|
|
27
|
+
* but NEVER derived from primary.main / brand.primary.600.
|
|
28
|
+
*/
|
|
29
|
+
exports.BRAND_SCOPE_INDEPENDENT = {
|
|
30
|
+
focus: {
|
|
31
|
+
primary: canvas_tokens_web_1.system.color.brand.focus.primary,
|
|
32
|
+
brandToken: canvas_tokens_web_1.brand.primary500,
|
|
33
|
+
semanticKey: 'focusOutline',
|
|
34
|
+
},
|
|
35
|
+
border: {
|
|
36
|
+
primary: canvas_tokens_web_1.system.color.brand.border.primary,
|
|
37
|
+
brandToken: canvas_tokens_web_1.brand.primary500,
|
|
38
|
+
semanticKey: 'focusOutline',
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
const commonTokenMapping = {
|
|
42
|
+
focusOutline: canvas_tokens_web_1.brand.common.focus,
|
|
43
|
+
alertInner: canvas_tokens_web_1.brand.common.caution.inner,
|
|
44
|
+
alertOuter: canvas_tokens_web_1.brand.common.caution.outer,
|
|
45
|
+
errorInner: canvas_tokens_web_1.brand.common.critical,
|
|
46
|
+
};
|
|
47
|
+
const brandColorMapping = {
|
|
48
|
+
primary: 'primary',
|
|
49
|
+
error: 'critical',
|
|
50
|
+
success: 'positive',
|
|
51
|
+
alert: 'caution',
|
|
52
|
+
neutral: 'neutral',
|
|
53
|
+
};
|
|
54
|
+
/** Brand ramp keys defined in Sana CSS but not yet exported from canvas-tokens-web. */
|
|
55
|
+
const EXTENDED_BRAND_TOKEN_MAP = {
|
|
56
|
+
neutral150: '--cnvs-brand-neutral-150',
|
|
57
|
+
neutral850: '--cnvs-brand-neutral-850',
|
|
58
|
+
neutralA150: '--cnvs-brand-neutral-a150',
|
|
59
|
+
};
|
|
60
|
+
const setStyleVar = (style, token, value) => {
|
|
61
|
+
// @ts-ignore - CSS custom property key
|
|
62
|
+
style[token] = (0, canvas_kit_styling_1.maybeWrapCSSVariables)(value);
|
|
63
|
+
};
|
|
64
|
+
/** Maps a numerical brand ramp onto `brand.<color><rampKey>` CSS variables. */
|
|
65
|
+
function writeNumericalBrandRamp(color, ramp, style, options) {
|
|
66
|
+
if (!ramp) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
Object.keys(ramp).forEach(rampKey => {
|
|
70
|
+
var _a, _b;
|
|
71
|
+
if ((_a = options === null || options === void 0 ? void 0 : options.skipKeys) === null || _a === void 0 ? void 0 : _a.has(String(rampKey))) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const value = ramp[rampKey];
|
|
75
|
+
if (value == null) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
const token = color === 'action'
|
|
79
|
+
? canvas_tokens_web_1.brand.action[rampKey]
|
|
80
|
+
: // @ts-ignore - dynamic token lookup
|
|
81
|
+
((_b = canvas_tokens_web_1.brand[`${color}${rampKey}`]) !== null && _b !== void 0 ? _b : EXTENDED_BRAND_TOKEN_MAP[`${color}${rampKey}`]);
|
|
82
|
+
if (token) {
|
|
83
|
+
setStyleVar(style, token, value);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
exports.writeNumericalBrandRamp = writeNumericalBrandRamp;
|
|
88
|
+
/** Called when consumer sets only `primary.main` or `brand.primary['600']`. */
|
|
89
|
+
function applyPrimaryBrandBundle(primaryColor, style) {
|
|
90
|
+
const value = (0, canvas_kit_styling_1.maybeWrapCSSVariables)(primaryColor);
|
|
91
|
+
setStyleVar(style, canvas_tokens_web_1.brand.primary.base, value);
|
|
92
|
+
setStyleVar(style, canvas_tokens_web_1.brand.primary600, value);
|
|
93
|
+
setStyleVar(style, canvas_tokens_web_1.brand.action.base, value);
|
|
94
|
+
if (canvas_tokens_web_1.system.color.brand.accent.primary) {
|
|
95
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.accent.primary, value);
|
|
96
|
+
}
|
|
97
|
+
if (canvas_tokens_web_1.system.color.brand.accent.action) {
|
|
98
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.accent.action, value);
|
|
99
|
+
}
|
|
100
|
+
const selectedFg = canvas_kit_styling_1.colorSpace.pressed({
|
|
101
|
+
color: `var(${canvas_tokens_web_1.brand.primary600})`,
|
|
102
|
+
fallback: value,
|
|
103
|
+
colorType: 'accent',
|
|
104
|
+
});
|
|
105
|
+
const selectedSurface = canvas_kit_styling_1.colorSpace.darken({
|
|
106
|
+
color: canvas_tokens_web_1.system.color.bg.default,
|
|
107
|
+
fallback: 'white',
|
|
108
|
+
mixinColor: `var(${canvas_tokens_web_1.brand.primary600})`,
|
|
109
|
+
mixinValue: '0.11',
|
|
110
|
+
});
|
|
111
|
+
setStyleVar(style, canvas_tokens_web_1.brand.primary700, selectedFg);
|
|
112
|
+
setStyleVar(style, canvas_tokens_web_1.brand.primary.dark, selectedFg);
|
|
113
|
+
setStyleVar(style, canvas_tokens_web_1.brand.primaryA50, selectedSurface);
|
|
114
|
+
if (exports.BRAND_SCOPE_PRIMARY_BUNDLE.selected.fg) {
|
|
115
|
+
setStyleVar(style, exports.BRAND_SCOPE_PRIMARY_BUNDLE.selected.fg, selectedFg);
|
|
116
|
+
}
|
|
117
|
+
if (exports.BRAND_SCOPE_PRIMARY_BUNDLE.selected.surface) {
|
|
118
|
+
setStyleVar(style, exports.BRAND_SCOPE_PRIMARY_BUNDLE.selected.surface, selectedSurface);
|
|
119
|
+
}
|
|
120
|
+
const hoverColor = canvas_kit_styling_1.colorSpace.hover({
|
|
121
|
+
color: `var(${canvas_tokens_web_1.brand.action.base})`,
|
|
122
|
+
fallback: value,
|
|
123
|
+
colorType: 'accent',
|
|
124
|
+
});
|
|
125
|
+
const pressedColor = canvas_kit_styling_1.colorSpace.pressed({
|
|
126
|
+
color: `var(${canvas_tokens_web_1.brand.action.base})`,
|
|
127
|
+
fallback: value,
|
|
128
|
+
colorType: 'accent',
|
|
129
|
+
});
|
|
130
|
+
setStyleVar(style, canvas_tokens_web_1.brand.action.dark, hoverColor);
|
|
131
|
+
setStyleVar(style, canvas_tokens_web_1.brand.action.darkest, pressedColor);
|
|
132
|
+
}
|
|
133
|
+
exports.applyPrimaryBrandBundle = applyPrimaryBrandBundle;
|
|
134
|
+
/** Called when consumer sets only `error.main` or `brand.critical['600']`. */
|
|
135
|
+
function applyCriticalBrandBundle(criticalColor, style) {
|
|
136
|
+
var _a;
|
|
137
|
+
const value = (0, canvas_kit_styling_1.maybeWrapCSSVariables)(criticalColor);
|
|
138
|
+
setStyleVar(style, canvas_tokens_web_1.brand.error.base, value);
|
|
139
|
+
setStyleVar(style, canvas_tokens_web_1.brand.critical600, value);
|
|
140
|
+
setStyleVar(style, canvas_tokens_web_1.brand.critical500, value);
|
|
141
|
+
if (canvas_tokens_web_1.system.color.brand.accent.critical) {
|
|
142
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.accent.critical, value);
|
|
143
|
+
}
|
|
144
|
+
if ((_a = canvas_tokens_web_1.system.color.brand.fg.critical) === null || _a === void 0 ? void 0 : _a.default) {
|
|
145
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.fg.critical.default, value);
|
|
146
|
+
}
|
|
147
|
+
if (canvas_tokens_web_1.system.color.brand.border.critical) {
|
|
148
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.border.critical, value);
|
|
149
|
+
}
|
|
150
|
+
if (canvas_tokens_web_1.system.color.brand.focus.critical) {
|
|
151
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.focus.critical, value);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
exports.applyCriticalBrandBundle = applyCriticalBrandBundle;
|
|
155
|
+
/** Called when consumer sets only `alert.main` or `brand.caution['400']`. */
|
|
156
|
+
function applyCautionBrandBundle(cautionColor, style) {
|
|
157
|
+
var _a, _b, _c;
|
|
158
|
+
const value = (0, canvas_kit_styling_1.maybeWrapCSSVariables)(cautionColor);
|
|
159
|
+
setStyleVar(style, canvas_tokens_web_1.brand.alert.base, value);
|
|
160
|
+
setStyleVar(style, canvas_tokens_web_1.brand.caution400, value);
|
|
161
|
+
setStyleVar(style, canvas_tokens_web_1.brand.caution500, value);
|
|
162
|
+
if (canvas_tokens_web_1.system.color.brand.accent.caution) {
|
|
163
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.accent.caution, value);
|
|
164
|
+
}
|
|
165
|
+
if ((_a = canvas_tokens_web_1.system.color.brand.fg.caution) === null || _a === void 0 ? void 0 : _a.default) {
|
|
166
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.fg.caution.default, value);
|
|
167
|
+
}
|
|
168
|
+
if (canvas_tokens_web_1.system.color.brand.border.caution) {
|
|
169
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.border.caution, value);
|
|
170
|
+
}
|
|
171
|
+
if ((_b = canvas_tokens_web_1.system.color.brand.focus.caution) === null || _b === void 0 ? void 0 : _b.inner) {
|
|
172
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.focus.caution.inner, value);
|
|
173
|
+
}
|
|
174
|
+
if ((_c = canvas_tokens_web_1.system.color.brand.focus.caution) === null || _c === void 0 ? void 0 : _c.outer) {
|
|
175
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.focus.caution.outer, value);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
exports.applyCautionBrandBundle = applyCautionBrandBundle;
|
|
179
|
+
/** Called when consumer sets only `success.main` or `brand.positive['600']`. */
|
|
180
|
+
function applyPositiveBrandBundle(positiveColor, style) {
|
|
181
|
+
var _a;
|
|
182
|
+
const value = (0, canvas_kit_styling_1.maybeWrapCSSVariables)(positiveColor);
|
|
183
|
+
setStyleVar(style, canvas_tokens_web_1.brand.success.base, value);
|
|
184
|
+
setStyleVar(style, canvas_tokens_web_1.brand.positive600, value);
|
|
185
|
+
if (canvas_tokens_web_1.system.color.brand.accent.positive) {
|
|
186
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.accent.positive, value);
|
|
187
|
+
}
|
|
188
|
+
if ((_a = canvas_tokens_web_1.system.color.brand.fg.positive) === null || _a === void 0 ? void 0 : _a.default) {
|
|
189
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.fg.positive.default, value);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
exports.applyPositiveBrandBundle = applyPositiveBrandBundle;
|
|
193
|
+
/** Called when consumer sets only `neutral.main` or `brand.neutral['600']`. */
|
|
194
|
+
function applyNeutralBrandBundle(neutralColor, style) {
|
|
195
|
+
const value = (0, canvas_kit_styling_1.maybeWrapCSSVariables)(neutralColor);
|
|
196
|
+
setStyleVar(style, canvas_tokens_web_1.brand.neutral.base, value);
|
|
197
|
+
setStyleVar(style, canvas_tokens_web_1.brand.neutral600, value);
|
|
198
|
+
}
|
|
199
|
+
exports.applyNeutralBrandBundle = applyNeutralBrandBundle;
|
|
200
|
+
/** Writes first-class selected shortcuts from numerical theme input. */
|
|
201
|
+
function writeSelectedShortcuts(selected, style) {
|
|
202
|
+
if (!selected) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (selected.fg && exports.BRAND_SCOPE_PRIMARY_BUNDLE.selected.fg) {
|
|
206
|
+
setStyleVar(style, exports.BRAND_SCOPE_PRIMARY_BUNDLE.selected.fg, selected.fg);
|
|
207
|
+
}
|
|
208
|
+
if (selected.surface && exports.BRAND_SCOPE_PRIMARY_BUNDLE.selected.surface) {
|
|
209
|
+
setStyleVar(style, exports.BRAND_SCOPE_PRIMARY_BUNDLE.selected.surface, selected.surface);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
exports.writeSelectedShortcuts = writeSelectedShortcuts;
|
|
213
|
+
function writeFocusBorderBundle(value, style) {
|
|
214
|
+
setStyleVar(style, canvas_tokens_web_1.brand.common.focusOutline, value);
|
|
215
|
+
setStyleVar(style, canvas_tokens_web_1.brand.primary500, value);
|
|
216
|
+
if (exports.BRAND_SCOPE_INDEPENDENT.focus.primary) {
|
|
217
|
+
setStyleVar(style, exports.BRAND_SCOPE_INDEPENDENT.focus.primary, value);
|
|
218
|
+
}
|
|
219
|
+
if (exports.BRAND_SCOPE_INDEPENDENT.border.primary) {
|
|
220
|
+
setStyleVar(style, exports.BRAND_SCOPE_INDEPENDENT.border.primary, value);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/** Writes focus/border from explicit common or brand.primary.500 input — never from primary.main. */
|
|
224
|
+
function writeIndependentBrandTokens(theme, style) {
|
|
225
|
+
var _a, _b, _c, _d;
|
|
226
|
+
if (!theme) {
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
if ((0, types_1.isNumericalTheme)(theme)) {
|
|
230
|
+
const focusValue = (_b = (_a = theme.brand) === null || _a === void 0 ? void 0 : _a.primary) === null || _b === void 0 ? void 0 : _b['500'];
|
|
231
|
+
if (focusValue) {
|
|
232
|
+
writeFocusBorderBundle(focusValue, style);
|
|
233
|
+
}
|
|
234
|
+
if (theme.system) {
|
|
235
|
+
writeSystemBrandOverrides(theme.system, style);
|
|
236
|
+
}
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
const common = (_d = (_c = theme.canvas) === null || _c === void 0 ? void 0 : _c.palette) === null || _d === void 0 ? void 0 : _d.common;
|
|
240
|
+
if (!common) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
['focusOutline', 'alertInner', 'alertOuter', 'errorInner'].forEach(key => {
|
|
244
|
+
var _a;
|
|
245
|
+
const rawValue = common[key];
|
|
246
|
+
if (rawValue == null) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
if (rawValue === theme_1.defaultCanvasTheme.palette.common[key]) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
const value = (0, canvas_kit_styling_1.maybeWrapCSSVariables)(rawValue);
|
|
253
|
+
// @ts-ignore
|
|
254
|
+
setStyleVar(style, canvas_tokens_web_1.brand.common[key], value);
|
|
255
|
+
// @ts-ignore
|
|
256
|
+
setStyleVar(style, commonTokenMapping[key], value);
|
|
257
|
+
if (key === 'focusOutline') {
|
|
258
|
+
writeFocusBorderBundle(value, style);
|
|
259
|
+
}
|
|
260
|
+
if (key === 'alertInner' && ((_a = canvas_tokens_web_1.system.color.brand.focus.caution) === null || _a === void 0 ? void 0 : _a.inner)) {
|
|
261
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.focus.caution.inner, value);
|
|
262
|
+
}
|
|
263
|
+
if (key === 'alertOuter' && canvas_tokens_web_1.system.color.brand.border.caution) {
|
|
264
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.border.caution, value);
|
|
265
|
+
}
|
|
266
|
+
if (key === 'errorInner') {
|
|
267
|
+
if (canvas_tokens_web_1.system.color.brand.focus.critical) {
|
|
268
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.focus.critical, value);
|
|
269
|
+
}
|
|
270
|
+
if (canvas_tokens_web_1.system.color.brand.border.critical) {
|
|
271
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.border.critical, value);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
exports.writeIndependentBrandTokens = writeIndependentBrandTokens;
|
|
277
|
+
/** Walks nested system override object and sets matching system CSS vars. */
|
|
278
|
+
function writeSystemBrandOverrides(systemOverrides, style) {
|
|
279
|
+
var _a;
|
|
280
|
+
const brandOverrides = (_a = systemOverrides === null || systemOverrides === void 0 ? void 0 : systemOverrides.color) === null || _a === void 0 ? void 0 : _a.brand;
|
|
281
|
+
if (!brandOverrides) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const walk = (node, path) => {
|
|
285
|
+
Object.entries(node).forEach(([key, val]) => {
|
|
286
|
+
var _a, _b;
|
|
287
|
+
if (val && typeof val === 'object') {
|
|
288
|
+
walk(val, [...path, key]);
|
|
289
|
+
}
|
|
290
|
+
else if (typeof val === 'string') {
|
|
291
|
+
let tokenNode = canvas_tokens_web_1.system.color.brand;
|
|
292
|
+
for (const seg of [...path, key]) {
|
|
293
|
+
// @ts-ignore
|
|
294
|
+
tokenNode = tokenNode === null || tokenNode === void 0 ? void 0 : tokenNode[seg];
|
|
295
|
+
}
|
|
296
|
+
if (typeof tokenNode === 'string') {
|
|
297
|
+
const cssVarName = (_b = (_a = tokenNode.match(/--[\w-]+/)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : tokenNode;
|
|
298
|
+
setStyleVar(style, cssVarName, val);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
};
|
|
303
|
+
walk(brandOverrides, []);
|
|
304
|
+
}
|
|
305
|
+
exports.writeSystemBrandOverrides = writeSystemBrandOverrides;
|
|
306
|
+
const mappedKeys = {
|
|
307
|
+
lightest: 'lightest',
|
|
308
|
+
lighter: 'lighter',
|
|
309
|
+
light: 'light',
|
|
310
|
+
main: 'base',
|
|
311
|
+
dark: 'dark',
|
|
312
|
+
darkest: 'darkest',
|
|
313
|
+
contrast: 'accent',
|
|
314
|
+
};
|
|
315
|
+
const numericalTokenMapping = {
|
|
316
|
+
lightest: '25',
|
|
317
|
+
lighter: '50',
|
|
318
|
+
light: '200',
|
|
319
|
+
main: '600',
|
|
320
|
+
dark: '700',
|
|
321
|
+
darkest: '800',
|
|
322
|
+
};
|
|
323
|
+
/** Full-scope semantic writer — filled palette compared against defaults unless `writeAll`. */
|
|
324
|
+
function writeSemanticTheme(palette, style, options) {
|
|
325
|
+
var _a;
|
|
326
|
+
const writeAll = (_a = options === null || options === void 0 ? void 0 : options.writeAll) !== null && _a !== void 0 ? _a : false;
|
|
327
|
+
['common', 'primary', 'error', 'alert', 'success', 'neutral'].forEach(color => {
|
|
328
|
+
if (color === 'common') {
|
|
329
|
+
['focusOutline', 'alertInner', 'alertOuter', 'errorInner'].forEach(key => {
|
|
330
|
+
var _a;
|
|
331
|
+
if (writeAll || palette.common[key] !== theme_1.defaultCanvasTheme.palette.common[key]) {
|
|
332
|
+
const value = (0, canvas_kit_styling_1.maybeWrapCSSVariables)(palette.common[key]);
|
|
333
|
+
// @ts-ignore
|
|
334
|
+
setStyleVar(style, canvas_tokens_web_1.brand.common[key], value);
|
|
335
|
+
// @ts-ignore
|
|
336
|
+
setStyleVar(style, commonTokenMapping[key], value);
|
|
337
|
+
if (key === 'focusOutline') {
|
|
338
|
+
writeFocusBorderBundle(value, style);
|
|
339
|
+
}
|
|
340
|
+
if (key === 'alertInner' && ((_a = canvas_tokens_web_1.system.color.brand.focus.caution) === null || _a === void 0 ? void 0 : _a.inner)) {
|
|
341
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.focus.caution.inner, value);
|
|
342
|
+
}
|
|
343
|
+
if (key === 'alertOuter' && canvas_tokens_web_1.system.color.brand.border.caution) {
|
|
344
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.border.caution, value);
|
|
345
|
+
}
|
|
346
|
+
if (key === 'errorInner') {
|
|
347
|
+
if (canvas_tokens_web_1.system.color.brand.focus.critical) {
|
|
348
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.focus.critical, value);
|
|
349
|
+
}
|
|
350
|
+
if (canvas_tokens_web_1.system.color.brand.border.critical) {
|
|
351
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.border.critical, value);
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
['lightest', 'lighter', 'light', 'main', 'dark', 'darkest', 'contrast'].forEach(key => {
|
|
359
|
+
var _a, _b, _c, _d, _e;
|
|
360
|
+
// @ts-ignore
|
|
361
|
+
if (writeAll || palette[color][key] !== theme_1.defaultCanvasTheme.palette[color][key]) {
|
|
362
|
+
// @ts-ignore
|
|
363
|
+
const value = (0, canvas_kit_styling_1.maybeWrapCSSVariables)(palette[color][key]);
|
|
364
|
+
// @ts-ignore
|
|
365
|
+
setStyleVar(style, canvas_tokens_web_1.brand[color][mappedKeys[key]], value);
|
|
366
|
+
if (key !== 'contrast' && key in numericalTokenMapping) {
|
|
367
|
+
const newBrandColor = brandColorMapping[color];
|
|
368
|
+
const numericalSuffix = numericalTokenMapping[key];
|
|
369
|
+
// @ts-ignore
|
|
370
|
+
const numericalToken = canvas_tokens_web_1.brand[newBrandColor + numericalSuffix];
|
|
371
|
+
if (numericalToken) {
|
|
372
|
+
setStyleVar(style, numericalToken, value);
|
|
373
|
+
}
|
|
374
|
+
if (key === 'main') {
|
|
375
|
+
// @ts-ignore
|
|
376
|
+
const systemAccentToken = canvas_tokens_web_1.system.color.brand.accent[newBrandColor];
|
|
377
|
+
if (systemAccentToken) {
|
|
378
|
+
setStyleVar(style, systemAccentToken, value);
|
|
379
|
+
}
|
|
380
|
+
// @ts-ignore
|
|
381
|
+
const systemFgToken = (_a = canvas_tokens_web_1.system.color.brand.fg[newBrandColor]) === null || _a === void 0 ? void 0 : _a.default;
|
|
382
|
+
if (systemFgToken) {
|
|
383
|
+
setStyleVar(style, systemFgToken, value);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
else if (key === 'dark') {
|
|
387
|
+
// @ts-ignore
|
|
388
|
+
const systemFgStrongToken = (_b = canvas_tokens_web_1.system.color.brand.fg[newBrandColor]) === null || _b === void 0 ? void 0 : _b.strong;
|
|
389
|
+
if (systemFgStrongToken) {
|
|
390
|
+
setStyleVar(style, systemFgStrongToken, value);
|
|
391
|
+
}
|
|
392
|
+
if (newBrandColor === 'primary' && canvas_tokens_web_1.system.color.brand.fg.selected) {
|
|
393
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.fg.selected, value);
|
|
394
|
+
}
|
|
395
|
+
if (newBrandColor === 'critical') {
|
|
396
|
+
if (canvas_tokens_web_1.system.color.brand.focus.critical) {
|
|
397
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.focus.critical, value);
|
|
398
|
+
}
|
|
399
|
+
if (canvas_tokens_web_1.system.color.brand.border.critical) {
|
|
400
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.border.critical, value);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
if (newBrandColor === 'caution') {
|
|
404
|
+
if ((_c = canvas_tokens_web_1.system.color.brand.focus.caution) === null || _c === void 0 ? void 0 : _c.outer) {
|
|
405
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.focus.caution.outer, value);
|
|
406
|
+
}
|
|
407
|
+
if (canvas_tokens_web_1.system.color.brand.border.caution) {
|
|
408
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.border.caution, value);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
else if (key === 'lighter') {
|
|
413
|
+
// @ts-ignore
|
|
414
|
+
const surfaceStrongToken = (_d = canvas_tokens_web_1.system.color.brand.surface[newBrandColor]) === null || _d === void 0 ? void 0 : _d.strong;
|
|
415
|
+
if (surfaceStrongToken) {
|
|
416
|
+
setStyleVar(style, surfaceStrongToken, value);
|
|
417
|
+
}
|
|
418
|
+
if (newBrandColor === 'primary' && canvas_tokens_web_1.system.color.brand.surface.selected) {
|
|
419
|
+
setStyleVar(style, canvas_tokens_web_1.system.color.brand.surface.selected, value);
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
else if (key === 'lightest') {
|
|
423
|
+
// @ts-ignore
|
|
424
|
+
const surfaceDefaultToken = (_e = canvas_tokens_web_1.system.color.brand.surface[newBrandColor]) === null || _e === void 0 ? void 0 : _e.default;
|
|
425
|
+
if (surfaceDefaultToken) {
|
|
426
|
+
setStyleVar(style, surfaceDefaultToken, value);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
}
|
|
435
|
+
exports.writeSemanticTheme = writeSemanticTheme;
|
|
436
|
+
/** Writes numerical theme — brand scope applies per-family shortcuts; remaining keys write 1:1. */
|
|
437
|
+
function writeNumericalTheme(theme, style, scope) {
|
|
438
|
+
var _a, _b, _c;
|
|
439
|
+
const brandPalette = theme.brand;
|
|
440
|
+
const skipRamp = {};
|
|
441
|
+
if (scope === 'brand' && brandPalette) {
|
|
442
|
+
if (((_a = brandPalette.primary) === null || _a === void 0 ? void 0 : _a['600']) && Object.keys(brandPalette.primary).length === 1) {
|
|
443
|
+
applyPrimaryBrandBundle(brandPalette.primary['600'], style);
|
|
444
|
+
skipRamp.primary = new Set(['600']);
|
|
445
|
+
// Do not skip action keys — explicit `brand.action.*` must win over derived shades
|
|
446
|
+
// written by applyPrimaryBrandBundle (writeNumericalBrandRamp runs after).
|
|
447
|
+
}
|
|
448
|
+
// Only the main ramp key triggers the family shortcut. Lone `'500'` (focus/border) must
|
|
449
|
+
// write 1:1 and must not overwrite critical600 / caution400 via the bundle.
|
|
450
|
+
const critical = brandPalette.critical;
|
|
451
|
+
if ((critical === null || critical === void 0 ? void 0 : critical['600']) && Object.keys(critical).length === 1) {
|
|
452
|
+
applyCriticalBrandBundle(critical['600'], style);
|
|
453
|
+
skipRamp.critical = new Set(['600']);
|
|
454
|
+
}
|
|
455
|
+
const caution = brandPalette.caution;
|
|
456
|
+
if ((caution === null || caution === void 0 ? void 0 : caution['400']) && Object.keys(caution).length === 1) {
|
|
457
|
+
applyCautionBrandBundle(caution['400'], style);
|
|
458
|
+
skipRamp.caution = new Set(['400']);
|
|
459
|
+
}
|
|
460
|
+
if (((_b = brandPalette.positive) === null || _b === void 0 ? void 0 : _b['600']) && Object.keys(brandPalette.positive).length === 1) {
|
|
461
|
+
applyPositiveBrandBundle(brandPalette.positive['600'], style);
|
|
462
|
+
skipRamp.positive = new Set(['600']);
|
|
463
|
+
}
|
|
464
|
+
if (((_c = brandPalette.neutral) === null || _c === void 0 ? void 0 : _c['600']) && Object.keys(brandPalette.neutral).length === 1) {
|
|
465
|
+
applyNeutralBrandBundle(brandPalette.neutral['600'], style);
|
|
466
|
+
skipRamp.neutral = new Set(['600']);
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
if (brandPalette) {
|
|
470
|
+
['primary', 'critical', 'caution', 'positive', 'neutral', 'action'].forEach(color => {
|
|
471
|
+
writeNumericalBrandRamp(color, brandPalette[color], style, { skipKeys: skipRamp[color] });
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
writeSelectedShortcuts(theme.selected, style);
|
|
475
|
+
writeIndependentBrandTokens(theme, style);
|
|
476
|
+
}
|
|
477
|
+
exports.writeNumericalTheme = writeNumericalTheme;
|
|
478
|
+
/** Brand-scope semantic path — reads raw input only, not useTheme-filled palette. */
|
|
479
|
+
function writeBrandScopeSemantic(theme, style) {
|
|
480
|
+
var _a, _b, _c, _d, _e, _f;
|
|
481
|
+
const palette = (_a = theme.canvas) === null || _a === void 0 ? void 0 : _a.palette;
|
|
482
|
+
if ((_b = palette === null || palette === void 0 ? void 0 : palette.primary) === null || _b === void 0 ? void 0 : _b.main) {
|
|
483
|
+
applyPrimaryBrandBundle(palette.primary.main, style);
|
|
484
|
+
}
|
|
485
|
+
if ((_c = palette === null || palette === void 0 ? void 0 : palette.error) === null || _c === void 0 ? void 0 : _c.main) {
|
|
486
|
+
applyCriticalBrandBundle(palette.error.main, style);
|
|
487
|
+
}
|
|
488
|
+
if ((_d = palette === null || palette === void 0 ? void 0 : palette.alert) === null || _d === void 0 ? void 0 : _d.main) {
|
|
489
|
+
applyCautionBrandBundle(palette.alert.main, style);
|
|
490
|
+
}
|
|
491
|
+
if ((_e = palette === null || palette === void 0 ? void 0 : palette.success) === null || _e === void 0 ? void 0 : _e.main) {
|
|
492
|
+
applyPositiveBrandBundle(palette.success.main, style);
|
|
493
|
+
}
|
|
494
|
+
if ((_f = palette === null || palette === void 0 ? void 0 : palette.neutral) === null || _f === void 0 ? void 0 : _f.main) {
|
|
495
|
+
applyNeutralBrandBundle(palette.neutral.main, style);
|
|
496
|
+
}
|
|
497
|
+
writeIndependentBrandTokens(theme, style);
|
|
498
|
+
}
|
|
499
|
+
exports.writeBrandScopeSemantic = writeBrandScopeSemantic;
|
|
@@ -14,6 +14,7 @@ export { default as styled, type StyleRewriteFn, filterOutProps } from './styled
|
|
|
14
14
|
* For more information, view our [Theming Docs](https://workday.github.io/canvas-kit/?path=/docs/features-theming-overview--docs#-preferred-approach-v14).
|
|
15
15
|
*/
|
|
16
16
|
export * from './theme';
|
|
17
|
+
export * from './sanaTheme';
|
|
17
18
|
/**
|
|
18
19
|
* @deprecated ⚠️ `useTheme` and `getTheme` are deprecated. Use CSS variables from `@workday/canvas-tokens-web` instead.
|
|
19
20
|
* For more information, view our [Theming Docs](https://workday.github.io/canvas-kit/?path=/docs/features-theming-overview--docs#-preferred-approach-v14).
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../common/lib/theming/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B;;;GAGG;AACH,cAAc,SAAS,CAAC;AACxB;;;GAGG;AACH,OAAO,EAAC,OAAO,IAAI,MAAM,EAAE,KAAK,cAAc,EAAE,cAAc,EAAC,MAAM,UAAU,CAAC;AAChF;;;GAGG;AACH,cAAc,SAAS,CAAC;AACxB;;;GAGG;AACH,cAAc,YAAY,CAAC;AAC3B;;;GAGG;AACH,cAAc,iBAAiB,CAAC;AAChC;;;GAGG;AACH,cAAc,YAAY,CAAC;AAC3B;;;GAGG;AACH,cAAc,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../common/lib/theming/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B;;;GAGG;AACH,cAAc,SAAS,CAAC;AACxB;;;GAGG;AACH,OAAO,EAAC,OAAO,IAAI,MAAM,EAAE,KAAK,cAAc,EAAE,cAAc,EAAC,MAAM,UAAU,CAAC;AAChF;;;GAGG;AACH,cAAc,SAAS,CAAC;AACxB,cAAc,aAAa,CAAC;AAC5B;;;GAGG;AACH,cAAc,YAAY,CAAC;AAC3B;;;GAGG;AACH,cAAc,iBAAiB,CAAC;AAChC;;;GAGG;AACH,cAAc,YAAY,CAAC;AAC3B;;;GAGG;AACH,cAAc,kBAAkB,CAAC"}
|
|
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "filterOutProps", { enumerable: true, get: functi
|
|
|
36
36
|
* For more information, view our [Theming Docs](https://workday.github.io/canvas-kit/?path=/docs/features-theming-overview--docs#-preferred-approach-v14).
|
|
37
37
|
*/
|
|
38
38
|
__exportStar(require("./theme"), exports);
|
|
39
|
+
__exportStar(require("./sanaTheme"), exports);
|
|
39
40
|
/**
|
|
40
41
|
* @deprecated ⚠️ `useTheme` and `getTheme` are deprecated. Use CSS variables from `@workday/canvas-tokens-web` instead.
|
|
41
42
|
* For more information, view our [Theming Docs](https://workday.github.io/canvas-kit/?path=/docs/features-theming-overview--docs#-preferred-approach-v14).
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { CanvasNumericalBrandTheme } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Sana Canvas brand tokens for scoped `CanvasProvider` / popup forwarding.
|
|
4
|
+
* Values are `var()` references to Sana brand variables — not merged from `defaultCanvasTheme`.
|
|
5
|
+
*/
|
|
6
|
+
export declare const sanaCanvasNumericalTheme: CanvasNumericalBrandTheme;
|
|
7
|
+
/**
|
|
8
|
+
* Pass to root `CanvasProvider` to forward Sana brand CSS variables onto popup containers
|
|
9
|
+
* (menus, selects, modals, tooltips).
|
|
10
|
+
*
|
|
11
|
+
* **When to use it**
|
|
12
|
+
* - **Required** when you cannot set `data-theme="sana-canvas"` on `<html>` (embedded apps,
|
|
13
|
+
* microfrontends, third-party shells). Popups portal to `document.body` and will not inherit
|
|
14
|
+
* a nested `data-theme` — this preset copies Sana brand vars onto the popup stack container.
|
|
15
|
+
* - Also useful in tests without global Sana CSS, or custom popup hosts outside normal cascade.
|
|
16
|
+
*
|
|
17
|
+
* **When you can skip it**
|
|
18
|
+
* - Prefer setting `data-theme="sana-canvas"` on `<html>` with Sana CSS imported. Popups then
|
|
19
|
+
* inherit brand variables from the document and no `theme` prop is needed.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* // Preferred — control <html>
|
|
24
|
+
* import '@workday/canvas-tokens-web/css/sana/_variables.css';
|
|
25
|
+
* // <html data-theme="sana-canvas">
|
|
26
|
+
* <CanvasProvider><App /></CanvasProvider>
|
|
27
|
+
*
|
|
28
|
+
* // No access to <html> — required for popup parity
|
|
29
|
+
* <CanvasProvider theme={sanaCanvasProviderTheme}><App /></CanvasProvider>
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const sanaCanvasProviderTheme: CanvasNumericalBrandTheme;
|
|
33
|
+
//# sourceMappingURL=sanaTheme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanaTheme.d.ts","sourceRoot":"","sources":["../../../../../common/lib/theming/sanaTheme.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAC,yBAAyB,EAAC,MAAM,SAAS,CAAC;AAevD;;;GAGG;AACH,eAAO,MAAM,wBAAwB,EAAE,yBAmEtC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,uBAAuB,2BAA2B,CAAC"}
|