Skip to content

Commit

Permalink
refactor(list)!: refactor list using md-item
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `<md-list-item>` now uses slots instead of properties and has removed many prescriptive items (such as avatar, image, and video items). The default slot can be used for any custom content.
```html
<md-list-item>
  <div slot="overline">OVERLINE</div>
  <div slot="headline">First line</div>
  <div slot="supporting-text">Second+ lines</div>
  <div slot="trailing-supporting-text">Trailing</div>
  <md-icon slot="start">star</md-icon>
  <md-icon slot="end">star</md-icon>
</md-list-item>
```
Add `type="button"` or `type="link"` for interactive list items.

PiperOrigin-RevId: 567732201
  • Loading branch information
asyncLiz authored and copybara-github committed Sep 22, 2023
1 parent 5fad4f0 commit 7536774
Show file tree
Hide file tree
Showing 14 changed files with 302 additions and 986 deletions.
2 changes: 1 addition & 1 deletion item/demo/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ function getKnobContent(knobs: StoryKnobs, threeLines = false) {
html`<md-icon class=${classMap(classes)} slot="end">star</md-icon>` :
nothing;

return html`${overline}${trailingText}${leadingIcon}${trailingIcon}`;
return [overline, trailingText, leadingIcon, trailingIcon];
}

/** Item stories. */
Expand Down
55 changes: 5 additions & 50 deletions list/demo/demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,63 +7,18 @@
import './index.js';
import './material-collection.js';

import {KnobTypesToKnobs, MaterialCollection, materialInitsToStoryInits, setUpDemo, title} from './material-collection.js';
import {KnobTypesToKnobs, MaterialCollection, materialInitsToStoryInits, setUpDemo} from './material-collection.js';
import {boolInput, Knob, textInput} from './index.js';

import {stories, StoryKnobs} from './stories.js';

/**
* User avatar as a dataurl.
*/
export const AVATAR_URL =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGAAAABgCAAAAADH8yjkAAABsklEQVR4Ae3WBaLjMAxF0dn/np4hVEY3cQqOupNh/i4oVT76buAUEkmfzgOXgAS8QiABCUhAAg71dlsfhgJOc4vv2flpAICWGr/TS5IGQoV/qoIs0OX4r7wTBcZ40lgSqBGplgMoQ6SMxACPaF4MmCPaXAwoEa0UAyyiWTFAIZoSAwyiGTGgQLRCDJgh2kwMaBCtEQPIIpIluVnkEMkJDjuq8KSKJMd1eDLusiC70U45/ik/Se/kbqbwOzXrBrgqDtOfhJoeBrqLyLvl0nlKp2MCXi1Ap1Prndv59iQOdPVqkqu/J9FoWQcp4LguES1f7B8HaJPhStk6PASElcGN9CL0B9YKd6TWPYFjgTsrjn2ARuPudMMHdgqM1I4LtAqsVMsDyIKZJRawBLslC7BgZzlAQI8CA+gM2JmOAZy9AjPleY/pAswWZx5AFVhVxATOVIJRSfxZRAXurqA+07Qb4c5GXb99QAvc1YJ6bzSncTPtHtnJYYwbjcODV0WT40p5I3C21AUQr6iFDi8/M5HZM/OSp2O7HP+FmPGyHeD4Db5x261rfEjnewISkIAEJODDAV8A/z6x+ahJu3sAAAAASUVORK5CYII=';

