Skip to content

Commit 0ebd7c7

Browse files
asyncLizcopybara-github
authored andcommitted
chore(card): add styles and tests
PiperOrigin-RevId: 576660710
1 parent cbcb891 commit 0ebd7c7

File tree

8 files changed

+107
-4
lines changed

8 files changed

+107
-4
lines changed

labs/card/elevated-card_test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @license
3+
* Copyright 2023 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// import 'jasmine'; (google3-only)
8+
9+
import {createTokenTests} from '../../testing/tokens.js';
10+
11+
import {MdElevatedCard} from './elevated-card.js';
12+
13+
describe('<md-elevated-card>', () => {
14+
describe('.styles', () => {
15+
createTokenTests(MdElevatedCard.styles);
16+
});
17+
});

labs/card/filled-card_test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @license
3+
* Copyright 2023 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// import 'jasmine'; (google3-only)
8+
9+
import {createTokenTests} from '../../testing/tokens.js';
10+
11+
import {MdFilledCard} from './filled-card.js';
12+
13+
describe('<md-filled-card>', () => {
14+
describe('.styles', () => {
15+
createTokenTests(MdFilledCard.styles);
16+
});
17+
});

labs/card/internal/_elevated-card.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,9 @@
2727
@mixin styles() {
2828
$tokens: tokens.md-comp-elevated-card-values();
2929

30-
// TODO(b/261201808): add styles
30+
:host {
31+
@each $token, $value in $tokens {
32+
--_#{$token}: var(--md-elevated-card-#{$token}, #{$value});
33+
}
34+
}
3135
}

labs/card/internal/_filled-card.scss

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,9 @@
2727
@mixin styles() {
2828
$tokens: tokens.md-comp-filled-card-values();
2929

30-
// TODO(b/261201808): add styles
30+
:host {
31+
@each $token, $value in $tokens {
32+
--_#{$token}: var(--md-filled-card-#{$token}, #{$value});
33+
}
34+
}
3135
}

labs/card/internal/_outlined-card.scss

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,13 @@
2727
@mixin styles() {
2828
$tokens: tokens.md-comp-outlined-card-values();
2929

30-
// TODO(b/261201808): add styles
30+
:host {
31+
@each $token, $value in $tokens {
32+
--_#{$token}: var(--md-outlined-card-#{$token}, #{$value});
33+
}
34+
}
35+
36+
.container {
37+
outline: var(--_outline-width) solid var(--_outline-color);
38+
}
3139
}

labs/card/internal/_shared.scss

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,38 @@
33
// SPDX-License-Identifier: Apache-2.0
44
//
55

6+
// go/keep-sorted start
7+
@use '../../../elevation/elevation';
8+
// go/keep-sorted end
9+
610
@mixin styles() {
711
:host {
12+
border-radius: var(--_container-shape);
813
display: flex;
14+
padding: 16px;
15+
position: relative;
16+
}
17+
18+
// Separate element will be needed for disabled opacities (b/307361748)
19+
.container {
20+
background: var(--_container-color);
21+
border-radius: inherit;
22+
inset: 0;
23+
position: absolute;
24+
}
25+
26+
md-elevation {
27+
border-radius: inherit;
28+
29+
@include elevation.theme(
30+
(
31+
'level': var(--_container-elevation),
32+
'shadow-color': var(--_container-shadow-color),
33+
)
34+
);
35+
}
36+
37+
slot {
38+
z-index: 0; // Place content above background elements
939
}
1040
}

labs/card/internal/card.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,19 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
import '../../../elevation/elevation.js';
8+
79
import {html, LitElement} from 'lit';
810

911
/**
1012
* A card component.
1113
*/
1214
export class Card extends LitElement {
1315
protected override render() {
14-
return html`<slot></slot>`;
16+
return html`
17+
<md-elevation part="elevation"></md-elevation>
18+
<div class="container"></div>
19+
<slot></slot>
20+
`;
1521
}
1622
}

labs/card/outlined-card_test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @license
3+
* Copyright 2023 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// import 'jasmine'; (google3-only)
8+
9+
import {createTokenTests} from '../../testing/tokens.js';
10+
11+
import {MdOutlinedCard} from './outlined-card.js';
12+
13+
describe('<md-outlined-card>', () => {
14+
describe('.styles', () => {
15+
createTokenTests(MdOutlinedCard.styles);
16+
});
17+
});

0 commit comments

Comments
 (0)