Skip to content

Commit 0cb5b38

Browse files
committed
AUI: Improve StyleProperty shorthand capabilities
1 parent 4607477 commit 0cb5b38

File tree

15 files changed

+251
-157
lines changed

15 files changed

+251
-157
lines changed

examples/customize-component/src/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
BorderFill,
32
createForegroundSet,
43
Styles
54
} from "@adaptive-web/adaptive-ui";
@@ -39,7 +38,7 @@ AdaptiveDesignSystem.defineComponents({
3938
// Define a custom style module.
4039
const accentOutlineReadableControlStyles: Styles = Styles.fromProperties({
4140
backgroundFill: neutralFillSubtle,
42-
...BorderFill.all(accentStrokeReadable),
41+
borderFill: accentStrokeReadable,
4342
foregroundFill: createForegroundSet(accentStrokeReadableRecipe, neutralFillSubtle),
4443
});
4544

package-lock.json

Lines changed: 32 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
Palette,
1010
PaletteRGB,
1111
StyleProperty,
12-
stylePropertyBorderFillAll,
12+
StylePropertyShorthand,
1313
Swatch,
1414
} from "@adaptive-web/adaptive-ui";
1515
import {
@@ -34,7 +34,7 @@ export const docPalette = createNonCss<Palette>("doc-palette").withDefault(
3434

3535
export const docForegroundRecipe = createTokenColorRecipe(
3636
"doc-foreground",
37-
[...stylePropertyBorderFillAll, StyleProperty.foregroundFill],
37+
[...StylePropertyShorthand.borderFill, StyleProperty.foregroundFill],
3838
(resolve: DesignTokenResolver, params?: ColorRecipeParams) =>
3939
contrastSwatch(
4040
resolve(docPalette),

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ import { css, customElement, FASTElement, html, observable, repeat, when } from
22
import { staticallyCompose } from "@microsoft/fast-foundation";
33
import {
44
StyleProperty,
5-
stylePropertyBorderFillAll,
6-
stylePropertyBorderThicknessAll,
7-
stylePropertyCornerRadiusAll,
8-
stylePropertyPaddingAll
5+
StylePropertyShorthand,
96
} from "@adaptive-web/adaptive-ui";
107
import {
118
cornerRadiusControl,
@@ -283,7 +280,7 @@ const template = html<App>`
283280
TokenGlyphType.backgroundSwatch)}
284281
${(x) =>
285282
availableTokensTemplate(
286-
stylePropertyBorderFillAll,
283+
StylePropertyShorthand.borderFill,
287284
"Stroke",
288285
"stack",
289286
TokenGlyphType.borderSwatch
@@ -312,12 +309,12 @@ const template = html<App>`
312309
${(x) => availableStylesTemplate("Shape")}
313310
${(x) =>
314311
availableTokensTemplate(
315-
stylePropertyCornerRadiusAll,
312+
StylePropertyShorthand.cornerRadius,
316313
"Corner radius",
317314
)}
318315
${(x) =>
319316
availableTokensTemplate(
320-
stylePropertyBorderThicknessAll,
317+
StylePropertyShorthand.borderThickness,
321318
"Stroke thickness",
322319
)}
323320
</div>
@@ -336,7 +333,7 @@ const template = html<App>`
336333
${(x) => availableStylesTemplate("Density")}
337334
${(x) =>
338335
availableTokensTemplate(
339-
[...stylePropertyPaddingAll, StyleProperty.gap],
336+
[...StylePropertyShorthand.padding, StyleProperty.gap],
340337
"Density",
341338
)}
342339
</div>
@@ -673,10 +670,10 @@ export class App extends FASTElement {
673670
private refreshObservables() {
674671
this.backgroundTokens = this.controller.styles.getAppliedDesignTokens([StyleProperty.backgroundFill]);
675672
this.foregroundTokens = this.controller.styles.getAppliedDesignTokens([StyleProperty.foregroundFill]);
676-
this.borderFillTokens = this.controller.styles.getAppliedDesignTokens(stylePropertyBorderFillAll);
677-
this.borderThicknessTokens = this.controller.styles.getAppliedDesignTokens(stylePropertyBorderThicknessAll);
678-
this.densityTokens = this.controller.styles.getAppliedDesignTokens([...stylePropertyPaddingAll, StyleProperty.gap]);
679-
this.cornerRadiusTokens = this.controller.styles.getAppliedDesignTokens(stylePropertyCornerRadiusAll);
673+
this.borderFillTokens = this.controller.styles.getAppliedDesignTokens(StylePropertyShorthand.borderFill);
674+
this.borderThicknessTokens = this.controller.styles.getAppliedDesignTokens(StylePropertyShorthand.borderThickness);
675+
this.densityTokens = this.controller.styles.getAppliedDesignTokens([...StylePropertyShorthand.padding, StyleProperty.gap]);
676+
this.cornerRadiusTokens = this.controller.styles.getAppliedDesignTokens(StylePropertyShorthand.cornerRadius);
680677
this.textTokens = this.controller.styles.getAppliedDesignTokens([
681678
StyleProperty.fontFamily,
682679
StyleProperty.fontStyle,

packages/adaptive-ui/docs/api-report.md

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ export function blackOrWhiteByContrastSet(set: InteractiveSwatchSet, minContrast
4040
// @public
4141
export type BooleanCondition = string;
4242

43-
// @public (undocumented)
43+
// @public @deprecated (undocumented)
4444
export const BorderFill: {
4545
all: (value: StyleValue) => StyleProperties;
4646
};
4747

48-
// @public (undocumented)
48+
// @public @deprecated (undocumented)
4949
export const BorderStyle: {
5050
all: (value: StyleValue) => StyleProperties;
5151
};
5252

53-
// @public (undocumented)
53+
// @public @deprecated (undocumented)
5454
export const BorderThickness: {
5555
all: (value: StyleValue) => StyleProperties;
5656
};
@@ -133,7 +133,7 @@ export function contrastSwatch(palette: Palette, reference: Swatch, minContrast:
133133
// @public
134134
export const convertStylesToFocusState: (styles: Styles) => Styles;
135135

136-
// @public (undocumented)
136+
// @public @deprecated (undocumented)
137137
export const CornerRadius: {
138138
all: (value: StyleValue) => StyleProperties;
139139
};
@@ -300,6 +300,9 @@ export type DesignTokenType = ValuesOf<typeof DesignTokenType> | string;
300300
// @public
301301
export function directionByIsDark(color: RelativeLuminance): PaletteDirectionValue;
302302

303+
// @public
304+
export type EffectiveStylePropertiesMap = Map<string, StyleValue>;
305+
303306
// @public
304307
export class ElementStylesRenderer {
305308
constructor(styles: Styles);
@@ -410,7 +413,7 @@ export function luminanceSwatch(luminance: number): Swatch;
410413
// @public
411414
export function makeSelector(params: StyleModuleEvaluateParameters, state: InteractiveState): string;
412415

413-
// @public (undocumented)
416+
// @public @deprecated (undocumented)
414417
export const Padding: {
415418
all: (value: StyleValue) => StyleProperties;
416419
verticalHorizontal: (valueVertical: StyleValue, valueHorizontal: StyleValue) => StyleProperties;
@@ -555,6 +558,9 @@ export type StyleDeclaration = {
555558
properties?: StyleProperties;
556559
};
557560

561+
// @public
562+
export type StyleKey = StyleProperty | StylePropertyShorthand | (string & Record<never, never>);
563+
558564
// @public
559565
export type StyleModuleEvaluateParameters = StyleModuleTarget & InteractivityDefinition;
560566

@@ -570,10 +576,10 @@ export interface StyleModuleTarget {
570576
}
571577

572578
// @public
573-
export type StyleProperties = Partial<Record<StylePropertyCss, StyleValue>>;
579+
export type StyleProperties = Partial<Record<StyleKey, StyleValue>>;
574580

575581
// @public
576-
export type StylePropertiesMap = Map<StylePropertyCss, StyleValue>;
582+
export type StylePropertiesMap = Map<StyleKey, StyleValue>;
577583

578584
// @public
579585
export const StyleProperty: {
@@ -626,24 +632,41 @@ export const StyleProperty: {
626632
// @public
627633
export type StyleProperty = ValuesOf<typeof StyleProperty>;
628634

629-
// @public
635+
// @public @deprecated
630636
export const stylePropertyBorderFillAll: ("borderFillTop" | "borderFillRight" | "borderFillBottom" | "borderFillLeft")[];
631637

632-
// @public
638+
// @public @deprecated
633639
export const stylePropertyBorderStyleAll: ("borderStyleTop" | "borderStyleRight" | "borderStyleBottom" | "borderStyleLeft")[];
634640

635-
// @public
641+
// @public @deprecated
636642
export const stylePropertyBorderThicknessAll: ("borderThicknessTop" | "borderThicknessRight" | "borderThicknessBottom" | "borderThicknessLeft")[];
637643

638-
// @public
644+
// @public @deprecated
639645
export const stylePropertyCornerRadiusAll: ("cornerRadiusTopLeft" | "cornerRadiusTopRight" | "cornerRadiusBottomRight" | "cornerRadiusBottomLeft")[];
640646

641-
// @public
647+
// @public @deprecated
642648
export type StylePropertyCss = StyleProperty | (string & Record<never, never>);
643649

644-
// @public
650+
// @public @deprecated
645651
export const stylePropertyPaddingAll: ("paddingTop" | "paddingRight" | "paddingBottom" | "paddingLeft")[];
646652

653+
// @public (undocumented)
654+
export const StylePropertyShorthand: {
655+
borderFill: ("borderFillTop" | "borderFillRight" | "borderFillBottom" | "borderFillLeft")[];
656+
borderThickness: ("borderThicknessTop" | "borderThicknessRight" | "borderThicknessBottom" | "borderThicknessLeft")[];
657+
borderStyle: ("borderStyleTop" | "borderStyleRight" | "borderStyleBottom" | "borderStyleLeft")[];
658+
cornerRadius: ("cornerRadiusTopLeft" | "cornerRadiusTopRight" | "cornerRadiusBottomRight" | "cornerRadiusBottomLeft")[];
659+
margin: ("marginTop" | "marginRight" | "marginBottom" | "marginLeft")[];
660+
marginHorizontal: ("marginRight" | "marginLeft")[];
661+
marginVertical: ("marginTop" | "marginBottom")[];
662+
padding: ("paddingTop" | "paddingRight" | "paddingBottom" | "paddingLeft")[];
663+
paddingHorizontal: ("paddingRight" | "paddingLeft")[];
664+
paddingVertical: ("paddingTop" | "paddingBottom")[];
665+
};
666+
667+
// @public
668+
export type StylePropertyShorthand = keyof typeof StylePropertyShorthand;
669+
647670
// @public
648671
export type StyleRule = {
649672
target?: StyleModuleTarget;
@@ -660,7 +683,7 @@ export class Styles {
660683
static compose(styles: Styles[], properties?: StyleProperties, name?: string): Styles;
661684
get composed(): Styles[] | undefined;
662685
get effectiveAdaptiveProperties(): Map<StyleProperty, StyleValue>;
663-
get effectiveProperties(): StylePropertiesMap;
686+
get effectiveProperties(): EffectiveStylePropertiesMap;
664687
static fromDeclaration(declaration: StyleDeclaration, name?: string): Styles;
665688
static fromProperties(properties: StyleProperties, name?: string): Styles;
666689
readonly name: string | undefined;

0 commit comments

Comments
 (0)