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

fix: correct palette generation behavior in Card #15429

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,8 @@
{
"type": "patch",
"comment": "removes palette generation for every card and adds better null checking to avoid runtime errors",
"packageName": "@fluentui/web-components",
"email": "[email protected]",
"dependentChangeType": "patch",
"date": "2020-10-08T17:29:03.955Z"
}
9 changes: 9 additions & 0 deletions packages/web-components/src/card/card.stories.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { createColorPalette } from '@microsoft/fast-components-styles-msft';
import { ColorRGBA64 } from '@microsoft/fast-colors';
import { FluentDesignSystemProvider } from '../design-system-provider';
import CardTemplate from './fixtures/card.html';
import { FluentCard } from './';
Expand All @@ -11,3 +13,10 @@ export default {
};

export const Card = (): string => CardTemplate;

document.addEventListener('readystatechange', e => {
if (document.readyState === 'complete') {
const red = document.getElementById('red') as FluentDesignSystemProvider;
red.neutralPalette = createColorPalette(new ColorRGBA64(1, 0, 0));
}
});
2 changes: 1 addition & 1 deletion packages/web-components/src/card/fixtures/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</fluent-card>
</fluent-design-system-provider>

<fluent-design-system-provider use-defaults background-color="#FF0000">
<fluent-design-system-provider use-defaults background-color="#FF0000" id="red">
<fluent-card style="--card-height: 400px; --card-width: 500px;">
Red
<div class="controls">
Expand Down
28 changes: 14 additions & 14 deletions packages/web-components/src/card/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { attr, Notifier, Observable } from '@microsoft/fast-element';
import { ColorRGBA64, parseColorHexRGB } from '@microsoft/fast-colors';
import { parseColorHexRGB } from '@microsoft/fast-colors';
import { designSystemProperty, designSystemProvider, CardTemplate as template } from '@microsoft/fast-foundation';
import { createColorPalette, DesignSystem, neutralFillCard } from '@microsoft/fast-components-styles-msft';
import { FluentDesignSystemProvider } from '../design-system-provider';
Expand Down Expand Up @@ -34,7 +34,10 @@ export class FluentCard extends FluentDesignSystemProvider
public backgroundColor: string;
protected backgroundColorChanged(): void {
const parsedColor = parseColorHexRGB(this.backgroundColor);
this.neutralPalette = createColorPalette(parsedColor as ColorRGBA64);

if (parsedColor !== null) {
this.neutralPalette = createColorPalette(parsedColor);
}
}

/**
Expand All @@ -49,8 +52,11 @@ export class FluentCard extends FluentDesignSystemProvider
public cardBackgroundColor: string;
private cardBackgroundColorChanged(): void {
const parsedColor = parseColorHexRGB(this.cardBackgroundColor);
this.neutralPalette = createColorPalette(parsedColor as ColorRGBA64);
this.backgroundColor = this.cardBackgroundColor;

if (parsedColor !== null) {
this.neutralPalette = createColorPalette(parsedColor);
this.backgroundColor = this.cardBackgroundColor;
}
}

/**
Expand All @@ -69,21 +75,15 @@ export class FluentCard extends FluentDesignSystemProvider
*/
public handleChange(source: DesignSystem, name: string): void {
if (!this.cardBackgroundColor) {
const parsedColor = parseColorHexRGB(source[name]);
this.neutralPalette = createColorPalette(parsedColor as ColorRGBA64);
const designSystem: DesignSystem = Object.assign({}, this.designSystem, {
backgroundColor: source[name],
neutralPallette: this.neutralPalette,
} as any);
this.backgroundColor = neutralFillCard(designSystem);
this.backgroundColor = neutralFillCard(source);
}
}

connectedCallback(): void {
super.connectedCallback();
const desinSystemNotifier: Notifier = Observable.getNotifier(this.provider?.designSystem);
desinSystemNotifier.subscribe(this, 'backgroundColor');
desinSystemNotifier.subscribe(this, 'neutralPalette');
const designSystemNotifier: Notifier = Observable.getNotifier(this.provider?.designSystem);
designSystemNotifier.subscribe(this, 'backgroundColor');
designSystemNotifier.subscribe(this, 'neutralPalette');
this.handleChange(this.provider?.designSystem as DesignSystem, 'backgroundColor');
}
}
Expand Down