|
| 1 | +import { Switch } from '~components/Dashboard/Switch' |
| 2 | +import { Icon } from '@iconify/react' |
| 3 | +import { button } from '~components/Dashboard/Button' |
| 4 | +import { Table } from '~components/Dashboard/Table' |
| 5 | + |
| 6 | +type Ads = { |
| 7 | + adName: string |
| 8 | + budget: 'Free' | 'Premium' |
| 9 | + schedule: 'Ongoing' | 'End' |
| 10 | + publish: boolean |
| 11 | +} |
| 12 | + |
| 13 | +export default function ListAds() { |
| 14 | + const mockData: Ads[] = [ |
| 15 | + { |
| 16 | + adName: 'Ad name', |
| 17 | + budget: 'Free', |
| 18 | + schedule: 'Ongoing', |
| 19 | + publish: true, |
| 20 | + }, |
| 21 | + { |
| 22 | + adName: 'Ad name', |
| 23 | + budget: 'Free', |
| 24 | + schedule: 'End', |
| 25 | + publish: true, |
| 26 | + }, |
| 27 | + { |
| 28 | + adName: 'Ad name', |
| 29 | + budget: 'Premium', |
| 30 | + schedule: 'Ongoing', |
| 31 | + publish: false, |
| 32 | + }, |
| 33 | + ] |
| 34 | + |
| 35 | + return ( |
| 36 | + <> |
| 37 | + <div className="overflow-auto"> |
| 38 | + <Table |
| 39 | + data={mockData} |
| 40 | + columns={[ |
| 41 | + { |
| 42 | + Header: 'Name', |
| 43 | + accessor: 'adName', |
| 44 | + width: 300, |
| 45 | + tdClassName: 'font-bold pl-4', // add padding left for first col |
| 46 | + Cell: ({ cell: { value } }: any) => { |
| 47 | + return <div>{value}</div> |
| 48 | + }, |
| 49 | + }, |
| 50 | + { |
| 51 | + Header: 'Budget', |
| 52 | + accessor: 'budget', |
| 53 | + Cell: ({ cell: { value }, row: { original } }: any) => { |
| 54 | + return ( |
| 55 | + <span |
| 56 | + className={!original.publish ? 'text-dashboard-gray-8' : ''} |
| 57 | + > |
| 58 | + {value} |
| 59 | + </span> |
| 60 | + ) |
| 61 | + }, |
| 62 | + }, |
| 63 | + { |
| 64 | + Header: 'Schedule', |
| 65 | + accessor: 'schedule', |
| 66 | + defaultCanSort: true, |
| 67 | + Cell: ({ cell: { value }, row: { original } }: any) => { |
| 68 | + return ( |
| 69 | + <span |
| 70 | + className={!original.publish ? 'text-dashboard-gray-8' : ''} |
| 71 | + > |
| 72 | + {value} |
| 73 | + </span> |
| 74 | + ) |
| 75 | + }, |
| 76 | + }, |
| 77 | + { |
| 78 | + Header: 'Publish', |
| 79 | + accessor: 'publish', |
| 80 | + thClassName: 'text-right', |
| 81 | + tdClassName: 'justify-end gap-2 pr-4', // add padding right for last col |
| 82 | + Cell: ({ cell: { value } }: any) => ( |
| 83 | + <> |
| 84 | + <div className="flex gap-2 opacity-0 pointer-events-none group-hover:opacity-100 group-hover:pointer-events-auto transition"> |
| 85 | + <button |
| 86 | + type="button" |
| 87 | + className={button({ |
| 88 | + appearance: 'tertiary', |
| 89 | + size: 'icon', |
| 90 | + })} |
| 91 | + > |
| 92 | + <Icon className="w-4 h-4" icon="mingcute:pencil-fill" /> |
| 93 | + </button> |
| 94 | + <button |
| 95 | + type="button" |
| 96 | + className={button({ |
| 97 | + appearance: 'tertiary', |
| 98 | + size: 'icon', |
| 99 | + })} |
| 100 | + > |
| 101 | + <Icon className="w-4 h-4" icon="mingcute:delete-fill" /> |
| 102 | + </button> |
| 103 | + </div> |
| 104 | + <Switch checked={value} /> |
| 105 | + </> |
| 106 | + ), |
| 107 | + }, |
| 108 | + ]} |
| 109 | + tableClassName="!overflow-visible" |
| 110 | + theadClassName="mb-2 text-xs font-bold uppercase thead text-dashboard-gray-2" |
| 111 | + tdClassName="flex items-center" |
| 112 | + trBodyClassName="py-4 bg-[#FFFFFF] rounded-lg border border-[#FFFFFF] hover:shadow hover:border-dashboard-gray-1 text-sm mb-2 transition group" |
| 113 | + /> |
| 114 | + </div> |
| 115 | + </> |
| 116 | + ) |
| 117 | +} |
0 commit comments