EsgSecuritiesTable.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. 'use client';
  2. import DataTable, { DataTableColumn } from '@/components/table/DataTable';
  3. import PriceChange from '@/components/table/PriceChange';
  4. import { EsgSecurityRow } from '@/types/market';
  5. import { formatNumber } from '@/lib/utils/stock';
  6. import { formatDecimal } from '@/lib/utils/market';
  7. function buildColumns(): DataTableColumn<EsgSecurityRow>[] {
  8. return [
  9. {
  10. key: 'name',
  11. header: '종목명',
  12. align: 'left',
  13. priority: 'high',
  14. cellClassName: 'data-table__cell--name',
  15. cell: (row) => <span className='stock-cell__name'>{row.name}</span>
  16. },
  17. {
  18. key: 'close',
  19. header: '현재가',
  20. align: 'right',
  21. priority: 'high',
  22. cell: (row) => formatDecimal(row.close)
  23. },
  24. {
  25. key: 'change',
  26. header: '등락률',
  27. align: 'right',
  28. priority: 'high',
  29. cell: (row) => <PriceChange rate={row.changeRate} />
  30. },
  31. {
  32. key: 'shares',
  33. header: '상장주식수',
  34. align: 'right',
  35. priority: 'low',
  36. cell: (row) => formatNumber(row.listedShares)
  37. },
  38. {
  39. key: 'volume',
  40. header: '거래량',
  41. align: 'right',
  42. priority: 'medium',
  43. cell: (row) => formatNumber(row.volume)
  44. }
  45. ];
  46. }
  47. export default function EsgSecuritiesTable({ rows }: { rows: EsgSecurityRow[] })
  48. {
  49. return (
  50. <DataTable<EsgSecurityRow>
  51. caption='ESG 증권 목록 — 종목명, 현재가, 등락률, 상장주식수, 거래량'
  52. columns={buildColumns()}
  53. rows={rows}
  54. rowKey={(row, index) => `${row.name}-${index}`}
  55. emptyMessage='표시할 ESG 증권이 없습니다.'
  56. />
  57. );
  58. }