spin.stories.ts


Overview

The spin.stories.ts file is a Storybook story definition for the Spin React component. Storybook is a tool for developing UI components in isolation and documenting them interactively. This file provides metadata, configuration, and example usage scenarios ("stories") for the Spin component, which is a loading spinner used to indicate loading states in the UI.

This file's primary purpose is to:


Detailed Explanation

Imports

import type { Meta, StoryObj } from '@storybook/react-webpack5';
import { Spin } from '@/components/ui/spin';

meta Object

The meta object defines the Storybook metadata for the Spin component:

const meta = {
  title: 'Example/Spin',
  component: Spin,
  parameters: {
    layout: 'centered',
    docs: {
      description: {
        component: ` ... detailed markdown description ... `,
      },
    },
  },
  tags: ['autodocs'],
  argTypes: { ... },
  args: {},
} satisfies Meta<typeof Spin>;

Properties

argTypes Details

Prop

Description

Control Type

Options

spinning

Whether the spinner is active

Boolean toggle

true/false

size

Size of the spinner

Select dropdown

'small', 'default', 'large'

className

Additional CSS classes

Text input

Free text

children

Wrapped content inside spinner

No control (disabled)

N/A


Exported Default

export default meta;

Story Type Alias

type Story = StoryObj<typeof meta>;

Exported Default Story

export const Default: Story = {
  args: {
    spinning: true,
    size: 'default',
  },
  parameters: {
    docs: {
      description: {
        story: `
### Default Spinner

Shows the basic spinner with default size and active state.

\`\`\`tsx
<Spin spinning={true} size="default" />
\`\`\`
        `,
      },
    },
  },
  tags: ['!dev'],
};

Usage Examples from Documentation

import { Spin } from '@/components/ui/spin';

function MyComponent() {
  return (
    <Spin spinning={true}>
      <div>Your content here</div>
    </Spin>
  );
}

This example shows how Spin can wrap content to display a loading overlay.


Implementation Details


Interaction with Other Parts of the System


Mermaid Diagram

The following diagram shows the structure of this Storybook configuration file, highlighting the meta object and the Default story.

classDiagram
    class Meta {
        +title: string
        +component: React.ComponentType
        +parameters: object
        +tags: string[]
        +argTypes: object
        +args: object
    }

    class Story {
        +args: object
        +parameters: object
        +tags: string[]
    }

    spin_stories_ts --> Meta : defines
    spin_stories_ts --> Story : exports

    Meta "1" --> "1" Spin : component
    Story "1" --> "1" Meta : based on

Summary