FuturesTable.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. 'use client';
  2. import DataTable, { DataTableColumn } from '@/components/table/DataTable';
  3. import { FuturesRow } from '@/types/market';
  4. import { formatNumber } from '@/lib/utils/stock';
  5. import { formatDecimal } from '@/lib/utils/market';
  6. function buildColumns(): DataTableColumn<FuturesRow>[] {
  7. return [
  8. {
  9. key: 'name',
  10. header: '종목명',
  11. align: 'left',
  12. priority: 'high',
  13. cellClassName: 'data-table__cell--name',
  14. cell: (row) => (
  15. <span className='stock-cell'>
  16. <span className='stock-cell__name'>{row.isuName}</span>
  17. <span className='stock-cell__code'>{row.isuCode}</span>
  18. </span>
  19. )
  20. },
  21. {
  22. key: 'close',
  23. header: '현재가',
  24. align: 'right',
  25. priority: 'high',
  26. cell: (row) => formatDecimal(row.close)
  27. },
  28. {
  29. key: 'changeAmount',
  30. header: '대비',
  31. align: 'right',
  32. priority: 'high',
  33. cell: (row) => formatDecimal(row.changeAmount)
  34. },
  35. {
  36. key: 'settle',
  37. header: '정산가',
  38. align: 'right',
  39. priority: 'low',
  40. cell: (row) => formatDecimal(row.settlePrice)
  41. },
  42. {
  43. key: 'volume',
  44. header: '거래량',
  45. align: 'right',
  46. priority: 'medium',
  47. cell: (row) => formatNumber(row.volume)
  48. },
  49. {
  50. key: 'oi',
  51. header: '미결제약정',
  52. align: 'right',
  53. priority: 'low',
  54. cell: (row) => formatNumber(row.openInterest)
  55. },
  56. {
  57. key: 'product',
  58. header: '상품',
  59. align: 'left',
  60. priority: 'low',
  61. cell: (row) => row.productName || '—'
  62. }
  63. ];
  64. }
  65. export default function FuturesTable({ rows }: { rows: FuturesRow[] })
  66. {
  67. return (
  68. <DataTable<FuturesRow>
  69. caption='선물 목록 — 종목명, 현재가, 대비, 정산가, 거래량, 미결제약정, 상품'
  70. columns={buildColumns()}
  71. rows={rows}
  72. rowKey={(row) => row.isuCode}
  73. emptyMessage='표시할 선물이 없습니다.'
  74. />
  75. );
  76. }