Skip to content

Commit

Permalink
chore(card): add Sass theming apis
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 575887392
  • Loading branch information
asyncLiz authored and copybara-github committed Oct 25, 2023
1 parent 2a06b29 commit 25e917e
Show file tree
Hide file tree
Showing 15 changed files with 255 additions and 0 deletions.
6 changes: 6 additions & 0 deletions labs/card/_elevated-card.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//
// Copyright 2023 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

@forward './internal/elevated-card' show theme;
6 changes: 6 additions & 0 deletions labs/card/_filled-card.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//
// Copyright 2023 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

@forward './internal/filled-card' show theme;
6 changes: 6 additions & 0 deletions labs/card/_outlined-card.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
//
// Copyright 2023 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

@forward './internal/outlined-card' show theme;
26 changes: 26 additions & 0 deletions labs/card/elevated-card.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import {customElement} from 'lit/decorators.js';

import {Card} from './internal/card.js';
import {styles as elevatedStyles} from './internal/elevated-styles.css.js';
import {styles as sharedStyles} from './internal/shared-styles.css.js';

declare global {
interface HTMLElementTagNameMap {
'md-elevated-card': MdElevatedCard;
}
}

/**
* @final
* @suppress {visibility}
*/
@customElement('md-elevated-card')
export class MdElevatedCard extends Card {
static override styles = [sharedStyles, elevatedStyles];
}
26 changes: 26 additions & 0 deletions labs/card/filled-card.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import {customElement} from 'lit/decorators.js';

import {Card} from './internal/card.js';
import {styles as filledStyles} from './internal/filled-styles.css.js';
import {styles as sharedStyles} from './internal/shared-styles.css.js';

declare global {
interface HTMLElementTagNameMap {
'md-filled-card': MdFilledCard;
}
}

/**
* @final
* @suppress {visibility}
*/
@customElement('md-filled-card')
export class MdFilledCard extends Card {
static override styles = [sharedStyles, filledStyles];
}
31 changes: 31 additions & 0 deletions labs/card/internal/_elevated-card.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Copyright 2023 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

// go/keep-sorted start
@use 'sass:list';
// go/keep-sorted end
// go/keep-sorted start
@use '../../../tokens';
// go/keep-sorted end

@mixin theme($tokens) {
$supported-tokens: tokens.$md-comp-elevated-card-supported-tokens;

@each $token, $value in $tokens {
@if list.index($supported-tokens, $token) == null {
@error 'Elevated card `#{$token}` is not a supported token.';
}

@if $value {
--md-elevated-card-#{$token}: #{$value};
}
}
}

@mixin styles() {
$tokens: tokens.md-comp-elevated-card-values();

// TODO(b/261201808): add styles
}
31 changes: 31 additions & 0 deletions labs/card/internal/_filled-card.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Copyright 2023 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

// go/keep-sorted start
@use 'sass:list';
// go/keep-sorted end
// go/keep-sorted start
@use '../../../tokens';
// go/keep-sorted end

@mixin theme($tokens) {
$supported-tokens: tokens.$md-comp-filled-card-supported-tokens;

@each $token, $value in $tokens {
@if list.index($supported-tokens, $token) == null {
@error 'Filled card `#{$token}` is not a supported token.';
}

@if $value {
--md-filled-card-#{$token}: #{$value};
}
}
}

@mixin styles() {
$tokens: tokens.md-comp-filled-card-values();

// TODO(b/261201808): add styles
}
31 changes: 31 additions & 0 deletions labs/card/internal/_outlined-card.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// Copyright 2023 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

// go/keep-sorted start
@use 'sass:list';
// go/keep-sorted end
// go/keep-sorted start
@use '../../../tokens';
// go/keep-sorted end

@mixin theme($tokens) {
$supported-tokens: tokens.$md-comp-outlined-card-supported-tokens;

@each $token, $value in $tokens {
@if list.index($supported-tokens, $token) == null {
@error 'Outlined card `#{$token}` is not a supported token.';
}

@if $value {
--md-outlined-card-#{$token}: #{$value};
}
}
}

@mixin styles() {
$tokens: tokens.md-comp-outlined-card-values();

// TODO(b/261201808): add styles
}
10 changes: 10 additions & 0 deletions labs/card/internal/_shared.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Copyright 2023 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

@mixin styles() {
:host {
display: flex;
}
}
16 changes: 16 additions & 0 deletions labs/card/internal/card.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import {html, LitElement} from 'lit';

/**
* A card component.
*/
export class Card extends LitElement {
protected override render() {
return html`<slot></slot>`;
}
}
10 changes: 10 additions & 0 deletions labs/card/internal/elevated-styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Copyright 2023 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

// go/keep-sorted start
@use './elevated-card';
// go/keep-sorted end

@include elevated-card.styles;
10 changes: 10 additions & 0 deletions labs/card/internal/filled-styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Copyright 2023 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

// go/keep-sorted start
@use './filled-card';
// go/keep-sorted end

@include filled-card.styles;
10 changes: 10 additions & 0 deletions labs/card/internal/outlined-styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Copyright 2023 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

// go/keep-sorted start
@use './outlined-card';
// go/keep-sorted end

@include outlined-card.styles;
10 changes: 10 additions & 0 deletions labs/card/internal/shared-styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//
// Copyright 2023 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

// go/keep-sorted start
@use './shared';
// go/keep-sorted end

@include shared.styles;
26 changes: 26 additions & 0 deletions labs/card/outlined-card.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @license
* Copyright 2023 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import {customElement} from 'lit/decorators.js';

import {Card} from './internal/card.js';
import {styles as outlinedStyles} from './internal/outlined-styles.css.js';
import {styles as sharedStyles} from './internal/shared-styles.css.js';

declare global {
interface HTMLElementTagNameMap {
'md-outlined-card': MdOutlinedCard;
}
}

/**
* @final
* @suppress {visibility}
*/
@customElement('md-outlined-card')
export class MdOutlinedCard extends Card {
static override styles = [sharedStyles, outlinedStyles];
}

0 comments on commit 25e917e

Please sign in to comment.