@underpin/ui 2.0.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"table.js","names":[],"sources":["../../src/components/table.tsx"],"sourcesContent":["\"use client\"\n\nimport { useRender } from \"@base-ui/react/use-render\"\nimport {\n Children,\n type ComponentProps,\n createContext,\n type CSSProperties,\n type ReactNode,\n use,\n} from \"react\"\nimport { rowPressClasses } from \"../lib/classes\"\nimport {\n AlertIcon,\n ArrowDownIcon,\n ArrowUpIcon,\n FilterIcon,\n MoreIcon,\n RefreshIcon,\n} from \"../lib/icons\"\nimport { cn, variants, type VariantProps } from \"../lib/variants\"\nimport { Button } from \"./button\"\nimport { Checkbox } from \"./checkbox\"\nimport { CopyButton } from \"./copy-button\"\nimport { EmptyState } from \"./empty-state\"\nimport { Menu, MenuContent, MenuTrigger } from \"./menu\"\nimport { Skeleton } from \"./skeleton\"\nimport { Sparkline } from \"./sparkline\"\n\n// The parts are table elements laid out as a CSS grid, so they carry their table roles\n// explicitly: a browser that sees `display: grid` on a `<table>` may stop exposing it as one.\n/* oxlint-disable jsx-a11y/no-redundant-roles */\n\n/**\n * Which columns give way as the table's box narrows: a `medium` column hides below the `@2xl`\n * container width (672px), a `low` one below `@4xl` (896px) and a `lowest` one below `@6xl`\n * (1152px), for a table with more columns than a laptop's content column holds. A column with\n * none always shows.\n */\nexport type TableColumnPriority = \"medium\" | \"low\" | \"lowest\"\n\nexport interface TableColumn {\n /** The column's grid track: `minmax(0,1fr)` for the name, a fixed `6rem` for a figure. */\n width: string\n priority?: TableColumnPriority\n /** Where a skeleton row puts its stand-in. */\n align?: \"start\" | \"end\"\n /** Whether a skeleton row draws a stand-in here. Off for a checkbox or actions column. */\n skeleton?: boolean\n}\n\ntype TableLayout = \"table\" | \"list\"\n\ninterface TableContextValue {\n layout: TableLayout\n columns: TableColumn[]\n}\n\nconst TableContext = createContext<TableContextValue>({ layout: \"table\", columns: [] })\n\ninterface TableColumnScopeValue {\n align?: \"start\" | \"end\"\n priority?: TableColumnPriority\n}\n\nconst TableColumnScopeContext = createContext<TableColumnScopeValue>({})\n\n/**\n * The classes that hide a cell of a column with a priority, on its head and on every cell, so\n * the column drops out whole. `Table` drops its track from the grid at the same widths.\n */\nexport const tableColumnPriorityClasses: Record<TableColumnPriority, string> = {\n medium: \"@max-2xl:hidden\",\n low: \"@max-4xl:hidden\",\n lowest: \"@max-6xl:hidden\",\n}\n\nfunction formatColumnTemplate(columns: TableColumn[], hidden: TableColumnPriority[]) {\n return columns\n .filter(column => !column.priority || !hidden.includes(column.priority))\n .map(column => column.width)\n .join(\" \")\n}\n\nconst ROW_GRID_CLASSES = \"col-span-full grid grid-cols-subgrid\"\n\nconst tableVariants = variants({\n slots: {\n container: \"@container relative\",\n table: [\n \"grid w-full text-control text-ink\",\n \"grid-cols-(--table-columns) @2xl:grid-cols-(--table-columns-md) @4xl:grid-cols-(--table-columns-lg) @6xl:grid-cols-(--table-columns-xl)\",\n // A sticky header pushes the sticky group headings down by its own height.\n \"has-[>[data-sticky]]:[--table-header-height:--spacing(10)]\",\n ],\n },\n\n variants: {\n variant: {\n // The card surface, its edge drawn by the wrapper so the rows' fills stay inside it.\n card: { container: \"overflow-clip rounded-lg border bg-surface shadow-card\" },\n // No surface, for a table inside another card or a dialog.\n flush: {},\n },\n },\n\n defaultVariants: {\n variant: \"card\",\n },\n})\n\nconst tableRowVariants = variants({\n base: [\n ROW_GRID_CLASSES,\n \"group/row relative items-center border-t border-edge-subtle\",\n // Only a row that opens something answers the pointer. The hover and focus fills leave out a\n // pressed link: they match with the same weight as the press fill and come later in the\n // stylesheet, so they would hide it.\n \"has-[[data-row-link]:not(:active)]:hover:bg-canvas has-[[data-row-link]:focus-visible:not(:active)]:bg-canvas\",\n rowPressClasses,\n \"data-selected:bg-fill-subtle data-selected:hover:bg-fill-subtle\",\n // The cell holding the row link sits on a layer above its neighbours. A faded cell is a\n // stacking context of its own, and a later one would otherwise paint over the link's box.\n // A grid item takes `z-index` without being positioned, so the link still fills the row.\n \"*:has-[[data-row-link]]:z-1\",\n // An archived or blocked record fades, all but its menu. A cell holding a control above the\n // row link (the checkbox, a copy button) fades its content instead: faded whole, it would be\n // a stacking context under the link's layer, and the control could not be clicked.\n \"data-inactive:*:not-data-[slot=actions]:not-data-[slot=checkbox]:not-data-[slot=mono]:opacity-50\",\n ],\n\n variants: {\n size: {\n /** 32px, for a feed or a dense list. */\n compact: \"h-8\",\n /** 44px, a one-line row. */\n default: \"h-11\",\n /** 52px, for a two-line name cell. */\n identity: \"h-13\",\n },\n },\n\n defaultVariants: {\n size: \"default\",\n },\n})\n\nconst tableCellVariants = variants({\n base: [\n \"flex min-w-0 items-center gap-2 px-2 first:pl-5 last:pr-5\",\n // The trailing inset goes to the last cell still shown: a hidden cell after it stays the\n // `:last-child`. Below 1152px that is a cell followed only by `lowest` ones, below 896px one\n // followed only by `low` and `lowest` ones, below 672px one followed only by cells with a\n // priority.\n \"@max-6xl:[&:not(:has(~:not([data-priority=lowest])))]:pr-5\",\n \"@max-4xl:[&:not(:has(~:not([data-priority=low]):not([data-priority=lowest])))]:pr-5\",\n \"@max-2xl:[&:not(:has(~:not([data-priority])))]:pr-5\",\n ],\n\n variants: {\n align: {\n start: \"justify-start text-left\",\n end: \"justify-end text-right\",\n },\n priority: tableColumnPriorityClasses,\n },\n\n defaultVariants: {\n align: \"start\",\n },\n})\n\ntype TableCellVariantProps = VariantProps<typeof tableCellVariants>\n\n/** Varied widths for a skeleton row's first line, so a stack of them does not read as stripes. */\nconst SKELETON_NAME_WIDTHS = [\"w-36\", \"w-28\", \"w-40\", \"w-32\", \"w-24\"]\n\nconst MESSAGE_ICONS = {\n filtered: <FilterIcon />,\n error: <AlertIcon />,\n}\n\nexport interface TableProps\n extends Omit<ComponentProps<\"table\">, \"children\">, VariantProps<typeof tableVariants> {\n /** Every column in order, the same list the head and the cells of each row follow. */\n columns: TableColumn[]\n /**\n * `list` draws the same rows with no column names, for a list of records (members, API keys):\n * the rows are list items rather than table rows.\n */\n layout?: TableLayout\n /** The band under the rows: `Pagination` or `PaginationInfinite`. */\n footer?: ReactNode\n /** Classes for the box around the table: the card, or the bare wrapper of a flush table. */\n containerClassName?: string\n children?: ReactNode\n}\n\n/**\n * A table on a CSS grid. The root sets one grid template from `columns`, and the header and\n * every row take it as a subgrid, so the columns line up however the rows are grouped. A row\n * stays a positioned box, which a real table row is not in Safari, so a stretched link can\n * fill it (`TableRowLink`). Columns with a `priority` drop out as the table's own box narrows.\n * Set `--table-sticky-top` on it when a sticky header must clear a bar pinned above it.\n */\nexport function Table({\n columns,\n layout = \"table\",\n variant,\n footer,\n className,\n containerClassName,\n style,\n children,\n ...props\n}: TableProps) {\n const styles = tableVariants({ variant })\n const template = {\n \"--table-columns\": formatColumnTemplate(columns, [\"medium\", \"low\", \"lowest\"]),\n \"--table-columns-md\": formatColumnTemplate(columns, [\"low\", \"lowest\"]),\n \"--table-columns-lg\": formatColumnTemplate(columns, [\"lowest\"]),\n \"--table-columns-xl\": formatColumnTemplate(columns, []),\n ...style,\n } as CSSProperties\n const Root = layout === \"list\" ? \"div\" : \"table\"\n\n return (\n <TableContext value={{ layout, columns }}>\n <div className={styles.container({ className: containerClassName })}>\n <Root\n role={layout === \"list\" ? \"list\" : \"table\"}\n className={styles.table({ className })}\n style={template}\n {...props}\n >\n {children}\n </Root>\n {footer}\n </div>\n </TableContext>\n )\n}\n\ninterface TableHeaderProps extends ComponentProps<\"thead\"> {\n /** Keeps the column names in view while the rows scroll under them. */\n sticky?: boolean\n}\n\n/**\n * The row of column names: 40px, on the surface, with one line under it in the card's edge\n * colour. The first row draws no line of its own, so the two never stack. A list has none, and\n * renders nothing for one.\n */\nexport function TableHeader({ sticky, className, children, ...props }: TableHeaderProps) {\n if (use(TableContext).layout === \"list\") return null\n\n return (\n <thead\n role=\"rowgroup\"\n data-sticky={sticky ? \"\" : undefined}\n className={cn(\n ROW_GRID_CLASSES,\n \"border-b bg-surface\",\n sticky && \"sticky top-(--table-sticky-top,0px) z-20\",\n className,\n )}\n {...props}\n >\n {/* The rule reads a header row as interactive; the role restores what `display: grid` drops. */}\n {/* oxlint-disable-next-line jsx-a11y/no-interactive-element-to-noninteractive-role */}\n <tr role=\"row\" className={cn(ROW_GRID_CLASSES, \"h-10 items-center\")}>\n {children}\n </tr>\n </thead>\n )\n}\n\n/**\n * The rows. A table cut into runs (days, workspaces) takes one body per run, each opening with\n * its `TableGroupHeader`, so the heading sticks while its own rows are in view.\n */\nexport function TableBody({ className, ...props }: ComponentProps<\"tbody\">) {\n const { layout } = use(TableContext)\n const Body = layout === \"list\" ? \"div\" : \"tbody\"\n\n return (\n <Body\n role={layout === \"list\" ? \"presentation\" : \"rowgroup\"}\n className={cn(\n ROW_GRID_CLASSES,\n // The first row of the table sits under the header's line, or the card's edge.\n \"[&:first-of-type>:first-child]:border-t-0\",\n className,\n )}\n {...props}\n />\n )\n}\n\nexport interface TableRowProps extends ComponentProps<\"tr\">, VariantProps<typeof tableRowVariants> {\n selected?: boolean\n /** Dims the row's cells, for a record that is archived or blocked. */\n inactive?: boolean\n}\n\n/**\n * One record. A row whose name is a `TableRowLink` opens it from anywhere on the row and takes\n * the hover fill; a row without one keeps its background under the pointer.\n */\nexport function TableRow({ size, selected, inactive, className, ...props }: TableRowProps) {\n const { layout } = use(TableContext)\n const Row = layout === \"list\" ? \"div\" : \"tr\"\n\n return (\n <Row\n role={layout === \"list\" ? \"listitem\" : \"row\"}\n data-selected={selected ? \"\" : undefined}\n data-inactive={inactive ? \"\" : undefined}\n className={tableRowVariants({ size, className })}\n {...props}\n />\n )\n}\n\nexport interface TableHeadProps extends Omit<ComponentProps<\"th\">, \"align\">, TableCellVariantProps {\n /** The order the table is in by this column. Left out for a column that does not sort. */\n sort?: \"ascending\" | \"descending\" | \"none\"\n /** Turns the name into a button that sorts by the column. */\n onSort?: () => void\n}\n\n/**\n * A column name, in the control weight. A sortable column is a button, with the arrow of its\n * order while the table is sorted by it; unsorted, it looks like any other name.\n */\nexport function TableHead({\n align,\n priority,\n sort,\n onSort,\n className,\n children,\n ...props\n}: TableHeadProps) {\n const sorted = sort === \"ascending\" || sort === \"descending\"\n const Arrow = sort === \"ascending\" ? ArrowUpIcon : ArrowDownIcon\n\n return (\n <th\n role=\"columnheader\"\n scope=\"col\"\n data-priority={priority}\n aria-sort={sort}\n className={tableCellVariants({\n align,\n priority,\n className: cn(\"gap-1 font-medium text-control text-ink\", className),\n })}\n {...props}\n >\n {onSort ? (\n <button\n type=\"button\"\n className=\"inline-flex min-w-0 cursor-pointer items-center gap-1 rounded-xs hover:text-ink-secondary\"\n onClick={onSort}\n >\n <span className=\"truncate\">{children}</span>\n {sorted && <Arrow className=\"size-3 shrink-0\" />}\n </button>\n ) : (\n children\n )}\n </th>\n )\n}\n\nexport interface TableCellProps\n extends Omit<ComponentProps<\"td\">, \"align\">, TableCellVariantProps {}\n\n/**\n * One cell, the Text type: a line of ink that ends in an ellipsis. Every other cell type is\n * built on it. Give it the `align` and `priority` of its column's head.\n */\nexport function TableCell({ align, priority, className, children, ...props }: TableCellProps) {\n const { layout } = use(TableContext)\n const scope = use(TableColumnScopeContext)\n const columnPriority = priority ?? scope.priority\n const Cell = layout === \"list\" ? \"div\" : \"td\"\n const text = typeof children === \"string\" || typeof children === \"number\"\n\n return (\n <Cell\n role={layout === \"list\" ? undefined : \"cell\"}\n data-priority={columnPriority}\n className={tableCellVariants({\n align: align ?? scope.align,\n priority: columnPriority,\n className,\n })}\n {...props}\n >\n {text ? <span className=\"truncate\">{children}</span> : children}\n </Cell>\n )\n}\n\ninterface TableColumnScopeProps extends TableColumnScopeValue {\n children?: ReactNode\n}\n\n/**\n * Hands the cells inside it their column's `align` and `priority`, for a cell rendered by code\n * that knows nothing of its column (a `DataTable` column's `cell`). A cell's own props win.\n */\nexport function TableColumnScope({ align, priority, children }: TableColumnScopeProps) {\n return <TableColumnScopeContext value={{ align, priority }}>{children}</TableColumnScopeContext>\n}\n\n/**\n * The record's name as a link that covers the whole row: its box stretches over the row, and\n * the focus ring is drawn round the row. The checkbox, the menu and any other link in the row\n * sit above it (`relative z-10`, as the checkbox and actions cells do), so each keeps its own\n * click. Pass `render` for a router's link.\n */\nexport function TableRowLink({ render, className, ...props }: useRender.ComponentProps<\"a\">) {\n return useRender({\n render,\n defaultTagName: \"a\",\n props: {\n \"data-row-link\": \"\",\n \"data-press-target\": \"\",\n className: cn(\n \"truncate outline-none after:absolute after:inset-0\",\n \"focus-visible:after:outline-2 focus-visible:after:-outline-offset-2 focus-visible:after:outline-focus\",\n className,\n ),\n ...props,\n },\n })\n}\n\ninterface TableIdentityCellProps extends Omit<TableCellProps, \"title\"> {\n /** A favicon, an avatar or a letter tile, sized 28px (`size-7`) by the caller. */\n leading?: ReactNode\n /** The record's name, usually a `TableRowLink`. */\n title: ReactNode\n /** One muted line under the name: a domain, an email. */\n detail?: ReactNode\n /** A flag or a badge after the name. */\n extras?: ReactNode\n}\n\n/** The name column: the leading mark, the name in the control weight and a muted line. */\nexport function TableIdentityCell({\n leading,\n title,\n detail,\n extras,\n className,\n ...props\n}: TableIdentityCellProps) {\n return (\n <TableCell className={cn(\"gap-3\", className)} {...props}>\n {leading && <span className=\"flex shrink-0\">{leading}</span>}\n <span className=\"flex min-w-0 flex-col gap-0.5\">\n <span className=\"flex min-w-0 items-center gap-1.5\">\n <span className=\"min-w-0 truncate font-medium\">{title}</span>\n {extras && <span className=\"flex shrink-0 items-center gap-1.5\">{extras}</span>}\n </span>\n {detail && <span className=\"truncate text-ink-muted text-xs\">{detail}</span>}\n </span>\n </TableCell>\n )\n}\n\n/**\n * A figure, Number or Money: end-aligned in tabular figures. The caller formats the value, a\n * sum of money with its currency.\n */\nexport function TableNumberCell({ align, className, ...props }: TableCellProps) {\n const scope = use(TableColumnScopeContext)\n\n return (\n <TableCell\n align={align ?? scope.align ?? \"end\"}\n className={cn(\"tabular-nums\", className)}\n {...props}\n />\n )\n}\n\n/** A date, muted: pass a `RelativeTime`, which keeps the exact moment for its tooltip. */\nexport function TableDateCell({ className, ...props }: TableCellProps) {\n return <TableCell className={cn(\"text-ink-muted tabular-nums\", className)} {...props} />\n}\n\n/** A status: pass one `Badge`. */\nexport function TableBadgeCell(props: TableCellProps) {\n return <TableCell {...props} />\n}\n\ninterface TableTagsCellProps extends Omit<TableCellProps, \"children\"> {\n /** One `Badge` per tag. */\n tags: ReactNode[]\n /** How many show before the rest fold into \"+N\". */\n max?: number\n}\n\n/** Tags: the first two, then a count of the rest. */\nexport function TableTagsCell({ tags, max = 2, className, ...props }: TableTagsCellProps) {\n const rest = tags.length - max\n\n return (\n <TableCell className={cn(\"gap-1\", className)} {...props}>\n {Children.toArray(tags.slice(0, max))}\n {rest > 0 && <span className=\"shrink-0 text-ink-muted text-xs tabular-nums\">+{rest}</span>}\n </TableCell>\n )\n}\n\ninterface TableSparklineCellProps extends Omit<TableCellProps, \"children\"> {\n data: number[]\n}\n\n/** A trend: a `Sparkline` across the cell, 32px tall. */\nexport function TableSparklineCell({ data, ...props }: TableSparklineCellProps) {\n return (\n <TableCell {...props}>\n <Sparkline data={data} className=\"h-8 w-full\" />\n </TableCell>\n )\n}\n\nconst METER_TONES = {\n neutral: { bar: \"bg-ink\", ring: \"stroke-ink\" },\n brand: { bar: \"bg-brand\", ring: \"stroke-brand\" },\n warning: { bar: \"bg-warning\", ring: \"stroke-warning\" },\n danger: { bar: \"bg-danger\", ring: \"stroke-danger\" },\n}\n\n/** The ring's radius in its 16px box, and the length of its circle. */\nconst RING_RADIUS = 6\nconst RING_LENGTH = 2 * Math.PI * RING_RADIUS\n\ninterface TableMeterCellProps extends Omit<TableCellProps, \"children\"> {\n value: number\n max: number\n /** The usage as text, formatted by the caller: \"8,240 of 10,000\". */\n label?: ReactNode\n /**\n * The meter's colour, for a meter whose state the app knows better than the share does (a\n * usage lock, a failed job). Left out, it is ink and turns warning past 90%.\n */\n tone?: keyof typeof METER_TONES\n /**\n * `bar` puts a 48px bar before a muted figure. `ring` puts a 14px ring before the figure in the\n * cell's own text, for a narrow column whose figure needs the room (\"35.5k of 657.2k rows\").\n */\n layout?: \"bar\" | \"ring\"\n}\n\n/** Usage against a limit: a bar or a ring, then the figure. It turns warning past 90%. */\nexport function TableMeterCell({\n value,\n max,\n label,\n tone,\n layout = \"bar\",\n className,\n ...props\n}: TableMeterCellProps) {\n const share = max > 0 ? Math.min(value / max, 1) : 0\n const tones = METER_TONES[tone ?? (share > 0.9 ? \"warning\" : \"neutral\")]\n const ring = layout === \"ring\"\n\n return (\n <TableCell className={cn(ring ? \"gap-1.5\" : \"gap-2\", className)} {...props}>\n <span\n // A native `<meter>` draws its own bar, which the theme's tokens cannot reach.\n // oxlint-disable-next-line jsx-a11y/prefer-tag-over-role\n role=\"meter\"\n aria-valuenow={value}\n aria-valuemin={0}\n aria-valuemax={max}\n aria-label={typeof label === \"string\" ? label : undefined}\n className={cn(\n \"shrink-0\",\n ring ? \"flex size-3.5\" : \"h-1 w-12 overflow-hidden rounded-full bg-fill\",\n )}\n >\n {ring ? (\n <svg aria-hidden viewBox=\"0 0 16 16\" fill=\"none\" className=\"size-full -rotate-90\">\n <circle\n cx=\"8\"\n cy=\"8\"\n r={RING_RADIUS}\n strokeWidth=\"2.5\"\n className=\"stroke-fill-strong\"\n />\n {share > 0 && (\n <circle\n cx=\"8\"\n cy=\"8\"\n r={RING_RADIUS}\n strokeWidth=\"2.5\"\n strokeLinecap=\"round\"\n strokeDasharray={`${share * RING_LENGTH} ${RING_LENGTH}`}\n className={tones.ring}\n />\n )}\n </svg>\n ) : (\n <span\n className={cn(\"block h-full rounded-full\", tones.bar)}\n style={{ width: `${share * 100}%` }}\n />\n )}\n </span>\n {label && (\n <span className={cn(\"truncate tabular-nums\", !ring && \"text-ink-muted text-xs\")}>\n {label}\n </span>\n )}\n </TableCell>\n )\n}\n\ninterface TableCountryCellProps extends Omit<TableCellProps, \"children\"> {\n /** The country's flag. */\n flag: ReactNode\n name: ReactNode\n}\n\n/** A country: its flag and its name. */\nexport function TableCountryCell({ flag, name, ...props }: TableCountryCellProps) {\n return (\n <TableCell {...props}>\n <span className=\"flex shrink-0\">{flag}</span>\n <span className=\"truncate\">{name}</span>\n </TableCell>\n )\n}\n\ninterface TableMonoCellProps extends Omit<TableCellProps, \"children\"> {\n value: string\n /** Adds a copy button after the value. */\n copy?: boolean\n}\n\n/** A machine string (a key, an id) in mono, with a copy button that sits above the row link. */\nexport function TableMonoCell({ value, copy, className, ...props }: TableMonoCellProps) {\n return (\n <TableCell data-slot=\"mono\" className={cn(\"gap-1\", className)} {...props}>\n <span className=\"truncate font-mono text-ink-secondary text-xs in-data-inactive:opacity-50\">\n {value}\n </span>\n {copy && (\n <CopyButton\n value={value}\n variant=\"ghost\"\n size=\"xs\"\n className=\"relative z-10 in-data-inactive:opacity-50\"\n />\n )}\n </TableCell>\n )\n}\n\ninterface TablePersonCellProps extends Omit<TableCellProps, \"children\"> {\n /** An avatar, sized 20px (`size-5`) by the caller. */\n avatar?: ReactNode\n name: ReactNode\n}\n\n/** A person on one line: a 20px avatar and the name. */\nexport function TablePersonCell({ avatar, name, ...props }: TablePersonCellProps) {\n return (\n <TableCell {...props}>\n {avatar && <span className=\"flex shrink-0\">{avatar}</span>}\n <span className=\"truncate\">{name}</span>\n </TableCell>\n )\n}\n\n/**\n * The row's menu, end-aligned above the row link. It shows on hover, on keyboard focus, while\n * open, and always on a touch screen, which has no hover to give.\n */\nexport function TableActionsCell({ align, className, children, ...props }: TableCellProps) {\n const scope = use(TableColumnScopeContext)\n\n return (\n <TableCell\n data-slot=\"actions\"\n align={align ?? scope.align ?? \"end\"}\n className={className}\n {...props}\n >\n <span\n className={cn(\n \"relative z-10 flex\",\n \"opacity-0 group-hover/row:opacity-100 focus-within:opacity-100 has-data-popup-open:opacity-100 pointer-coarse:opacity-100\",\n )}\n >\n {children}\n </span>\n </TableCell>\n )\n}\n\ninterface TableActionsMenuProps {\n /** Names the menu and its trigger for a screen reader: \"Actions for figma.com\". */\n label: string\n /** Classes for the trigger, e.g. its place on a card. */\n className?: string\n children: ReactNode\n}\n\n/**\n * The row's \"…\" menu, for a `TableActionsCell`: a quiet ghost trigger that grows to finger size\n * on a touch screen, and a menu aligned to the row's end.\n */\nexport function TableActionsMenu({ label, className, children }: TableActionsMenuProps) {\n return (\n <Menu>\n <MenuTrigger\n render={\n <Button\n aria-label={label}\n variant=\"ghost\"\n size=\"sm\"\n prefix={<MoreIcon />}\n className={cn(\"text-ink-muted pointer-coarse:size-10\", className)}\n />\n }\n />\n <MenuContent label={label} align=\"end\">\n {children}\n </MenuContent>\n </Menu>\n )\n}\n\ninterface TableCheckboxCellProps\n extends\n Omit<TableCellProps, \"children\" | \"onChange\">,\n Pick<\n ComponentProps<typeof Checkbox>,\n \"checked\" | \"indeterminate\" | \"disabled\" | \"onCheckedChange\"\n > {\n /** Names the checkbox: \"Select openalternative.com\", \"Select all\". */\n label: string\n /** Renders a head cell for the header row: the select-all box. Ignored in a list. */\n header?: boolean\n}\n\n/** Selects the row, or every row on the page in the header. */\nexport function TableCheckboxCell({\n label,\n header: headerProp,\n checked,\n indeterminate,\n disabled,\n onCheckedChange,\n className,\n ...props\n}: TableCheckboxCellProps) {\n // A list has no header row, so a header box there renders as a plain cell.\n const { layout } = use(TableContext)\n const header = headerProp && layout === \"table\"\n const box = (\n <Checkbox\n aria-label={label}\n checked={checked}\n indeterminate={indeterminate}\n disabled={disabled}\n className=\"relative z-10 in-data-inactive:opacity-50\"\n onCheckedChange={onCheckedChange}\n />\n )\n const classes = cn(\"pr-0 first:pl-4\", className)\n\n if (header) {\n const { align, priority, ...headProps } = props\n return (\n <th\n role=\"columnheader\"\n scope=\"col\"\n data-slot=\"checkbox\"\n className={tableCellVariants({ align, priority, className: classes })}\n {...headProps}\n >\n {box}\n </th>\n )\n }\n\n return (\n <TableCell data-slot=\"checkbox\" className={classes} {...props}>\n {box}\n </TableCell>\n )\n}\n\ninterface TableGroupHeaderProps extends ComponentProps<\"tr\"> {}\n\n/**\n * A heading row for the run of rows under it: a day of a feed, a workspace of a list. It sticks\n * under the header while its own body is in view, and the next one pushes it out. Opaque, so the\n * rows slide under it.\n */\nexport function TableGroupHeader({ className, children, ...props }: TableGroupHeaderProps) {\n const { layout } = use(TableContext)\n const list = layout === \"list\"\n const Row = list ? \"div\" : \"tr\"\n const Heading = list ? \"div\" : \"th\"\n\n return (\n <Row\n role={list ? \"listitem\" : \"row\"}\n className={cn(\n ROW_GRID_CLASSES,\n // Above the controls of the rows sliding under it (`z-10`), below a sticky header (`z-20`).\n \"sticky top-[calc(var(--table-sticky-top,0px)+var(--table-header-height,0px))] z-15\",\n \"h-7 border-t border-edge-subtle bg-fill-subtle\",\n className,\n )}\n {...props}\n >\n <Heading\n role={list ? \"heading\" : \"rowheader\"}\n aria-level={list ? 3 : undefined}\n scope={list ? undefined : \"rowgroup\"}\n className=\"col-span-full flex items-center px-5 text-left font-medium text-ink-secondary text-xs\"\n >\n {children}\n </Heading>\n </Row>\n )\n}\n\ninterface TableSkeletonRowProps extends VariantProps<typeof tableRowVariants> {\n /** The row's place in the stack, which picks the width of its first line. */\n index?: number\n}\n\n/**\n * A loading row the size of the rows it stands in for, one stand-in per column of the table.\n * Put five in the body on a first load; while a later page loads, keep the old rows and dim them.\n */\nexport function TableSkeletonRow({ size, index = 0 }: TableSkeletonRowProps) {\n const { columns } = use(TableContext)\n const nameWidth = SKELETON_NAME_WIDTHS[index % SKELETON_NAME_WIDTHS.length]\n // The first column that draws a stand-in, past a leading checkbox.\n const nameColumn = columns.findIndex(column => column.skeleton !== false)\n\n return (\n <TableRow size={size} aria-hidden>\n {columns.map((column, position) => (\n <TableCell\n // oxlint-disable-next-line react/no-array-index-key\n key={position}\n align={column.align}\n priority={column.priority}\n className=\"gap-2\"\n >\n {column.skeleton === false ? null : position === nameColumn && size === \"identity\" ? (\n <>\n <Skeleton className=\"size-7 shrink-0 rounded-md\" />\n <span className=\"flex flex-col gap-1.5\">\n <Skeleton className={cn(\"h-3\", nameWidth)} />\n <Skeleton className=\"h-2.5 w-24\" />\n </span>\n </>\n ) : (\n <Skeleton className={cn(\"h-3\", position === nameColumn ? nameWidth : \"w-16\")} />\n )}\n </TableCell>\n ))}\n </TableRow>\n )\n}\n\ninterface TableMessageProps {\n /**\n * `empty`: nothing exists yet, with the create action. `filtered`: nothing matches, with a way\n * to clear the filters. `error`: the load failed, with a retry.\n */\n kind: \"empty\" | \"filtered\" | \"error\"\n /** Required for `empty`; `filtered` and `error` draw a filter and an alert by default. */\n icon?: ReactNode\n title: ReactNode\n description?: ReactNode\n /** The message's button. Left out, an `error` with `onRetry` draws the retry button. */\n action?: ReactNode\n /** Loads the rows again, from the \"Try again\" button of an `error`. */\n onRetry?: () => void\n /** The retry button's label. */\n retryLabel?: ReactNode\n}\n\n/**\n * Stands in for the rows: the small empty state across every column, under the header, which\n * keeps its line. Put it inside `TableBody`.\n */\nexport function TableMessage({\n kind,\n icon,\n title,\n description,\n action,\n onRetry,\n retryLabel = \"Try again\",\n}: TableMessageProps) {\n const { layout } = use(TableContext)\n const list = layout === \"list\"\n const Row = list ? \"div\" : \"tr\"\n const Cell = list ? \"div\" : \"td\"\n const retry = kind === \"error\" && onRetry && (\n <Button variant=\"secondary\" size=\"sm\" prefix={<RefreshIcon />} onClick={onRetry}>\n {retryLabel}\n </Button>\n )\n\n return (\n <Row\n role={list ? \"listitem\" : \"row\"}\n data-kind={kind}\n className={cn(ROW_GRID_CLASSES, \"border-t border-edge-subtle\")}\n >\n <Cell role={list ? undefined : \"cell\"} className=\"col-span-full py-5\">\n <EmptyState\n size=\"sm\"\n role={kind === \"error\" ? \"alert\" : undefined}\n icon={icon ?? (kind === \"empty\" ? undefined : MESSAGE_ICONS[kind])}\n title={title}\n description={description}\n action={action ?? retry}\n />\n </Cell>\n </Row>\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;AA0DA,MAAM,eAAe,cAAiC;CAAE,QAAQ;CAAS,SAAS,CAAC;AA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;EAExE,GAhBJ,QAgBI,CACZ;CACO,CAAA;AAEd;;;;;AAwBA,SAAgB,aAAa,EAC3B,MACA,MACA,OACA,aACA,QACA,SACA,aAAa,eACO;CACpB,MAAM,EAAE,WAAW,IAAI,YAAY;CACnC,MAAM,OAAO,WAAW;CACxB,MAAM,MAAM,OAAO,QAAQ;CAC3B,MAAM,OAAO,OAAO,QAAQ;CAC5B,MAAM,QAAQ,SAAS,WAAW,WAChC,oBAAC,QAAD;EAAQ,SAAQ;EAAY,MAAK;EAAK,QAAQ,oBAAC,aAAD,CAAc,CAAA;EAAG,SAAS;EACrE,UAAA;CACK,CAAA;CAGV,OACE,oBAAC,KAAD;EACE,MAAM,OAAO,aAAa;EAC1B,aAAW;EACX,WAAW,GAAG,kBAAkB,6BAA6B;EAE7D,UAAA,oBAAC,MAAD;GAAM,MAAM,OAAO,KAAA,IAAY;GAAQ,WAAU;GAC/C,UAAA,oBAAC,YAAD;IACE,MAAK;IACL,MAAM,SAAS,UAAU,UAAU,KAAA;IACnC,MAAM,SAAS,SAAS,UAAU,KAAA,IAAY,cAAc;IACrD;IACM;IACb,QAAQ,UAAU;GACnB,CAAA;EACG,CAAA;CACH,CAAA;AAET"}
@@ -1,5 +1,6 @@
1
- import { segmentedVariants } from "../lib/segmented.js";
1
+ import { SegmentedStyle, segmentedVariants } from "../lib/segmented.js";
2
2
  import { VariantProps } from "../lib/variants.js";
