/** * @license * Copyright 2023 Google LLC * SPDX-License-Identifier: Apache-2.0 */ import '@material/web/icon/icon.js'; import '@material/web/labs/item/item.js'; import {MaterialStoryInit} from './material-collection.js'; import {css, html, nothing} from 'lit'; import {classMap} from 'lit/directives/class-map.js'; /** Knob types for item stories. */ export interface StoryKnobs { overline: string; trailingSupportingText: string; leadingIcon: boolean; trailingIcon: boolean; } const styles = css` /* Use this CSS to prevent lines from wrapping */ .nowrap { white-space: nowrap; } /* Use this CSS on items to limit the number of wrapping lines */ .clamp-lines { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; } /* Use this on start/end content when the item requires it, typically 3+ line height items) */ .align-start { align-self: flex-start; /* Optional, some items line icons and text should visually appear 16px from the top. Others, like interactive controls, should hug the top at 12px */ padding-top: 4px; } .container { align-items: flex-start; display: flex; gap: 32px; flex-wrap: wrap; } md-item { border-radius: 16px; outline: 1px solid var(--md-sys-color-outline); width: 300px; } `; const LOREM_IPSUM = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus condimentum rhoncus est volutpat venenatis.'; const items: MaterialStoryInit = { name: 'Items', styles, render(knobs) { return html`
Single line item ${getKnobContent(knobs)} Two line item
Supporting text
${getKnobContent(knobs)}
Three line item
Second line text
Third line text
${getKnobContent(knobs, /* threeLines */ true)}
`; }, }; const longText: MaterialStoryInit = { name: 'Items with long text', styles, render(knobs) { return html`
Item with a truncated headline and supporting text.
Supporting text. ${LOREM_IPSUM}
${getKnobContent(knobs)}
Item with clamped lines
Supporting text that wraps up to two lines. ${LOREM_IPSUM}
${getKnobContent(knobs, /* threeLines */ true)}
Item that always shows long wrapping text.
Supporting text. ${LOREM_IPSUM}
${getKnobContent(knobs, /* threeLines */ true)}
`; }, }; function getKnobContent(knobs: StoryKnobs, threeLines = false) { const overline = knobs.overline ? html`
${knobs.overline}
` : nothing; const classes = { 'align-start': threeLines, }; const trailingText = knobs.trailingSupportingText ? html`
${knobs.trailingSupportingText}
` : nothing; const leadingIcon = knobs.leadingIcon ? html`event` : nothing; const trailingIcon = knobs.trailingIcon ? html`star` : nothing; return [overline, trailingText, leadingIcon, trailingIcon]; } /** Item stories. */ export const stories = [items, longText];