Skip to content

Commit

Permalink
feat(list): Added video web component to list
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 461910693
  • Loading branch information
material-web-copybara authored and copybara-github committed Jul 19, 2022
1 parent e7924eb commit 261b6ef
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 3 deletions.
11 changes: 11 additions & 0 deletions list/lib/_list-item-theme.scss
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
@use '@material/web/sass/resolvers';
@use '@material/web/sass/theme';
@use './image/list-item-image-theme';
@use './video/list-item-video-theme';
@use './tokens';

$selectors: (
Expand Down Expand Up @@ -129,6 +130,16 @@ $light-theme: tokens.md-comp-list-values();
map.get($theme, list-item-leading-image-shape),
)
);
@include list-item-video-theme.theme(
(
list-item-leading-video-height:
map.get($theme, list-item-leading-video-height),
list-item-leading-video-width:
map.get($theme, list-item-leading-video-width),
list-item-leading-video-shape:
map.get($theme, list-item-leading-video-shape),
)
);
}

@mixin _set-leading-icon-size($size) {
Expand Down
6 changes: 3 additions & 3 deletions list/lib/_tokens.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
list-item-overline-tracking: null,
list-item-overline-weight: null,
list-item-leading-icon-size: 24px,
list-item-leading-video-shape: null,
list-item-leading-video-width: null,
list-item-leading-video-height: null,
list-item-leading-video-shape: 0px,
list-item-leading-video-width: 114px,
list-item-leading-video-height: 64px,
list-item-leading-avatar-color: null,
list-item-leading-avatar-shape: 9999px,
list-item-leading-avatar-size: 40px,
Expand Down
36 changes: 36 additions & 0 deletions list/lib/video/_list-item-video-theme.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Copyright 2022 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

@use 'sass:map';
@use '@material/web/sass/theme';
@use '@material/web/sass/map-ext';
@use '../tokens';

$light-theme: map-ext.pick(
tokens.md-comp-list-values(),
(
list-item-leading-video-height,
list-item-leading-video-width,
list-item-leading-video-shape
)
);

$_custom-property-prefix: 'list-item-video';

@mixin theme($theme) {
$theme: theme.validate-theme($light-theme, $theme);
$theme: theme.create-theme-vars($theme, $_custom-property-prefix);

@include theme.emit-theme-vars($theme);
}

@mixin theme-styles($theme) {
$theme: theme.validate-theme($light-theme, $theme);
$theme: theme.create-theme-vars($theme, $_custom-property-prefix);

height: map.get($theme, list-item-leading-video-height);
width: map.get($theme, list-item-leading-video-width);
border-radius: map.get($theme, list-item-leading-video-shape);
}
14 changes: 14 additions & 0 deletions list/lib/video/_list-item-video.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// Copyright 2022 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

// stylelint-disable selector-class-pattern --
// Selector '.md3-*' should only be used in this project.

@mixin static-styles() {
.md3-list-item__video {
display: inline-flex;
object-fit: cover;
}
}
20 changes: 20 additions & 0 deletions list/lib/video/list-item-video-styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Copyright 2022 Google LLC
// SPDX-License-Identifier: Apache-2.0
//

// stylelint-disable selector-class-pattern --
// Selector '.md3-*' should only be used in this project.

@use './list-item-video';
@use './list-item-video-theme';

:host {
@include list-item-video.static-styles();

.md3-list-item__video {
@include list-item-video-theme.theme-styles(
list-item-video-theme.$light-theme
);
}
}
24 changes: 24 additions & 0 deletions list/lib/video/list-item-video.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import {html, LitElement, TemplateResult} from 'lit';
import {property} from 'lit/decorators';
import {ifDefined} from 'lit/directives/if-defined';

/** @soyCompatible */
export class ListItemVideo extends LitElement {
@property({type: String, reflect: true}) media = 'video';
@property({type: String, reflect: true}) video = '';
@property({type: String, reflect: true}) altText?: string;

/** @soyTemplate */
override render(): TemplateResult {
return html`
<img src="${this.video}" alt="${ifDefined(this.altText)}"
class="md3-list-item__video" />
`;
}
}
26 changes: 26 additions & 0 deletions list/list-item-video.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* @license
* Copyright 2022 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import {customElement} from 'lit/decorators';

import {ListItemVideo} from './lib/video/list-item-video';
import {styles} from './lib/video/list-item-video-styles.css';

declare global {
interface HTMLElementTagNameMap {
'md-list-item-video': MdListItemVideo;
}
}

/**
* @soyCompatible
* @final
* @suppress {visibility}
*/
@customElement('md-list-item-video')
export class MdListItemVideo extends ListItemVideo {
static override styles = [styles];
}

0 comments on commit 261b6ef

Please sign in to comment.