3
+ import { ComponentProps } from "react";
3
4
  import { Tabs as Tabs$1 } from "@base-ui/react/tabs";
4
5
  /**
5
6
  * Tabs that switch a panel: each `TabsTrigger` shows its `TabsPanel`, and a screen reader
@@ -12,7 +13,24 @@ declare const Tabs: import("react").ForwardRefExoticComponent<Omit<import("@base
12
13
  * `value` of its `TabsTrigger`.
13
14
  */
14
15
  declare const TabsPanel: import("react").ForwardRefExoticComponent<Omit<import("@base-ui/react").TabsPanelProps, "ref"> & import("react").RefAttributes<HTMLDivElement>>;
15
- type TabsListProps = Tabs$1.List.Props & VariantProps<typeof segmentedVariants>;
16
+ type TabsVariant = SegmentedStyle["variant"] | "underline";
17
+ type TabsListProps = Tabs$1.List.Props & Omit<VariantProps<typeof segmentedVariants>, "variant"> & {
18
+ /** `underline` for the view tabs above a table. */
19
+ variant?: TabsVariant;
20
+ };
16
21
  declare function TabsList({ className, children, variant, size, ...props }: TabsListProps): import("react").JSX.Element;
17
22
  declare const TabsTrigger: import("react").MemoExoticComponent<({ className, ...props }: Tabs$1.Tab.Props) => import("react").JSX.Element>;
