{"version":3,"file":"Table.components.cjs","sources":["../../../src/components/Table/Table.components.tsx"],"sourcesContent":["import {\n  Box,\n  BoxProps,\n  CompoundStylesApiProps,\n  ElementProps,\n  factory,\n  Factory,\n  FactoryPayload,\n  useProps,\n} from '../../core';\nimport type { TableFactory } from './Table';\nimport { TableContextValue, useTableContext } from './Table.context';\n\nexport interface TableElementProps<Selector extends string>\n  extends BoxProps,\n    CompoundStylesApiProps<Omit<TableFactory, 'stylesNames'> & { stylesNames: Selector }> {}\n\nexport interface TableThProps extends TableElementProps<'th'>, ElementProps<'th'> {}\nexport interface TableTdProps extends TableElementProps<'td'>, ElementProps<'td'> {}\nexport interface TableTrProps extends TableElementProps<'tr'>, ElementProps<'tr'> {}\nexport interface TableTheadProps extends TableElementProps<'thead'>, ElementProps<'thead'> {}\nexport interface TableTbodyProps extends TableElementProps<'tbody'>, ElementProps<'tbody'> {}\nexport interface TableTfootProps extends TableElementProps<'tfoot'>, ElementProps<'tfoot'> {}\nexport interface TableCaptionProps extends TableElementProps<'caption'>, ElementProps<'caption'> {}\n\nexport type TableThFactory = Factory<{\n  props: TableThProps;\n  ref: HTMLTableCellElement;\n  stylesNames: 'th';\n  compound: true;\n}>;\n\nexport type TableTdFactory = Factory<{\n  props: TableTdProps;\n  ref: HTMLTableCellElement;\n  stylesNames: 'td';\n  compound: true;\n}>;\n\nexport type TableTrFactory = Factory<{\n  props: TableTrProps;\n  ref: HTMLTableRowElement;\n  stylesNames: 'tr';\n  compound: true;\n}>;\n\nexport type TableTheadFactory = Factory<{\n  props: TableTheadProps;\n  ref: HTMLTableSectionElement;\n  stylesNames: 'thead';\n  compound: true;\n}>;\n\nexport type TableTbodyFactory = Factory<{\n  props: TableTbodyProps;\n  ref: HTMLTableSectionElement;\n  stylesNames: 'tbody';\n  compound: true;\n}>;\n\nexport type TableTfootFactory = Factory<{\n  props: TableTfootProps;\n  ref: HTMLTableSectionElement;\n  stylesNames: 'tfoot';\n  compound: true;\n}>;\n\nexport type TableCaptionFactory = Factory<{\n  props: TableCaptionProps;\n  ref: HTMLTableCaptionElement;\n  stylesNames: 'caption';\n  compound: true;\n}>;\n\ninterface TableElementOptions {\n  columnBorder?: true;\n  rowBorder?: true;\n  striped?: true;\n  highlightOnHover?: true;\n  captionSide?: true;\n  stickyHeader?: true;\n}\n\nfunction getDataAttributes(ctx: TableContextValue, options?: TableElementOptions) {\n  if (!options) {\n    return undefined;\n  }\n\n  const data: Record<string, boolean | string> = {};\n\n  if (options.columnBorder && ctx.withColumnBorders) {\n    data['data-with-column-border'] = true;\n  }\n\n  if (options.rowBorder && ctx.withRowBorders) {\n    data['data-with-row-border'] = true;\n  }\n\n  if (options.striped && ctx.striped) {\n    data['data-striped'] = ctx.striped;\n  }\n\n  if (options.highlightOnHover && ctx.highlightOnHover) {\n    data['data-hover'] = true;\n  }\n\n  if (options.captionSide && ctx.captionSide) {\n    data['data-side'] = ctx.captionSide;\n  }\n\n  if (options.stickyHeader && ctx.stickyHeader) {\n    data['data-sticky'] = true;\n  }\n\n  return data;\n}\n\nexport function tableElement<Factory extends FactoryPayload>(\n  element: 'th' | 'td' | 'tr' | 'thead' | 'tbody' | 'tfoot' | 'caption',\n  options?: TableElementOptions\n) {\n  const name = `Table${element.charAt(0).toUpperCase()}${element.slice(1)}`;\n  const Component = factory<Factory>((_props, ref) => {\n    const props = useProps(name, {}, _props);\n    const { classNames, className, style, styles, ...others } = props;\n\n    const ctx = useTableContext();\n\n    return (\n      <Box\n        component={element}\n        ref={ref}\n        {...getDataAttributes(ctx, options)}\n        {...ctx.getStyles(element, { className, classNames, style, styles, props })}\n        {...others}\n      />\n    );\n  });\n\n  Component.displayName = `@raikou/core/${name}`;\n  return Component;\n}\n\nexport const TableTh = tableElement<TableThFactory>('th', { columnBorder: true });\nexport const TableTd = tableElement<TableTdFactory>('td', { columnBorder: true });\nexport const TableTr = tableElement<TableTrFactory>('tr', {\n  rowBorder: true,\n  striped: true,\n  highlightOnHover: true,\n});\nexport const TableThead = tableElement<TableTheadFactory>('thead', { stickyHeader: true });\nexport const TableTbody = tableElement<TableTbodyFactory>('tbody');\nexport const TableTfoot = tableElement<TableTfootFactory>('tfoot');\nexport const TableCaption = tableElement<TableCaptionFactory>('caption', { captionSide: true });\n"],"names":["factory","useProps","useTableContext","jsx","Box"],"mappings":";;;;;;;;;;;;;AAmFA,SAAS,iBAAA,CAAkB,KAAwB,OAA+B,EAAA;AAChF,EAAA,IAAI,CAAC,OAAS,EAAA;AACZ,IAAO,OAAA,KAAA,CAAA;AAAA;AAGT,EAAA,MAAM,OAAyC,EAAC;AAEhD,EAAI,IAAA,OAAA,CAAQ,YAAgB,IAAA,GAAA,CAAI,iBAAmB,EAAA;AACjD,IAAA,IAAA,CAAK,yBAAyB,CAAI,GAAA,IAAA;AAAA;AAGpC,EAAI,IAAA,OAAA,CAAQ,SAAa,IAAA,GAAA,CAAI,cAAgB,EAAA;AAC3C,IAAA,IAAA,CAAK,sBAAsB,CAAI,GAAA,IAAA;AAAA;AAGjC,EAAI,IAAA,OAAA,CAAQ,OAAW,IAAA,GAAA,CAAI,OAAS,EAAA;AAClC,IAAK,IAAA,CAAA,cAAc,IAAI,GAAI,CAAA,OAAA;AAAA;AAG7B,EAAI,IAAA,OAAA,CAAQ,gBAAoB,IAAA,GAAA,CAAI,gBAAkB,EAAA;AACpD,IAAA,IAAA,CAAK,YAAY,CAAI,GAAA,IAAA;AAAA;AAGvB,EAAI,IAAA,OAAA,CAAQ,WAAe,IAAA,GAAA,CAAI,WAAa,EAAA;AAC1C,IAAK,IAAA,CAAA,WAAW,IAAI,GAAI,CAAA,WAAA;AAAA;AAG1B,EAAI,IAAA,OAAA,CAAQ,YAAgB,IAAA,GAAA,CAAI,YAAc,EAAA;AAC5C,IAAA,IAAA,CAAK,aAAa,CAAI,GAAA,IAAA;AAAA;AAGxB,EAAO,OAAA,IAAA;AACT;AAEgB,SAAA,YAAA,CACd,SACA,OACA,EAAA;AACA,EAAA,MAAM,IAAO,GAAA,CAAA,KA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