import { html } from '@microsoft/fast-element'; import { type Meta, renderComponent, type StoryArgs, type StoryObj } from '../helpers.stories.js'; import { colorNeutralBackground6 } from '../theme/design-tokens.js'; import { getStorybookHelpers } from '../../.storybook/wc-toolkit-helpers.js'; import type { Text as FluentText } from './text.js'; import { TextAlign, TextFont, TextSize, TextWeight } from './text.options.js'; type Story = StoryObj; const { argTypes } = getStorybookHelpers('fluent-text'); /** * Used to generate slotted content for stories * @param as - the element to generate * @param content - the content for the element * @returns ViewTemplate */ const generateSemanticElementTemplate = (as: string, content: string) => { switch (as) { case 'h1': return html`

${content}

`; case 'h2': return html`

${content}

`; case 'h3': return html`

${content}

`; case 'h4': return html`

${content}

`; case 'h5': return html`
${content}
`; case 'h6': return html`
${content}
`; case 'p': return html`

${content}

`; case 'pre': return html`
${content}
`; case 'span': default: return html`${content}`; } }; const storyTemplate = html>` story.align} font=${story => story.font} size=${story => story.size} weight=${story => story.weight} ?nowrap=${story => story.nowrap} ?truncate=${story => story.truncate} ?italic=${story => story.italic} ?underline=${story => story.underline} ?strikethrough=${story => story.strikethrough} ?block=${story => story.block} >${story => story.slottedContent?.()} `; export default { title: 'Components/Text', render: renderComponent(storyTemplate), args: { slottedContent: () => html`${story => generateSemanticElementTemplate(story.as, 'text')}`, }, argTypes: { ...argTypes, as: { name: 'Text wrapping element', description: 'The semantic element to use for the slotted content.', control: 'select', options: ['span', 'p', 'pre', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6'], table: { category: 'demo', }, }, }, } as Meta; export const Text: Story = {}; // // Attribute stories // export const Nowrap: Story = { render: renderComponent(html>`
This text will not wrap lines when it overflows the container.
`), }; export const Truncate: Story = { render: renderComponent(html>`
Setting truncate and nowrap will truncate when it overflows the container.
`), }; export const Italic: Story = { render: renderComponent(html>` Italics are emphasized text. `), }; export const Underline: Story = { render: renderComponent(html>` Underlined text draws the reader's attention to the words. `), }; export const Strikethrough: Story = { render: renderComponent(html>` Strikethrough text is used to indicate something that is no longer relevant. `), }; export const Block: Story = { render: renderComponent(html>` Fluent text is inline by default. Setting block will make it behave as a block element. `), }; export const Size: Story = { render: renderComponent(html>`
100 200 300 400 500 600 700 800 900 1000
`), }; export const Weight: Story = { render: renderComponent(html>`
This text is regular. This text is medium. This text is semibold. This text is bold.
`), }; export const Align: Story = { render: renderComponent(html>`
Start aligned block. End aligned block. Center aligned block. Justify aligned block text stretches wrapped lines to meet container edges.
`), }; export const Font: Story = { render: renderComponent(html>`
Font base. Font numeric 0123456789. Font monospace.
`), };