ComponentsDemoPage.tsx 7.3 KB
import { useState } from 'react';

import {
  Alert,
  Avatar,
  AvatarGroup,
  Badge,
  Button,
  Card,
  Checkbox,
  Collapse,
  ColorInput,
  ColorPicker,
  DatePicker,
  DateRangePicker,
  Drawer,
  Empty,
  Form,
  FormItem,
  Input,
  Message,
  Modal,
  Pagination,
  Popconfirm,
  Progress,
  Radio,
  SearchInput,
  Select,
  Skeleton,
  Steps,
  Switch,
  Table,
  Tabs,
  Tag,
  Timeline,
  Tooltip,
  TreeSelect,
} from '../../../packages/ui/src';
import { Icon } from '../../../packages/ui/src/components/Icon';
import styles from './ComponentsDemoPage.module.css';

export function ComponentsDemoPage() {
  const tableRows = [{ id: '1', name: '项目A', status: '启用' }];
  const [checkboxChecked, setCheckboxChecked] = useState(true);
  const [switchChecked, setSwitchChecked] = useState(true);
  const [treeValue, setTreeValue] = useState<string | undefined>();
  const [dateValue, setDateValue] = useState('2026-05-16');
  const [showMessage, setShowMessage] = useState(false);

  return (
    <section className={styles.page}>
      <div className={styles.heading}>
        <p className={styles.eyebrow}>Component Library</p>
        <h2>组件库 Demo</h2>
        <p>全局 UI 组件库展示入口</p>
      </div>
      <section className={styles.group}>
        <h3>基础交互</h3>
        <div className={styles.grid}>
          <div className={styles.buttonDemo}>
            <Button variant="primary">主按钮</Button>
            <Button>普通按钮</Button>
            <Button variant="outline">描边按钮</Button>
            <Button variant="text">文字按钮</Button>
            <Button variant="danger">危险按钮</Button>
          </div>
          <div className={styles.buttonDemo}>
            <Button size="small">小按钮</Button>
            <Button size="medium">中按钮</Button>
            <Button size="large">大按钮</Button>
            <Button icon={<Icon name="search" size={14} />}>图标按钮</Button>
            <Button disabled>禁用按钮</Button>
            <Button loading>加载中</Button>
          </div>
          <Input aria-label="名称" defaultValue="项目名称" allowClear />
          <SearchInput aria-label="搜索" defaultValue="合同" />
          <Checkbox label="Demo 启用" checked={checkboxChecked} onChange={setCheckboxChecked} />
          <Radio label="按项目" name="demo-radio" checked value="project" />
          <Switch aria-label="Demo 启用审批" checked={switchChecked} onChange={setSwitchChecked} />
        </div>
      </section>
      <section className={styles.group}>
        <h3>选择与日期</h3>
        <div className={styles.grid}>
          <Select aria-label="负责人" options={[{ label: '张三', value: 'zhang' }, { label: '李四', value: 'li' }]} />
          <TreeSelect aria-label="组织" value={treeValue} onChange={setTreeValue} treeData={[{ label: '总部', value: 'root', children: [{ label: '财务部', value: 'finance' }] }]} />
          <DatePicker aria-label="计划日期" value={dateValue} onChange={setDateValue} />
          <DateRangePicker aria-label="周期" />
        </div>
      </section>
      <section className={styles.group}>
        <h3>表格与分页</h3>
        <Table
          rowKey="id"
          columns={[
            { title: '名称', dataIndex: 'name' },
            { title: '状态', dataIndex: 'status', render: (value) => <Tag status="success">{String(value)}</Tag> },
          ]}
          dataSource={tableRows}
        />
        <Table
          rowKey="id"
          columns={[
            { title: '名称', dataIndex: 'name' },
            { title: '状态', dataIndex: 'status' },
          ]}
          dataSource={[]}
          empty={{ description: '暂无审批记录', action: <Button size="small">新建审批</Button> }}
        />
        <Pagination current={1} pageSize={10} total={42} />
      </section>
      <section className={styles.group}>
        <h3>反馈与浮层</h3>
        <div className={styles.grid}>
          <Form className={styles.formDemo} columns={2} initialValues={{ projectName: '', role: '驻店销售岗', remark: '' }}>
            <FormItem
              label="项目名称"
              layout="horizontal"
              name="projectName"
              required
              rules={[{ required: true, message: '请输入项目名称' }]}
            >
              <Input aria-label="项目名称" />
            </FormItem>
            <FormItem label="所属岗位" layout="horizontal" name="role" tips="从 Agent 管理自动带入,不可修改">
              <Input aria-label="所属岗位" disabled />
            </FormItem>
            <FormItem label="备注" layout="horizontal" name="remark" span={2}>
              <Input aria-label="备注" />
            </FormItem>
            <Button type="submit" variant="primary">提交表单</Button>
          </Form>
          {/* <Alert type="info" title="提示">保存后立即生效</Alert> */}
          {/* <Button variant="primary" onClick={() => setShowMessage(true)}>展示消息提示</Button> */}
          {showMessage ? (
            <Message
              items={[
                { key: 'demo-save-success', type: 'success', content: '保存成功', duration: 0, closable: true, onClose: () => setShowMessage(false) },
                { key: 'demo-approval-warning', type: 'warning', content: '请补充审批人', duration: 0 },
                { key: 'demo-delete-error', type: 'error', content: '删除失败', duration: 0 },
              ]}
            />
          ) : null}
          <Tooltip content="补充说明"><Button>帮助</Button></Tooltip>
          <Popconfirm title="确认删除?"><Button variant="danger">删除</Button></Popconfirm>
          <Modal open={false} title="编辑项目">内容</Modal>
          <Drawer open={false} title="详情">内容</Drawer>
        </div>
      </section>
      <section className={styles.group}>
        <h3>数据展示</h3>
        <div className={styles.grid}>
          <Card title="概览" extra={<Button size="small">刷新</Button>}>卡片内容</Card>
          <Badge count={12}><Button>消息</Button></Badge>
          <AvatarGroup maxCount={2}><Avatar name="张三" /><Avatar name="李四" /><Avatar name="王五" /></AvatarGroup>
          <Progress percent={68} percentPosition="top-right" />
          <Timeline items={[{ title: '提交', time: '09:00' }, { title: '审批', time: '10:00', description: '处理中' }]} />
        </div>
      </section>
      <section className={styles.group}>
        <h3>导航与占位</h3>
        <div className={styles.grid}>
          <Tabs activeKey="base" items={[{ key: 'base', label: '基础信息', children: '基础内容' }, { key: 'advanced', label: '高级配置', children: '高级内容' }]} />
          <Steps current={1} items={[{ title: '提交' }, { title: '审批' }, { title: '完成' }]} />
          <Empty description="暂无项目" action={<Button>新建项目</Button>} />
          <Skeleton active />
          <Collapse activeKeys={['one']} items={[{ key: 'one', title: '基础设置', children: '设置内容' }]} />
        </div>
      </section>
      <section className={styles.group}>
        <h3>颜色能力</h3>
        <div className={styles.grid}>
          <ColorPicker value="#2468f2" />
          <ColorInput aria-label="主题色" value="#2468f2" />
        </div>
      </section>
    </section>
  );
}