@manakind/ui-core 0.32.0 → 0.34.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.
- package/dist/ark-native-input.d.ts +65 -0
- package/dist/ark-native-input.d.ts.map +1 -0
- package/dist/ark-native-input.js +72 -0
- package/dist/ark-native-input.js.map +1 -0
- package/dist/badge/badge.css +6 -0
- package/dist/badge/badge.d.ts +4 -3
- package/dist/badge/badge.d.ts.map +1 -1
- package/dist/badge/badge.js.map +1 -1
- package/dist/checkbox/checkbox.d.ts.map +1 -1
- package/dist/checkbox/checkbox.js +11 -27
- package/dist/checkbox/checkbox.js.map +1 -1
- package/dist/icon-defaults.d.ts +1 -1
- package/dist/icon-defaults.d.ts.map +1 -1
- package/dist/icon-defaults.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/radio-group/radio-group.d.ts.map +1 -1
- package/dist/radio-group/radio-group.js +7 -21
- package/dist/radio-group/radio-group.js.map +1 -1
- package/dist/segment-group/segment-group.d.ts.map +1 -1
- package/dist/segment-group/segment-group.js +7 -26
- package/dist/segment-group/segment-group.js.map +1 -1
- package/dist/switch/switch.d.ts.map +1 -1
- package/dist/switch/switch.js +11 -24
- package/dist/switch/switch.js.map +1 -1
- package/dist/table/index.d.ts +3 -0
- package/dist/table/index.d.ts.map +1 -0
- package/dist/table/index.js +2 -0
- package/dist/table/index.js.map +1 -0
- package/dist/table/table.css +189 -0
- package/dist/table/table.css.d.ts +2 -0
- package/dist/table/table.d.ts +144 -0
- package/dist/table/table.d.ts.map +1 -0
- package/dist/table/table.js +95 -0
- package/dist/table/table.js.map +1 -0
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"segment-group.js","sourceRoot":"","sources":["../../src/segment-group/segment-group.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,IAAI,eAAe,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T,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,CACL,MAAC,eAAe,CAAC,IAAI,IACnB,GAAG,EAAE,OAAO,EACZ,SAAS,EAAE,EAAE,CACX,kBAAkB,EAClB,qBAAqB,IAAI,EAAE,EAC3B,GAAG,KAAK,SAAS,IAAI,+BAA+B,EACpD,OAAO,KAAK,OAAO,IAAI,yBAAyB,EAChD,SAAS,IAAI,8BAA8B,EAC3C,SAAS,CACV,EACD,KAAK,EAAE,KAAK,EACZ,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,iBAAiB,EAChC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,WAAW,EAAC,YAAY,gBACZ,SAAS,aAEpB,YAAY,EACb,eAAK,SAAS,EAAC,yBAAyB,aACrC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,EACrB,MAAM,IAAI,CACT,KAAC,eAAe,CAAC,OAAO,cACrB,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,GACrB,CAC3B,IACG,IACe,CACxB,CAAC;AACJ,CAAC","sourcesContent":["import { SegmentGroup as ArkSegmentGroup } from '@ark-ui/react/segment-group';\nimport { type ReactNode, useRef } from 'react';\nimport './segment-group.css';\nimport { cx } from '../cx';\n\nexport type SegmentGroupSize = 'sm' | 'md';\n\nexport interface SegmentGroupItem {\n /** Stable value reported by `onValueChange` and compared with `value`. */\n value: string;\n /** Text shown on the segment. Keep it to a word or two; a longer one wraps inside its segment. */\n label: string;\n /** Individually disable this choice without removing it. */\n disabled?: boolean;\n}\n\n/**\n * A value typed beside the segments, for one no segment offers: the minutes\n * of a duration whose presets are 30 minutes and an hour. The consumer owns\n * both values and keeps them agreeing: a typed value that matches a segment\n * checks that segment, and choosing a segment fills the field with its value.\n */\nexport interface SegmentGroupCustom {\n /** What the field holds, `''` when empty. */\n value: string;\n /** Fired with the field's text on every change. */\n onValueChange: (value: string) => void;\n /** The field's accessible name (\"Duration in minutes\"); it has no visible label of its own. */\n 'aria-label': string;\n /** Shown while the field is empty. */\n placeholder?: string;\n /** A unit written after the value, such as `min`. Decorative: put the unit in `aria-label` too. */\n unit?: string;\n /** The keyboard a phone shows for the field. */\n inputMode?: 'numeric' | 'decimal' | 'text';\n}\n\n/**\n * A segment group has to have a name. A visible `label` is the one to reach\n * for; expressed as a union so an unnamed group is a compile error rather\n * than an axe finding, as `Checkbox` and `Switch` do.\n */\ntype SegmentGroupName =\n | {\n /** Visible label, rendered above the track and naming the group. */\n label: ReactNode;\n /**\n * A different accessible name when the visible label alone would not\n * say what the choice is. Keep the visible words in it (\"Period\" →\n * \"Reporting period\"), so a voice user can still say what they see.\n */\n 'aria-label'?: string;\n }\n | {\n label?: undefined;\n /** Accessible name when the surrounding heading or row already says what the choice is. */\n 'aria-label': string;\n };\n\nexport type SegmentGroupProps = SegmentGroupName & {\n /** The choices, in order. Exactly one is checked. */\n items: SegmentGroupItem[];\n /**\n * Controlled value. `null` is controlled with nothing checked, for a form\n * that starts without a choice; `undefined` leaves the component to own\n * its value from `defaultValue` onward, as `Select` does.\n */\n value?: string | null;\n /** Initial value when uncontrolled. */\n defaultValue?: string;\n /**\n * Fired with the newly checked value. Choosing the checked segment again\n * does nothing, so a consumer that saves on change never writes twice.\n */\n onValueChange?: (value: string) => void;\n /** Segment height and type scale. `sm` suits a toolbar or a card header. */\n size?: SegmentGroupSize;\n /**\n * How the segments share the track. `equal` (default): every segment as\n * wide as the widest, and a word longer than its column breaks inside it.\n * `content`: each segment as wide as its own label, the spare width shared\n * out, so a group of labels of uneven length fits a narrow container\n * without breaking a word.\n */\n fit?: 'equal' | 'content';\n /**\n * `dense` tightens each segment's inline padding, for a group of many\n * short items (six t-shirt sizes) that has to fit a phone.\n */\n density?: 'default' | 'dense';\n /**\n * Whether the group takes the whole width of its row, the track with it:\n * a state or effort choice in a form, level with the fields above it.\n */\n fullWidth?: boolean;\n /**\n * A field at the end of the track for a value no segment offers. While it\n * holds a value and no segment is checked, it is drawn as the choice and\n * submits under `name`.\n */\n custom?: SegmentGroupCustom;\n /** Disable every segment. The checked one keeps showing which is set. */\n disabled?: boolean;\n /** Name for native form participation through the hidden radio inputs. */\n name?: string;\n /** Extra class names appended after the `ds-segment-group` modifiers. */\n className?: string;\n};\n\n/**\n * One choice among a few, shown as a row of segments, built on Ark UI's\n * SegmentGroup: a radio group whose radios are drawn as one control.\n *\n * Ark owns the behaviour: hidden radio inputs carry the state, the arrow keys\n * move the choice, and the whole segment is its radio's label. This wrapper\n * contributes `ds-` classes, the `--ds-segment-group-*` bindings and a flat\n * `items` API in place of Ark's anatomy.\n *\n * ```tsx\n * <SegmentGroup\n * label=\"Period\"\n * items={[\n * { value: 'today', label: 'Today' },\n * { value: 'week', label: 'Week' },\n * { value: 'month', label: 'Month' },\n * ]}\n * value={period}\n * onValueChange={setPeriod}\n * />\n * ```\n *\n * Reach for it when the choices are few, short and all worth seeing at once:\n * a period, a size, a view. More than five, or labels that need a sentence,\n * want a `Select`. Panels that change with the choice are `Tabs`; a segment\n * group changes a value, not what is on the page.\n */\nexport function SegmentGroup({\n label,\n items,\n value,\n defaultValue,\n onValueChange,\n size = 'md',\n fit = 'equal',\n density = 'default',\n fullWidth = false,\n custom,\n disabled,\n name,\n className,\n 'aria-label': ariaLabel,\n}: SegmentGroupProps) {\n const rootRef = useRef<HTMLDivElement>(null);\n\n /*\n * Zag reports `null` only when the value is cleared through its API, which\n * this wrapper never calls; a user can only move the choice to a segment.\n *\n * Ark renders the hidden radios uncontrolled and syncs them only when its\n * own state changes, so a controlled parent that declines a choice would\n * leave the native radio checked while the segment shows the old one.\n * Restoring the parent's value after Ark has read the radios keeps the two\n * agreeing, as Checkbox and Switch do.\n */\n const handleValueChange = (details: { value: string | null }) => {\n if (details.value !== null) onValueChange?.(details.value);\n if (value === undefined || !rootRef.current) return;\n for (const input of rootRef.current.querySelectorAll<HTMLInputElement>('input[type=\"radio\"]')) {\n input.checked = input.value === value;\n }\n };\n\n /*\n * Zag always names the root by its label part's id, which would outrank an\n * `aria-label`. With both given, the visible label is plain text instead,\n * so that id resolves to nothing and the `aria-label` is what is announced.\n */\n const visibleLabel =\n label &&\n (ariaLabel ? (\n <span className=\"ds-segment-group__label\">{label}</span>\n ) : (\n <ArkSegmentGroup.Label className=\"ds-segment-group__label\">{label}</ArkSegmentGroup.Label>\n ));\n\n const renderItem = (item: SegmentGroupItem) => (\n <ArkSegmentGroup.Item\n key={item.value}\n value={item.value}\n disabled={item.disabled}\n className=\"ds-segment-group__item\"\n >\n <ArkSegmentGroup.ItemText className=\"ds-segment-group__item-text\">\n {item.label}\n </ArkSegmentGroup.ItemText>\n <ArkSegmentGroup.ItemHiddenInput />\n </ArkSegmentGroup.Item>\n );\n\n /*\n * The field is the choice while it holds a value no segment has. That is\n * read from Ark's own value, so an uncontrolled group draws it right too,\n * and it submits under `name` only then, when no radio is checked.\n */\n const renderCustom = (custom: SegmentGroupCustom, current: string | null) => {\n const chosen = custom.value !== '' && !items.some((item) => item.value === current);\n return (\n <label\n className=\"ds-segment-group__custom\"\n data-state={chosen ? 'checked' : 'unchecked'}\n data-disabled={disabled ? '' : undefined}\n >\n <input\n className=\"ds-segment-group__custom-input\"\n value={custom.value}\n onChange={(event) => custom.onValueChange(event.target.value)}\n aria-label={custom['aria-label']}\n placeholder={custom.placeholder}\n inputMode={custom.inputMode}\n name={chosen ? name : undefined}\n disabled={disabled}\n />\n {custom.unit && (\n <span className=\"ds-segment-group__custom-unit\" aria-hidden=\"true\">\n {custom.unit}\n </span>\n )}\n </label>\n );\n };\n\n return (\n <ArkSegmentGroup.Root\n ref={rootRef}\n className={cx(\n 'ds-segment-group',\n `ds-segment-group--${size}`,\n fit === 'content' && 'ds-segment-group--fit-content',\n density === 'dense' && 'ds-segment-group--dense',\n fullWidth && 'ds-segment-group--full-width',\n className,\n )}\n value={value}\n defaultValue={defaultValue}\n onValueChange={handleValueChange}\n disabled={disabled}\n name={name}\n orientation=\"horizontal\"\n aria-label={ariaLabel}\n >\n {visibleLabel}\n <div className=\"ds-segment-group__track\">\n {items.map(renderItem)}\n {custom && (\n <ArkSegmentGroup.Context>\n {(group) => renderCustom(custom, group.value)}\n </ArkSegmentGroup.Context>\n )}\n </div>\n </ArkSegmentGroup.Root>\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"segment-group.js","sourceRoot":"","sources":["../../src/segment-group/segment-group.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,IAAI,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,EAAkB,MAAM,EAAE,MAAM,OAAO,CAAC;AAC/C,OAAO,qBAAqB,CAAC;AAC7B,OAAO,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AA0G3B;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,YAAY,CAAC,EAC3B,KAAK,EACL,KAAK,EACL,KAAK,EACL,YAAY,EACZ,aAAa,EACb,IAAI,GAAG,IAAI,EACX,GAAG,GAAG,OAAO,EACb,OAAO,GAAG,SAAS,EACnB,SAAS,GAAG,KAAK,EACjB,MAAM,EACN,QAAQ,EACR,IAAI,EACJ,SAAS,EACT,YAAY,EAAE,SAAS,GACL;IAClB,MAAM,OAAO,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IAE7C,MAAM,iBAAiB,GAAG,uBAAuB,CAAC,OAAO,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC;IAEjF,MAAM,YAAY,GAAG,kBAAkB,CAAC,eAAe,CAAC,KAAK,EAAE;QAC7D,KAAK;QACL,SAAS;QACT,SAAS,EAAE,yBAAyB;KACrC,CAAC,CAAC;IAEH,MAAM,UAAU,GAAG,CAAC,IAAsB,EAAE,EAAE,CAAC,CAC7C,MAAC,eAAe,CAAC,IAAI,IAEnB,KAAK,EAAE,IAAI,CAAC,KAAK,EACj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AO,EACZ,SAAS,EAAE,EAAE,CACX,kBAAkB,EAClB,qBAAqB,IAAI,EAAE,EAC3B,GAAG,KAAK,SAAS,IAAI,+BAA+B,EACpD,OAAO,KAAK,OAAO,IAAI,yBAAyB,EAChD,SAAS,IAAI,8BAA8B,EAC3C,SAAS,CACV,EACD,KAAK,EAAE,KAAK,EACZ,YAAY,EAAE,YAAY,EAC1B,aAAa,EAAE,iBAAiB,EAChC,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,WAAW,EAAC,YAAY,gBACZ,SAAS,aAEpB,YAAY,EACb,eAAK,SAAS,EAAC,yBAAyB,aACrC,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,EACrB,MAAM,IAAI,CACT,KAAC,eAAe,CAAC,OAAO,cACrB,CAAC,KAAK,EAAE,EAAE,CAAC,YAAY,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,GACrB,CAC3B,IACG,IACe,CACxB,CAAC;AACJ,CAAC","sourcesContent":["import { SegmentGroup as ArkSegmentGroup } from '@ark-ui/react/segment-group';\nimport { type ReactNode, useRef } from 'react';\nimport './segment-group.css';\nimport { radioGroupChangeHandler, renderVisibleLabel } from '../ark-native-input';\nimport { cx } from '../cx';\n\nexport type SegmentGroupSize = 'sm' | 'md';\n\nexport interface SegmentGroupItem {\n /** Stable value reported by `onValueChange` and compared with `value`. */\n value: string;\n /** Text shown on the segment. Keep it to a word or two; a longer one wraps inside its segment. */\n label: string;\n /** Individually disable this choice without removing it. */\n disabled?: boolean;\n}\n\n/**\n * A value typed beside the segments, for one no segment offers: the minutes\n * of a duration whose presets are 30 minutes and an hour. The consumer owns\n * both values and keeps them agreeing: a typed value that matches a segment\n * checks that segment, and choosing a segment fills the field with its value.\n */\nexport interface SegmentGroupCustom {\n /** What the field holds, `''` when empty. */\n value: string;\n /** Fired with the field's text on every change. */\n onValueChange: (value: string) => void;\n /** The field's accessible name (\"Duration in minutes\"); it has no visible label of its own. */\n 'aria-label': string;\n /** Shown while the field is empty. */\n placeholder?: string;\n /** A unit written after the value, such as `min`. Decorative: put the unit in `aria-label` too. */\n unit?: string;\n /** The keyboard a phone shows for the field. */\n inputMode?: 'numeric' | 'decimal' | 'text';\n}\n\n/**\n * A segment group has to have a name. A visible `label` is the one to reach\n * for; expressed as a union so an unnamed group is a compile error rather\n * than an axe finding, as `Checkbox` and `Switch` do.\n */\ntype SegmentGroupName =\n | {\n /** Visible label, rendered above the track and naming the group. */\n label: ReactNode;\n /**\n * A different accessible name when the visible label alone would not\n * say what the choice is. Keep the visible words in it (\"Period\" →\n * \"Reporting period\"), so a voice user can still say what they see.\n */\n 'aria-label'?: string;\n }\n | {\n label?: undefined;\n /** Accessible name when the surrounding heading or row already says what the choice is. */\n 'aria-label': string;\n };\n\nexport type SegmentGroupProps = SegmentGroupName & {\n /** The choices, in order. Exactly one is checked. */\n items: SegmentGroupItem[];\n /**\n * Controlled value. `null` is controlled with nothing checked, for a form\n * that starts without a choice; `undefined` leaves the component to own\n * its value from `defaultValue` onward, as `Select` does.\n */\n value?: string | null;\n /** Initial value when uncontrolled. */\n defaultValue?: string;\n /**\n * Fired with the newly checked value. Choosing the checked segment again\n * does nothing, so a consumer that saves on change never writes twice.\n */\n onValueChange?: (value: string) => void;\n /** Segment height and type scale. `sm` suits a toolbar or a card header. */\n size?: SegmentGroupSize;\n /**\n * How the segments share the track. `equal` (default): every segment as\n * wide as the widest, and a word longer than its column breaks inside it.\n * `content`: each segment as wide as its own label, the spare width shared\n * out, so a group of labels of uneven length fits a narrow container\n * without breaking a word.\n */\n fit?: 'equal' | 'content';\n /**\n * `dense` tightens each segment's inline padding, for a group of many\n * short items (six t-shirt sizes) that has to fit a phone.\n */\n density?: 'default' | 'dense';\n /**\n * Whether the group takes the whole width of its row, the track with it:\n * a state or effort choice in a form, level with the fields above it.\n */\n fullWidth?: boolean;\n /**\n * A field at the end of the track for a value no segment offers. While it\n * holds a value and no segment is checked, it is drawn as the choice and\n * submits under `name`.\n */\n custom?: SegmentGroupCustom;\n /** Disable every segment. The checked one keeps showing which is set. */\n disabled?: boolean;\n /** Name for native form participation through the hidden radio inputs. */\n name?: string;\n /** Extra class names appended after the `ds-segment-group` modifiers. */\n className?: string;\n};\n\n/**\n * One choice among a few, shown as a row of segments, built on Ark UI's\n * SegmentGroup: a radio group whose radios are drawn as one control.\n *\n * Ark owns the behaviour: hidden radio inputs carry the state, the arrow keys\n * move the choice, and the whole segment is its radio's label. This wrapper\n * contributes `ds-` classes, the `--ds-segment-group-*` bindings and a flat\n * `items` API in place of Ark's anatomy.\n *\n * ```tsx\n * <SegmentGroup\n * label=\"Period\"\n * items={[\n * { value: 'today', label: 'Today' },\n * { value: 'week', label: 'Week' },\n * { value: 'month', label: 'Month' },\n * ]}\n * value={period}\n * onValueChange={setPeriod}\n * />\n * ```\n *\n * Reach for it when the choices are few, short and all worth seeing at once:\n * a period, a size, a view. More than five, or labels that need a sentence,\n * want a `Select`. Panels that change with the choice are `Tabs`; a segment\n * group changes a value, not what is on the page.\n */\nexport function SegmentGroup({\n label,\n items,\n value,\n defaultValue,\n onValueChange,\n size = 'md',\n fit = 'equal',\n density = 'default',\n fullWidth = false,\n custom,\n disabled,\n name,\n className,\n 'aria-label': ariaLabel,\n}: SegmentGroupProps) {\n const rootRef = useRef<HTMLDivElement>(null);\n\n const handleValueChange = radioGroupChangeHandler(rootRef, value, onValueChange);\n\n const visibleLabel = renderVisibleLabel(ArkSegmentGroup.Label, {\n label,\n ariaLabel,\n className: 'ds-segment-group__label',\n });\n\n const renderItem = (item: SegmentGroupItem) => (\n <ArkSegmentGroup.Item\n key={item.value}\n value={item.value}\n disabled={item.disabled}\n className=\"ds-segment-group__item\"\n >\n <ArkSegmentGroup.ItemText className=\"ds-segment-group__item-text\">\n {item.label}\n </ArkSegmentGroup.ItemText>\n <ArkSegmentGroup.ItemHiddenInput />\n </ArkSegmentGroup.Item>\n );\n\n /*\n * The field is the choice while it holds a value no segment has. That is\n * read from Ark's own value, so an uncontrolled group draws it right too,\n * and it submits under `name` only then, when no radio is checked.\n */\n const renderCustom = (custom: SegmentGroupCustom, current: string | null) => {\n const chosen = custom.value !== '' && !items.some((item) => item.value === current);\n return (\n <label\n className=\"ds-segment-group__custom\"\n data-state={chosen ? 'checked' : 'unchecked'}\n data-disabled={disabled ? '' : undefined}\n >\n <input\n className=\"ds-segment-group__custom-input\"\n value={custom.value}\n onChange={(event) => custom.onValueChange(event.target.value)}\n aria-label={custom['aria-label']}\n placeholder={custom.placeholder}\n inputMode={custom.inputMode}\n name={chosen ? name : undefined}\n disabled={disabled}\n />\n {custom.unit && (\n <span className=\"ds-segment-group__custom-unit\" aria-hidden=\"true\">\n {custom.unit}\n </span>\n )}\n </label>\n );\n };\n\n return (\n <ArkSegmentGroup.Root\n ref={rootRef}\n className={cx(\n 'ds-segment-group',\n `ds-segment-group--${size}`,\n fit === 'content' && 'ds-segment-group--fit-content',\n density === 'dense' && 'ds-segment-group--dense',\n fullWidth && 'ds-segment-group--full-width',\n className,\n )}\n value={value}\n defaultValue={defaultValue}\n onValueChange={handleValueChange}\n disabled={disabled}\n name={name}\n orientation=\"horizontal\"\n aria-label={ariaLabel}\n >\n {visibleLabel}\n <div className=\"ds-segment-group__track\">\n {items.map(renderItem)}\n {custom && (\n <ArkSegmentGroup.Context>\n {(group) => renderCustom(custom, group.value)}\n </ArkSegmentGroup.Context>\n )}\n </div>\n </ArkSegmentGroup.Root>\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["../../src/switch/switch.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"switch.d.ts","sourceRoot":"","sources":["../../src/switch/switch.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,SAAS,EAAU,MAAM,OAAO,CAAC;AAC/C,OAAO,cAAc,CAAC;AAItB,MAAM,MAAM,UAAU,GAAG,IAAI,GA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AQ,EACR,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,SAAS,EACT,YAAY,EAAE,SAAS,EACvB,kBAAkB,EAAE,eAAe,GACpC,EAAE,WAAW,2CA4Cb"}
|
package/dist/switch/switch.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Switch as ArkSwitch } from '@ark-ui/react/switch';
|
|
3
|
-
import {
|
|
3
|
+
import { useRef } from 'react';
|
|
4
4
|
import './switch.css';
|
|
5
|
+
import { renderVisibleLabel, restoreNativeInputs, useOwnCheckableIds } from '../ark-native-input';
|
|
5
6
|
import { cx } from '../cx';
|
|
6
7
|
/**
|
|
7
8
|
* On/off control for a setting that takes effect at once, built on Ark UI.
|
|
@@ -22,31 +23,17 @@ import { cx } from '../cx';
|
|
|
22
23
|
* or a segmented control.
|
|
23
24
|
*/
|
|
24
25
|
export function Switch({ label, labelPlacement = 'end', checked, defaultChecked, onCheckedChange, size = 'md', disabled, invalid, readOnly, required, name, value, className, 'aria-label': ariaLabel, 'aria-describedby': ariaDescribedBy, }) {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
const inputRef = useRef(null);
|
|
33
|
-
// Own ids, as Checkbox: a switch names itself, and two switches in one
|
|
34
|
-
// Field must not share the field's control id.
|
|
35
|
-
const ownId = useId();
|
|
36
|
-
const ids = { hiddenInput: `${ownId}:input`, label: `${ownId}:label` };
|
|
37
|
-
/*
|
|
38
|
-
* Ark renders the hidden input uncontrolled (`defaultChecked`) and syncs it
|
|
39
|
-
* only when its own state changes. A controlled parent that declines a
|
|
40
|
-
* toggle therefore leaves the native input flipped while the control shows
|
|
41
|
-
* the old state, and assistive tech reads the input. Ark reports the toggle
|
|
42
|
-
* after reading the input, so restoring the parent's value here is safe:
|
|
43
|
-
* a parent that accepts re-renders, and Ark syncs the input again.
|
|
44
|
-
*/
|
|
26
|
+
const labelNode = renderVisibleLabel(ArkSwitch.Label, {
|
|
27
|
+
label,
|
|
28
|
+
ariaLabel,
|
|
29
|
+
className: 'ds-switch__label',
|
|
30
|
+
});
|
|
31
|
+
const rootRef = useRef(null);
|
|
32
|
+
const ids = useOwnCheckableIds();
|
|
45
33
|
const handleCheckedChange = (details) => {
|
|
46
34
|
onCheckedChange?.(details.checked);
|
|
47
|
-
|
|
48
|
-
inputRef.current.checked = checked;
|
|
35
|
+
restoreNativeInputs(rootRef.current, checked);
|
|
49
36
|
};
|
|
50
|
-
return (_jsxs(ArkSwitch.Root, { ids: ids, className: cx('ds-switch', `ds-switch--${size}`, className), checked: checked, defaultChecked: defaultChecked, onCheckedChange: handleCheckedChange, disabled: disabled, invalid: invalid, readOnly: readOnly, required: required, name: name, value: value, children: [labelPlacement === 'start' && labelNode, _jsx(ArkSwitch.Control, { className: "ds-switch__control", children: _jsx(ArkSwitch.Thumb, { className: "ds-switch__thumb" }) }), labelPlacement === 'end' && labelNode, _jsx(ArkSwitch.HiddenInput, {
|
|
37
|
+
return (_jsxs(ArkSwitch.Root, { ref: rootRef, ids: ids, className: cx('ds-switch', `ds-switch--${size}`, className), checked: checked, defaultChecked: defaultChecked, onCheckedChange: handleCheckedChange, disabled: disabled, invalid: invalid, readOnly: readOnly, required: required, name: name, value: value, children: [labelPlacement === 'start' && labelNode, _jsx(ArkSwitch.Control, { className: "ds-switch__control", children: _jsx(ArkSwitch.Thumb, { className: "ds-switch__thumb" }) }), labelPlacement === 'end' && labelNode, _jsx(ArkSwitch.HiddenInput, { role: "switch", "aria-label": ariaLabel, "aria-describedby": ariaDescribedBy, "aria-readonly": readOnly || undefined })] }));
|
|
51
38
|
}
|
|
52
39
|
//# sourceMappingURL=switch.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switch.js","sourceRoot":"","sources":["../../src/switch/switch.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE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E,CAAC,WAAW,EAAE,cAAc,IAAI,EAAE,EAAE,SAAS,CAAC,EAC3D,OAAO,EAAE,OAAO,EAChB,cAAc,EAAE,cAAc,EAC9B,eAAe,EAAE,mBAAmB,EACpC,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,OAAO,EAChB,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,KAAK,EAAE,KAAK,aAEX,cAAc,KAAK,OAAO,IAAI,SAAS,EACxC,KAAC,SAAS,CAAC,OAAO,IAAC,SAAS,EAAC,oBAAoB,YAC/C,KAAC,SAAS,CAAC,KAAK,IAAC,SAAS,EAAC,kBAAkB,GAAG,GAC9B,EACnB,cAAc,KAAK,KAAK,IAAI,SAAS,EACtC,KAAC,SAAS,CAAC,WAAW,IACpB,IAAI,EAAC,QAAQ,gBACD,SAAS,sBACH,eAAe,mBAClB,QAAQ,IAAI,SAAS,GACpC,IACa,CAClB,CAAC;AACJ,CAAC","sourcesContent":["import { Switch as ArkSwitch } from '@ark-ui/react/switch';\nimport { type ReactNode, useRef } from 'react';\nimport './switch.css';\nimport { renderVisibleLabel, restoreNativeInputs, useOwnCheckableIds } from '../ark-native-input';\nimport { cx } from '../cx';\n\nexport type SwitchSize = 'sm' | 'md' | 'lg';\n\nexport type SwitchLabelPlacement = 'start' | 'end';\n\n/**\n * A switch has to have a name. A visible `label` is the one to reach for: the\n * whole label is the click target, so it also enlarges the hit area. Expressed\n * as a union so an unnamed switch is a compile error rather than an axe\n * finding, the way `IconProps` pairs label and decorative.\n */\ntype SwitchName =\n | {\n /** Visible label. The whole label is the click target. */\n label: ReactNode;\n /**\n * A different accessible name when the visible label alone would not\n * say what the control is. Keep the visible words in it, so a voice\n * user can still say what they see.\n */\n 'aria-label'?: string;\n }\n | {\n label?: undefined;\n /** Accessible name when no visible label fits, such as a table cell whose row already says what the switch is. */\n 'aria-label': string;\n };\n\nexport type SwitchProps = SwitchName & {\n /**\n * Which side of the control the label sits on. `end` (default) reads\n * \"control, then what it does\"; `start` puts the label first, for a\n * settings row. Only the order changes; the row's layout is the caller's.\n */\n labelPlacement?: SwitchLabelPlacement;\n /** Controlled checked state. Leave undefined to let the component own it. */\n checked?: boolean;\n /** Initial state when uncontrolled. */\n defaultChecked?: boolean;\n /** Fired with the new state whenever the user toggles the switch. */\n onCheckedChange?: (checked: boolean) => void;\n /** Control size and label type scale. */\n size?: SwitchSize;\n /** Disable the control. It keeps its state and stops responding. */\n disabled?: boolean;\n /**\n * Marks the control invalid for assistive tech and styling (`data-invalid`).\n * Pair it with a message the control points at through `aria-describedby`;\n * a red border alone is not an accessible error.\n */\n invalid?: boolean;\n /** Id of the element that describes the control, such as an error message. */\n 'aria-describedby'?: string;\n /** Show the state without letting the user change it. */\n readOnly?: boolean;\n /** Marks the hidden input required for native form validation. */\n required?: boolean;\n /** Name for native form participation. */\n name?: string;\n /** Value submitted under `name` while checked. Defaults to `on`. */\n value?: string;\n /** Extra class names appended after the `ds-switch` modifiers. */\n className?: string;\n};\n\n/**\n * On/off control for a setting that takes effect at once, built on Ark UI.\n *\n * Ark owns the behaviour: a hidden checkbox carries the checked state, the\n * root is the `<label>` that names it, and keyboard (Space) and pointer\n * toggling come for free. The input is given `role=\"switch\"` and\n * `aria-readonly` here, which Ark leaves off, so it is announced as a switch\n * rather than a checkbox, and a read-only one says so. This wrapper contributes `ds-`\n * classes, the `--ds-switch-*` bindings, and a flat prop API.\n *\n * ```tsx\n * <Switch label=\"Gap view\" checked={gapView} onCheckedChange={setGapView} />\n * ```\n *\n * A switch is for a setting that applies immediately. A choice that is only\n * saved on submit is a checkbox; a choice between several values is a select\n * or a segmented control.\n */\nexport function Switch({\n label,\n labelPlacement = 'end',\n checked,\n defaultChecked,\n onCheckedChange,\n size = 'md',\n disabled,\n invalid,\n readOnly,\n required,\n name,\n value,\n className,\n 'aria-label': ariaLabel,\n 'aria-describedby': ariaDescribedBy,\n}: SwitchProps) {\n const labelNode = renderVisibleLabel(ArkSwitch.Label, {\n label,\n ariaLabel,\n className: 'ds-switch__label',\n });\n\n const rootRef = useRef<HTMLLabelElement>(null);\n\n const ids = useOwnCheckableIds();\n\n const handleCheckedChange = (details: { checked: boolean }) => {\n onCheckedChange?.(details.checked);\n restoreNativeInputs(rootRef.current, checked);\n };\n\n return (\n <ArkSwitch.Root\n ref={rootRef}\n ids={ids}\n className={cx('ds-switch', `ds-switch--${size}`, className)}\n checked={checked}\n defaultChecked={defaultChecked}\n onCheckedChange={handleCheckedChange}\n disabled={disabled}\n invalid={invalid}\n readOnly={readOnly}\n required={required}\n name={name}\n value={value}\n >\n {labelPlacement === 'start' && labelNode}\n <ArkSwitch.Control className=\"ds-switch__control\">\n <ArkSwitch.Thumb className=\"ds-switch__thumb\" />\n </ArkSwitch.Control>\n {labelPlacement === 'end' && labelNode}\n <ArkSwitch.HiddenInput\n role=\"switch\"\n aria-label={ariaLabel}\n aria-describedby={ariaDescribedBy}\n aria-readonly={readOnly || undefined}\n />\n </ArkSwitch.Root>\n );\n}\n"]}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { TableActionsCellProps, TableAlign, TableBodyProps, TableCellProps, TableEmptyProps, TableFootProps, TableHeaderCellProps, TableHeadProps, TableProps, TableRowProps, TableSort, TableToolbarProps, } from './table';
|
|
2
|
+
export { Table, TableActionsCell, TableBody, TableCell, TableEmpty, TableFoot, TableHead, TableHeaderCell, TableRow, TableToolbar, } from './table';
|
|
3
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/table/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,qBAAqB,EACrB,UAAU,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,cAAc,EACd,oBAAoB,EACpB,cAAc,EACd,UAAU,EACV,aAAa,EACb,SAAS,EACT,iBAAiB,GAClB,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,UAAU,EACV,SAAS,EACT,SAAS,EACT,eAAe,EACf,QAAQ,EACR,YAAY,GACb,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/table/index.ts"],"names":[],"mappings":"AAcA,OAAO,EACL,KAAK,EACL,gBAAgB,EAChB,SAAS,EACT,SAAS,EACT,UAAU,EACV,SAAS,EACT,SAAS,EACT,eAAe,EACf,QAAQ,EACR,YAAY,GACb,MAAM,SAAS,CAAC","sourcesContent":["export type {\n TableActionsCellProps,\n TableAlign,\n TableBodyProps,\n TableCellProps,\n TableEmptyProps,\n TableFootProps,\n TableHeaderCellProps,\n TableHeadProps,\n TableProps,\n TableRowProps,\n TableSort,\n TableToolbarProps,\n} from './table';\nexport {\n Table,\n TableActionsCell,\n TableBody,\n TableCell,\n TableEmpty,\n TableFoot,\n TableHead,\n TableHeaderCell,\n TableRow,\n TableToolbar,\n} from './table';\n"]}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
@layer components {
|
|
2
|
+
.ds-table {
|
|
3
|
+
display: flex;
|
|
4
|
+
flex-direction: column;
|
|
5
|
+
gap: var(--ds-layout-gap);
|
|
6
|
+
min-width: 0;
|
|
7
|
+
color: var(--ds-table-text);
|
|
8
|
+
overflow-wrap: anywhere;
|
|
9
|
+
|
|
10
|
+
& .ds-table__toolbar {
|
|
11
|
+
display: flex;
|
|
12
|
+
flex-wrap: wrap;
|
|
13
|
+
align-items: center;
|
|
14
|
+
gap: var(--ds-layout-gap);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
& .ds-table__toolbar-start {
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-wrap: wrap;
|
|
20
|
+
align-items: center;
|
|
21
|
+
gap: var(--ds-layout-gap);
|
|
22
|
+
min-width: 0;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/* The actions keep to the end of the row whether or not a start slot is there. */
|
|
26
|
+
& .ds-table__toolbar-actions {
|
|
27
|
+
display: flex;
|
|
28
|
+
flex-wrap: wrap;
|
|
29
|
+
align-items: center;
|
|
30
|
+
gap: var(--ds-layout-gap);
|
|
31
|
+
margin-inline-start: auto;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
& .ds-table__scroll {
|
|
35
|
+
border: 1px solid var(--ds-table-border);
|
|
36
|
+
border-radius: var(--ds-table-radius);
|
|
37
|
+
background-color: var(--ds-table-bg);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/*
|
|
41
|
+
* Words stay whole inside a table: a column too narrow for its longest
|
|
42
|
+
* word widens and the table scrolls sideways, which the long-words rule
|
|
43
|
+
* allows a sideways scroller, rather than breaking an id or an amount
|
|
44
|
+
* letter by letter.
|
|
45
|
+
*/
|
|
46
|
+
& .ds-table__table {
|
|
47
|
+
width: 100%;
|
|
48
|
+
border-collapse: collapse;
|
|
49
|
+
font-size: var(--ds-table-font-size);
|
|
50
|
+
overflow-wrap: normal;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
& .ds-table__header-cell,
|
|
54
|
+
& .ds-table__cell {
|
|
55
|
+
padding-block: var(--ds-table-cell-padding-block);
|
|
56
|
+
padding-inline: var(--ds-table-cell-padding-inline);
|
|
57
|
+
text-align: start;
|
|
58
|
+
vertical-align: middle;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/* The column heads are labels: the product's small-caps label style. */
|
|
62
|
+
& .ds-table__header-cell {
|
|
63
|
+
border-block-end: 1px solid var(--ds-table-border);
|
|
64
|
+
background-color: var(--ds-table-header-bg);
|
|
65
|
+
color: var(--ds-table-text-muted);
|
|
66
|
+
font-family: var(--ds-text-caps-font-family);
|
|
67
|
+
font-size: var(--ds-text-size-xs-font-size);
|
|
68
|
+
font-weight: var(--ds-text-caps-font-weight);
|
|
69
|
+
line-height: var(--ds-text-size-xs-line-height);
|
|
70
|
+
letter-spacing: var(--ds-text-caps-letter-spacing);
|
|
71
|
+
text-transform: uppercase;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
& .ds-table__header-content {
|
|
75
|
+
display: inline-flex;
|
|
76
|
+
align-items: center;
|
|
77
|
+
gap: var(--ds-layout-gap-tight);
|
|
78
|
+
max-width: 100%;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
& .ds-table__sort {
|
|
82
|
+
display: inline-flex;
|
|
83
|
+
align-items: center;
|
|
84
|
+
gap: var(--ds-layout-gap-tight);
|
|
85
|
+
max-width: 100%;
|
|
86
|
+
padding: 0;
|
|
87
|
+
border: 0;
|
|
88
|
+
background-color: transparent;
|
|
89
|
+
color: inherit;
|
|
90
|
+
font: inherit;
|
|
91
|
+
letter-spacing: inherit;
|
|
92
|
+
text-align: inherit;
|
|
93
|
+
text-transform: inherit;
|
|
94
|
+
cursor: pointer;
|
|
95
|
+
|
|
96
|
+
&:hover,
|
|
97
|
+
&[data-sort="ascending"],
|
|
98
|
+
&[data-sort="descending"] {
|
|
99
|
+
color: var(--ds-table-text);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
&:focus-visible {
|
|
103
|
+
outline: 2px solid var(--ds-table-focus-ring);
|
|
104
|
+
outline-offset: 2px;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/*
|
|
109
|
+
* One glyph, the product's right chevron, turned to point up for
|
|
110
|
+
* ascending and down for descending. An unsorted sortable column shows
|
|
111
|
+
* both, at three-quarter size, so it reads as sortable before it is pressed.
|
|
112
|
+
*/
|
|
113
|
+
& .ds-table__sort-indicator {
|
|
114
|
+
display: inline-grid;
|
|
115
|
+
place-items: center;
|
|
116
|
+
color: var(--ds-table-text-muted);
|
|
117
|
+
|
|
118
|
+
& > * {
|
|
119
|
+
grid-area: 1 / 1;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
& .ds-table__sort[data-sort="ascending"] .ds-table__sort-indicator > * {
|
|
124
|
+
transform: rotate(-90deg);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
& .ds-table__sort[data-sort="descending"] .ds-table__sort-indicator > * {
|
|
128
|
+
transform: rotate(90deg);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
& .ds-table__sort[data-sort="none"] .ds-table__sort-indicator {
|
|
132
|
+
& > :first-child {
|
|
133
|
+
transform: translateY(-30%) rotate(-90deg) scale(0.75);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
& > :last-child {
|
|
137
|
+
transform: translateY(30%) rotate(90deg) scale(0.75);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
& .ds-table__cell--end {
|
|
142
|
+
text-align: end;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/* Figures line up digit under digit; a number never breaks across lines in the sideways scroller. */
|
|
146
|
+
& .ds-table__cell--numeric {
|
|
147
|
+
font-variant-numeric: tabular-nums;
|
|
148
|
+
white-space: nowrap;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
& .ds-table__cell--row-header {
|
|
152
|
+
font-weight: inherit;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/* As narrow as its buttons, at the end of the row. */
|
|
156
|
+
& .ds-table__cell--actions {
|
|
157
|
+
width: 1%;
|
|
158
|
+
text-align: end;
|
|
159
|
+
white-space: nowrap;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
& .ds-table__actions {
|
|
163
|
+
display: inline-flex;
|
|
164
|
+
align-items: center;
|
|
165
|
+
gap: var(--ds-layout-gap-tight);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
& .ds-table__body .ds-table__row + .ds-table__row {
|
|
169
|
+
border-block-start: 1px solid var(--ds-table-border);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
&.ds-table--striped .ds-table__body .ds-table__row:nth-child(even) {
|
|
173
|
+
background-color: var(--ds-table-row-bg-striped);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/*
|
|
177
|
+
* A layer over the row's own fill rather than a replacement for it, so a
|
|
178
|
+
* translucent highlight tints a striped row instead of matching its stripe.
|
|
179
|
+
*/
|
|
180
|
+
&.ds-table--row-hover .ds-table__body .ds-table__row:not(.ds-table__empty):hover {
|
|
181
|
+
background-image: linear-gradient(var(--ds-table-row-bg-hover), var(--ds-table-row-bg-hover));
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
& .ds-table__foot {
|
|
185
|
+
border-block-start: 1px solid var(--ds-table-border);
|
|
186
|
+
font-weight: var(--ds-table-footer-font-weight);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { type ComponentProps, type ReactNode } from 'react';
|
|
2
|
+
import './table.css';
|
|
3
|
+
/** Where a column's content sits: text at the start, numbers at the end. */
|
|
4
|
+
export type TableAlign = 'start' | 'end';
|
|
5
|
+
/** A sortable column's state. `none` is sortable but not the sort in force. */
|
|
6
|
+
export type TableSort = 'ascending' | 'descending' | 'none';
|
|
7
|
+
export interface TableProps extends ComponentProps<'div'> {
|
|
8
|
+
/**
|
|
9
|
+
* The table's name, required: it names the table for a screen reader and
|
|
10
|
+
* the scroll region around it, which takes keyboard focus so a table wider
|
|
11
|
+
* than its column can be scrolled with the arrow keys.
|
|
12
|
+
*/
|
|
13
|
+
label: string;
|
|
14
|
+
/** Tint every other body row, so a long row is easier to follow across. */
|
|
15
|
+
striped?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Highlight the body row under the pointer, to read it across or compare
|
|
18
|
+
* it with its neighbours. Not a sign that the row is clickable: a row that
|
|
19
|
+
* opens something puts a link in its first cell.
|
|
20
|
+
*/
|
|
21
|
+
rowHover?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* What sits above the table: a {@link TableToolbar} with the table's
|
|
24
|
+
* actions (add a row, history), and optionally a search or filter at its
|
|
25
|
+
* start.
|
|
26
|
+
*/
|
|
27
|
+
toolbar?: ReactNode;
|
|
28
|
+
/** The rows are loading: marks the table busy while skeleton rows stand in. */
|
|
29
|
+
busy?: boolean;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Rows and columns of data in a real `<table>`, so a screen reader can move
|
|
33
|
+
* by row and column and announce each cell's column.
|
|
34
|
+
*
|
|
35
|
+
* A structural primitive, styled against the `--ds-table-*` contract. It
|
|
36
|
+
* holds no data and no sorting of its own: the product passes the rows in
|
|
37
|
+
* the order it wants and owns the sort and filter state, which on a server-
|
|
38
|
+
* paged list is the only place it can live.
|
|
39
|
+
*
|
|
40
|
+
* Compose with {@link TableHead}, {@link TableBody} and {@link TableFoot},
|
|
41
|
+
* made of {@link TableRow}s holding {@link TableHeaderCell}s and
|
|
42
|
+
* {@link TableCell}s; {@link TableActionsCell} holds a row's icon buttons and
|
|
43
|
+
* {@link TableEmpty} stands in for the rows when there are none.
|
|
44
|
+
*
|
|
45
|
+
* The table scrolls sideways inside its box when its columns don't fit, so a
|
|
46
|
+
* phone keeps every column instead of squeezing them. `className` and the
|
|
47
|
+
* other props go to that box, which holds the toolbar and the table.
|
|
48
|
+
*/
|
|
49
|
+
export declare function Table({ label, striped, rowHover, toolbar, busy, className, children, ...props }: TableProps): import("react/jsx-runtime").JSX.Element;
|
|
50
|
+
export interface TableToolbarProps extends ComponentProps<'div'> {
|
|
51
|
+
/** What sits at the start of the row: a search or a filter for the whole table. */
|
|
52
|
+
start?: ReactNode;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The row above a table: its actions at the end (add a row, history,
|
|
56
|
+
* export), and optionally a search or filter at the start. Pass it to
|
|
57
|
+
* {@link Table}'s `toolbar`.
|
|
58
|
+
*/
|
|
59
|
+
export declare function TableToolbar({ start, className, children, ...props }: TableToolbarProps): import("react/jsx-runtime").JSX.Element;
|
|
60
|
+
export type TableHeadProps = ComponentProps<'thead'>;
|
|
61
|
+
/** The column heads: a {@link TableRow} of {@link TableHeaderCell}s. */
|
|
62
|
+
export declare function TableHead({ className, children, ...props }: TableHeadProps): import("react/jsx-runtime").JSX.Element;
|
|
63
|
+
export type TableBodyProps = ComponentProps<'tbody'>;
|
|
64
|
+
/** The data rows. */
|
|
65
|
+
export declare function TableBody({ className, children, ...props }: TableBodyProps): import("react/jsx-runtime").JSX.Element;
|
|
66
|
+
export type TableFootProps = ComponentProps<'tfoot'>;
|
|
67
|
+
/** A totals row under the data, set apart by a rule and the footer weight. */
|
|
68
|
+
export declare function TableFoot({ className, children, ...props }: TableFootProps): import("react/jsx-runtime").JSX.Element;
|
|
69
|
+
export type TableRowProps = ComponentProps<'tr'>;
|
|
70
|
+
/** One row of cells. */
|
|
71
|
+
export declare function TableRow({ className, children, ...props }: TableRowProps): import("react/jsx-runtime").JSX.Element;
|
|
72
|
+
/** A sortable column's state and its handler, which come together or not at all. */
|
|
73
|
+
type TableHeaderCellSorting = {
|
|
74
|
+
sort?: undefined;
|
|
75
|
+
onSortChange?: undefined;
|
|
76
|
+
} | {
|
|
77
|
+
/**
|
|
78
|
+
* Makes the column sortable and says how it is sorted now. The head
|
|
79
|
+
* becomes a button, and the sorted column carries `aria-sort`.
|
|
80
|
+
*/
|
|
81
|
+
sort: TableSort;
|
|
82
|
+
/**
|
|
83
|
+
* Called with the direction a press asks for: `ascending` from an
|
|
84
|
+
* unsorted or descending column, `descending` from an ascending one.
|
|
85
|
+
* The product sorts its rows and passes the new `sort` back.
|
|
86
|
+
*/
|
|
87
|
+
onSortChange: (next: Exclude<TableSort, 'none'>) => void;
|
|
88
|
+
};
|
|
89
|
+
export type TableHeaderCellProps = Omit<ComponentProps<'th'>, 'align'> & TableHeaderCellSorting & {
|
|
90
|
+
/** Where the head sits: at the end over a column of numbers. Defaults to `start`. */
|
|
91
|
+
align?: TableAlign;
|
|
92
|
+
/**
|
|
93
|
+
* A control after the label that filters this column, typically an
|
|
94
|
+
* `IconButton` opening a `Popover`. It stays outside the sort button, so
|
|
95
|
+
* opening the filter never re-sorts, and out of the column's name.
|
|
96
|
+
*/
|
|
97
|
+
filter?: ReactNode;
|
|
98
|
+
};
|
|
99
|
+
/**
|
|
100
|
+
* A column's head, a `th` scoped to its column, in the small-caps label
|
|
101
|
+
* style. With `sort` it is a button that re-sorts the column; with `filter`
|
|
102
|
+
* it carries the column's filter control beside the label. The column is
|
|
103
|
+
* named by its label alone, so each of its cells is announced with that.
|
|
104
|
+
*/
|
|
105
|
+
export declare function TableHeaderCell({ align, sort, onSortChange, filter, className, children, ...props }: TableHeaderCellProps): import("react/jsx-runtime").JSX.Element;
|
|
106
|
+
export interface TableCellProps extends Omit<ComponentProps<'td'>, 'align'> {
|
|
107
|
+
/** Where the content sits. Defaults to `start`; `numeric` puts it at the end. */
|
|
108
|
+
align?: TableAlign;
|
|
109
|
+
/**
|
|
110
|
+
* A number: set at the end of the cell with tabular figures, so a column
|
|
111
|
+
* of amounts lines up digit under digit. Format it (currency, decimals)
|
|
112
|
+
* before passing it in.
|
|
113
|
+
*/
|
|
114
|
+
numeric?: boolean;
|
|
115
|
+
/**
|
|
116
|
+
* The cell that names its row, rendered as a `th` scoped to the row, so a
|
|
117
|
+
* screen reader announces it with each of the row's other cells.
|
|
118
|
+
*/
|
|
119
|
+
rowHeader?: boolean;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* One cell of data: text by default, a number with `numeric`, or the row's
|
|
123
|
+
* name with `rowHeader`. A date, a status (`Badge`) or a link to the row's
|
|
124
|
+
* page (`Link`) goes inside as content.
|
|
125
|
+
*/
|
|
126
|
+
export declare function TableCell({ align, numeric, rowHeader, className, children, ...props }: TableCellProps): import("react/jsx-runtime").JSX.Element;
|
|
127
|
+
export type TableActionsCellProps = Omit<TableCellProps, 'align' | 'numeric' | 'rowHeader'>;
|
|
128
|
+
/**
|
|
129
|
+
* The row's actions at the end of the row: up to two `IconButton`s, and an
|
|
130
|
+
* `ActionMenu` for any more, so the column stays narrow. Name each button
|
|
131
|
+
* after its row ("Delete Stratechery"), since the column head can't.
|
|
132
|
+
*/
|
|
133
|
+
export declare function TableActionsCell({ className, children, ...props }: TableActionsCellProps): import("react/jsx-runtime").JSX.Element;
|
|
134
|
+
export interface TableEmptyProps extends ComponentProps<'tr'> {
|
|
135
|
+
/** How many columns the table has, so the message spans all of them. */
|
|
136
|
+
colSpan: number;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Stands in for the body's rows when there are none: one row whose single
|
|
140
|
+
* cell spans every column, holding an `EmptyState` that says why.
|
|
141
|
+
*/
|
|
142
|
+
export declare function TableEmpty({ colSpan, className, children, ...props }: TableEmptyProps): import("react/jsx-runtime").JSX.Element;
|
|
143
|
+
export {};
|
|
144
|
+
//# sourceMappingURL=table.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../src/table/table.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,SAAS,EAAS,MAAM,OAAO,CAAC;AACnE,OAAO,aAAa,CAAC;AAMrB,4EAA4E;AAC5E,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,KAAK,CAAC;AAEzC,+EAA+E;AAC/E,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG,YAAY,GAAG,MAAM,CAAC;AAE5D,MAAM,WAAW,UAAW,SAAQ,cAAc,CAAC,KAAK,CAAC;IACvD;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC;IACd,2EAA2E;IAC3E,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;;OAIG;IACH,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,+EAA+E;IAC/E,IAAI,CAAC,EAAE,OAAO,CAAC;CAChB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,KAAK,CAAC,EACpB,KAAK,EACL,OAAe,EACf,QAAgB,EAChB,OAAO,EACP,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AAE,eAAe,2CAQrF"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from 'react';
|
|
3
|
+
import './table.css';
|
|
4
|
+
import { cx } from '../cx';
|
|
5
|
+
import { Icon } from '../icon/icon';
|
|
6
|
+
import { useIconDefaults } from '../icon-defaults';
|
|
7
|
+
import { ScrollArea } from '../scroll-area/scroll-area';
|
|
8
|
+
/**
|
|
9
|
+
* Rows and columns of data in a real `<table>`, so a screen reader can move
|
|
10
|
+
* by row and column and announce each cell's column.
|
|
11
|
+
*
|
|
12
|
+
* A structural primitive, styled against the `--ds-table-*` contract. It
|
|
13
|
+
* holds no data and no sorting of its own: the product passes the rows in
|
|
14
|
+
* the order it wants and owns the sort and filter state, which on a server-
|
|
15
|
+
* paged list is the only place it can live.
|
|
16
|
+
*
|
|
17
|
+
* Compose with {@link TableHead}, {@link TableBody} and {@link TableFoot},
|
|
18
|
+
* made of {@link TableRow}s holding {@link TableHeaderCell}s and
|
|
19
|
+
* {@link TableCell}s; {@link TableActionsCell} holds a row's icon buttons and
|
|
20
|
+
* {@link TableEmpty} stands in for the rows when there are none.
|
|
21
|
+
*
|
|
22
|
+
* The table scrolls sideways inside its box when its columns don't fit, so a
|
|
23
|
+
* phone keeps every column instead of squeezing them. `className` and the
|
|
24
|
+
* other props go to that box, which holds the toolbar and the table.
|
|
25
|
+
*/
|
|
26
|
+
export function Table({ label, striped = false, rowHover = false, toolbar, busy = false, className, children, ...props }) {
|
|
27
|
+
return (_jsxs("div", { className: cx('ds-table', striped && 'ds-table--striped', rowHover && 'ds-table--row-hover', className), ...props, children: [toolbar, _jsx(ScrollArea, { axis: "x", className: "ds-table__scroll", label: label, children: _jsx("table", { "aria-busy": busy || undefined, "aria-label": label, className: "ds-table__table", children: children }) })] }));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The row above a table: its actions at the end (add a row, history,
|
|
31
|
+
* export), and optionally a search or filter at the start. Pass it to
|
|
32
|
+
* {@link Table}'s `toolbar`.
|
|
33
|
+
*/
|
|
34
|
+
export function TableToolbar({ start, className, children, ...props }) {
|
|
35
|
+
return (_jsxs("div", { className: cx('ds-table__toolbar', className), ...props, children: [start ? _jsx("div", { className: "ds-table__toolbar-start", children: start }) : null, _jsx("div", { className: "ds-table__toolbar-actions", children: children })] }));
|
|
36
|
+
}
|
|
37
|
+
/** The column heads: a {@link TableRow} of {@link TableHeaderCell}s. */
|
|
38
|
+
export function TableHead({ className, children, ...props }) {
|
|
39
|
+
return (_jsx("thead", { className: cx('ds-table__head', className), ...props, children: children }));
|
|
40
|
+
}
|
|
41
|
+
/** The data rows. */
|
|
42
|
+
export function TableBody({ className, children, ...props }) {
|
|
43
|
+
return (_jsx("tbody", { className: cx('ds-table__body', className), ...props, children: children }));
|
|
44
|
+
}
|
|
45
|
+
/** A totals row under the data, set apart by a rule and the footer weight. */
|
|
46
|
+
export function TableFoot({ className, children, ...props }) {
|
|
47
|
+
return (_jsx("tfoot", { className: cx('ds-table__foot', className), ...props, children: children }));
|
|
48
|
+
}
|
|
49
|
+
/** One row of cells. */
|
|
50
|
+
export function TableRow({ className, children, ...props }) {
|
|
51
|
+
return (_jsx("tr", { className: cx('ds-table__row', className), ...props, children: children }));
|
|
52
|
+
}
|
|
53
|
+
const ARIA_SORT = { ascending: 'ascending', descending: 'descending', none: undefined };
|
|
54
|
+
/**
|
|
55
|
+
* A column's head, a `th` scoped to its column, in the small-caps label
|
|
56
|
+
* style. With `sort` it is a button that re-sorts the column; with `filter`
|
|
57
|
+
* it carries the column's filter control beside the label. The column is
|
|
58
|
+
* named by its label alone, so each of its cells is announced with that.
|
|
59
|
+
*/
|
|
60
|
+
export function TableHeaderCell({ align = 'start', sort, onSortChange, filter, className, children, ...props }) {
|
|
61
|
+
const icons = useIconDefaults();
|
|
62
|
+
const labelId = useId();
|
|
63
|
+
const text = (_jsx("span", { className: "ds-table__header-label", id: labelId, children: children }));
|
|
64
|
+
const label = sort === undefined ? (text) : (_jsxs("button", { className: "ds-table__sort", "data-sort": sort, onClick: () => onSortChange(sort === 'ascending' ? 'descending' : 'ascending'), type: "button", children: [text, _jsxs("span", { "aria-hidden": "true", className: "ds-table__sort-indicator", children: [_jsx(Icon, { decorative: true, size: "sm", source: icons.chevronRight }), sort === 'none' ? _jsx(Icon, { decorative: true, size: "sm", source: icons.chevronRight }) : null] })] }));
|
|
65
|
+
return (_jsx("th", { "aria-labelledby": labelId, "aria-sort": sort === undefined ? undefined : ARIA_SORT[sort], className: cx('ds-table__header-cell', align === 'end' && 'ds-table__cell--end', className), scope: "col", ...props, children: _jsxs("span", { className: "ds-table__header-content", children: [label, filter] }) }));
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* One cell of data: text by default, a number with `numeric`, or the row's
|
|
69
|
+
* name with `rowHeader`. A date, a status (`Badge`) or a link to the row's
|
|
70
|
+
* page (`Link`) goes inside as content.
|
|
71
|
+
*/
|
|
72
|
+
export function TableCell({ align, numeric = false, rowHeader = false, className, children, ...props }) {
|
|
73
|
+
const end = (align ?? (numeric ? 'end' : 'start')) === 'end';
|
|
74
|
+
const classes = cx('ds-table__cell', end && 'ds-table__cell--end', numeric && 'ds-table__cell--numeric', rowHeader && 'ds-table__cell--row-header', className);
|
|
75
|
+
if (rowHeader) {
|
|
76
|
+
return (_jsx("th", { className: classes, scope: "row", ...props, children: children }));
|
|
77
|
+
}
|
|
78
|
+
return (_jsx("td", { className: classes, ...props, children: children }));
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* The row's actions at the end of the row: up to two `IconButton`s, and an
|
|
82
|
+
* `ActionMenu` for any more, so the column stays narrow. Name each button
|
|
83
|
+
* after its row ("Delete Stratechery"), since the column head can't.
|
|
84
|
+
*/
|
|
85
|
+
export function TableActionsCell({ className, children, ...props }) {
|
|
86
|
+
return (_jsx("td", { className: cx('ds-table__cell', 'ds-table__cell--actions', className), ...props, children: _jsx("span", { className: "ds-table__actions", children: children }) }));
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Stands in for the body's rows when there are none: one row whose single
|
|
90
|
+
* cell spans every column, holding an `EmptyState` that says why.
|
|
91
|
+
*/
|
|
92
|
+
export function TableEmpty({ colSpan, className, children, ...props }) {
|
|
93
|
+
return (_jsx("tr", { className: cx('ds-table__row', 'ds-table__empty', className), ...props, children: _jsx("td", { className: "ds-table__cell", colSpan: colSpan, children: children }) }));
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=table.js.map
|