@spark-ui/components 11.1.4 → 11.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/docgen.json CHANGED
@@ -37649,6 +37649,25 @@
37649
37649
  "name": "string"
37650
37650
  }
37651
37651
  },
37652
+ "aria-valuetext": {
37653
+ "defaultValue": null,
37654
+ "description": "Textual representation of the current value (aria-valuetext)\nBy default, percentage is used (e.g. \"33%\")",
37655
+ "name": "aria-valuetext",
37656
+ "parent": {
37657
+ "fileName": "src/segmented-gauge/SegmentedGauge.tsx",
37658
+ "name": "SegmentedGaugeProps"
37659
+ },
37660
+ "declarations": [
37661
+ {
37662
+ "fileName": "src/segmented-gauge/SegmentedGauge.tsx",
37663
+ "name": "SegmentedGaugeProps"
37664
+ }
37665
+ ],
37666
+ "required": false,
37667
+ "type": {
37668
+ "name": "string"
37669
+ }
37670
+ },
37652
37671
  "className": {
37653
37672
  "defaultValue": null,
37654
37673
  "description": "Additional CSS classes",
@@ -38,6 +38,11 @@ interface SegmentedGaugeProps {
38
38
  * Accessible label for the gauge (required if no id is provided)
39
39
  */
40
40
  'aria-label'?: string;
41
+ /**
42
+ * Textual representation of the current value (aria-valuetext)
43
+ * By default, percentage is used (e.g. "33%")
44
+ */
45
+ 'aria-valuetext'?: string;
41
46
  /**
42
47
  * Additional CSS classes
43
48
  */
@@ -38,6 +38,11 @@ interface SegmentedGaugeProps {
38
38
  * Accessible label for the gauge (required if no id is provided)
39
39
  */
40
40
  'aria-label'?: string;
41
+ /**
42
+ * Textual representation of the current value (aria-valuetext)
43
+ * By default, percentage is used (e.g. "33%")
44
+ */
45
+ 'aria-valuetext'?: string;
41
46
  /**
42
47
  * Additional CSS classes
43
48
  */
@@ -225,12 +225,6 @@ var SegmentedGauge = ({
225
225
  }),
226
226
  [value, min, max, segments, currentIndex, size, intent, customColor, internalLabelId, gaugeId]
227
227
  );
228
- if (children) {
229
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SegmentedGaugeContext.Provider, { value: contextValue, children: children({
230
- segments: segmentsData,
231
- currentIndex
232
- }) });
233
- }
234
228
  const roleProps = value != null ? {
235
229
  role: "meter",
236
230
  "aria-valuenow": value,
@@ -239,22 +233,25 @@ var SegmentedGauge = ({
239
233
  } : {
240
234
  role: "status"
241
235
  };
242
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SegmentedGaugeContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
236
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SegmentedGaugeContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
243
237
  "div",
244
238
  {
245
239
  id: gaugeId,
246
240
  "data-spark-component": "segmented-gauge",
247
241
  ref,
248
- className: (0, import_class_variance_authority4.cx)("gap-md flex items-center", className),
242
+ className: (0, import_class_variance_authority4.cx)("gap-md flex flex-wrap items-center", className),
249
243
  ...roleProps,
250
244
  "aria-labelledby": id ? `${gaugeId}-label` : void 0,
251
245
  "aria-label": !id ? ariaLabel : void 0,
252
246
  "aria-describedby": internalLabelId,
253
247
  ...props,
254
- children: [
248
+ children: children ? children({
249
+ segments: segmentsData,
250
+ currentIndex
251
+ }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(import_jsx_runtime4.Fragment, { children: [
255
252
  /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SegmentedGaugeTrack, { children: segmentsData.map((_, index) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SegmentedGaugeSegment, { index }, index)) }),
256
253
  description && /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SegmentedGaugeLabel, { id: internalLabelId, children: description })
257
- ]
254
+ ] })
258
255
  }
259
256
  ) });
