Skip to content

Commit 6834958

Browse files
authored
Updating palette base color token type for better type safety (#222)
1 parent 7274f4b commit 6834958

15 files changed

Lines changed: 73 additions & 35 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "Updating palette base color token type for better type safety",
4+
"packageName": "@adaptive-web/adaptive-ui",
5+
"email": "47367562+bheston@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "minor",
3+
"comment": "Updating palette base color token type for better type safety",
4+
"packageName": "@adaptive-web/adaptive-ui-designer-core",
5+
"email": "47367562+bheston@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

examples/use-adaptive-components/src/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
layerFillFixedBase
2626
} from "@adaptive-web/adaptive-ui/reference";
2727
import { DesignToken, FASTRadioGroup, FASTSwitch } from "@microsoft/fast-foundation";
28+
import { Color } from '@adaptive-web/adaptive-ui';
2829

2930
// This must be called during initialization for the Design Tokens to be setup so the component styling is applied.
3031
DesignToken.registerDefaultStyleTarget();
@@ -47,5 +48,5 @@ document.getElementById("accentColor").onchange = function(event) {
4748
const value = (event.target as FASTRadioGroup).value;
4849
console.log("accentColor change", value);
4950
// This Design Token causes the accent palette to update, including any components styled with recipes based on that palette.
50-
accentBaseColor.withDefault("#" + value);
51+
accentBaseColor.withDefault(Color.parse("#" + value));
5152
};

packages/adaptive-ui-designer-core/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export {
1313
AppliedDesignTokens,
1414
DesignTokenValues
1515
} from "./model.js";
16-
export { mapReplacer, mapReviver, deserializeMap } from "./serialization.js";
16+
export { mapReplacer, mapReviver, deserializeMap, serializeMap } from "./serialization.js";
1717
export { State, StatesState, PluginNode, focusIndicatorNodeName, } from "./node.js";
1818
export { DesignTokenDefinition, DesignTokenRegistry, FormControlId } from "./registry/design-token-registry.js";
1919
export { nameToTitle, registerAppliableTokens, registerTokens } from "./registry/recipes.js";