/**
* Example image as a dataurl.
*/
export const IMAGE_URL =
'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAHAAAABwCAYAAADG4PRLAAAK4GlDQ1BJQ0MgUHJvZmlsZQAASImVlwdUk8kWgOf/00NCgNClhN6RTgApoYciSAdRCUkgoYSYEBDEzuIKrgoiIqCu4EpTcHUpshbEggVRbNgXRBTUdbFgQ2V/4BF295333nn3nPnnO/e/c+fee2bOuQMA2Z8lFKbBcgCkCzJFYX6etJjYOBruKcABWUAFENBnscVCRmhoEEBkdv67vL+N2CFyw2LK17///6+iwOGK2QBA8QgncsTsdIQ7kfGcLRRlAoA6iOj1sjOFU3wNYUUREiDCT6Y4eYY/TnHiNKNJ0zYRYV4I0wDAk1gsUTIAJHNET8tiJyN+SFM5WAk4fAHCeQi7sXksDsLHETZPT8+Y4hGEjRF7IQBkpDqAnvgXn8l/858o9c9iJUt5Jq9pwXvzxcI0Vs7/WZr/Lelpktk9DJFB4on8w6ZqitTvTmpGoJQFiQtDZpnPman7FPMk/pGzzBZ7xc0yh+UdKF2btjBolpP4vkypn0xmxCxzxT7hsyz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4B7wPn54Tzvb4gN8nXvk5jbu0KcT3f/dnW2W9pbOeKsv7FgoIiVTSfr48zvKpMW99+7LJQRgJBKmvd0dV/cVy6yv378PYd93tncovZ6mk6+nxg9kWQ0+wrqN7MYmHXFofdLB9RFC1kYI055EBQEcYjhz+YLxe/RmRUPLkN3cpP1Xu8anEy3FPVlmQizwXoG++ToHgSEG9m9rXjWNjdcRFoiIMoTiI2E6LLGSoNXVFA/OV2k7u8UdFfe25tIAX3jkAHKV32Op5L7hAP7uiOX1gT+8+VgfiPUOYe6ohDmvwxb3SFoN8JFKnj4AMJi5EeHDe7oGa0f1MMKa3qS5SgOUBoU1QTRAa3qT5ioNUBoU1gTRAK3pTZqrNEBpUFgTRAO0pjdprtIApUFhTRAN0JrepLlKA5QGhTVBNEBrepPmKg1QGhTWBNEArelNmqs0QGlQWBNEA7SmN2mugj/Qu3XGzqhB7G5yzsgorNT/AQI1K7I2zvkPAAAAAElFTkSuQmCC';

/**
* One frame of the color blue in webm as a dataurl.
*
* Generated with
* ffmpeg -f lavfi -i color=blue:s=1280x720 -vframes 1 ~/out.webm
* cat ~/out.webm | base64 | tr -d '\n'
*/
export const VIDEO_URL =
'data:video/webm;base64,GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQJChYECGFOAZwEAAAAAAAJrEU2bdLpNu4tTq4QVSalmU6yBoU27i1OrhBZUrmtTrIHYTbuMU6uEElTDZ1OsggEgTbuMU6uEHFO7a1OsggJV7AEAAAAAAABZAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSalmsirXsYMPQkBNgI1MYXZmNTkuMjcuMTAwV0GNTGF2ZjU5LjI3LjEwMESJiEBEAAAAAAAAFlSua8OuAQAAAAAAADrXgQFzxYjFaDr5zFhASZyBACK1nIN1bmSIgQCGhVZfVlA5g4EBI+ODhAJiWgDgi7CCBQC6ggLQmoECElTDZ0CBc3OgY8CAZ8iaRaOHRU5DT0RFUkSHjUxhdmY1OS4yNy4xMDBzc9tjwItjxYjFaDr5zFhASWfIpUWjh0VOQ09ERVJEh5hMYXZjNTkuMzcuMTAwIGxpYnZweC12cDlnyKJFo4hEVVJBVElPTkSHlDAwOjAwOjAwLjA0MDAwMDAwMAAAH0O2dUCo54EAo0CigQAAgIJJg0IAT/As9gA4JBwYShgAQGIMw/o6+kdo6+kAuaP9KgAAAAAcZw5Vl/m2cRY6ymCqlMFVJYKqSwVSleqUBBBCAAAAABxnDlWX+bZxFjrKYKqUwVUlgqpLBVKV6pQEEEIAAAAAHGcOVZf5tnEWOspgqpTBVSWCqksFUpXqlAQQQgBnDlWX+bZxFjrKYKqUwVUlgqpLBVKV6pQEEEIAHFO7a5G7j7OBALeK94EB8YIBp/CBAw==';

