{"version":3,"file":"Table.components.cjs","names":["factory","useProps","useTableContext","Box","classes"],"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';\nimport classes from './Table.module.css';\n\nexport interface TableElementProps<Selector extends string>\n  extends\n    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) => {\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        {...getDataAttributes(ctx, options)}\n        {...ctx.getStyles(element, { className, classNames, style, styles, props })}\n        {...others}\n      />\n    );\n  });\n\n  Component.displayName = `@mantine/core/${name}`;\n  Component.classes = classes;\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"],"mappings":";;;;;;;;;AAqFA,SAAS,kBAAkB,KAAwB,SAA+B;AAChF,KAAI,CAAC,QACH;CAGF,MAAM,OAAyC,EAAE;AAEjD,KAAI,QAAQ,gBAAgB,IAAI,kBAC9B,MAAK,6BAA6B;AAGpC,KAAI,QAAQ,aAAa,IAAI,eAC3B,MAAK,0BAA0B;AAGjC,KAAI,QAAQ,WAAW,IAAI,QACzB,MAAK,kBAAkB,IAAI;AAG7B,KAAI,QAAQ,oBAAoB,IAAI,iBAClC,MAAK,gBAAgB;AAGvB,KAAI,QAAQ,eAAe,IAAI,YAC7B,MAAK,eAAe,IAAI;AAG1B,KAAI,QAAQ,gBAAgB,IAAI,aAC9B,MAAK,iBAAiB;AAGxB,QAAO;;AAGT,SAAgB,aACd,SACA,SACA;CACA,MAAM,OAAO,QAAQ,QAAQ,OAAO,EAAE,CAAC,aAAa,GAAG,QAAQ,MAAM,EAAE;CACvE,MAAM,YAAYA,gBAAAA,SAAkB,WAAW;EAC7C,MAAM,QAAQC,kBAAAA,SAAS,MAAM,EAAE,EAAE,OAAO;EACxC,MAAM,EAAE,YAAY,WAAW,OAAO,QAAQ,GAAG,WAAW;EAE5D,MAAM,MAAMC,sBAAAA,iBAAiB;AAE7B,SACE,iBAAA,GAAA,kBAAA,KAACC,YAAAA,KAAD;GACE,WAAW;GACX,GAAI,kBAAkB,KAAK,QAAQ;GACnC,GAAI,IAAI,UAAU,SAAS;IAAE;IAAW;IAAY;IAAO;IAAQ;IAAO,CAAC;GAC3E,GAAI;GACJ,CAAA;GAEJ;AAEF,WAAU,cAAc,iBAAiB;AACzC,WAAU,UAAUC,qBAAAA;AACpB,QAAO;;AAGT,MAAa,UAAU,aAA6B,MAAM,EAAE,cAAc,MAAM,CAAC;AACjF,MAAa,UAAU,aAA6B,MAAM,EAAE,cAAc,MAAM,CAAC;AACjF,MAAa,UAAU,aAA6B,MAAM;CACxD,WAAW;CACX,SAAS;CACT,kBAAkB;CACnB,CAAC;AACF,MAAa,aAAa,aAAgC,SAAS,EAAE,cAAc,MAAM,CAAC;AAC1F,MAAa,aAAa,aAAgC,QAAQ;AAClE,MAAa,aAAa,aAAgC,QAAQ;AAClE,MAAa,eAAe,aAAkC,WAAW,EAAE,aAAa,MAAM,CAAC"}