@fanvue/ui 3.30.0 → 3.31.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.
@@ -45,7 +45,7 @@ const trackPointer = (event) => {
45
45
  const { left, width } = event.currentTarget.getBoundingClientRect();
46
46
  event.currentTarget.style.setProperty("--fv-ai-x", `${(event.clientX - left) / width * 100}%`);
47
47
  };
48
- const ShimmerLabel = ({ text, disabled }) => /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", children: Array.from(text).map((character, index) => /* @__PURE__ */ jsxRuntime.jsx(
48
+ const ShimmerLabel = ({ text, shimmer }) => /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", children: Array.from(text).map((character, index) => /* @__PURE__ */ jsxRuntime.jsx(
49
49
  "span",
50
50
  {
51
51
  className: cn.cn(
@@ -54,7 +54,7 @@ const ShimmerLabel = ({ text, disabled }) => /* @__PURE__ */ jsxRuntime.jsx("spa
54
54
  // that would rely on the generated rule ordering to beat `group-hover`.
55
55
  // A faded control that still shimmers and still lights up green under the
56
56
  // cursor reads as busy rather than unavailable.
57
- !disabled && [
57
+ shimmer && [
58
58
  "[animation:fv-ai-letter_2s_ease-in-out_infinite]",
59
59
  "group-hover/ai:text-content-primary group-hover/ai:[animation:none]",
60
60
  // On focus each letter blows up and settles, then the idle shimmer
@@ -75,6 +75,7 @@ const AiButton = React__namespace.forwardRef(
75
75
  label,
76
76
  activeLabel,
77
77
  active = false,
78
+ idleShimmer = true,
78
79
  size = "32",
79
80
  icon,
80
81
  type = "button",
@@ -85,6 +86,7 @@ const AiButton = React__namespace.forwardRef(
85
86
  ...props
86
87
  }, ref) => {
87
88
  const resolvedActiveLabel = activeLabel ?? label;
89
+ const shimmer = !disabled && (idleShimmer || active);
88
90
  return /* @__PURE__ */ jsxRuntime.jsxs(
89
91
  "button",
90
92
  {
@@ -125,8 +127,8 @@ const AiButton = React__namespace.forwardRef(
125
127
  iconScaleVariants[size],
126
128
  "[filter:drop-shadow(0_0_2px_color-mix(in_srgb,var(--color-content-primary)_60%,transparent))]",
127
129
  // Same reasoning as the letters: no flicker and no green lift once the
128
- // button is unavailable.
129
- !disabled && [
130
+ // button is unavailable or shimmer is turned off for this instance.
131
+ shimmer && [
130
132
  "[animation-delay:0.5s] [animation:fv-ai-flicker_2s_linear_infinite]",
131
133
  // Settles solid on hover, lit green from below like the sheen.
132
134
  "group-hover/ai:[animation:none]",
@@ -146,7 +148,7 @@ const AiButton = React__namespace.forwardRef(
146
148
  "col-start-1 row-start-1 transition-opacity duration-300",
147
149
  active ? "opacity-0" : "opacity-100"
148
150
  ),
149
- children: /* @__PURE__ */ jsxRuntime.jsx(ShimmerLabel, { text: label, disabled })
151
+ children: /* @__PURE__ */ jsxRuntime.jsx(ShimmerLabel, { text: label, shimmer })
150
152
  }
151
153
  ),
152
154
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -156,7 +158,7 @@ const AiButton = React__namespace.forwardRef(
156
158
  "col-start-1 row-start-1 transition-opacity duration-300",
157
159
  active ? "opacity-100" : "opacity-0"
158
160
  ),
159
- children: /* @__PURE__ */ jsxRuntime.jsx(ShimmerLabel, { text: resolvedActiveLabel, disabled })
161
+ children: /* @__PURE__ */ jsxRuntime.jsx(ShimmerLabel, { text: resolvedActiveLabel, shimmer })
160
162
  }
161
163
  )
162
164
  ] })
@@ -1 +1 @@
1
- {"version":3,"file":"AiButton.cjs","sources":["../../../../src/components/AiButton/AiButton.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { AIIcon } from \"../Icons/AIIcon\";\nimport type { IconSize } from \"../Icons/types\";\n\n/** Height, padding and label typography, matching {@link Button}'s scale. */\nexport type AiButtonSize = \"24\" | \"32\" | \"40\";\n\nconst sizeVariants: Record<AiButtonSize, string> = {\n // At 24 the label steps down to the 12px description scale: the 14px label\n // Button uses at this height leaves the glyph and text crowding a 24px box,\n // since 16px is the smallest authored icon geometry and cannot step down with it.\n \"24\": \"h-6 gap-1 px-2 py-1 typography-description-12px-semibold\",\n \"32\": \"h-8 gap-2 px-3 py-[7px] typography-body-small-14px-semibold\",\n \"40\": \"h-10 gap-2 px-4 py-2 typography-body-default-16px-semibold\",\n};\n\nconst iconSizeVariants: Record<AiButtonSize, IconSize> = {\n \"24\": 16,\n \"32\": 16,\n \"40\": 24,\n};\n\n/**\n * Optical size, applied on top of the authored geometry. Only 16, 24 and 32 have\n * dedicated paths, so the 24 button renders the 16px glyph down at 14 to sit with\n * its 12px label rather than towering over it.\n */\nconst iconScaleVariants: Record<AiButtonSize, string> = {\n \"24\": \"[&_svg]:size-3.5\",\n \"32\": \"\",\n \"40\": \"\",\n};\n\n/** Delay between adjacent letters, in seconds. */\nconst LETTER_STAGGER = 0.08;\n\n/**\n * Points the bottom sheen at the cursor by writing its x offset, as a percentage\n * of the button's width, straight to the DOM node. Deliberately not React state:\n * this fires every pointer-move frame, and a re-render per frame would both cost\n * more than the paint and leave the glow trailing the cursor.\n */\nconst trackPointer = (event: React.PointerEvent<HTMLButtonElement>) => {\n const { left, width } = event.currentTarget.getBoundingClientRect();\n event.currentTarget.style.setProperty(\"--fv-ai-x\", `${((event.clientX - left) / width) * 100}%`);\n};\n\n/** Props for {@link AiButton}. */\nexport interface AiButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"type\"> {\n /** Resting label. Also the accessible name unless `aria-label` is given. */\n label: string;\n /** Label shown while `active`. Falls back to {@link label}. */\n activeLabel?: string;\n /** Swap to {@link activeLabel} and keep the shimmer running. @default false */\n active?: boolean;\n /** @default \"32\" */\n size?: AiButtonSize;\n /** Replace the leading AI glyph. */\n icon?: React.ReactNode;\n /** @default \"button\" */\n type?: \"button\" | \"submit\" | \"reset\";\n}\n\n/**\n * Renders one `<span>` per character so each can carry its own animation delay.\n * The run is hidden from assistive tech — the button's accessible name comes from\n * its `aria-label`, so a screen reader says \"Analyse\" rather than spelling it out.\n */\nconst ShimmerLabel: React.FC<{ text: string; disabled?: boolean }> = ({ text, disabled }) => (\n <span aria-hidden=\"true\">\n {Array.from(text).map((character, index) => (\n <span\n key={`${character}-${index}`}\n className={cn(\n \"inline-block whitespace-pre text-content-secondary\",\n // Gated in JS rather than with a `group-disabled/ai:` override, because\n // that would rely on the generated rule ordering to beat `group-hover`.\n // A faded control that still shimmers and still lights up green under the\n // cursor reads as busy rather than unavailable.\n !disabled && [\n \"[animation:fv-ai-letter_2s_ease-in-out_infinite]\",\n \"group-hover/ai:text-content-primary group-hover/ai:[animation:none]\",\n // On focus each letter blows up and settles, then the idle shimmer\n // resumes underneath it — the two animations are sequenced by delay.\n \"group-focus-visible/ai:[animation:fv-ai-letter-focus_1s_ease-in-out,fv-ai-letter_1.2s_ease-in-out_infinite_1s]\",\n \"group-active/ai:text-content-primary group-active/ai:[animation:none]\",\n \"group-active/ai:[text-shadow:0_0_4px_var(--color-content-primary)]\",\n ],\n \"motion-reduce:[animation:none]\",\n )}\n style={{ animationDelay: `${index * LETTER_STAGGER}s` }}\n >\n {character}\n </span>\n ))}\n </span>\n);\n\n/**\n * A pill button for AI actions. The label shimmers letter by letter and the glyph\n * flickers at rest; on hover both settle and the green treatment eases in together\n * — outline, rim and a sheen pooling along the bottom edge under the cursor, which\n * follows it across the button. On focus each letter blooms once before the shimmer\n * resumes. The lit rim and sheen come from the `fv-ai-button` utility in `base.css`.\n *\n * It shares {@link Button}'s geometry — `rounded-full`, the same heights and label\n * typography — so it sits alongside one without looking foreign. Both labels are\n * rendered stacked in a single grid cell, so swapping to `active` crossfades\n * without the button changing width.\n *\n * Honours `prefers-reduced-motion`: the shimmer and flicker are dropped and the\n * label renders in its settled state.\n *\n * @example\n * ```tsx\n * <AiButton label=\"Analyse\" activeLabel=\"Analysing\" active={isPending} onClick={run} />\n * ```\n */\nexport const AiButton = React.forwardRef<HTMLButtonElement, AiButtonProps>(\n (\n {\n label,\n activeLabel,\n active = false,\n size = \"32\",\n icon,\n type = \"button\",\n className,\n disabled,\n onPointerMove,\n onPointerLeave,\n ...props\n },\n ref,\n ) => {\n const resolvedActiveLabel = activeLabel ?? label;\n\n return (\n <button\n ref={ref}\n type={type}\n disabled={disabled}\n aria-label={props[\"aria-label\"] ?? (active ? resolvedActiveLabel : label)}\n aria-busy={active || undefined}\n onPointerMove={(event) => {\n trackPointer(event);\n onPointerMove?.(event);\n }}\n // Drop back to the utility's centred default, so a keyboard focus after\n // the pointer has left does not light up wherever the cursor last was.\n onPointerLeave={(event) => {\n event.currentTarget.style.removeProperty(\"--fv-ai-x\");\n onPointerLeave?.(event);\n }}\n className={cn(\n \"fv-ai-button\",\n \"group/ai inline-flex cursor-pointer items-center justify-center whitespace-nowrap rounded-full\",\n \"border border-border-primary bg-background-primary\",\n // Matched to the rim and sheen so the whole treatment arrives as one\n // movement — at the old 300ms the outline landed ahead of the glow.\n \"transition-[background-color,border-color] duration-[400ms] ease-out\",\n \"hover:border-brand-primary-default\",\n \"focus-visible:outline-none\",\n \"active:border-brand-primary-hover active:bg-brand-primary-muted\",\n \"disabled:cursor-not-allowed disabled:opacity-60 disabled:hover:border-border-primary\",\n sizeVariants[size],\n className,\n )}\n {...props}\n >\n <span\n className={cn(\n \"flex shrink-0 items-center text-content-primary\",\n iconScaleVariants[size],\n \"[filter:drop-shadow(0_0_2px_color-mix(in_srgb,var(--color-content-primary)_60%,transparent))]\",\n // Same reasoning as the letters: no flicker and no green lift once the\n // button is unavailable.\n !disabled && [\n \"[animation-delay:0.5s] [animation:fv-ai-flicker_2s_linear_infinite]\",\n // Settles solid on hover, lit green from below like the sheen.\n \"group-hover/ai:[animation:none]\",\n \"group-hover/ai:[filter:drop-shadow(0_0_3px_var(--color-brand-primary-default))_drop-shadow(0_-4px_6px_color-mix(in_srgb,var(--color-content-always-black)_60%,transparent))]\",\n \"group-focus-visible/ai:[animation-delay:0.2s] group-focus-visible/ai:[animation-duration:1.2s]\",\n ],\n \"motion-reduce:[animation:none]\",\n )}\n >\n {icon ?? <AIIcon size={iconSizeVariants[size]} filled />}\n </span>\n {/* Both labels occupy one grid cell so the button keeps the width of the\n longer of the two and the swap never reflows the row around it. */}\n <span className=\"grid\">\n <span\n className={cn(\n \"col-start-1 row-start-1 transition-opacity duration-300\",\n active ? \"opacity-0\" : \"opacity-100\",\n )}\n >\n <ShimmerLabel text={label} disabled={disabled} />\n </span>\n <span\n className={cn(\n \"col-start-1 row-start-1 transition-opacity duration-300\",\n active ? \"opacity-100\" : \"opacity-0\",\n )}\n >\n <ShimmerLabel text={resolvedActiveLabel} disabled={disabled} />\n </span>\n </span>\n </button>\n );\n },\n);\n\nAiButton.displayName = \"AiButton\";\n"],"names":["jsx","cn","React","jsxs","AIIcon"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAQA,MAAM,eAA6C;AAAA;AAAA;AAAA;AAAA,EAIjD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,mBAAmD;AAAA,EACvD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAOA,MAAM,oBAAkD;AAAA,EACtD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAGA,MAAM,iBAAiB;AAQvB,MAAM,eAAe,CAAC,UAAiD;AACrE,QAAM,EAAE,MAAM,MAAA,IAAU,MAAM,cAAc,sBAAA;AAC5C,QAAM,cAAc,MAAM,YAAY,aAAa,IAAK,MAAM,UAAU,QAAQ,QAAS,GAAG,GAAG;AACjG;AAuBA,MAAM,eAA+D,CAAC,EAAE,MAAM,SAAA,MAC5EA,+BAAC,QAAA,EAAK,eAAY,QACf,gBAAM,KAAK,IAAI,EAAE,IAAI,CAAC,WAAW,UAChCA,2BAAAA;AAAAA,EAAC;AAAA,EAAA;AAAA,IAEC,WAAWC,GAAAA;AAAAA,MACT;AAAA;AAAA;AAAA;AAAA;AAAA,MAKA,CAAC,YAAY;AAAA,QACX;AAAA,QACA;AAAA;AAAA;AAAA,QAGA;AAAA,QACA;AAAA,QACA;AAAA,M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AASG,eAAA,EAAO,MAAM,iBAAiB,IAAI,GAAG,QAAM,KAAA,CAAC;AAAA,YAAA;AAAA,UAAA;AAAA,UAIxDD,2BAAAA,KAAC,QAAA,EAAK,WAAU,QACd,UAAA;AAAA,YAAAH,2BAAAA;AAAAA,cAAC;AAAA,cAAA;AAAA,gBACC,WAAWC,GAAAA;AAAAA,kBACT;AAAA,kBACA,SAAS,cAAc;AAAA,gBAAA;AAAA,gBAGzB,UAAAD,2BAAAA,IAAC,cAAA,EAAa,MAAM,OAAO,SAAA,CAAoB;AAAA,cAAA;AAAA,YAAA;AAAA,YAEjDA,2BAAAA;AAAAA,cAAC;AAAA,cAAA;AAAA,gBACC,WAAWC,GAAAA;AAAAA,kBACT;AAAA,kBACA,SAAS,gBAAgB;AAAA,gBAAA;AAAA,gBAG3B,UAAAD,2BAAAA,IAAC,cAAA,EAAa,MAAM,qBAAqB,SAAA,CAAoB;AAAA,cAAA;AAAA,YAAA;AAAA,UAC/D,EAAA,CACF;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AACF;AAEA,SAAS,cAAc;;"}
1
+ {"version":3,"file":"AiButton.cjs","sources":["../../../../src/components/AiButton/AiButton.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { AIIcon } from \"../Icons/AIIcon\";\nimport type { IconSize } from \"../Icons/types\";\n\n/** Height, padding and label typography, matching {@link Button}'s scale. */\nexport type AiButtonSize = \"24\" | \"32\" | \"40\";\n\nconst sizeVariants: Record<AiButtonSize, string> = {\n // At 24 the label steps down to the 12px description scale: the 14px label\n // Button uses at this height leaves the glyph and text crowding a 24px box,\n // since 16px is the smallest authored icon geometry and cannot step down with it.\n \"24\": \"h-6 gap-1 px-2 py-1 typography-description-12px-semibold\",\n \"32\": \"h-8 gap-2 px-3 py-[7px] typography-body-small-14px-semibold\",\n \"40\": \"h-10 gap-2 px-4 py-2 typography-body-default-16px-semibold\",\n};\n\nconst iconSizeVariants: Record<AiButtonSize, IconSize> = {\n \"24\": 16,\n \"32\": 16,\n \"40\": 24,\n};\n\n/**\n * Optical size, applied on top of the authored geometry. Only 16, 24 and 32 have\n * dedicated paths, so the 24 button renders the 16px glyph down at 14 to sit with\n * its 12px label rather than towering over it.\n */\nconst iconScaleVariants: Record<AiButtonSize, string> = {\n \"24\": \"[&_svg]:size-3.5\",\n \"32\": \"\",\n \"40\": \"\",\n};\n\n/** Delay between adjacent letters, in seconds. */\nconst LETTER_STAGGER = 0.08;\n\n/**\n * Points the bottom sheen at the cursor by writing its x offset, as a percentage\n * of the button's width, straight to the DOM node. Deliberately not React state:\n * this fires every pointer-move frame, and a re-render per frame would both cost\n * more than the paint and leave the glow trailing the cursor.\n */\nconst trackPointer = (event: React.PointerEvent<HTMLButtonElement>) => {\n const { left, width } = event.currentTarget.getBoundingClientRect();\n event.currentTarget.style.setProperty(\"--fv-ai-x\", `${((event.clientX - left) / width) * 100}%`);\n};\n\n/** Props for {@link AiButton}. */\nexport interface AiButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"type\"> {\n /** Resting label. Also the accessible name unless `aria-label` is given. */\n label: string;\n /** Label shown while `active`. Falls back to {@link label}. */\n activeLabel?: string;\n /** Swap to {@link activeLabel} and keep the shimmer running. @default false */\n active?: boolean;\n /**\n * Shimmer and flicker while enabled and idle, inviting a click. Turn off when\n * several `AiButton`s sit side by side, so an idle one sits still and only the\n * `active` one reads as busy. @default true\n */\n idleShimmer?: boolean;\n /** @default \"32\" */\n size?: AiButtonSize;\n /** Replace the leading AI glyph. */\n icon?: React.ReactNode;\n /** @default \"button\" */\n type?: \"button\" | \"submit\" | \"reset\";\n}\n\n/**\n * Renders one `<span>` per character so each can carry its own animation delay.\n * The run is hidden from assistive tech — the button's accessible name comes from\n * its `aria-label`, so a screen reader says \"Analyse\" rather than spelling it out.\n */\nconst ShimmerLabel: React.FC<{ text: string; shimmer: boolean }> = ({ text, shimmer }) => (\n <span aria-hidden=\"true\">\n {Array.from(text).map((character, index) => (\n <span\n key={`${character}-${index}`}\n className={cn(\n \"inline-block whitespace-pre text-content-secondary\",\n // Gated in JS rather than with a `group-disabled/ai:` override, because\n // that would rely on the generated rule ordering to beat `group-hover`.\n // A faded control that still shimmers and still lights up green under the\n // cursor reads as busy rather than unavailable.\n shimmer && [\n \"[animation:fv-ai-letter_2s_ease-in-out_infinite]\",\n \"group-hover/ai:text-content-primary group-hover/ai:[animation:none]\",\n // On focus each letter blows up and settles, then the idle shimmer\n // resumes underneath it — the two animations are sequenced by delay.\n \"group-focus-visible/ai:[animation:fv-ai-letter-focus_1s_ease-in-out,fv-ai-letter_1.2s_ease-in-out_infinite_1s]\",\n \"group-active/ai:text-content-primary group-active/ai:[animation:none]\",\n \"group-active/ai:[text-shadow:0_0_4px_var(--color-content-primary)]\",\n ],\n \"motion-reduce:[animation:none]\",\n )}\n style={{ animationDelay: `${index * LETTER_STAGGER}s` }}\n >\n {character}\n </span>\n ))}\n </span>\n);\n\n/**\n * A pill button for AI actions. The label shimmers letter by letter and the glyph\n * flickers at rest; on hover both settle and the green treatment eases in together\n * — outline, rim and a sheen pooling along the bottom edge under the cursor, which\n * follows it across the button. On focus each letter blooms once before the shimmer\n * resumes. The lit rim and sheen come from the `fv-ai-button` utility in `base.css`.\n *\n * It shares {@link Button}'s geometry — `rounded-full`, the same heights and label\n * typography — so it sits alongside one without looking foreign. Both labels are\n * rendered stacked in a single grid cell, so swapping to `active` crossfades\n * without the button changing width.\n *\n * Honours `prefers-reduced-motion`: the shimmer and flicker are dropped and the\n * label renders in its settled state.\n *\n * Set `idleShimmer={false}` when several `AiButton`s sit side by side, so an\n * idle one sits still and the shimmer reads as \"this one is genuinely busy\"\n * rather than \"any of these could be clicked\".\n *\n * @example\n * ```tsx\n * <AiButton label=\"Analyse\" activeLabel=\"Analysing\" active={isPending} onClick={run} />\n * ```\n */\nexport const AiButton = React.forwardRef<HTMLButtonElement, AiButtonProps>(\n (\n {\n label,\n activeLabel,\n active = false,\n idleShimmer = true,\n size = \"32\",\n icon,\n type = \"button\",\n className,\n disabled,\n onPointerMove,\n onPointerLeave,\n ...props\n },\n ref,\n ) => {\n const resolvedActiveLabel = activeLabel ?? label;\n const shimmer = !disabled && (idleShimmer || active);\n\n return (\n <button\n ref={ref}\n type={type}\n disabled={disabled}\n aria-label={props[\"aria-label\"] ?? (active ? resolvedActiveLabel : label)}\n aria-busy={active || undefined}\n onPointerMove={(event) => {\n trackPointer(event);\n onPointerMove?.(event);\n }}\n // Drop back to the utility's centred default, so a keyboard focus after\n // the pointer has left does not light up wherever the cursor last was.\n onPointerLeave={(event) => {\n event.currentTarget.style.removeProperty(\"--fv-ai-x\");\n onPointerLeave?.(event);\n }}\n className={cn(\n \"fv-ai-button\",\n \"group/ai inline-flex cursor-pointer items-center justify-center whitespace-nowrap rounded-full\",\n \"border border-border-primary bg-background-primary\",\n // Matched to the rim and sheen so the whole treatment arrives as one\n // movement — at the old 300ms the outline landed ahead of the glow.\n \"transition-[background-color,border-color] duration-[400ms] ease-out\",\n \"hover:border-brand-primary-default\",\n \"focus-visible:outline-none\",\n \"active:border-brand-primary-hover active:bg-brand-primary-muted\",\n \"disabled:cursor-not-allowed disabled:opacity-60 disabled:hover:border-border-primary\",\n sizeVariants[size],\n className,\n )}\n {...props}\n >\n <span\n className={cn(\n \"flex shrink-0 items-center text-content-primary\",\n iconScaleVariants[size],\n \"[filter:drop-shadow(0_0_2px_color-mix(in_srgb,var(--color-content-primary)_60%,transparent))]\",\n // Same reasoning as the letters: no flicker and no green lift once the\n // button is unavailable or shimmer is turned off for this instance.\n shimmer && [\n \"[animation-delay:0.5s] [animation:fv-ai-flicker_2s_linear_infinite]\",\n // Settles solid on hover, lit green from below like the sheen.\n \"group-hover/ai:[animation:none]\",\n \"group-hover/ai:[filter:drop-shadow(0_0_3px_var(--color-brand-primary-default))_drop-shadow(0_-4px_6px_color-mix(in_srgb,var(--color-content-always-black)_60%,transparent))]\",\n \"group-focus-visible/ai:[animation-delay:0.2s] group-focus-visible/ai:[animation-duration:1.2s]\",\n ],\n \"motion-reduce:[animation:none]\",\n )}\n >\n {icon ?? <AIIcon size={iconSizeVariants[size]} filled />}\n </span>\n {/* Both labels occupy one grid cell so the button keeps the width of the\n longer of the two and the swap never reflows the row around it. */}\n <span className=\"grid\">\n <span\n className={cn(\n \"col-start-1 row-start-1 transition-opacity duration-300\",\n active ? \"opacity-0\" : \"opacity-100\",\n )}\n >\n <ShimmerLabel text={label} shimmer={shimmer} />\n </span>\n <span\n className={cn(\n \"col-start-1 row-start-1 transition-opacity duration-300\",\n active ? \"opacity-100\" : \"opacity-0\",\n )}\n >\n <ShimmerLabel text={resolvedActiveLabel} shimmer={shimmer} />\n </span>\n </span>\n </button>\n );\n },\n);\n\nAiButton.displayName = \"AiButton\";\n"],"names":["jsx","cn","React","jsxs","AIIcon"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAQA,MAAM,eAA6C;AAAA;AAAA;AAAA;AAAA,EAIjD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,mBAAmD;AAAA,EACvD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAOA,MAAM,oBAAkD;AAAA,EACtD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAGA,MAAM,iBAAiB;AAQvB,MAAM,eAAe,CAAC,UAAiD;AACrE,QAAM,EAAE,MAAM,MAAA,IAAU,MAAM,cAAc,sBAAA;AAC5C,QAAM,cAAc,MAAM,YAAY,aAAa,IAAK,MAAM,UAAU,QAAQ,QAAS,GAAG,GAAG;AACjG;AA6BA,MAAM,eAA6D,CAAC,EAAE,MAAM,QAAA,MAC1EA,+BAAC,QAAA,EAAK,eAAY,QACf,gBAAM,KAAK,IAAI,EAAE,IAAI,CAAC,WAAW,UAChCA,2BAAAA;AAAAA,EAAC;AAAA,EAAA;AAAA,IAEC,WAAWC,GAAAA;AAAAA,MACT;AAAA;AAAA;AAA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tB;AAAA;AAAA;AAAA,gBAGA,WAAW;AAAA,kBACT;AAAA;AAAA,kBAEA;AAAA,kBACA;AAAA,kBACA;AAAA,gBAAA;AAAA,gBAEF;AAAA,cAAA;AAAA,cAGD,UAAA,uCAASG,eAAA,EAAO,MAAM,iBAAiB,IAAI,GAAG,QAAM,KAAA,CAAC;AAAA,YAAA;AAAA,UAAA;AAAA,UAIxDD,2BAAAA,KAAC,QAAA,EAAK,WAAU,QACd,UAAA;AAAA,YAAAH,2BAAAA;AAAAA,cAAC;AAAA,cAAA;AAAA,gBACC,WAAWC,GAAAA;AAAAA,kBACT;AAAA,kBACA,SAAS,cAAc;AAAA,gBAAA;AAAA,gBAGzB,UAAAD,2BAAAA,IAAC,cAAA,EAAa,MAAM,OAAO,QAAA,CAAkB;AAAA,cAAA;AAAA,YAAA;AAAA,YAE/CA,2BAAAA;AAAAA,cAAC;AAAA,cAAA;AAAA,gBACC,WAAWC,GAAAA;AAAAA,kBACT;AAAA,kBACA,SAAS,gBAAgB;AAAA,gBAAA;AAAA,gBAG3B,UAAAD,2BAAAA,IAAC,cAAA,EAAa,MAAM,qBAAqB,QAAA,CAAkB;AAAA,cAAA;AAAA,YAAA;AAAA,UAC7D,EAAA,CACF;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AACF;AAEA,SAAS,cAAc;;"}
@@ -0,0 +1,97 @@
1
+ "use client";
2
+ "use strict";
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
+ const jsxRuntime = require("react/jsx-runtime");
5
+ const reactUseControllableState = require("@radix-ui/react-use-controllable-state");
6
+ const React = require("react");
7
+ const cn = require("../../utils/cn.cjs");
8
+ const AddIcon = require("../Icons/AddIcon.cjs");
9
+ const AIIcon = require("../Icons/AIIcon.cjs");
10
+ function _interopNamespaceDefault(e) {
11
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
12
+ if (e) {
13
+ for (const k in e) {
14
+ if (k !== "default") {
15
+ const d = Object.getOwnPropertyDescriptor(e, k);
16
+ Object.defineProperty(n, k, d.get ? d : {
17
+ enumerable: true,
18
+ get: () => e[k]
19
+ });
20
+ }
21
+ }
22
+ }
23
+ n.default = e;
24
+ return Object.freeze(n);
25
+ }
26
+ const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
27
+ const sizeVariants = {
28
+ "24": "h-6 px-2 py-1 typography-description-12px-semibold",
29
+ "32": "h-8 px-3 py-[7px] typography-body-small-14px-semibold",
30
+ "40": "h-10 px-4 py-2 typography-body-default-16px-semibold"
31
+ };
32
+ const ICON_SLOT_CLASSES = "flex size-4 shrink-0 items-center justify-center";
33
+ const AI_PRESSED_FILL = "relative bg-buttons-ai-default before:pointer-events-none before:absolute before:inset-0 before:rounded-full before:p-px before:[background:linear-gradient(90deg,var(--color-buttons-ai-stroke-end)_0%,var(--color-buttons-ai-stroke-start)_50%,var(--color-buttons-ai-stroke-end)_100%)] before:[mask:linear-gradient(#000_0_0)_content-box_exclude,linear-gradient(#000_0_0)]";
34
+ const SwitchButton = React__namespace.forwardRef(
35
+ ({
36
+ label,
37
+ size = "32",
38
+ variant = "default",
39
+ pressed: pressedProp,
40
+ defaultPressed = false,
41
+ onPressedChange,
42
+ showLeftIcon = false,
43
+ showRightIcon = false,
44
+ leftIcon,
45
+ rightIcon,
46
+ type = "button",
47
+ className,
48
+ disabled = false,
49
+ onClick,
50
+ ...props
51
+ }, ref) => {
52
+ const [pressed = false, setPressed] = reactUseControllableState.useControllableState({
53
+ prop: pressedProp,
54
+ defaultProp: defaultPressed,
55
+ onChange: onPressedChange
56
+ });
57
+ const isAi = variant === "ai";
58
+ const leading = isAi ? /* @__PURE__ */ jsxRuntime.jsx(AIIcon.AIIcon, { size: 16, filled: true }) : showLeftIcon ? leftIcon ?? /* @__PURE__ */ jsxRuntime.jsx(AddIcon.AddIcon, { size: 16 }) : void 0;
59
+ const trailing = !isAi && showRightIcon ? rightIcon ?? /* @__PURE__ */ jsxRuntime.jsx(AddIcon.AddIcon, { size: 16 }) : void 0;
60
+ return /* @__PURE__ */ jsxRuntime.jsxs(
61
+ "button",
62
+ {
63
+ ref,
64
+ type,
65
+ disabled,
66
+ "aria-pressed": pressed,
67
+ "data-state": pressed ? "on" : "off",
68
+ onClick: (event) => {
69
+ onClick?.(event);
70
+ if (event.defaultPrevented) return;
71
+ setPressed(!pressed);
72
+ },
73
+ className: cn.cn(
74
+ "inline-flex w-fit shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-full",
75
+ "motion-safe:transition-colors motion-safe:duration-150",
76
+ "focus-visible:shadow-focus-ring focus-visible:outline-none",
77
+ sizeVariants[size],
78
+ !disabled && "cursor-pointer",
79
+ !disabled && !pressed && "text-content-primary hover:bg-buttons-switch-hover",
80
+ !disabled && pressed && !isAi && "bg-buttons-switch-active text-content-primary-inverted shadow-sm",
81
+ !disabled && pressed && isAi && `text-content-primary shadow-sm ${AI_PRESSED_FILL}`,
82
+ disabled && "cursor-not-allowed text-content-disabled",
83
+ className
84
+ ),
85
+ ...props,
86
+ children: [
87
+ leading && /* @__PURE__ */ jsxRuntime.jsx("span", { className: ICON_SLOT_CLASSES, "aria-hidden": "true", children: leading }),
88
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "min-w-0 truncate", children: label }),
89
+ trailing && /* @__PURE__ */ jsxRuntime.jsx("span", { className: ICON_SLOT_CLASSES, "aria-hidden": "true", children: trailing })
90
+ ]
91
+ }
92
+ );
93
+ }
94
+ );
95
+ SwitchButton.displayName = "SwitchButton";
96
+ exports.SwitchButton = SwitchButton;
97
+ //# sourceMappingURL=SwitchButton.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SwitchButton.cjs","sources":["../../../../src/components/SwitchButton/SwitchButton.tsx"],"sourcesContent":["import { useControllableState } from \"@radix-ui/react-use-controllable-state\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { AddIcon } from \"../Icons/AddIcon\";\nimport { AIIcon } from \"../Icons/AIIcon\";\n\n/** Height of the button in pixels. Matches {@link Button}'s scale. */\nexport type SwitchButtonSize = \"24\" | \"32\" | \"40\";\n\n/** Visual treatment of the button. */\nexport type SwitchButtonVariant = \"default\" | \"ai\";\n\n/** Padding and label typography per size, from `Spacing/Global` xs/sm/md. */\nconst sizeVariants: Record<SwitchButtonSize, string> = {\n \"24\": \"h-6 px-2 py-1 typography-description-12px-semibold\",\n \"32\": \"h-8 px-3 py-[7px] typography-body-small-14px-semibold\",\n \"40\": \"h-10 px-4 py-2 typography-body-default-16px-semibold\",\n};\n\n/** Glyphs are a flat 16px at every size, per the design. */\nconst ICON_SLOT_CLASSES = \"flex size-4 shrink-0 items-center justify-center\";\n\n/**\n * Pressed `\"ai\"` treatment, matching Figma node `16800:9469`: the translucent\n * `Buttons/AI/Default` fill, plus a 1px stroke whose three-stop gradient runs\n * `Stroke-End → Stroke-Start → Stroke-End` horizontally.\n *\n * The stroke is a masked overlay rather than a border because Figma draws it with\n * `strokeAlign: INSIDE` — a real border would add 2px to the hug width and push\n * every size past its Figma dimensions.\n *\n * Written as one literal string because Tailwind scans source text — composing it\n * from parts stops the utilities being generated at all.\n */\nconst AI_PRESSED_FILL =\n \"relative bg-buttons-ai-default before:pointer-events-none before:absolute before:inset-0 before:rounded-full before:p-px before:[background:linear-gradient(90deg,var(--color-buttons-ai-stroke-end)_0%,var(--color-buttons-ai-stroke-start)_50%,var(--color-buttons-ai-stroke-end)_100%)] before:[mask:linear-gradient(#000_0_0)_content-box_exclude,linear-gradient(#000_0_0)]\";\n\ninterface SwitchButtonBaseProps\n extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"type\" | \"children\"> {\n /** Visible text label, which is also the accessible name. */\n label: string;\n /** Height of the button in pixels. @default \"32\" */\n size?: SwitchButtonSize;\n /** On/off state for controlled usage. Pair with `onPressedChange`. */\n pressed?: boolean;\n /** Initial on/off state for uncontrolled usage. @default false */\n defaultPressed?: boolean;\n /** Fired with the next state each time the button flips. */\n onPressedChange?: (pressed: boolean) => void;\n /** Native button behaviour. @default \"button\" */\n type?: \"button\" | \"submit\" | \"reset\";\n}\n\n/**\n * Props for the `\"default\"` variant, the only one with icon slots. The two are\n * independent: pass either, neither, or both.\n */\nexport interface SwitchButtonDefaultProps extends SwitchButtonBaseProps {\n /** Visual treatment. @default \"default\" */\n variant?: \"default\";\n /** Show an icon before the label. @default false */\n showLeftIcon?: boolean;\n /** Show an icon after the label. @default false */\n showRightIcon?: boolean;\n /** Icon rendered before the label when `showLeftIcon` is set. @default `<AddIcon size={16} />` */\n leftIcon?: React.ReactNode;\n /** Icon rendered after the label when `showRightIcon` is set. @default `<AddIcon size={16} />` */\n rightIcon?: React.ReactNode;\n}\n\n/**\n * Props for the `\"ai\"` variant. Its leading sparkle is fixed and it has no\n * trailing slot, so neither icon prop is available here.\n */\nexport interface SwitchButtonAiProps extends SwitchButtonBaseProps {\n /** Visual treatment. */\n variant: \"ai\";\n /** Unavailable on `\"ai\"` — the leading sparkle is always shown and cannot be swapped. */\n showLeftIcon?: never;\n /** Unavailable on `\"ai\"` — this variant has no trailing icon slot. */\n showRightIcon?: never;\n /** Unavailable on `\"ai\"` — the leading sparkle is fixed. */\n leftIcon?: never;\n /** Unavailable on `\"ai\"` — this variant has no trailing icon slot. */\n rightIcon?: never;\n}\n\n/**\n * Props for {@link SwitchButton}. A discriminated union on `variant`, so the icon\n * slots only type-check on the `\"default\"` variant.\n */\nexport type SwitchButtonProps = SwitchButtonDefaultProps | SwitchButtonAiProps;\n\n/**\n * A labelled pill that switches one feature or mode on and off, for settings\n * panels, filter bars and tool options. Unlike {@link Switch} it names the thing\n * it controls, which suits contexts where the action needs spelling out.\n *\n * Rendered as a `<button>` carrying `aria-pressed` — the ARIA toggle-button\n * pattern — so it flips on click and on Enter or Space, and exposes\n * `data-state=\"on\" | \"off\"` for styling. Supports controlled (`pressed`) and\n * uncontrolled (`defaultPressed`) usage. The visible `label` is the accessible\n * name, so no `aria-label` is needed.\n *\n * For two or three mutually exclusive options, reach for {@link SegmentedControl}\n * instead: this button is independently on or off, not a choice between options.\n *\n * @example\n * ```tsx\n * <SwitchButton label=\"Hide sold out\" pressed={hidden} onPressedChange={setHidden} />\n * ```\n *\n * @example Independent icon flags, available on the default variant only\n * ```tsx\n * <SwitchButton size=\"40\" label=\"Add filter\" showLeftIcon showRightIcon />\n * ```\n *\n * @example The AI variant, whose sparkle is fixed\n * ```tsx\n * <SwitchButton variant=\"ai\" label=\"Smart replies\" defaultPressed />\n * ```\n */\nexport const SwitchButton = React.forwardRef<HTMLButtonElement, SwitchButtonProps>(\n (\n {\n label,\n size = \"32\",\n variant = \"default\",\n pressed: pressedProp,\n defaultPressed = false,\n onPressedChange,\n showLeftIcon = false,\n showRightIcon = false,\n leftIcon,\n rightIcon,\n type = \"button\",\n className,\n disabled = false,\n onClick,\n ...props\n },\n ref,\n ) => {\n const [pressed = false, setPressed] = useControllableState({\n prop: pressedProp,\n defaultProp: defaultPressed,\n onChange: onPressedChange,\n });\n\n const isAi = variant === \"ai\";\n const leading = isAi ? (\n <AIIcon size={16} filled />\n ) : showLeftIcon ? (\n (leftIcon ?? <AddIcon size={16} />)\n ) : undefined;\n const trailing = !isAi && showRightIcon ? (rightIcon ?? <AddIcon size={16} />) : undefined;\n\n return (\n <button\n ref={ref}\n type={type}\n disabled={disabled}\n aria-pressed={pressed}\n data-state={pressed ? \"on\" : \"off\"}\n onClick={(event) => {\n onClick?.(event);\n // A consumer cancelling the event, typically to stop a `type=\"submit\"`\n // button submitting, means the interaction did not happen, so the state\n // must not flip either.\n if (event.defaultPrevented) return;\n setPressed(!pressed);\n }}\n className={cn(\n \"inline-flex w-fit shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-full\",\n \"motion-safe:transition-colors motion-safe:duration-150\",\n \"focus-visible:shadow-focus-ring focus-visible:outline-none\",\n sizeVariants[size],\n !disabled && \"cursor-pointer\",\n !disabled && !pressed && \"text-content-primary hover:bg-buttons-switch-hover\",\n !disabled &&\n pressed &&\n !isAi &&\n \"bg-buttons-switch-active text-content-primary-inverted shadow-sm\",\n !disabled && pressed && isAi && `text-content-primary shadow-sm ${AI_PRESSED_FILL}`,\n disabled && \"cursor-not-allowed text-content-disabled\",\n className,\n )}\n {...props}\n >\n {leading && (\n <span className={ICON_SLOT_CLASSES} aria-hidden=\"true\">\n {leading}\n </span>\n )}\n <span className=\"min-w-0 truncate\">{label}</span>\n {trailing && (\n <span className={ICON_SLOT_CLASSES} aria-hidden=\"true\">\n {trailing}\n </span>\n )}\n </button>\n );\n },\n);\n\nSwitchButton.displayName = \"SwitchButton\";\n"],"names":["React","useControllableState","jsx","AIIcon","AddIcon","jsxs","cn"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAaA,MAAM,eAAiD;AAAA,EACrD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAGA,MAAM,oBAAoB;AAc1B,MAAM,kBACJ;AAuFK,MAAM,eAAeA,iBAAM;AAAA,EAChC,CACE;AAAA,IACE;AAAA,IACA,OAAO;AAAA,IACP,UAAU;AAAA,IACV,SAAS;AAAA,IACT,iBAAiB;AAAA,IACjB;AAAA,IACA,eAAe;AAAA,IACf,gBAAgB;AAAA,IAChB;AAAA,IACA;AAAA,IACA,OAAO;AAAA,IACP;AAAA,IACA,WAAW;AAAA,IACX;AAAA,IACA,GAAG;AAAA,EAAA,GAEL,QACG;AACH,UAAM,CAAC,UAAU,OAAO,UAAU,IAAIC,0BAAAA,qBAAqB;AAAA,MACzD,MAAM;AAAA,MACN,aAAa;AAAA,MACb,UAAU;AAAA,IAAA,CACX;AAED,UAAM,OAAO,YAAY;AACzB,UAAM,UAAU,OACdC,2BAAAA,IAACC,OAAAA,QAAA,EAAO,MAAM,IAAI,QAAM,KAAA,CAAC,IACvB,eACD,YAAYD,+BAACE,QAAAA,SAAA,EAAQ,MAAM,IAAI,IAC9B;AACJ,UAAM,WAAW,CAAC,QAAQ,gBAAiB,aAAaF,+BAACE,QAAAA,SAAA,EAAQ,MAAM,GAAA,CAAI,IAAM;AAEjF,WACEC,2BAAAA;AAAAA,MAAC;AAAA,MAAA;AAAA,QACC;AAAA,QACA;AAAA,QACA;AAAA,QACA,gBAAc;AAAA,QACd,cAAY,UAAU,OAAO;AAAA,QAC7B,SAAS,CAAC,UAAU;AAClB,oBAAU,KAAK;AAIf,cAAI,MAAM,iBAAkB;AAC5B,qBAAW,CAAC,OAAO;AAAA,QACrB;AAAA,QACA,WAAWC,GAAAA;AAAAA,UACT;AAAA,UACA;AAAA,UACA;AAAA,UACA,aAAa,IAAI;AAAA,UACjB,CAAC,YAAY;AAAA,UACb,CAAC,YAAY,CAAC,WAAW;AAAA,UACzB,CAAC,YACC,WACA,CAAC,QACD;AAAA,UACF,CAAC,YAAY,WAAW,QAAQ,kCAAkC,eAAe;AAAA,UACjF,YAAY;AAAA,UACZ;AAAA,QAAA;AAAA,QAED,GAAG;AAAA,QAEH,UAAA;AAAA,UAAA,0CACE,QAAA,EAAK,WAAW,mBAAmB,eAAY,QAC7C,UAAA,SACH;AAAA,UAEFJ,2BAAAA,IAAC,QAAA,EAAK,WAAU,oBAAoB,UAAA,OAAM;AAAA,UACzC,YACCA,2BAAAA,IAAC,QAAA,EAAK,WAAW,mBAAmB,eAAY,QAC7C,UAAA,SAAA,CACH;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEA,aAAa,cAAc;;"}
@@ -249,6 +249,7 @@ const Stepper = require("./components/Stepper/Stepper.cjs");
249
249
  const StepperStep = require("./components/Stepper/StepperStep.cjs");
250
250
  const SubscribeButton = require("./components/SubscribeButton/SubscribeButton.cjs");
251
251
  const Switch = require("./components/Switch/Switch.cjs");
252
+ const SwitchButton = require("./components/SwitchButton/SwitchButton.cjs");
252
253
  const SwitchField = require("./components/SwitchField/SwitchField.cjs");
253
254
  const SwitchToggle = require("./components/SwitchToggle/SwitchToggle.cjs");
254
255
  const Table = require("./components/Table/Table.cjs");
@@ -575,6 +576,7 @@ exports.Stepper = Stepper.Stepper;
575
576
  exports.StepperStep = StepperStep.StepperStep;
576
577
  exports.SubscribeButton = SubscribeButton.SubscribeButton;
577
578
  exports.Switch = Switch.Switch;
579
+ exports.SwitchButton = SwitchButton.SwitchButton;
578
580
  exports.SwitchField = SwitchField.SwitchField;
579
581
  exports.SwitchToggle = SwitchToggle.SwitchToggle;
580
582
  exports.Table = Table.Table;
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -26,7 +26,7 @@ const trackPointer = (event) => {
26
26
  const { left, width } = event.currentTarget.getBoundingClientRect();
27
27
  event.currentTarget.style.setProperty("--fv-ai-x", `${(event.clientX - left) / width * 100}%`);
28
28
  };
29
- const ShimmerLabel = ({ text, disabled }) => /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: Array.from(text).map((character, index) => /* @__PURE__ */ jsx(
29
+ const ShimmerLabel = ({ text, shimmer }) => /* @__PURE__ */ jsx("span", { "aria-hidden": "true", children: Array.from(text).map((character, index) => /* @__PURE__ */ jsx(
30
30
  "span",
31
31
  {
32
32
  className: cn(
@@ -35,7 +35,7 @@ const ShimmerLabel = ({ text, disabled }) => /* @__PURE__ */ jsx("span", { "aria
35
35
  // that would rely on the generated rule ordering to beat `group-hover`.
36
36
  // A faded control that still shimmers and still lights up green under the
37
37
  // cursor reads as busy rather than unavailable.
38
- !disabled && [
38
+ shimmer && [
39
39
  "[animation:fv-ai-letter_2s_ease-in-out_infinite]",
40
40
  "group-hover/ai:text-content-primary group-hover/ai:[animation:none]",
41
41
  // On focus each letter blows up and settles, then the idle shimmer
@@ -56,6 +56,7 @@ const AiButton = React.forwardRef(
56
56
  label,
57
57
  activeLabel,
58
58
  active = false,
59
+ idleShimmer = true,
59
60
  size = "32",
60
61
  icon,
61
62
  type = "button",
@@ -66,6 +67,7 @@ const AiButton = React.forwardRef(
66
67
  ...props
67
68
  }, ref) => {
68
69
  const resolvedActiveLabel = activeLabel ?? label;
70
+ const shimmer = !disabled && (idleShimmer || active);
69
71
  return /* @__PURE__ */ jsxs(
70
72
  "button",
71
73
  {
@@ -106,8 +108,8 @@ const AiButton = React.forwardRef(
106
108
  iconScaleVariants[size],
107
109
  "[filter:drop-shadow(0_0_2px_color-mix(in_srgb,var(--color-content-primary)_60%,transparent))]",
108
110
  // Same reasoning as the letters: no flicker and no green lift once the
109
- // button is unavailable.
110
- !disabled && [
111
+ // button is unavailable or shimmer is turned off for this instance.
112
+ shimmer && [
111
113
  "[animation-delay:0.5s] [animation:fv-ai-flicker_2s_linear_infinite]",
112
114
  // Settles solid on hover, lit green from below like the sheen.
113
115
  "group-hover/ai:[animation:none]",
@@ -127,7 +129,7 @@ const AiButton = React.forwardRef(
127
129
  "col-start-1 row-start-1 transition-opacity duration-300",
128
130
  active ? "opacity-0" : "opacity-100"
129
131
  ),
130
- children: /* @__PURE__ */ jsx(ShimmerLabel, { text: label, disabled })
132
+ children: /* @__PURE__ */ jsx(ShimmerLabel, { text: label, shimmer })
131
133
  }
132
134
  ),
133
135
  /* @__PURE__ */ jsx(
@@ -137,7 +139,7 @@ const AiButton = React.forwardRef(
137
139
  "col-start-1 row-start-1 transition-opacity duration-300",
138
140
  active ? "opacity-100" : "opacity-0"
139
141
  ),
140
- children: /* @__PURE__ */ jsx(ShimmerLabel, { text: resolvedActiveLabel, disabled })
142
+ children: /* @__PURE__ */ jsx(ShimmerLabel, { text: resolvedActiveLabel, shimmer })
141
143
  }
142
144
  )
143
145
  ] })
@@ -1 +1 @@
1
- {"version":3,"file":"AiButton.mjs","sources":["../../../src/components/AiButton/AiButton.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { AIIcon } from \"../Icons/AIIcon\";\nimport type { IconSize } from \"../Icons/types\";\n\n/** Height, padding and label typography, matching {@link Button}'s scale. */\nexport type AiButtonSize = \"24\" | \"32\" | \"40\";\n\nconst sizeVariants: Record<AiButtonSize, string> = {\n // At 24 the label steps down to the 12px description scale: the 14px label\n // Button uses at this height leaves the glyph and text crowding a 24px box,\n // since 16px is the smallest authored icon geometry and cannot step down with it.\n \"24\": \"h-6 gap-1 px-2 py-1 typography-description-12px-semibold\",\n \"32\": \"h-8 gap-2 px-3 py-[7px] typography-body-small-14px-semibold\",\n \"40\": \"h-10 gap-2 px-4 py-2 typography-body-default-16px-semibold\",\n};\n\nconst iconSizeVariants: Record<AiButtonSize, IconSize> = {\n \"24\": 16,\n \"32\": 16,\n \"40\": 24,\n};\n\n/**\n * Optical size, applied on top of the authored geometry. Only 16, 24 and 32 have\n * dedicated paths, so the 24 button renders the 16px glyph down at 14 to sit with\n * its 12px label rather than towering over it.\n */\nconst iconScaleVariants: Record<AiButtonSize, string> = {\n \"24\": \"[&_svg]:size-3.5\",\n \"32\": \"\",\n \"40\": \"\",\n};\n\n/** Delay between adjacent letters, in seconds. */\nconst LETTER_STAGGER = 0.08;\n\n/**\n * Points the bottom sheen at the cursor by writing its x offset, as a percentage\n * of the button's width, straight to the DOM node. Deliberately not React state:\n * this fires every pointer-move frame, and a re-render per frame would both cost\n * more than the paint and leave the glow trailing the cursor.\n */\nconst trackPointer = (event: React.PointerEvent<HTMLButtonElement>) => {\n const { left, width } = event.currentTarget.getBoundingClientRect();\n event.currentTarget.style.setProperty(\"--fv-ai-x\", `${((event.clientX - left) / width) * 100}%`);\n};\n\n/** Props for {@link AiButton}. */\nexport interface AiButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"type\"> {\n /** Resting label. Also the accessible name unless `aria-label` is given. */\n label: string;\n /** Label shown while `active`. Falls back to {@link label}. */\n activeLabel?: string;\n /** Swap to {@link activeLabel} and keep the shimmer running. @default false */\n active?: boolean;\n /** @default \"32\" */\n size?: AiButtonSize;\n /** Replace the leading AI glyph. */\n icon?: React.ReactNode;\n /** @default \"button\" */\n type?: \"button\" | \"submit\" | \"reset\";\n}\n\n/**\n * Renders one `<span>` per character so each can carry its own animation delay.\n * The run is hidden from assistive tech — the button's accessible name comes from\n * its `aria-label`, so a screen reader says \"Analyse\" rather than spelling it out.\n */\nconst ShimmerLabel: React.FC<{ text: string; disabled?: boolean }> = ({ text, disabled }) => (\n <span aria-hidden=\"true\">\n {Array.from(text).map((character, index) => (\n <span\n key={`${character}-${index}`}\n className={cn(\n \"inline-block whitespace-pre text-content-secondary\",\n // Gated in JS rather than with a `group-disabled/ai:` override, because\n // that would rely on the generated rule ordering to beat `group-hover`.\n // A faded control that still shimmers and still lights up green under the\n // cursor reads as busy rather than unavailable.\n !disabled && [\n \"[animation:fv-ai-letter_2s_ease-in-out_infinite]\",\n \"group-hover/ai:text-content-primary group-hover/ai:[animation:none]\",\n // On focus each letter blows up and settles, then the idle shimmer\n // resumes underneath it — the two animations are sequenced by delay.\n \"group-focus-visible/ai:[animation:fv-ai-letter-focus_1s_ease-in-out,fv-ai-letter_1.2s_ease-in-out_infinite_1s]\",\n \"group-active/ai:text-content-primary group-active/ai:[animation:none]\",\n \"group-active/ai:[text-shadow:0_0_4px_var(--color-content-primary)]\",\n ],\n \"motion-reduce:[animation:none]\",\n )}\n style={{ animationDelay: `${index * LETTER_STAGGER}s` }}\n >\n {character}\n </span>\n ))}\n </span>\n);\n\n/**\n * A pill button for AI actions. The label shimmers letter by letter and the glyph\n * flickers at rest; on hover both settle and the green treatment eases in together\n * — outline, rim and a sheen pooling along the bottom edge under the cursor, which\n * follows it across the button. On focus each letter blooms once before the shimmer\n * resumes. The lit rim and sheen come from the `fv-ai-button` utility in `base.css`.\n *\n * It shares {@link Button}'s geometry — `rounded-full`, the same heights and label\n * typography — so it sits alongside one without looking foreign. Both labels are\n * rendered stacked in a single grid cell, so swapping to `active` crossfades\n * without the button changing width.\n *\n * Honours `prefers-reduced-motion`: the shimmer and flicker are dropped and the\n * label renders in its settled state.\n *\n * @example\n * ```tsx\n * <AiButton label=\"Analyse\" activeLabel=\"Analysing\" active={isPending} onClick={run} />\n * ```\n */\nexport const AiButton = React.forwardRef<HTMLButtonElement, AiButtonProps>(\n (\n {\n label,\n activeLabel,\n active = false,\n size = \"32\",\n icon,\n type = \"button\",\n className,\n disabled,\n onPointerMove,\n onPointerLeave,\n ...props\n },\n ref,\n ) => {\n const resolvedActiveLabel = activeLabel ?? label;\n\n return (\n <button\n ref={ref}\n type={type}\n disabled={disabled}\n aria-label={props[\"aria-label\"] ?? (active ? resolvedActiveLabel : label)}\n aria-busy={active || undefined}\n onPointerMove={(event) => {\n trackPointer(event);\n onPointerMove?.(event);\n }}\n // Drop back to the utility's centred default, so a keyboard focus after\n // the pointer has left does not light up wherever the cursor last was.\n onPointerLeave={(event) => {\n event.currentTarget.style.removeProperty(\"--fv-ai-x\");\n onPointerLeave?.(event);\n }}\n className={cn(\n \"fv-ai-button\",\n \"group/ai inline-flex cursor-pointer items-center justify-center whitespace-nowrap rounded-full\",\n \"border border-border-primary bg-background-primary\",\n // Matched to the rim and sheen so the whole treatment arrives as one\n // movement — at the old 300ms the outline landed ahead of the glow.\n \"transition-[background-color,border-color] duration-[400ms] ease-out\",\n \"hover:border-brand-primary-default\",\n \"focus-visible:outline-none\",\n \"active:border-brand-primary-hover active:bg-brand-primary-muted\",\n \"disabled:cursor-not-allowed disabled:opacity-60 disabled:hover:border-border-primary\",\n sizeVariants[size],\n className,\n )}\n {...props}\n >\n <span\n className={cn(\n \"flex shrink-0 items-center text-content-primary\",\n iconScaleVariants[size],\n \"[filter:drop-shadow(0_0_2px_color-mix(in_srgb,var(--color-content-primary)_60%,transparent))]\",\n // Same reasoning as the letters: no flicker and no green lift once the\n // button is unavailable.\n !disabled && [\n \"[animation-delay:0.5s] [animation:fv-ai-flicker_2s_linear_infinite]\",\n // Settles solid on hover, lit green from below like the sheen.\n \"group-hover/ai:[animation:none]\",\n \"group-hover/ai:[filter:drop-shadow(0_0_3px_var(--color-brand-primary-default))_drop-shadow(0_-4px_6px_color-mix(in_srgb,var(--color-content-always-black)_60%,transparent))]\",\n \"group-focus-visible/ai:[animation-delay:0.2s] group-focus-visible/ai:[animation-duration:1.2s]\",\n ],\n \"motion-reduce:[animation:none]\",\n )}\n >\n {icon ?? <AIIcon size={iconSizeVariants[size]} filled />}\n </span>\n {/* Both labels occupy one grid cell so the button keeps the width of the\n longer of the two and the swap never reflows the row around it. */}\n <span className=\"grid\">\n <span\n className={cn(\n \"col-start-1 row-start-1 transition-opacity duration-300\",\n active ? \"opacity-0\" : \"opacity-100\",\n )}\n >\n <ShimmerLabel text={label} disabled={disabled} />\n </span>\n <span\n className={cn(\n \"col-start-1 row-start-1 transition-opacity duration-300\",\n active ? \"opacity-100\" : \"opacity-0\",\n )}\n >\n <ShimmerLabel text={resolvedActiveLabel} disabled={disabled} />\n </span>\n </span>\n </button>\n );\n },\n);\n\nAiButton.displayName = \"AiButton\";\n"],"names":[],"mappings":";;;;;AAQA,MAAM,eAA6C;AAAA;AAAA;AAAA;AAAA,EAIjD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,mBAAmD;AAAA,EACvD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAOA,MAAM,oBAAkD;AAAA,EACtD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAGA,MAAM,iBAAiB;AAQvB,MAAM,eAAe,CAAC,UAAiD;AACrE,QAAM,EAAE,MAAM,MAAA,IAAU,MAAM,cAAc,sBAAA;AAC5C,QAAM,cAAc,MAAM,YAAY,aAAa,IAAK,M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;AAAA,QAAA;AAAA,QAED,GAAG;AAAA,QAEJ,UAAA;AAAA,UAAA;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,WAAW;AAAA,gBACT;AAAA,gBACA,kBAAkB,IAAI;AAAA,gBACtB;AAAA;AAAA;AAAA,gBAGA,CAAC,YAAY;AAAA,kBACX;AAAA;AAAA,kBAEA;AAAA,kBACA;AAAA,kBACA;AAAA,gBAAA;AAAA,gBAEF;AAAA,cAAA;AAAA,cAGD,UAAA,4BAAS,QAAA,EAAO,MAAM,iBAAiB,IAAI,GAAG,QAAM,KAAA,CAAC;AAAA,YAAA;AAAA,UAAA;AAAA,UAIxD,qBAAC,QAAA,EAAK,WAAU,QACd,UAAA;AAAA,YAAA;AAAA,cAAC;AAAA,cAAA;AAAA,gBACC,WAAW;AAAA,kBACT;AAAA,kBACA,SAAS,cAAc;AAAA,gBAAA;AAAA,gBAGzB,UAAA,oBAAC,cAAA,EAAa,MAAM,OAAO,SAAA,CAAoB;AAAA,cAAA;AAAA,YAAA;AAAA,YAEjD;AAAA,cAAC;AAAA,cAAA;AAAA,gBACC,WAAW;AAAA,kBACT;AAAA,kBACA,SAAS,gBAAgB;AAAA,gBAAA;AAAA,gBAG3B,UAAA,oBAAC,cAAA,EAAa,MAAM,qBAAqB,SAAA,CAAoB;AAAA,cAAA;AAAA,YAAA;AAAA,UAC/D,EAAA,CACF;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AACF;AAEA,SAAS,cAAc;"}
1
+ {"version":3,"file":"AiButton.mjs","sources":["../../../src/components/AiButton/AiButton.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { AIIcon } from \"../Icons/AIIcon\";\nimport type { IconSize } from \"../Icons/types\";\n\n/** Height, padding and label typography, matching {@link Button}'s scale. */\nexport type AiButtonSize = \"24\" | \"32\" | \"40\";\n\nconst sizeVariants: Record<AiButtonSize, string> = {\n // At 24 the label steps down to the 12px description scale: the 14px label\n // Button uses at this height leaves the glyph and text crowding a 24px box,\n // since 16px is the smallest authored icon geometry and cannot step down with it.\n \"24\": \"h-6 gap-1 px-2 py-1 typography-description-12px-semibold\",\n \"32\": \"h-8 gap-2 px-3 py-[7px] typography-body-small-14px-semibold\",\n \"40\": \"h-10 gap-2 px-4 py-2 typography-body-default-16px-semibold\",\n};\n\nconst iconSizeVariants: Record<AiButtonSize, IconSize> = {\n \"24\": 16,\n \"32\": 16,\n \"40\": 24,\n};\n\n/**\n * Optical size, applied on top of the authored geometry. Only 16, 24 and 32 have\n * dedicated paths, so the 24 button renders the 16px glyph down at 14 to sit with\n * its 12px label rather than towering over it.\n */\nconst iconScaleVariants: Record<AiButtonSize, string> = {\n \"24\": \"[&_svg]:size-3.5\",\n \"32\": \"\",\n \"40\": \"\",\n};\n\n/** Delay between adjacent letters, in seconds. */\nconst LETTER_STAGGER = 0.08;\n\n/**\n * Points the bottom sheen at the cursor by writing its x offset, as a percentage\n * of the button's width, straight to the DOM node. Deliberately not React state:\n * this fires every pointer-move frame, and a re-render per frame would both cost\n * more than the paint and leave the glow trailing the cursor.\n */\nconst trackPointer = (event: React.PointerEvent<HTMLButtonElement>) => {\n const { left, width } = event.currentTarget.getBoundingClientRect();\n event.currentTarget.style.setProperty(\"--fv-ai-x\", `${((event.clientX - left) / width) * 100}%`);\n};\n\n/** Props for {@link AiButton}. */\nexport interface AiButtonProps extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"type\"> {\n /** Resting label. Also the accessible name unless `aria-label` is given. */\n label: string;\n /** Label shown while `active`. Falls back to {@link label}. */\n activeLabel?: string;\n /** Swap to {@link activeLabel} and keep the shimmer running. @default false */\n active?: boolean;\n /**\n * Shimmer and flicker while enabled and idle, inviting a click. Turn off when\n * several `AiButton`s sit side by side, so an idle one sits still and only the\n * `active` one reads as busy. @default true\n */\n idleShimmer?: boolean;\n /** @default \"32\" */\n size?: AiButtonSize;\n /** Replace the leading AI glyph. */\n icon?: React.ReactNode;\n /** @default \"button\" */\n type?: \"button\" | \"submit\" | \"reset\";\n}\n\n/**\n * Renders one `<span>` per character so each can carry its own animation delay.\n * The run is hidden from assistive tech — the button's accessible name comes from\n * its `aria-label`, so a screen reader says \"Analyse\" rather than spelling it out.\n */\nconst ShimmerLabel: React.FC<{ text: string; shimmer: boolean }> = ({ text, shimmer }) => (\n <span aria-hidden=\"true\">\n {Array.from(text).map((character, index) => (\n <span\n key={`${character}-${index}`}\n className={cn(\n \"inline-block whitespace-pre text-content-secondary\",\n // Gated in JS rather than with a `group-disabled/ai:` override, because\n // that would rely on the generated rule ordering to beat `group-hover`.\n // A faded control that still shimmers and still lights up green under the\n // cursor reads as busy rather than unavailable.\n shimmer && [\n \"[animation:fv-ai-letter_2s_ease-in-out_infinite]\",\n \"group-hover/ai:text-content-primary group-hover/ai:[animation:none]\",\n // On focus each letter blows up and settles, then the idle shimmer\n // resumes underneath it — the two animations are sequenced by delay.\n \"group-focus-visible/ai:[animation:fv-ai-letter-focus_1s_ease-in-out,fv-ai-letter_1.2s_ease-in-out_infinite_1s]\",\n \"group-active/ai:text-content-primary group-active/ai:[animation:none]\",\n \"group-active/ai:[text-shadow:0_0_4px_var(--color-content-primary)]\",\n ],\n \"motion-reduce:[animation:none]\",\n )}\n style={{ animationDelay: `${index * LETTER_STAGGER}s` }}\n >\n {character}\n </span>\n ))}\n </span>\n);\n\n/**\n * A pill button for AI actions. The label shimmers letter by letter and the glyph\n * flickers at rest; on hover both settle and the green treatment eases in together\n * — outline, rim and a sheen pooling along the bottom edge under the cursor, which\n * follows it across the button. On focus each letter blooms once before the shimmer\n * resumes. The lit rim and sheen come from the `fv-ai-button` utility in `base.css`.\n *\n * It shares {@link Button}'s geometry — `rounded-full`, the same heights and label\n * typography — so it sits alongside one without looking foreign. Both labels are\n * rendered stacked in a single grid cell, so swapping to `active` crossfades\n * without the button changing width.\n *\n * Honours `prefers-reduced-motion`: the shimmer and flicker are dropped and the\n * label renders in its settled state.\n *\n * Set `idleShimmer={false}` when several `AiButton`s sit side by side, so an\n * idle one sits still and the shimmer reads as \"this one is genuinely busy\"\n * rather than \"any of these could be clicked\".\n *\n * @example\n * ```tsx\n * <AiButton label=\"Analyse\" activeLabel=\"Analysing\" active={isPending} onClick={run} />\n * ```\n */\nexport const AiButton = React.forwardRef<HTMLButtonElement, AiButtonProps>(\n (\n {\n label,\n activeLabel,\n active = false,\n idleShimmer = true,\n size = \"32\",\n icon,\n type = \"button\",\n className,\n disabled,\n onPointerMove,\n onPointerLeave,\n ...props\n },\n ref,\n ) => {\n const resolvedActiveLabel = activeLabel ?? label;\n const shimmer = !disabled && (idleShimmer || active);\n\n return (\n <button\n ref={ref}\n type={type}\n disabled={disabled}\n aria-label={props[\"aria-label\"] ?? (active ? resolvedActiveLabel : label)}\n aria-busy={active || undefined}\n onPointerMove={(event) => {\n trackPointer(event);\n onPointerMove?.(event);\n }}\n // Drop back to the utility's centred default, so a keyboard focus after\n // the pointer has left does not light up wherever the cursor last was.\n onPointerLeave={(event) => {\n event.currentTarget.style.removeProperty(\"--fv-ai-x\");\n onPointerLeave?.(event);\n }}\n className={cn(\n \"fv-ai-button\",\n \"group/ai inline-flex cursor-pointer items-center justify-center whitespace-nowrap rounded-full\",\n \"border border-border-primary bg-background-primary\",\n // Matched to the rim and sheen so the whole treatment arrives as one\n // movement — at the old 300ms the outline landed ahead of the glow.\n \"transition-[background-color,border-color] duration-[400ms] ease-out\",\n \"hover:border-brand-primary-default\",\n \"focus-visible:outline-none\",\n \"active:border-brand-primary-hover active:bg-brand-primary-muted\",\n \"disabled:cursor-not-allowed disabled:opacity-60 disabled:hover:border-border-primary\",\n sizeVariants[size],\n className,\n )}\n {...props}\n >\n <span\n className={cn(\n \"flex shrink-0 items-center text-content-primary\",\n iconScaleVariants[size],\n \"[filter:drop-shadow(0_0_2px_color-mix(in_srgb,var(--color-content-primary)_60%,transparent))]\",\n // Same reasoning as the letters: no flicker and no green lift once the\n // button is unavailable or shimmer is turned off for this instance.\n shimmer && [\n \"[animation-delay:0.5s] [animation:fv-ai-flicker_2s_linear_infinite]\",\n // Settles solid on hover, lit green from below like the sheen.\n \"group-hover/ai:[animation:none]\",\n \"group-hover/ai:[filter:drop-shadow(0_0_3px_var(--color-brand-primary-default))_drop-shadow(0_-4px_6px_color-mix(in_srgb,var(--color-content-always-black)_60%,transparent))]\",\n \"group-focus-visible/ai:[animation-delay:0.2s] group-focus-visible/ai:[animation-duration:1.2s]\",\n ],\n \"motion-reduce:[animation:none]\",\n )}\n >\n {icon ?? <AIIcon size={iconSizeVariants[size]} filled />}\n </span>\n {/* Both labels occupy one grid cell so the button keeps the width of the\n longer of the two and the swap never reflows the row around it. */}\n <span className=\"grid\">\n <span\n className={cn(\n \"col-start-1 row-start-1 transition-opacity duration-300\",\n active ? \"opacity-0\" : \"opacity-100\",\n )}\n >\n <ShimmerLabel text={label} shimmer={shimmer} />\n </span>\n <span\n className={cn(\n \"col-start-1 row-start-1 transition-opacity duration-300\",\n active ? \"opacity-100\" : \"opacity-0\",\n )}\n >\n <ShimmerLabel text={resolvedActiveLabel} shimmer={shimmer} />\n </span>\n </span>\n </button>\n );\n },\n);\n\nAiButton.displayName = \"AiButton\";\n"],"names":[],"mappings":";;;;;AAQA,MAAM,eAA6C;AAAA;AAAA;AAAA;AAAA,EAIjD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAEA,MAAM,mBAAmD;AAAA,EACvD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAOA,MAAM,oBAAkD;AAAA,EACtD,MAAM;AAAA,EACN,MAAM;AAAA,EACN,MAAM;AACR;AAGA,MAAM,iBAAiB;AAQvB,MAAM,eAAe,CAAC,UAAiD;AACrE,QAAM,EAAE,MAAM,MAAA,IAAU,MAAM,cAAc,sBAAA;AAC5C,QAAM,cAAc,MAAM,YAAY,aAAa,IAAK,MAAM,UAAU,QAAQ,QAAS,GAAG,GAAG;AACjG;AA6BA,MAAM,eAA6D,CAAC,EAAE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AAG;AAAA,QAEJ,UAAA;AAAA,UAAA;AAAA,YAAC;AAAA,YAAA;AAAA,cACC,WAAW;AAAA,gBACT;AAAA,gBACA,kBAAkB,IAAI;AAAA,gBACtB;AAAA;AAAA;AAAA,gBAGA,WAAW;AAAA,kBACT;AAAA;AAAA,kBAEA;AAAA,kBACA;AAAA,kBACA;AAAA,gBAAA;AAAA,gBAEF;AAAA,cAAA;AAAA,cAGD,UAAA,4BAAS,QAAA,EAAO,MAAM,iBAAiB,IAAI,GAAG,QAAM,KAAA,CAAC;AAAA,YAAA;AAAA,UAAA;AAAA,UAIxD,qBAAC,QAAA,EAAK,WAAU,QACd,UAAA;AAAA,YAAA;AAAA,cAAC;AAAA,cAAA;AAAA,gBACC,WAAW;AAAA,kBACT;AAAA,kBACA,SAAS,cAAc;AAAA,gBAAA;AAAA,gBAGzB,UAAA,oBAAC,cAAA,EAAa,MAAM,OAAO,QAAA,CAAkB;AAAA,cAAA;AAAA,YAAA;AAAA,YAE/C;AAAA,cAAC;AAAA,cAAA;AAAA,gBACC,WAAW;AAAA,kBACT;AAAA,kBACA,SAAS,gBAAgB;AAAA,gBAAA;AAAA,gBAG3B,UAAA,oBAAC,cAAA,EAAa,MAAM,qBAAqB,QAAA,CAAkB;AAAA,cAAA;AAAA,YAAA;AAAA,UAC7D,EAAA,CACF;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAGN;AACF;AAEA,SAAS,cAAc;"}
@@ -0,0 +1,80 @@
1
+ "use client";
2
+ import { jsxs, jsx } from "react/jsx-runtime";
3
+ import { useControllableState } from "@radix-ui/react-use-controllable-state";
4
+ import * as React from "react";
5
+ import { cn } from "../../utils/cn.mjs";
6
+ import { AddIcon } from "../Icons/AddIcon.mjs";
7
+ import { AIIcon } from "../Icons/AIIcon.mjs";
8
+ const sizeVariants = {
9
+ "24": "h-6 px-2 py-1 typography-description-12px-semibold",
10
+ "32": "h-8 px-3 py-[7px] typography-body-small-14px-semibold",
11
+ "40": "h-10 px-4 py-2 typography-body-default-16px-semibold"
12
+ };
13
+ const ICON_SLOT_CLASSES = "flex size-4 shrink-0 items-center justify-center";
14
+ const AI_PRESSED_FILL = "relative bg-buttons-ai-default before:pointer-events-none before:absolute before:inset-0 before:rounded-full before:p-px before:[background:linear-gradient(90deg,var(--color-buttons-ai-stroke-end)_0%,var(--color-buttons-ai-stroke-start)_50%,var(--color-buttons-ai-stroke-end)_100%)] before:[mask:linear-gradient(#000_0_0)_content-box_exclude,linear-gradient(#000_0_0)]";
15
+ const SwitchButton = React.forwardRef(
16
+ ({
17
+ label,
18
+ size = "32",
19
+ variant = "default",
20
+ pressed: pressedProp,
21
+ defaultPressed = false,
22
+ onPressedChange,
23
+ showLeftIcon = false,
24
+ showRightIcon = false,
25
+ leftIcon,
26
+ rightIcon,
27
+ type = "button",
28
+ className,
29
+ disabled = false,
30
+ onClick,
31
+ ...props
32
+ }, ref) => {
33
+ const [pressed = false, setPressed] = useControllableState({
34
+ prop: pressedProp,
35
+ defaultProp: defaultPressed,
36
+ onChange: onPressedChange
37
+ });
38
+ const isAi = variant === "ai";
39
+ const leading = isAi ? /* @__PURE__ */ jsx(AIIcon, { size: 16, filled: true }) : showLeftIcon ? leftIcon ?? /* @__PURE__ */ jsx(AddIcon, { size: 16 }) : void 0;
40
+ const trailing = !isAi && showRightIcon ? rightIcon ?? /* @__PURE__ */ jsx(AddIcon, { size: 16 }) : void 0;
41
+ return /* @__PURE__ */ jsxs(
42
+ "button",
43
+ {
44
+ ref,
45
+ type,
46
+ disabled,
47
+ "aria-pressed": pressed,
48
+ "data-state": pressed ? "on" : "off",
49
+ onClick: (event) => {
50
+ onClick?.(event);
51
+ if (event.defaultPrevented) return;
52
+ setPressed(!pressed);
53
+ },
54
+ className: cn(
55
+ "inline-flex w-fit shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-full",
56
+ "motion-safe:transition-colors motion-safe:duration-150",
57
+ "focus-visible:shadow-focus-ring focus-visible:outline-none",
58
+ sizeVariants[size],
59
+ !disabled && "cursor-pointer",
60
+ !disabled && !pressed && "text-content-primary hover:bg-buttons-switch-hover",
61
+ !disabled && pressed && !isAi && "bg-buttons-switch-active text-content-primary-inverted shadow-sm",
62
+ !disabled && pressed && isAi && `text-content-primary shadow-sm ${AI_PRESSED_FILL}`,
63
+ disabled && "cursor-not-allowed text-content-disabled",
64
+ className
65
+ ),
66
+ ...props,
67
+ children: [
68
+ leading && /* @__PURE__ */ jsx("span", { className: ICON_SLOT_CLASSES, "aria-hidden": "true", children: leading }),
69
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 truncate", children: label }),
70
+ trailing && /* @__PURE__ */ jsx("span", { className: ICON_SLOT_CLASSES, "aria-hidden": "true", children: trailing })
71
+ ]
72
+ }
73
+ );
74
+ }
75
+ );
76
+ SwitchButton.displayName = "SwitchButton";
77
+ export {
78
+ SwitchButton
79
+ };
80
+ //# sourceMappingURL=SwitchButton.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SwitchButton.mjs","sources":["../../../src/components/SwitchButton/SwitchButton.tsx"],"sourcesContent":["import { useControllableState } from \"@radix-ui/react-use-controllable-state\";\nimport * as React from \"react\";\nimport { cn } from \"../../utils/cn\";\nimport { AddIcon } from \"../Icons/AddIcon\";\nimport { AIIcon } from \"../Icons/AIIcon\";\n\n/** Height of the button in pixels. Matches {@link Button}'s scale. */\nexport type SwitchButtonSize = \"24\" | \"32\" | \"40\";\n\n/** Visual treatment of the button. */\nexport type SwitchButtonVariant = \"default\" | \"ai\";\n\n/** Padding and label typography per size, from `Spacing/Global` xs/sm/md. */\nconst sizeVariants: Record<SwitchButtonSize, string> = {\n \"24\": \"h-6 px-2 py-1 typography-description-12px-semibold\",\n \"32\": \"h-8 px-3 py-[7px] typography-body-small-14px-semibold\",\n \"40\": \"h-10 px-4 py-2 typography-body-default-16px-semibold\",\n};\n\n/** Glyphs are a flat 16px at every size, per the design. */\nconst ICON_SLOT_CLASSES = \"flex size-4 shrink-0 items-center justify-center\";\n\n/**\n * Pressed `\"ai\"` treatment, matching Figma node `16800:9469`: the translucent\n * `Buttons/AI/Default` fill, plus a 1px stroke whose three-stop gradient runs\n * `Stroke-End → Stroke-Start → Stroke-End` horizontally.\n *\n * The stroke is a masked overlay rather than a border because Figma draws it with\n * `strokeAlign: INSIDE` — a real border would add 2px to the hug width and push\n * every size past its Figma dimensions.\n *\n * Written as one literal string because Tailwind scans source text — composing it\n * from parts stops the utilities being generated at all.\n */\nconst AI_PRESSED_FILL =\n \"relative bg-buttons-ai-default before:pointer-events-none before:absolute before:inset-0 before:rounded-full before:p-px before:[background:linear-gradient(90deg,var(--color-buttons-ai-stroke-end)_0%,var(--color-buttons-ai-stroke-start)_50%,var(--color-buttons-ai-stroke-end)_100%)] before:[mask:linear-gradient(#000_0_0)_content-box_exclude,linear-gradient(#000_0_0)]\";\n\ninterface SwitchButtonBaseProps\n extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"type\" | \"children\"> {\n /** Visible text label, which is also the accessible name. */\n label: string;\n /** Height of the button in pixels. @default \"32\" */\n size?: SwitchButtonSize;\n /** On/off state for controlled usage. Pair with `onPressedChange`. */\n pressed?: boolean;\n /** Initial on/off state for uncontrolled usage. @default false */\n defaultPressed?: boolean;\n /** Fired with the next state each time the button flips. */\n onPressedChange?: (pressed: boolean) => void;\n /** Native button behaviour. @default \"button\" */\n type?: \"button\" | \"submit\" | \"reset\";\n}\n\n/**\n * Props for the `\"default\"` variant, the only one with icon slots. The two are\n * independent: pass either, neither, or both.\n */\nexport interface SwitchButtonDefaultProps extends SwitchButtonBaseProps {\n /** Visual treatment. @default \"default\" */\n variant?: \"default\";\n /** Show an icon before the label. @default false */\n showLeftIcon?: boolean;\n /** Show an icon after the label. @default false */\n showRightIcon?: boolean;\n /** Icon rendered before the label when `showLeftIcon` is set. @default `<AddIcon size={16} />` */\n leftIcon?: React.ReactNode;\n /** Icon rendered after the label when `showRightIcon` is set. @default `<AddIcon size={16} />` */\n rightIcon?: React.ReactNode;\n}\n\n/**\n * Props for the `\"ai\"` variant. Its leading sparkle is fixed and it has no\n * trailing slot, so neither icon prop is available here.\n */\nexport interface SwitchButtonAiProps extends SwitchButtonBaseProps {\n /** Visual treatment. */\n variant: \"ai\";\n /** Unavailable on `\"ai\"` — the leading sparkle is always shown and cannot be swapped. */\n showLeftIcon?: never;\n /** Unavailable on `\"ai\"` — this variant has no trailing icon slot. */\n showRightIcon?: never;\n /** Unavailable on `\"ai\"` — the leading sparkle is fixed. */\n leftIcon?: never;\n /** Unavailable on `\"ai\"` — this variant has no trailing icon slot. */\n rightIcon?: never;\n}\n\n/**\n * Props for {@link SwitchButton}. A discriminated union on `variant`, so the icon\n * slots only type-check on the `\"default\"` variant.\n */\nexport type SwitchButtonProps = SwitchButtonDefaultProps | SwitchButtonAiProps;\n\n/**\n * A labelled pill that switches one feature or mode on and off, for settings\n * panels, filter bars and tool options. Unlike {@link Switch} it names the thing\n * it controls, which suits contexts where the action needs spelling out.\n *\n * Rendered as a `<button>` carrying `aria-pressed` — the ARIA toggle-button\n * pattern — so it flips on click and on Enter or Space, and exposes\n * `data-state=\"on\" | \"off\"` for styling. Supports controlled (`pressed`) and\n * uncontrolled (`defaultPressed`) usage. The visible `label` is the accessible\n * name, so no `aria-label` is needed.\n *\n * For two or three mutually exclusive options, reach for {@link SegmentedControl}\n * instead: this button is independently on or off, not a choice between options.\n *\n * @example\n * ```tsx\n * <SwitchButton label=\"Hide sold out\" pressed={hidden} onPressedChange={setHidden} />\n * ```\n *\n * @example Independent icon flags, available on the default variant only\n * ```tsx\n * <SwitchButton size=\"40\" label=\"Add filter\" showLeftIcon showRightIcon />\n * ```\n *\n * @example The AI variant, whose sparkle is fixed\n * ```tsx\n * <SwitchButton variant=\"ai\" label=\"Smart replies\" defaultPressed />\n * ```\n */\nexport const SwitchButton = React.forwardRef<HTMLButtonElement, SwitchButtonProps>(\n (\n {\n label,\n size = \"32\",\n variant = \"default\",\n pressed: pressedProp,\n defaultPressed = false,\n onPressedChange,\n showLeftIcon = false,\n showRightIcon = false,\n leftIcon,\n rightIcon,\n type = \"button\",\n className,\n disabled = false,\n onClick,\n ...props\n },\n ref,\n ) => {\n const [pressed = false, setPressed] = useControllableState({\n prop: pressedProp,\n defaultProp: defaultPressed,\n onChange: onPressedChange,\n });\n\n const isAi = variant === \"ai\";\n const leading = isAi ? (\n <AIIcon size={16} filled />\n ) : showLeftIcon ? (\n (leftIcon ?? <AddIcon size={16} />)\n ) : undefined;\n const trailing = !isAi && showRightIcon ? (rightIcon ?? <AddIcon size={16} />) : undefined;\n\n return (\n <button\n ref={ref}\n type={type}\n disabled={disabled}\n aria-pressed={pressed}\n data-state={pressed ? \"on\" : \"off\"}\n onClick={(event) => {\n onClick?.(event);\n // A consumer cancelling the event, typically to stop a `type=\"submit\"`\n // button submitting, means the interaction did not happen, so the state\n // must not flip either.\n if (event.defaultPrevented) return;\n setPressed(!pressed);\n }}\n className={cn(\n \"inline-flex w-fit shrink-0 items-center justify-center gap-2 whitespace-nowrap rounded-full\",\n \"motion-safe:transition-colors motion-safe:duration-150\",\n \"focus-visible:shadow-focus-ring focus-visible:outline-none\",\n sizeVariants[size],\n !disabled && \"cursor-pointer\",\n !disabled && !pressed && \"text-content-primary hover:bg-buttons-switch-hover\",\n !disabled &&\n pressed &&\n !isAi &&\n \"bg-buttons-switch-active text-content-primary-inverted shadow-sm\",\n !disabled && pressed && isAi && `text-content-primary shadow-sm ${AI_PRESSED_FILL}`,\n disabled && \"cursor-not-allowed text-content-disabled\",\n className,\n )}\n {...props}\n >\n {leading && (\n <span className={ICON_SLOT_CLASSES} aria-hidden=\"true\">\n {leading}\n </span>\n )}\n <span className=\"min-w-0 truncate\">{label}</span>\n {trailing && (\n <span className={ICON_SLOT_CLASSES} aria-hidden=\"true\">\n {trailing}\n </span>\n )}\n </button>\n );\n },\n);\n\nSwitchButton.displayName = \"SwitchButton\";\n"],"names":[],"mappings":";;;;;;;AAaA,MAAM,eAAiD;AAAA,EACrD,M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QAED,GAAG;AAAA,QAEH,UAAA;AAAA,UAAA,+BACE,QAAA,EAAK,WAAW,mBAAmB,eAAY,QAC7C,UAAA,SACH;AAAA,UAEF,oBAAC,QAAA,EAAK,WAAU,oBAAoB,UAAA,OAAM;AAAA,UACzC,YACC,oBAAC,QAAA,EAAK,WAAW,mBAAmB,eAAY,QAC7C,UAAA,SAAA,CACH;AAAA,QAAA;AAAA,MAAA;AAAA,IAAA;AAAA,EAIR;AACF;AAEA,aAAa,cAAc;"}
package/dist/index.d.ts CHANGED
@@ -153,6 +153,10 @@ export declare type AI2IconProps = BaseIconProps;
153
153
  * Honours `prefers-reduced-motion`: the shimmer and flicker are dropped and the
154
154
  * label renders in its settled state.
155
155
  *
156
+ * Set `idleShimmer={false}` when several `AiButton`s sit side by side, so an
157
+ * idle one sits still and the shimmer reads as "this one is genuinely busy"
158
+ * rather than "any of these could be clicked".
159
+ *
156
160
  * @example
157
161
  * ```tsx
158
162
  * <AiButton label="Analyse" activeLabel="Analysing" active={isPending} onClick={run} />
@@ -168,6 +172,12 @@ export declare interface AiButtonProps extends Omit<React_2.ButtonHTMLAttributes
168
172
  activeLabel?: string;
169
173
  /** Swap to {@link activeLabel} and keep the shimmer running. @default false */
170
174
  active?: boolean;
175
+ /**
176
+ * Shimmer and flicker while enabled and idle, inviting a click. Turn off when
177
+ * several `AiButton`s sit side by side, so an idle one sits still and only the
178
+ * `active` one reads as busy. @default true
179
+ */
180
+ idleShimmer?: boolean;
171
181
  /** @default "32" */
172
182
  size?: AiButtonSize;
173
183
  /** Replace the leading AI glyph. */
@@ -5574,6 +5584,98 @@ export declare type SupportIconProps = BaseIconProps;
5574
5584
  */
5575
5585
  export declare const Switch: React_2.ForwardRefExoticComponent<SwitchProps & React_2.RefAttributes<HTMLButtonElement>>;
5576
5586
 
5587
+ /**
5588
+ * A labelled pill that switches one feature or mode on and off, for settings
5589
+ * panels, filter bars and tool options. Unlike {@link Switch} it names the thing
5590
+ * it controls, which suits contexts where the action needs spelling out.
5591
+ *
5592
+ * Rendered as a `<button>` carrying `aria-pressed` — the ARIA toggle-button
5593
+ * pattern — so it flips on click and on Enter or Space, and exposes
5594
+ * `data-state="on" | "off"` for styling. Supports controlled (`pressed`) and
5595
+ * uncontrolled (`defaultPressed`) usage. The visible `label` is the accessible
5596
+ * name, so no `aria-label` is needed.
5597
+ *
5598
+ * For two or three mutually exclusive options, reach for {@link SegmentedControl}
5599
+ * instead: this button is independently on or off, not a choice between options.
5600
+ *
5601
+ * @example
5602
+ * ```tsx
5603
+ * <SwitchButton label="Hide sold out" pressed={hidden} onPressedChange={setHidden} />
5604
+ * ```
5605
+ *
5606
+ * @example Independent icon flags, available on the default variant only
5607
+ * ```tsx
5608
+ * <SwitchButton size="40" label="Add filter" showLeftIcon showRightIcon />
5609
+ * ```
5610
+ *
5611
+ * @example The AI variant, whose sparkle is fixed
5612
+ * ```tsx
5613
+ * <SwitchButton variant="ai" label="Smart replies" defaultPressed />
5614
+ * ```
5615
+ */
5616
+ export declare const SwitchButton: React_2.ForwardRefExoticComponent<SwitchButtonProps & React_2.RefAttributes<HTMLButtonElement>>;
5617
+
5618
+ /**
5619
+ * Props for the `"ai"` variant. Its leading sparkle is fixed and it has no
5620
+ * trailing slot, so neither icon prop is available here.
5621
+ */
5622
+ export declare interface SwitchButtonAiProps extends SwitchButtonBaseProps {
5623
+ /** Visual treatment. */
5624
+ variant: "ai";
5625
+ /** Unavailable on `"ai"` — the leading sparkle is always shown and cannot be swapped. */
5626
+ showLeftIcon?: never;
5627
+ /** Unavailable on `"ai"` — this variant has no trailing icon slot. */
5628
+ showRightIcon?: never;
5629
+ /** Unavailable on `"ai"` — the leading sparkle is fixed. */
5630
+ leftIcon?: never;
5631
+ /** Unavailable on `"ai"` — this variant has no trailing icon slot. */
5632
+ rightIcon?: never;
5633
+ }
5634
+
5635
+ declare interface SwitchButtonBaseProps extends Omit<React_2.ButtonHTMLAttributes<HTMLButtonElement>, "type" | "children"> {
5636
+ /** Visible text label, which is also the accessible name. */
5637
+ label: string;
5638
+ /** Height of the button in pixels. @default "32" */
5639
+ size?: SwitchButtonSize;
5640
+ /** On/off state for controlled usage. Pair with `onPressedChange`. */
5641
+ pressed?: boolean;
5642
+ /** Initial on/off state for uncontrolled usage. @default false */
5643
+ defaultPressed?: boolean;
5644
+ /** Fired with the next state each time the button flips. */
5645
+ onPressedChange?: (pressed: boolean) => void;
5646
+ /** Native button behaviour. @default "button" */
5647
+ type?: "button" | "submit" | "reset";
5648
+ }
5649
+
5650
+ /**
5651
+ * Props for the `"default"` variant, the only one with icon slots. The two are
5652
+ * independent: pass either, neither, or both.
5653
+ */
5654
+ export declare interface SwitchButtonDefaultProps extends SwitchButtonBaseProps {
5655
+ /** Visual treatment. @default "default" */
5656
+ variant?: "default";
5657
+ /** Show an icon before the label. @default false */
5658
+ showLeftIcon?: boolean;
5659
+ /** Show an icon after the label. @default false */
5660
+ showRightIcon?: boolean;
5661
+ /** Icon rendered before the label when `showLeftIcon` is set. @default `<AddIcon size={16} />` */
5662
+ leftIcon?: React_2.ReactNode;
5663
+ /** Icon rendered after the label when `showRightIcon` is set. @default `<AddIcon size={16} />` */
5664
+ rightIcon?: React_2.ReactNode;
5665
+ }
5666
+
5667
+ /**
5668
+ * Props for {@link SwitchButton}. A discriminated union on `variant`, so the icon
5669
+ * slots only type-check on the `"default"` variant.
5670
+ */
5671
+ export declare type SwitchButtonProps = SwitchButtonDefaultProps | SwitchButtonAiProps;
5672
+
5673
+ /** Height of the button in pixels. Matches {@link Button}'s scale. */
5674
+ export declare type SwitchButtonSize = "24" | "32" | "40";
5675
+
5676
+ /** Visual treatment of the button. */
5677
+ export declare type SwitchButtonVariant = "default" | "ai";
5678
+
5577
5679
  /**
5578
5680
  * A labelled switch field with optional helper text and info tooltip. Composes
5579
5681
  * the {@link Switch} component with a `<label>` and description.
package/dist/index.mjs CHANGED
@@ -247,6 +247,7 @@ import { Stepper } from "./components/Stepper/Stepper.mjs";
247
247
  import { StepperStep } from "./components/Stepper/StepperStep.mjs";
248
248
  import { SubscribeButton } from "./components/SubscribeButton/SubscribeButton.mjs";
249
249
  import { Switch } from "./components/Switch/Switch.mjs";
250
+ import { SwitchButton } from "./components/SwitchButton/SwitchButton.mjs";
250
251
  import { SwitchField } from "./components/SwitchField/SwitchField.mjs";
251
252
  import { SwitchToggle } from "./components/SwitchToggle/SwitchToggle.mjs";
252
253
  import { Table, TableBody, TableCard, TableCell, TableCellContent, TableCellGroup, TableFooter, TableHead, TableHeader, TableLineClamp, TableMediaThumbnail, TablePillProgressLayout, TableProgressTrack, TableRow, TableRowsPerPageSelect, TableScrollArea, TableSortLabel, TableStackedText, TableStatusDot, TableToolbar } from "./components/Table/Table.mjs";
@@ -533,6 +534,7 @@ export {
533
534
  Support2Icon,
534
535
  SupportIcon,
535
536
  Switch,
537
+ SwitchButton,
536
538
  SwitchField,
537
539
  SwitchToggle,
538
540
  Table,
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fanvue/ui",
3
- "version": "3.30.0",
3
+ "version": "3.31.0",
4
4
  "description": "React component library built with Tailwind CSS for Fanvue ecosystem",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org",