{"version":3,"file":"Table.cjs","sources":["../../../src/components/Table/Table.tsx"],"sourcesContent":["'use client'\n\nimport { type ComponentProps, type FC, type PropsWithChildren, useMemo, useRef } from 'react'\nimport { type VariantProps, tv } from 'tailwind-variants'\n\nimport { TableReel } from './TableReel'\nimport { TableScrollContext } from './TableScrollContext'\n\ntype AbstractProps = PropsWithChildren<\n  VariantProps<typeof classNameGenerator> & {\n    reel?: boolean\n  }\n>\ntype Props = AbstractProps & Omit<ComponentProps<'table'>, keyof AbstractProps>\n\nconst ROUNDED = {\n  t_l: '[&>thead:first-child>tr:first-child>th:first-child]:shr-rounded-tl-l [&>thead:first-child>tr:first-child>td:first-child]:shr-rounded-tl-l',\n  t_r: '[&>thead:first-child>tr:first-child>th:last-child]:shr-rounded-tr-l [&>thead:first-child>tr:first-child>td:last-child]:shr-rounded-tr-l',\n  b_l: '[&>tbody:last-child>tr:last-child>th:first-child]:shr-rounded-bl-l [&>tbody:last-child>tr:last-child>td:first-child]:shr-rounded-bl-l',\n  b_r: '[&>tbody:last-child>tr:last-child>th:last-child]:shr-rounded-br-l [&>tbody:last-child>tr:last-child>td:last-child]:shr-rounded-br-l',\n}\nconst ROUNDED_ALL = [ROUNDED.t_l, ROUNDED.t_r, ROUNDED.b_l, ROUNDED.b_r]\n\nconst classNameGenerator = tv({\n  slots: {\n    reelWrapper: ['smarthr-ui-TableReel', 'shr-relative'],\n    inner: ['smarthr-ui-TableReel-inner', 'shr-relative'],\n    table: [\n      'smarthr-ui-Table',\n      'shr-w-full shr-border-collapse',\n      '[&_tbody]:shr-bg-white',\n      '[&_th]:contrast-more:shr-border-shorthand [&_th]:shr-bg-head [&_th]:contrast-more:shr-border-high-contrast',\n      '[&_td]:contrast-more:shr-border-shorthand [&_td]:contrast-more:shr-border-high-contrast',\n      'contrast-more:shr-border-shorthand contrast-more:shr-border-high-contrast',\n    ],\n  },\n  variants: {\n    borderType: {\n      vertical: {},\n      horizontal: {},\n      both: {},\n      outer: {\n        table: 'shr-border-shorthand',\n      },\n      all: {\n        table: 'shr-border-shorthand',\n      },\n    },\n    borderStyle: {\n      solid: {\n        table: '[&_:is(.smarthr-ui-Th,.smarthr-ui-Td)]:shr-border-solid',\n      },\n      dotted: {\n        table: '[&_:is(.smarthr-ui-Th,.smarthr-ui-Td)]:shr-border-dotted',\n      },\n      dashed: {\n        table: '[&_:is(.smarthr-ui-Th,.smarthr-ui-Td)]:shr-border-dashed',\n      },\n    },\n    rounded: {\n      true: {\n        table: ROUNDED_ALL,\n      },\n      all: {\n        table: ROUNDED_ALL,\n      },\n      top: {\n        table: [ROUNDED.t_l, ROUNDED.t_r],\n      },\n      right: {\n        table: [ROUNDED.t_r, ROUNDED.b_r],\n      },\n      bottom: {\n        table: [ROUNDED.b_l, ROUNDED.b_r],\n      },\n      left: {\n        table: [ROUNDED.t_l, ROUNDED.b_l],\n      },\n    },\n    layout: {\n      auto: {},\n      fixed: {\n        table: 'shr-table-fixed',\n      },\n    },\n    fixedHead: {\n      true: {\n        table:\n          '[&_tbody]:shr-relative [&_tbody]:shr-z-1 [&_thead]:shr-sticky [&_thead]:shr-start-0 [&_thead]:shr-top-0 [&_thead]:shr-z-[2]',\n      },\n    },\n  },\n  compoundVariants: [\n    {\n      borderType: ['vertical', 'both', 'all'],\n      className: {\n        table: [\n          '[&_:is(.smarthr-ui-Th:not(:first-child),.smarthr-ui-Td:not(:first-child))]:shr-border-l',\n          '[&_:is(.smarthr-ui-Th:not(:first-child),.smarthr-ui-Td:not(:first-child))]:shr-border-l-default',\n        ],\n      },\n    },\n    {\n      borderType: ['horizontal', 'both', 'all'],\n      className: {\n        table: [\n          // thead がある場合は、thead 配下以外の th と td に border-t を適用\n          [\n            '[&:has(thead)_tr:not(:where(thead_tr))_:is(.smarthr-ui-Th,.smarthr-ui-Td)]:shr-border-t',\n            '[&:has(thead)_tr:not(:where(thead_tr))_:is(.smarthr-ui-Th,.smarthr-ui-Td)]:shr-border-t-default',\n          ],\n          // thead がない場合は、最初以外の tr 配下の th と td に border-t を適用\n          [\n            '[&:not(:has(thead))_tr:not(:first-of-type)_:is(.smarthr-ui-Th,.smarthr-ui-Td)]:shr-border-t',\n            '[&:not(:has(thead))_tr:not(:first-of-type)_:is(.smarthr-ui-Th,.smarthr-ui-Td)]:shr-border-t-default',\n          ],\n        ],\n      },\n    },\n  ],\n  defaultVariants: {\n    borderType: 'horizontal',\n    borderStyle: 'solid',\n    layout: 'auto',\n    fixedHead: false,\n  },\n})\n\nexport const Table: FC<Props> = ({\n  borderType,\n  borderStyle,\n  fixedHead,\n  layout,\n  rounded,\n  className,\n  reel = true,\n  ...rest\n}) => {\n  const tableWrapperRef = useRef<HTMLDivElement>(null)\n  const classNames = useMemo(() => {\n    const { table } = classNameGenerator({\n      borderType,\n      borderStyle,\n      fixedHead,\n      layout,\n      rounded,\n      className,\n    })\n    return { table: table({ className }) }\n  }, [borderType, borderStyle, className, fixedHead, layout, rounded])\n\n  const renderedTable = <table {...rest} className={classNames.table} />\n\n  return (\n    <TableScrollContext ref={tableWrapperRef} fixedHead={fixedHead}>\n      {reel ? (\n        <TableReel tableWrapperRef={tableWrapperRef}>{renderedTable}</TableReel>\n      ) : (\n        renderedTable\n      )}\n    </TableScrollContext>\n  )\n}\n"],"names":[],"mappings":";;;;;;;;;AAeA;AACE;AACA;AACA;AACA;;AAEF;AAEA;AACE;AACE;AACA;AACA;;;;;;;AAOC;AACF;AACD;AACE;AACE;AACA;AACA;AACA;AACE;AACD;AACD;AACE;AACD;AACF;AACD;AACE;AACE;AACD;AACD;AACE;AACD;AACD;AACE;AACD;AACF;AACD;AACE;AACE;AACD;AACD;AACE;AACD;AACD;;AAEC;AACD;;AAEC;AACD;;AAEC;AACD;;AAEC;AACF;AACD;AACE;AACA;AACE;AACD;AACF;AACD;AACE;AACE;AAED;AACF;AACF;AACD;AACE;AACE;AACA;AACE;;;AAGC;AACF;AACF;AACD;AACE;AACA;AACE;;AAEE;;;AAGC;;AAED;;;AAGC;AACF;AACF;AACF;AACF;AACD;AACE;AACA;AACA;AACA;AACD;AACF;AAEM;AAUL;AACA;AACE;;;;;;;AAOC;;AAEH;;AAIA;AASF;;"}