18
- export { Tabs, TabsList, TabsPanel, TabsTrigger };
23
+ declare const tabsCountVariants: import("tailwind-variants").TVReturnType<{
24
+ tone: {
25
+ muted: string;
26
+ warning: string;
27
+ danger: string;
28
+ };
29
+ }, undefined, "inline-flex h-4.5 items-center rounded-full px-1.5 font-medium text-2xs tabular-nums", undefined, undefined, undefined>;
30
+ type TabsCountProps = ComponentProps<"span"> & VariantProps<typeof tabsCountVariants>;
31
+ /**
32
+ * The row count after a view tab's label, formatted by the caller. `warning` or `danger` marks
33
+ * a count that needs attention (Needs review 3, Reported 2).
34
+ */
35
+ declare function TabsCount({ tone, className, ...props }: TabsCountProps): import("react").JSX.Element;
36
+ export { Tabs, TabsCount, TabsList, TabsPanel, TabsTrigger };
@@ -1,8 +1,9 @@
1
1
  "use client";
2
+ import { interactiveVariants } from "../lib/interactive.js";
2
3
  import { segmentedVariants } from "../lib/segmented.js";
3
- import { cn } from "../lib/variants.js";
4
+ import { cn, variants } from "../lib/variants.js";
4
5
  import { jsx, jsxs } from "react/jsx-runtime";
