-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlayer.ts
More file actions
322 lines (293 loc) · 9.62 KB
/
Copy pathlayer.ts
File metadata and controls
322 lines (293 loc) · 9.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
import { DesignTokenResolver } from "@microsoft/fast-foundation";
import { DesignTokenType } from "../core/adaptive-design-tokens.js";
import { Palette, PaletteDirectionValue } from "../core/color/palette.js";
import { ColorRecipeParams, InteractivePaintSet } from "../core/color/recipe.js";
import { deltaSwatch, deltaSwatchSet, invertingPaletteDeltasForSet } from "../core/color/recipes/index.js";
import { Color } from "../core/color/color.js";
import { luminanceSwatch } from "../core/color/utilities/luminance-swatch.js";
import { StyleProperty } from "../core/modules/types.js";
import { createTokenColor, createTokenNonCss, createTokenRecipe } from "../core/token-helpers.js";
import { createTokenColorRecipe, createTokenColorSet, createTokenDelta } from "../core/token-helpers-color.js";
import { InteractiveState } from "../core/types.js";
import { colorContext } from "./color.js";
import { neutralPalette } from "./palette.js";
/**
* Baseline values for light and dark mode for {@link layerFillBaseLuminance}.
*
* @remarks
* These values represent reasonable starting points for light and dark modes, but custom values can be used instead.
*
* @public
*/
export const LayerBaseLuminance = Object.freeze({
LightMode: 0.95,
DarkMode: 0.15,
} as const);
/**
* The {@link Palette} to use for Layer recipes.
*
* @remarks
* By default this maps to the {@link neutralPalette}.
* Use a custom palette like `layerPalette.withDefault(PaletteRGB.from("#[HEX_COLOR]"))`.
*
* @public
*/
export const layerPalette = createTokenNonCss<Palette>("color.layer.palette", DesignTokenType.palette).withDefault(neutralPalette);
const layerFillName = "color.layer.fill";
/**
* The offset between "Fixed" layers, or from the container for "Interactive" rest state, {@link layerFillInteractiveRest}.
*
* @remarks
* A negative value causes "Minus" recipes to go darker and "Plus" recipes to go lighter. A positive value causes the reverse.
*
* @public
*/
export const layerFillRestDelta = createTokenDelta(layerFillName, "layer", -2);
/**
* @public
* @deprecated Use `layerFillRestDelta` instead.
*/
export const layerFillDelta = layerFillRestDelta;
const layerFillFixedName = `${layerFillName}.ramp`;
/**
* The ideal luminance value for the "Base" layer, {@link layerFillFixedBase}.
*
* @remarks
* 0...1, 0 = black, 1 = white.
*
* @public
*/
export const layerFillBaseLuminance = createTokenNonCss<number>(`${layerFillFixedName}.baseLuminance`, DesignTokenType.number).withDefault(LayerBaseLuminance.LightMode);
/**
* The "Fixed" layers represent background fills commonly used to define app structure.
*
* @remarks
* The primary content is {@link layerFillFixedBase}.
* Underlying sections like navigation or header are logically *beneath* using {@link layerFillFixedMinus1}, etc.
* Layers above the "Base" like flyouts or dialogs use {@link layerFillFixedPlus1}, etc.
*
* See {@link layerFillRestDelta}.
*
* @public
*/
export const layerFillFixedRecipe = createTokenRecipe<number, Color>(
layerFillFixedName,
StyleProperty.backgroundFill,
(resolve: DesignTokenResolver, index: number) =>
deltaSwatch(
resolve(layerPalette),
luminanceSwatch(resolve(layerFillBaseLuminance)),
resolve(layerFillRestDelta) * index,
PaletteDirectionValue.darker
),
);
/**
* The fill of the "Base" or primary content layer.
*
* @remarks
* See {@link layerFillFixedRecipe}.
*
* @public
*/
export const layerFillFixedBase = createTokenColor(`${layerFillFixedName}.base`, StyleProperty.backgroundFill).withDefault(
(resolve: DesignTokenResolver) =>
resolve(layerFillFixedRecipe).evaluate(resolve, 0)
);
/**
* The fill of the layer 1 level beneath "Base".
*
* @remarks
* See {@link layerFillFixedRecipe}.
*
* @public
*/
export const layerFillFixedMinus1 = createTokenColor(`${layerFillFixedName}.minus1`, StyleProperty.backgroundFill).withDefault(
(resolve: DesignTokenResolver) =>
resolve(layerFillFixedRecipe).evaluate(resolve, -1)
);
/**
* The fill of the layer 2 levels beneath "Base".
*
* @remarks
* See {@link layerFillFixedRecipe}.
*
* @public
*/
export const layerFillFixedMinus2 = createTokenColor(`${layerFillFixedName}.minus2`, StyleProperty.backgroundFill).withDefault(
(resolve: DesignTokenResolver) =>
resolve(layerFillFixedRecipe).evaluate(resolve, -2)
);
/**
* The fill of the layer 3 levels beneath "Base".
*
* @remarks
* See {@link layerFillFixedRecipe}.
*
* @public
*/
export const layerFillFixedMinus3 = createTokenColor(`${layerFillFixedName}.minus3`, StyleProperty.backgroundFill).withDefault(
(resolve: DesignTokenResolver) =>
resolve(layerFillFixedRecipe).evaluate(resolve, -3)
);
/**
* The fill of the layer 4 levels beneath "Base".
*
* @remarks
* See {@link layerFillFixedRecipe}.
*
* @public
*/
export const layerFillFixedMinus4 = createTokenColor(`${layerFillFixedName}.minus4`, StyleProperty.backgroundFill).withDefault(
(resolve: DesignTokenResolver) =>
resolve(layerFillFixedRecipe).evaluate(resolve, -4)
);
/**
* The fill of the layer 1 level above "Base".
*
* @remarks
* See {@link layerFillFixedRecipe}.
*
* @public
*/
export const layerFillFixedPlus1 = createTokenColor(`${layerFillFixedName}.plus1`, StyleProperty.backgroundFill).withDefault(
(resolve: DesignTokenResolver) =>
resolve(layerFillFixedRecipe).evaluate(resolve, 1)
);
/**
* The fill of the layer 2 levels above "Base".
*
* @remarks
* See {@link layerFillFixedRecipe}.
*
* @public
*/
export const layerFillFixedPlus2 = createTokenColor(`${layerFillFixedName}.plus2`, StyleProperty.backgroundFill).withDefault(
(resolve: DesignTokenResolver) =>
resolve(layerFillFixedRecipe).evaluate(resolve, 2)
);
/**
* The fill of the layer 3 levels above "Base".
*
* @remarks
* See {@link layerFillFixedRecipe}.
*
* @public
*/
export const layerFillFixedPlus3 = createTokenColor(`${layerFillFixedName}.plus3`, StyleProperty.backgroundFill).withDefault(
(resolve: DesignTokenResolver) =>
resolve(layerFillFixedRecipe).evaluate(resolve, 3)
);
/**
* The fill of the layer 4 levels above "Base".
*
* @remarks
* See {@link layerFillFixedRecipe}.
*
* @public
*/
export const layerFillFixedPlus4 = createTokenColor(`${layerFillFixedName}.plus4`, StyleProperty.backgroundFill).withDefault(
(resolve: DesignTokenResolver) =>
resolve(layerFillFixedRecipe).evaluate(resolve, 4)
);
const layerFillInteractiveName = `${layerFillName}.interactive`;
/**
* The offset from the container for "Interactive" hover state, {@link layerFillInteractiveHover}.
*
* @public
*/
export const layerFillHoverDelta = createTokenDelta(layerFillInteractiveName, InteractiveState.hover, -3);
/**
* The offset from the container for "Interactive" active state, {@link layerFillInteractiveActive}.
*
* @public
*/
export const layerFillActiveDelta = createTokenDelta(layerFillInteractiveName, InteractiveState.active, -1);
/**
* The offset from the container for "Interactive" focus state, {@link layerFillInteractiveFocus}.
*
* @public
*/
export const layerFillFocusDelta = createTokenDelta(layerFillInteractiveName, InteractiveState.focus, -3);
/**
* The offset from the container for "Interactive" disabled state, {@link layerFillInteractiveDisabled}.
*
* @public
*/
export const layerFillDisabledDelta = createTokenDelta(layerFillInteractiveName, InteractiveState.disabled, -1);
/**
* The recipe for a layer relative to its context (as opposed to {@link layerFillBaseLuminance}).
*
* @remarks
* Useful for a `Card` or other container that's interactive.
*
* @public
*/
export const layerFillInteractiveRecipe = createTokenColorRecipe<InteractivePaintSet>(layerFillInteractiveName, StyleProperty.backgroundFill,
(resolve: DesignTokenResolver, params?: ColorRecipeParams): InteractivePaintSet => {
const palette = resolve(layerPalette);
const reference = params?.reference || resolve(colorContext);
const restDelta = resolve(layerFillRestDelta);
const hoverDelta = resolve(layerFillHoverDelta);
const activeDelta = resolve(layerFillActiveDelta);
const focusDelta = resolve(layerFillFocusDelta);
const disabledDelta = resolve(layerFillDisabledDelta);
const deltas = invertingPaletteDeltasForSet(palette, reference, restDelta, hoverDelta, activeDelta, focusDelta, disabledDelta);
return deltaSwatchSet(
palette,
reference,
deltas.rest,
deltas.hover,
deltas.active,
deltas.focus,
deltas.disabled,
undefined,
PaletteDirectionValue.darker,
);
}
);
export const layerFillInteractive = createTokenColorSet(layerFillInteractiveRecipe);
/**
* The fill of an interactive layer at rest.
*
* @remarks
* See {@link layerFillRestDelta}.
*
* @public
*/
export const layerFillInteractiveRest = layerFillInteractive.rest;
/**
* The fill of an interactive layer while hovered.
*
* @remarks
* See {@link layerFillHoverDelta}.
*
* @public
*/
export const layerFillInteractiveHover = layerFillInteractive.hover;
/**
* The fill of an interactive layer while pressed.
*
* @remarks
* See {@link layerFillActiveDelta}.
*
* @public
*/
export const layerFillInteractiveActive = layerFillInteractive.active;
/**
* The fill of an interactive layer while focused.
*
* @remarks
* See {@link layerFillFocusDelta}.
*
* @public
*/
export const layerFillInteractiveFocus = layerFillInteractive.focus;
/**
* The fill of an interactive layer while disabled.
*
* @remarks
* See {@link layerFillDisabledDelta}.
*
* @public
*/
export const layerFillInteractiveDisabled = layerFillInteractive.disabled;