import { html, ref, repeat } from '@microsoft/fast-element'; import { type Meta, renderComponent, type StoryArgs, type StoryObj } from '../helpers.stories.js'; import { colorStatusSuccessBackground3 } from '../theme/design-tokens.js'; import { getStorybookHelpers } from '../../.storybook/wc-toolkit-helpers.js'; import type { Field as FluentField } from './field.js'; import { LabelPosition } from './field.options.js'; type Story = StoryObj; const { argTypes } = getStorybookHelpers('fluent-field'); const SuccessIcon = html.partial(/* html */ ` `); export const storyTemplate = html>` ${story => story.labelSlottedContent?.()} ${story => story.inputSlottedContent?.()} ${story => story.messageSlottedContent?.()} `; const textInputLink = 'Text Input'; const textAreaLink = 'Text Area'; const storyDescription = ` The ${textInputLink} and ${textAreaLink} components have a specific implementation with \`\` that differs from other form controls to ensure proper accessibility support. **For Text Input and Text Area:** - The label must be passed as a child element (not using the field's label slot) - This implementation is required for accessibility features like zoom text and voice over to work correctly - A previous issue where the aria-hidden attribute prevented zoom text functionality on the field label has been resolved **For Other Form Controls (checkbox, radio, etc.):** - The label should be placed in the field's label slot using \`slot="label"\` - This is the standard implementation pattern for most form controls This distinction ensures that text-based inputs maintain proper accessibility while other controls follow the standard slotting pattern. `; export default { title: 'Components/Field', render: renderComponent(storyTemplate), excludeStories: ['storyTemplate'], parameters: { docs: { description: { component: storyDescription, }, }, }, args: { label: { text: 'Example field', }, message: { message: 'This is a success message', icon: () => html`${SuccessIcon}`, }, labelSlottedContent: () => html``, inputSlottedContent: () => html``, labelPosition: LabelPosition.above, }, argTypes, } as Meta; export const Default: Story = {}; export const LabelPositions: Story = { render: renderComponent(html>` ${repeat( story => story.storyItems, html`

`, )} `), args: { storyItems: Object.values(LabelPosition).map(labelPosition => ({ labelPosition, label: `Label position: ${labelPosition}`, })), }, }; export const TextInput: Story = { args: { label: { text: 'Text Input', }, labelPosition: undefined, inputSlottedContent: () => html`${story => story.label.text}`, labelSlottedContent: () => html``, messageSlottedContent: undefined, }, }; export const TextInputFormSubmission: Story = { render: renderComponent(html>`
${story => story.label} Submit
`), args: { label: 'Form', }, }; export const Required: Story = { args: { label: { text: 'Required field', }, inputSlottedContent: () => html``, messageSlottedContent: undefined, }, }; export const DisabledControl: Story = { args: { label: { text: 'Disabled field', }, inputSlottedContent: () => html``, messageSlottedContent: undefined, }, }; export const Size: Story = { render: renderComponent(html` `), }; export const Hint: Story = { args: { label: { text: 'Example with hint', }, message: { message: 'Sample hint text.', }, inputSlottedContent: () => html`${story => story.label.text}`, labelSlottedContent: () => html``, messageSlottedContent: () => html`${story => story.message?.message}`, }, }; export const ComponentExamples: Story = { render: renderComponent(html`
`), }; export const ThirdPartyControls: Story = { render: renderComponent(html`
`), };