|
1 | | -import { DataTable, Form, FormItem, Input } from '../../src' |
| 1 | +import { Button, Checkbox, Input, Label } from '../../src' |
| 2 | +import { useState } from 'react' |
2 | 3 |
|
3 | | -export type Payment = { |
4 | | - id: string |
5 | | - amount: number |
6 | | - status: 'pending' | 'processing' | 'success' | 'failed' |
7 | | - email: string |
8 | | -} |
9 | | - |
10 | | -const data: Payment[] = [ |
11 | | - { |
12 | | - id: 'm5gr84i9', |
13 | | - amount: 316, |
14 | | - status: 'success', |
15 | | - email: 'ken99@example.com', |
16 | | - }, |
17 | | - { |
18 | | - id: '3u1reuv4', |
19 | | - amount: 242, |
20 | | - status: 'success', |
21 | | - email: 'Abe45@example.com', |
22 | | - }, |
23 | | - { |
24 | | - id: 'derv1ws0', |
25 | | - amount: 837, |
26 | | - status: 'processing', |
27 | | - email: 'Monserrat44@example.com', |
28 | | - }, |
29 | | - { |
30 | | - id: '5kma53ae', |
31 | | - amount: 874, |
32 | | - status: 'success', |
33 | | - email: 'Silas22@example.com', |
34 | | - }, |
35 | | - { |
36 | | - id: 'bhqecj4p', |
37 | | - amount: 721, |
38 | | - status: 'failed', |
39 | | - email: 'carmella@example.com', |
40 | | - }, |
41 | | -] |
42 | | - |
43 | | -export const columns: DataTable.ColumnDef<Payment>[] = [ |
44 | | - { |
45 | | - accessorKey: 'id', |
46 | | - header: 'ID', |
47 | | - cell: ({ row }) => row.getValue('id'), |
48 | | - }, |
49 | | - { |
50 | | - accessorKey: 'status', |
51 | | - header: 'Status', |
52 | | - cell: ({ row }) => ( |
53 | | - <div className="capitalize">{row.getValue('status')}</div> |
54 | | - ), |
55 | | - }, |
56 | | - { |
57 | | - accessorKey: 'email', |
58 | | - header: 'email', |
59 | | - cell: ({ row }) => <div className="lowercase">{row.getValue('email')}</div>, |
60 | | - }, |
61 | | - { |
62 | | - accessorKey: 'amount', |
63 | | - header: () => <div className="text-right">Amount</div>, |
64 | | - cell: ({ row }) => { |
65 | | - const amount = parseFloat(row.getValue('amount')) |
66 | | - // Format the amount as a dollar amount |
67 | | - const formatted = new Intl.NumberFormat('en-US', { |
68 | | - style: 'currency', |
69 | | - currency: 'USD', |
70 | | - }).format(amount) |
71 | | - return <div className="text-right font-medium">{formatted}</div> |
72 | | - }, |
73 | | - }, |
74 | | -] |
75 | | - |
76 | | -export function App() { |
77 | | - const table = DataTable.useReactTable({ |
78 | | - data, |
79 | | - columns, |
80 | | - getCoreRowModel: DataTable.getCoreRowModel(), |
81 | | - getFilteredRowModel: DataTable.getFilteredRowModel(), |
82 | | - }) |
83 | | - |
84 | | - const handleSubmit = (v: { email?: string }) => { |
85 | | - console.log(v?.email) |
86 | | - table.getColumn('email')?.setFilterValue(v.email) |
87 | | - } |
| 4 | +function App() { |
| 5 | + const [error, setError] = useState(false) |
| 6 | + const [disabled, setDisabled] = useState(false) |
88 | 7 |
|
89 | 8 | return ( |
90 | | - <div> |
91 | | - <div> |
92 | | - <Form onSubmit={handleSubmit}> |
93 | | - <FormItem name="email" label="Email" render={<Input />} /> |
94 | | - </Form> |
| 9 | + <> |
| 10 | + <div style={{ display: 'flex', alignItems: 'center', gap: 10 }}> |
| 11 | + <Checkbox aria-invalid={error} disabled={disabled} id="food" /> |
| 12 | + <Label htmlFor="food">香蕉</Label> |
| 13 | + <Input placeholder="nihao" /> |
95 | 14 | </div> |
96 | | - <div> |
97 | | - <DataTable.Table table={table} /> |
| 15 | + <div style={{ marginTop: 20, display: 'flex', gap: 20 }}> |
| 16 | + <Button variant="destructive" onClick={() => setError(!error)}> |
| 17 | + Toggle Error |
| 18 | + </Button> |
| 19 | + <Button onClick={() => setDisabled(!disabled)}>Toggle disabled</Button> |
98 | 20 | </div> |
99 | | - </div> |
| 21 | + </> |
100 | 22 | ) |
101 | 23 | } |
| 24 | + |
| 25 | +export default App |
0 commit comments