const collection =
new MaterialCollection<KnobTypesToKnobs<StoryKnobs>>('List', [
new Knob('md-list-item', {ui: title()}),
new Knob('disabled', {ui: boolInput(), defaultValue: false}),
new Knob('interactive', {ui: boolInput(), defaultValue: false}),
new Knob(
'multiLineSupportingText', {ui: boolInput(), defaultValue: false}),
new Knob('headline', {ui: textInput(), defaultValue: 'Headline'}),
new Knob('supportingText', {ui: textInput(), defaultValue: ''}),
new Knob('trailingSupportingText', {ui: textInput(), defaultValue: ''}),
new Knob('href', {ui: textInput(), defaultValue: 'https://google.com'}),
new Knob('target', {ui: textInput(), defaultValue: '_blank'}),
new Knob('link end icon', {ui: textInput(), defaultValue: 'open_in_new'}),

new Knob('slot[name=start|end-icon]', {ui: title()}),
new Knob('start icon', {ui: textInput(), defaultValue: 'account_circle'}),
new Knob('end icon', {ui: textInput(), defaultValue: 'check_circle'}),

new Knob('slot[name=start-avatar]', {ui: title()}),
new Knob('avatar img', {ui: textInput(), defaultValue: AVATAR_URL}),
new Knob('avatar label', {ui: textInput(), defaultValue: 'EM'}),

new Knob('slot[name=start-image]', {ui: title()}),
new Knob('image', {ui: textInput(), defaultValue: IMAGE_URL}),

new Knob('slot[name=start-video]', {ui: title()}),
new Knob(
'slot[name=start-video-large]',
{ui: boolInput(), defaultValue: false}),
new Knob('video src', {ui: textInput(), defaultValue: VIDEO_URL}),
new Knob('overline', {ui: textInput()}),
new Knob('trailingSupportingText', {ui: textInput()}),
new Knob('leadingIcon', {ui: boolInput()}),
new Knob('trailingIcon', {ui: boolInput()}),
]);

collection.addStories(...materialInitsToStoryInits(stories));
Expand Down
236 changes: 95 additions & 141 deletions list/demo/stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,159 +10,113 @@ import '@material/web/list/list.js';
import '@material/web/icon/icon.js';

import {MaterialStoryInit} from './material-collection.js';
import {css, html} from 'lit';
import {css, html, nothing} from 'lit';
import {classMap} from 'lit/directives/class-map.js';

/** Knob types for list stories. */
export interface StoryKnobs {
'md-list-item': void;
disabled: boolean;
interactive: boolean;
multiLineSupportingText: boolean;
headline: string;
supportingText: string;
overline: string;
trailingSupportingText: string;
href: string;
target: string;
'link end icon': string;

'slot[name=start|end-icon]': void;
'start icon': string;
'end icon': string;

'slot[name=start-avatar]': void;
'avatar img': string;
'avatar label': string;

'slot[name=start-image]': void;
image: string;

'slot[name=start-video]': void;
'slot[name=start-video-large]': boolean;
'video src': string;
leadingIcon: boolean;
trailingIcon: boolean;
}

const styles = css`
md-list {
border-radius: 8px;
outline: 1px solid var(--md-sys-color-outline);
max-width: 360px;
overflow: hidden;
width: 100%;
}
`;

