@underpin/ui 0.0.0 → 2.1.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/LICENSE +21 -0
- package/README.md +44 -1
- package/components/autocomplete.d.ts +25 -0
- package/components/autocomplete.js +71 -0
- package/components/autocomplete.js.map +1 -0
- package/components/avatar.d.ts +5 -0
- package/components/avatar.js +26 -0
- package/components/avatar.js.map +1 -0
- package/components/badge.d.ts +36 -0
- package/components/badge.js +140 -0
- package/components/badge.js.map +1 -0
- package/components/bar-list.d.ts +133 -0
- package/components/bar-list.js +204 -0
- package/components/bar-list.js.map +1 -0
- package/components/breakdown-card.d.ts +30 -0
- package/components/breakdown-card.js +43 -0
- package/components/breakdown-card.js.map +1 -0
- package/components/bulk-action-bar.d.ts +21 -0
- package/components/bulk-action-bar.js +38 -0
- package/components/bulk-action-bar.js.map +1 -0
- package/components/button-group.d.ts +21 -0
- package/components/button-group.js +32 -0
- package/components/button-group.js.map +1 -0
- package/components/button.d.ts +39 -0
- package/components/button.js +145 -0
- package/components/button.js.map +1 -0
- package/components/calendar.d.ts +27 -0
- package/components/calendar.js +95 -0
- package/components/calendar.js.map +1 -0
- package/components/callout.d.ts +26 -0
- package/components/callout.js +71 -0
- package/components/callout.js.map +1 -0
- package/components/card.d.ts +55 -0
- package/components/card.js +96 -0
- package/components/card.js.map +1 -0
- package/components/chart.d.ts +32 -0
- package/components/chart.js +43 -0
- package/components/chart.js.map +1 -0
- package/components/checkbox.d.ts +15 -0
- package/components/checkbox.js +42 -0
- package/components/checkbox.js.map +1 -0
- package/components/code-block.d.ts +21 -0
- package/components/code-block.js +35 -0
- package/components/code-block.js.map +1 -0
- package/components/collapse.d.ts +14 -0
- package/components/collapse.js +25 -0
- package/components/collapse.js.map +1 -0
- package/components/combobox.d.ts +71 -0
- package/components/combobox.js +155 -0
- package/components/combobox.js.map +1 -0
- package/components/copy-button.d.ts +29 -0
- package/components/copy-button.js +100 -0
- package/components/copy-button.js.map +1 -0
- package/components/copy-input.d.ts +15 -0
- package/components/copy-input.js +51 -0
- package/components/copy-input.js.map +1 -0
- package/components/data-table.d.ts +120 -0
- package/components/data-table.js +336 -0
- package/components/data-table.js.map +1 -0
- package/components/date-picker-trigger.d.ts +12 -0
- package/components/date-picker-trigger.js +30 -0
- package/components/date-picker-trigger.js.map +1 -0
- package/components/date-picker.d.ts +36 -0
- package/components/date-picker.js +70 -0
- package/components/date-picker.js.map +1 -0
- package/components/detail-row.d.ts +51 -0
- package/components/detail-row.js +77 -0
- package/components/detail-row.js.map +1 -0
- package/components/dialog.d.ts +121 -0
- package/components/dialog.js +327 -0
- package/components/dialog.js.map +1 -0
- package/components/disabled-reason.d.ts +31 -0
- package/components/disabled-reason.js +67 -0
- package/components/disabled-reason.js.map +1 -0
- package/components/empty-state.d.ts +41 -0
- package/components/empty-state.js +84 -0
- package/components/empty-state.js.map +1 -0
- package/components/entity-avatar.d.ts +54 -0
- package/components/entity-avatar.js +68 -0
- package/components/entity-avatar.js.map +1 -0
- package/components/form-section.d.ts +22 -0
- package/components/form-section.js +38 -0
- package/components/form-section.js.map +1 -0
- package/components/form.d.ts +199 -0
- package/components/form.js +456 -0
- package/components/form.js.map +1 -0
- package/components/formatted-number.d.ts +21 -0
- package/components/formatted-number.js +13 -0
- package/components/formatted-number.js.map +1 -0
- package/components/heading.d.ts +23 -0
- package/components/heading.js +44 -0
- package/components/heading.js.map +1 -0
- package/components/icon-swap.d.ts +15 -0
- package/components/icon-swap.js +29 -0
- package/components/icon-swap.js.map +1 -0
- package/components/inline-action.d.ts +21 -0
- package/components/inline-action.js +36 -0
- package/components/inline-action.js.map +1 -0
- package/components/input.d.ts +51 -0
- package/components/input.js +52 -0
- package/components/input.js.map +1 -0
- package/components/kbd.d.ts +17 -0
- package/components/kbd.js +34 -0
- package/components/kbd.js.map +1 -0
- package/components/label.d.ts +10 -0
- package/components/label.js +20 -0
- package/components/label.js.map +1 -0
- package/components/menu.d.ts +77 -0
- package/components/menu.js +189 -0
- package/components/menu.js.map +1 -0
- package/components/nav-button.d.ts +34 -0
- package/components/nav-button.js +71 -0
- package/components/nav-button.js.map +1 -0
- package/components/nav.d.ts +39 -0
- package/components/nav.js +68 -0
- package/components/nav.js.map +1 -0
- package/components/number-input.d.ts +16 -0
- package/components/number-input.js +25 -0
- package/components/number-input.js.map +1 -0
- package/components/page.d.ts +14 -0
- package/components/page.js +23 -0
- package/components/page.js.map +1 -0
- package/components/pagination.d.ts +73 -0
- package/components/pagination.js +212 -0
- package/components/pagination.js.map +1 -0
- package/components/ping.d.ts +38 -0
- package/components/ping.js +50 -0
- package/components/ping.js.map +1 -0
- package/components/popover.d.ts +5 -0
- package/components/popover.js +25 -0
- package/components/popover.js.map +1 -0
- package/components/radio-group.d.ts +35 -0
- package/components/radio-group.js +81 -0
- package/components/radio-group.js.map +1 -0
- package/components/relative-time.d.ts +25 -0
- package/components/relative-time.js +51 -0
- package/components/relative-time.js.map +1 -0
- package/components/saved-mark.d.ts +15 -0
- package/components/saved-mark.js +45 -0
- package/components/saved-mark.js.map +1 -0
- package/components/search-input.d.ts +13 -0
- package/components/search-input.js +44 -0
- package/components/search-input.js.map +1 -0
- package/components/section-header.d.ts +83 -0
- package/components/section-header.js +170 -0
- package/components/section-header.js.map +1 -0
- package/components/segmented-control.d.ts +24 -0
- package/components/segmented-control.js +70 -0
- package/components/segmented-control.js.map +1 -0
- package/components/select.d.ts +28 -0
- package/components/select.js +129 -0
- package/components/select.js.map +1 -0
- package/components/shortcut-keys.d.ts +14 -0
- package/components/shortcut-keys.js +32 -0
- package/components/shortcut-keys.js.map +1 -0
- package/components/shortcuts-dialog.d.ts +10 -0
- package/components/shortcuts-dialog.js +92 -0
- package/components/shortcuts-dialog.js.map +1 -0
- package/components/skeleton.d.ts +8 -0
- package/components/skeleton.js +23 -0
- package/components/skeleton.js.map +1 -0
- package/components/sparkline.d.ts +25 -0
- package/components/sparkline.js +70 -0
- package/components/sparkline.js.map +1 -0
- package/components/stack.d.ts +21 -0
- package/components/stack.js +45 -0
- package/components/stack.js.map +1 -0
- package/components/stat-strip.d.ts +43 -0
- package/components/stat-strip.js +151 -0
- package/components/stat-strip.js.map +1 -0
- package/components/steps.d.ts +19 -0
- package/components/steps.js +25 -0
- package/components/steps.js.map +1 -0
- package/components/switch.d.ts +16 -0
- package/components/switch.js +29 -0
- package/components/switch.js.map +1 -0
- package/components/table-toolbar.d.ts +55 -0
- package/components/table-toolbar.js +119 -0
- package/components/table-toolbar.js.map +1 -0
- package/components/table.d.ts +276 -0
- package/components/table.js +572 -0
- package/components/table.js.map +1 -0
- package/components/tabs.d.ts +36 -0
- package/components/tabs.js +120 -0
- package/components/tabs.js.map +1 -0
- package/components/text-link.d.ts +16 -0
- package/components/text-link.js +32 -0
- package/components/text-link.js.map +1 -0
- package/components/textarea.d.ts +10 -0
- package/components/textarea.js +23 -0
- package/components/textarea.js.map +1 -0
- package/components/theme.d.ts +28 -0
- package/components/theme.js +158 -0
- package/components/theme.js.map +1 -0
- package/components/time-series-chart.d.ts +122 -0
- package/components/time-series-chart.js +722 -0
- package/components/time-series-chart.js.map +1 -0
- package/components/toaster.d.ts +3 -0
- package/components/toaster.js +44 -0
- package/components/toaster.js.map +1 -0
- package/components/tooltip.d.ts +64 -0
- package/components/tooltip.js +126 -0
- package/components/tooltip.js.map +1 -0
- package/components/view-picker.d.ts +20 -0
- package/components/view-picker.js +24 -0
- package/components/view-picker.js.map +1 -0
- package/fonts/inter-OFL.txt +93 -0
- package/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/fonts/inter-cyrillic.woff2 +0 -0
- package/fonts/inter-greek-ext.woff2 +0 -0
- package/fonts/inter-greek.woff2 +0 -0
- package/fonts/inter-latin-ext.woff2 +0 -0
- package/fonts/inter-latin.woff2 +0 -0
- package/fonts/inter-vietnamese.woff2 +0 -0
- package/fonts.css +83 -0
- package/lib/animation.d.ts +14 -0
- package/lib/animation.js +20 -0
- package/lib/animation.js.map +1 -0
- package/lib/aria.d.ts +5 -0
- package/lib/aria.js +12 -0
- package/lib/aria.js.map +1 -0
- package/lib/chart-curve.d.ts +13 -0
- package/lib/chart-curve.js +79 -0
- package/lib/chart-curve.js.map +1 -0
- package/lib/classes.d.ts +134 -0
- package/lib/classes.js +152 -0
- package/lib/classes.js.map +1 -0
- package/lib/color.d.ts +25 -0
- package/lib/color.js +149 -0
- package/lib/color.js.map +1 -0
- package/lib/data-table-state.d.ts +87 -0
- package/lib/data-table-state.js +92 -0
- package/lib/data-table-state.js.map +1 -0
- package/lib/day.d.ts +9 -0
- package/lib/day.js +20 -0
- package/lib/day.js.map +1 -0
- package/lib/design-tokens.d.ts +56 -0
- package/lib/design-tokens.js +196 -0
- package/lib/design-tokens.js.map +1 -0
- package/lib/icon.d.ts +17 -0
- package/lib/icon.js +34 -0
- package/lib/icon.js.map +1 -0
- package/lib/icons.d.ts +29 -0
- package/lib/icons.js +34 -0
- package/lib/icons.js.map +1 -0
- package/lib/interactive.d.ts +21 -0
- package/lib/interactive.js +31 -0
- package/lib/interactive.js.map +1 -0
- package/lib/load-more.d.ts +14 -0
- package/lib/load-more.js +27 -0
- package/lib/load-more.js.map +1 -0
- package/lib/media.d.ts +58 -0
- package/lib/media.js +116 -0
- package/lib/media.js.map +1 -0
- package/lib/segmented.d.ts +57 -0
- package/lib/segmented.js +83 -0
- package/lib/segmented.js.map +1 -0
- package/lib/shortcuts.d.ts +94 -0
- package/lib/shortcuts.js +271 -0
- package/lib/shortcuts.js.map +1 -0
- package/lib/slot.d.ts +9 -0
- package/lib/slot.js +18 -0
- package/lib/slot.js.map +1 -0
- package/lib/time-series.d.ts +100 -0
- package/lib/time-series.js +144 -0
- package/lib/time-series.js.map +1 -0
- package/lib/tone.d.ts +6 -0
- package/lib/tone.js +0 -0
- package/lib/variants.d.ts +12 -0
- package/lib/variants.js +14 -0
- package/lib/variants.js.map +1 -0
- package/package.json +122 -3
- package/styles.css +630 -0
- package/tokens.d.ts +104 -0
- package/tokens.js +108 -0
- package/tokens.js.map +1 -0
- package/publish.log +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"design-tokens.js","names":[],"sources":["../../src/lib/design-tokens.ts"],"sourcesContent":["import {\n formatHex,\n readColorNames,\n readToken,\n splitTopLevel,\n toSrgb,\n type Oklch,\n type Rgb,\n type Theme,\n} from \"./color\"\n\n/*\n * The stylesheet's tokens as one JSON document for the Figma library: every colour per theme,\n * every shadow layer, the type scale, radii and spacing. Figma names follow the CSS names by one\n * rule, the prefix becomes the group (`--color-ink-muted` is `color/ink-muted`), so a script can\n * apply the document to the library and nobody names a variable by hand. Radii, spacing and\n * Tailwind's own type steps come from Tailwind's `theme.css`, which the stylesheet builds on.\n */\n\ninterface Paint {\n hex: string\n alpha: number\n}\n\ninterface ColorToken {\n name: string\n css: string\n description?: string\n /** The Figma variable this one points at, when the CSS value is a bare `var()` of another. */\n alias?: string\n light: Paint\n dark: Paint\n}\n\ninterface ShadowLayer {\n offsetX: number\n offsetY: number\n blur: number\n spread: number\n /** Drawn inside the box rather than under it. */\n inset?: boolean\n /** The colour variable the layer is bound to; `light` and `dark` are its resolved values. */\n variable?: string\n light: Paint\n dark: Paint\n}\n\ninterface ShadowToken {\n name: string\n css: string\n description?: string\n layers: ShadowLayer[]\n}\n\ninterface TextToken {\n name: string\n css: string\n size: number\n lineHeight: number\n}\n\ninterface NumberToken {\n name: string\n css: string\n value: number\n}\n\ninterface Declaration {\n value: string\n description?: string\n}\n\nexport interface DesignTokens {\n fonts: { sans: string; mono: string }\n colors: ColorToken[]\n shadows: ShadowToken[]\n text: TextToken[]\n tracking: NumberToken[]\n radius: NumberToken[]\n spacing: NumberToken[]\n}\n\nconst REM = 16\n// Tailwind's steps the library draws with. Tailwind holds their values.\nconst TAILWIND_TEXT = [\"xs\", \"sm\", \"base\", \"lg\", \"xl\", \"2xl\", \"3xl\", \"4xl\"]\nconst RADIUS_STEPS = [\"xs\", \"sm\", \"md\", \"lg\", \"xl\"]\nconst SPACING_STEPS = [0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 5, 6, 8, 10, 12]\n\n/**\n * Every custom property in a stylesheet, in source order, with the comment above its group.\n * A comment applies to the declarations under it until a blank line.\n */\nfunction readDeclarations(css: string) {\n const declarations = new Map<string, Declaration>()\n let comment: string | undefined\n\n for (const match of css.matchAll(/(\\/\\*[\\s\\S]*?\\*\\/)|(\\n\\s*\\n)|--([a-z0-9-]+):\\s*([^;]+);/g)) {\n const [, block, blank, name, value] = match\n if (block) {\n comment = block\n .replace(/^\\/\\*+|\\*+\\/$/g, \"\")\n .split(\"\\n\")\n .map(line => line.replace(/^\\s*\\*\\s?/, \"\").trim())\n .filter(Boolean)\n .join(\" \")\n } else if (blank) {\n comment = undefined\n } else if (name && value && !declarations.has(name)) {\n declarations.set(name, { value: value.replace(/\\s+/g, \" \").trim(), description: comment })\n }\n }\n\n return declarations\n}\n\nfunction toPaint(oklch: Oklch): Paint {\n return { hex: formatHex(toSrgb(oklch)), alpha: Math.round(oklch.alpha * 1000) / 1000 }\n}\n\nfunction toPaints(color: Record<Theme, Oklch>): Record<Theme, Paint> {\n return { light: toPaint(color.light), dark: toPaint(color.dark) }\n}\n\nfunction toFigmaName(name: string) {\n return name.replace(/^(color|gray|shadow|text|tracking|radius|spacing)-/, \"$1/\")\n}\n\nfunction readPixels(value: string) {\n return Number.parseFloat(value) * (value.endsWith(\"rem\") ? REM : 1)\n}\n\nfunction readShadowLayers(\n css: string,\n name: string,\n declarations: Map<string, Declaration>,\n): ShadowLayer[] {\n const value = declarations.get(name)?.value ?? \"\"\n\n return splitTopLevel(value).flatMap(layer => {\n const nested = layer.match(/^var\\(--(shadow-[a-z0-9-]+)\\)$/)?.[1]\n if (nested) return readShadowLayers(css, nested, declarations)\n\n const inset = layer.startsWith(\"inset \")\n const [, lengths = \"\", color = \"\"] =\n layer.replace(/^inset /, \"\").match(/^([-\\d.px ]+?)\\s+((?:var|rgb)\\(.+\\))$/) ?? []\n const [offsetX = 0, offsetY = 0, blur = 0, spread = 0] = lengths\n .trim()\n .split(/\\s+/)\n .map(readPixels)\n const variable = color.match(/^var\\(--([a-z0-9-]+)\\)$/)?.[1]\n if (variable) {\n return [\n {\n offsetX,\n offsetY,\n blur,\n spread,\n ...(inset && { inset }),\n variable: toFigmaName(variable),\n ...toPaints(readToken(css, variable)),\n },\n ]\n }\n\n const [red = 0, green = 0, blue = 0, alpha = \"100%\"] =\n color.match(/^rgb\\((\\d+) (\\d+) (\\d+) \\/ ([\\d.]+%)\\)$/)?.slice(1) ?? []\n const rgb = [red, green, blue].map(channel => Number(channel) / 255) as Rgb\n const paint = { hex: formatHex(rgb), alpha: Number.parseFloat(alpha) / 100 }\n return [{ offsetX, offsetY, blur, spread, ...(inset && { inset }), light: paint, dark: paint }]\n })\n}\n\n/** A line height in pixels: a length, a multiplier, a `calc(a / b)` multiplier or a `var()`. */\nfunction readLineHeight(value: string, size: number, declarations: Map<string, Declaration>) {\n const alias = value.match(/^var\\(--([a-z0-9-]+)\\)$/)?.[1]\n if (alias) return readLineHeight(declarations.get(alias)?.value ?? \"\", size, declarations)\n\n const ratio = value.match(/^calc\\(([\\d.]+) \\/ ([\\d.]+)\\)$/)\n if (ratio?.[1] && ratio[2]) return Math.round(size * (Number(ratio[1]) / Number(ratio[2])))\n if (/(px|rem)$/.test(value)) return readPixels(value)\n return Math.round(size * Number(value) * 100) / 100\n}\n\nfunction readText(name: string, declarations: Map<string, Declaration>): TextToken {\n const size = readPixels(declarations.get(`text-${name}`)?.value ?? \"\")\n const lineHeight = declarations.get(`text-${name}--line-height`)?.value ?? \"\"\n return {\n name: `text/${name}`,\n css: `var(--text-${name})`,\n size,\n lineHeight: readLineHeight(lineHeight, size, declarations),\n }\n}\n\nfunction readFamily(value = \"\") {\n return (\n value\n .split(\",\")[0]\n ?.replaceAll('\"', \"\")\n .replace(/ Variable$/, \"\") ?? \"\"\n )\n}\n\nexport function readDesignTokens(css: string, tailwindTheme: string): DesignTokens {\n const declarations = readDeclarations(css)\n const tailwind = readDeclarations(tailwindTheme)\n const names = [...declarations.keys()]\n\n const colorNames = readColorNames(css)\n const colors = colorNames.map(name => {\n const { value, description } = declarations.get(name) ?? { value: \"\" }\n const target = value.match(/^var\\(--([a-z0-9-]+)\\)$/)?.[1]\n return {\n name: toFigmaName(name),\n css: `var(--${name})`,\n ...(description && { description }),\n ...(target && colorNames.includes(target) && { alias: toFigmaName(target) }),\n ...toPaints(readToken(css, name)),\n }\n })\n\n const shadows = names\n .filter(name => name.startsWith(\"shadow-\"))\n .map(name => {\n const description = declarations.get(name)?.description\n return {\n name: toFigmaName(name),\n css: `var(--${name})`,\n ...(description && { description }),\n layers: readShadowLayers(css, name, declarations),\n }\n })\n\n const customText = names\n .filter(name => /^text-[a-z0-9]+$/.test(name))\n .map(name => name.replace(/^text-/, \"\"))\n const allText = new Map([...tailwind, ...declarations])\n\n const spacingBase = readPixels(tailwind.get(\"spacing\")?.value ?? \"\")\n\n return {\n fonts: {\n sans: readFamily(declarations.get(\"font-sans\")?.value),\n mono: readFamily(declarations.get(\"font-mono\")?.value),\n },\n colors,\n shadows,\n text: [...TAILWIND_TEXT, ...customText].map(name => readText(name, allText)),\n tracking: names\n .filter(name => name.startsWith(\"tracking-\"))\n .map(name => ({\n name: toFigmaName(name),\n css: `var(--${name})`,\n value: Number.parseFloat(declarations.get(name)?.value ?? \"\"),\n })),\n radius: [\n ...RADIUS_STEPS.map(step => ({\n name: `radius/${step}`,\n css: `var(--radius-${step})`,\n value: readPixels(\n (declarations.get(`radius-${step}`) ?? tailwind.get(`radius-${step}`))?.value ?? \"\",\n ),\n })),\n { name: \"radius/full\", css: \"calc(infinity * 1px)\", value: 9999 },\n ],\n spacing: [\n ...SPACING_STEPS.map(step => ({\n name: `spacing/${String(step).replace(\".\", \"-\")}`,\n css: `--spacing(${step})`,\n value: step * spacingBase,\n })),\n ...names\n .filter(name => name.startsWith(\"spacing-\"))\n .map(name => ({\n name: toFigmaName(name),\n css: `var(--${name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C3B,MAAM,UAAU;GAChB,KAAK,gBAAgB,KAAK;GAC1B,OAAO,YACJ,aAAa,IAAI,UAAU,MAAM,KAAK,SAAS,IAAI,UAAU,MAAM,EAAA,EAAI,SAAS,EACnF;EACF,EAAE,GACF;GAAE,MAAM;GAAe,KAAK;GAAwB,OAAO;EAAK,CAClE;EACA,SAAS,CACP,GAAG,cAAc,KAAI,UAAS;GAC5B,MAAM,WAAW,OAAO,IAAI,CAAC,CAAC,QAAQ,KAAK,GAAG;GAC9C,KAAK,aAAa,KAAK;GACvB,OAAO,OAAO;EAChB,EAAE,GACF,GAAG,MACA,QAAO,SAAQ,KAAK,WAAW,UAAU,CAAC,CAAC,CAC3C,KAAI,UAAS;GACZ,MAAM,YAAY,IAAI;GACtB,KAAK,SAAS,KAAK;GACnB,OAAO,WAAW,aAAa,IAAI,IAAI,CAAC,EAAE,SAAS,EAAE;EACvD,EAAE,CACN;CACF;AACF"}
|
package/lib/icon.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ComponentType } from "react";
|
|
2
|
+
import { HugeiconsProps, IconSvgElement } from "@hugeicons/react";
|
|
3
|
+
export type IconProps = Omit<HugeiconsProps, "icon" | "altIcon" | "showAlt">;
|
|
4
|
+
export type IconComponent = ComponentType<IconProps>;
|
|
5
|
+
/**
|
|
6
|
+
* Wraps a Hugeicons definition as a plain icon component, so call sites render `<CheckIcon />`.
|
|
7
|
+
* The package ships no icon registry of its own: icon choice belongs to each consuming app,
|
|
8
|
+
* which names every glyph it renders once with this helper.
|
|
9
|
+
*
|
|
10
|
+
* Sized to `1em`, so a `size-*` class or the surrounding font size drives it, at the 1.75
|
|
11
|
+
* stroke of the design's icon grid. Decorative by default, since an icon almost always sits
|
|
12
|
+
* beside the label that already names it; an icon that carries the meaning on its own
|
|
13
|
+
* overrides with `aria-hidden={false}`, `role="img"` and an `aria-label`. `defaults` sets props
|
|
14
|
+
* every use of one glyph shares. Memoised, since a glyph almost never changes with the
|
|
15
|
+
* component that renders it.
|
|
16
|
+
*/
|
|
17
|
+
export declare function icon(def: IconSvgElement, name: string, defaults?: IconProps): IconComponent;
|
package/lib/icon.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { memo } from "react";
|
|
3
|
+
import { HugeiconsIcon } from "@hugeicons/react";
|
|
4
|
+
// src/lib/icon.tsx
|
|
5
|
+
/**
|
|
6
|
+
* Wraps a Hugeicons definition as a plain icon component, so call sites render `<CheckIcon />`.
|
|
7
|
+
* The package ships no icon registry of its own: icon choice belongs to each consuming app,
|
|
8
|
+
* which names every glyph it renders once with this helper.
|
|
9
|
+
*
|
|
10
|
+
* Sized to `1em`, so a `size-*` class or the surrounding font size drives it, at the 1.75
|
|
11
|
+
* stroke of the design's icon grid. Decorative by default, since an icon almost always sits
|
|
12
|
+
* beside the label that already names it; an icon that carries the meaning on its own
|
|
13
|
+
* overrides with `aria-hidden={false}`, `role="img"` and an `aria-label`. `defaults` sets props
|
|
14
|
+
* every use of one glyph shares. Memoised, since a glyph almost never changes with the
|
|
15
|
+
* component that renders it.
|
|
16
|
+
*/
|
|
17
|
+
function icon(def, name, defaults) {
|
|
18
|
+
function Icon(props) {
|
|
19
|
+
return /* @__PURE__ */ jsx(HugeiconsIcon, {
|
|
20
|
+
icon: def,
|
|
21
|
+
size: "1em",
|
|
22
|
+
strokeWidth: 1.75,
|
|
23
|
+
"aria-hidden": true,
|
|
24
|
+
focusable: "false",
|
|
25
|
+
...defaults,
|
|
26
|
+
...props
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
Icon.displayName = name;
|
|
30
|
+
return memo(Icon);
|
|
31
|
+
}
|
|
32
|
+
export { icon };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=icon.js.map
|
package/lib/icon.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"icon.js","names":[],"sources":["../../src/lib/icon.tsx"],"sourcesContent":["import { HugeiconsIcon, type HugeiconsProps, type IconSvgElement } from \"@hugeicons/react\"\nimport { type ComponentType, memo } from \"react\"\n\nexport type IconProps = Omit<HugeiconsProps, \"icon\" | \"altIcon\" | \"showAlt\">\nexport type IconComponent = ComponentType<IconProps>\n\n/**\n * Wraps a Hugeicons definition as a plain icon component, so call sites render `<CheckIcon />`.\n * The package ships no icon registry of its own: icon choice belongs to each consuming app,\n * which names every glyph it renders once with this helper.\n *\n * Sized to `1em`, so a `size-*` class or the surrounding font size drives it, at the 1.75\n * stroke of the design's icon grid. Decorative by default, since an icon almost always sits\n * beside the label that already names it; an icon that carries the meaning on its own\n * overrides with `aria-hidden={false}`, `role=\"img\"` and an `aria-label`. `defaults` sets props\n * every use of one glyph shares. Memoised, since a glyph almost never changes with the\n * component that renders it.\n */\nexport function icon(def: IconSvgElement, name: string, defaults?: IconProps): IconComponent {\n function Icon(props: IconProps) {\n return (\n <HugeiconsIcon\n icon={def}\n size=\"1em\"\n strokeWidth={1.75}\n aria-hidden={true}\n focusable=\"false\"\n {...defaults}\n {...props}\n />\n )\n }\n\n Icon.displayName = name\n\n return memo(Icon)\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAkBA,SAAgB,KAAK,KAAqB,MAAc,UAAqC;CAC3F,SAAS,KAAK,OAAkB;EAC9B,OACE,oBAAC,eAAD;GACE,MAAM;GACN,MAAK;GACL,aAAa;GACb,eAAa;GACb,WAAU;GACV,GAAI;GACJ,GAAI;EACL,CAAA;CAEL;CAEA,KAAK,cAAc;CAEnB,OAAO,KAAK,IAAI;AAClB"}
|
package/lib/icons.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { IconComponent } from "./icon.js";
|
|
2
|
+
export declare const AlertIcon: IconComponent;
|
|
3
|
+
export declare const AlertCircleIcon: IconComponent;
|
|
4
|
+
export declare const ArrowDownIcon: IconComponent;
|
|
5
|
+
export declare const ArrowUpIcon: IconComponent;
|
|
6
|
+
export declare const ArrowUpRightIcon: IconComponent;
|
|
7
|
+
export declare const CalendarIcon: IconComponent;
|
|
8
|
+
export declare const CancelIcon: IconComponent;
|
|
9
|
+
export declare const CancelCircleIcon: IconComponent;
|
|
10
|
+
export declare const CheckIcon: IconComponent;
|
|
11
|
+
export declare const CheckCircleIcon: IconComponent;
|
|
12
|
+
export declare const ChevronDownIcon: IconComponent;
|
|
13
|
+
export declare const ChevronsLeftIcon: IconComponent;
|
|
14
|
+
export declare const ChevronsRightIcon: IconComponent;
|
|
15
|
+
export declare const ChevronLeftIcon: IconComponent;
|
|
16
|
+
export declare const ChevronRightIcon: IconComponent;
|
|
17
|
+
export declare const ChevronUpIcon: IconComponent;
|
|
18
|
+
export declare const ChevronsUpDownIcon: IconComponent;
|
|
19
|
+
export declare const ComputerIcon: IconComponent;
|
|
20
|
+
export declare const CopyIcon: IconComponent;
|
|
21
|
+
export declare const DashIcon: IconComponent;
|
|
22
|
+
export declare const FilterIcon: IconComponent;
|
|
23
|
+
export declare const HelpIcon: IconComponent;
|
|
24
|
+
export declare const InfoIcon: IconComponent;
|
|
25
|
+
export declare const LoadingIcon: IconComponent;
|
|
26
|
+
export declare const MoonIcon: IconComponent;
|
|
27
|
+
export declare const PlusCircleIcon: IconComponent;
|
|
28
|
+
export declare const SearchIcon: IconComponent;
|
|
29
|
+
export declare const SunIcon: IconComponent;
|
package/lib/icons.js
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { icon } from "./icon.js";
|
|
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, PlusSignCircleIcon, Remove01Icon, Search01Icon, Sun03Icon, Tick02Icon, UnfoldMoreIcon } from "@hugeicons/core-free-icons";
|
|
3
|
+
// src/lib/icons.tsx
|
|
4
|
+
const AlertIcon = icon(Alert02Icon, "AlertIcon");
|
|
5
|
+
const AlertCircleIcon = icon(AlertCircleIcon$1, "AlertCircleIcon");
|
|
6
|
+
const ArrowDownIcon = icon(ArrowDown02Icon, "ArrowDownIcon");
|
|
7
|
+
const ArrowUpIcon = icon(ArrowUp02Icon, "ArrowUpIcon");
|
|
8
|
+
const ArrowUpRightIcon = icon(ArrowUpRight01Icon, "ArrowUpRightIcon");
|
|
9
|
+
const CalendarIcon = icon(Calendar03Icon, "CalendarIcon");
|
|
10
|
+
const CancelIcon = icon(Cancel01Icon, "CancelIcon");
|
|
11
|
+
const CancelCircleIcon = icon(CancelCircleIcon$1, "CancelCircleIcon");
|
|
12
|
+
const CheckIcon = icon(Tick02Icon, "CheckIcon");
|
|
13
|
+
const CheckCircleIcon = icon(CheckmarkCircle02Icon, "CheckCircleIcon");
|
|
14
|
+
const ChevronDownIcon = icon(ArrowDown01Icon, "ChevronDownIcon");
|
|
15
|
+
const ChevronsLeftIcon = icon(ArrowLeftDoubleIcon, "ChevronsLeftIcon");
|
|
16
|
+
const ChevronsRightIcon = icon(ArrowRightDoubleIcon, "ChevronsRightIcon");
|
|
17
|
+
const ChevronLeftIcon = icon(ArrowLeft01Icon, "ChevronLeftIcon");
|
|
18
|
+
const ChevronRightIcon = icon(ArrowRight01Icon, "ChevronRightIcon");
|
|
19
|
+
const ChevronUpIcon = icon(ArrowUp01Icon, "ChevronUpIcon");
|
|
20
|
+
const ChevronsUpDownIcon = icon(UnfoldMoreIcon, "ChevronsUpDownIcon");
|
|
21
|
+
const ComputerIcon = icon(ComputerIcon$1, "ComputerIcon");
|
|
22
|
+
const CopyIcon = icon(Copy01Icon, "CopyIcon");
|
|
23
|
+
const DashIcon = icon(Remove01Icon, "DashIcon");
|
|
24
|
+
const FilterIcon = icon(ListFilterIcon, "FilterIcon");
|
|
25
|
+
const HelpIcon = icon(HelpCircleIcon, "HelpIcon");
|
|
26
|
+
const InfoIcon = icon(InformationCircleIcon, "InfoIcon");
|
|
27
|
+
const LoadingIcon = icon(Loading03Icon, "LoadingIcon");
|
|
28
|
+
const MoonIcon = icon(Moon02Icon, "MoonIcon");
|
|
29
|
+
const PlusCircleIcon = icon(PlusSignCircleIcon, "PlusCircleIcon");
|
|
30
|
+
const SearchIcon = icon(Search01Icon, "SearchIcon");
|
|
31
|
+
const SunIcon = icon(Sun03Icon, "SunIcon");
|
|
32
|
+
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, PlusCircleIcon, SearchIcon, SunIcon };
|
|
33
|
+
|
|
34
|
+
//# sourceMappingURL=icons.js.map
|
package/lib/icons.js.map
ADDED
|
@@ -0,0 +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 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 PlusSignCircleIcon,\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\")\nexport const PlusCircleIcon = icon(PlusSignCircleIcon, \"PlusCircleIcon\")\nexport const SearchIcon = icon(Search01Icon, \"SearchIcon\")\nexport const SunIcon = icon(Sun03Icon, \"SunIcon\")\n"],"mappings":";;;AAoCA,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;AACnD,MAAa,iBAAiB,KAAK,oBAAoB,gBAAgB;AACvE,MAAa,aAAa,KAAK,cAAc,YAAY;AACzD,MAAa,UAAU,KAAK,WAAW,SAAS"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared chrome for every interactive surface (buttons, inputs, select triggers, switches,
|
|
3
|
+
* tabs): a snappy colour transition, a pointer cursor when `interactive`, and, when `bordered`,
|
|
4
|
+
* the strong 1px border, which darkens under the pointer, plus the subtle fill when the control
|
|
5
|
+
* is clicked rather than typed into. Components layer their own fill and text colours on top
|
|
6
|
+
* with `cn`. An `aria-disabled` control keeps the pointer for its reason's tooltip, so it shows
|
|
7
|
+
* the not-allowed cursor and no hover fill or edge.
|
|
8
|
+
*
|
|
9
|
+
* Focus is not a variant: every focusable element gets the one focus ring from `styles.css`
|
|
10
|
+
* (`:focus-visible`), so there is nothing to opt into here. An invalid control
|
|
11
|
+
* (`aria-invalid`, set by a form field with an error) turns its border to the danger tone and
|
|
12
|
+
* keeps it while focused, so the field the message belongs to reads at a glance.
|
|
13
|
+
*/
|
|
14
|
+
export declare const interactiveVariants: import("tailwind-variants").TVReturnType<{
|
|
15
|
+
interactive: {
|
|
16
|
+
true: string;
|
|
17
|
+
};
|
|
18
|
+
bordered: {
|
|
19
|
+
true: string;
|
|
20
|
+
};
|
|
21
|
+
}, undefined, "transition-[color,background-color,border-color,box-shadow,opacity,filter] duration-75 ease-out aria-invalid:border-danger aria-invalid:focus:border-danger", undefined, undefined, undefined>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { variants } from "./variants.js";
|
|
2
|
+
// src/lib/interactive.ts
|
|
3
|
+
/**
|
|
4
|
+
* Shared chrome for every interactive surface (buttons, inputs, select triggers, switches,
|
|
5
|
+
* tabs): a snappy colour transition, a pointer cursor when `interactive`, and, when `bordered`,
|
|
6
|
+
* the strong 1px border, which darkens under the pointer, plus the subtle fill when the control
|
|
7
|
+
* is clicked rather than typed into. Components layer their own fill and text colours on top
|
|
8
|
+
* with `cn`. An `aria-disabled` control keeps the pointer for its reason's tooltip, so it shows
|
|
9
|
+
* the not-allowed cursor and no hover fill or edge.
|
|
10
|
+
*
|
|
11
|
+
* Focus is not a variant: every focusable element gets the one focus ring from `styles.css`
|
|
12
|
+
* (`:focus-visible`), so there is nothing to opt into here. An invalid control
|
|
13
|
+
* (`aria-invalid`, set by a form field with an error) turns its border to the danger tone and
|
|
14
|
+
* keeps it while focused, so the field the message belongs to reads at a glance.
|
|
15
|
+
*/
|
|
16
|
+
const interactiveVariants = variants({
|
|
17
|
+
base: "transition-[color,background-color,border-color,box-shadow,opacity,filter] duration-75 ease-out aria-invalid:border-danger aria-invalid:focus:border-danger",
|
|
18
|
+
variants: {
|
|
19
|
+
interactive: { true: "not-disabled:not-aria-disabled:cursor-pointer aria-disabled:cursor-not-allowed" },
|
|
20
|
+
bordered: { true: "border border-edge-strong hover:not-disabled:not-aria-disabled:not-aria-invalid:border-edge-solid" }
|
|
21
|
+
},
|
|
22
|
+
compoundVariants: [{
|
|
23
|
+
interactive: true,
|
|
24
|
+
bordered: true,
|
|
25
|
+
class: "hover:not-disabled:not-aria-disabled:bg-fill-subtle"
|
|
26
|
+
}],
|
|
27
|
+
defaultVariants: { interactive: true }
|
|
28
|
+
});
|
|
29
|
+
export { interactiveVariants };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=interactive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interactive.js","names":[],"sources":["../../src/lib/interactive.ts"],"sourcesContent":["import { variants } from \"./variants\"\n\n/**\n * Shared chrome for every interactive surface (buttons, inputs, select triggers, switches,\n * tabs): a snappy colour transition, a pointer cursor when `interactive`, and, when `bordered`,\n * the strong 1px border, which darkens under the pointer, plus the subtle fill when the control\n * is clicked rather than typed into. Components layer their own fill and text colours on top\n * with `cn`. An `aria-disabled` control keeps the pointer for its reason's tooltip, so it shows\n * the not-allowed cursor and no hover fill or edge.\n *\n * Focus is not a variant: every focusable element gets the one focus ring from `styles.css`\n * (`:focus-visible`), so there is nothing to opt into here. An invalid control\n * (`aria-invalid`, set by a form field with an error) turns its border to the danger tone and\n * keeps it while focused, so the field the message belongs to reads at a glance.\n */\nexport const interactiveVariants = variants({\n base: \"transition-[color,background-color,border-color,box-shadow,opacity,filter] duration-75 ease-out aria-invalid:border-danger aria-invalid:focus:border-danger\",\n\n variants: {\n interactive: {\n true: \"not-disabled:not-aria-disabled:cursor-pointer aria-disabled:cursor-not-allowed\",\n },\n bordered: {\n true: \"border border-edge-strong hover:not-disabled:not-aria-disabled:not-aria-invalid:border-edge-solid\",\n },\n },\n\n compoundVariants: [\n {\n interactive: true,\n bordered: true,\n class: \"hover:not-disabled:not-aria-disabled:bg-fill-subtle\",\n },\n ],\n\n defaultVariants: {\n interactive: true,\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;AAeA,MAAa,sBAAsB,SAAS;CAC1C,MAAM;CAEN,UAAU;EACR,aAAa,EACX,MAAM,iFACR;EACA,UAAU,EACR,MAAM,oGACR;CACF;CAEA,kBAAkB,CAChB;EACE,aAAa;EACb,UAAU;EACV,OAAO;CACT,CACF;CAEA,iBAAiB,EACf,aAAa,KACf;AACF,CAAC"}
|
|
@@ -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;
|
package/lib/load-more.js
ADDED
|
@@ -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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-more.js","names":[],"sources":["../../src/lib/load-more.ts"],"sourcesContent":["\"use client\"\n\nimport { useEffect } from \"react\"\n\nexport interface LoadMoreOptions {\n /** False while a page is in flight, when there is no next page, or after a failed page. */\n enabled: boolean\n onLoad: () => void\n /** How far below the viewport the sentinel starts loading, in pixels. */\n ahead?: number\n}\n\n/**\n * Loads the next page as `sentinel` scrolls into view. The observer is dropped while a page is\n * in flight and set up again after it lands: observing fires straight away for an element\n * already on screen, which is what walks a fast scroll on through page after page. Pass the\n * element through a state setter (`ref={setSentinel}`), so the hook sees it once it mounts.\n */\nexport function useLoadMore(sentinel: Element | null, { enabled, onLoad, ahead }: LoadMoreOptions) {\n useEffect(() => {\n if (!sentinel || !enabled) return\n const observer = new IntersectionObserver(\n entries => {\n if (entries.some(entry => entry.isIntersecting)) onLoad()\n },\n ahead === undefined ? undefined : { rootMargin: `0px 0px ${ahead}px 0px` },\n )\n observer.observe(sentinel)\n return () => observer.disconnect()\n }, [sentinel, enabled, onLoad, ahead])\n}\n"],"mappings":";;;;;;;;;AAkBA,SAAgB,YAAY,UAA0B,EAAE,SAAS,QAAQ,SAA0B;CACjG,gBAAgB;EACd,IAAI,CAAC,YAAY,CAAC,SAAS;EAC3B,MAAM,WAAW,IAAI,sBACnB,YAAW;GACT,IAAI,QAAQ,MAAK,UAAS,MAAM,cAAc,GAAG,OAAO;EAC1D,GACA,UAAU,KAAA,IAAY,KAAA,IAAY,EAAE,YAAY,WAAW,MAAM,QAAQ,CAC3E;EACA,SAAS,QAAQ,QAAQ;EACzB,aAAa,SAAS,WAAW;CACnC,GAAG;EAAC;EAAU;EAAS;EAAQ;CAAK,CAAC;AACvC"}
|
package/lib/media.d.ts
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** Tailwind's `lg` and up, where an app shell has room for a side rail. */
|
|
2
|
+
export declare const FROM_LG = "(min-width: 64rem)";
|
|
3
|
+
/** A mouse or trackpad: the device the `pointer-fine:` variant styles for. */
|
|
4
|
+
export declare const POINTER_FINE = "(pointer: fine)";
|
|
5
|
+
/**
|
|
6
|
+
* Whether a media query matches right now, for a callback. A render reads `useMediaQuery`
|
|
7
|
+
* instead, which is false on the server and re-renders when the answer changes.
|
|
8
|
+
*/
|
|
9
|
+
export declare function matchesMedia(query: string): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Whether a media query matches, re-rendering when that changes. False on the server and
|
|
12
|
+
* through hydration, so the first client render matches the markup; React then re-renders
|
|
13
|
+
* with the truth. Pass a module constant: the store is keyed on the string.
|
|
14
|
+
*/
|
|
15
|
+
export declare function useMediaQuery(query: string): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Whether the viewport is under `sm`. A component that swaps on it remounts when the
|
|
18
|
+
* breakpoint is crossed, which only ever happens on a resize.
|
|
19
|
+
*/
|
|
20
|
+
export declare function useBelowSm(): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Whether a popup opening now takes the phone's bottom sheet: true under `sm`. The answer is
|
|
23
|
+
* read once, when the caller mounts, and held. Call it from inside the popup's portal, which
|
|
24
|
+
* mounts as the popup opens and unmounts once it has closed: a popup then keeps one shape for
|
|
25
|
+
* as long as it is open, and a resize across `sm` neither moves nor remounts it.
|
|
26
|
+
*/
|
|
27
|
+
export declare function usePopupSheet(): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Whether a popup takes the phone's bottom sheet, for a caller that renders the sheet or a
|
|
30
|
+
* popover itself rather than through `Dialog`. It follows the viewport while `open`
|
|
31
|
+
* is false and holds while it is true, so a resize across `sm` neither swaps the component in
|
|
32
|
+
* use nor drops what is typed in it.
|
|
33
|
+
*/
|
|
34
|
+
export declare function useSheetWhileOpen(open: boolean): boolean;
|
|
35
|
+
interface ElementWidthOptions {
|
|
36
|
+
/** Rounds the width down to a multiple of this many pixels. */
|
|
37
|
+
step?: number;
|
|
38
|
+
/** Applies a new width as a transition. Default true. */
|
|
39
|
+
deferred?: boolean;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The width of the element the caller holds in state, in pixels, rounded down to a multiple
|
|
43
|
+
* of `step`, and `undefined` until it has been measured. The rounding is what makes the
|
|
44
|
+
* reading usable as a key: a drag-resize would otherwise report every pixel on the way, and
|
|
45
|
+
* anything derived from the width (a lattice, a bucket count) would be rebuilt on each one.
|
|
46
|
+
*
|
|
47
|
+
* The element comes from a callback ref (`ref={setElement}`) rather than a `RefObject`, so
|
|
48
|
+
* one that mounts later than the hook is measured as soon as it arrives: a `RefObject` is the
|
|
49
|
+
* same object on every render, so an effect keyed on it never runs again, and an element
|
|
50
|
+
* mounted after an error state gave way would never be observed at all.
|
|
51
|
+
*
|
|
52
|
+
* The new width arrives as a transition by default, so a drag-resize stays responsive while the
|
|
53
|
+
* work behind it re-runs. A transition waits on every other pending one, so while a page loads
|
|
54
|
+
* its data the first width can land a second late: `deferred: false` applies it at once, for
|
|
55
|
+
* a layout that reads wrong until measured.
|
|
56
|
+
*/
|
|
57
|
+
export declare function useElementWidth(element: HTMLElement | null, { step, deferred }?: ElementWidthOptions): number | undefined;
|
|
58
|
+
export {};
|
package/lib/media.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { startTransition, useEffect, useState, useSyncExternalStore } from "react";
|
|
3
|
+
// src/lib/media.ts
|
|
4
|
+
/**
|
|
5
|
+
* Below Tailwind's `sm` (40rem), i.e. the phone layout. Kept as a constant so this JS-driven
|
|
6
|
+
* switch flips on exactly the same pixel as the `max-sm:` classes components style with.
|
|
7
|
+
*/
|
|
8
|
+
const BELOW_SM = "(max-width: 39.9375rem)";
|
|
9
|
+
/** Tailwind's `lg` and up, where an app shell has room for a side rail. */
|
|
10
|
+
const FROM_LG = "(min-width: 64rem)";
|
|
11
|
+
/** A mouse or trackpad: the device the `pointer-fine:` variant styles for. */
|
|
12
|
+
const POINTER_FINE = "(pointer: fine)";
|
|
13
|
+
const stores = /* @__PURE__ */ new Map();
|
|
14
|
+
/**
|
|
15
|
+
* Whether a media query matches right now, for a callback. A render reads `useMediaQuery`
|
|
16
|
+
* instead, which is false on the server and re-renders when the answer changes.
|
|
17
|
+
*/
|
|
18
|
+
function matchesMedia(query) {
|
|
19
|
+
return matchMedia(query).matches;
|
|
20
|
+
}
|
|
21
|
+
function storeFor(query) {
|
|
22
|
+
const existing = stores.get(query);
|
|
23
|
+
if (existing) return existing;
|
|
24
|
+
const store = {
|
|
25
|
+
subscribe(onChange) {
|
|
26
|
+
const list = matchMedia(query);
|
|
27
|
+
list.addEventListener("change", onChange);
|
|
28
|
+
return () => list.removeEventListener("change", onChange);
|
|
29
|
+
},
|
|
30
|
+
getSnapshot() {
|
|
31
|
+
return matchesMedia(query);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
stores.set(query, store);
|
|
35
|
+
return store;
|
|
36
|
+
}
|
|
37
|
+
function serverSnapshot() {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Whether a media query matches, re-rendering when that changes. False on the server and
|
|
42
|
+
* through hydration, so the first client render matches the markup; React then re-renders
|
|
43
|
+
* with the truth. Pass a module constant: the store is keyed on the string.
|
|
44
|
+
*/
|
|
45
|
+
function useMediaQuery(query) {
|
|
46
|
+
const { subscribe, getSnapshot } = storeFor(query);
|
|
47
|
+
return useSyncExternalStore(subscribe, getSnapshot, serverSnapshot);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Whether the viewport is under `sm`. A component that swaps on it remounts when the
|
|
51
|
+
* breakpoint is crossed, which only ever happens on a resize.
|
|
52
|
+
*/
|
|
53
|
+
function useBelowSm() {
|
|
54
|
+
return useMediaQuery(BELOW_SM);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Whether a popup opening now takes the phone's bottom sheet: true under `sm`. The answer is
|
|
58
|
+
* read once, when the caller mounts, and held. Call it from inside the popup's portal, which
|
|
59
|
+
* mounts as the popup opens and unmounts once it has closed: a popup then keeps one shape for
|
|
60
|
+
* as long as it is open, and a resize across `sm` neither moves nor remounts it.
|
|
61
|
+
*/
|
|
62
|
+
function usePopupSheet() {
|
|
63
|
+
const [sheet] = useState(() => matchesMedia(BELOW_SM));
|
|
64
|
+
return sheet;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Whether a popup takes the phone's bottom sheet, for a caller that renders the sheet or a
|
|
68
|
+
* popover itself rather than through `Dialog`. It follows the viewport while `open`
|
|
69
|
+
* is false and holds while it is true, so a resize across `sm` neither swaps the component in
|
|
70
|
+
* use nor drops what is typed in it.
|
|
71
|
+
*/
|
|
72
|
+
function useSheetWhileOpen(open) {
|
|
73
|
+
const belowSm = useBelowSm();
|
|
74
|
+
const [sheet, setSheet] = useState(belowSm);
|
|
75
|
+
if (!open && sheet !== belowSm) setSheet(belowSm);
|
|
76
|
+
return sheet;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* The width of the element the caller holds in state, in pixels, rounded down to a multiple
|
|
80
|
+
* of `step`, and `undefined` until it has been measured. The rounding is what makes the
|
|
81
|
+
* reading usable as a key: a drag-resize would otherwise report every pixel on the way, and
|
|
82
|
+
* anything derived from the width (a lattice, a bucket count) would be rebuilt on each one.
|
|
83
|
+
*
|
|
84
|
+
* The element comes from a callback ref (`ref={setElement}`) rather than a `RefObject`, so
|
|
85
|
+
* one that mounts later than the hook is measured as soon as it arrives: a `RefObject` is the
|
|
86
|
+
* same object on every render, so an effect keyed on it never runs again, and an element
|
|
87
|
+
* mounted after an error state gave way would never be observed at all.
|
|
88
|
+
*
|
|
89
|
+
* The new width arrives as a transition by default, so a drag-resize stays responsive while the
|
|
90
|
+
* work behind it re-runs. A transition waits on every other pending one, so while a page loads
|
|
91
|
+
* its data the first width can land a second late: `deferred: false` applies it at once, for
|
|
92
|
+
* a layout that reads wrong until measured.
|
|
93
|
+
*/
|
|
94
|
+
function useElementWidth(element, { step = 1, deferred = true } = {}) {
|
|
95
|
+
const [width, setWidth] = useState();
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
if (!element) return;
|
|
98
|
+
function apply(measured) {
|
|
99
|
+
const next = measured > 0 ? Math.floor(measured / step) * step : void 0;
|
|
100
|
+
if (deferred) startTransition(() => setWidth(next));
|
|
101
|
+
else setWidth(next);
|
|
102
|
+
}
|
|
103
|
+
if (!deferred) apply(element.clientWidth);
|
|
104
|
+
const observer = new ResizeObserver(([entry]) => apply(entry?.contentRect.width ?? 0));
|
|
105
|
+
observer.observe(element);
|
|
106
|
+
return () => observer.disconnect();
|
|
107
|
+
}, [
|
|
108
|
+
element,
|
|
109
|
+
step,
|
|
110
|
+
deferred
|
|
111
|
+
]);
|
|
112
|
+
return width;
|
|
113
|
+
}
|
|
114
|
+
export { FROM_LG, POINTER_FINE, matchesMedia, useBelowSm, useElementWidth, useMediaQuery, usePopupSheet, useSheetWhileOpen };
|
|
115
|
+
|
|
116
|
+
//# sourceMappingURL=media.js.map
|
package/lib/media.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.js","names":[],"sources":["../../src/lib/media.ts"],"sourcesContent":["\"use client\"\n\nimport { startTransition, useEffect, useState, useSyncExternalStore } from \"react\"\n\n/**\n * Below Tailwind's `sm` (40rem), i.e. the phone layout. Kept as a constant so this JS-driven\n * switch flips on exactly the same pixel as the `max-sm:` classes components style with.\n */\nconst BELOW_SM = \"(max-width: 39.9375rem)\"\n\n/** Tailwind's `lg` and up, where an app shell has room for a side rail. */\nexport const FROM_LG = \"(min-width: 64rem)\"\n\n/** A mouse or trackpad: the device the `pointer-fine:` variant styles for. */\nexport const POINTER_FINE = \"(pointer: fine)\"\n\ninterface MediaQueryStore {\n subscribe: (onChange: () => void) => () => void\n getSnapshot: () => boolean\n}\n\n// One store per query string, so every component watching the same query shares a listener\n// and `useSyncExternalStore` gets the referentially stable callbacks it compares on.\nconst stores = new Map<string, MediaQueryStore>()\n\n/**\n * Whether a media query matches right now, for a callback. A render reads `useMediaQuery`\n * instead, which is false on the server and re-renders when the answer changes.\n */\nexport function matchesMedia(query: string): boolean {\n return matchMedia(query).matches\n}\n\n// `matchMedia` is only ever touched inside these callbacks, which is what keeps the module\n// importable on the server.\nfunction storeFor(query: string): MediaQueryStore {\n const existing = stores.get(query)\n if (existing) return existing\n\n const store: MediaQueryStore = {\n subscribe(onChange) {\n const list = matchMedia(query)\n list.addEventListener(\"change\", onChange)\n return () => list.removeEventListener(\"change\", onChange)\n },\n getSnapshot() {\n return matchesMedia(query)\n },\n }\n stores.set(query, store)\n\n return store\n}\n\nfunction serverSnapshot() {\n return false\n}\n\n/**\n * Whether a media query matches, re-rendering when that changes. False on the server and\n * through hydration, so the first client render matches the markup; React then re-renders\n * with the truth. Pass a module constant: the store is keyed on the string.\n */\nexport function useMediaQuery(query: string): boolean {\n const { subscribe, getSnapshot } = storeFor(query)\n\n return useSyncExternalStore(subscribe, getSnapshot, serverSnapshot)\n}\n\n/**\n * Whether the viewport is under `sm`. A component that swaps on it remounts when the\n * breakpoint is crossed, which only ever happens on a resize.\n */\nexport function useBelowSm() {\n return useMediaQuery(BELOW_SM)\n}\n\n/**\n * Whether a popup opening now takes the phone's bottom sheet: true under `sm`. The answer is\n * read once, when the caller mounts, and held. Call it from inside the popup's portal, which\n * mounts as the popup opens and unmounts once it has closed: a popup then keeps one shape for\n * as long as it is open, and a resize across `sm` neither moves nor remounts it.\n */\nexport function usePopupSheet() {\n const [sheet] = useState(() => matchesMedia(BELOW_SM))\n\n return sheet\n}\n\n/**\n * Whether a popup takes the phone's bottom sheet, for a caller that renders the sheet or a\n * popover itself rather than through `Dialog`. It follows the viewport while `open`\n * is false and holds while it is true, so a resize across `sm` neither swaps the component in\n * use nor drops what is typed in it.\n */\nexport function useSheetWhileOpen(open: boolean) {\n const belowSm = useBelowSm()\n const [sheet, setSheet] = useState(belowSm)\n\n // Adjusting state while rendering: only a closed popup takes up a new answer.\n if (!open && sheet !== belowSm) setSheet(belowSm)\n\n return sheet\n}\n\ninterface ElementWidthOptions {\n /** Rounds the width down to a multiple of this many pixels. */\n step?: number\n /** Applies a new width as a transition. Default true. */\n deferred?: boolean\n}\n\n/**\n * The width of the element the caller holds in state, in pixels, rounded down to a multiple\n * of `step`, and `undefined` until it has been measured. The rounding is what makes the\n * reading usable as a key: a drag-resize would otherwise report every pixel on the way, and\n * anything derived from the width (a lattice, a bucket count) would be rebuilt on each one.\n *\n * The element comes from a callback ref (`ref={setElement}`) rather than a `RefObject`, so\n * one that mounts later than the hook is measured as soon as it arrives: a `RefObject` is the\n * same object on every render, so an effect keyed on it never runs again, and an element\n * mounted after an error state gave way would never be observed at all.\n *\n * The new width arrives as a transition by default, so a drag-resize stays responsive while the\n * work behind it re-runs. A transition waits on every other pending one, so while a page loads\n * its data the first width can land a second late: `deferred: false` applies it at once, for\n * a layout that reads wrong until measured.\n */\nexport function useElementWidth(\n element: HTMLElement | null,\n { step = 1, deferred = true }: ElementWidthOptions = {},\n) {\n const [width, setWidth] = useState<number>()\n\n useEffect(() => {\n if (!element) return\n\n function apply(measured: number) {\n const next = measured > 0 ? Math.floor(measured / step) * step : undefined\n if (deferred) startTransition(() => setWidth(next))\n else setWidth(next)\n }\n\n // Urgent means now: layout already knows the width a frame before the observer reports it.\n if (!deferred) apply(element.clientWidth)\n const observer = new ResizeObserver(([entry]) => apply(entry?.contentRect.width ?? 0))\n observer.observe(element)\n return () => observer.disconnect()\n }, [element, step, deferred])\n\n return width\n}\n"],"mappings":";;;;;;;AAQA,MAAM,WAAW;;AAGjB,MAAa,UAAU;;AAGvB,MAAa,eAAe;AAS5B,MAAM,yBAAS,IAAI,IAA6B;;;;;AAMhD,SAAgB,aAAa,OAAwB;CACnD,OAAO,WAAW,KAAK,CAAC,CAAC;AAC3B;AAIA,SAAS,SAAS,OAAgC;CAChD,MAAM,WAAW,OAAO,IAAI,KAAK;CACjC,IAAI,UAAU,OAAO;CAErB,MAAM,QAAyB;EAC7B,UAAU,UAAU;GAClB,MAAM,OAAO,WAAW,KAAK;GAC7B,KAAK,iBAAiB,UAAU,QAAQ;GACxC,aAAa,KAAK,oBAAoB,UAAU,QAAQ;EAC1D;EACA,cAAc;GACZ,OAAO,aAAa,KAAK;EAC3B;CACF;CACA,OAAO,IAAI,OAAO,KAAK;CAEvB,OAAO;AACT;AAEA,SAAS,iBAAiB;CACxB,OAAO;AACT;;;;;;AAOA,SAAgB,cAAc,OAAwB;CACpD,MAAM,EAAE,WAAW,gBAAgB,SAAS,KAAK;CAEjD,OAAO,qBAAqB,WAAW,aAAa,cAAc;AACpE;;;;;AAMA,SAAgB,aAAa;CAC3B,OAAO,cAAc,QAAQ;AAC/B;;;;;;;AAQA,SAAgB,gBAAgB;CAC9B,MAAM,CAAC,SAAS,eAAe,aAAa,QAAQ,CAAC;CAErD,OAAO;AACT;;;;;;;AAQA,SAAgB,kBAAkB,MAAe;CAC/C,MAAM,UAAU,WAAW;CAC3B,MAAM,CAAC,OAAO,YAAY,SAAS,OAAO;CAG1C,IAAI,CAAC,QAAQ,UAAU,SAAS,SAAS,OAAO;CAEhD,OAAO;AACT;;;;;;;;;;;;;;;;;AAyBA,SAAgB,gBACd,SACA,EAAE,OAAO,GAAG,WAAW,SAA8B,CAAC,GACtD;CACA,MAAM,CAAC,OAAO,YAAY,SAAiB;CAE3C,gBAAgB;EACd,IAAI,CAAC,SAAS;EAEd,SAAS,MAAM,UAAkB;GAC/B,MAAM,OAAO,WAAW,IAAI,KAAK,MAAM,WAAW,IAAI,IAAI,OAAO,KAAA;GACjE,IAAI,UAAU,sBAAsB,SAAS,IAAI,CAAC;QAC7C,SAAS,IAAI;EACpB;EAGA,IAAI,CAAC,UAAU,MAAM,QAAQ,WAAW;EACxC,MAAM,WAAW,IAAI,gBAAgB,CAAC,WAAW,MAAM,OAAO,YAAY,SAAS,CAAC,CAAC;EACrF,SAAS,QAAQ,OAAO;EACxB,aAAa,SAAS,WAAW;CACnC,GAAG;EAAC;EAAS;EAAM;CAAQ,CAAC;CAE5B,OAAO;AACT"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { VariantProps } from "./variants.js";
|
|
2
|
+
import { RefObject } from "react";
|
|
3
|
+
/** The variant and size a row hands its options, with the defaults filled in. */
|
|
4
|
+
export interface SegmentedStyle {
|
|
5
|
+
variant: NonNullable<VariantProps<typeof segmentedVariants>["variant"]>;
|
|
6
|
+
size: NonNullable<VariantProps<typeof segmentedVariants>["size"]>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The row of options with one sliding pill behind the chosen one, shared by `Tabs` and
|
|
10
|
+
* `SegmentedControl`. Each component positions the pill from its own measurements and adds the
|
|
11
|
+
* state classes its primitive emits (`data-active` on a tab, `data-checked` on a radio), so
|
|
12
|
+
* the slots here hold only the shape.
|
|
13
|
+
*/
|
|
14
|
+
export declare const segmentedVariants: import("tailwind-variants").TVReturnType<{
|
|
15
|
+
variant: {
|
|
16
|
+
segmented: {
|
|
17
|
+
root: string;
|
|
18
|
+
indicator: string;
|
|
19
|
+
};
|
|
20
|
+
plain: {
|
|
21
|
+
root: string;
|
|
22
|
+
indicator: string;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
size: {
|
|
26
|
+
md: {
|
|
27
|
+
item: string;
|
|
28
|
+
};
|
|
29
|
+
sm: {
|
|
30
|
+
item: string;
|
|
31
|
+
};
|
|
32
|
+
xs: {
|
|
33
|
+
root: string;
|
|
34
|
+
indicator: string;
|
|
35
|
+
item: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
icon: {
|
|
39
|
+
true: {
|
|
40
|
+
item: string;
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
}, {
|
|
44
|
+
root: string;
|
|
45
|
+
indicator: string;
|
|
46
|
+
item: string;
|
|
47
|
+
}, undefined, undefined, undefined, undefined>;
|
|
48
|
+
/** The pill's box, read from what `useSegmentedIndicator` wrote, hidden until it is measured. */
|
|
49
|
+
export declare const SEGMENTED_INDICATOR_BOX = "hidden h-(--indicator-height) w-(--indicator-width) translate-x-(--indicator-left) translate-y-(--indicator-top) in-data-measured:block";
|
|
50
|
+
/** A segmented row's raised key on the checked option itself, until the pill has a box to take. */
|
|
51
|
+
export declare const SEGMENTED_UNMEASURED_KEY = "[&:not([data-measured])_[data-checked]]:bg-surface [&:not([data-measured])_[data-checked]]:shadow-control [&:not([data-measured])_[data-checked]]:outline [&:not([data-measured])_[data-checked]]:-outline-offset-1 [&:not([data-measured])_[data-checked]]:outline-edge-strong";
|
|
52
|
+
/**
|
|
53
|
+
* Keeps a row's pill on its checked option: measures again when `value` changes and when the
|
|
54
|
+
* row resizes, as a label that wraps, a font that loads, or an option added later moves the
|
|
55
|
+
* checked one. The returned ref goes on the row.
|
|
56
|
+
*/
|
|
57
|
+
export declare function useSegmentedIndicator(value: unknown): RefObject<HTMLDivElement | null>;
|
package/lib/segmented.js
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { interactiveVariants } from "./interactive.js";
|
|
2
|
+
import { cn, variants } from "./variants.js";
|
|
3
|
+
import { useLayoutEffect, useRef } from "react";
|
|
4
|
+
// src/lib/segmented.ts
|
|
5
|
+
/**
|
|
6
|
+
* The row of options with one sliding pill behind the chosen one, shared by `Tabs` and
|
|
7
|
+
* `SegmentedControl`. Each component positions the pill from its own measurements and adds the
|
|
8
|
+
* state classes its primitive emits (`data-active` on a tab, `data-checked` on a radio), so
|
|
9
|
+
* the slots here hold only the shape.
|
|
10
|
+
*/
|
|
11
|
+
const segmentedVariants = variants({
|
|
12
|
+
slots: {
|
|
13
|
+
root: "relative inline-flex items-center text-ink-muted",
|
|
14
|
+
indicator: "absolute top-0 left-0 z-0 rounded-md transition-[translate,width,height] duration-200 ease-out-expo",
|
|
15
|
+
item: cn(interactiveVariants({ interactive: false }), "relative z-10 inline-flex items-center justify-center whitespace-nowrap font-medium", "hover:text-ink active:text-ink", "pointer-coarse:before:absolute pointer-coarse:before:inset-x-0 pointer-coarse:before:top-1/2 pointer-coarse:before:h-10 pointer-coarse:before:-translate-y-1/2")
|
|
16
|
+
},
|
|
17
|
+
variants: {
|
|
18
|
+
variant: {
|
|
19
|
+
segmented: {
|
|
20
|
+
root: "rounded-md bg-well shadow-well",
|
|
21
|
+
indicator: "rounded-md border border-edge-strong bg-surface shadow-control"
|
|
22
|
+
},
|
|
23
|
+
plain: {
|
|
24
|
+
root: "gap-0.5",
|
|
25
|
+
indicator: "rounded-md bg-fill"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
size: {
|
|
29
|
+
md: { item: "h-control rounded-md px-2.5 text-control" },
|
|
30
|
+
sm: { item: "h-7 rounded-md px-2 text-control" },
|
|
31
|
+
xs: {
|
|
32
|
+
root: "rounded",
|
|
33
|
+
indicator: "rounded",
|
|
34
|
+
item: "h-6 rounded px-1.5 text-xs"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
icon: { true: { item: "aspect-square px-0 [&_svg]:size-3.5" } }
|
|
38
|
+
},
|
|
39
|
+
compoundVariants: [{
|
|
40
|
+
size: "xs",
|
|
41
|
+
icon: true,
|
|
42
|
+
class: { item: "[&_svg]:size-3" }
|
|
43
|
+
}],
|
|
44
|
+
defaultVariants: {
|
|
45
|
+
variant: "segmented",
|
|
46
|
+
size: "md"
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
/** The pill's box, read from what `useSegmentedIndicator` wrote, hidden until it is measured. */
|
|
50
|
+
const SEGMENTED_INDICATOR_BOX = "hidden h-(--indicator-height) w-(--indicator-width) translate-x-(--indicator-left) translate-y-(--indicator-top) in-data-measured:block";
|
|
51
|
+
/** A segmented row's raised key on the checked option itself, until the pill has a box to take. */
|
|
52
|
+
const SEGMENTED_UNMEASURED_KEY = "[&:not([data-measured])_[data-checked]]:bg-surface [&:not([data-measured])_[data-checked]]:shadow-control [&:not([data-measured])_[data-checked]]:outline [&:not([data-measured])_[data-checked]]:-outline-offset-1 [&:not([data-measured])_[data-checked]]:outline-edge-strong";
|
|
53
|
+
/** Writes the checked option's box onto the row, where the pill reads it. */
|
|
54
|
+
function measure(root) {
|
|
55
|
+
const checked = root.querySelector("[role=\"radio\"][data-checked], [role=\"menuitemradio\"][data-checked]");
|
|
56
|
+
root.style.setProperty("--indicator-left", `${checked?.offsetLeft ?? 0}px`);
|
|
57
|
+
root.style.setProperty("--indicator-top", `${checked?.offsetTop ?? 0}px`);
|
|
58
|
+
root.style.setProperty("--indicator-width", `${checked?.offsetWidth ?? 0}px`);
|
|
59
|
+
root.style.setProperty("--indicator-height", `${checked?.offsetHeight ?? 0}px`);
|
|
60
|
+
root.dataset.measured = "";
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Keeps a row's pill on its checked option: measures again when `value` changes and when the
|
|
64
|
+
* row resizes, as a label that wraps, a font that loads, or an option added later moves the
|
|
65
|
+
* checked one. The returned ref goes on the row.
|
|
66
|
+
*/
|
|
67
|
+
function useSegmentedIndicator(value) {
|
|
68
|
+
const ref = useRef(null);
|
|
69
|
+
useLayoutEffect(() => {
|
|
70
|
+
if (ref.current) measure(ref.current);
|
|
71
|
+
}, [value]);
|
|
72
|
+
useLayoutEffect(() => {
|
|
73
|
+
const root = ref.current;
|
|
74
|
+
if (!root) return;
|
|
75
|
+
const observer = new ResizeObserver(() => measure(root));
|
|
76
|
+
observer.observe(root);
|
|
77
|
+
return () => observer.disconnect();
|
|
78
|
+
}, []);
|
|
79
|
+
return ref;
|
|
80
|
+
}
|
|
81
|
+
export { SEGMENTED_INDICATOR_BOX, SEGMENTED_UNMEASURED_KEY, segmentedVariants, useSegmentedIndicator };
|
|
82
|
+
|
|
83
|
+
//# sourceMappingURL=segmented.js.map
|