packages/adaptive-ui-designer-core/src/registry/custom-recipes.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import {
22
ColorRecipeParams,
33
contrastSwatch,
44
createNonCss,
5-
createTokenColor,
65
createTokenColorRecipe,
76
createTokenColorRecipeValue,
87
createTokenSwatch,
@@ -11,6 +10,7 @@ import {
1110
PaletteRGB,
1211
StyleProperty,
1312
stylePropertyBorderFillAll,
13+
Swatch,
1414
} from "@adaptive-web/adaptive-ui";
1515
import {
1616
blackOrWhiteDiscernibleRecipe,
@@ -25,7 +25,7 @@ import { DesignTokenResolver } from "@microsoft/fast-foundation";
2525

2626
// Local recipes for use in documentation files.
2727

28-
export const docBaseColor = createTokenColor("doc-base-color").withDefault("#E1477E");
28+
export const docBaseColor = createTokenSwatch("doc-base-color").withDefault(Swatch.parse("#E1477E")!);
2929

3030
export const docPalette = createNonCss<Palette>("doc-palette").withDefault(
3131
(resolve: DesignTokenResolver) =>

packages/adaptive-ui-designer-core/src/registry/recipes.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { sentenceCase } from "change-case";
22
import type { DesignToken } from "@microsoft/fast-foundation";
33
import {
4+
Color,
45
densityAdjustmentUnits,
56
DesignTokenMetadata,
67
DesignTokenType,
7-
Swatch,
88
TypedCSSDesignToken
99
} from "@adaptive-web/adaptive-ui"
1010
import {
@@ -79,6 +79,7 @@ import {
7979
labelFontFamily,
8080
labelFontStyle,
8181
labelFontWeight,
82+
layerFillActiveDelta,
8283
layerFillBaseLuminance,
8384
layerFillFixedBase,
8485
layerFillFixedMinus1,
@@ -89,7 +90,10 @@ import {
8990
layerFillFixedPlus2,
9091
layerFillFixedPlus3,
9192
layerFillFixedPlus4,
93+
layerFillFocusDelta,
94+
layerFillHoverDelta,
9295
layerFillInteractive,
96+
layerFillRestDelta,
9397
neutralBaseColor,
9498
neutralFillDiscernible,
9599
neutralFillIdeal,
@@ -167,6 +171,10 @@ const designTokens: DesignTokenStore = [
167171
warningBaseColor,
168172
criticalBaseColor,
169173
layerFillBaseLuminance,
174+
layerFillRestDelta,
175+
layerFillHoverDelta,
176+
layerFillActiveDelta,
177+
layerFillFocusDelta,
170178
docBaseColor,
171179
wcagContrastLevel,
172180
densityAdjustmentUnits,
@@ -195,7 +203,7 @@ const designTokens: DesignTokenStore = [
195203
strokeStrongRestDelta,
196204
];
197205

198-
const colorTokens: DesignTokenStore<Swatch> = [
206+
const colorTokens: DesignTokenStore<Color> = [
199207
// Layer
200208
layerFillFixedMinus4,
201209
layerFillFixedMinus3,
@@ -208,36 +216,43 @@ const colorTokens: DesignTokenStore<Swatch> = [
208216
layerFillFixedPlus4,
209217
layerFillInteractive.rest,
210218
// Fill
219+
accentBaseColor,
211220
accentFillStealth.rest,
212221
accentFillSubtle.rest,
213222
accentFillIdeal.rest,
214223
accentFillDiscernible.rest,
215224
accentFillReadable.rest,
225+
highlightBaseColor,
216226
highlightFillStealth.rest,
217227
highlightFillSubtle.rest,
218228
highlightFillIdeal.rest,
219229
highlightFillDiscernible.rest,
220230
highlightFillReadable.rest,
231+
criticalBaseColor,
221232
criticalFillStealth.rest,
222233
criticalFillSubtle.rest,
223234
criticalFillIdeal.rest,
224235
criticalFillDiscernible.rest,
225236
criticalFillReadable.rest,
237+
warningBaseColor,
226238
warningFillStealth.rest,
227239
warningFillSubtle.rest,
228240
warningFillIdeal.rest,
229241
warningFillDiscernible.rest,
230242
warningFillReadable.rest,
243+
successBaseColor,
231244
successFillStealth.rest,
232245
successFillSubtle.rest,
233246
successFillIdeal.rest,
234247
successFillDiscernible.rest,
235248
successFillReadable.rest,
249+
infoBaseColor,
236250
infoFillStealth.rest,
237251
infoFillSubtle.rest,
238252
infoFillIdeal.rest,
239253
infoFillDiscernible.rest,
240254
infoFillReadable.rest,
255+
neutralBaseColor,
241256
neutralFillStealth.rest,
242257
neutralFillSubtle.rest,
243258
neutralFillIdeal.rest,

packages/adaptive-ui-designer-figma-plugin/src/figma/node.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { type Color, modeLrgb, modeRgb, parse, type Rgb, useMode, wcagLuminance } from "culori/fn";
22
import { Shadow, StyleProperty } from "@adaptive-web/adaptive-ui";
3-
import { Controller, STYLE_REMOVE } from "@adaptive-web/adaptive-ui-designer-core";
4-
import { AppliedStyleModules, AppliedStyleValues, PluginNodeData } from "@adaptive-web/adaptive-ui-designer-core";
5-
import { focusIndicatorNodeName, PluginNode, State, StatesState } from "@adaptive-web/adaptive-ui-designer-core";
3+
import { AppliedStyleModules, AppliedStyleValues, Controller, focusIndicatorNodeName, PluginNode, PluginNodeData, serializeMap, State, StatesState, STYLE_REMOVE } from "@adaptive-web/adaptive-ui-designer-core";
64
import { FIGMA_SHARED_DATA_NAMESPACE } from "@adaptive-web/adaptive-ui-designer-figma";
75
import { colorToRgba, variantBooleanHelper } from "./utility.js";
86

@@ -217,11 +215,11 @@ export class FigmaPluginNode extends PluginNode {
217215
});
218216

219217
if (deserializedDesignTokens.size) {
220-
// console.log(" reconciled design tokens", this.debugInfo, deserializedDesignTokens.serialize());
218+
// console.log(" reconciled design tokens", this.debugInfo, serializeMap(deserializedDesignTokens));
221219
}
222220

223221
if (deserializedAppliedDesignTokens.size) {
224-
// console.log(" reconciled applied design tokens", this.debugInfo, deserializedAppliedDesignTokens.serialize());
222+
// console.log(" reconciled applied design tokens", this.debugInfo, serializeMap(deserializedAppliedDesignTokens));
225223
}
226224
}
227225

packages/adaptive-ui-designer-figma-plugin/src/ui/components/design-token-add/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class DesignTokenAdd extends FASTElement {
8888
}
8989

9090
if (this.field) {
91-
this.field.value = this.selectedDesignToken?.token.default;
91+
this.field.value = "" + this.selectedDesignToken?.token.default;
9292
}
9393
}
9494
}

packages/adaptive-ui-designer-figma-plugin/src/ui/ui-controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ export class UIController {
224224
source,
225225
});
226226
} else {
227-
console.error("Token not found:", applied.tokenID, node.name, node.type);
227+
console.error("Token not found:", applied.tokenID, node.name, node.type, node.id, applied.value);
228228
}
229229
} else { // Removed
230230
allApplied.set(target, {

packages/adaptive-ui-explorer/src/components/control-pane/control-pane.template.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ElementViewTemplate, html, repeat } from "@microsoft/fast-element";
22
import { twoWay } from "@microsoft/fast-element/binding/two-way.js";
3+
import { Color } from "@adaptive-web/adaptive-ui";
34
import { WcagContrastLevel } from "@adaptive-web/adaptive-ui/reference";
45
import { ComponentType } from "../../component-type.js";
56
import { ControlPane } from "./control-pane.js";
@@ -34,7 +35,7 @@ export function controlPaneTemplate<T extends ControlPane>(): ElementViewTemplat
3435
type="color"
3536
value=${(x) => x.state.neutralColor}
3637
@change=${(x, c) =>
37-
x.state.neutralColor = c.eventTarget<HTMLInputElement>().value
38+
x.state.neutralColor = Color.parse(c.eventTarget<HTMLInputElement>().value)!
3839
}
3940
/>
4041
</div>
@@ -50,7 +51,7 @@ export function controlPaneTemplate<T extends ControlPane>(): ElementViewTemplat
5051
type="color"
5152
value=${(x) => x.state.accentColor}
5253
@change=${(x, c) =>
53-
x.state.accentColor = c.eventTarget<HTMLInputElement>().value
54+
x.state.accentColor = Color.parse(c.eventTarget<HTMLInputElement>().value)!
5455
}
5556
/>
5657
</div>
@@ -61,7 +62,7 @@ export function controlPaneTemplate<T extends ControlPane>(): ElementViewTemplat
6162
type="color"
6263
value=${(x) => x.state.highlightColor}
6364
@change=${(x, c) =>
64-
x.state.highlightColor = c.eventTarget<HTMLInputElement>().value
65+
x.state.highlightColor = Color.parse(c.eventTarget<HTMLInputElement>().value)!
6566
}
6667
/>
6768
</div>

0 commit comments

Comments
 (0)