Skip to content

Commit f35c710

Browse files
authored
Designer: Added support for applying individual density tokens (#176)
1 parent d9a07e8 commit f35c710

File tree

6 files changed

+65
-15
lines changed

6 files changed

+65
-15
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Updated density token settings",
4+
"packageName": "@adaptive-web/adaptive-ui",
5+
"email": "47367562+bheston@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,16 @@ const strokeWidthTokens: DesignTokenStore = [
250250
];
251251

252252
const densityTokens: DesignTokenStore<string> = [
253+
densityControl.horizontalPadding,
254+
densityControl.verticalPadding,
253255
densityControl.horizontalGap,
254256
densityControl.verticalGap,
257+
densityItemContainer.horizontalPadding,
258+
densityItemContainer.verticalPadding,
255259
densityItemContainer.horizontalGap,
256260
densityItemContainer.verticalGap,
261+
densityLayer.horizontalPadding,
262+
densityLayer.verticalPadding,
257263
densityLayer.horizontalGap,
258264
densityLayer.verticalGap,
259265
];

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,18 @@ const SOLID_BLACK: SolidPaint = {
2424
},
2525
};
2626

27+
const SOLID_TRANSPARENT: SolidPaint = {
28+
type: "SOLID",
29+
visible: true,
30+
opacity: 0,
31+
blendMode: "NORMAL",
32+
color: {
33+
r: 1,
34+
g: 1,
35+
b: 1,
36+
},
37+
};
38+
2739
function isNodeType<T extends BaseNode>(type: NodeType): (node: BaseNode) => node is T {
2840
return (node: BaseNode): node is T => node.type === type;
2941
}
@@ -850,6 +862,9 @@ export class FigmaPluginNode extends PluginNode {
850862

851863
private paintStrokeWidth(value: string): void {
852864
(this._node as MinimalStrokesMixin).strokeWeight = this.safeNumber(value);
865+
if ((this._node as MinimalStrokesMixin).strokes.length === 0) {
866+
(this._node as MinimalStrokesMixin).strokes = [SOLID_TRANSPARENT];
867+
}
853868
}
854869

855870
private paintCornerRadius(target: StyleProperty, value: string): void {

packages/adaptive-ui-figma-designer/src/ui/app.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import {
44
StyleProperty,
55
stylePropertyBorderFillAll,
66
stylePropertyBorderThicknessAll,
7-
stylePropertyCornerRadiusAll
7+
stylePropertyCornerRadiusAll,
8+
stylePropertyPaddingAll
89
} from "@adaptive-web/adaptive-ui";
910
import {
1011
cornerRadiusControl,
@@ -130,28 +131,28 @@ const appliedTokensTemplate = (
130131
`;
131132

132133
const availableTokensTemplate = (
133-
tokenType: StyleProperty[], // Changed to array for _applying_ individual values like top/bottom, but only _checking_ the first one.
134+
tokenTypes: StyleProperty[],
134135
title: string | null,
135136
tokenLayout: "stack" | "grid" = "stack",
136137
glyphType?: TokenGlyphType
137138
) => html<App>`
138139
${when(
139-
(x) => x.selectedNodes?.some((node) => node.supports.includes(tokenType[0])),
140+
(x) => x.selectedNodes?.some((node) => tokenTypes.some((prop) => node.supports.includes(prop))),
140141
html<App>`
141142
${when(
142143
(_) => title,
143144
html`<p class="title">${(_) => title}</p>`
144145
)}
145146
<div class="swatch-${tokenLayout}">
146147
${repeat(
147-
(x) => x.controller.styles.getAppliableDesignTokenOptionsByType(tokenType[0]),
148+
(x) => x.controller.styles.getAppliableDesignTokenOptions(tokenTypes),
148149
html<DesignTokenDefinition, App>`
149150
<designer-style-token-item
150151
title=${(x) => x.title}
151152
value=${(x, c) => c.parent.controller.designTokens.getDefaultDesignTokenValueAsString(x.token)}
152153
glyphType=${(_) => glyphType}
153154
content-button
154-
@click=${(x, c) => c.parent.controller.styles.applyDesignToken(tokenType, x)}
155+
@click=${(x, c) => c.parent.controller.styles.applyDesignToken(x.intendedFor, x)}
155156
>
156157
</designer-style-token-item>
157158
`
@@ -307,7 +308,7 @@ const template = html<App>`
307308
${(x) => availableStylesTemplate("Density")}
308309
${(x) =>
309310
availableTokensTemplate(
310-
[StyleProperty.gap],
311+
[...stylePropertyPaddingAll, StyleProperty.gap],
311312
"Density",
312313
)}
313314
</div>
@@ -617,7 +618,7 @@ export class App extends FASTElement {
617618
this.foregroundTokens = this.controller.styles.getAppliedDesignTokens([StyleProperty.foregroundFill]);
618619
this.borderFillTokens = this.controller.styles.getAppliedDesignTokens(stylePropertyBorderFillAll);
619620
this.borderThicknessTokens = this.controller.styles.getAppliedDesignTokens(stylePropertyBorderThicknessAll);
620-
this.densityTokens = this.controller.styles.getAppliedDesignTokens([StyleProperty.gap]);
621+
this.densityTokens = this.controller.styles.getAppliedDesignTokens([...stylePropertyPaddingAll, StyleProperty.gap]);
621622
this.cornerRadiusTokens = this.controller.styles.getAppliedDesignTokens(stylePropertyCornerRadiusAll);
622623
this.textTokens = this.controller.styles.getAppliedDesignTokens([
623624
StyleProperty.fontFamily,

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

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export class StylesController {
132132
}
133133

134134
/**
135-
* Gets a display representation of applied design tokens for the selected nodes.
135+
* Gets a display representation of applied design tokens for the style property types.
136136
*
137137
* @param targets - Style property types
138138
* @returns Applied design tokens
@@ -172,14 +172,35 @@ export class StylesController {
172172
}
173173

174174
/**
175-
* Gets a list of appliable design tokens for the style property type.
175+
* Gets a list of appliable design tokens for the style property types.
176176
*
177-
* @param target - Style property type
177+
* @param targets - Style property types
178178
* @returns List of available appliable design tokens
179179
*/
180-
public getAppliableDesignTokenOptionsByType(target: StyleProperty): DesignTokenDefinition[] {
181-
const val = this.controller.appliableDesignTokenRegistry.find(target);
182-
return val;
180+
public getAppliableDesignTokenOptions(targets: StyleProperty[]): DesignTokenDefinition[] {
181+
const tokens: DesignTokenDefinition[] = [];
182+
183+
// Collect the individual tokens available for the requested targets
184+
// TODO: Handle multiple values better
185+
targets.forEach(target => {
186+
const appliable = this.controller.appliableDesignTokenRegistry.find(target);
187+
if (appliable) {
188+
tokens.push(...appliable);
189+
}
190+
});
191+
192+
// Group by token name
193+
return tokens.reduce((accumulated: DesignTokenDefinition[], current: DesignTokenDefinition): DesignTokenDefinition[] => {
194+
const found = accumulated.find((item) => {
195+
return item.token.name === current.token.name
196+
});
197+
198+
if (!found) {
199+
accumulated.push(current);
200+
}
201+
202+
return accumulated;
203+
}, []).sort((a, b): number => a.title.localeCompare(b.title));
183204
}
184205

185206
/**

packages/adaptive-ui/src/density/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ export class DensityPaddingAndGapTokenGroup implements TokenGroup {
137137

138138
this.horizontalPadding = createTokenDimension(
139139
`${name}-horizontal-padding`,
140-
[StyleProperty.paddingTop, StyleProperty.paddingRight, StyleProperty.paddingBottom, StyleProperty.paddingLeft],
140+
[StyleProperty.paddingRight, StyleProperty.paddingLeft],
141141
).withDefault(
142142
(resolve: DesignTokenResolver) =>
143143
`calc((${resolve(this.horizontalPaddingUnits) + resolve(densityAdjustmentUnits)} * ${resolve(designUnit)}) - ${resolve(strokeThickness)})`
@@ -163,7 +163,7 @@ export class DensityPaddingAndGapTokenGroup implements TokenGroup {
163163

164164
this.verticalPadding = createTokenDimension(
165165
`${name}-vertical-padding`,
166-
[StyleProperty.paddingTop, StyleProperty.paddingRight, StyleProperty.paddingBottom, StyleProperty.paddingLeft],
166+
[StyleProperty.paddingTop, StyleProperty.paddingBottom],
167167
).withDefault(
168168
(resolve: DesignTokenResolver) =>
169169
`calc((${resolve(this.verticalPaddingUnits) + resolve(densityAdjustmentUnits)} * ${resolve(designUnit)}) - ${resolve(strokeThickness)})`

0 commit comments

Comments
 (0)