button-loading.stories.ts


Overview

button-loading.stories.ts is a Storybook story definition file for the ButtonLoading React component. It serves as a showcase and documentation tool for the ButtonLoading component within a Storybook environment. The file sets up metadata, controls, and example scenarios (stories) that demonstrate how ButtonLoading behaves, especially focusing on its loading state.

This file enables developers and designers to visualize, interact with, and understand the usage of the ButtonLoading component in isolation, improving component discoverability and facilitating UI testing.


Detailed Explanation

Imports


Meta Object (meta)

Defines the metadata and configuration for the ButtonLoading component stories.

const meta = {
  title: 'Example/ButtonLoading',
  component: ButtonLoading,
  parameters: {
    layout: 'centered',
    docs: {
      description: {
        component: `
## Component Description

ButtonLoading is a button component with a loading state and supports displaying loading animation.
        `,
      },
    },
  },
  tags: ['autodocs'],
  argTypes: {
    loading: { control: 'boolean' },
  },
  args: { onClick: fn() },
} satisfies Meta<typeof ButtonLoading>;

Exported Story: WithLoading

export const WithLoading: Story = {
  args: {
    loading: true,
    children: 'Button',
  },
  parameters: {
    docs: {
      description: {
        story: `
### Usage Examples

\`\`\`tsx
import { ButtonLoading } from '@/components/ui/button';

<ButtonLoading loading={true}>
  Loading Button
</ButtonLoading>
\`\`\`
        `,
      },
    },
  },
  tags: ['!dev'],
};

Usage Example

In Storybook UI, users can interact with the WithLoading story to see how the ButtonLoading component looks and behaves when loading. The loading control allows toggling the loading state on and off dynamically.

Example JSX usage extracted from the story docs:

import { ButtonLoading } from '@/components/ui/button';

<ButtonLoading loading={true}>
  Loading Button
</ButtonLoading>

Implementation Details


Interaction with Other System Parts


Mermaid Diagram: Story Structure Flowchart

flowchart TD
    A[button-loading.stories.ts]
    A --> B[Meta Configuration]
    B --> B1[title: 'Example/ButtonLoading']
    B --> B2[component: ButtonLoading]
    B --> B3[parameters]
    B3 --> B3a[layout: 'centered']
    B3 --> B3b[docs.description.component]
    B --> B4[argTypes: loading (boolean)]
    B --> B5[args: onClick fn()]

    A --> C[Story: WithLoading]
    C --> C1[args: loading = true, children = 'Button']
    C --> C2[parameters: docs.description.story (usage example)]
    C --> C3[tags: !dev]

    style A fill:#f9f,stroke:#333,stroke-width:2px
    style B fill:#bbf,stroke:#333
    style C fill:#bfb,stroke:#333

Summary

button-loading.stories.ts is a Storybook story file that documents the ButtonLoading React component. It provides a centered display with interactive controls, action logging for clicks, and clear usage examples to assist developers in understanding and testing the button's loading state. The file uses TypeScript to enforce typing and Storybook best practices for documentation and interactivity.