-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(web-components) fix card color (#18631)
Updated Card color handling for new design tokens Updated fill-color handling in design-system-provider Added neutral-fill-layer-rest-delta to design-system-provider Updated use of fluent-design-system-provider in samples Cleaned up styles and sorted imports
- Loading branch information
1 parent
9ab679e
commit a8ae140
Showing
36 changed files
with
483 additions
and
1,307 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@fluentui-web-components-187ac3c3-51d0-4ebc-bf18-1d431cfd1247.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "minor", | ||
"comment": "Updated Card color handling for new design tokens Updated fill-color handling in design-system-provider Added neutral-fill-layer-rest-delta to design-system-provider Updated use of fluent-design-system-provider in samples Cleaned up styles and sorted imports", | ||
"packageName": "@fluentui/web-components", | ||
"email": "47367562+bheston@users.noreply.github.com", | ||
"dependentChangeType": "patch" | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,77 +1,107 @@ | ||
import { composedParent, Card as FoundationCard, CardTemplate as template } from '@microsoft/fast-foundation'; | ||
import { attr, Notifier, Observable } from '@microsoft/fast-element'; | ||
import { parseColorHexRGB } from '@microsoft/fast-colors'; | ||
import { designSystemProvider, CardTemplate as template } from '@microsoft/fast-foundation'; | ||
import { neutralFillCard } from '../color'; | ||
import { DesignSystem } from '../fluent-design-system'; | ||
import { FluentDesignSystemProvider } from '../design-system-provider'; | ||
import { fillColor, neutralFillLayerRecipe, neutralPalette } from '../design-tokens'; | ||
import { Swatch, SwatchRGB } from '../color-vNext/swatch'; | ||
import { PaletteRGB } from '../color-vNext/palette'; | ||
import { CardStyles as styles } from './card.styles'; | ||
|
||
/** | ||
* The Fluent Card Element. Implements {@link @microsoft/fast-foundation#Card}, | ||
* {@link @microsoft/fast-foundation#CardTemplate} | ||
* | ||
* | ||
* @public | ||
* @remarks | ||
* HTML Element: \<fluent-card\> | ||
*/ | ||
@designSystemProvider({ | ||
name: 'fluent-card', | ||
template, | ||
styles, | ||
shadowOptions: { | ||
mode: 'closed', | ||
}, | ||
}) | ||
export class FluentCard extends FluentDesignSystemProvider { | ||
export class Card extends FoundationCard { | ||
/** | ||
* Background color for the card component. Sets context for the design system. | ||
* Fill color for the card component. Sets context for the design system. | ||
* | ||
* Updates the neutral palette and sets the card to the source color. For tinting use neutral-palette-source instead. | ||
* @public | ||
* @remarks | ||
* HTML Attribute: card-background-color | ||
* HTML Attribute: card-fill-color | ||
*/ | ||
@attr({ | ||
attribute: 'card-background-color', | ||
attribute: 'card-fill-color', | ||
mode: 'fromView', | ||
}) | ||
public cardBackgroundColor: string; | ||
private cardBackgroundColorChanged(prev: string | void, next: string | void): void { | ||
public cardFillColor: string; | ||
private cardFillColorChanged(prev: string | void, next: string | void): void { | ||
if (next) { | ||
const parsedColor = parseColorHexRGB(this.cardBackgroundColor); | ||
const parsedColor = parseColorHexRGB(next); | ||
|
||
if (parsedColor !== null) { | ||
this.neutralBaseColor = this.cardBackgroundColor; | ||
this.backgroundColor = this.cardBackgroundColor; | ||
this.neutralPaletteSource = next; | ||
fillColor.setValueFor( | ||
this, | ||
SwatchRGB.create(parsedColor.r, parsedColor.g, parsedColor.b) | ||
); | ||
} | ||
} else if (this.provider && this.provider.designSystem) { | ||
this.handleChange(this.provider.designSystem as DesignSystem, 'backgroundColor'); | ||
} | ||
} | ||
|
||
/** | ||
* Neutral palette source color for the card component. Sets context for the design system. | ||
* | ||
* This allows for tinting the card while maintaining the light or dark context. For a fixed color use card-fill-color instead. | ||
* @public | ||
* @remarks | ||
* HTML Attribute: neutral-palette-source | ||
*/ | ||
@attr({ | ||
attribute: 'neutral-palette-source', | ||
mode: 'fromView', | ||
}) | ||
public neutralPaletteSource: string; | ||
private neutralPaletteSourceChanged(prev: string | void, next: string | void): void { | ||
if (next) { | ||
const color = parseColorHexRGB(next)!; | ||
const swatch = SwatchRGB.create(color.r, color.g, color.b); | ||
neutralPalette.setValueFor(this, PaletteRGB.create(swatch)); | ||
} | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
public handleChange(source: DesignSystem, name: string): void { | ||
if (!this.cardBackgroundColor) { | ||
if (this.neutralBaseColor) { | ||
this.backgroundColor = neutralFillCard(this.designSystem as DesignSystem); | ||
} else { | ||
this.backgroundColor = neutralFillCard(source); | ||
} | ||
public handleChange(source: any, propertyName: string): void { | ||
if (!this.cardFillColor) { | ||
fillColor.setValueFor( | ||
this, | ||
(target: HTMLElement): Swatch => | ||
neutralFillLayerRecipe.getValueFor(target).evaluate(target, fillColor.getValueFor(source)), | ||
); | ||
} | ||
} | ||
|
||
connectedCallback(): void { | ||
super.connectedCallback(); | ||
const parentDSNotifier: Notifier = Observable.getNotifier(this.provider?.designSystem); | ||
parentDSNotifier.subscribe(this, 'backgroundColor'); | ||
parentDSNotifier.subscribe(this, 'neutralPalette'); | ||
this.handleChange(this.provider?.designSystem as DesignSystem, 'backgroundColor'); | ||
|
||
const parent = composedParent(this); | ||
|
||
if (parent) { | ||
const parentNotifier: Notifier = Observable.getNotifier(parent); | ||
parentNotifier.subscribe(this, 'fillColor'); | ||
parentNotifier.subscribe(this, 'neutralPalette'); | ||
this.handleChange(parent, 'fillColor'); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* The Fluent Card Element. Implements {@link @microsoft/fast-foundation#Card}, | ||
* {@link @microsoft/fast-foundation#CardTemplate} | ||
* | ||
* | ||
* @public | ||
* @remarks | ||
* HTML Element: \<fluent-card\> | ||
*/ | ||
export const fluentCard = Card.compose({ | ||
baseName: 'card', | ||
template, | ||
styles, | ||
}); | ||
|
||
/** | ||
* Styles for Card | ||
* @public | ||
*/ | ||
export const CardStyles = styles; | ||
export const cardStyles = styles; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.