CommoditiesTable.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. 'use client';
  2. import DataTable, { DataTableColumn } from '@/components/table/DataTable';
  3. import PriceChange from '@/components/table/PriceChange';
  4. import { CommodityRow, COMMODITY_MARKET_LABEL } from '@/types/market';
  5. import { formatNumber } from '@/lib/utils/stock';
  6. import { formatDecimal } from '@/lib/utils/market';
  7. function buildColumns(): DataTableColumn<CommodityRow>[] {
  8. return [
  9. {
  10. key: 'name',
  11. header: '종목명',
  12. align: 'left',
  13. priority: 'high',
  14. cellClassName: 'data-table__cell--name',
  15. cell: (row) => (
  16. <span className='stock-cell'>
  17. <span className='stock-cell__name'>{row.name}</span>
  18. <span className='stock-cell__code'>{row.code}</span>
  19. </span>
  20. )
  21. },
  22. {
  23. key: 'market',
  24. header: '시장',
  25. align: 'center',
  26. priority: 'low',
  27. cell: (row) => <span className='market__cls-badge'>{COMMODITY_MARKET_LABEL[row.market] ?? row.market}</span>
  28. },
  29. {
  30. key: 'close',
  31. header: '현재가',
  32. align: 'right',
  33. priority: 'high',
  34. cell: (row) => formatDecimal(row.close)
  35. },
  36. {
  37. key: 'change',
  38. header: '등락률',
  39. align: 'right',
  40. priority: 'high',
  41. cell: (row) => <PriceChange rate={row.changeRate} />
  42. },
  43. {
  44. key: 'weighted',
  45. header: '가중평균가',
  46. align: 'right',
  47. priority: 'low',
  48. cell: (row) => formatDecimal(row.weightedDiscussionPrice)
  49. },
  50. {
  51. key: 'volume',
  52. header: '거래량',
  53. align: 'right',
  54. priority: 'medium',
  55. cell: (row) => formatNumber(row.volume)
  56. }
  57. ];
  58. }
  59. export default function CommoditiesTable({ rows }: { rows: CommodityRow[] })
  60. {
  61. return (
  62. <DataTable<CommodityRow>
  63. caption='상품 목록 — 종목명, 시장, 현재가, 등락률, 가중평균가, 거래량'
  64. columns={buildColumns()}
  65. rows={rows}
  66. rowKey={(row) => row.code}
  67. emptyMessage='표시할 상품이 없습니다.'
  68. />
  69. );
  70. }