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

Feat: convert card to be design system provider #15068

Merged
merged 2 commits into from
Sep 17, 2020
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": "minor",
"comment": "Feat: convert card to be design system provider",
"packageName": "@fluentui/web-components",
"email": "[email protected]",
"dependentChangeType": "patch",
"date": "2020-09-16T16:06:16.034Z"
}
2 changes: 1 addition & 1 deletion packages/web-components/src/card/card.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const CardStyles = css`
height: var(--card-height, 100%);
width: var(--card-width, 100%);
box-sizing: border-box;
background: ${neutralFillCardRestBehavior.var};
background: var(--background-color);
border-radius: calc(var(--elevated-corner-radius) * 1px);
${elevation}
}
Expand Down
16 changes: 16 additions & 0 deletions packages/web-components/src/card/fixtures/card.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
.state-override:hover {
--elevation: 12;
}

.controls {
display: flex;
margin: 20px;
flex-direction: column;
}
</style>
<div>
<fluent-card style="--card-height: 400px; --card-width: 500px;">
Expand All @@ -19,5 +25,15 @@
</fluent-card>
<br />
<fluent-card class="state-override">Custom depth on hover using CSS</fluent-card>
<br />
<fluent-card background-color="#333333" style="--card-height: 400px; --card-width: 500px; color: white">
Custom background
<div class="controls">
<fluent-button appearance="accent">Accent</fluent-button>
<fluent-button appearance="stealth">Stealth</fluent-button>
<fluent-button appearance="outline">Outline</fluent-button>
<fluent-button appearance="lightweight">Lightweight</fluent-button>
</div>
</fluent-card>
</div>
</fluent-design-system-provider>
42 changes: 40 additions & 2 deletions packages/web-components/src/card/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { customElement } from '@microsoft/fast-element';
import { Card, CardTemplate as template } from '@microsoft/fast-foundation';
import { ColorRGBA64, parseColorHexRGB } from '@microsoft/fast-colors';
import { designSystemProperty, DesignSystemProvider, CardTemplate as template } from '@microsoft/fast-foundation';
import { createColorPalette, DesignSystem } from '@microsoft/fast-components-styles-msft';
import { CardStyles as styles } from './card.styles';

/**
Expand All @@ -16,7 +18,43 @@ import { CardStyles as styles } from './card.styles';
template,
styles,
})
export class FluentCard extends Card {}
export class FluentCard extends DesignSystemProvider
implements Pick<DesignSystem, 'backgroundColor' | 'neutralPalette'> {
/**
* Background color for the banner component. Sets context for the design system.
* @public
* @remarks
* HTML Attribute: background-color
*/
@designSystemProperty({
attribute: 'background-color',
default: '#FFFFFF',
})
public backgroundColor: string;
private backgroundColorChanged(): void {
const parsedColor = parseColorHexRGB(this.backgroundColor);
this.neutralPalette = createColorPalette(parsedColor as ColorRGBA64);
}

/**
* Neutral pallette for the the design system provider.
* @internal
*/
@designSystemProperty({
attribute: false,
default: createColorPalette(parseColorHexRGB('#FFFFFF')!),
cssCustomProperty: false,
})
public neutralPalette: string[];

connectedCallback(): void {
super.connectedCallback();

if (this.backgroundColor === undefined) {
this.setAttribute('use-defaults', '');
}
}
}

/**
* Styles for Card
Expand Down