Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[web-components] add attr for changing accent base color on design system provider #18922

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "minor",
"comment": "add attribute to recreate the accent palette using design system provider",
"packageName": "@fluentui/web-components",
"email": "[email protected]",
"dependentChangeType": "patch"
}
1 change: 1 addition & 0 deletions packages/web-components/docs/api-report.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ export const density: import("@microsoft/fast-foundation").CSSDesignToken<number
// @public
export class DesignSystemProvider extends FoundationElement {
constructor();
accentBaseColor: Swatch;
accentFillActiveDelta: number;
accentFillFocusDelta: number;
accentFillHoverDelta: number;
Expand Down
22 changes: 22 additions & 0 deletions packages/web-components/src/design-system-provider/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,28 @@ export class DesignSystemProvider extends FoundationElement {
@designToken(fillColor)
public fillColor: Swatch;

/**
* A convenience to recreate the accentPalette
* @remarks
* HTML attribute: accent-base-color
*/
@attr({
attribute: 'accent-base-color',
converter: swatchConverter,
})
public accentBaseColor: Swatch;

/**
* @internal
*/
private accentBaseColorChanged(prev: Swatch, next: Swatch): void {
if (next !== undefined && next !== null) {
accentPalette.setValueFor(this, PaletteRGB.create(next as SwatchRGB));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This kind of casting makes me a bit nervous. Is it possible to get a non-RGB swatch here somehow? If not, should we type the property to SwatchRGB instead?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bheston thoughts on the above? This mimics the neutral change you just made :)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could update the type to SwatchRGB as well. I was trying to keep the interface the same as the design tokens, which hide the RGB portion internally. I think we may actually be able to simplify this implementation in the future, so I think in the interest of not breaking the interface, I think this is a reasonable implementation. Alternatively we could toString and reparse, which wouldn't assume the type, but I'm not sure what other types of Swatches are reasonable, so I think it's unlikely to break.

} else {
accentPalette.deleteValueFor(this);
}
}

/**
* A convenience to recreate the neutralPalette
* @remarks
Expand Down