const standard: MaterialStoryInit<StoryKnobs> = {
name: '<md-list>',
styles: css`
.list-demo {
border-radius: 8px;
border: 1px solid var(--md-sys-color-outline);
max-width: 360px;
overflow: hidden;
width: 100%;
}
.list {
max-width: 200px;
}`,
name: 'List',
styles,
render(knobs) {
const {
disabled,
interactive,
multiLineSupportingText,
headline,
supportingText,
trailingSupportingText,
href,
target,
image,
} = knobs;
return html`
<div class="list-demo">
<md-list class="list" role="listbox">
<md-list-item
.headline=${headline}
.supportingText=${supportingText}
.multiLineSupportingText=${multiLineSupportingText}
.trailingSupportingText=${trailingSupportingText}
.disabled=${disabled}
.interactive=${interactive}>
</md-list-item>
<md-list-item
.headline=${headline}
.supportingText=${supportingText}
.multiLineSupportingText=${multiLineSupportingText}
.trailingSupportingText=${trailingSupportingText}
.disabled=${disabled}
.interactive=${interactive}>
<md-icon slot="start-icon">
${knobs['start icon']}
</md-icon>
<md-icon slot="end-icon">
${knobs['end icon']}
</md-icon>
</md-list-item>
<md-list-item
.headline=${headline}
.supportingText=${supportingText}
.multiLineSupportingText=${multiLineSupportingText}
.trailingSupportingText=${trailingSupportingText}
.disabled=${disabled}
.interactive=${interactive}
.href=${href}
.target=${target as '' | '_blank' | '_parent' | '_self' | '_top'}>
<md-icon slot="end-icon">${knobs['link end icon']}</md-icon>
</md-list-item>
<md-divider></md-divider>
<md-list-item
.headline=${headline}
.supportingText=${supportingText}
.multiLineSupportingText=${multiLineSupportingText}
.trailingSupportingText=${trailingSupportingText}
.disabled=${disabled}
.interactive=${interactive}>
<img src=${knobs['avatar img']} slot="start-avatar">
</md-list-item>
<md-list-item
.headline=${headline}
.supportingText=${supportingText}
.multiLineSupportingText=${multiLineSupportingText}
.trailingSupportingText=${trailingSupportingText}
.disabled=${disabled}
.interactive=${interactive}>
<span slot="start-avatar">
${knobs['avatar label']}
</span>
</md-list-item>
<md-list-item
.headline=${headline}
.supportingText=${supportingText}
.multiLineSupportingText=${multiLineSupportingText}
.trailingSupportingText=${trailingSupportingText}
.disabled=${disabled}
.interactive=${interactive}>
<img .src=${image} slot="start-image">
</md-list-item>
<md-list-item
.headline=${headline}
.supportingText=${supportingText}
.multiLineSupportingText=${multiLineSupportingText}
.trailingSupportingText=${trailingSupportingText}
.disabled=${disabled}
.interactive=${interactive}>
<video
muted
autoplay
loop
playsinline
.src=${knobs['video src']}
slot=${
knobs['slot[name=start-video-large]'] ? 'start-video-large' :
'start-video'}
></video>
</md-list-item>
</md-list>
</div>
<md-list>
<md-list-item ?disabled=${knobs.disabled}>
Single line item
${getKnobContent(knobs)}
</md-list-item>
<md-list-item ?disabled=${knobs.disabled}>
Two line item
<div slot="supporting-text">Supporting text</div>
${getKnobContent(knobs)}
</md-list-item>
<md-list-item ?disabled=${knobs.disabled}>
Three line item
<div slot="supporting-text">
<div>Second line text</div>
<div>Third line text</div>
</div>
${getKnobContent(knobs, /* threeLines */ true)}
</md-list-item>
</md-list>
`;
},
};

const interactive: MaterialStoryInit<StoryKnobs> = {
name: 'Interactive list',
styles,
render(knobs) {
const knobsNoTrailing = {...knobs, trailingIcon: false};
return html`
<md-list>
<md-list-item ?disabled=${knobs.disabled}
type="link"
href="https://google.com"
target="_blank"
>
Link item
<md-icon slot="end">link</md-icon>
${getKnobContent(knobsNoTrailing)}
</md-list-item>
<md-list-item type="button" ?disabled=${knobs.disabled}>
Button item
${getKnobContent(knobs)}
</md-list-item>
<md-list-item ?disabled=${knobs.disabled}>
Non-interactive item
${getKnobContent(knobs)}
</md-list-item>
</md-list>
`;
},
};

function getKnobContent(knobs: StoryKnobs, threeLines = false) {
const overline = knobs.overline ?
html`<div slot="overline">${knobs.overline}</div>` :
nothing;

const classes = {
'align-start': threeLines,
};

const trailingText = knobs.trailingSupportingText ?
html`<div class=${classMap(classes)} slot="trailing-supporting-text">${
knobs.trailingSupportingText}</div>` :
nothing;

const leadingIcon = knobs.leadingIcon ?
html`<md-icon class=${classMap(classes)} slot="start">event</md-icon>` :
nothing;

const trailingIcon = knobs.trailingIcon ?
html`<md-icon class=${classMap(classes)} slot="end">star</md-icon>` :
nothing;

return [overline, trailingText, leadingIcon, trailingIcon];
}

/** List stories. */
export const stories = [standard];
export const stories = [standard, interactive];
Loading

0 comments on commit 7536774

Please sign in to comment.