260
257
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/segmented-gauge/index.ts","../../src/segmented-gauge/SegmentedGauge.tsx","../../src/segmented-gauge/SegmentedGaugeContext.tsx","../../src/segmented-gauge/SegmentedGaugeLabel.tsx","../../src/segmented-gauge/SegmentedGaugeSegment.tsx","../../src/segmented-gauge/SegmentedGaugeTrack.tsx"],"sourcesContent":["import { SegmentedGauge as Root } from './SegmentedGauge'\nimport { SegmentedGaugeLabel } from './SegmentedGaugeLabel'\nimport { SegmentedGaugeSegment } from './SegmentedGaugeSegment'\nimport { SegmentedGaugeTrack } from './SegmentedGaugeTrack'\n\nexport const SegmentedGauge: typeof Root & {\n Track: typeof SegmentedGaugeTrack\n Segment: typeof SegmentedGaugeSegment\n Label: typeof SegmentedGaugeLabel\n} = Object.assign(Root, {\n Track: SegmentedGaugeTrack,\n Segment: SegmentedGaugeSegment,\n Label: SegmentedGaugeLabel,\n})\n\nSegmentedGauge.displayName = 'SegmentedGauge'\nSegmentedGaugeTrack.displayName = 'SegmentedGauge.Track'\nSegmentedGaugeSegment.displayName = 'SegmentedGauge.Segment'\nSegmentedGaugeLabel.displayName = 'SegmentedGauge.Label'\n\nexport { type SegmentedGaugeProps } from './SegmentedGauge'\nexport { type SegmentedGaugeTrackProps } from './SegmentedGaugeTrack'\nexport { type SegmentedGaugeSegmentProps } from './SegmentedGaugeSegment'\nexport { type SegmentedGaugeLabelProps } from './SegmentedGaugeLabel'\n","import { cx } from 'class-variance-authority'\nimport { Ref, useId, useMemo } from 'react'\n\nimport { SegmentedGaugeContext } from './SegmentedGaugeContext'\nimport { SegmentedGaugeLabel } from './SegmentedGaugeLabel'\nimport { SegmentedGaugeSegment } from './SegmentedGaugeSegment'\nimport { SegmentedGaugeTrack } from './SegmentedGaugeTrack'\n\nconst calculateCurrentIndex = (\n value: number | undefined,\n min: number,\n max: number,\n segments: number\n) => {\n // If value is undefined or null, no segment is active\n if (value == null) {\n return -1\n }\n const normalizedValue = Math.max(min, Math.min(max, value))\n const range = max - min\n const segmentSize = range / (segments - 1)\n const rawIndex = (normalizedValue - min) / segmentSize\n\n // Clamp the index to valid range\n return Math.max(0, Math.min(segments - 1, Math.round(rawIndex)))\n}\n\nexport interface SegmentedGaugeProps {\n /**\n * The current value of the gauge\n */\n value?: number\n /**\n * Minimum value of the gauge (aria-valuemin)\n */\n min: number\n /**\n * Maximum value of the gauge (aria-valuemax)\n */\n max: number\n /**\n * Description text for the gauge (aria-describedby)\n */\n description?: string\n /**\n * Size of the gauge\n */\n size?: 'sm' | 'md'\n /**\n * Intent of the gauge - predefined color intent\n */\n intent?:\n | 'main'\n | 'support'\n | 'basic'\n | 'accent'\n | 'success'\n | 'alert'\n | 'danger'\n | 'info'\n | 'neutral'\n /**\n * Custom color for the gauge (hex, CSS variable, etc.)\n */\n customColor?: string\n /**\n * ID of the gauge element\n */\n id?: string\n /**\n * Accessible label for the gauge (required if no id is provided)\n */\n 'aria-label'?: string\n /**\n * Additional CSS classes\n */\n className?: string\n /**\n * Ref to the root element\n */\n ref?: Ref<HTMLDivElement>\n /**\n * Children render prop for custom rendering\n */\n children?: (props: {\n segments: {\n isActive: boolean\n isCurrent: boolean\n }[]\n currentIndex: number\n }) => React.ReactNode\n}\n\nexport const SegmentedGauge = ({\n value,\n min,\n max,\n description,\n size = 'md',\n intent = 'neutral',\n customColor,\n id,\n 'aria-label': ariaLabel,\n className,\n ref,\n children,\n ...props\n}: SegmentedGaugeProps) => {\n // Calculate segments from min and max\n const segments = max - min + 1\n const currentIndex = useMemo(\n () => calculateCurrentIndex(value, min, max, segments),\n [value, min, max, segments]\n )\n\n // Generate unique IDs\n const internalLabelId = useId()\n const generatedId = useId()\n // Use provided id or generated one for the gauge element\n const gaugeId = id || generatedId\n\n const segmentsData = useMemo(() => {\n return Array.from({ length: segments }, (_, index) => ({\n isActive: currentIndex !== -1 && index <= currentIndex,\n isCurrent: currentIndex !== -1 && index === currentIndex,\n }))\n }, [segments, currentIndex])\n\n const contextValue = useMemo(\n () => ({\n value,\n min,\n max,\n segments,\n currentIndex,\n size,\n intent,\n customColor,\n labelId: internalLabelId,\n gaugeId,\n }),\n [value, min, max, segments, currentIndex, size, intent, customColor, internalLabelId, gaugeId]\n )\n\n // If children is provided, use render prop pattern\n if (children) {\n return (\n <SegmentedGaugeContext.Provider value={contextValue}>\n {children({\n segments: segmentsData,\n currentIndex,\n })}\n </SegmentedGaugeContext.Provider>\n )\n }\n\n /**\n * A `meter` role MUST have a value. If the value is not available, the component uses a `status` role instead.\n */\n const roleProps =\n value != null\n ? {\n role: 'meter',\n 'aria-valuenow': value,\n 'aria-valuemin': min,\n 'aria-valuemax': max,\n }\n : {\n role: 'status',\n }\n\n // Default rendering\n return (\n <SegmentedGaugeContext.Provider value={contextValue}>\n <div\n id={gaugeId}\n data-spark-component=\"segmented-gauge\"\n ref={ref}\n className={cx('gap-md flex items-center', className)}\n {...roleProps}\n aria-labelledby={id ? `${gaugeId}-label` : undefined}\n aria-label={!id ? ariaLabel : undefined}\n aria-describedby={internalLabelId}\n {...props}\n >\n <SegmentedGaugeTrack>\n {segmentsData.map((_, index) => (\n <SegmentedGaugeSegment key={index} index={index} />\n ))}\n </SegmentedGaugeTrack>\n\n {description && (\n <SegmentedGaugeLabel id={internalLabelId}>{description}</SegmentedGaugeLabel>\n )}\n </div>\n </SegmentedGaugeContext.Provider>\n )\n}\n\nSegmentedGauge.displayName = 'SegmentedGauge'\n","import { createContext, useContext } from 'react'\n\nexport interface SegmentedGaugeContextValue {\n value?: number\n min: number\n max: number\n segments: number\n currentIndex: number\n size: 'sm' | 'md'\n intent:\n | 'main'\n | 'support'\n | 'basic'\n | 'accent'\n | 'success'\n | 'alert'\n | 'danger'\n | 'info'\n | 'neutral'\n customColor?: string\n labelId: string\n gaugeId: string\n}\n\nexport const SegmentedGaugeContext = createContext<SegmentedGaugeContextValue | null>(null)\n\nexport const useSegmentedGaugeContext = () => {\n const context = useContext(SegmentedGaugeContext)\n\n if (!context) {\n throw new Error('useSegmentedGaugeContext must be used within a SegmentedGauge provider')\n }\n\n return context\n}\n","import { cx } from 'class-variance-authority'\nimport { ComponentProps, Ref } from 'react'\n\nimport { useSegmentedGaugeContext } from './SegmentedGaugeContext'\n\nexport interface SegmentedGaugeLabelProps extends ComponentProps<'span'> {\n ref?: Ref<HTMLSpanElement>\n id?: string\n}\n\nexport const SegmentedGaugeLabel = ({\n className,\n children,\n ref,\n id,\n ...props\n}: SegmentedGaugeLabelProps) => {\n const { labelId } = useSegmentedGaugeContext()\n\n return (\n <span\n data-spark-component=\"segmented-gauge-label\"\n data-testid=\"segmented-gauge-label\"\n ref={ref}\n id={id || labelId}\n className={cx('default:text-on-surface default:text-body-2', className)}\n {...props}\n >\n {children}\n </span>\n )\n}\n\nSegmentedGaugeLabel.displayName = 'SegmentedGauge.Label'\n","import { cx } from 'class-variance-authority'\nimport { ComponentProps, Ref, useMemo } from 'react'\n\nimport { useSegmentedGaugeContext } from './SegmentedGaugeContext'\n\nexport interface SegmentedGaugeSegmentProps extends ComponentProps<'div'> {\n /**\n * Index of this segment (0-based)\n */\n index?: number\n ref?: Ref<HTMLDivElement>\n}\n\nexport const SegmentedGaugeSegment = ({\n index = 0,\n className,\n children,\n ref,\n ...props\n}: SegmentedGaugeSegmentProps) => {\n const { size, intent, customColor, currentIndex } = useSegmentedGaugeContext()\n\n // Calculate isActive and isCurrent from context and index\n const isActive = currentIndex !== -1 && index <= currentIndex\n const isCurrent = currentIndex !== -1 && index === currentIndex\n\n const gaugeColor = useMemo(() => {\n // If customColor is provided, use it\n if (customColor) {\n return customColor\n }\n\n // Handle predefined intents\n switch (intent) {\n case 'main':\n return 'var(--color-main)'\n case 'support':\n return 'var(--color-support)'\n case 'basic':\n return 'var(--color-basic)'\n case 'accent':\n return 'var(--color-accent)'\n case 'success':\n return 'var(--color-success)'\n case 'alert':\n return 'var(--color-alert)'\n case 'danger':\n return 'var(--color-error)'\n case 'info':\n return 'var(--color-info)'\n case 'neutral':\n return 'var(--color-neutral)'\n default:\n return 'var(--color-neutral)'\n }\n }, [intent, customColor])\n\n const segmentClasses = cx(\n 'border-outline relative rounded-full',\n {\n 'h-sz-8 w-sz-24': size === 'sm',\n 'h-sz-12 w-sz-36': size === 'md',\n 'default:bg-[var(--gauge-color)]': isActive,\n 'border-sm bg-surface': !isActive,\n },\n className\n )\n\n const indicatorClasses = cx(\n 'absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2',\n 'default:bg-surface default:rounded-full',\n 'border-[var(--gauge-color)]',\n {\n 'size-sz-12 border-md': size === 'sm',\n 'size-sz-20 border-lg': size === 'md',\n }\n )\n\n return (\n <div\n data-spark-component=\"segmented-gauge-segment\"\n data-testid=\"segmented-gauge-segment\"\n data-active={isActive}\n data-current={isCurrent}\n ref={ref}\n style={\n {\n '--gauge-color': gaugeColor,\n } as React.CSSProperties\n }\n className={segmentClasses}\n {...props}\n >\n {children}\n {isCurrent && <div className={indicatorClasses} aria-hidden=\"true\" />}\n </div>\n )\n}\n\nSegmentedGaugeSegment.displayName = 'SegmentedGauge.Segment'\n","import { cx } from 'class-variance-authority'\nimport { ComponentProps, Ref } from 'react'\n\nexport interface SegmentedGaugeTrackProps extends ComponentProps<'div'> {\n ref?: Ref<HTMLDivElement>\n}\n\nexport const SegmentedGaugeTrack = ({\n className,\n children,\n ref,\n ...props\n}: SegmentedGaugeTrackProps) => {\n return (\n <div\n data-spark-component=\"segmented-gauge-track\"\n ref={ref}\n className={cx('gap-sm relative flex rounded-full', className)}\n {...props}\n >\n {children}\n </div>\n )\n}\n\nSegmentedGaugeTrack.displayName = 'SegmentedGauge.Track'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAAA;AAAA;AAAA;;;ACAA,IAAAC,mCAAmB;AACnB,IAAAC,gBAAoC;;;ACDpC,mBAA0C;AAwBnC,IAAM,4BAAwB,4BAAiD,IAAI;AAEnF,IAAM,2BAA2B,MAAM;AAC5C,QAAM,cAAU,yBAAW,qBAAqB;AAEhD,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,wEAAwE;AAAA,EAC1F;AAEA,SAAO;AACT;;;AClCA,sCAAmB;AAoBf;AAVG,IAAM,s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IAAC;AAAA;AAAA,MACC,IAAI;AAAA,MACJ,wBAAqB;AAAA,MACrB;AAAA,MACA,eAAW,qCAAG,4BAA4B,SAAS;AAAA,MAClD,GAAG;AAAA,MACJ,mBAAiB,KAAK,GAAG,OAAO,WAAW;AAAA,MAC3C,cAAY,CAAC,KAAK,YAAY;AAAA,MAC9B,oBAAkB;AAAA,MACjB,GAAG;AAAA,MAEJ;AAAA,qDAAC,uBACE,uBAAa,IAAI,CAAC,GAAG,UACpB,6CAAC,yBAAkC,SAAP,KAAqB,CAClD,GACH;AAAA,QAEC,eACC,6CAAC,uBAAoB,IAAI,iBAAkB,uBAAY;AAAA;AAAA;AAAA,EAE3D,GACF;AAEJ;AAEA,eAAe,cAAc;;;ADlMtB,IAAMC,kBAIT,OAAO,OAAO,gBAAM;AAAA,EACtB,OAAO;AAAA,EACP,SAAS;AAAA,EACT,OAAO;AACT,CAAC;AAEDA,gBAAe,cAAc;AAC7B,oBAAoB,cAAc;AAClC,sBAAsB,cAAc;AACpC,oBAAoB,cAAc;","names":["SegmentedGauge","import_class_variance_authority","import_react","import_class_variance_authority","import_react","import_jsx_runtime","import_class_variance_authority","import_jsx_runtime","import_jsx_runtime","SegmentedGauge"]}
1
+ {"version":3,"sources":["../../src/segmented-gauge/index.ts","../../src/segmented-gauge/SegmentedGauge.tsx","../../src/segmented-gauge/SegmentedGaugeContext.tsx","../../src/segmented-gauge/SegmentedGaugeLabel.tsx","../../src/segmented-gauge/SegmentedGaugeSegment.tsx","../../src/segmented-gauge/SegmentedGaugeTrack.tsx"],"sourcesContent":["import { SegmentedGauge as Root } from './SegmentedGauge'\nimport { SegmentedGaugeLabel } from './SegmentedGaugeLabel'\nimport { SegmentedGaugeSegment } from './SegmentedGaugeSegment'\nimport { SegmentedGaugeTrack } from './SegmentedGaugeTrack'\n\nexport const SegmentedGauge: typeof Root & {\n Track: typeof SegmentedGaugeTrack\n Segment: typeof SegmentedGaugeSegment\n Label: typeof SegmentedGaugeLabel\n} = Object.assign(Root, {\n Track: SegmentedGaugeTrack,\n Segment: SegmentedGaugeSegment,\n Label: SegmentedGaugeLabel,\n})\n\nSegmentedGauge.displayName = 'SegmentedGauge'\nSegmentedGaugeTrack.displayName = 'SegmentedGauge.Track'\nSegmentedGaugeSegment.displayName = 'SegmentedGauge.Segment'\nSegmentedGaugeLabel.displayName = 'SegmentedGauge.Label'\n\nexport { type SegmentedGaugeProps } from './SegmentedGauge'\nexport { type SegmentedGaugeTrackProps } from './SegmentedGaugeTrack'\nexport { type SegmentedGaugeSegmentProps } from './SegmentedGaugeSegment'\nexport { type SegmentedGaugeLabelProps } from './SegmentedGaugeLabel'\n","import { cx } from 'class-variance-authority'\nimport { Ref, useId, useMemo } from 'react'\n\nimport { SegmentedGaugeContext } from './SegmentedGaugeContext'\nimport { SegmentedGaugeLabel } from './SegmentedGaugeLabel'\nimport { SegmentedGaugeSegment } from './SegmentedGaugeSegment'\nimport { SegmentedGaugeTrack } from './SegmentedGaugeTrack'\n\nconst calculateCurrentIndex = (\n value: number | undefined,\n min: number,\n max: number,\n segments: number\n) => {\n // If value is undefined or null, no segment is active\n if (value == null) {\n return -1\n }\n const normalizedValue = Math.max(min, Math.min(max, value))\n const range = max - min\n const segmentSize = range / (segments - 1)\n const rawIndex = (normalizedValue - min) / segmentSize\n\n // Clamp the index to valid range\n return Math.max(0, Math.min(segments - 1, Math.round(rawIndex)))\n}\n\nexport interface SegmentedGaugeProps {\n /**\n * The current value of the gauge\n */\n value?: number\n /**\n * Minimum value of the gauge (aria-valuemin)\n */\n min: number\n /**\n * Maximum value of the gauge (aria-valuemax)\n */\n max: number\n /**\n * Description text for the gauge (aria-describedby)\n */\n description?: string\n /**\n * Size of the gauge\n */\n size?: 'sm' | 'md'\n /**\n * Intent of the gauge - predefined color intent\n */\n intent?:\n | 'main'\n | 'support'\n | 'basic'\n | 'accent'\n | 'success'\n | 'alert'\n | 'danger'\n | 'info'\n | 'neutral'\n /**\n * Custom color for the gauge (hex, CSS variable, etc.)\n */\n customColor?: string\n /**\n * ID of the gauge element\n */\n id?: string\n /**\n * Accessible label for the gauge (required if no id is provided)\n */\n 'aria-label'?: string\n /**\n * Textual representation of the current value (aria-valuetext)\n * By default, percentage is used (e.g. \"33%\")\n */\n 'aria-valuetext'?: string\n /**\n * Additional CSS classes\n */\n className?: string\n /**\n * Ref to the root element\n */\n ref?: Ref<HTMLDivElement>\n /**\n * Children render prop for custom rendering\n */\n children?: (props: {\n segments: {\n isActive: boolean\n isCurrent: boolean\n }[]\n currentIndex: number\n }) => React.ReactNode\n}\n\nexport const SegmentedGauge = ({\n value,\n min,\n max,\n description,\n size = 'md',\n intent = 'neutral',\n customColor,\n id,\n 'aria-label': ariaLabel,\n className,\n ref,\n children,\n ...props\n}: SegmentedGaugeProps) => {\n // Calculate segments from min and max\n const segments = max - min + 1\n const currentIndex = useMemo(\n () => calculateCurrentIndex(value, min, max, segments),\n [value, min, max, segments]\n )\n\n // Generate unique IDs\n const internalLabelId = useId()\n const generatedId = useId()\n // Use provided id or generated one for the gauge element\n const gaugeId = id || generatedId\n\n const segmentsData = useMemo(() => {\n return Array.from({ length: segments }, (_, index) => ({\n isActive: currentIndex !== -1 && index <= currentIndex,\n isCurrent: currentIndex !== -1 && index === currentIndex,\n }))\n }, [segments, currentIndex])\n\n const contextValue = useMemo(\n () => ({\n value,\n min,\n max,\n segments,\n currentIndex,\n size,\n intent,\n customColor,\n labelId: internalLabelId,\n gaugeId,\n }),\n [value, min, max, segments, currentIndex, size, intent, customColor, internalLabelId, gaugeId]\n )\n\n /**\n * A `meter` role MUST have a value. If the value is not available, the component uses a `status` role instead.\n */\n const roleProps =\n value != null\n ? {\n role: 'meter',\n 'aria-valuenow': value,\n 'aria-valuemin': min,\n 'aria-valuemax': max,\n }\n : {\n role: 'status',\n }\n\n return (\n <SegmentedGaugeContext.Provider value={contextValue}>\n <div\n id={gaugeId}\n data-spark-component=\"segmented-gauge\"\n ref={ref}\n className={cx('gap-md flex flex-wrap items-center', className)}\n {...roleProps}\n aria-labelledby={id ? `${gaugeId}-label` : undefined}\n aria-label={!id ? ariaLabel : undefined}\n aria-describedby={internalLabelId}\n {...props}\n >\n {children ? (\n children({\n segments: segmentsData,\n currentIndex,\n })\n ) : (\n <>\n <SegmentedGaugeTrack>\n {segmentsData.map((_, index) => (\n <SegmentedGaugeSegment key={index} index={index} />\n ))}\n </SegmentedGaugeTrack>\n\n {description && (\n <SegmentedGaugeLabel id={internalLabelId}>{description}</SegmentedGaugeLabel>\n )}\n </>\n )}\n </div>\n </SegmentedGaugeContext.Provider>\n )\n}\n\nSegmentedGauge.displayName = 'SegmentedGauge'\n","import { createContext, useContext } from 'react'\n\nexport interface SegmentedGaugeContextValue {\n value?: number\n min: number\n max: number\n segments: number\n currentIndex: number\n size: 'sm' | 'md'\n intent:\n | 'main'\n | 'support'\n | 'basic'\n | 'accent'\n | 'success'\n | 'alert'\n | 'danger'\n | 'info'\n | 'neutral'\n customColor?: string\n labelId: string\n gaugeId: string\n}\n\nexport const SegmentedGaugeContext = createContext<SegmentedGaugeContextValue | null>(null)\n\nexport const useSegmentedGaugeContext = () => {\n const context = useContext(SegmentedGaugeContext)\n\n if (!context) {\n throw new Error('useSegmentedGaugeContext must be used within a SegmentedGauge provider')\n }\n\n return context\n}\n","import { cx } from 'class-variance-authority'\nimport { ComponentProps, Ref } from 'react'\n\nimport { useSegmentedGaugeContext } from './SegmentedGaugeContext'\n\nexport interface SegmentedGaugeLabelProps extends ComponentProps<'span'> {\n ref?: Ref<HTMLSpanElement>\n id?: string\n}\n\nexport const SegmentedGaugeLabel = ({\n className,\n children,\n ref,\n id,\n ...props\n}: SegmentedGaugeLabelProps) => {\n const { labelId } = useSegmentedGaugeContext()\n\n return (\n <span\n data-spark-component=\"segmented-gauge-label\"\n data-testid=\"segmented-gauge-label\"\n ref={ref}\n id={id || labelId}\n className={cx('default:text-on-surface default:text-body-2', className)}\n {...props}\n >\n {children}\n </span>\n )\n}\n\nSegmentedGaugeLabel.displayName = 'SegmentedGauge.Label'\n","import { cx } from 'class-variance-authority'\nimport { ComponentProps, Ref, useMemo } from 'react'\n\nimport { useSegmentedGaugeContext } from './SegmentedGaugeContext'\n\nexport interface SegmentedGaugeSegmentProps extends ComponentProps<'div'> {\n /**\n * Index of this segment (0-based)\n */\n index?: number\n ref?: Ref<HTMLDivElement>\n}\n\nexport const SegmentedGaugeSegment = ({\n index = 0,\n className,\n children,\n ref,\n ...props\n}: SegmentedGaugeSegmentProps) => {\n const { size, intent, customColor, currentIndex } = useSegmentedGaugeContext()\n\n // Calculate isActive and isCurrent from context and index\n const isActive = currentIndex !== -1 && index <= currentIndex\n const isCurrent = currentIndex !== -1 && index === currentIndex\n\n const gaugeColor = useMemo(() => {\n // If customColor is provided, use it\n if (customColor) {\n return customColor\n }\n\n // Handle predefined intents\n switch (intent) {\n case 'main':\n return 'var(--color-main)'\n case 'support':\n return 'var(--color-support)'\n case 'basic':\n return 'var(--color-basic)'\n case 'accent':\n return 'var(--color-accent)'\n case 'success':\n return 'var(--color-success)'\n case 'alert':\n return 'var(--color-alert)'\n case 'danger':\n return 'var(--color-error)'\n case 'info':\n return 'var(--color-info)'\n case 'neutral':\n return 'var(--color-neutral)'\n default:\n return 'var(--color-neutral)'\n }\n }, [intent, customColor])\n\n const segmentClasses = cx(\n 'border-outline relative rounded-full',\n {\n 'h-sz-8 w-sz-24': size === 'sm',\n 'h-sz-12 w-sz-36': size === 'md',\n 'default:bg-[var(--gauge-color)]': isActive,\n 'border-sm bg-surface': !isActive,\n },\n className\n )\n\n const indicatorClasses = cx(\n 'absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2',\n 'default:bg-surface default:rounded-full',\n 'border-[var(--gauge-color)]',\n {\n 'size-sz-12 border-md': size === 'sm',\n 'size-sz-20 border-lg': size === 'md',\n }\n )\n\n return (\n <div\n data-spark-component=\"segmented-gauge-segment\"\n data-testid=\"segmented-gauge-segment\"\n data-active={isActive}\n data-current={isCurrent}\n ref={ref}\n style={\n {\n '--gauge-color': gaugeColor,\n } as React.CSSProperties\n }\n className={segmentClasses}\n {...props}\n >\n {children}\n {isCurrent && <div className={indicatorClasses} aria-hidden=\"true\" />}\n </div>\n )\n}\n\nSegmentedGaugeSegment.displayName = 'SegmentedGauge.Segment'\n","import { cx } from 'class-variance-authority'\nimport { ComponentProps, Ref } from 'react'\n\nexport interface SegmentedGaugeTrackProps extends ComponentProps<'div'> {\n ref?: Ref<HTMLDivElement>\n}\n\nexport const SegmentedGaugeTrack = ({\n className,\n children,\n ref,\n ...props\n}: SegmentedGaugeTrackProps) => {\n return (\n <div\n data-spark-component=\"segmented-gauge-track\"\n ref={ref}\n className={cx('gap-sm relative flex rounded-full', className)}\n {...props}\n >\n {children}\n </div>\n )\n}\n\nSegmentedGaugeTrack.displayName = 'SegmentedGauge.Track'\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,wBAAAA;AAAA;AAAA;;;ACAA,IAAAC,mCAAmB;AACnB,IAAAC,gBAAoC;;;ACDpC,mBAA0C;AAwBnC,IAAM,4BAAwB,4BAAiD,IAAI;AAEnF,IAAM,2BAA2B,MAAM;AAC5C,QAAM,cAAU,yBAAW,qBAAqB;AAEhD,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,wEAAwE;AAAA,EAC1F;AAEA,SAAO;AACT;;;AClCA,sCAAmB;AAoBf;AAVG,IAAM,sBAAsB,CAAC;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAgC;AAC9B,QAAM,EAAE,QAAQ,IAAI,yBAAyB;AAE7C,SACE;AAAA,IAAC;AAAA;AAAA,MACC,wBAAqB;AAAA,MACrB,eAAY;AAAA,MACZ;AAAA,MACA,IAAI,MAAM;AAAA,MACV,eAAW,oCAAG,+CAA+C,SAAS;AAAA,MACrE,GAAG;AAAA,MAEH;AAAA;AAAA,EACH;AAEJ;AAEA,oBAAoB,cAAc;;;ACjClC,IAAAC,mC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AEJ;AAEA,eAAe,cAAc;;;ADnMtB,IAAMC,kBAIT,OAAO,OAAO,gBAAM;AAAA,EACtB,OAAO;AAAA,EACP,SAAS;AAAA,EACT,OAAO;AACT,CAAC;AAEDA,gBAAe,cAAc;AAC7B,oBAAoB,cAAc;AAClC,sBAAsB,cAAc;AACpC,oBAAoB,cAAc;","names":["SegmentedGauge","import_class_variance_authority","import_react","import_class_variance_authority","import_react","import_jsx_runtime","import_class_variance_authority","import_jsx_runtime","import_jsx_runtime","SegmentedGauge"]}
@@ -144,7 +144,7 @@ var SegmentedGaugeTrack = ({
144
144
  SegmentedGaugeTrack.displayName = "SegmentedGauge.Track";
145
145
 
146
146
  // src/segmented-gauge/SegmentedGauge.tsx
147
- import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
147
+ import { Fragment, jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
148
148
  var calculateCurrentIndex = (value, min, max, segments) => {
149
149
  if (value == null) {
150
150
  return -1;
@@ -199,12 +199,6 @@ var SegmentedGauge = ({
199
199
  }),
200
200
  [value, min, max, segments, currentIndex, size, intent, customColor, internalLabelId, gaugeId]
201
201
  );
202
- if (children) {
203
- return /* @__PURE__ */ jsx4(SegmentedGaugeContext.Provider, { value: contextValue, children: children({
204
- segments: segmentsData,
205
- currentIndex
206
- }) });
207
- }
208
202
  const roleProps = value != null ? {
209
203
  role: "meter",
210
204
  "aria-valuenow": value,
@@ -213,22 +207,25 @@ var SegmentedGauge = ({
213
207
  } : {
214
208
  role: "status"
215
209
  };
216
- return /* @__PURE__ */ jsx4(SegmentedGaugeContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxs2(
210
+ return /* @__PURE__ */ jsx4(SegmentedGaugeContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx4(
217
211
  "div",
218
212
  {
219
213
  id: gaugeId,
220
214
  "data-spark-component": "segmented-gauge",
221
215
  ref,
222
- className: cx4("gap-md flex items-center", className),
216
+ className: cx4("gap-md flex flex-wrap items-center", className),
223
217
  ...roleProps,
224
218
  "aria-labelledby": id ? `${gaugeId}-label` : void 0,
225
219
  "aria-label": !id ? ariaLabel : void 0,
226
220
  "aria-describedby": internalLabelId,
227
221
  ...props,
228
- children: [
222
+ children: children ? children({
223
+ segments: segmentsData,
224
+ currentIndex
225
+ }) : /* @__PURE__ */ jsxs2(Fragment, { children: [
229
226
  /* @__PURE__ */ jsx4(SegmentedGaugeTrack, { children: segmentsData.map((_, index) => /* @__PURE__ */ jsx4(SegmentedGaugeSegment, { index }, index)) }),
230
227
  description && /* @__PURE__ */ jsx4(SegmentedGaugeLabel, { id: internalLabelId, children: description })
231
- ]
228
+ ] })
232
229
  }
233
230
  ) });
234
231
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/segmented-gauge/SegmentedGauge.tsx","../../src/segmented-gauge/SegmentedGaugeContext.tsx","../../src/segmented-gauge/SegmentedGaugeLabel.tsx","../../src/segmented-gauge/SegmentedGaugeSegment.tsx","../../src/segmented-gauge/SegmentedGaugeTrack.tsx","../../src/segmented-gauge/index.ts"],"sourcesContent":["import { cx } from 'class-variance-authority'\nimport { Ref, useId, useMemo } from 'react'\n\nimport { SegmentedGaugeContext } from './SegmentedGaugeContext'\nimport { SegmentedGaugeLabel } from './SegmentedGaugeLabel'\nimport { SegmentedGaugeSegment } from './SegmentedGaugeSegment'\nimport { SegmentedGaugeTrack } from './SegmentedGaugeTrack'\n\nconst calculateCurrentIndex = (\n value: number | undefined,\n min: number,\n max: number,\n segments: number\n) => {\n // If value is undefined or null, no segment is active\n if (value == null) {\n return -1\n }\n const normalizedValue = Math.max(min, Math.min(max, value))\n const range = max - min\n const segmentSize = range / (segments - 1)\n const rawIndex = (normalizedValue - min) / segmentSize\n\n // Clamp the index to valid range\n return Math.max(0, Math.min(segments - 1, Math.round(rawIndex)))\n}\n\nexport interface SegmentedGaugeProps {\n /**\n * The current value of the gauge\n */\n value?: number\n /**\n * Minimum value of the gauge (aria-valuemin)\n */\n min: number\n /**\n * Maximum value of the gauge (aria-valuemax)\n */\n max: number\n /**\n * Description text for the gauge (aria-describedby)\n */\n description?: string\n /**\n * Size of the gauge\n */\n size?: 'sm' | 'md'\n /**\n * Intent of the gauge - predefined color intent\n */\n intent?:\n | 'main'\n | 'support'\n | 'basic'\n | 'accent'\n | 'success'\n | 'alert'\n | 'danger'\n | 'info'\n | 'neutral'\n /**\n * Custom color for the gauge (hex, CSS variable, etc.)\n */\n customColor?: string\n /**\n * ID of the gauge element\n */\n id?: string\n /**\n * Accessible label for the gauge (required if no id is provided)\n */\n 'aria-label'?: string\n /**\n * Additional CSS classes\n */\n className?: string\n /**\n * Ref to the root element\n */\n ref?: Ref<HTMLDivElement>\n /**\n * Children render prop for custom rendering\n */\n children?: (props: {\n segments: {\n isActive: boolean\n isCurrent: boolean\n }[]\n currentIndex: number\n }) => React.ReactNode\n}\n\nexport const SegmentedGauge = ({\n value,\n min,\n max,\n description,\n size = 'md',\n intent = 'neutral',\n customColor,\n id,\n 'aria-label': ariaLabel,\n className,\n ref,\n children,\n ...props\n}: SegmentedGaugeProps) => {\n // Calculate segments from min and max\n const segments = max - min + 1\n const currentIndex = useMemo(\n () => calculateCurrentIndex(value, min, max, segments),\n [value, min, max, segments]\n )\n\n // Generate unique IDs\n const internalLabelId = useId()\n const generatedId = useId()\n // Use provided id or generated one for the gauge element\n const gaugeId = id || generatedId\n\n const segmentsData = useMemo(() => {\n return Array.from({ length: segments }, (_, index) => ({\n isActive: currentIndex !== -1 && index <= currentIndex,\n isCurrent: currentIndex !== -1 && index === currentIndex,\n }))\n }, [segments, currentIndex])\n\n const contextValue = useMemo(\n () => ({\n value,\n min,\n max,\n segments,\n currentIndex,\n size,\n intent,\n customColor,\n labelId: internalLabelId,\n gaugeId,\n }),\n [value, min, max, segments, currentIndex, size, intent, customColor, internalLabelId, gaugeId]\n )\n\n // If children is provided, use render prop pattern\n if (children) {\n return (\n <SegmentedGaugeContext.Provider value={contextValue}>\n {children({\n segments: segmentsData,\n currentIndex,\n })}\n </SegmentedGaugeContext.Provider>\n )\n }\n\n /**\n * A `meter` role MUST have a value. If the value is not available, the component uses a `status` role instead.\n */\n const roleProps =\n value != null\n ? {\n role: 'meter',\n 'aria-valuenow': value,\n 'aria-valuemin': min,\n 'aria-valuemax': max,\n }\n : {\n role: 'status',\n }\n\n // Default rendering\n return (\n <SegmentedGaugeContext.Provider value={contextValue}>\n <div\n id={gaugeId}\n data-spark-component=\"segmented-gauge\"\n ref={ref}\n className={cx('gap-md flex items-center', className)}\n {...roleProps}\n aria-labelledby={id ? `${gaugeId}-label` : undefined}\n aria-label={!id ? ariaLabel : undefined}\n aria-describedby={internalLabelId}\n {...props}\n >\n <SegmentedGaugeTrack>\n {segmentsData.map((_, index) => (\n <SegmentedGaugeSegment key={index} index={index} />\n ))}\n </SegmentedGaugeTrack>\n\n {description && (\n <SegmentedGaugeLabel id={internalLabelId}>{description}</SegmentedGaugeLabel>\n )}\n </div>\n </SegmentedGaugeContext.Provider>\n )\n}\n\nSegmentedGauge.displayName = 'SegmentedGauge'\n","import { createContext, useContext } from 'react'\n\nexport interface SegmentedGaugeContextValue {\n value?: number\n min: number\n max: number\n segments: number\n currentIndex: number\n size: 'sm' | 'md'\n intent:\n | 'main'\n | 'support'\n | 'basic'\n | 'accent'\n | 'success'\n | 'alert'\n | 'danger'\n | 'info'\n | 'neutral'\n customColor?: string\n labelId: string\n gaugeId: string\n}\n\nexport const SegmentedGaugeContext = createContext<SegmentedGaugeContextValue | null>(null)\n\nexport const useSegmentedGaugeContext = () => {\n const context = useContext(SegmentedGaugeContext)\n\n if (!context) {\n throw new Error('useSegmentedGaugeContext must be used within a SegmentedGauge provider')\n }\n\n return context\n}\n","import { cx } from 'class-variance-authority'\nimport { ComponentProps, Ref } from 'react'\n\nimport { useSegmentedGaugeContext } from './SegmentedGaugeContext'\n\nexport interface SegmentedGaugeLabelProps extends ComponentProps<'span'> {\n ref?: Ref<HTMLSpanElement>\n id?: string\n}\n\nexport const SegmentedGaugeLabel = ({\n className,\n children,\n ref,\n id,\n ...props\n}: SegmentedGaugeLabelProps) => {\n const { labelId } = useSegmentedGaugeContext()\n\n return (\n <span\n data-spark-component=\"segmented-gauge-label\"\n data-testid=\"segmented-gauge-label\"\n ref={ref}\n id={id || labelId}\n className={cx('default:text-on-surface default:text-body-2', className)}\n {...props}\n >\n {children}\n </span>\n )\n}\n\nSegmentedGaugeLabel.displayName = 'SegmentedGauge.Label'\n","import { cx } from 'class-variance-authority'\nimport { ComponentProps, Ref, useMemo } from 'react'\n\nimport { useSegmentedGaugeContext } from './SegmentedGaugeContext'\n\nexport interface SegmentedGaugeSegmentProps extends ComponentProps<'div'> {\n /**\n * Index of this segment (0-based)\n */\n index?: number\n ref?: Ref<HTMLDivElement>\n}\n\nexport const SegmentedGaugeSegment = ({\n index = 0,\n className,\n children,\n ref,\n ...props\n}: SegmentedGaugeSegmentProps) => {\n const { size, intent, customColor, currentIndex } = useSegmentedGaugeContext()\n\n // Calculate isActive and isCurrent from context and index\n const isActive = currentIndex !== -1 && index <= currentIndex\n const isCurrent = currentIndex !== -1 && index === currentIndex\n\n const gaugeColor = useMemo(() => {\n // If customColor is provided, use it\n if (customColor) {\n return customColor\n }\n\n // Handle predefined intents\n switch (intent) {\n case 'main':\n return 'var(--color-main)'\n case 'support':\n return 'var(--color-support)'\n case 'basic':\n return 'var(--color-basic)'\n case 'accent':\n return 'var(--color-accent)'\n case 'success':\n return 'var(--color-success)'\n case 'alert':\n return 'var(--color-alert)'\n case 'danger':\n return 'var(--color-error)'\n case 'info':\n return 'var(--color-info)'\n case 'neutral':\n return 'var(--color-neutral)'\n default:\n return 'var(--color-neutral)'\n }\n }, [intent, customColor])\n\n const segmentClasses = cx(\n 'border-outline relative rounded-full',\n {\n 'h-sz-8 w-sz-24': size === 'sm',\n 'h-sz-12 w-sz-36': size === 'md',\n 'default:bg-[var(--gauge-color)]': isActive,\n 'border-sm bg-surface': !isActive,\n },\n className\n )\n\n const indicatorClasses = cx(\n 'absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2',\n 'default:bg-surface default:rounded-full',\n 'border-[var(--gauge-color)]',\n {\n 'size-sz-12 border-md': size === 'sm',\n 'size-sz-20 border-lg': size === 'md',\n }\n )\n\n return (\n <div\n data-spark-component=\"segmented-gauge-segment\"\n data-testid=\"segmented-gauge-segment\"\n data-active={isActive}\n data-current={isCurrent}\n ref={ref}\n style={\n {\n '--gauge-color': gaugeColor,\n } as React.CSSProperties\n }\n className={segmentClasses}\n {...props}\n >\n {children}\n {isCurrent && <div className={indicatorClasses} aria-hidden=\"true\" />}\n </div>\n )\n}\n\nSegmentedGaugeSegment.displayName = 'SegmentedGauge.Segment'\n","import { cx } from 'class-variance-authority'\nimport { ComponentProps, Ref } from 'react'\n\nexport interface SegmentedGaugeTrackProps extends ComponentProps<'div'> {\n ref?: Ref<HTMLDivElement>\n}\n\nexport const SegmentedGaugeTrack = ({\n className,\n children,\n ref,\n ...props\n}: SegmentedGaugeTrackProps) => {\n return (\n <div\n data-spark-component=\"segmented-gauge-track\"\n ref={ref}\n className={cx('gap-sm relative flex rounded-full', className)}\n {...props}\n >\n {children}\n </div>\n )\n}\n\nSegmentedGaugeTrack.displayName = 'SegmentedGauge.Track'\n","import { SegmentedGauge as Root } from './SegmentedGauge'\nimport { SegmentedGaugeLabel } from './SegmentedGaugeLabel'\nimport { SegmentedGaugeSegment } from './SegmentedGaugeSegment'\nimport { SegmentedGaugeTrack } from './SegmentedGaugeTrack'\n\nexport const SegmentedGauge: typeof Root & {\n Track: typeof SegmentedGaugeTrack\n Segment: typeof SegmentedGaugeSegment\n Label: typeof SegmentedGaugeLabel\n} = Object.assign(Root, {\n Track: SegmentedGaugeTrack,\n Segment: SegmentedGaugeSegment,\n Label: SegmentedGaugeLabel,\n})\n\nSegmentedGauge.displayName = 'SegmentedGauge'\nSegmentedGaugeTrack.displayName = 'SegmentedGauge.Track'\nSegmentedGaugeSegment.displayName = 'SegmentedGauge.Segment'\nSegmentedGaugeLabel.displayName = 'SegmentedGauge.Label'\n\nexport { type SegmentedGaugeProps } from './SegmentedGauge'\nexport { type SegmentedGaugeTrackProps } from './SegmentedGaugeTrack'\nexport { type SegmentedGaugeSegmentProps } from './SegmentedGaugeSegment'\nexport { type SegmentedGaugeLabelProps } from './SegmentedGaugeLabel'\n"],"mappings":";AAAA,SAAS,MAAAA,WAAU;AACnB,SAAc,OAAO,WAAAC,gBAAe;;;ACDpC,SAAS,eAAe,kBAAkB;AAwBnC,IAAM,wBAAwB,cAAiD,IAAI;AAEnF,IAAM,2BAA2B,MAAM;AAC5C,QAAM,UAAU,WAAW,qBAAqB;AAEhD,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,wEAAwE;AAAA,EAC1F;AAEA,SAAO;AACT;;;AClCA,SAAS,UAAU;AAoBf;AAVG,IAAM,sBAAsB,CAAC;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAgC;AAC9B,QAAM,EAAE,QAAQ,IAAI,yBAAyB;AAE7C,SACE;AAAA,IAAC;AAAA;AAAA,MACC,wBAAqB;AAAA,MACrB,eAAY;AAAA,MACZ;AAAA,MACA,IAAI,MAAM;AAAA,MACV,WAAW,GAAG,+CAA+C,SAAS;AAAA,MACrE,GAAG;AAAA,MAEH;AAAA;AAAA,EACH;AAEJ;AAEA,oBAAoB,cAAc;;;ACjClC,SAAS,MAAAC,WAAU;AACnB,SAA8B,eAAe;AA8EzC,SAegB,OAAAC,MAfhB;AAlEG,IAAM,wBAAwB,CAAC;AAAA,EACpC,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA;AAAA,EACA,GAAG;AACL,MAAkC;AAChC,QAAM,EAAE,MAAM,QAAQ,aAAa,aAAa,IAAI,yBAAyB;AAG7E,QAAM,WAAW,iBAAiB,MAAM,SAAS;AACjD,QAAM,YAAY,iBAAiB,MAAM,UAAU;AAEnD,QAAM,aAAa,QAAQ,MAAM;AAE/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c;AACpC,oBAAoB,cAAc;","names":["cx","useMemo","cx","jsx","cx","cx","jsx","jsx","jsxs","useMemo","cx","SegmentedGauge"]}
1
+ {"version":3,"sources":["../../src/segmented-gauge/SegmentedGauge.tsx","../../src/segmented-gauge/SegmentedGaugeContext.tsx","../../src/segmented-gauge/SegmentedGaugeLabel.tsx","../../src/segmented-gauge/SegmentedGaugeSegment.tsx","../../src/segmented-gauge/SegmentedGaugeTrack.tsx","../../src/segmented-gauge/index.ts"],"sourcesContent":["import { cx } from 'class-variance-authority'\nimport { Ref, useId, useMemo } from 'react'\n\nimport { SegmentedGaugeContext } from './SegmentedGaugeContext'\nimport { SegmentedGaugeLabel } from './SegmentedGaugeLabel'\nimport { SegmentedGaugeSegment } from './SegmentedGaugeSegment'\nimport { SegmentedGaugeTrack } from './SegmentedGaugeTrack'\n\nconst calculateCurrentIndex = (\n value: number | undefined,\n min: number,\n max: number,\n segments: number\n) => {\n // If value is undefined or null, no segment is active\n if (value == null) {\n return -1\n }\n const normalizedValue = Math.max(min, Math.min(max, value))\n const range = max - min\n const segmentSize = range / (segments - 1)\n const rawIndex = (normalizedValue - min) / segmentSize\n\n // Clamp the index to valid range\n return Math.max(0, Math.min(segments - 1, Math.round(rawIndex)))\n}\n\nexport interface SegmentedGaugeProps {\n /**\n * The current value of the gauge\n */\n value?: number\n /**\n * Minimum value of the gauge (aria-valuemin)\n */\n min: number\n /**\n * Maximum value of the gauge (aria-valuemax)\n */\n max: number\n /**\n * Description text for the gauge (aria-describedby)\n */\n description?: string\n /**\n * Size of the gauge\n */\n size?: 'sm' | 'md'\n /**\n * Intent of the gauge - predefined color intent\n */\n intent?:\n | 'main'\n | 'support'\n | 'basic'\n | 'accent'\n | 'success'\n | 'alert'\n | 'danger'\n | 'info'\n | 'neutral'\n /**\n * Custom color for the gauge (hex, CSS variable, etc.)\n */\n customColor?: string\n /**\n * ID of the gauge element\n */\n id?: string\n /**\n * Accessible label for the gauge (required if no id is provided)\n */\n 'aria-label'?: string\n /**\n * Textual representation of the current value (aria-valuetext)\n * By default, percentage is used (e.g. \"33%\")\n */\n 'aria-valuetext'?: string\n /**\n * Additional CSS classes\n */\n className?: string\n /**\n * Ref to the root element\n */\n ref?: Ref<HTMLDivElement>\n /**\n * Children render prop for custom rendering\n */\n children?: (props: {\n segments: {\n isActive: boolean\n isCurrent: boolean\n }[]\n currentIndex: number\n }) => React.ReactNode\n}\n\nexport const SegmentedGauge = ({\n value,\n min,\n max,\n description,\n size = 'md',\n intent = 'neutral',\n customColor,\n id,\n 'aria-label': ariaLabel,\n className,\n ref,\n children,\n ...props\n}: SegmentedGaugeProps) => {\n // Calculate segments from min and max\n const segments = max - min + 1\n const currentIndex = useMemo(\n () => calculateCurrentIndex(value, min, max, segments),\n [value, min, max, segments]\n )\n\n // Generate unique IDs\n const internalLabelId = useId()\n const generatedId = useId()\n // Use provided id or generated one for the gauge element\n const gaugeId = id || generatedId\n\n const segmentsData = useMemo(() => {\n return Array.from({ length: segments }, (_, index) => ({\n isActive: currentIndex !== -1 && index <= currentIndex,\n isCurrent: currentIndex !== -1 && index === currentIndex,\n }))\n }, [segments, currentIndex])\n\n const contextValue = useMemo(\n () => ({\n value,\n min,\n max,\n segments,\n currentIndex,\n size,\n intent,\n customColor,\n labelId: internalLabelId,\n gaugeId,\n }),\n [value, min, max, segments, currentIndex, size, intent, customColor, internalLabelId, gaugeId]\n )\n\n /**\n * A `meter` role MUST have a value. If the value is not available, the component uses a `status` role instead.\n */\n const roleProps =\n value != null\n ? {\n role: 'meter',\n 'aria-valuenow': value,\n 'aria-valuemin': min,\n 'aria-valuemax': max,\n }\n : {\n role: 'status',\n }\n\n return (\n <SegmentedGaugeContext.Provider value={contextValue}>\n <div\n id={gaugeId}\n data-spark-component=\"segmented-gauge\"\n ref={ref}\n className={cx('gap-md flex flex-wrap items-center', className)}\n {...roleProps}\n aria-labelledby={id ? `${gaugeId}-label` : undefined}\n aria-label={!id ? ariaLabel : undefined}\n aria-describedby={internalLabelId}\n {...props}\n >\n {children ? (\n children({\n segments: segmentsData,\n currentIndex,\n })\n ) : (\n <>\n <SegmentedGaugeTrack>\n {segmentsData.map((_, index) => (\n <SegmentedGaugeSegment key={index} index={index} />\n ))}\n </SegmentedGaugeTrack>\n\n {description && (\n <SegmentedGaugeLabel id={internalLabelId}>{description}</SegmentedGaugeLabel>\n )}\n </>\n )}\n </div>\n </SegmentedGaugeContext.Provider>\n )\n}\n\nSegmentedGauge.displayName = 'SegmentedGauge'\n","import { createContext, useContext } from 'react'\n\nexport interface SegmentedGaugeContextValue {\n value?: number\n min: number\n max: number\n segments: number\n currentIndex: number\n size: 'sm' | 'md'\n intent:\n | 'main'\n | 'support'\n | 'basic'\n | 'accent'\n | 'success'\n | 'alert'\n | 'danger'\n | 'info'\n | 'neutral'\n customColor?: string\n labelId: string\n gaugeId: string\n}\n\nexport const SegmentedGaugeContext = createContext<SegmentedGaugeContextValue | null>(null)\n\nexport const useSegmentedGaugeContext = () => {\n const context = useContext(SegmentedGaugeContext)\n\n if (!context) {\n throw new Error('useSegmentedGaugeContext must be used within a SegmentedGauge provider')\n }\n\n return context\n}\n","import { cx } from 'class-variance-authority'\nimport { ComponentProps, Ref } from 'react'\n\nimport { useSegmentedGaugeContext } from './SegmentedGaugeContext'\n\nexport interface SegmentedGaugeLabelProps extends ComponentProps<'span'> {\n ref?: Ref<HTMLSpanElement>\n id?: string\n}\n\nexport const SegmentedGaugeLabel = ({\n className,\n children,\n ref,\n id,\n ...props\n}: SegmentedGaugeLabelProps) => {\n const { labelId } = useSegmentedGaugeContext()\n\n return (\n <span\n data-spark-component=\"segmented-gauge-label\"\n data-testid=\"segmented-gauge-label\"\n ref={ref}\n id={id || labelId}\n className={cx('default:text-on-surface default:text-body-2', className)}\n {...props}\n >\n {children}\n </span>\n )\n}\n\nSegmentedGaugeLabel.displayName = 'SegmentedGauge.Label'\n","import { cx } from 'class-variance-authority'\nimport { ComponentProps, Ref, useMemo } from 'react'\n\nimport { useSegmentedGaugeContext } from './SegmentedGaugeContext'\n\nexport interface SegmentedGaugeSegmentProps extends ComponentProps<'div'> {\n /**\n * Index of this segment (0-based)\n */\n index?: number\n ref?: Ref<HTMLDivElement>\n}\n\nexport const SegmentedGaugeSegment = ({\n index = 0,\n className,\n children,\n ref,\n ...props\n}: SegmentedGaugeSegmentProps) => {\n const { size, intent, customColor, currentIndex } = useSegmentedGaugeContext()\n\n // Calculate isActive and isCurrent from context and index\n const isActive = currentIndex !== -1 && index <= currentIndex\n const isCurrent = currentIndex !== -1 && index === currentIndex\n\n const gaugeColor = useMemo(() => {\n // If customColor is provided, use it\n if (customColor) {\n return customColor\n }\n\n // Handle predefined intents\n switch (intent) {\n case 'main':\n return 'var(--color-main)'\n case 'support':\n return 'var(--color-support)'\n case 'basic':\n return 'var(--color-basic)'\n case 'accent':\n return 'var(--color-accent)'\n case 'success':\n return 'var(--color-success)'\n case 'alert':\n return 'var(--color-alert)'\n case 'danger':\n return 'var(--color-error)'\n case 'info':\n return 'var(--color-info)'\n case 'neutral':\n return 'var(--color-neutral)'\n default:\n return 'var(--color-neutral)'\n }\n }, [intent, customColor])\n\n const segmentClasses = cx(\n 'border-outline relative rounded-full',\n {\n 'h-sz-8 w-sz-24': size === 'sm',\n 'h-sz-12 w-sz-36': size === 'md',\n 'default:bg-[var(--gauge-color)]': isActive,\n 'border-sm bg-surface': !isActive,\n },\n className\n )\n\n const indicatorClasses = cx(\n 'absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2',\n 'default:bg-surface default:rounded-full',\n 'border-[var(--gauge-color)]',\n {\n 'size-sz-12 border-md': size === 'sm',\n 'size-sz-20 border-lg': size === 'md',\n }\n )\n\n return (\n <div\n data-spark-component=\"segmented-gauge-segment\"\n data-testid=\"segmented-gauge-segment\"\n data-active={isActive}\n data-current={isCurrent}\n ref={ref}\n style={\n {\n '--gauge-color': gaugeColor,\n } as React.CSSProperties\n }\n className={segmentClasses}\n {...props}\n >\n {children}\n {isCurrent && <div className={indicatorClasses} aria-hidden=\"true\" />}\n </div>\n )\n}\n\nSegmentedGaugeSegment.displayName = 'SegmentedGauge.Segment'\n","import { cx } from 'class-variance-authority'\nimport { ComponentProps, Ref } from 'react'\n\nexport interface SegmentedGaugeTrackProps extends ComponentProps<'div'> {\n ref?: Ref<HTMLDivElement>\n}\n\nexport const SegmentedGaugeTrack = ({\n className,\n children,\n ref,\n ...props\n}: SegmentedGaugeTrackProps) => {\n return (\n <div\n data-spark-component=\"segmented-gauge-track\"\n ref={ref}\n className={cx('gap-sm relative flex rounded-full', className)}\n {...props}\n >\n {children}\n </div>\n )\n}\n\nSegmentedGaugeTrack.displayName = 'SegmentedGauge.Track'\n","import { SegmentedGauge as Root } from './SegmentedGauge'\nimport { SegmentedGaugeLabel } from './SegmentedGaugeLabel'\nimport { SegmentedGaugeSegment } from './SegmentedGaugeSegment'\nimport { SegmentedGaugeTrack } from './SegmentedGaugeTrack'\n\nexport const SegmentedGauge: typeof Root & {\n Track: typeof SegmentedGaugeTrack\n Segment: typeof SegmentedGaugeSegment\n Label: typeof SegmentedGaugeLabel\n} = Object.assign(Root, {\n Track: SegmentedGaugeTrack,\n Segment: SegmentedGaugeSegment,\n Label: SegmentedGaugeLabel,\n})\n\nSegmentedGauge.displayName = 'SegmentedGauge'\nSegmentedGaugeTrack.displayName = 'SegmentedGauge.Track'\nSegmentedGaugeSegment.displayName = 'SegmentedGauge.Segment'\nSegmentedGaugeLabel.displayName = 'SegmentedGauge.Label'\n\nexport { type SegmentedGaugeProps } from './SegmentedGauge'\nexport { type SegmentedGaugeTrackProps } from './SegmentedGaugeTrack'\nexport { type SegmentedGaugeSegmentProps } from './SegmentedGaugeSegment'\nexport { type SegmentedGaugeLabelProps } from './SegmentedGaugeLabel'\n"],"mappings":";AAAA,SAAS,MAAAA,WAAU;AACnB,SAAc,OAAO,WAAAC,gBAAe;;;ACDpC,SAAS,eAAe,kBAAkB;AAwBnC,IAAM,wBAAwB,cAAiD,IAAI;AAEnF,IAAM,2BAA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;AAAA,EACR;AAEN,SACE,gBAAAF,KAAC,sBAAsB,UAAtB,EAA+B,OAAO,cACrC,0BAAAA;AAAA,IAAC;AAAA;AAAA,MACC,IAAI;AAAA,MACJ,wBAAqB;AAAA,MACrB;AAAA,MACA,WAAWG,IAAG,sCAAsC,SAAS;AAAA,MAC5D,GAAG;AAAA,MACJ,mBAAiB,KAAK,GAAG,OAAO,WAAW;AAAA,MAC3C,cAAY,CAAC,KAAK,YAAY;AAAA,MAC9B,oBAAkB;AAAA,MACjB,GAAG;AAAA,MAEH,qBACC,SAAS;AAAA,QACP,UAAU;AAAA,QACV;AAAA,MACF,CAAC,IAED,gBAAAF,MAAA,YACE;AAAA,wBAAAD,KAAC,uBACE,uBAAa,IAAI,CAAC,GAAG,UACpB,gBAAAA,KAAC,yBAAkC,SAAP,KAAqB,CAClD,GACH;AAAA,QAEC,eACC,gBAAAA,KAAC,uBAAoB,IAAI,iBAAkB,uBAAY;AAAA,SAE3D;AAAA;AAAA,EAEJ,GACF;AAEJ;AAEA,eAAe,cAAc;;;AKnMtB,IAAMI,kBAIT,OAAO,OAAO,gBAAM;AAAA,EACtB,OAAO;AAAA,EACP,SAAS;AAAA,EACT,OAAO;AACT,CAAC;AAEDA,gBAAe,cAAc;AAC7B,oBAAoB,cAAc;AAClC,sBAAsB,cAAc;AACpC,oBAAoB,cAAc;","names":["cx","useMemo","cx","jsx","cx","cx","jsx","jsx","jsxs","useMemo","cx","SegmentedGauge"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@spark-ui/components",
3
- "version": "11.1.4",
3
+ "version": "11.1.5",
4
4
  "license": "MIT",
5
5
  "description": "Spark (Leboncoin design system) components.",
6
6
  "exports": {
@@ -53,9 +53,9 @@
53
53
  "@react-aria/toast": "^3.0.0-beta.18",
54
54
  "@react-stately/numberfield": "3.9.11",
55
55
  "@react-stately/toast": "^3.0.0-beta.7",
56
- "@spark-ui/hooks": "^11.1.4",
57
- "@spark-ui/icons": "^11.1.4",
58
- "@spark-ui/internal-utils": "^11.1.4",
56
+ "@spark-ui/hooks": "^11.1.5",
57
+ "@spark-ui/icons": "^11.1.5",
58
+ "@spark-ui/internal-utils": "^11.1.5",
59
59
  "@zag-js/pagination": "1.25.0",
60
60
  "@zag-js/react": "1.25.0",
61
61
  "class-variance-authority": "0.7.1",
@@ -82,5 +82,5 @@
82
82
  "url": "https://github.com/leboncoin/spark-web/issues?q=is%3Aopen+label%3A%22Component%3A+button%22"
83
83
  },
84
84
  "homepage": "https://sparkui.vercel.app",
85
- "gitHead": "d56526a1747a6d189b1ade29ae3bce338cae57db"
85
+ "gitHead": "b974e73fbf68488879bbbd276e0db0eb9fe026e6"
86
86
  }