ragflow-pagination.stories.ts


Overview

This file defines Storybook stories for the RAGFlowPagination React component, which is a UI pagination control designed to facilitate navigation through large datasets by dividing content into pages. The stories provide a sandbox environment for developers and designers to visualize, interact with, and document the component's behavior and appearance.

The file leverages Storybook's modern configuration with:


Detailed Breakdown

1. Imports

import type { Meta, StoryObj } from '@storybook/react-webpack5';
import { fn } from 'storybook/test';
import { RAGFlowPagination } from '@/components/ui/ragflow-pagination';

2. Storybook Metadata (meta)

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

RAGFlowPagination is a pagination component that helps navigate through large datasets by dividing them into pages. It provides intuitive controls for users to move between pages, adjust page size, and view their current position within the dataset.`,
      },
    },
  },
  tags: ['autodocs'],
  argTypes: {
    current: { control: 'number' },
    pageSize: { control: 'number' },
    total: { control: 'number' },
  },
  args: { onChange: fn() },
} satisfies Meta<typeof RAGFlowPagination>;

3. Type Aliases

type Story = StoryObj<typeof meta>;

Defines the Story type to be used for all stories consistent with the defined meta.


4. Story: WithLoading

export const WithLoading: Story = {
  args: {
    current: 1,
    pageSize: 10,
    total: 100,
    showSizeChanger: true,
  },
  parameters: {
    docs: {
      description: {
        story: `
### Usage Examples

\`\`\`tsx
import { RAGFlowPagination } from '@/components/ui/ragflow-pagination';

  <RAGFlowPagination
    {...pick(pagination, 'current', 'pageSize')}
    total={pagination.total}
    onChange={(page, pageSize) => {
      setPagination({ page, pageSize });
    }}>
  </RAGFlowPagination>
\`\`\`
        `,
      },
    },
  },
  tags: ['!dev'],
};

Important Implementation Details


Interaction with Other System Parts

This file does not affect runtime application logic but serves as a development and documentation tool to improve component usability and consistency.


Usage Example Summary

import { RAGFlowPagination } from '@/components/ui/ragflow-pagination';

const [pagination, setPagination] = useState({ current: 1, pageSize: 10, total: 100 });

<RAGFlowPagination
  current={pagination.current}
  pageSize={pagination.pageSize}
  total={pagination.total}
  onChange={(page, pageSize) => setPagination({ current: page, pageSize })}
/>

This pattern lets the parent component fully control pagination state while allowing the user to interact through the RAGFlowPagination UI.


Visual Diagram

flowchart TD
    A[RAGFlowPagination Stories File]
    A --> B[Meta Configuration]
    A --> C[Story: WithLoading]

    B --> D[title: string]
    B --> E[component: RAGFlowPagination]
    B --> F[argTypes: controls for current, pageSize, total]
    B --> G[args: default onChange = fn()]

    C --> H[args: current, pageSize, total, showSizeChanger]
    C --> I[parameters.docs.description.story (usage example)]
    C --> J[tags: !dev]

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

Summary

ragflow-pagination.stories.ts provides a well-structured Storybook configuration for the RAGFlowPagination component. It documents the component's purpose, exposes interactive controls for key props, and offers usage examples to assist developers in integrating pagination controls into their applications. The file enhances component discoverability and usability during UI development without involving actual logic implementation.