{"version":3,"file":"Table.cjs","sources":["../../../src/components/Table/Table.tsx"],"sourcesContent":["import {\n  Box,\n  BoxProps,\n  createVarsResolver,\n  ElementProps,\n  factory,\n  Factory,\n  getSpacing,\n  getThemeColor,\n  RaikouColor,\n  RaikouSpacing,\n  rem,\n  StylesApiProps,\n  useProps,\n  useStyles,\n} from '../../core';\nimport {\n  TableCaption,\n  TableTbody,\n  TableTd,\n  TableTfoot,\n  TableTh,\n  TableThead,\n  TableTr,\n} from './Table.components';\nimport { TableProvider } from './Table.context';\nimport { TableDataRenderer } from './TableDataRenderer';\nimport { TableScrollContainer } from './TableScrollContainer';\nimport {\n  TableCaptionStyle,\n  TableRootStyle,\n  TableTbodyStyle,\n  TableTdStyle,\n  TableTheadStyle,\n  TableThStyle,\n  TableTrStyle,\n} from './Table.css';\n\nexport type TableVariant = 'default' | 'vertical';\n\nexport type TableStylesNames =\n  | 'table'\n  | 'thead'\n  | 'tbody'\n  | 'tfoot'\n  | 'tr'\n  | 'th'\n  | 'td'\n  | 'caption';\n\nexport type TableCssVariables = {\n  table:\n    | '--table-layout'\n    | '--table-border-color'\n    | '--table-caption-side'\n    | '--table-horizontal-spacing'\n    | '--table-vertical-spacing'\n    | '--table-striped-color'\n    | '--table-highlight-on-hover-color'\n    | '--table-sticky-header-offset';\n};\n\nexport interface TableData {\n  head?: React.ReactNode[];\n  body?: React.ReactNode[][];\n  foot?: React.ReactNode[];\n  caption?: string;\n}\n\nexport interface TableProps extends BoxProps, StylesApiProps<TableFactory>, ElementProps<'table'> {\n  /** Value of `table-layout` style, `auto` by default */\n  layout?: React.CSSProperties['tableLayout'];\n\n  /** Determines on which side `Table.Caption` is displayed, `bottom` by default */\n  captionSide?: 'top' | 'bottom';\n\n  /** Color of table borders, key of `theme.colors` or any valid CSS color */\n  borderColor?: RaikouColor;\n\n  /** Determines whether the table should have outer border, `false` by default */\n  withTableBorder?: boolean;\n\n  /** Determines whether the table should have borders between columns, `false` by default */\n  withColumnBorders?: boolean;\n\n  /** Determines whether the table should have borders between rows, `true` by default */\n  withRowBorders?: boolean;\n\n  /** Horizontal cells spacing, key of `theme.spacing` or any valid CSS value for padding, numbers are converted to rem, default value is `xs` */\n  horizontalSpacing?: RaikouSpacing;\n\n  /** Vertical cells spacing, key of `theme.spacing` or any valid CSS value for padding, numbers are converted to rem, default value is `xs` */\n  verticalSpacing?: RaikouSpacing;\n\n  /** Determines whether every odd/even row background should be changed to `strippedColor`, if set to `true`, then `odd` value will be used, `false` by default  */\n  striped?: boolean | 'odd' | 'even';\n\n  /** Background color of striped rows, key of `theme.colors` or any valid CSS color */\n  stripedColor?: RaikouColor;\n\n  /** Determines whether table rows background should change to `highlightOnHoverColor` when hovered, `false` by default */\n  highlightOnHover?: boolean;\n\n  /** Background color of table rows when hovered, key of `theme.colors` or any valid CSS color */\n  highlightOnHoverColor?: RaikouColor;\n\n  /** Data that should be used to generate table, ignored if `children` prop is set */\n  data?: TableData;\n\n  /** Determines whether `Table.Thead` should be sticky, `false` by default */\n  stickyHeader?: boolean;\n\n  /** Offset from top at which `Table.Thead` should become sticky, `0` by default */\n  stickyHeaderOffset?: number | string;\n\n  /** Determines whether `font-variant-numeric: tabular-nums` style should be set, `false` by default */\n  tabularNums?: boolean;\n}\n\nexport type TableFactory = Factory<{\n  props: TableProps;\n  ref: HTMLTableElement;\n  stylesNames: TableStylesNames;\n  vars: TableCssVariables;\n  staticComponents: {\n    Thead: typeof TableThead;\n    Tbody: typeof TableTbody;\n    Tfoot: typeof TableTfoot;\n    Td: typeof TableTd;\n    Th: typeof TableTh;\n    Tr: typeof TableTr;\n    Caption: typeof TableCaption;\n    ScrollContainer: typeof TableScrollContainer;\n    DataRenderer: typeof TableDataRenderer;\n  };\n}>;\n\nconst defaultProps: Partial<TableProps> = {\n  withRowBorders: true,\n  verticalSpacing: 7,\n};\n\nconst varsResolver = createVarsResolver<TableFactory>(\n  (\n    theme,\n    {\n      layout,\n      captionSide,\n      horizontalSpacing,\n      verticalSpacing,\n      borderColor,\n      stripedColor,\n      highlightOnHoverColor,\n      striped,\n      highlightOnHover,\n      stickyHeaderOffset,\n      stickyHeader,\n    }\n  ) => ({\n    table: {\n      '--table-layout': layout,\n      '--table-caption-side': captionSide,\n      '--table-horizontal-spacing': getSpacing(horizontalSpacing),\n      '--table-vertical-spacing': getSpacing(verticalSpacing),\n      '--table-border-color': borderColor ? getThemeColor(borderColor, theme) : undefined,\n      '--table-striped-color':\n        striped && stripedColor ? getThemeColor(stripedColor, theme) : undefined,\n      '--table-highlight-on-hover-color':\n        highlightOnHover && highlightOnHoverColor\n          ? getThemeColor(highlightOnHoverColor, theme)\n          : undefined,\n      '--table-sticky-header-offset': stickyHeader ? rem(stickyHeaderOffset) : undefined,\n    },\n  })\n);\n\nexport const Table = factory<TableFactory>((_props, ref) => {\n  const props = useProps('Table', defaultProps, _props);\n  const {\n    classNames,\n    className,\n    style,\n    styles,\n    unstyled,\n    vars,\n    horizontalSpacing,\n    verticalSpacing,\n    captionSide,\n    stripedColor,\n    highlightOnHoverColor,\n    striped,\n    highlightOnHover,\n    withColumnBorders,\n    withRowBorders,\n    withTableBorder,\n    borderColor,\n    layout,\n    variant,\n    data,\n    children,\n    stickyHeader,\n    stickyHeaderOffset,\n    mod,\n    tabularNums,\n    ...others\n  } = props;\n\n  const getStyles = useStyles<TableFactory>({\n    name: 'Table',\n    props,\n    className,\n    style,\n    classes: {\n      table: TableRootStyle,\n      thead: TableTheadStyle,\n      tbody: TableTbodyStyle,\n      tr: TableTrStyle,\n      th: TableThStyle,\n      td: TableTdStyle,\n      caption: TableCaptionStyle,\n    },\n    classNames,\n    styles,\n    unstyled,\n    rootSelector: 'table',\n    vars,\n    varsResolver,\n  });\n\n  return (\n    <TableProvider\n      value={{\n        getStyles,\n        stickyHeader,\n        striped: striped === true ? 'odd' : striped || undefined,\n        highlightOnHover,\n        withColumnBorders,\n        withRowBorders,\n        captionSide: captionSide || 'bottom',\n      }}\n    >\n      <Box\n        component=\"table\"\n        variant={variant}\n        ref={ref}\n        mod={[{ 'data-with-table-border': withTableBorder, 'data-tabular-nums': tabularNums }, mod]}\n        {...getStyles('table')}\n        {...others}\n      >\n        {children || (!!data && <TableDataRenderer data={data} />)}\n      </Box>\n    </TableProvider>\n  );\n});\n\nTable.displayName = '@raikou/core/Table';\nTable.Td = TableTd;\nTable.Th = TableTh;\nTable.Tr = TableTr;\nTable.Thead = TableThead;\nTable.Tbody = TableTbody;\nTable.Tfoot = TableTfoot;\nTable.Caption = TableCaption;\nTable.ScrollContainer = TableScrollContainer;\nTable.DataRenderer = TableDataRenderer;\n"],"names":["createVarsResolver","getSpacing","getThemeColor","rem","factory","useProps","useStyles","TableRootStyle","TableTheadStyle","TableTbodyStyle","TableTrStyle","TableThStyle","TableTdStyle","TableCaptionStyle","jsx","TableProvider","Box","TableDataRenderer","TableTd","TableTh","TableTr","TableThead","TableTbody","TableTfoot","TableCaption","TableScrollContainer"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAyIA,MAAM,YAAoC,GAAA;AAAA,EACxC,cAAgB,EAAA,IAAA;AAAA,EAChB,eAAiB,EAAA;AACnB,CAAA;AAEA,MAAM,YAAe,GAAAA,qCAAA;AAAA,EACnB,CACE,KACA,EAAA;AAAA,IACE,MAAA;AAAA,IACA,WAAA;AAAA,IACA,iBAAA;AAAA,IACA,eAAA;AAAA,IACA,WAAA;AAAA,IACA,YAAA;AAAA,IACA,qBAAA;AAAA,IACA,OAAA;AAAA,IACA,gBAAA;AAAA,IACA,kBAAA;AAAA,IACA;AAAA,GAEE,MAAA;AAAA,IACJ,KAAO,EAAA;AAAA,MACL,gBAAkB,EAAA,MAAA;AAAA,MAClB,sBAAwB,EAAA,WAAA;AAAA,MACxB,4BAAA,EAA8BC,mBAAW,iBAAiB,CAAA;AAAA,MAC1D,0BAAA,EAA4BA,mBAAW,eAAe,CAAA;AAAA,MACtD,sBAAwB,EAAA,WAAA,GAAcC,2BAAc,CAAA,WAAA,EAAa,KAAK,CAAI,GAAA,KAAA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