5
- import { createContext, memo, use } from "react";
6
+ import { createContext, memo, use, useEffect, useRef } from "react";
6
7
  import { Tabs as Tabs$1 } from "@base-ui/react/tabs";
7
8
  // src/components/tabs.tsx
8
9
  /**
@@ -21,27 +22,59 @@ const TabsVariantContext = createContext({
21
22
  size: "md"
22
23
  });
23
24
  /**
25
+ * The view tabs above a table: a row of labels on a hairline, the chosen one in ink over a 2px
26
+ * ink underline that slides to it. Each label may carry a `TabsCount`. The size does not apply:
27
+ * every tab is 36px, so the row reads as part of the page rather than a control. A row wider
28
+ * than its box scrolls sideways rather than wrapping.
29
+ */
30
+ const UNDERLINE_CLASSES = {
31
+ root: "relative flex items-center gap-5 overflow-x-auto border-b py-px [scrollbar-width:none]",
32
+ indicator: [
33
+ "absolute bottom-0 left-0 h-0.5 bg-ink",
34
+ "w-(--active-tab-width) translate-x-(--active-tab-left)",
35
+ "transition-[translate,width] duration-200 ease-out-expo"
36
+ ].join(" "),
37
+ item: cn(interactiveVariants({ interactive: false }), "relative inline-flex h-9 shrink-0 items-center gap-1.5 whitespace-nowrap font-medium text-control text-ink-secondary", "hover:text-ink data-active:text-ink")
38
+ };
39
+ /**
24
40
  * Sliding highlight that tracks the active tab via Base UI's --active-tab-* CSS variables.
25
41
  * Rendered automatically by TabsList, so every tab group shares one pill.
26
42
  */
27
43
  function TabsIndicator({ className, ...props }) {
28
44
  const { variant, size } = use(TabsVariantContext);
29
45
  return /* @__PURE__ */ jsx(Tabs$1.Indicator, {
30
- className: cn(segmentedVariants({
46
+ className: cn(variant === "underline" ? UNDERLINE_CLASSES.indicator : [segmentedVariants({
31
47
  variant,
32
48
  size
33
- }).indicator(), "h-(--active-tab-height) w-(--active-tab-width) translate-x-(--active-tab-left) translate-y-(--active-tab-top)", className),
49
+ }).indicator(), "h-(--active-tab-height) w-(--active-tab-width) translate-x-(--active-tab-left) translate-y-(--active-tab-top)"], className),
34
50
  ...props
35
51
  });
36
52
  }
