EsgIndicesTable.tsx 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. 'use client';
  2. import DataTable, { DataTableColumn } from '@/components/table/DataTable';
  3. import { EsgIndexRow } from '@/types/market';
  4. import { formatNumber, changeDirection, changeSymbol } from '@/lib/utils/stock';
  5. import { formatDecimal, formatBpRate } from '@/lib/utils/market';
  6. function buildColumns(): DataTableColumn<EsgIndexRow>[] {
  7. return [
  8. {
  9. key: 'name',
  10. header: '지수명',
  11. align: 'left',
  12. priority: 'high',
  13. cellClassName: 'data-table__cell--name',
  14. cell: (row) => <span className='stock-cell__name'>{row.name}</span>
  15. },
  16. {
  17. key: 'close',
  18. header: '지수',
  19. align: 'right',
  20. priority: 'high',
  21. cell: (row) => formatDecimal(row.close)
  22. },
  23. {
  24. key: 'change',
  25. header: '등락률',
  26. align: 'right',
  27. priority: 'high',
  28. cell: (row) => {
  29. const direction = changeDirection(row.flucRateBp);
  30. return (
  31. <span className={`market__index-change market__index-change--${direction}`}>
  32. <span aria-hidden='true'>{changeSymbol(direction)}</span> {formatBpRate(row.flucRateBp)}
  33. </span>
  34. );
  35. }
  36. },
  37. {
  38. key: 'constituents',
  39. header: '구성종목수',
  40. align: 'right',
  41. priority: 'medium',
  42. cell: (row) => formatNumber(row.constituentCount)
  43. },
  44. {
  45. key: 'volume',
  46. header: '거래량',
  47. align: 'right',
  48. priority: 'low',
  49. cell: (row) => formatNumber(row.volume)
  50. }
  51. ];
  52. }
  53. export default function EsgIndicesTable({ rows }: { rows: EsgIndexRow[] })
  54. {
  55. return (
  56. <DataTable<EsgIndexRow>
  57. caption='ESG 지수 목록 — 지수명, 지수, 등락률, 구성종목수, 거래량'
  58. columns={buildColumns()}
  59. rows={rows}
  60. rowKey={(row, index) => `${row.name}-${index}`}
  61. emptyMessage='표시할 ESG 지수가 없습니다.'
  62. />
  63. );
  64. }