37
53
  function TabsList({ className, children, variant = "segmented", size = "md", ...props }) {
54
+ const listRef = useRef(null);
55
+ useEffect(() => {
56
+ const list = listRef.current;
57
+ if (variant !== "underline" || !list) return;
58
+ function reveal() {
59
+ const active = list?.querySelector("[data-active]");
60
+ if (!list || !active) return;
61
+ const end = active.offsetLeft + active.offsetWidth;
62
+ if (end > list.scrollLeft + list.clientWidth) list.scrollLeft = end - list.clientWidth;
63
+ }
64
+ reveal();
65
+ if (typeof ResizeObserver === "undefined") return;
66
+ const observer = new ResizeObserver(reveal);
67
+ for (const tab of list.children) observer.observe(tab);
68
+ return () => observer.disconnect();
69
+ }, [variant]);
38
70
  return /* @__PURE__ */ jsx(TabsVariantContext, {
39
71
  value: {
40
72
  variant,
41
73
  size
42
74
  },
43
75
  children: /* @__PURE__ */ jsxs(Tabs$1.List, {
44
- className: cn(segmentedVariants({
76
+ ref: listRef,
77
+ className: cn(variant === "underline" ? UNDERLINE_CLASSES.root : segmentedVariants({
45
78
  variant,
46
79
  size
47
80
  }).root(), className),
@@ -53,13 +86,35 @@ function TabsList({ className, children, variant = "segmented", size = "md", ...
53
86
  const TabsTrigger = memo(function TabsTrigger({ className, ...props }) {
54
87
  const { variant, size } = use(TabsVariantContext);
55
88
  return /* @__PURE__ */ jsx(Tabs$1.Tab, {
56
- className: cn(segmentedVariants({
89
+ className: cn(variant === "underline" ? UNDERLINE_CLASSES.item : [segmentedVariants({
57
90
  variant,
58
91
  size
59
- }).item(), "not-disabled:cursor-pointer disabled:opacity-50 data-active:text-ink", className),
92
+ }).item(), "data-active:text-ink"], "not-disabled:cursor-pointer disabled:opacity-50", className),
60
93
  ...props
61
94
  });
62
95
  });
63
- export { Tabs, TabsList, TabsPanel, TabsTrigger };
96
+ const tabsCountVariants = variants({
97
+ base: "inline-flex h-4.5 items-center rounded-full px-1.5 font-medium text-2xs tabular-nums",
98
+ variants: { tone: {
99
+ muted: "bg-fill text-ink-muted",
100
+ warning: "bg-warning-subtle text-warning-ink",
101
+ danger: "bg-danger-subtle text-danger-ink"
102
+ } },
103
+ defaultVariants: { tone: "muted" }
104
+ });
105
+ /**
106
+ * The row count after a view tab's label, formatted by the caller. `warning` or `danger` marks
107
+ * a count that needs attention (Needs review 3, Reported 2).
108
+ */
109
+ function TabsCount({ tone, className, ...props }) {
110
+ return /* @__PURE__ */ jsx("span", {
111
+ className: tabsCountVariants({
112
+ tone,
113
+ className
114
+ }),
115
+ ...props
116
+ });
117
+ }
118
+ export { Tabs, TabsCount, TabsList, TabsPanel, TabsTrigger };
64
119
 
65
120
  //# sourceMappingURL=tabs.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"tabs.js","names":["TabsPrimitive"],"sources":["../../src/components/tabs.tsx"],"sourcesContent":["\"use client\"\n\nimport { Tabs as TabsPrimitive } from \"@base-ui/react/tabs\"\nimport { createContext, memo, use } from \"react\"\nimport { type SegmentedStyle, segmentedVariants } from \"../lib/segmented\"\nimport { cn, type VariantProps } from \"../lib/variants\"\n\n/**\n * Tabs that switch a panel: each `TabsTrigger` shows its `TabsPanel`, and a screen reader\n * announces the pair. A row that picks a value and shows nothing of its own is a\n * `SegmentedControl`.\n */\nconst Tabs = TabsPrimitive.Root\n\n/**\n * The content of one tab, rendered while its trigger is active and labelled by it. Give it the\n * `value` of its `TabsTrigger`.\n */\nconst TabsPanel = TabsPrimitive.Panel\n\n// The parts below merge `className` outside the variants call, unlike everywhere else: Base UI\n// types it as a function of the part's own state too, which `variants` cannot take.\n\nconst TabsVariantContext = createContext<SegmentedStyle>({\n variant: \"segmented\",\n size: \"md\",\n})\n\n/**\n * Sliding highlight that tracks the active tab via Base UI's --active-tab-* CSS variables.\n * Rendered automatically by TabsList, so every tab group shares one pill.\n */\nfunction TabsIndicator({ className, ...props }: TabsPrimitive.Indicator.Props) {\n const { variant, size } = use(TabsVariantContext)\n\n return (\n <TabsPrimitive.Indicator\n className={cn(\n segmentedVariants({ variant, size }).indicator(),\n \"h-(--active-tab-height) w-(--active-tab-width) translate-x-(--active-tab-left) translate-y-(--active-tab-top)\",\n className,\n )}\n {...props}\n />\n )\n}\n\ntype TabsListProps = TabsPrimitive.List.Props & VariantProps<typeof segmentedVariants>\n\nfunction TabsList({\n className,\n children,\n variant = \"segmented\",\n size = \"md\",\n ...props\n}: TabsListProps) {\n return (\n <TabsVariantContext value={{ variant, size }}>\n <TabsPrimitive.List\n className={cn(segmentedVariants({ variant, size }).root(), className)}\n {...props}\n >\n <TabsIndicator />\n {children}\n </TabsPrimitive.List>\n </TabsVariantContext>\n )\n}\n\n// Memoised: a tab row re-renders with its card, and its triggers rarely change with it.\nconst TabsTrigger = memo(function TabsTrigger({ className, ...props }: TabsPrimitive.Tab.Props) {\n const { variant, size } = use(TabsVariantContext)\n\n return (\n <TabsPrimitive.Tab\n className={cn(\n segmentedVariants({ variant, size }).item(),\n \"not-disabled:cursor-pointer disabled:opacity-50 data-active:text-ink\",\n className,\n )}\n {...props}\n />\n )\n})\n\nexport { Tabs, TabsList, TabsPanel, TabsTrigger }\n"],"mappings":";;;;;;;;;;;;AAYA,MAAM,OAAOA,OAAc;;;;;AAM3B,MAAM,YAAYA,OAAc;AAKhC,MAAM,qBAAqB,cAA8B;CACvD,SAAS;CACT,MAAM;AACR,CAAC;;;;;AAMD,SAAS,cAAc,EAAE,WAAW,GAAG,SAAwC;CAC7E,MAAM,EAAE,SAAS,SAAS,IAAI,kBAAkB;CAEhD,OACE,oBAACA,OAAc,WAAf;EACE,WAAW,GACT,kBAAkB;GAAE;GAAS;EAAK,CAAC,CAAC,CAAC,UAAU,GAC/C,iHACA,SACF;EACA,GAAI;CACL,CAAA;AAEL;AAIA,SAAS,SAAS,EAChB,WACA,UACA,UAAU,aACV,OAAO,MACP,GAAG,SACa;CAChB,OACE,oBAAC,oBAAD;EAAoB,OAAO;GAAE;GAAS;EAAK;EACzC,UAAA,qBAACA,OAAc,MAAf;GACE,WAAW,GAAG,kBAAkB;IAAE;IAAS;GAAK,CAAC,CAAC,CAAC,KAAK,GAAG,SAAS;GACpE,GAAI;GAFN,UAAA,CAIE,oBAAC,eAAD,CAAgB,CAAA,GACf,QACiB;;CACF,CAAA;AAExB;AAGA,MAAM,cAAc,KAAK,SAAS,YAAY,EAAE,WAAW,GAAG,SAAkC;CAC9F,MAAM,EAAE,SAAS,SAAS,IAAI,kBAAkB;CAEhD,OACE,oBAACA,OAAc,KAAf;EACE,WAAW,GACT,kBAAkB;GAAE;GAAS;EAAK,CAAC,CAAC,CAAC,KAAK,GAC1C,wEACA,SACF;EACA,GAAI;CACL,CAAA;AAEL,CAAC"}
1
+ {"version":3,"file":"tabs.js","names":["TabsPrimitive"],"sources":["../../src/components/tabs.tsx"],"sourcesContent":["\"use client\"\n\nimport { Tabs as TabsPrimitive } from \"@base-ui/react/tabs\"\nimport { type ComponentProps, createContext, memo, use, useEffect, useRef } from \"react\"\nimport { interactiveVariants } from \"../lib/interactive\"\nimport { type SegmentedStyle, segmentedVariants } from \"../lib/segmented\"\nimport { cn, variants, type VariantProps } from \"../lib/variants\"\n\n/**\n * Tabs that switch a panel: each `TabsTrigger` shows its `TabsPanel`, and a screen reader\n * announces the pair. A row that picks a value and shows nothing of its own is a\n * `SegmentedControl`.\n */\nconst Tabs = TabsPrimitive.Root\n\n/**\n * The content of one tab, rendered while its trigger is active and labelled by it. Give it the\n * `value` of its `TabsTrigger`.\n */\nconst TabsPanel = TabsPrimitive.Panel\n\n// The parts below merge `className` outside the variants call, unlike everywhere else: Base UI\n// types it as a function of the part's own state too, which `variants` cannot take.\n\ntype TabsVariant = SegmentedStyle[\"variant\"] | \"underline\"\n\ninterface TabsStyle {\n variant: TabsVariant\n size: SegmentedStyle[\"size\"]\n}\n\nconst TabsVariantContext = createContext<TabsStyle>({\n variant: \"segmented\",\n size: \"md\",\n})\n\n/**\n * The view tabs above a table: a row of labels on a hairline, the chosen one in ink over a 2px\n * ink underline that slides to it. Each label may carry a `TabsCount`. The size does not apply:\n * every tab is 36px, so the row reads as part of the page rather than a control. A row wider\n * than its box scrolls sideways rather than wrapping.\n */\nconst UNDERLINE_CLASSES = {\n // A row wider than its box (a phone) scrolls sideways, with no bar under the hairline. The\n // pixel above and below keeps the focus ring, drawn a pixel outside a tab, out of the clip.\n root: \"relative flex items-center gap-5 overflow-x-auto border-b py-px [scrollbar-width:none]\",\n indicator: [\n \"absolute bottom-0 left-0 h-0.5 bg-ink\",\n \"w-(--active-tab-width) translate-x-(--active-tab-left)\",\n \"transition-[translate,width] duration-200 ease-out-expo\",\n ].join(\" \"),\n item: cn(\n interactiveVariants({ interactive: false }),\n \"relative inline-flex h-9 shrink-0 items-center gap-1.5 whitespace-nowrap font-medium text-control text-ink-secondary\",\n \"hover:text-ink data-active:text-ink\",\n ),\n}\n\n/**\n * Sliding highlight that tracks the active tab via Base UI's --active-tab-* CSS variables.\n * Rendered automatically by TabsList, so every tab group shares one pill.\n */\nfunction TabsIndicator({ className, ...props }: TabsPrimitive.Indicator.Props) {\n const { variant, size } = use(TabsVariantContext)\n\n return (\n <TabsPrimitive.Indicator\n className={cn(\n variant === \"underline\"\n ? UNDERLINE_CLASSES.indicator\n : [\n segmentedVariants({ variant, size }).indicator(),\n \"h-(--active-tab-height) w-(--active-tab-width) translate-x-(--active-tab-left) translate-y-(--active-tab-top)\",\n ],\n className,\n )}\n {...props}\n />\n )\n}\n\ntype TabsListProps = TabsPrimitive.List.Props &\n Omit<VariantProps<typeof segmentedVariants>, \"variant\"> & {\n /** `underline` for the view tabs above a table. */\n variant?: TabsVariant\n }\n\nfunction TabsList({\n className,\n children,\n variant = \"segmented\",\n size = \"md\",\n ...props\n}: TabsListProps) {\n const listRef = useRef<HTMLDivElement>(null)\n\n // A row that scrolls keeps its active tab in view, for a link straight to a view far along\n // it. It checks again whenever a tab changes size (a count arriving widens every label), and\n // never when the reader scrolls the row themselves.\n useEffect(() => {\n const list = listRef.current\n if (variant !== \"underline\" || !list) return\n\n function reveal() {\n const active = list?.querySelector<HTMLElement>(\"[data-active]\")\n if (!list || !active) return\n const end = active.offsetLeft + active.offsetWidth\n if (end > list.scrollLeft + list.clientWidth) list.scrollLeft = end - list.clientWidth\n }\n\n reveal()\n if (typeof ResizeObserver === \"undefined\") return\n const observer = new ResizeObserver(reveal)\n for (const tab of list.children) observer.observe(tab)\n return () => observer.disconnect()\n }, [variant])\n\n return (\n <TabsVariantContext value={{ variant, size }}>\n <TabsPrimitive.List\n ref={listRef}\n className={cn(\n variant === \"underline\"\n ? UNDERLINE_CLASSES.root\n : segmentedVariants({ variant, size }).root(),\n className,\n )}\n {...props}\n >\n <TabsIndicator />\n {children}\n </TabsPrimitive.List>\n </TabsVariantContext>\n )\n}\n\n// Memoised: a tab row re-renders with its card, and its triggers rarely change with it.\nconst TabsTrigger = memo(function TabsTrigger({ className, ...props }: TabsPrimitive.Tab.Props) {\n const { variant, size } = use(TabsVariantContext)\n\n return (\n <TabsPrimitive.Tab\n className={cn(\n variant === \"underline\"\n ? UNDERLINE_CLASSES.item\n : [segmentedVariants({ variant, size }).item(), \"data-active:text-ink\"],\n \"not-disabled:cursor-pointer disabled:opacity-50\",\n className,\n )}\n {...props}\n />\n )\n})\n\nconst tabsCountVariants = variants({\n base: \"inline-flex h-4.5 items-center rounded-full px-1.5 font-medium text-2xs tabular-nums\",\n\n variants: {\n tone: {\n muted: \"bg-fill text-ink-muted\",\n warning: \"bg-warning-subtle text-warning-ink\",\n danger: \"bg-danger-subtle text-danger-ink\",\n },\n },\n\n defaultVariants: {\n tone: \"muted\",\n },\n})\n\ntype TabsCountProps = ComponentProps<\"span\"> & VariantProps<typeof tabsCountVariants>\n\n/**\n * The row count after a view tab's label, formatted by the caller. `warning` or `danger` marks\n * a count that needs attention (Needs review 3, Reported 2).\n */\nfunction TabsCount({ tone, className, ...props }: TabsCountProps) {\n return <span className={tabsCountVariants({ tone, className })} {...props} />\n}\n\nexport { Tabs, TabsCount, TabsList, TabsPanel, TabsTrigger }\n"],"mappings":";;;;;;;;;;;;;AAaA,MAAM,OAAOA,OAAc;;;;;AAM3B,MAAM,YAAYA,OAAc;AAYhC,MAAM,qBAAqB,cAAyB;CAClD,SAAS;CACT,MAAM;AACR,CAAC;;;;;;;AAQD,MAAM,oBAAoB;CAGxB,MAAM;CACN,WAAW;EACT;EACA;EACA;CACF,CAAC,CAAC,KAAK,GAAG;CACV,MAAM,GACJ,oBAAoB,EAAE,aAAa,MAAM,CAAC,GAC1C,wHACA,qCACF;AACF;;;;;AAMA,SAAS,cAAc,EAAE,WAAW,GAAG,SAAwC;CAC7E,MAAM,EAAE,SAAS,SA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,CAAC,kBAAkB;GAAE;GAAS;EAAK,CAAC,CAAC,CAAC,KAAK,GAAG,sBAAsB,GACxE,mDACA,SACF;EACA,GAAI;CACL,CAAA;AAEL,CAAC;AAED,MAAM,oBAAoB,SAAS;CACjC,MAAM;CAEN,UAAU,EACR,MAAM;EACJ,OAAO;EACP,SAAS;EACT,QAAQ;CACV,EACF;CAEA,iBAAiB,EACf,MAAM,QACR;AACF,CAAC;;;;;AAQD,SAAS,UAAU,EAAE,MAAM,WAAW,GAAG,SAAyB;CAChE,OAAO,oBAAC,QAAD;EAAM,WAAW,kBAAkB;GAAE;GAAM;EAAU,CAAC;EAAG,GAAI;CAAQ,CAAA;AAC9E"}
@@ -0,0 +1,87 @@
1
+ import { TableColumnPriority } from "../components/table.js";
2
+ import { ColumnVisibilityState, RowData } from "@tanstack/react-table";
3
+ /**
4
+ * The model behind `DataTable`: its react-table features, the meta a column carries, and the
5
+ * state the app owns. The package never reads the URL: an app keeps `DataTableState` in its
6
+ * router's search params (TanStack Router, nuqs) and hands it back on every change.
7
+ */
8
+ /** What a column tells the table about its own head and cells. */
9
+ export interface DataTableColumnMeta {
10
+ /** Figures read from the end. */
11
+ align?: "start" | "end";
12
+ /** The column's grid track: `minmax(0,1fr)` (the default) for the name, `6rem` for a figure. */
13
+ width?: string;
14
+ /**
15
+ * Where the column gives way as the table narrows: `medium` below 672px, `low` below 896px,
16
+ * `lowest` below 1152px.
17
+ */
18
+ priority?: TableColumnPriority;
19
+ /**
20
+ * Turns the column's name into a button that sorts by it. The first click sorts ascending, or
21
+ * descending for `"descending"` (a figure, a date read newest first); the next flips it.
22
+ */
23
+ sortable?: boolean | "ascending" | "descending";
24
+ /** Whether a skeleton row draws a stand-in here. Off for an actions column. */
25
+ skeleton?: boolean;
26
+ /** The column's name in the column picker, for a column whose header is not a string. */
27
+ label?: string;
28
+ }
29
+ /** The react-table features every `DataTable` registers. */
30
+ export declare const DATA_TABLE_FEATURES: {
31
+ rowSortingFeature: import("@tanstack/react-table").TableFeature;
32
+ rowSelectionFeature: import("@tanstack/react-table").TableFeature;
33
+ columnVisibilityFeature: import("@tanstack/react-table").TableFeature;
34
+ columnMeta: DataTableColumnMeta;
35
+ };
36
+ export type DataTableFeatures = typeof DATA_TABLE_FEATURES;
37
+ /**
38
+ * The column helper for a `DataTable` of `TData` rows. A column's `cell` returns one of the
39
+ * table's cell parts (`TableCell`, `TableIdentityCell`, `TableNumberCell`…), which take the
40
+ * column's `align` and `priority` from its meta.
41
+ */
42
+ export declare function createDataTableColumnHelper<TData extends RowData>(): import("@tanstack/react-table").ColumnHelper<{
43
+ rowSortingFeature: import("@tanstack/react-table").TableFeature;
44
+ rowSelectionFeature: import("@tanstack/react-table").TableFeature;
45
+ columnVisibilityFeature: import("@tanstack/react-table").TableFeature;
46
+ columnMeta: DataTableColumnMeta;
47
+ }, TData>;
48
+ export interface DataTableSort {
49
+ /** The column's id. */
50
+ id: string;
51
+ desc: boolean;
52
+ }
53
+ /** What a table shows, owned by the app. */
54
+ export interface DataTableState {
55
+ /** 1-based. Read by a paged table, left out by one that loads as it scrolls. */
56
+ page?: number;
57
+ /** Rows on a page. Read by a paged table. */
58
+ perPage?: number;
59
+ /** Left out while the server's own order applies, so no column shows an arrow. */
60
+ sort?: DataTableSort;
61
+ search?: string;
62
+ /** The chosen values of each filtered field, by field. */
63
+ filters?: Record<string, string[]>;
64
+ }
65
+ /** The page size of a paged table whose state names none. */
66
+ export declare const DEFAULT_PER_PAGE = 25;
67
+ /**
68
+ * The state after a change, under the paging rules: a new sort, search, filter or page size
69
+ * starts over on page 1, since the page the reader was on no longer holds the same rows.
70
+ */
71
+ export declare function changeDataTableState(state: DataTableState, change: Partial<DataTableState>): DataTableState;
72
+ /** How many pages `total` rows fill. An empty table still has its one page. */
73
+ export declare function getPageCount(total: number, perPage: number): number;
74
+ /**
75
+ * The page a table shows for the one its state asks for: page 1 for a page before it, the last
76
+ * page for one past the end (a stale link, rows deleted since).
77
+ */
78
+ export declare function clampPage(page: number, pageCount: number): number;
79
+ /**
80
+ * A key that changes whenever the rows a table holds stop being the same set: a new page, sort,
81
+ * search or filter. A selection covers one such set.
82
+ */
83
+ export declare function formatRowSetKey({ page, perPage, sort, search, filters }: DataTableState): string;
84
+ /** The columns the reader hid on this table, saved in this browser. Empty when none are. */
85
+ export declare function readColumnVisibility(storageKey: string): ColumnVisibilityState;
86
+ /** Saves the columns the reader hid. A browser that blocks storage keeps them for the visit. */
87
+ export declare function writeColumnVisibility(storageKey: string, visibility: ColumnVisibilityState): void;
@@ -0,0 +1,92 @@
1
+ import { columnVisibilityFeature, createColumnHelper, metaHelper, rowSelectionFeature, rowSortingFeature, tableFeatures } from "@tanstack/react-table";
2
+ // src/lib/data-table-state.ts
3
+ /** The react-table features every `DataTable` registers. */
4
+ const DATA_TABLE_FEATURES = tableFeatures({
5
+ rowSortingFeature,
6
+ rowSelectionFeature,
7
+ columnVisibilityFeature,
8
+ columnMeta: metaHelper()
9
+ });
10
+ /**
11
+ * The column helper for a `DataTable` of `TData` rows. A column's `cell` returns one of the
12
+ * table's cell parts (`TableCell`, `TableIdentityCell`, `TableNumberCell`…), which take the
13
+ * column's `align` and `priority` from its meta.
14
+ */
15
+ function createDataTableColumnHelper() {
16
+ return createColumnHelper();
17
+ }
18
+ /** The page size of a paged table whose state names none. */
19
+ const DEFAULT_PER_PAGE = 25;
20
+ function isSameSort(one, other) {
21
+ return one?.id === other?.id && one?.desc === other?.desc;
22
+ }
23
+ function isSameFilters(one, other) {
24
+ return [.../* @__PURE__ */ new Set([...Object.keys(one ?? {}), ...Object.keys(other ?? {})])].every((key) => {
25
+ const left = one?.[key] ?? [];
26
+ const right = other?.[key] ?? [];
27
+ return left.length === right.length && left.every((value) => right.includes(value));
28
+ });
29
+ }
30
+ /**
31
+ * The state after a change, under the paging rules: a new sort, search, filter or page size
32
+ * starts over on page 1, since the page the reader was on no longer holds the same rows.
33
+ */
34
+ function changeDataTableState(state, change) {
35
+ const next = {
36
+ ...state,
37
+ ...change
38
+ };
39
+ return "sort" in change && !isSameSort(state.sort, change.sort) || "search" in change && (state.search ?? "") !== (change.search ?? "") || "filters" in change && !isSameFilters(state.filters, change.filters) || "perPage" in change && state.perPage !== change.perPage ? {
40
+ ...next,
41
+ page: 1
42
+ } : next;
43
+ }
44
+ /** How many pages `total` rows fill. An empty table still has its one page. */
45
+ function getPageCount(total, perPage) {
46
+ return Math.max(1, Math.ceil(total / perPage));
47
+ }
48
+ /**
49
+ * The page a table shows for the one its state asks for: page 1 for a page before it, the last
50
+ * page for one past the end (a stale link, rows deleted since).
51
+ */
52
+ function clampPage(page, pageCount) {
53
+ return Math.min(Math.max(1, Math.floor(page)), pageCount);
54
+ }
55
+ /**
56
+ * A key that changes whenever the rows a table holds stop being the same set: a new page, sort,
57
+ * search or filter. A selection covers one such set.
58
+ */
59
+ function formatRowSetKey({ page, perPage, sort, search, filters }) {
60
+ const filterKey = Object.entries(filters ?? {}).filter(([, values]) => values.length > 0).map(([field, values]) => [field, values.toSorted()]).toSorted(([one], [other]) => String(one).localeCompare(String(other)));
61
+ return JSON.stringify([
62
+ page,
63
+ perPage,
64
+ sort?.id,
65
+ sort?.desc,
66
+ search ?? "",
67
+ filterKey
68
+ ]);
69
+ }
70
+ function formatStorageKey(storageKey) {
71
+ return `underpin:data-table:${storageKey}:columns`;
72
+ }
73
+ /** The columns the reader hid on this table, saved in this browser. Empty when none are. */
74
+ function readColumnVisibility(storageKey) {
75
+ try {
76
+ const stored = JSON.parse(localStorage.getItem(formatStorageKey(storageKey)) ?? "{}");
77
+ if (typeof stored !== "object" || stored === null || Array.isArray(stored)) return {};
78
+ return Object.fromEntries(Object.entries(stored).filter((entry) => entry[1] === false));
79
+ } catch {
80
+ return {};
81
+ }
82
+ }
83
+ /** Saves the columns the reader hid. A browser that blocks storage keeps them for the visit. */
84
+ function writeColumnVisibility(storageKey, visibility) {
85
+ const hidden = Object.fromEntries(Object.entries(visibility).filter(([, shown]) => !shown));
86
+ try {
87
+ localStorage.setItem(formatStorageKey(storageKey), JSON.stringify(hidden));
88
+ } catch {}
89
+ }
90
+ export { DATA_TABLE_FEATURES, DEFAULT_PER_PAGE, changeDataTableState, clampPage, createDataTableColumnHelper, formatRowSetKey, getPageCount, readColumnVisibility, writeColumnVisibility };
91
+
92
+ //# sourceMappingURL=data-table-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-table-state.js","names":[],"sources":["../../src/lib/data-table-state.ts"],"sourcesContent":["import {\n type ColumnVisibilityState,\n columnVisibilityFeature,\n createColumnHelper,\n metaHelper,\n type RowData,\n rowSelectionFeature,\n rowSortingFeature,\n tableFeatures,\n} from \"@tanstack/react-table\"\nimport type { TableColumnPriority } from \"../components/table\"\n\n/**\n * The model behind `DataTable`: its react-table features, the meta a column carries, and the\n * state the app owns. The package never reads the URL: an app keeps `DataTableState` in its\n * router's search params (TanStack Router, nuqs) and hands it back on every change.\n */\n\n/** What a column tells the table about its own head and cells. */\nexport interface DataTableColumnMeta {\n /** Figures read from the end. */\n align?: \"start\" | \"end\"\n /** The column's grid track: `minmax(0,1fr)` (the default) for the name, `6rem` for a figure. */\n width?: string\n /**\n * Where the column gives way as the table narrows: `medium` below 672px, `low` below 896px,\n * `lowest` below 1152px.\n */\n priority?: TableColumnPriority\n /**\n * Turns the column's name into a button that sorts by it. The first click sorts ascending, or\n * descending for `\"descending\"` (a figure, a date read newest first); the next flips it.\n */\n sortable?: boolean | \"ascending\" | \"descending\"\n /** Whether a skeleton row draws a stand-in here. Off for an actions column. */\n skeleton?: boolean\n /** The column's name in the column picker, for a column whose header is not a string. */\n label?: string\n}\n\n/** The react-table features every `DataTable` registers. */\nexport const DATA_TABLE_FEATURES = tableFeatures({\n rowSortingFeature,\n rowSelectionFeature,\n columnVisibilityFeature,\n columnMeta: metaHelper<DataTableColumnMeta>(),\n})\n\nexport type DataTableFeatures = typeof DATA_TABLE_FEATURES\n\n/**\n * The column helper for a `DataTable` of `TData` rows. A column's `cell` returns one of the\n * table's cell parts (`TableCell`, `TableIdentityCell`, `TableNumberCell`…), which take the\n * column's `align` and `priority` from its meta.\n */\nexport function createDataTableColumnHelper<TData extends RowData>() {\n return createColumnHelper<DataTableFeatures, TData>()\n}\n\nexport interface DataTableSort {\n /** The column's id. */\n id: string\n desc: boolean\n}\n\n/** What a table shows, owned by the app. */\nexport interface DataTableState {\n /** 1-based. Read by a paged table, left out by one that loads as it scrolls. */\n page?: number\n /** Rows on a page. Read by a paged table. */\n perPage?: number\n /** Left out while the server's own order applies, so no column shows an arrow. */\n sort?: DataTableSort\n search?: string\n /** The chosen values of each filtered field, by field. */\n filters?: Record<string, string[]>\n}\n\n/** The page size of a paged table whose state names none. */\nexport const DEFAULT_PER_PAGE = 25\n\nfunction isSameSort(one: DataTableSort | undefined, other: DataTableSort | undefined) {\n return one?.id === other?.id && one?.desc === other?.desc\n}\n\nfunction isSameFilters(one: DataTableState[\"filters\"], other: DataTableState[\"filters\"]) {\n const keys = new Set([...Object.keys(one ?? {}), ...Object.keys(other ?? {})])\n\n return [...keys].every(key => {\n const left = one?.[key] ?? []\n const right = other?.[key] ?? []\n return left.length === right.length && left.every(value => right.includes(value))\n })\n}\n\n/**\n * The state after a change, under the paging rules: a new sort, search, filter or page size\n * starts over on page 1, since the page the reader was on no longer holds the same rows.\n */\nexport function changeDataTableState(\n state: DataTableState,\n change: Partial<DataTableState>,\n): DataTableState {\n const next = { ...state, ...change }\n const restarts =\n (\"sort\" in change && !isSameSort(state.sort, change.sort)) ||\n (\"search\" in change && (state.search ?? \"\") !== (change.search ?? \"\")) ||\n (\"filters\" in change && !isSameFilters(state.filters, change.filters)) ||\n (\"perPage\" in change && state.perPage !== change.perPage)\n\n return restarts ? { ...next, page: 1 } : next\n}\n\n/** How many pages `total` rows fill. An empty table still has its one page. */\nexport function getPageCount(total: number, perPage: number) {\n return Math.max(1, Math.ceil(total / perPage))\n}\n\n/**\n * The page a table shows for the one its state asks for: page 1 for a page before it, the last\n * page for one past the end (a stale link, rows deleted since).\n */\nexport function clampPage(page: number, pageCount: number) {\n return Math.min(Math.max(1, Math.floor(page)), pageCount)\n}\n\n/**\n * A key that changes whenever the rows a table holds stop being the same set: a new page, sort,\n * search or filter. A selection covers one such set.\n */\nexport function formatRowSetKey({ page, perPage, sort, search, filters }: DataTableState) {\n // Sorted, so the same filters in another order make the same key, as `isSameFilters` reads them.\n const filterKey = Object.entries(filters ?? {})\n .filter(([, values]) => values.length > 0)\n .map(([field, values]) => [field, values.toSorted()])\n .toSorted(([one], [other]) => String(one).localeCompare(String(other)))\n\n return JSON.stringify([page, perPage, sort?.id, sort?.desc, search ?? \"\", filterKey])\n}\n\nfunction formatStorageKey(storageKey: string) {\n return `underpin:data-table:${storageKey}:columns`\n}\n\n/** The columns the reader hid on this table, saved in this browser. Empty when none are. */\nexport function readColumnVisibility(storageKey: string): ColumnVisibilityState {\n try {\n const stored: unknown = JSON.parse(localStorage.getItem(formatStorageKey(storageKey)) ?? \"{}\")\n if (typeof stored !== \"object\" || stored === null || Array.isArray(stored)) return {}\n\n return Object.fromEntries(\n Object.entries(stored).filter((entry): entry is [string, boolean] => entry[1] === false),\n )\n } catch {\n return {}\n }\n}\n\n/** Saves the columns the reader hid. A browser that blocks storage keeps them for the visit. */\nexport function writeColumnVisibility(storageKey: string, visibility: ColumnVisibilityState) {\n const hidden = Object.fromEntries(Object.entries(visibility).filter(([, shown]) => !shown))\n\n try {\n localStorage.setItem(formatStorageKey(storageKey), JSON.stringify(hidden))\n } catch {}\n}\n"],"mappings":";;;AAyCA,MAAa,sBAAsB,cAAc;CAC/C;CACA;CACA;CACA,YAAY,WAAgC;AAC9C,CAAC;;;;;;AASD,SAAgB,8BAAqD;CACnE,OAAO,mBAA6C;AACtD;;AAsBA,MAAa,mBAAmB;AAEhC,SAAS,WAAW,KAAgC,OAAkC;CACpF,OAAO,KAAK,OAAO,OAAO,MAAM,KAAK,SAAS,OAAO;AACvD;AAEA,SAAS,cAAc,KAAgC,OAAkC;CAGvF,OAAO,CAAC,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UAAU;EAAC;EAAM;EAAS,MAAM;EAAI,MAAM;EAAM,UAAU;EAAI;CAAS,CAAC;AACtF;AAEA,SAAS,iBAAiB,YAAoB;CAC5C,OAAO,uBAAuB,WAAW;AAC3C;;AAGA,SAAgB,qBAAqB,YAA2C;CAC9E,IAAI;EACF,MAAM,SAAkB,KAAK,MAAM,aAAa,QAAQ,iBAAiB,UAAU,CAAC,KAAK,IAAI;EAC7F,IAAI,OAAO,WAAW,YAAY,WAAW,QAAQ,MAAM,QAAQ,MAAM,GAAG,OAAO,CAAC;EAEpF,OAAO,OAAO,YACZ,OAAO,QAAQ,MAAM,CAAC,CAAC,QAAQ,UAAsC,MAAM,OAAO,KAAK,CACzF;CACF,QAAQ;EACN,OAAO,CAAC;CACV;AACF;;AAGA,SAAgB,sBAAsB,YAAoB,YAAmC;CAC3F,MAAM,SAAS,OAAO,YAAY,OAAO,QAAQ,UAAU,CAAC,CAAC,QAAQ,GAAG,WAAW,CAAC,KAAK,CAAC;CAE1F,IAAI;EACF,aAAa,QAAQ,iBAAiB,UAAU,GAAG,KAAK,UAAU,MAAM,CAAC;CAC3E,QAAQ,CAAC;AACX"}
package/lib/icons.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  import { IconComponent } from "./icon.js";
2
2
  export declare const AlertIcon: IconComponent;
3
3
  export declare const AlertCircleIcon: IconComponent;
4
+ export declare const ArrowDownIcon: IconComponent;
5
+ export declare const ArrowUpIcon: IconComponent;
4
6
  export declare const ArrowUpRightIcon: IconComponent;
5
7
  export declare const CalendarIcon: IconComponent;
6
8
  export declare const CancelIcon: IconComponent;
@@ -8,6 +10,8 @@ export declare const CancelCircleIcon: IconComponent;
8
10
  export declare const CheckIcon: IconComponent;
9
11
  export declare const CheckCircleIcon: IconComponent;
10
12
  export declare const ChevronDownIcon: IconComponent;
13
+ export declare const ChevronsLeftIcon: IconComponent;
14
+ export declare const ChevronsRightIcon: IconComponent;
11
15
  export declare const ChevronLeftIcon: IconComponent;
12
16
  export declare const ChevronRightIcon: IconComponent;
13
17
  export declare const ChevronUpIcon: IconComponent;
@@ -15,9 +19,13 @@ export declare const ChevronsUpDownIcon: IconComponent;
15
19
  export declare const ComputerIcon: IconComponent;
16
20
  export declare const CopyIcon: IconComponent;
17
21
  export declare const DashIcon: IconComponent;
22
+ export declare const FilterIcon: IconComponent;
18
23
  export declare const HelpIcon: IconComponent;
19
24
  export declare const InfoIcon: IconComponent;
20
25
  export declare const LoadingIcon: IconComponent;
21
26
  export declare const MoonIcon: IconComponent;
27
+ export declare const MoreIcon: IconComponent;
28
+ export declare const PlusCircleIcon: IconComponent;
29
+ export declare const RefreshIcon: IconComponent;
22
30
  export declare const SearchIcon: IconComponent;
23
31
  export declare const SunIcon: IconComponent;
package/lib/icons.js CHANGED
@@ -1,8 +1,10 @@
1
1
  import { icon } from "./icon.js";
2
- import { Alert02Icon, AlertCircleIcon as AlertCircleIcon$1, ArrowDown01Icon, ArrowLeft01Icon, ArrowRight01Icon, ArrowUp01Icon, ArrowUpRight01Icon, Calendar03Icon, Cancel01Icon, CancelCircleIcon as CancelCircleIcon$1, CheckmarkCircle02Icon, ComputerIcon as ComputerIcon$1, Copy01Icon, HelpCircleIcon, InformationCircleIcon, Loading03Icon, Moon02Icon, Remove01Icon, Search01Icon, Sun03Icon, Tick02Icon, UnfoldMoreIcon } from "@hugeicons/core-free-icons";
2
+ import { Alert02Icon, AlertCircleIcon as AlertCircleIcon$1, ArrowDown01Icon, ArrowDown02Icon, ArrowLeft01Icon, ArrowLeftDoubleIcon, ArrowRight01Icon, ArrowRightDoubleIcon, ArrowUp01Icon, ArrowUp02Icon, ArrowUpRight01Icon, Calendar03Icon, Cancel01Icon, CancelCircleIcon as CancelCircleIcon$1, CheckmarkCircle02Icon, ComputerIcon as ComputerIcon$1, Copy01Icon, HelpCircleIcon, InformationCircleIcon, ListFilterIcon, Loading03Icon, Moon02Icon, MoreHorizontalCircle01Icon, PlusSignCircleIcon, Refresh01Icon, Remove01Icon, Search01Icon, Sun03Icon, Tick02Icon, UnfoldMoreIcon } from "@hugeicons/core-free-icons";
3
3
  // src/lib/icons.tsx
4
4
  const AlertIcon = icon(Alert02Icon, "AlertIcon");
5
5
  const AlertCircleIcon = icon(AlertCircleIcon$1, "AlertCircleIcon");
6
+ const ArrowDownIcon = icon(ArrowDown02Icon, "ArrowDownIcon");
7
+ const ArrowUpIcon = icon(ArrowUp02Icon, "ArrowUpIcon");
6
8
  const ArrowUpRightIcon = icon(ArrowUpRight01Icon, "ArrowUpRightIcon");
7
9
  const CalendarIcon = icon(Calendar03Icon, "CalendarIcon");
8
10
  const CancelIcon = icon(Cancel01Icon, "CancelIcon");
@@ -10,6 +12,8 @@ const CancelCircleIcon = icon(CancelCircleIcon$1, "CancelCircleIcon");
10
12
  const CheckIcon = icon(Tick02Icon, "CheckIcon");
11
13
  const CheckCircleIcon = icon(CheckmarkCircle02Icon, "CheckCircleIcon");
12
14
  const ChevronDownIcon = icon(ArrowDown01Icon, "ChevronDownIcon");
15
+ const ChevronsLeftIcon = icon(ArrowLeftDoubleIcon, "ChevronsLeftIcon");
16
+ const ChevronsRightIcon = icon(ArrowRightDoubleIcon, "ChevronsRightIcon");
13
17
  const ChevronLeftIcon = icon(ArrowLeft01Icon, "ChevronLeftIcon");
14
18
  const ChevronRightIcon = icon(ArrowRight01Icon, "ChevronRightIcon");
15
19
  const ChevronUpIcon = icon(ArrowUp01Icon, "ChevronUpIcon");
@@ -17,12 +21,16 @@ const ChevronsUpDownIcon = icon(UnfoldMoreIcon, "ChevronsUpDownIcon");
17
21
  const ComputerIcon = icon(ComputerIcon$1, "ComputerIcon");
18
22
  const CopyIcon = icon(Copy01Icon, "CopyIcon");
19
23
  const DashIcon = icon(Remove01Icon, "DashIcon");
24
+ const FilterIcon = icon(ListFilterIcon, "FilterIcon");
20
25
  const HelpIcon = icon(HelpCircleIcon, "HelpIcon");
21
26
  const InfoIcon = icon(InformationCircleIcon, "InfoIcon");
22
27
  const LoadingIcon = icon(Loading03Icon, "LoadingIcon");
23
28
  const MoonIcon = icon(Moon02Icon, "MoonIcon");
29
+ const MoreIcon = icon(MoreHorizontalCircle01Icon, "MoreIcon", { fill: "currentColor" });
30
+ const PlusCircleIcon = icon(PlusSignCircleIcon, "PlusCircleIcon");
31
+ const RefreshIcon = icon(Refresh01Icon, "RefreshIcon");
24
32
  const SearchIcon = icon(Search01Icon, "SearchIcon");
25
33
  const SunIcon = icon(Sun03Icon, "SunIcon");
26
- export { AlertCircleIcon, AlertIcon, ArrowUpRightIcon, CalendarIcon, CancelCircleIcon, CancelIcon, CheckCircleIcon, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon, ChevronsUpDownIcon, ComputerIcon, CopyIcon, DashIcon, HelpIcon, InfoIcon, LoadingIcon, MoonIcon, SearchIcon, SunIcon };
34
+ export { AlertCircleIcon, AlertIcon, ArrowDownIcon, ArrowUpIcon, ArrowUpRightIcon, CalendarIcon, CancelCircleIcon, CancelIcon, CheckCircleIcon, CheckIcon, ChevronDownIcon, ChevronLeftIcon, ChevronRightIcon, ChevronUpIcon, ChevronsLeftIcon, ChevronsRightIcon, ChevronsUpDownIcon, ComputerIcon, CopyIcon, DashIcon, FilterIcon, HelpIcon, InfoIcon, LoadingIcon, MoonIcon, MoreIcon, PlusCircleIcon, RefreshIcon, SearchIcon, SunIcon };
27
35
 
28
36
  //# sourceMappingURL=icons.js.map
package/lib/icons.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"icons.js","names":["AlertCircleDef","CancelCircleDef","ComputerDef"],"sources":["../../src/lib/icons.tsx"],"sourcesContent":["import {\n Alert02Icon,\n AlertCircleIcon as AlertCircleDef,\n ArrowDown01Icon,\n ArrowLeft01Icon,\n ArrowRight01Icon,\n ArrowUp01Icon,\n ArrowUpRight01Icon,\n Calendar03Icon,\n Cancel01Icon,\n CancelCircleIcon as CancelCircleDef,\n CheckmarkCircle02Icon,\n ComputerIcon as ComputerDef,\n Copy01Icon,\n HelpCircleIcon,\n InformationCircleIcon,\n Loading03Icon,\n Moon02Icon,\n Remove01Icon,\n Search01Icon,\n Sun03Icon,\n Tick02Icon,\n UnfoldMoreIcon,\n} from \"@hugeicons/core-free-icons\"\nimport { icon } from \"./icon\"\n\n// The handful of structural glyphs the package's own components render. This file lives in\n// `lib/` rather than `components/` so the `\"./*\"` wildcard export, which maps into\n// `components/`, never exposes it.\n\nexport const AlertIcon = icon(Alert02Icon, \"AlertIcon\")\nexport const AlertCircleIcon = icon(AlertCircleDef, \"AlertCircleIcon\")\nexport const ArrowUpRightIcon = icon(ArrowUpRight01Icon, \"ArrowUpRightIcon\")\nexport const CalendarIcon = icon(Calendar03Icon, \"CalendarIcon\")\nexport const CancelIcon = icon(Cancel01Icon, \"CancelIcon\")\nexport const CancelCircleIcon = icon(CancelCircleDef, \"CancelCircleIcon\")\nexport const CheckIcon = icon(Tick02Icon, \"CheckIcon\")\nexport const CheckCircleIcon = icon(CheckmarkCircle02Icon, \"CheckCircleIcon\")\nexport const ChevronDownIcon = icon(ArrowDown01Icon, \"ChevronDownIcon\")\nexport const ChevronLeftIcon = icon(ArrowLeft01Icon, \"ChevronLeftIcon\")\nexport const ChevronRightIcon = icon(ArrowRight01Icon, \"ChevronRightIcon\")\nexport const ChevronUpIcon = icon(ArrowUp01Icon, \"ChevronUpIcon\")\nexport const ChevronsUpDownIcon = icon(UnfoldMoreIcon, \"ChevronsUpDownIcon\")\nexport const ComputerIcon = icon(ComputerDef, \"ComputerIcon\")\nexport const CopyIcon = icon(Copy01Icon, \"CopyIcon\")\nexport const DashIcon = icon(Remove01Icon, \"DashIcon\")\nexport const HelpIcon = icon(HelpCircleIcon, \"HelpIcon\")\nexport const InfoIcon = icon(InformationCircleIcon, \"InfoIcon\")\nexport const LoadingIcon = icon(Loading03Icon, \"LoadingIcon\")\nexport const MoonIcon = icon(Moon02Icon, \"MoonIcon\")\nexport const SearchIcon = icon(Search01Icon, \"SearchIcon\")\nexport const SunIcon = icon(Sun03Icon, \"SunIcon\")\n"],"mappings":";;;AA8BA,MAAa,YAAY,KAAK,aAAa,WAAW;AACtD,MAAa,kBAAkB,KAAKA,mBAAgB,iBAAiB;AACrE,MAAa,mBAAmB,KAAK,oBAAoB,kBAAkB;AAC3E,MAAa,eAAe,KAAK,gBAAgB,cAAc;AAC/D,MAAa,aAAa,KAAK,cAAc,YAAY;AACzD,MAAa,mBAAmB,KAAKC,oBAAiB,kBAAkB;AACxE,MAAa,YAAY,KAAK,YAAY,WAAW;AACrD,MAAa,kBAAkB,KAAK,uBAAuB,iBAAiB;AAC5E,MAAa,kBAAkB,KAAK,iBAAiB,iBAAiB;AACtE,MAAa,kBAAkB,KAAK,iBAAiB,iBAAiB;AACtE,MAAa,mBAAmB,KAAK,kBAAkB,kBAAkB;AACzE,MAAa,gBAAgB,KAAK,eAAe,eAAe;AAChE,MAAa,qBAAqB,KAAK,gBAAgB,oBAAoB;AAC3E,MAAa,eAAe,KAAKC,gBAAa,cAAc;AAC5D,MAAa,WAAW,KAAK,YAAY,UAAU;AACnD,MAAa,WAAW,KAAK,cAAc,UAAU;AACrD,MAAa,WAAW,KAAK,gBAAgB,UAAU;AACvD,MAAa,WAAW,KAAK,uBAAuB,UAAU;AAC9D,MAAa,cAAc,KAAK,eAAe,aAAa;AAC5D,MAAa,WAAW,KAAK,YAAY,UAAU;AACnD,MAAa,aAAa,KAAK,cAAc,YAAY;AACzD,MAAa,UAAU,KAAK,WAAW,SAAS"}
1
+ {"version":3,"file":"icons.js","names":["AlertCircleDef","CancelCircleDef","ComputerDef"],"sources":["../../src/lib/icons.tsx"],"sourcesContent":["import {\n Alert02Icon,\n AlertCircleIcon as AlertCircleDef,\n ArrowDown01Icon,\n ArrowDown02Icon,\n ArrowLeft01Icon,\n ArrowLeftDoubleIcon,\n ArrowRight01Icon,\n ArrowRightDoubleIcon,\n ArrowUp01Icon,\n ArrowUp02Icon,\n ArrowUpRight01Icon,\n Calendar03Icon,\n Cancel01Icon,\n CancelCircleIcon as CancelCircleDef,\n CheckmarkCircle02Icon,\n ListFilterIcon,\n ComputerIcon as ComputerDef,\n Copy01Icon,\n HelpCircleIcon,\n InformationCircleIcon,\n Loading03Icon,\n Moon02Icon,\n MoreHorizontalCircle01Icon,\n PlusSignCircleIcon,\n Refresh01Icon,\n Remove01Icon,\n Search01Icon,\n Sun03Icon,\n Tick02Icon,\n UnfoldMoreIcon,\n} from \"@hugeicons/core-free-icons\"\nimport { icon } from \"./icon\"\n\n// The handful of structural glyphs the package's own components render. This file lives in\n// `lib/` rather than `components/` so the `\"./*\"` wildcard export, which maps into\n// `components/`, never exposes it.\n\nexport const AlertIcon = icon(Alert02Icon, \"AlertIcon\")\nexport const AlertCircleIcon = icon(AlertCircleDef, \"AlertCircleIcon\")\nexport const ArrowDownIcon = icon(ArrowDown02Icon, \"ArrowDownIcon\")\nexport const ArrowUpIcon = icon(ArrowUp02Icon, \"ArrowUpIcon\")\nexport const ArrowUpRightIcon = icon(ArrowUpRight01Icon, \"ArrowUpRightIcon\")\nexport const CalendarIcon = icon(Calendar03Icon, \"CalendarIcon\")\nexport const CancelIcon = icon(Cancel01Icon, \"CancelIcon\")\nexport const CancelCircleIcon = icon(CancelCircleDef, \"CancelCircleIcon\")\nexport const CheckIcon = icon(Tick02Icon, \"CheckIcon\")\nexport const CheckCircleIcon = icon(CheckmarkCircle02Icon, \"CheckCircleIcon\")\nexport const ChevronDownIcon = icon(ArrowDown01Icon, \"ChevronDownIcon\")\nexport const ChevronsLeftIcon = icon(ArrowLeftDoubleIcon, \"ChevronsLeftIcon\")\nexport const ChevronsRightIcon = icon(ArrowRightDoubleIcon, \"ChevronsRightIcon\")\nexport const ChevronLeftIcon = icon(ArrowLeft01Icon, \"ChevronLeftIcon\")\nexport const ChevronRightIcon = icon(ArrowRight01Icon, \"ChevronRightIcon\")\nexport const ChevronUpIcon = icon(ArrowUp01Icon, \"ChevronUpIcon\")\nexport const ChevronsUpDownIcon = icon(UnfoldMoreIcon, \"ChevronsUpDownIcon\")\nexport const ComputerIcon = icon(ComputerDef, \"ComputerIcon\")\nexport const CopyIcon = icon(Copy01Icon, \"CopyIcon\")\nexport const DashIcon = icon(Remove01Icon, \"DashIcon\")\nexport const FilterIcon = icon(ListFilterIcon, \"FilterIcon\")\nexport const HelpIcon = icon(HelpCircleIcon, \"HelpIcon\")\nexport const InfoIcon = icon(InformationCircleIcon, \"InfoIcon\")\nexport const LoadingIcon = icon(Loading03Icon, \"LoadingIcon\")\nexport const MoonIcon = icon(Moon02Icon, \"MoonIcon\")\n// Filled: a hollow dot all but disappears at the size a menu trigger draws it.\nexport const MoreIcon = icon(MoreHorizontalCircle01Icon, \"MoreIcon\", { fill: \"currentColor\" })\nexport const PlusCircleIcon = icon(PlusSignCircleIcon, \"PlusCircleIcon\")\nexport const RefreshIcon = icon(Refresh01Icon, \"RefreshIcon\")\nexport const SearchIcon = icon(Search01Icon, \"SearchIcon\")\nexport const SunIcon = icon(Sun03Icon, \"SunIcon\")\n"],"mappings":";;;AAsCA,MAAa,YAAY,KAAK,aAAa,WAAW;AACtD,MAAa,kBAAkB,KAAKA,mBAAgB,iBAAiB;AACrE,MAAa,gBAAgB,KAAK,iBAAiB,eAAe;AAClE,MAAa,cAAc,KAAK,eAAe,aAAa;AAC5D,MAAa,mBAAmB,KAAK,oBAAoB,kBAAkB;AAC3E,MAAa,eAAe,KAAK,gBAAgB,cAAc;AAC/D,MAAa,aAAa,KAAK,cAAc,YAAY;AACzD,MAAa,mBAAmB,KAAKC,oBAAiB,kBAAkB;AACxE,MAAa,YAAY,KAAK,YAAY,WAAW;AACrD,MAAa,kBAAkB,KAAK,uBAAuB,iBAAiB;AAC5E,MAAa,kBAAkB,KAAK,iBAAiB,iBAAiB;AACtE,MAAa,mBAAmB,KAAK,qBAAqB,kBAAkB;AAC5E,MAAa,oBAAoB,KAAK,sBAAsB,mBAAmB;AAC/E,MAAa,kBAAkB,KAAK,iBAAiB,iBAAiB;AACtE,MAAa,mBAAmB,KAAK,kBAAkB,kBAAkB;AACzE,MAAa,gBAAgB,KAAK,eAAe,eAAe;AAChE,MAAa,qBAAqB,KAAK,gBAAgB,oBAAoB;AAC3E,MAAa,eAAe,KAAKC,gBAAa,cAAc;AAC5D,MAAa,WAAW,KAAK,YAAY,UAAU;AACnD,MAAa,WAAW,KAAK,cAAc,UAAU;AACrD,MAAa,aAAa,KAAK,gBAAgB,YAAY;AAC3D,MAAa,WAAW,KAAK,gBAAgB,UAAU;AACvD,MAAa,WAAW,KAAK,uBAAuB,UAAU;AAC9D,MAAa,cAAc,KAAK,eAAe,aAAa;AAC5D,MAAa,WAAW,KAAK,YAAY,UAAU;AAEnD,MAAa,WAAW,KAAK,4BAA4B,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7F,MAAa,iBAAiB,KAAK,oBAAoB,gBAAgB;AACvE,MAAa,cAAc,KAAK,eAAe,aAAa;AAC5D,MAAa,aAAa,KAAK,cAAc,YAAY;AACzD,MAAa,UAAU,KAAK,WAAW,SAAS"}
@@ -0,0 +1,14 @@
1
+ export interface LoadMoreOptions {
2
+ /** False while a page is in flight, when there is no next page, or after a failed page. */
3
+ enabled: boolean;
4
+ onLoad: () => void;
5
+ /** How far below the viewport the sentinel starts loading, in pixels. */
6
+ ahead?: number;
7
+ }
8
+ /**
9
+ * Loads the next page as `sentinel` scrolls into view. The observer is dropped while a page is
10
+ * in flight and set up again after it lands: observing fires straight away for an element
11
+ * already on screen, which is what walks a fast scroll on through page after page. Pass the
12
+ * element through a state setter (`ref={setSentinel}`), so the hook sees it once it mounts.
13
+ */
14
+ export declare function useLoadMore(sentinel: Element | null, { enabled, onLoad, ahead }: LoadMoreOptions): void;
@@ -0,0 +1,27 @@
1
+ "use client";
2
+ import { useEffect } from "react";
3
+ // src/lib/load-more.ts
4
+ /**
5
+ * Loads the next page as `sentinel` scrolls into view. The observer is dropped while a page is
6
+ * in flight and set up again after it lands: observing fires straight away for an element
7
+ * already on screen, which is what walks a fast scroll on through page after page. Pass the
8
+ * element through a state setter (`ref={setSentinel}`), so the hook sees it once it mounts.
9
+ */
10
+ function useLoadMore(sentinel, { enabled, onLoad, ahead }) {
11
+ useEffect(() => {
12
+ if (!sentinel || !enabled) return;
13
+ const observer = new IntersectionObserver((entries) => {
14
+ if (entries.some((entry) => entry.isIntersecting)) onLoad();
15
+ }, ahead === void 0 ? void 0 : { rootMargin: `0px 0px ${ahead}px 0px` });
16
+ observer.observe(sentinel);
17
+ return () => observer.disconnect();
18
+ }, [
19
+ sentinel,
20
+ enabled,
21
+ onLoad,
22
+ ahead
23
+ ]);
24
+ }
25
+ export { useLoadMore };
26
+
27
+ //# sourceMappingURL=load-more.js.map