@spark-ui/components 17.2.1-beta.1 → 17.2.1
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/radio-group/Radio.d.ts +2 -2
- package/dist/radio-group/RadioGroup.d.ts +5 -1
- package/dist/radio-group/RadioIndicator.d.ts +7 -4
- package/dist/radio-group/RadioInput.d.ts +4 -16
- package/dist/radio-group/RadioLabel.d.ts +20 -0
- package/dist/radio-group/RadioLabel.styles.d.ts +5 -0
- package/dist/radio-group/index.js +1 -1
- package/dist/radio-group/index.js.map +1 -1
- package/dist/radio-group/index.mjs +129 -123
- package/dist/radio-group/index.mjs.map +1 -1
- package/dist/segmented-control/index.js +1 -1
- package/dist/segmented-control/index.js.map +1 -1
- package/dist/segmented-control/index.mjs +128 -116
- package/dist/segmented-control/index.mjs.map +1 -1
- package/package.json +4 -4
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Ref } from 'react';
|
|
2
2
|
import { RadioInputProps } from './RadioInput';
|
|
3
3
|
export type RadioProps = RadioInputProps & {
|
|
4
|
-
ref?: Ref<
|
|
4
|
+
ref?: Ref<HTMLButtonElement>;
|
|
5
5
|
};
|
|
6
6
|
export declare const Radio: {
|
|
7
|
-
({ className, children, disabled: disabledProp, ref, ...others }: RadioProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
({ className, children, id, disabled: disabledProp, ref, ...others }: RadioProps): import("react/jsx-runtime").JSX.Element;
|
|
8
8
|
displayName: string;
|
|
9
9
|
};
|
|
@@ -38,6 +38,10 @@ export interface RadioGroupProps extends RadioGroupVariantsProps, Pick<RadioInpu
|
|
|
38
38
|
* The reading direction of the radio group.
|
|
39
39
|
*/
|
|
40
40
|
dir?: 'ltr' | 'rtl';
|
|
41
|
+
/**
|
|
42
|
+
* When true, keyboard navigation will loop from last item to first, and vice versa.
|
|
43
|
+
*/
|
|
44
|
+
loop?: boolean;
|
|
41
45
|
/**
|
|
42
46
|
* When true, the label will be placed on the left side of the Radio
|
|
43
47
|
*/
|
|
@@ -45,6 +49,6 @@ export interface RadioGroupProps extends RadioGroupVariantsProps, Pick<RadioInpu
|
|
|
45
49
|
ref?: Ref<HTMLDivElement>;
|
|
46
50
|
}
|
|
47
51
|
export declare const RadioGroup: {
|
|
48
|
-
({ orientation, intent, disabled, className, required: requiredProp, reverse,
|
|
52
|
+
({ orientation, loop, intent, disabled, className, required: requiredProp, reverse, ref, ...others }: RadioGroupProps): import("react/jsx-runtime").JSX.Element;
|
|
49
53
|
displayName: string;
|
|
50
54
|
};
|
|
@@ -3,13 +3,16 @@ import { RadioIndicatorStylesProps } from './RadioIndicator.styles';
|
|
|
3
3
|
export interface RadioIndicatorProps extends RadioIndicatorStylesProps {
|
|
4
4
|
className?: string;
|
|
5
5
|
/**
|
|
6
|
-
*
|
|
7
|
-
* Useful when controlling animation with React animation libraries.
|
|
6
|
+
* Change the component to the HTML tag or custom component of the only child.
|
|
8
7
|
*/
|
|
9
|
-
|
|
8
|
+
asChild?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries.
|
|
11
|
+
*/
|
|
12
|
+
forceMount?: true | undefined;
|
|
10
13
|
ref?: Ref<HTMLSpanElement>;
|
|
11
14
|
}
|
|
12
15
|
export declare const RadioIndicator: {
|
|
13
|
-
({ intent, className,
|
|
16
|
+
({ intent, className, ref, ...others }: RadioIndicatorProps): import("react/jsx-runtime").JSX.Element;
|
|
14
17
|
displayName: string;
|
|
15
18
|
};
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ButtonHTMLAttributes, Ref } from 'react';
|
|
2
2
|
import { RadioInputVariantsProps } from './RadioInput.styles';
|
|
3
|
-
export interface RadioInputProps extends RadioInputVariantsProps, Omit<
|
|
3
|
+
export interface RadioInputProps extends RadioInputVariantsProps, Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'value' | 'onChange'> {
|
|
4
4
|
/**
|
|
5
5
|
* Change the component to the HTML tag or custom component of the only child.
|
|
6
|
-
* Uses Base UI's render prop internally to merge behaviour into the child element.
|
|
7
6
|
*/
|
|
8
7
|
asChild?: boolean;
|
|
9
8
|
/**
|
|
@@ -18,20 +17,9 @@ export interface RadioInputProps extends RadioInputVariantsProps, Omit<HTMLAttri
|
|
|
18
17
|
* When true, indicates that the user must check the radio item before the owning form can be submitted.
|
|
19
18
|
*/
|
|
20
19
|
required?: boolean;
|
|
21
|
-
|
|
22
|
-
* Ref forwarded to the hidden `<input type="radio">` rendered by Base UI.
|
|
23
|
-
* Useful for programmatic activation (e.g. clicking from an associated label span).
|
|
24
|
-
*/
|
|
25
|
-
inputRef?: Ref<HTMLInputElement>;
|
|
26
|
-
ref?: Ref<HTMLElement>;
|
|
27
|
-
/**
|
|
28
|
-
* When true, the visual radio input (outer ring and inner dot) is visually hidden but remains
|
|
29
|
-
* accessible in the DOM. Useful for custom radio appearances where only the label matters visually.
|
|
30
|
-
* @default false
|
|
31
|
-
*/
|
|
32
|
-
hideInput?: boolean;
|
|
20
|
+
ref?: Ref<HTMLButtonElement>;
|
|
33
21
|
}
|
|
34
22
|
export declare const RadioInput: {
|
|
35
|
-
({ intent: intentProp, className,
|
|
23
|
+
({ intent: intentProp, className, ref, ...others }: RadioInputProps): import("react/jsx-runtime").JSX.Element;
|
|
36
24
|
displayName: string;
|
|
37
25
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { HTMLAttributes, PropsWithChildren } from 'react';
|
|
2
|
+
import { RadioLabelStylesProps } from './RadioLabel.styles';
|
|
3
|
+
export interface RadioLabelProps extends RadioLabelStylesProps, PropsWithChildren<HTMLAttributes<HTMLLabelElement>> {
|
|
4
|
+
/**
|
|
5
|
+
* Change the component to the HTML tag or custom component of the only child.
|
|
6
|
+
*/
|
|
7
|
+
asChild?: boolean;
|
|
8
|
+
/**
|
|
9
|
+
* The id of the element the label is associated with.
|
|
10
|
+
*/
|
|
11
|
+
htmlFor?: string;
|
|
12
|
+
/**
|
|
13
|
+
* When true, prevents the user from interacting with the radio item.
|
|
14
|
+
*/
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
}
|
|
17
|
+
export declare const RadioLabel: {
|
|
18
|
+
({ disabled, ...others }: RadioLabelProps): import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
displayName: string;
|
|
20
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { VariantProps } from 'class-variance-authority';
|
|
2
|
+
export declare const radioLabelStyles: (props?: ({
|
|
3
|
+
disabled?: boolean | null | undefined;
|
|
4
|
+
} & import('class-variance-authority/types').ClassProp) | undefined) => string;
|
|
5
|
+
export type RadioLabelStylesProps = VariantProps<typeof radioLabelStyles>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const a=require("react/jsx-runtime"),d=require("class-variance-authority"),s=require("react"),G=require("@spark-ui/components/form-field"),b=require("radix-ui"),y=require("@spark-ui/internal-utils"),k=s.createContext(null),w=()=>{const e=s.useContext(k);if(!e)throw Error("useRadioGroup must be used within a RadioGroup provider");return e},V=d.cva(["relative block","size-3/5","after:absolute","after:left-1/2 after:top-1/2 after:-translate-x-1/2 after:-translate-y-1/2","after:h-0","after:w-0","after:block","after:rounded-[50%]","after:content-['']","after:transition-all","data-[state=checked]:after:size-full"],{variants:{intent:y.makeVariants({main:["after:bg-main"],support:["after:bg-support"],accent:["after:bg-accent"],neutral:["after:bg-neutral"],success:["after:bg-success"],alert:["after:bg-alert"],error:["after:bg-error"],info:["after:bg-info"]})},defaultVariants:{intent:"support"}}),I=({intent:e,className:r,ref:t,...o})=>a.jsx(b.RadioGroup.Indicator,{ref:t,className:V({intent:e,className:r}),...o});I.displayName="RadioGroup.RadioIndicator";const L=d.cva(["flex shrink-0 items-center justify-center","rounded-full","border-md","outline-hidden","hover:ring-4","focus-visible:u-outline","disabled:cursor-not-allowed disabled:border-outline/dim-2 disabled:hover:ring-transparent","u-shadow-border-transition","size-sz-24"],{variants:{intent:y.makeVariants({main:["border-outline","data-[state=checked]:border-main","hover:ring-main-container"],support:["border-outline","data-[state=checked]:border-support","hover:ring-support-container"],accent:["border-outline","data-[state=checked]:border-accent","hover:ring-accent-container"],neutral:["border-outline","data-[state=checked]:border-neutral","hover:ring-neutral-container"],info:["border-info","data-[state=checked]:border-info","hover:ring-info-container"],success:["border-success","data-[state=checked]:border-success","hover:ring-success-container"],alert:["border-alert","data-[state=checked]:border-alert","hover:ring-alert-container"],error:["border-error","data-[state=checked]:border-error","hover:ring-error-container"]})},defaultVariants:{intent:"support"}}),j=({intent:e,className:r,ref:t,...o})=>{const{state:n}=G.useFormFieldControl(),i=n??e;return a.jsx(b.RadioGroup.RadioGroupItem,{"data-spark-component":"radio-input",ref:t,className:L({intent:i,className:r}),...o,children:a.jsx(I,{intent:i,forceMount:!0})})};j.displayName="RadioGroup.RadioInput";const z=d.cva("grow",{variants:{disabled:{true:["text-neutral/dim-2","cursor-not-allowed"],false:["cursor-pointer"]}},defaultVariants:{disabled:!1}}),N=({disabled:e,...r})=>a.jsx(b.Label.Root,{"data-spark-component":"radio-label",className:z({disabled:e}),...r});N.displayName="RadioGroup.RadioLabel";const x=":radio",v=({className:e,children:r,id:t,disabled:o,ref:n,...i})=>{const c=`${x}-input-${s.useId()}`,l=`${x}-label-${s.useId()}`,{intent:f,disabled:m,reverse:R}=w(),u=r&&a.jsx(N,{disabled:o||m,htmlFor:t||c,id:l,children:r}),p=a.jsx(j,{ref:n,id:t||c,intent:f,"aria-labelledby":r?l:void 0,...i,disabled:o}),h=R?a.jsxs(a.Fragment,{children:[u,p]}):a.jsxs(a.Fragment,{children:[p,u]});return a.jsx("span",{className:d.cx("gap-md text-body-1 flex items-start",e),children:h})};v.displayName="RadioGroup.Radio";const C=d.cva(["flex"],{variants:{orientation:{vertical:["flex-col","gap-lg"],horizontal:["flex-row","gap-xl"]}}}),S=({intent:e,disabled:r,reverse:t,children:o})=>{const n=s.useMemo(()=>({intent:e,disabled:r,reverse:t}),[e,r,t]);return a.jsx(k.Provider,{value:n,children:o})},q=({orientation:e="vertical",loop:r=!0,intent:t="support",disabled:o,className:n,required:i,reverse:c=!1,ref:l,...f})=>{const{labelId:m,isInvalid:R,isRequired:u,description:p,name:h}=G.useFormFieldControl(),g=i!==void 0?i:u;return a.jsx(S,{reverse:c,intent:t,disabled:o,children:a.jsx(b.RadioGroup.RadioGroup,{"data-spark-component":"radio-group",className:C({orientation:e,className:n}),name:h,ref:l,disabled:o,orientation:e,loop:r,required:g,"aria-labelledby":m,"aria-invalid":R,"aria-required":g,"aria-describedby":p,...f})})};q.displayName="RadioGroup";const F=Object.assign(q,{Radio:v});F.displayName="RadioGroup";v.displayName="RadioGroup.Radio";exports.RadioGroup=F;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/radio-group/RadioGroupContext.tsx","../../src/radio-group/RadioIndicator.styles.ts","../../src/radio-group/RadioIndicator.tsx","../../src/radio-group/RadioInput.styles.ts","../../src/radio-group/RadioInput.tsx","../../src/radio-group/Radio.tsx","../../src/radio-group/RadioGroup.styles.ts","../../src/radio-group/RadioGroupProvider.tsx","../../src/radio-group/RadioGroup.tsx","../../src/radio-group/index.ts"],"sourcesContent":["import { createContext, useContext } from 'react'\n\nimport type { RadioGroupProps } from './RadioGroup'\nimport type { RadioInputProps } from './RadioInput'\n\nexport type RadioGroupContextState = Pick<RadioInputProps, 'intent' | 'disabled'> &\n Pick<RadioGroupProps, 'reverse'>\n\nexport const RadioGroupContext = createContext<RadioGroupContextState | null>(null)\n\nexport const useRadioGroup = () => {\n const context = useContext(RadioGroupContext)\n\n if (!context) {\n throw Error('useRadioGroup must be used within a RadioGroup provider')\n }\n\n return context\n}\n","import { makeVariants } from '@spark-ui/internal-utils'\nimport { cva, VariantProps } from 'class-variance-authority'\n\nexport const radioIndicatorStyles = cva(\n [\n 'relative block',\n 'size-3/5',\n 'after:absolute',\n 'after:left-1/2 after:top-1/2 after:-translate-x-1/2 after:-translate-y-1/2',\n 'after:h-0',\n 'after:w-0',\n 'after:block',\n 'after:rounded-[50%]',\n \"after:content-['']\",\n 'after:transition-all',\n 'data-checked:after:size-full',\n ],\n {\n variants: {\n intent: makeVariants<\n 'intent',\n ['main', 'support', 'accent', 'success', 'alert', 'error', 'info', 'neutral']\n >({\n main: ['after:bg-main'],\n support: ['after:bg-support'],\n accent: ['after:bg-accent'],\n neutral: ['after:bg-neutral'],\n success: ['after:bg-success'],\n alert: ['after:bg-alert'],\n error: ['after:bg-error'],\n info: ['after:bg-info'],\n }),\n },\n defaultVariants: {\n intent: 'support',\n },\n }\n)\n\nexport type RadioIndicatorStylesProps = VariantProps<typeof radioIndicatorStyles>\n","import { Radio } from '@base-ui/react/radio'\nimport { Ref } from 'react'\n\nimport { radioIndicatorStyles, RadioIndicatorStylesProps } from './RadioIndicator.styles'\n\nexport interface RadioIndicatorProps extends RadioIndicatorStylesProps {\n className?: string\n /**\n * Whether to keep the indicator mounted in the DOM when the radio is unchecked.\n * Useful when controlling animation with React animation libraries.\n */\n keepMounted?: boolean\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const RadioIndicator = ({\n intent,\n className,\n keepMounted,\n ref,\n ...others\n}: RadioIndicatorProps) => {\n return (\n <Radio.Indicator\n ref={ref}\n keepMounted={keepMounted}\n className={radioIndicatorStyles({ intent, className })}\n {...others}\n />\n )\n}\n\nRadioIndicator.displayName = 'RadioGroup.RadioIndicator'\n","import { makeVariants } from '@spark-ui/internal-utils'\nimport { cva, VariantProps } from 'class-variance-authority'\n\nexport const radioInputVariants = cva(\n [\n 'flex shrink-0 items-center justify-center',\n 'rounded-full',\n 'border-md',\n 'outline-hidden',\n 'hover:ring-4',\n 'focus-visible:u-outline',\n 'data-disabled:cursor-not-allowed data-disabled:border-outline/dim-2 data-disabled:hover:ring-transparent',\n 'u-shadow-border-transition',\n 'size-sz-24',\n ],\n {\n variants: {\n /**\n * Color scheme of the radio input.\n */\n intent: makeVariants<\n 'intent',\n ['main', 'support', 'accent', 'success', 'alert', 'error', 'info', 'neutral']\n >({\n main: ['border-outline', 'data-checked:border-main', 'hover:ring-main-container'],\n support: ['border-outline', 'data-checked:border-support', 'hover:ring-support-container'],\n accent: ['border-outline', 'data-checked:border-accent', 'hover:ring-accent-container'],\n neutral: ['border-outline', 'data-checked:border-neutral', 'hover:ring-neutral-container'],\n info: ['border-info', 'data-checked:border-info', 'hover:ring-info-container'],\n success: ['border-success', 'data-checked:border-success', 'hover:ring-success-container'],\n alert: ['border-alert', 'data-checked:border-alert', 'hover:ring-alert-container'],\n error: ['border-error', 'data-checked:border-error', 'hover:ring-error-container'],\n }),\n },\n defaultVariants: {\n intent: 'support',\n },\n }\n)\n\nexport type RadioInputVariantsProps = VariantProps<typeof radioInputVariants>\n","import { Radio } from '@base-ui/react/radio'\nimport { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { HTMLAttributes, ReactElement, Ref } from 'react'\n\nimport { RadioIndicator } from './RadioIndicator'\nimport { radioInputVariants, RadioInputVariantsProps } from './RadioInput.styles'\n\nexport interface RadioInputProps\n extends RadioInputVariantsProps,\n Omit<HTMLAttributes<HTMLElement>, 'value' | 'onChange'> {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Uses Base UI's render prop internally to merge behaviour into the child element.\n */\n asChild?: boolean\n /**\n * The value given as data when submitted with a name.\n */\n value: string\n /**\n * When true, prevents the user from interacting with the radio item.\n */\n disabled?: boolean\n /**\n * When true, indicates that the user must check the radio item before the owning form can be submitted.\n */\n required?: boolean\n /**\n * Ref forwarded to the hidden `<input type=\"radio\">` rendered by Base UI.\n * Useful for programmatic activation (e.g. clicking from an associated label span).\n */\n inputRef?: Ref<HTMLInputElement>\n ref?: Ref<HTMLElement>\n /**\n * When true, the visual radio input (outer ring and inner dot) is visually hidden but remains\n * accessible in the DOM. Useful for custom radio appearances where only the label matters visually.\n * @default false\n */\n hideInput?: boolean\n}\n\nexport const RadioInput = ({\n intent: intentProp,\n className,\n asChild,\n children,\n inputRef,\n hideInput = false,\n ref,\n ...others\n}: RadioInputProps) => {\n const { state } = useFormFieldControl()\n\n const intent = state ?? intentProp\n\n return (\n <Radio.Root\n data-spark-component=\"radio-input\"\n ref={ref}\n inputRef={inputRef}\n render={asChild ? (children as ReactElement) : undefined}\n className={hideInput ? 'sr-only' : radioInputVariants({ intent, className })}\n {...others}\n >\n {!asChild && !hideInput && <RadioIndicator intent={intent} keepMounted />}\n </Radio.Root>\n )\n}\n\nRadioInput.displayName = 'RadioGroup.RadioInput'\n","import { cx } from 'class-variance-authority'\nimport { Ref, useId } from 'react'\n\nimport { Label } from '../label'\nimport { useRadioGroup } from './RadioGroupContext'\nimport { RadioInput, RadioInputProps } from './RadioInput'\n\nexport type RadioProps = RadioInputProps & {\n ref?: Ref<HTMLElement>\n}\n\nconst ID_PREFIX = ':radio'\n\nexport const Radio = ({\n className,\n children,\n disabled: disabledProp,\n ref,\n ...others\n}: RadioProps) => {\n const innerLabelId = `${ID_PREFIX}-label-${useId()}`\n\n const { intent, disabled, reverse } = useRadioGroup()\n\n const isDisabled = disabledProp || disabled\n\n const radioLabel = children && (\n <Label\n data-spark-component=\"radio-label\"\n id={innerLabelId}\n className={cx(\n 'grow',\n isDisabled ? 'text-neutral/dim-2 cursor-not-allowed' : 'cursor-pointer'\n )}\n >\n {children}\n </Label>\n )\n\n const radioInput = (\n <RadioInput\n ref={ref}\n intent={intent}\n aria-labelledby={children ? innerLabelId : undefined}\n {...others}\n disabled={disabledProp}\n />\n )\n\n const content = reverse ? (\n <>\n {radioLabel}\n {radioInput}\n </>\n ) : (\n <>\n {radioInput}\n {radioLabel}\n </>\n )\n\n return <span className={cx('gap-md text-body-1 flex items-start', className)}>{content}</span>\n}\n\nRadio.displayName = 'RadioGroup.Radio'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const radioGroupStyles = cva(['flex'], {\n variants: {\n orientation: {\n vertical: ['flex-col', 'gap-lg'],\n horizontal: ['flex-row', 'gap-xl'],\n },\n },\n})\n\nexport type RadioGroupVariantsProps = VariantProps<typeof radioGroupStyles>\n","import { ReactNode, useMemo } from 'react'\n\nimport type { RadioGroupProps } from './RadioGroup'\nimport { RadioGroupContext } from './RadioGroupContext'\nimport type { RadioInputProps } from './RadioInput'\n\nexport interface RadioGroupProviderProps\n extends Pick<RadioInputProps, 'intent' | 'disabled'>,\n Pick<RadioGroupProps, 'reverse'> {\n children: ReactNode\n}\n\nexport const RadioGroupProvider = ({\n intent,\n disabled,\n reverse,\n children,\n}: RadioGroupProviderProps) => {\n const value = useMemo(() => ({ intent, disabled, reverse }), [intent, disabled, reverse])\n\n return <RadioGroupContext.Provider value={value}>{children}</RadioGroupContext.Provider>\n}\n","import { RadioGroup as BaseUIRadioGroup } from '@base-ui/react/radio-group'\nimport { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { HTMLAttributes, Ref } from 'react'\n\nimport { radioGroupStyles, RadioGroupVariantsProps } from './RadioGroup.styles'\nimport { RadioGroupProvider } from './RadioGroupProvider'\nimport { RadioInputVariantsProps } from './RadioInput.styles'\n\nexport interface RadioGroupProps\n extends RadioGroupVariantsProps,\n Pick<RadioInputVariantsProps, 'intent'>,\n Omit<HTMLAttributes<HTMLDivElement>, 'value' | 'defaultValue' | 'dir' | 'onChange'> {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n */\n asChild?: boolean\n /**\n * The value of the radio item that should be checked when initially rendered. Use when you do not need to control the state of the radio items.\n */\n defaultValue?: string\n /**\n * The controlled value of the radio item to check. Should be used in conjunction with onValueChange.\n */\n value?: string\n /**\n * Event handler called when the value changes.\n */\n onValueChange?: (value: string) => void\n /**\n * When true, prevents the user from interacting with radio items.\n */\n disabled?: boolean\n /**\n * The name of the group. Submitted with its owning form as part of a name/value pair.\n */\n name?: string\n /**\n * When true, indicates that the user must check a radio item before the owning form can be submitted.\n */\n required?: boolean\n /**\n * The orientation of the component.\n */\n orientation?: 'horizontal' | 'vertical'\n /**\n * The reading direction of the radio group.\n */\n dir?: 'ltr' | 'rtl'\n /**\n * When true, the label will be placed on the left side of the Radio\n */\n reverse?: boolean\n ref?: Ref<HTMLDivElement>\n}\n\nexport const RadioGroup = ({\n orientation = 'vertical',\n intent = 'support',\n disabled,\n className,\n required: requiredProp,\n reverse = false,\n onValueChange: onValueChangeProp,\n ref,\n ...others\n}: RadioGroupProps) => {\n const { labelId, isInvalid, isRequired, description, name } = useFormFieldControl()\n const required = requiredProp !== undefined ? requiredProp : isRequired\n\n const handleValueChange = onValueChangeProp\n ? (value: unknown) => onValueChangeProp(value as string)\n : undefined\n\n return (\n <RadioGroupProvider reverse={reverse} intent={intent} disabled={disabled}>\n <BaseUIRadioGroup\n data-spark-component=\"radio-group\"\n className={radioGroupStyles({ orientation, className })}\n name={name}\n ref={ref}\n disabled={disabled}\n required={required}\n onValueChange={handleValueChange}\n aria-orientation={orientation}\n aria-labelledby={labelId}\n aria-invalid={isInvalid}\n aria-required={required}\n aria-describedby={description}\n {...others}\n />\n </RadioGroupProvider>\n )\n}\n\nRadioGroup.displayName = 'RadioGroup'\n","import { Radio } from './Radio'\nimport { RadioGroup as Root } from './RadioGroup'\n\nexport const RadioGroup: typeof Root & {\n Radio: typeof Radio\n} = Object.assign(Root, {\n Radio,\n})\n\nRadioGroup.displayName = 'RadioGroup'\nRadio.displayName = 'RadioGroup.Radio'\n\nexport { type RadioGroupProps } from './RadioGroup'\nexport { type RadioProps } from './Radio'\n"],"names":["RadioGroupContext","createContext","useRadioGroup","context","useContext","radioIndicatorStyles","cva","makeVariants","RadioIndicator","intent","className","keepMounted","ref","others","jsx","Radio","radioInputVariants","RadioInput","intentProp","asChild","children","inputRef","hideInput","state","useFormFieldControl","ID_PREFIX","disabledProp","innerLabelId","useId","disabled","reverse","isDisabled","radioLabel","Label","cx","radioInput","content","jsxs","Fragment","radioGroupStyles","RadioGroupProvider","value","useMemo","RadioGroup","orientation","requiredProp","onValueChangeProp","labelId","isInvalid","isRequired","description","name","required","handleValueChange","BaseUIRadioGroup","Root"],"mappings":"0WAQaA,EAAoBC,EAAAA,cAA6C,IAAI,EAErEC,EAAgB,IAAM,CACjC,MAAMC,EAAUC,EAAAA,WAAWJ,CAAiB,EAE5C,GAAI,CAACG,EACH,MAAM,MAAM,yDAAyD,EAGvE,OAAOA,CACT,ECfaE,EAAuBC,EAAAA,IAClC,CACE,iBACA,WACA,iBACA,6EACA,YACA,YACA,cACA,sBACA,qBACA,uBACA,8BAAA,EAEF,CACE,SAAU,CACR,OAAQC,EAAAA,aAGN,CACA,KAAM,CAAC,eAAe,EACtB,QAAS,CAAC,kBAAkB,EAC5B,OAAQ,CAAC,iBAAiB,EAC1B,QAAS,CAAC,kBAAkB,EAC5B,QAAS,CAAC,kBAAkB,EAC5B,MAAO,CAAC,gBAAgB,EACxB,MAAO,CAAC,gBAAgB,EACxB,KAAM,CAAC,eAAe,CAAA,CACvB,CAAA,EAEH,gBAAiB,CACf,OAAQ,SAAA,CACV,CAEJ,ECtBaC,EAAiB,CAAC,CAC7B,OAAAC,EACA,UAAAC,EACA,YAAAC,EACA,IAAAC,EACA,GAAGC,CACL,IAEIC,EAAAA,IAACC,EAAAA,MAAM,UAAN,CACC,IAAAH,EACA,YAAAD,EACA,UAAWN,EAAqB,CAAE,OAAAI,EAAQ,UAAAC,EAAW,EACpD,GAAGG,CAAA,CAAA,EAKVL,EAAe,YAAc,4BC7BtB,MAAMQ,EAAqBV,EAAAA,IAChC,CACE,4CACA,eACA,YACA,iBACA,eACA,0BACA,2GACA,6BACA,YAAA,EAEF,CACE,SAAU,CAIR,OAAQC,EAAAA,aAGN,CACA,KAAM,CAAC,iBAAkB,2BAA4B,2BAA2B,EAChF,QAAS,CAAC,iBAAkB,8BAA+B,8BAA8B,EACzF,OAAQ,CAAC,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ACrD,OAEJ,OACE3B,EAAAA,IAAC0B,EAAA,CAAmB,QAAAV,EAAkB,OAAArB,EAAgB,SAAAoB,EACpD,SAAAf,EAAAA,IAACwC,EAAAA,WAAA,CACC,uBAAqB,cACrB,UAAWf,EAAiB,CAAE,YAAAK,EAAa,UAAAlC,EAAW,EACtD,KAAAyC,EACA,IAAAvC,EACA,SAAAiB,EACA,SAAAuB,EACA,cAAeC,EACf,mBAAkBT,EAClB,kBAAiBG,EACjB,eAAcC,EACd,gBAAeI,EACf,mBAAkBF,EACjB,GAAGrC,CAAA,CAAA,EAER,CAEJ,EAEA8B,EAAW,YAAc,aC3FlB,MAAMA,EAET,OAAO,OAAOY,EAAM,CACtB,MAAAxC,CACF,CAAC,EAED4B,EAAW,YAAc,aACzB5B,EAAM,YAAc"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/radio-group/RadioGroupContext.tsx","../../src/radio-group/RadioIndicator.styles.ts","../../src/radio-group/RadioIndicator.tsx","../../src/radio-group/RadioInput.styles.ts","../../src/radio-group/RadioInput.tsx","../../src/radio-group/RadioLabel.styles.tsx","../../src/radio-group/RadioLabel.tsx","../../src/radio-group/Radio.tsx","../../src/radio-group/RadioGroup.styles.ts","../../src/radio-group/RadioGroupProvider.tsx","../../src/radio-group/RadioGroup.tsx","../../src/radio-group/index.ts"],"sourcesContent":["import { createContext, useContext } from 'react'\n\nimport type { RadioGroupProps } from './RadioGroup'\nimport type { RadioInputProps } from './RadioInput'\n\nexport type RadioGroupContextState = Pick<RadioInputProps, 'intent' | 'disabled'> &\n Pick<RadioGroupProps, 'reverse'>\n\nexport const RadioGroupContext = createContext<RadioGroupContextState | null>(null)\n\nexport const useRadioGroup = () => {\n const context = useContext(RadioGroupContext)\n\n if (!context) {\n throw Error('useRadioGroup must be used within a RadioGroup provider')\n }\n\n return context\n}\n","import { makeVariants } from '@spark-ui/internal-utils'\nimport { cva, VariantProps } from 'class-variance-authority'\n\nexport const radioIndicatorStyles = cva(\n [\n 'relative block',\n 'size-3/5',\n 'after:absolute',\n 'after:left-1/2 after:top-1/2 after:-translate-x-1/2 after:-translate-y-1/2',\n 'after:h-0',\n 'after:w-0',\n 'after:block',\n 'after:rounded-[50%]',\n \"after:content-['']\",\n 'after:transition-all',\n 'data-[state=checked]:after:size-full',\n ],\n {\n variants: {\n intent: makeVariants<\n 'intent',\n ['main', 'support', 'accent', 'success', 'alert', 'error', 'info', 'neutral']\n >({\n main: ['after:bg-main'],\n support: ['after:bg-support'],\n accent: ['after:bg-accent'],\n neutral: ['after:bg-neutral'],\n success: ['after:bg-success'],\n alert: ['after:bg-alert'],\n error: ['after:bg-error'],\n info: ['after:bg-info'],\n }),\n },\n defaultVariants: {\n intent: 'support',\n },\n }\n)\n\nexport type RadioIndicatorStylesProps = VariantProps<typeof radioIndicatorStyles>\n","import { RadioGroup as RadixRadioGroup } from 'radix-ui'\nimport { Ref } from 'react'\n\nimport { radioIndicatorStyles, RadioIndicatorStylesProps } from './RadioIndicator.styles'\n\nexport interface RadioIndicatorProps extends RadioIndicatorStylesProps {\n className?: string\n /**\n * Change the component to the HTML tag or custom component of the only child.\n */\n asChild?: boolean\n /**\n * Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries.\n */\n forceMount?: true | undefined\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const RadioIndicator = ({ intent, className, ref, ...others }: RadioIndicatorProps) => {\n return (\n <RadixRadioGroup.Indicator\n ref={ref}\n className={radioIndicatorStyles({ intent, className })}\n {...others}\n />\n )\n}\n\nRadioIndicator.displayName = 'RadioGroup.RadioIndicator'\n","import { makeVariants } from '@spark-ui/internal-utils'\nimport { cva, VariantProps } from 'class-variance-authority'\n\nexport const radioInputVariants = cva(\n [\n 'flex shrink-0 items-center justify-center',\n 'rounded-full',\n 'border-md',\n 'outline-hidden',\n 'hover:ring-4',\n 'focus-visible:u-outline',\n 'disabled:cursor-not-allowed disabled:border-outline/dim-2 disabled:hover:ring-transparent',\n 'u-shadow-border-transition',\n 'size-sz-24',\n ],\n {\n variants: {\n /**\n * Color scheme of the radio input.\n */\n intent: makeVariants<\n 'intent',\n ['main', 'support', 'accent', 'success', 'alert', 'error', 'info', 'neutral']\n >({\n main: ['border-outline', 'data-[state=checked]:border-main', 'hover:ring-main-container'],\n support: [\n 'border-outline',\n 'data-[state=checked]:border-support',\n 'hover:ring-support-container',\n ],\n accent: [\n 'border-outline',\n 'data-[state=checked]:border-accent',\n 'hover:ring-accent-container',\n ],\n neutral: [\n 'border-outline',\n 'data-[state=checked]:border-neutral',\n 'hover:ring-neutral-container',\n ],\n info: ['border-info', 'data-[state=checked]:border-info', 'hover:ring-info-container'],\n success: [\n 'border-success',\n 'data-[state=checked]:border-success',\n 'hover:ring-success-container',\n ],\n alert: ['border-alert', 'data-[state=checked]:border-alert', 'hover:ring-alert-container'],\n error: ['border-error', 'data-[state=checked]:border-error', 'hover:ring-error-container'],\n }),\n },\n defaultVariants: {\n intent: 'support',\n },\n }\n)\n\nexport type RadioInputVariantsProps = VariantProps<typeof radioInputVariants>\n","import { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { RadioGroup as RadixRadioGroup } from 'radix-ui'\nimport { ButtonHTMLAttributes, Ref } from 'react'\n\nimport { RadioIndicator } from './RadioIndicator'\nimport { radioInputVariants, RadioInputVariantsProps } from './RadioInput.styles'\n\nexport interface RadioInputProps\n extends RadioInputVariantsProps,\n Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'value' | 'onChange'> {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n */\n asChild?: boolean\n /**\n * The value given as data when submitted with a name.\n */\n value: string\n /**\n * When true, prevents the user from interacting with the radio item.\n */\n disabled?: boolean\n /**\n * When true, indicates that the user must check the radio item before the owning form can be submitted.\n */\n required?: boolean\n ref?: Ref<HTMLButtonElement>\n}\n\nexport const RadioInput = ({ intent: intentProp, className, ref, ...others }: RadioInputProps) => {\n const { state } = useFormFieldControl()\n\n const intent = state ?? intentProp\n\n return (\n <RadixRadioGroup.RadioGroupItem\n data-spark-component=\"radio-input\"\n ref={ref}\n className={radioInputVariants({ intent, className })}\n {...others}\n >\n <RadioIndicator intent={intent} forceMount />\n </RadixRadioGroup.RadioGroupItem>\n )\n}\n\nRadioInput.displayName = 'RadioGroup.RadioInput'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const radioLabelStyles = cva('grow', {\n variants: {\n disabled: {\n true: ['text-neutral/dim-2', 'cursor-not-allowed'],\n false: ['cursor-pointer'],\n },\n },\n defaultVariants: {\n disabled: false,\n },\n})\n\nexport type RadioLabelStylesProps = VariantProps<typeof radioLabelStyles>\n","import { Label } from 'radix-ui'\nimport type { HTMLAttributes, PropsWithChildren } from 'react'\n\nimport { radioLabelStyles, RadioLabelStylesProps } from './RadioLabel.styles'\n\nexport interface RadioLabelProps\n extends RadioLabelStylesProps,\n PropsWithChildren<HTMLAttributes<HTMLLabelElement>> {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n */\n asChild?: boolean\n /**\n * The id of the element the label is associated with.\n */\n htmlFor?: string\n /**\n * When true, prevents the user from interacting with the radio item.\n */\n disabled?: boolean\n}\n\nexport const RadioLabel = ({ disabled, ...others }: RadioLabelProps) => {\n return (\n <Label.Root\n data-spark-component=\"radio-label\"\n className={radioLabelStyles({ disabled })}\n {...others}\n />\n )\n}\n\nRadioLabel.displayName = 'RadioGroup.RadioLabel'\n","import { cx } from 'class-variance-authority'\nimport { Ref, useId } from 'react'\n\nimport { useRadioGroup } from './RadioGroupContext'\nimport { RadioInput, RadioInputProps } from './RadioInput'\nimport { RadioLabel } from './RadioLabel'\n\nexport type RadioProps = RadioInputProps & {\n ref?: Ref<HTMLButtonElement>\n}\n\nconst ID_PREFIX = ':radio'\n\nexport const Radio = ({\n className,\n children,\n id,\n disabled: disabledProp,\n ref,\n ...others\n}: RadioProps) => {\n const innerId = `${ID_PREFIX}-input-${useId()}`\n const innerLabelId = `${ID_PREFIX}-label-${useId()}`\n\n const { intent, disabled, reverse } = useRadioGroup()\n\n const radioLabel = children && (\n <RadioLabel disabled={disabledProp || disabled} htmlFor={id || innerId} id={innerLabelId}>\n {children}\n </RadioLabel>\n )\n\n const radioInput = (\n <RadioInput\n ref={ref}\n id={id || innerId}\n intent={intent}\n aria-labelledby={children ? innerLabelId : undefined}\n {...others}\n disabled={disabledProp}\n />\n )\n\n const content = reverse ? (\n <>\n {radioLabel}\n {radioInput}\n </>\n ) : (\n <>\n {radioInput}\n {radioLabel}\n </>\n )\n\n return <span className={cx('gap-md text-body-1 flex items-start', className)}>{content}</span>\n}\n\nRadio.displayName = 'RadioGroup.Radio'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const radioGroupStyles = cva(['flex'], {\n variants: {\n orientation: {\n vertical: ['flex-col', 'gap-lg'],\n horizontal: ['flex-row', 'gap-xl'],\n },\n },\n})\n\nexport type RadioGroupVariantsProps = VariantProps<typeof radioGroupStyles>\n","import { ReactNode, useMemo } from 'react'\n\nimport type { RadioGroupProps } from './RadioGroup'\nimport { RadioGroupContext } from './RadioGroupContext'\nimport type { RadioInputProps } from './RadioInput'\n\nexport interface RadioGroupProviderProps\n extends Pick<RadioInputProps, 'intent' | 'disabled'>,\n Pick<RadioGroupProps, 'reverse'> {\n children: ReactNode\n}\n\nexport const RadioGroupProvider = ({\n intent,\n disabled,\n reverse,\n children,\n}: RadioGroupProviderProps) => {\n const value = useMemo(() => ({ intent, disabled, reverse }), [intent, disabled, reverse])\n\n return <RadioGroupContext.Provider value={value}>{children}</RadioGroupContext.Provider>\n}\n","import { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { RadioGroup as RadixRadioGroup } from 'radix-ui'\nimport { HTMLAttributes, Ref } from 'react'\n\nimport { radioGroupStyles, RadioGroupVariantsProps } from './RadioGroup.styles'\nimport { RadioGroupProvider } from './RadioGroupProvider'\nimport { RadioInputVariantsProps } from './RadioInput.styles'\n\nexport interface RadioGroupProps\n extends RadioGroupVariantsProps,\n Pick<RadioInputVariantsProps, 'intent'>,\n Omit<HTMLAttributes<HTMLDivElement>, 'value' | 'defaultValue' | 'dir' | 'onChange'> {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n */\n asChild?: boolean\n /**\n * The value of the radio item that should be checked when initially rendered. Use when you do not need to control the state of the radio items.\n */\n defaultValue?: string\n /**\n * The controlled value of the radio item to check. Should be used in conjunction with onValueChange.\n */\n value?: string\n /**\n * Event handler called when the value changes.\n */\n onValueChange?: (value: string) => void\n /**\n * When true, prevents the user from interacting with radio items.\n */\n disabled?: boolean\n /**\n * The name of the group. Submitted with its owning form as part of a name/value pair.\n */\n name?: string\n /**\n * When true, indicates that the user must check a radio item before the owning form can be submitted.\n */\n required?: boolean\n /**\n * The orientation of the component.\n */\n orientation?: 'horizontal' | 'vertical'\n /**\n * The reading direction of the radio group.\n */\n dir?: 'ltr' | 'rtl'\n /**\n * When true, keyboard navigation will loop from last item to first, and vice versa.\n */\n loop?: boolean\n /**\n * When true, the label will be placed on the left side of the Radio\n */\n reverse?: boolean\n ref?: Ref<HTMLDivElement>\n}\n\nexport const RadioGroup = ({\n orientation = 'vertical',\n loop = true,\n intent = 'support',\n disabled,\n className,\n required: requiredProp,\n reverse = false,\n ref,\n ...others\n}: RadioGroupProps) => {\n const { labelId, isInvalid, isRequired, description, name } = useFormFieldControl()\n const required = requiredProp !== undefined ? requiredProp : isRequired\n\n return (\n <RadioGroupProvider reverse={reverse} intent={intent} disabled={disabled}>\n <RadixRadioGroup.RadioGroup\n data-spark-component=\"radio-group\"\n className={radioGroupStyles({ orientation, className })}\n name={name}\n ref={ref}\n disabled={disabled}\n orientation={orientation}\n loop={loop}\n required={required}\n aria-labelledby={labelId}\n aria-invalid={isInvalid}\n aria-required={required}\n aria-describedby={description}\n {...others}\n />\n </RadioGroupProvider>\n )\n}\n\nRadioGroup.displayName = 'RadioGroup'\n","import { Radio } from './Radio'\nimport { RadioGroup as Root } from './RadioGroup'\n\nexport const RadioGroup: typeof Root & {\n Radio: typeof Radio\n} = Object.assign(Root, {\n Radio,\n})\n\nRadioGroup.displayName = 'RadioGroup'\nRadio.displayName = 'RadioGroup.Radio'\n\nexport { type RadioGroupProps } from './RadioGroup'\nexport { type RadioProps } from './Radio'\n"],"names":["RadioGroupContext","createContext","useRadioGroup","context","useContext","radioIndicatorStyles","cva","makeVariants","RadioIndicator","intent","className","ref","others","jsx","RadixRadioGroup","radioInputVariants","RadioInput","intentProp","state","useFormFieldControl","radioLabelStyles","RadioLabel","disabled","Label","ID_PREFIX","Radio","children","id","disabledProp","innerId","useId","innerLabelId","reverse","radioLabel","radioInput","content","jsxs","Fragment","cx","radioGroupStyles","RadioGroupProvider","value","useMemo","RadioGroup","orientation","loop","requiredProp","labelId","isInvalid","isRequired","description","name","required","Root"],"mappings":"uRAQaA,EAAoBC,EAAAA,cAA6C,IAAI,EAErEC,EAAgB,IAAM,CACjC,MAAMC,EAAUC,EAAAA,WAAWJ,CAAiB,EAE5C,GAAI,CAACG,EACH,MAAM,MAAM,yDAAyD,EAGvE,OAAOA,CACT,ECfaE,EAAuBC,EAAAA,IAClC,CACE,iBACA,WACA,iBACA,6EACA,YACA,YACA,cACA,sBACA,qBACA,uBACA,sCAAA,EAEF,CACE,SAAU,CACR,OAAQC,EAAAA,aAGN,CACA,KAAM,CAAC,eAAe,EACtB,QAAS,CAAC,kBAAkB,EAC5B,OAAQ,CAAC,iBAAiB,EAC1B,QAAS,CAAC,kBAAkB,EAC5B,QAAS,CAAC,kBAAkB,EAC5B,MAAO,CAAC,gBAAgB,EACxB,MAAO,CAAC,gBAAgB,EACxB,KAAM,CAAC,eAAe,CAAA,CACvB,CAAA,EAEH,gBAAiB,CACf,OAAQ,SAAA,CACV,CAEJ,ECnBaC,EAAiB,CAAC,CAAE,OAAAC,EAAQ,UAAAC,EAAW,IAAAC,EAAK,GAAGC,KAExDC,EAAAA,IAACC,EAAAA,WAAgB,UAAhB,CACC,IAAAH,EACA,UAAWN,EAAqB,CAAE,OAAAI,EAAQ,UAAAC,EAAW,EACpD,GAAGE,CAA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,SAAAa,EAAU,QAAAU,CAAA,GAAY,CAACvB,EAAQa,EAAUU,CAAO,CAAC,EAExF,OAAOnB,EAAAA,IAACb,EAAkB,SAAlB,CAA2B,MAAAyC,EAAe,SAAAf,CAAA,CAAS,CAC7D,ECsCaiB,EAAa,CAAC,CACzB,YAAAC,EAAc,WACd,KAAAC,EAAO,GACP,OAAApC,EAAS,UACT,SAAAa,EACA,UAAAZ,EACA,SAAUoC,EACV,QAAAd,EAAU,GACV,IAAArB,EACA,GAAGC,CACL,IAAuB,CACrB,KAAM,CAAE,QAAAmC,EAAS,UAAAC,EAAW,WAAAC,EAAY,YAAAC,EAAa,KAAAC,CAAA,EAAShC,sBAAA,EACxDiC,EAAWN,IAAiB,OAAYA,EAAeG,EAE7D,OACEpC,EAAAA,IAAC2B,EAAA,CAAmB,QAAAR,EAAkB,OAAAvB,EAAgB,SAAAa,EACpD,SAAAT,EAAAA,IAACC,EAAAA,WAAgB,WAAhB,CACC,uBAAqB,cACrB,UAAWyB,EAAiB,CAAE,YAAAK,EAAa,UAAAlC,EAAW,EACtD,KAAAyC,EACA,IAAAxC,EACA,SAAAW,EACA,YAAAsB,EACA,KAAAC,EACA,SAAAO,EACA,kBAAiBL,EACjB,eAAcC,EACd,gBAAeI,EACf,mBAAkBF,EACjB,GAAGtC,CAAA,CAAA,EAER,CAEJ,EAEA+B,EAAW,YAAc,aC3FlB,MAAMA,EAET,OAAO,OAAOU,EAAM,CACtB,MAAA5B,CACF,CAAC,EAEDkB,EAAW,YAAc,aACzBlB,EAAM,YAAc"}
|
|
@@ -1,17 +1,15 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { cva as
|
|
3
|
-
import { createContext as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const y = $(null), E = () => {
|
|
10
|
-
const r = j(y);
|
|
1
|
+
import { jsx as o, jsxs as g, Fragment as G } from "react/jsx-runtime";
|
|
2
|
+
import { cva as u, cx as F } from "class-variance-authority";
|
|
3
|
+
import { createContext as V, useContext as j, useId as x, useMemo as C } from "react";
|
|
4
|
+
import { useFormFieldControl as y } from "@spark-ui/components/form-field";
|
|
5
|
+
import { RadioGroup as h, Label as q } from "radix-ui";
|
|
6
|
+
import { makeVariants as I } from "@spark-ui/internal-utils";
|
|
7
|
+
const N = V(null), S = () => {
|
|
8
|
+
const r = j(N);
|
|
11
9
|
if (!r)
|
|
12
10
|
throw Error("useRadioGroup must be used within a RadioGroup provider");
|
|
13
11
|
return r;
|
|
14
|
-
},
|
|
12
|
+
}, E = u(
|
|
15
13
|
[
|
|
16
14
|
"relative block",
|
|
17
15
|
"size-3/5",
|
|
@@ -23,11 +21,11 @@ const y = $(null), E = () => {
|
|
|
23
21
|
"after:rounded-[50%]",
|
|
24
22
|
"after:content-['']",
|
|
25
23
|
"after:transition-all",
|
|
26
|
-
"data-checked:after:size-full"
|
|
24
|
+
"data-[state=checked]:after:size-full"
|
|
27
25
|
],
|
|
28
26
|
{
|
|
29
27
|
variants: {
|
|
30
|
-
intent:
|
|
28
|
+
intent: I({
|
|
31
29
|
main: ["after:bg-main"],
|
|
32
30
|
support: ["after:bg-support"],
|
|
33
31
|
accent: ["after:bg-accent"],
|
|
@@ -42,23 +40,16 @@ const y = $(null), E = () => {
|
|
|
42
40
|
intent: "support"
|
|
43
41
|
}
|
|
44
42
|
}
|
|
45
|
-
),
|
|
46
|
-
|
|
47
|
-
className: a,
|
|
48
|
-
keepMounted: e,
|
|
49
|
-
ref: t,
|
|
50
|
-
...o
|
|
51
|
-
}) => /* @__PURE__ */ n(
|
|
52
|
-
k.Indicator,
|
|
43
|
+
), w = ({ intent: r, className: e, ref: a, ...t }) => /* @__PURE__ */ o(
|
|
44
|
+
h.Indicator,
|
|
53
45
|
{
|
|
54
|
-
ref:
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
...o
|
|
46
|
+
ref: a,
|
|
47
|
+
className: E({ intent: r, className: e }),
|
|
48
|
+
...t
|
|
58
49
|
}
|
|
59
50
|
);
|
|
60
|
-
|
|
61
|
-
const
|
|
51
|
+
w.displayName = "RadioGroup.RadioIndicator";
|
|
52
|
+
const M = u(
|
|
62
53
|
[
|
|
63
54
|
"flex shrink-0 items-center justify-center",
|
|
64
55
|
"rounded-full",
|
|
@@ -66,7 +57,7 @@ const S = f(
|
|
|
66
57
|
"outline-hidden",
|
|
67
58
|
"hover:ring-4",
|
|
68
59
|
"focus-visible:u-outline",
|
|
69
|
-
"
|
|
60
|
+
"disabled:cursor-not-allowed disabled:border-outline/dim-2 disabled:hover:ring-transparent",
|
|
70
61
|
"u-shadow-border-transition",
|
|
71
62
|
"size-sz-24"
|
|
72
63
|
],
|
|
@@ -75,136 +66,151 @@ const S = f(
|
|
|
75
66
|
/**
|
|
76
67
|
* Color scheme of the radio input.
|
|
77
68
|
*/
|
|
78
|
-
intent:
|
|
79
|
-
main: ["border-outline", "data-checked:border-main", "hover:ring-main-container"],
|
|
80
|
-
support: [
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
69
|
+
intent: I({
|
|
70
|
+
main: ["border-outline", "data-[state=checked]:border-main", "hover:ring-main-container"],
|
|
71
|
+
support: [
|
|
72
|
+
"border-outline",
|
|
73
|
+
"data-[state=checked]:border-support",
|
|
74
|
+
"hover:ring-support-container"
|
|
75
|
+
],
|
|
76
|
+
accent: [
|
|
77
|
+
"border-outline",
|
|
78
|
+
"data-[state=checked]:border-accent",
|
|
79
|
+
"hover:ring-accent-container"
|
|
80
|
+
],
|
|
81
|
+
neutral: [
|
|
82
|
+
"border-outline",
|
|
83
|
+
"data-[state=checked]:border-neutral",
|
|
84
|
+
"hover:ring-neutral-container"
|
|
85
|
+
],
|
|
86
|
+
info: ["border-info", "data-[state=checked]:border-info", "hover:ring-info-container"],
|
|
87
|
+
success: [
|
|
88
|
+
"border-success",
|
|
89
|
+
"data-[state=checked]:border-success",
|
|
90
|
+
"hover:ring-success-container"
|
|
91
|
+
],
|
|
92
|
+
alert: ["border-alert", "data-[state=checked]:border-alert", "hover:ring-alert-container"],
|
|
93
|
+
error: ["border-error", "data-[state=checked]:border-error", "hover:ring-error-container"]
|
|
87
94
|
})
|
|
88
95
|
},
|
|
89
96
|
defaultVariants: {
|
|
90
97
|
intent: "support"
|
|
91
98
|
}
|
|
92
99
|
}
|
|
93
|
-
),
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
children: t,
|
|
98
|
-
inputRef: o,
|
|
99
|
-
hideInput: i = !1,
|
|
100
|
-
ref: d,
|
|
101
|
-
...s
|
|
102
|
-
}) => {
|
|
103
|
-
const { state: c } = x(), l = c ?? r;
|
|
104
|
-
return /* @__PURE__ */ n(
|
|
105
|
-
k.Root,
|
|
100
|
+
), L = ({ intent: r, className: e, ref: a, ...t }) => {
|
|
101
|
+
const { state: n } = y(), i = n ?? r;
|
|
102
|
+
return /* @__PURE__ */ o(
|
|
103
|
+
h.RadioGroupItem,
|
|
106
104
|
{
|
|
107
105
|
"data-spark-component": "radio-input",
|
|
108
|
-
ref:
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
...s,
|
|
113
|
-
children: !e && !i && /* @__PURE__ */ n(I, { intent: l, keepMounted: !0 })
|
|
106
|
+
ref: a,
|
|
107
|
+
className: M({ intent: i, className: e }),
|
|
108
|
+
...t,
|
|
109
|
+
children: /* @__PURE__ */ o(w, { intent: i, forceMount: !0 })
|
|
114
110
|
}
|
|
115
111
|
);
|
|
116
112
|
};
|
|
117
|
-
|
|
118
|
-
const
|
|
113
|
+
L.displayName = "RadioGroup.RadioInput";
|
|
114
|
+
const D = u("grow", {
|
|
115
|
+
variants: {
|
|
116
|
+
disabled: {
|
|
117
|
+
true: ["text-neutral/dim-2", "cursor-not-allowed"],
|
|
118
|
+
false: ["cursor-pointer"]
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
defaultVariants: {
|
|
122
|
+
disabled: !1
|
|
123
|
+
}
|
|
124
|
+
}), $ = ({ disabled: r, ...e }) => /* @__PURE__ */ o(
|
|
125
|
+
q.Root,
|
|
126
|
+
{
|
|
127
|
+
"data-spark-component": "radio-label",
|
|
128
|
+
className: D({ disabled: r }),
|
|
129
|
+
...e
|
|
130
|
+
}
|
|
131
|
+
);
|
|
132
|
+
$.displayName = "RadioGroup.RadioLabel";
|
|
133
|
+
const k = ":radio", R = ({
|
|
119
134
|
className: r,
|
|
120
|
-
children:
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
135
|
+
children: e,
|
|
136
|
+
id: a,
|
|
137
|
+
disabled: t,
|
|
138
|
+
ref: n,
|
|
139
|
+
...i
|
|
124
140
|
}) => {
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
{
|
|
128
|
-
"data-spark-component": "radio-label",
|
|
129
|
-
id: i,
|
|
130
|
-
className: R(
|
|
131
|
-
"grow",
|
|
132
|
-
e || s ? "text-neutral/dim-2 cursor-not-allowed" : "cursor-pointer"
|
|
133
|
-
),
|
|
134
|
-
children: a
|
|
135
|
-
}
|
|
136
|
-
), p = /* @__PURE__ */ n(
|
|
137
|
-
N,
|
|
141
|
+
const s = `${k}-input-${x()}`, d = `${k}-label-${x()}`, { intent: p, disabled: b, reverse: f } = S(), c = e && /* @__PURE__ */ o($, { disabled: t || b, htmlFor: a || s, id: d, children: e }), l = /* @__PURE__ */ o(
|
|
142
|
+
L,
|
|
138
143
|
{
|
|
139
|
-
ref:
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
+
ref: n,
|
|
145
|
+
id: a || s,
|
|
146
|
+
intent: p,
|
|
147
|
+
"aria-labelledby": e ? d : void 0,
|
|
148
|
+
...i,
|
|
149
|
+
disabled: t
|
|
144
150
|
}
|
|
145
|
-
),
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
] }) : /* @__PURE__ */ g(
|
|
149
|
-
|
|
150
|
-
|
|
151
|
+
), m = f ? /* @__PURE__ */ g(G, { children: [
|
|
152
|
+
c,
|
|
153
|
+
l
|
|
154
|
+
] }) : /* @__PURE__ */ g(G, { children: [
|
|
155
|
+
l,
|
|
156
|
+
c
|
|
151
157
|
] });
|
|
152
|
-
return /* @__PURE__ */
|
|
158
|
+
return /* @__PURE__ */ o("span", { className: F("gap-md text-body-1 flex items-start", r), children: m });
|
|
153
159
|
};
|
|
154
|
-
|
|
155
|
-
const
|
|
160
|
+
R.displayName = "RadioGroup.Radio";
|
|
161
|
+
const O = u(["flex"], {
|
|
156
162
|
variants: {
|
|
157
163
|
orientation: {
|
|
158
164
|
vertical: ["flex-col", "gap-lg"],
|
|
159
165
|
horizontal: ["flex-row", "gap-xl"]
|
|
160
166
|
}
|
|
161
167
|
}
|
|
162
|
-
}),
|
|
168
|
+
}), P = ({
|
|
163
169
|
intent: r,
|
|
164
|
-
disabled:
|
|
165
|
-
reverse:
|
|
170
|
+
disabled: e,
|
|
171
|
+
reverse: a,
|
|
166
172
|
children: t
|
|
167
173
|
}) => {
|
|
168
|
-
const
|
|
169
|
-
return /* @__PURE__ */
|
|
170
|
-
},
|
|
174
|
+
const n = C(() => ({ intent: r, disabled: e, reverse: a }), [r, e, a]);
|
|
175
|
+
return /* @__PURE__ */ o(N.Provider, { value: n, children: t });
|
|
176
|
+
}, z = ({
|
|
171
177
|
orientation: r = "vertical",
|
|
178
|
+
loop: e = !0,
|
|
172
179
|
intent: a = "support",
|
|
173
|
-
disabled:
|
|
174
|
-
className:
|
|
175
|
-
required:
|
|
176
|
-
reverse:
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
...c
|
|
180
|
+
disabled: t,
|
|
181
|
+
className: n,
|
|
182
|
+
required: i,
|
|
183
|
+
reverse: s = !1,
|
|
184
|
+
ref: d,
|
|
185
|
+
...p
|
|
180
186
|
}) => {
|
|
181
|
-
const { labelId:
|
|
182
|
-
return /* @__PURE__ */
|
|
183
|
-
|
|
187
|
+
const { labelId: b, isInvalid: f, isRequired: c, description: l, name: m } = y(), v = i !== void 0 ? i : c;
|
|
188
|
+
return /* @__PURE__ */ o(P, { reverse: s, intent: a, disabled: t, children: /* @__PURE__ */ o(
|
|
189
|
+
h.RadioGroup,
|
|
184
190
|
{
|
|
185
191
|
"data-spark-component": "radio-group",
|
|
186
|
-
className:
|
|
187
|
-
name:
|
|
188
|
-
ref:
|
|
189
|
-
disabled:
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
"aria-labelledby":
|
|
194
|
-
"aria-invalid":
|
|
195
|
-
"aria-required":
|
|
196
|
-
"aria-describedby":
|
|
197
|
-
...
|
|
192
|
+
className: O({ orientation: r, className: n }),
|
|
193
|
+
name: m,
|
|
194
|
+
ref: d,
|
|
195
|
+
disabled: t,
|
|
196
|
+
orientation: r,
|
|
197
|
+
loop: e,
|
|
198
|
+
required: v,
|
|
199
|
+
"aria-labelledby": b,
|
|
200
|
+
"aria-invalid": f,
|
|
201
|
+
"aria-required": v,
|
|
202
|
+
"aria-describedby": l,
|
|
203
|
+
...p
|
|
198
204
|
}
|
|
199
205
|
) });
|
|
200
206
|
};
|
|
201
|
-
|
|
202
|
-
const
|
|
203
|
-
Radio:
|
|
207
|
+
z.displayName = "RadioGroup";
|
|
208
|
+
const X = Object.assign(z, {
|
|
209
|
+
Radio: R
|
|
204
210
|
});
|
|
205
|
-
|
|
206
|
-
|
|
211
|
+
X.displayName = "RadioGroup";
|
|
212
|
+
R.displayName = "RadioGroup.Radio";
|
|
207
213
|
export {
|
|
208
|
-
|
|
214
|
+
X as RadioGroup
|
|
209
215
|
};
|
|
210
216
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/radio-group/RadioGroupContext.tsx","../../src/radio-group/RadioIndicator.styles.ts","../../src/radio-group/RadioIndicator.tsx","../../src/radio-group/RadioInput.styles.ts","../../src/radio-group/RadioInput.tsx","../../src/radio-group/Radio.tsx","../../src/radio-group/RadioGroup.styles.ts","../../src/radio-group/RadioGroupProvider.tsx","../../src/radio-group/RadioGroup.tsx","../../src/radio-group/index.ts"],"sourcesContent":["import { createContext, useContext } from 'react'\n\nimport type { RadioGroupProps } from './RadioGroup'\nimport type { RadioInputProps } from './RadioInput'\n\nexport type RadioGroupContextState = Pick<RadioInputProps, 'intent' | 'disabled'> &\n Pick<RadioGroupProps, 'reverse'>\n\nexport const RadioGroupContext = createContext<RadioGroupContextState | null>(null)\n\nexport const useRadioGroup = () => {\n const context = useContext(RadioGroupContext)\n\n if (!context) {\n throw Error('useRadioGroup must be used within a RadioGroup provider')\n }\n\n return context\n}\n","import { makeVariants } from '@spark-ui/internal-utils'\nimport { cva, VariantProps } from 'class-variance-authority'\n\nexport const radioIndicatorStyles = cva(\n [\n 'relative block',\n 'size-3/5',\n 'after:absolute',\n 'after:left-1/2 after:top-1/2 after:-translate-x-1/2 after:-translate-y-1/2',\n 'after:h-0',\n 'after:w-0',\n 'after:block',\n 'after:rounded-[50%]',\n \"after:content-['']\",\n 'after:transition-all',\n 'data-checked:after:size-full',\n ],\n {\n variants: {\n intent: makeVariants<\n 'intent',\n ['main', 'support', 'accent', 'success', 'alert', 'error', 'info', 'neutral']\n >({\n main: ['after:bg-main'],\n support: ['after:bg-support'],\n accent: ['after:bg-accent'],\n neutral: ['after:bg-neutral'],\n success: ['after:bg-success'],\n alert: ['after:bg-alert'],\n error: ['after:bg-error'],\n info: ['after:bg-info'],\n }),\n },\n defaultVariants: {\n intent: 'support',\n },\n }\n)\n\nexport type RadioIndicatorStylesProps = VariantProps<typeof radioIndicatorStyles>\n","import { Radio } from '@base-ui/react/radio'\nimport { Ref } from 'react'\n\nimport { radioIndicatorStyles, RadioIndicatorStylesProps } from './RadioIndicator.styles'\n\nexport interface RadioIndicatorProps extends RadioIndicatorStylesProps {\n className?: string\n /**\n * Whether to keep the indicator mounted in the DOM when the radio is unchecked.\n * Useful when controlling animation with React animation libraries.\n */\n keepMounted?: boolean\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const RadioIndicator = ({\n intent,\n className,\n keepMounted,\n ref,\n ...others\n}: RadioIndicatorProps) => {\n return (\n <Radio.Indicator\n ref={ref}\n keepMounted={keepMounted}\n className={radioIndicatorStyles({ intent, className })}\n {...others}\n />\n )\n}\n\nRadioIndicator.displayName = 'RadioGroup.RadioIndicator'\n","import { makeVariants } from '@spark-ui/internal-utils'\nimport { cva, VariantProps } from 'class-variance-authority'\n\nexport const radioInputVariants = cva(\n [\n 'flex shrink-0 items-center justify-center',\n 'rounded-full',\n 'border-md',\n 'outline-hidden',\n 'hover:ring-4',\n 'focus-visible:u-outline',\n 'data-disabled:cursor-not-allowed data-disabled:border-outline/dim-2 data-disabled:hover:ring-transparent',\n 'u-shadow-border-transition',\n 'size-sz-24',\n ],\n {\n variants: {\n /**\n * Color scheme of the radio input.\n */\n intent: makeVariants<\n 'intent',\n ['main', 'support', 'accent', 'success', 'alert', 'error', 'info', 'neutral']\n >({\n main: ['border-outline', 'data-checked:border-main', 'hover:ring-main-container'],\n support: ['border-outline', 'data-checked:border-support', 'hover:ring-support-container'],\n accent: ['border-outline', 'data-checked:border-accent', 'hover:ring-accent-container'],\n neutral: ['border-outline', 'data-checked:border-neutral', 'hover:ring-neutral-container'],\n info: ['border-info', 'data-checked:border-info', 'hover:ring-info-container'],\n success: ['border-success', 'data-checked:border-success', 'hover:ring-success-container'],\n alert: ['border-alert', 'data-checked:border-alert', 'hover:ring-alert-container'],\n error: ['border-error', 'data-checked:border-error', 'hover:ring-error-container'],\n }),\n },\n defaultVariants: {\n intent: 'support',\n },\n }\n)\n\nexport type RadioInputVariantsProps = VariantProps<typeof radioInputVariants>\n","import { Radio } from '@base-ui/react/radio'\nimport { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { HTMLAttributes, ReactElement, Ref } from 'react'\n\nimport { RadioIndicator } from './RadioIndicator'\nimport { radioInputVariants, RadioInputVariantsProps } from './RadioInput.styles'\n\nexport interface RadioInputProps\n extends RadioInputVariantsProps,\n Omit<HTMLAttributes<HTMLElement>, 'value' | 'onChange'> {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n * Uses Base UI's render prop internally to merge behaviour into the child element.\n */\n asChild?: boolean\n /**\n * The value given as data when submitted with a name.\n */\n value: string\n /**\n * When true, prevents the user from interacting with the radio item.\n */\n disabled?: boolean\n /**\n * When true, indicates that the user must check the radio item before the owning form can be submitted.\n */\n required?: boolean\n /**\n * Ref forwarded to the hidden `<input type=\"radio\">` rendered by Base UI.\n * Useful for programmatic activation (e.g. clicking from an associated label span).\n */\n inputRef?: Ref<HTMLInputElement>\n ref?: Ref<HTMLElement>\n /**\n * When true, the visual radio input (outer ring and inner dot) is visually hidden but remains\n * accessible in the DOM. Useful for custom radio appearances where only the label matters visually.\n * @default false\n */\n hideInput?: boolean\n}\n\nexport const RadioInput = ({\n intent: intentProp,\n className,\n asChild,\n children,\n inputRef,\n hideInput = false,\n ref,\n ...others\n}: RadioInputProps) => {\n const { state } = useFormFieldControl()\n\n const intent = state ?? intentProp\n\n return (\n <Radio.Root\n data-spark-component=\"radio-input\"\n ref={ref}\n inputRef={inputRef}\n render={asChild ? (children as ReactElement) : undefined}\n className={hideInput ? 'sr-only' : radioInputVariants({ intent, className })}\n {...others}\n >\n {!asChild && !hideInput && <RadioIndicator intent={intent} keepMounted />}\n </Radio.Root>\n )\n}\n\nRadioInput.displayName = 'RadioGroup.RadioInput'\n","import { cx } from 'class-variance-authority'\nimport { Ref, useId } from 'react'\n\nimport { Label } from '../label'\nimport { useRadioGroup } from './RadioGroupContext'\nimport { RadioInput, RadioInputProps } from './RadioInput'\n\nexport type RadioProps = RadioInputProps & {\n ref?: Ref<HTMLElement>\n}\n\nconst ID_PREFIX = ':radio'\n\nexport const Radio = ({\n className,\n children,\n disabled: disabledProp,\n ref,\n ...others\n}: RadioProps) => {\n const innerLabelId = `${ID_PREFIX}-label-${useId()}`\n\n const { intent, disabled, reverse } = useRadioGroup()\n\n const isDisabled = disabledProp || disabled\n\n const radioLabel = children && (\n <Label\n data-spark-component=\"radio-label\"\n id={innerLabelId}\n className={cx(\n 'grow',\n isDisabled ? 'text-neutral/dim-2 cursor-not-allowed' : 'cursor-pointer'\n )}\n >\n {children}\n </Label>\n )\n\n const radioInput = (\n <RadioInput\n ref={ref}\n intent={intent}\n aria-labelledby={children ? innerLabelId : undefined}\n {...others}\n disabled={disabledProp}\n />\n )\n\n const content = reverse ? (\n <>\n {radioLabel}\n {radioInput}\n </>\n ) : (\n <>\n {radioInput}\n {radioLabel}\n </>\n )\n\n return <span className={cx('gap-md text-body-1 flex items-start', className)}>{content}</span>\n}\n\nRadio.displayName = 'RadioGroup.Radio'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const radioGroupStyles = cva(['flex'], {\n variants: {\n orientation: {\n vertical: ['flex-col', 'gap-lg'],\n horizontal: ['flex-row', 'gap-xl'],\n },\n },\n})\n\nexport type RadioGroupVariantsProps = VariantProps<typeof radioGroupStyles>\n","import { ReactNode, useMemo } from 'react'\n\nimport type { RadioGroupProps } from './RadioGroup'\nimport { RadioGroupContext } from './RadioGroupContext'\nimport type { RadioInputProps } from './RadioInput'\n\nexport interface RadioGroupProviderProps\n extends Pick<RadioInputProps, 'intent' | 'disabled'>,\n Pick<RadioGroupProps, 'reverse'> {\n children: ReactNode\n}\n\nexport const RadioGroupProvider = ({\n intent,\n disabled,\n reverse,\n children,\n}: RadioGroupProviderProps) => {\n const value = useMemo(() => ({ intent, disabled, reverse }), [intent, disabled, reverse])\n\n return <RadioGroupContext.Provider value={value}>{children}</RadioGroupContext.Provider>\n}\n","import { RadioGroup as BaseUIRadioGroup } from '@base-ui/react/radio-group'\nimport { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { HTMLAttributes, Ref } from 'react'\n\nimport { radioGroupStyles, RadioGroupVariantsProps } from './RadioGroup.styles'\nimport { RadioGroupProvider } from './RadioGroupProvider'\nimport { RadioInputVariantsProps } from './RadioInput.styles'\n\nexport interface RadioGroupProps\n extends RadioGroupVariantsProps,\n Pick<RadioInputVariantsProps, 'intent'>,\n Omit<HTMLAttributes<HTMLDivElement>, 'value' | 'defaultValue' | 'dir' | 'onChange'> {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n */\n asChild?: boolean\n /**\n * The value of the radio item that should be checked when initially rendered. Use when you do not need to control the state of the radio items.\n */\n defaultValue?: string\n /**\n * The controlled value of the radio item to check. Should be used in conjunction with onValueChange.\n */\n value?: string\n /**\n * Event handler called when the value changes.\n */\n onValueChange?: (value: string) => void\n /**\n * When true, prevents the user from interacting with radio items.\n */\n disabled?: boolean\n /**\n * The name of the group. Submitted with its owning form as part of a name/value pair.\n */\n name?: string\n /**\n * When true, indicates that the user must check a radio item before the owning form can be submitted.\n */\n required?: boolean\n /**\n * The orientation of the component.\n */\n orientation?: 'horizontal' | 'vertical'\n /**\n * The reading direction of the radio group.\n */\n dir?: 'ltr' | 'rtl'\n /**\n * When true, the label will be placed on the left side of the Radio\n */\n reverse?: boolean\n ref?: Ref<HTMLDivElement>\n}\n\nexport const RadioGroup = ({\n orientation = 'vertical',\n intent = 'support',\n disabled,\n className,\n required: requiredProp,\n reverse = false,\n onValueChange: onValueChangeProp,\n ref,\n ...others\n}: RadioGroupProps) => {\n const { labelId, isInvalid, isRequired, description, name } = useFormFieldControl()\n const required = requiredProp !== undefined ? requiredProp : isRequired\n\n const handleValueChange = onValueChangeProp\n ? (value: unknown) => onValueChangeProp(value as string)\n : undefined\n\n return (\n <RadioGroupProvider reverse={reverse} intent={intent} disabled={disabled}>\n <BaseUIRadioGroup\n data-spark-component=\"radio-group\"\n className={radioGroupStyles({ orientation, className })}\n name={name}\n ref={ref}\n disabled={disabled}\n required={required}\n onValueChange={handleValueChange}\n aria-orientation={orientation}\n aria-labelledby={labelId}\n aria-invalid={isInvalid}\n aria-required={required}\n aria-describedby={description}\n {...others}\n />\n </RadioGroupProvider>\n )\n}\n\nRadioGroup.displayName = 'RadioGroup'\n","import { Radio } from './Radio'\nimport { RadioGroup as Root } from './RadioGroup'\n\nexport const RadioGroup: typeof Root & {\n Radio: typeof Radio\n} = Object.assign(Root, {\n Radio,\n})\n\nRadioGroup.displayName = 'RadioGroup'\nRadio.displayName = 'RadioGroup.Radio'\n\nexport { type RadioGroupProps } from './RadioGroup'\nexport { type RadioProps } from './Radio'\n"],"names":["RadioGroupContext","createContext","useRadioGroup","context","useContext","radioIndicatorStyles","cva","makeVariants","RadioIndicator","intent","className","keepMounted","ref","others","jsx","Radio","radioInputVariants","RadioInput","intentProp","asChild","children","inputRef","hideInput","state","useFormFieldControl","ID_PREFIX","disabledProp","innerLabelId","useId","disabled","reverse","radioLabel","Label","cx","radioInput","content","jsxs","Fragment","radioGroupStyles","RadioGroupProvider","value","useMemo","RadioGroup","orientation","requiredProp","onValueChangeProp","labelId","isInvalid","isRequired","description","name","required","handleValueChange","BaseUIRadioGroup","Root"],"mappings":";;;;;;;;AAQO,MAAMA,IAAoBC,EAA6C,IAAI,GAErEC,IAAgB,MAAM;AACjC,QAAMC,IAAUC,EAAWJ,CAAiB;AAE5C,MAAI,CAACG;AACH,UAAM,MAAM,yDAAyD;AAGvE,SAAOA;AACT,GCfaE,IAAuBC;AAAA,EAClC;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAAA,EAEF;AAAA,IACE,UAAU;AAAA,MACR,QAAQC,EAGN;AAAA,QACA,MAAM,CAAC,eAAe;AAAA,QACtB,SAAS,CAAC,kBAAkB;AAAA,QAC5B,QAAQ,CAAC,iBAAiB;AAAA,QAC1B,SAAS,CAAC,kBAAkB;AAAA,QAC5B,SAAS,CAAC,kBAAkB;AAAA,QAC5B,OAAO,CAAC,gBAAgB;AAAA,QACxB,OAAO,CAAC,gBAAgB;AAAA,QACxB,MAAM,CAAC,eAAe;AAAA,MAAA,CACvB;AAA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A,gBAAAf;AAAA,IAACuC;AAAAA,IAAA;AAAA,MACC,wBAAqB;AAAA,MACrB,WAAWf,EAAiB,EAAE,aAAAK,GAAa,WAAAjC,GAAW;AAAA,MACtD,MAAAwC;AAAA,MACA,KAAAtC;AAAA,MACA,UAAAiB;AAAA,MACA,UAAAsB;AAAA,MACA,eAAeC;AAAA,MACf,oBAAkBT;AAAA,MAClB,mBAAiBG;AAAA,MACjB,gBAAcC;AAAA,MACd,iBAAeI;AAAA,MACf,oBAAkBF;AAAA,MACjB,GAAGpC;AAAA,IAAA;AAAA,EAAA,GAER;AAEJ;AAEA6B,EAAW,cAAc;AC3FlB,MAAMA,IAET,OAAO,OAAOY,GAAM;AAAA,EACtB,OAAAvC;AACF,CAAC;AAED2B,EAAW,cAAc;AACzB3B,EAAM,cAAc;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/radio-group/RadioGroupContext.tsx","../../src/radio-group/RadioIndicator.styles.ts","../../src/radio-group/RadioIndicator.tsx","../../src/radio-group/RadioInput.styles.ts","../../src/radio-group/RadioInput.tsx","../../src/radio-group/RadioLabel.styles.tsx","../../src/radio-group/RadioLabel.tsx","../../src/radio-group/Radio.tsx","../../src/radio-group/RadioGroup.styles.ts","../../src/radio-group/RadioGroupProvider.tsx","../../src/radio-group/RadioGroup.tsx","../../src/radio-group/index.ts"],"sourcesContent":["import { createContext, useContext } from 'react'\n\nimport type { RadioGroupProps } from './RadioGroup'\nimport type { RadioInputProps } from './RadioInput'\n\nexport type RadioGroupContextState = Pick<RadioInputProps, 'intent' | 'disabled'> &\n Pick<RadioGroupProps, 'reverse'>\n\nexport const RadioGroupContext = createContext<RadioGroupContextState | null>(null)\n\nexport const useRadioGroup = () => {\n const context = useContext(RadioGroupContext)\n\n if (!context) {\n throw Error('useRadioGroup must be used within a RadioGroup provider')\n }\n\n return context\n}\n","import { makeVariants } from '@spark-ui/internal-utils'\nimport { cva, VariantProps } from 'class-variance-authority'\n\nexport const radioIndicatorStyles = cva(\n [\n 'relative block',\n 'size-3/5',\n 'after:absolute',\n 'after:left-1/2 after:top-1/2 after:-translate-x-1/2 after:-translate-y-1/2',\n 'after:h-0',\n 'after:w-0',\n 'after:block',\n 'after:rounded-[50%]',\n \"after:content-['']\",\n 'after:transition-all',\n 'data-[state=checked]:after:size-full',\n ],\n {\n variants: {\n intent: makeVariants<\n 'intent',\n ['main', 'support', 'accent', 'success', 'alert', 'error', 'info', 'neutral']\n >({\n main: ['after:bg-main'],\n support: ['after:bg-support'],\n accent: ['after:bg-accent'],\n neutral: ['after:bg-neutral'],\n success: ['after:bg-success'],\n alert: ['after:bg-alert'],\n error: ['after:bg-error'],\n info: ['after:bg-info'],\n }),\n },\n defaultVariants: {\n intent: 'support',\n },\n }\n)\n\nexport type RadioIndicatorStylesProps = VariantProps<typeof radioIndicatorStyles>\n","import { RadioGroup as RadixRadioGroup } from 'radix-ui'\nimport { Ref } from 'react'\n\nimport { radioIndicatorStyles, RadioIndicatorStylesProps } from './RadioIndicator.styles'\n\nexport interface RadioIndicatorProps extends RadioIndicatorStylesProps {\n className?: string\n /**\n * Change the component to the HTML tag or custom component of the only child.\n */\n asChild?: boolean\n /**\n * Used to force mounting when more control is needed. Useful when controlling animation with React animation libraries.\n */\n forceMount?: true | undefined\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const RadioIndicator = ({ intent, className, ref, ...others }: RadioIndicatorProps) => {\n return (\n <RadixRadioGroup.Indicator\n ref={ref}\n className={radioIndicatorStyles({ intent, className })}\n {...others}\n />\n )\n}\n\nRadioIndicator.displayName = 'RadioGroup.RadioIndicator'\n","import { makeVariants } from '@spark-ui/internal-utils'\nimport { cva, VariantProps } from 'class-variance-authority'\n\nexport const radioInputVariants = cva(\n [\n 'flex shrink-0 items-center justify-center',\n 'rounded-full',\n 'border-md',\n 'outline-hidden',\n 'hover:ring-4',\n 'focus-visible:u-outline',\n 'disabled:cursor-not-allowed disabled:border-outline/dim-2 disabled:hover:ring-transparent',\n 'u-shadow-border-transition',\n 'size-sz-24',\n ],\n {\n variants: {\n /**\n * Color scheme of the radio input.\n */\n intent: makeVariants<\n 'intent',\n ['main', 'support', 'accent', 'success', 'alert', 'error', 'info', 'neutral']\n >({\n main: ['border-outline', 'data-[state=checked]:border-main', 'hover:ring-main-container'],\n support: [\n 'border-outline',\n 'data-[state=checked]:border-support',\n 'hover:ring-support-container',\n ],\n accent: [\n 'border-outline',\n 'data-[state=checked]:border-accent',\n 'hover:ring-accent-container',\n ],\n neutral: [\n 'border-outline',\n 'data-[state=checked]:border-neutral',\n 'hover:ring-neutral-container',\n ],\n info: ['border-info', 'data-[state=checked]:border-info', 'hover:ring-info-container'],\n success: [\n 'border-success',\n 'data-[state=checked]:border-success',\n 'hover:ring-success-container',\n ],\n alert: ['border-alert', 'data-[state=checked]:border-alert', 'hover:ring-alert-container'],\n error: ['border-error', 'data-[state=checked]:border-error', 'hover:ring-error-container'],\n }),\n },\n defaultVariants: {\n intent: 'support',\n },\n }\n)\n\nexport type RadioInputVariantsProps = VariantProps<typeof radioInputVariants>\n","import { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { RadioGroup as RadixRadioGroup } from 'radix-ui'\nimport { ButtonHTMLAttributes, Ref } from 'react'\n\nimport { RadioIndicator } from './RadioIndicator'\nimport { radioInputVariants, RadioInputVariantsProps } from './RadioInput.styles'\n\nexport interface RadioInputProps\n extends RadioInputVariantsProps,\n Omit<ButtonHTMLAttributes<HTMLButtonElement>, 'value' | 'onChange'> {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n */\n asChild?: boolean\n /**\n * The value given as data when submitted with a name.\n */\n value: string\n /**\n * When true, prevents the user from interacting with the radio item.\n */\n disabled?: boolean\n /**\n * When true, indicates that the user must check the radio item before the owning form can be submitted.\n */\n required?: boolean\n ref?: Ref<HTMLButtonElement>\n}\n\nexport const RadioInput = ({ intent: intentProp, className, ref, ...others }: RadioInputProps) => {\n const { state } = useFormFieldControl()\n\n const intent = state ?? intentProp\n\n return (\n <RadixRadioGroup.RadioGroupItem\n data-spark-component=\"radio-input\"\n ref={ref}\n className={radioInputVariants({ intent, className })}\n {...others}\n >\n <RadioIndicator intent={intent} forceMount />\n </RadixRadioGroup.RadioGroupItem>\n )\n}\n\nRadioInput.displayName = 'RadioGroup.RadioInput'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const radioLabelStyles = cva('grow', {\n variants: {\n disabled: {\n true: ['text-neutral/dim-2', 'cursor-not-allowed'],\n false: ['cursor-pointer'],\n },\n },\n defaultVariants: {\n disabled: false,\n },\n})\n\nexport type RadioLabelStylesProps = VariantProps<typeof radioLabelStyles>\n","import { Label } from 'radix-ui'\nimport type { HTMLAttributes, PropsWithChildren } from 'react'\n\nimport { radioLabelStyles, RadioLabelStylesProps } from './RadioLabel.styles'\n\nexport interface RadioLabelProps\n extends RadioLabelStylesProps,\n PropsWithChildren<HTMLAttributes<HTMLLabelElement>> {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n */\n asChild?: boolean\n /**\n * The id of the element the label is associated with.\n */\n htmlFor?: string\n /**\n * When true, prevents the user from interacting with the radio item.\n */\n disabled?: boolean\n}\n\nexport const RadioLabel = ({ disabled, ...others }: RadioLabelProps) => {\n return (\n <Label.Root\n data-spark-component=\"radio-label\"\n className={radioLabelStyles({ disabled })}\n {...others}\n />\n )\n}\n\nRadioLabel.displayName = 'RadioGroup.RadioLabel'\n","import { cx } from 'class-variance-authority'\nimport { Ref, useId } from 'react'\n\nimport { useRadioGroup } from './RadioGroupContext'\nimport { RadioInput, RadioInputProps } from './RadioInput'\nimport { RadioLabel } from './RadioLabel'\n\nexport type RadioProps = RadioInputProps & {\n ref?: Ref<HTMLButtonElement>\n}\n\nconst ID_PREFIX = ':radio'\n\nexport const Radio = ({\n className,\n children,\n id,\n disabled: disabledProp,\n ref,\n ...others\n}: RadioProps) => {\n const innerId = `${ID_PREFIX}-input-${useId()}`\n const innerLabelId = `${ID_PREFIX}-label-${useId()}`\n\n const { intent, disabled, reverse } = useRadioGroup()\n\n const radioLabel = children && (\n <RadioLabel disabled={disabledProp || disabled} htmlFor={id || innerId} id={innerLabelId}>\n {children}\n </RadioLabel>\n )\n\n const radioInput = (\n <RadioInput\n ref={ref}\n id={id || innerId}\n intent={intent}\n aria-labelledby={children ? innerLabelId : undefined}\n {...others}\n disabled={disabledProp}\n />\n )\n\n const content = reverse ? (\n <>\n {radioLabel}\n {radioInput}\n </>\n ) : (\n <>\n {radioInput}\n {radioLabel}\n </>\n )\n\n return <span className={cx('gap-md text-body-1 flex items-start', className)}>{content}</span>\n}\n\nRadio.displayName = 'RadioGroup.Radio'\n","import { cva, VariantProps } from 'class-variance-authority'\n\nexport const radioGroupStyles = cva(['flex'], {\n variants: {\n orientation: {\n vertical: ['flex-col', 'gap-lg'],\n horizontal: ['flex-row', 'gap-xl'],\n },\n },\n})\n\nexport type RadioGroupVariantsProps = VariantProps<typeof radioGroupStyles>\n","import { ReactNode, useMemo } from 'react'\n\nimport type { RadioGroupProps } from './RadioGroup'\nimport { RadioGroupContext } from './RadioGroupContext'\nimport type { RadioInputProps } from './RadioInput'\n\nexport interface RadioGroupProviderProps\n extends Pick<RadioInputProps, 'intent' | 'disabled'>,\n Pick<RadioGroupProps, 'reverse'> {\n children: ReactNode\n}\n\nexport const RadioGroupProvider = ({\n intent,\n disabled,\n reverse,\n children,\n}: RadioGroupProviderProps) => {\n const value = useMemo(() => ({ intent, disabled, reverse }), [intent, disabled, reverse])\n\n return <RadioGroupContext.Provider value={value}>{children}</RadioGroupContext.Provider>\n}\n","import { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { RadioGroup as RadixRadioGroup } from 'radix-ui'\nimport { HTMLAttributes, Ref } from 'react'\n\nimport { radioGroupStyles, RadioGroupVariantsProps } from './RadioGroup.styles'\nimport { RadioGroupProvider } from './RadioGroupProvider'\nimport { RadioInputVariantsProps } from './RadioInput.styles'\n\nexport interface RadioGroupProps\n extends RadioGroupVariantsProps,\n Pick<RadioInputVariantsProps, 'intent'>,\n Omit<HTMLAttributes<HTMLDivElement>, 'value' | 'defaultValue' | 'dir' | 'onChange'> {\n /**\n * Change the component to the HTML tag or custom component of the only child.\n */\n asChild?: boolean\n /**\n * The value of the radio item that should be checked when initially rendered. Use when you do not need to control the state of the radio items.\n */\n defaultValue?: string\n /**\n * The controlled value of the radio item to check. Should be used in conjunction with onValueChange.\n */\n value?: string\n /**\n * Event handler called when the value changes.\n */\n onValueChange?: (value: string) => void\n /**\n * When true, prevents the user from interacting with radio items.\n */\n disabled?: boolean\n /**\n * The name of the group. Submitted with its owning form as part of a name/value pair.\n */\n name?: string\n /**\n * When true, indicates that the user must check a radio item before the owning form can be submitted.\n */\n required?: boolean\n /**\n * The orientation of the component.\n */\n orientation?: 'horizontal' | 'vertical'\n /**\n * The reading direction of the radio group.\n */\n dir?: 'ltr' | 'rtl'\n /**\n * When true, keyboard navigation will loop from last item to first, and vice versa.\n */\n loop?: boolean\n /**\n * When true, the label will be placed on the left side of the Radio\n */\n reverse?: boolean\n ref?: Ref<HTMLDivElement>\n}\n\nexport const RadioGroup = ({\n orientation = 'vertical',\n loop = true,\n intent = 'support',\n disabled,\n className,\n required: requiredProp,\n reverse = false,\n ref,\n ...others\n}: RadioGroupProps) => {\n const { labelId, isInvalid, isRequired, description, name } = useFormFieldControl()\n const required = requiredProp !== undefined ? requiredProp : isRequired\n\n return (\n <RadioGroupProvider reverse={reverse} intent={intent} disabled={disabled}>\n <RadixRadioGroup.RadioGroup\n data-spark-component=\"radio-group\"\n className={radioGroupStyles({ orientation, className })}\n name={name}\n ref={ref}\n disabled={disabled}\n orientation={orientation}\n loop={loop}\n required={required}\n aria-labelledby={labelId}\n aria-invalid={isInvalid}\n aria-required={required}\n aria-describedby={description}\n {...others}\n />\n </RadioGroupProvider>\n )\n}\n\nRadioGroup.displayName = 'RadioGroup'\n","import { Radio } from './Radio'\nimport { RadioGroup as Root } from './RadioGroup'\n\nexport const RadioGroup: typeof Root & {\n Radio: typeof Radio\n} = Object.assign(Root, {\n Radio,\n})\n\nRadioGroup.displayName = 'RadioGroup'\nRadio.displayName = 'RadioGroup.Radio'\n\nexport { type RadioGroupProps } from './RadioGroup'\nexport { type RadioProps } from './Radio'\n"],"names":["RadioGroupContext","createContext","useRadioGroup","context","useContext","radioIndicatorStyles","cva","makeVariants","RadioIndicator","intent","className","ref","others","jsx","RadixRadioGroup","radioInputVariants","RadioInput","intentProp","state","useFormFieldControl","radioLabelStyles","RadioLabel","disabled","Label","ID_PREFIX","Radio","children","id","disabledProp","innerId","useId","innerLabelId","reverse","radioLabel","radioInput","content","jsxs","Fragment","cx","radioGroupStyles","RadioGroupProvider","value","useMemo","RadioGroup","orientation","loop","requiredProp","labelId","isInvalid","isRequired","description","name","required","Root"],"mappings":";;;;;;AAQO,MAAMA,IAAoBC,EAA6C,IAAI,GAErEC,IAAgB,MAAM;AACjC,QAAMC,IAAUC,EAAWJ,CAAiB;AAE5C,MAAI,CAACG;AACH,UAAM,MAAM,yDAAyD;AAGvE,SAAOA;AACT,GCfaE,IAAuBC;AAAA,EAClC;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAAA,EAEF;AAAA,IACE,UAAU;AAAA,MACR,QAAQC,EAGN;AAAA,QACA,MAAM,CAAC,eAAe;AAAA,QACtB,SAAS,CAAC,kBAAkB;AAAA,QAC5B,QAAQ,CAAC,iBAAiB;AAAA,QAC1B,SAAS,CAAC,kBAAkB;AAAA,QAC5B,SAAS,CAAC,kBAAkB;AAAA,QAC5B,OAAO,CAAC,gBAAgB;AAAA,QACxB,OAAO,CAAC,gBAAgB;AAAA,QACxB,MAAM,CAAC,eAAe;AAAA,MAAA,CACvB;AAAA,IAAA;AAAA,IAEH,iBAAiB;AAAA,MACf,QAAQ;AAAA,IAAA;AAAA,EACV;AAEJ,GCnBaC,IAAiB,CAAC,EAAE,QAAAC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ACE,gBAAApC,EAAC2B,GAAA,EAAmB,SAAAR,GAAkB,QAAAvB,GAAgB,UAAAa,GACpD,UAAA,gBAAAT;AAAA,IAACC,EAAgB;AAAA,IAAhB;AAAA,MACC,wBAAqB;AAAA,MACrB,WAAWyB,EAAiB,EAAE,aAAAK,GAAa,WAAAlC,GAAW;AAAA,MACtD,MAAAyC;AAAA,MACA,KAAAxC;AAAA,MACA,UAAAW;AAAA,MACA,aAAAsB;AAAA,MACA,MAAAC;AAAA,MACA,UAAAO;AAAA,MACA,mBAAiBL;AAAA,MACjB,gBAAcC;AAAA,MACd,iBAAeI;AAAA,MACf,oBAAkBF;AAAA,MACjB,GAAGtC;AAAA,IAAA;AAAA,EAAA,GAER;AAEJ;AAEA+B,EAAW,cAAc;AC3FlB,MAAMA,IAET,OAAO,OAAOU,GAAM;AAAA,EACtB,OAAA5B;AACF,CAAC;AAEDkB,EAAW,cAAc;AACzBlB,EAAM,cAAc;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("react/jsx-runtime"),z=require("@base-ui/react/radio-group"),N=require("@spark-ui/components/form-field"),E=require("@spark-ui/hooks/use-merge-refs"),o=require("react"),S=require("class-variance-authority"),L=require("@base-ui/react/radio"),F=S.cva(["default:self-start","group inline-grid grid-flow-col auto-cols-fr","relative items-stretch min-w-max","rounded-xl p-sm","bg-surface border-sm border-outline"]),M=S.cva(["relative z-raised min-h-sz-44 focus-visible:outline-none","flex flex-none items-center justify-center gap-md","default:px-lg default:py-md","rounded-[20px]","cursor-pointer select-none","font-medium","transition-colors duration-150","outline-none","focus-visible:u-outline","data-disabled:cursor-not-allowed data-disabled:opacity-dim-3","data-checked:text-on-support-container","data-checked:[&>[data-spark-segmented-control-text]]:[text-shadow:0.35px_0_currentColor,-0.35px_0_currentColor]"]),O=S.cva(["absolute z-base","rounded-[20px]","bg-support-container border-md border-support","group-has-focus-visible:border-focus","transition-[left,top,width,height] duration-200 ease-in-out","pointer-events-none"]),I=o.createContext({}),_=()=>{const e=o.useContext(I);if(!e)throw Error("useSegmentedControlContext must be used within a SegmentedControlContext Provider");return e},P=e=>{let n=null;return o.Children.forEach(e,r=>{n===null&&o.isValidElement(r)&&typeof r.props.value=="string"&&(n=r.props.value)}),n},V=({value:e,defaultValue:n,onValueChange:r,className:c,children:i,ref:s,...u})=>{const t=o.useRef(null),g=E.useMergeRefs(t,s),f=P(i),m=e!==void 0,[a,h]=o.useState(()=>n??f),p=m?e??null:a,l=k=>{const R=k;m||h(R),r?.(R)},{labelId:C,description:d,isRequired:b,isInvalid:x,name:j}=N.useFormFieldControl();return v.jsx(I.Provider,{value:{checkedValue:p,containerRef:t},children:v.jsx(z.RadioGroup,{ref:g,value:m?e:void 0,defaultValue:m?void 0:n??f??void 0,onValueChange:l,"data-spark-component":"segmented-control",className:F({className:c}),"aria-labelledby":C,"aria-describedby":d,"aria-required":b||void 0,"aria-invalid":x||void 0,name:j,...u,children:i})})};V.displayName="SegmentedControl";const y=({className:e,ref:n,...r})=>{const{checkedValue:c,containerRef:i}=_(),[s,u]=o.useState(null),t=o.useMemo(()=>c?`[data-value="${CSS.escape(c)}"]`:null,[c]);if(o.useEffect(()=>{const f=i.current;if(!f)return;const m=t?f.querySelector(t):null,a=()=>{const p=i.current;if(!p||!t){u(null);return}const l=p.querySelector(t);if(!l){u(null);return}const C=p.getBoundingClientRect(),d=l.getBoundingClientRect(),b=l.offsetWidth>0?d.width/l.offsetWidth:1,x=l.offsetHeight>0?d.height/l.offsetHeight:1;u({left:(d.left-C.left)/b-p.clientLeft,top:(d.top-C.top)/x-p.clientTop,width:d.width/b,height:d.height/x})};a();const h=typeof ResizeObserver<"u"?new ResizeObserver(()=>{a()}):null;return h?.observe(f),m&&h?.observe(m),window.addEventListener("resize",a,{passive:!0}),window.visualViewport?.addEventListener("resize",a,{passive:!0}),()=>{h?.disconnect(),window.removeEventListener("resize",a),window.visualViewport?.removeEventListener("resize",a)}},[i,t]),!s)return null;const g={left:s.left,top:s.top,width:s.width,height:s.height};return v.jsx("span",{ref:n,"data-spark-component":"segmented-control-indicator","aria-hidden":!0,className:O({className:e}),style:g,...r})};y.displayName="SegmentedControl.Indicator";const w=({value:e,disabled:n=!1,children:r,className:c,ref:i,...s})=>{const u=o.Children.toArray(r).map((t,g)=>typeof t=="string"||typeof t=="number"?v.jsx("span",{"data-spark-segmented-control-text":!0,children:t},`text-${g}`):t);return v.jsx(L.Radio.Root,{ref:i,"data-spark-component":"segmented-control-item","data-value":e,value:e,disabled:n,className:M({className:c}),...s,children:u})};w.displayName="SegmentedControl.Item";const q=Object.assign(V,{Item:w,Indicator:y});q.displayName="SegmentedControl";w.displayName="SegmentedControl.Item";y.displayName="SegmentedControl.Indicator";exports.SegmentedControl=q;
|
|
2
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/segmented-control/SegmentedControl.styles.ts","../../src/segmented-control/SegmentedControlContext.tsx","../../src/segmented-control/SegmentedControl.tsx","../../src/segmented-control/SegmentedControlIndicator.tsx","../../src/segmented-control/SegmentedControlItem.tsx","../../src/segmented-control/index.ts"],"sourcesContent":["import { cva, VariantProps } from 'class-variance-authority'\n\nexport const rootStyles = cva([\n 'default:self-start',\n 'group inline-grid grid-flow-col auto-cols-fr',\n 'relative items-stretch min-w-max',\n 'rounded-xl p-sm',\n 'bg-surface border-sm border-outline',\n])\n\nexport const itemStyles = cva([\n 'relative z-raised min-h-sz-44 focus-visible:outline-none',\n 'flex flex-none items-center justify-center flex-col',\n 'default:px-lg default:py-md',\n 'rounded-[20px]',\n 'cursor-pointer select-none',\n 'font-medium',\n 'transition-colors duration-150',\n 'outline-none',\n 'focus-visible:u-outline',\n 'data-disabled:cursor-not-allowed data-disabled:opacity-dim-3',\n 'data-checked:text-on-support-container',\n 'data-checked:font-bold',\n])\n\nexport const indicatorStyles = cva([\n 'absolute z-base',\n 'rounded-[20px]',\n 'bg-support-container border-md border-support',\n 'group-has-focus-visible:border-focus',\n 'transition-[left,top,width,height] duration-200 ease-in-out',\n 'pointer-events-none',\n])\n\nexport type SegmentedControlStylesProps = VariantProps<typeof itemStyles>\n","import { createContext, RefObject, useContext } from 'react'\n\nexport interface SegmentedControlContextInterface {\n checkedValue: string | null\n containerRef: RefObject<HTMLDivElement | null>\n}\n\nexport const SegmentedControlContext = createContext<SegmentedControlContextInterface>(\n {} as SegmentedControlContextInterface\n)\n\nexport const useSegmentedControlContext = () => {\n const context = useContext(SegmentedControlContext)\n\n if (!context) {\n throw Error('useSegmentedControlContext must be used within a SegmentedControlContext Provider')\n }\n\n return context\n}\n","import { RadioGroup } from '@base-ui/react/radio-group'\nimport { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { useMergeRefs } from '@spark-ui/hooks/use-merge-refs'\nimport { Children, type ComponentProps, isValidElement, Ref, useRef, useState } from 'react'\n\nimport type { SegmentedControlStylesProps } from './SegmentedControl.styles'\nimport { rootStyles } from './SegmentedControl.styles'\nimport { SegmentedControlContext } from './SegmentedControlContext'\n\nexport interface SegmentedControlProps\n extends Omit<ComponentProps<typeof RadioGroup>, 'value' | 'defaultValue' | 'onValueChange'>,\n SegmentedControlStylesProps {\n /**\n * The controlled selected value.\n */\n value?: string\n /**\n * The uncontrolled default selected value.\n */\n defaultValue?: string\n /**\n * Callback fired when the selected value changes.\n */\n onValueChange?: (value: string) => void\n ref?: Ref<HTMLDivElement>\n}\n\nconst getFirstItemValue = (children: React.ReactNode): string | null => {\n let firstValue: string | null = null\n\n Children.forEach(children, child => {\n if (firstValue !== null) return\n if (isValidElement(child) && typeof (child.props as { value?: string }).value === 'string') {\n firstValue = (child.props as { value: string }).value\n }\n })\n\n return firstValue\n}\n\nexport const SegmentedControl = ({\n value,\n defaultValue,\n onValueChange,\n className,\n children,\n ref,\n ...rest\n}: SegmentedControlProps) => {\n const containerRef = useRef<HTMLDivElement | null>(null)\n const mergedRef = useMergeRefs(containerRef, ref)\n\n const firstValue = getFirstItemValue(children)\n\n const isControlled = value !== undefined\n const [internalValue, setInternalValue] = useState<string | null>(\n () => defaultValue ?? firstValue\n )\n const checkedValue = isControlled ? (value ?? null) : internalValue\n\n const handleValueChange = (newValue: unknown) => {\n const next = newValue as string\n\n if (!isControlled) {\n setInternalValue(next)\n }\n\n onValueChange?.(next)\n }\n\n const { labelId, description, isRequired, isInvalid, name } = useFormFieldControl()\n\n return (\n <SegmentedControlContext.Provider\n value={{\n checkedValue,\n containerRef,\n }}\n >\n <RadioGroup\n ref={mergedRef}\n value={isControlled ? value : undefined}\n defaultValue={!isControlled ? (defaultValue ?? firstValue ?? undefined) : undefined}\n onValueChange={handleValueChange}\n data-spark-component=\"segmented-control\"\n className={rootStyles({ className })}\n aria-labelledby={labelId}\n aria-describedby={description}\n aria-required={isRequired || undefined}\n aria-invalid={isInvalid || undefined}\n name={name}\n {...rest}\n >\n {children}\n </RadioGroup>\n </SegmentedControlContext.Provider>\n )\n}\n\nSegmentedControl.displayName = 'SegmentedControl'\n","import { type ComponentProps, type CSSProperties, Ref, useEffect, useState } from 'react'\n\nimport { indicatorStyles } from './SegmentedControl.styles'\nimport { useSegmentedControlContext } from './SegmentedControlContext'\n\ninterface IndicatorRect {\n left: number\n top: number\n width: number\n height: number\n}\n\nexport interface SegmentedControlIndicatorProps extends ComponentProps<'span'> {\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const SegmentedControlIndicator = ({\n className,\n ref,\n ...rest\n}: SegmentedControlIndicatorProps) => {\n const { checkedValue, containerRef } = useSegmentedControlContext()\n const [rect, setRect] = useState<IndicatorRect | null>(null)\n\n useEffect(() => {\n const container = containerRef.current\n\n if (!container) {\n return\n }\n\n const selectedItem = checkedValue\n ? container.querySelector<HTMLElement>(`[data-value=\"${checkedValue}\"]`)\n : null\n\n if (!selectedItem) {\n setRect(null)\n\n return\n }\n\n const containerRect = container.getBoundingClientRect()\n const itemRect = selectedItem.getBoundingClientRect()\n\n const rootBorderWidth = 1\n\n setRect({\n left: itemRect.left - containerRect.left - rootBorderWidth,\n top: itemRect.top - containerRect.top - rootBorderWidth,\n width: itemRect.width,\n height: itemRect.height,\n })\n }, [checkedValue, containerRef])\n\n if (!rect) return null\n\n const style: CSSProperties = {\n left: rect.left,\n top: rect.top,\n width: rect.width,\n height: rect.height,\n }\n\n return (\n <span\n ref={ref}\n data-spark-component=\"segmented-control-indicator\"\n aria-hidden\n className={indicatorStyles({ className })}\n style={style}\n {...rest}\n />\n )\n}\n\nSegmentedControlIndicator.displayName = 'SegmentedControl.Indicator'\n","import { Radio } from '@base-ui/react/radio'\nimport { type ComponentProps, Ref } from 'react'\n\nimport { itemStyles } from './SegmentedControl.styles'\n\nexport interface SegmentedControlItemProps\n extends Omit<ComponentProps<typeof Radio.Root>, 'value'> {\n /**\n * A unique value that identifies this item within the segmented control.\n */\n value: string\n /**\n * When true, prevents the user from interacting with this item.\n * @default false\n */\n disabled?: boolean\n ref?: Ref<HTMLElement>\n}\n\nexport const SegmentedControlItem = ({\n value,\n disabled = false,\n children,\n className,\n ref,\n ...rest\n}: SegmentedControlItemProps) => {\n return (\n <Radio.Root\n ref={ref}\n data-spark-component=\"segmented-control-item\"\n data-value={value}\n value={value}\n disabled={disabled}\n className={itemStyles({ className })}\n {...rest}\n >\n {children}\n <span\n aria-hidden=\"true\"\n className=\"bg-success pointer-events-none h-0 overflow-hidden font-bold content-[attr(data-text)/'']\"\n >\n {children}\n </span>\n </Radio.Root>\n )\n}\n\nSegmentedControlItem.displayName = 'SegmentedControl.Item'\n","import { SegmentedControl as Root } from './SegmentedControl'\nimport { SegmentedControlIndicator as Indicator } from './SegmentedControlIndicator'\nimport { SegmentedControlItem as Item } from './SegmentedControlItem'\n\nexport const SegmentedControl: typeof Root & {\n Item: typeof Item\n Indicator: typeof Indicator\n} = Object.assign(Root, {\n Item,\n Indicator,\n})\n\nSegmentedControl.displayName = 'SegmentedControl'\nItem.displayName = 'SegmentedControl.Item'\nIndicator.displayName = 'SegmentedControl.Indicator'\n\nexport type { SegmentedControlProps } from './SegmentedControl'\nexport type { SegmentedControlItemProps } from './SegmentedControlItem'\nexport type { SegmentedControlIndicatorProps } from './SegmentedControlIndicator'\n"],"names":["rootStyles","cva","itemStyles","indicatorStyles","SegmentedControlContext","createContext","useSegmentedControlContext","context","useContext","getFirstItemValue","children","firstValue","Children","child","isValidElement","SegmentedControl","value","defaultValue","onValueChange","className","ref","rest","containerRef","useRef","mergedRef","useMergeRefs","isControlled","internalValue","setInternalValue","useState","checkedValue","handleValueChange","newValue","next","labelId","description","isRequired","isInvalid","name","useFormFieldControl","jsx","RadioGroup","SegmentedControlIndicator","rect","setRect","useEffect","container","selectedItem","containerRect","itemRect","rootBorderWidth","style","SegmentedControlItem","disabled","jsxs","Radio","Root","Item","Indicator"],"mappings":"iVAEaA,EAAaC,EAAAA,IAAI,CAC5B,qBACA,+CACA,mCACA,kBACA,qCACF,CAAC,EAEYC,EAAaD,EAAAA,IAAI,CAC5B,2DACA,sDACA,8BACA,iBACA,6BACA,cACA,iCACA,eACA,0BACA,+DACA,yCACA,wBACF,CAAC,EAEYE,EAAkBF,EAAAA,IAAI,CACjC,kBACA,iBACA,gDACA,uCACA,8DACA,qBACF,CAAC,ECzBYG,EAA0BC,EAAAA,cACrC,CAAA,CACF,EAEaC,EAA6B,IAAM,CAC9C,MAAMC,EAAUC,EAAAA,WAAWJ,CAAuB,EAElD,GAAI,CAACG,EACH,MAAM,MAAM,mFAAmF,EAGjG,OAAOA,CACT,ECQME,EAAqBC,GAA6C,CACtE,IAAIC,EAA4B,KAEhCC,OAAAA,EAAAA,SAAS,QAAQF,EAAUG,GAAS,CAC9BF,IAAe,MACfG,EAAAA,eAAeD,CAAK,GAAK,OAAQA,EAAM,MAA6B,OAAU,WAChFF,EAAcE,EAAM,MAA4B,MAEpD,CAAC,EAEMF,CACT,EAEaI,EAAmB,C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3C,EAAiB,YAAc,mBAC/B0C,EAAK,YAAc,wBACnBC,EAAU,YAAc"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../src/segmented-control/SegmentedControl.styles.ts","../../src/segmented-control/SegmentedControlContext.tsx","../../src/segmented-control/SegmentedControl.tsx","../../src/segmented-control/SegmentedControlIndicator.tsx","../../src/segmented-control/SegmentedControlItem.tsx","../../src/segmented-control/index.ts"],"sourcesContent":["import { cva, VariantProps } from 'class-variance-authority'\n\nexport const rootStyles = cva([\n 'default:self-start',\n 'group inline-grid grid-flow-col auto-cols-fr',\n 'relative items-stretch min-w-max',\n 'rounded-xl p-sm',\n 'bg-surface border-sm border-outline',\n])\n\nexport const itemStyles = cva([\n 'relative z-raised min-h-sz-44 focus-visible:outline-none',\n 'flex flex-none items-center justify-center gap-md',\n 'default:px-lg default:py-md',\n 'rounded-[20px]',\n 'cursor-pointer select-none',\n 'font-medium',\n 'transition-colors duration-150',\n 'outline-none',\n 'focus-visible:u-outline',\n 'data-disabled:cursor-not-allowed data-disabled:opacity-dim-3',\n 'data-checked:text-on-support-container',\n // Avoid layout shift: simulate \"bold\" without changing font metrics.\n // Apply only to wrapped text nodes (not arbitrary nested JSX like Tag).\n 'data-checked:[&>[data-spark-segmented-control-text]]:[text-shadow:0.35px_0_currentColor,-0.35px_0_currentColor]',\n])\n\nexport const indicatorStyles = cva([\n 'absolute z-base',\n 'rounded-[20px]',\n 'bg-support-container border-md border-support',\n 'group-has-focus-visible:border-focus',\n 'transition-[left,top,width,height] duration-200 ease-in-out',\n 'pointer-events-none',\n])\n\nexport type SegmentedControlStylesProps = VariantProps<typeof itemStyles>\n","import { createContext, RefObject, useContext } from 'react'\n\nexport interface SegmentedControlContextInterface {\n checkedValue: string | null\n containerRef: RefObject<HTMLDivElement | null>\n}\n\nexport const SegmentedControlContext = createContext<SegmentedControlContextInterface>(\n {} as SegmentedControlContextInterface\n)\n\nexport const useSegmentedControlContext = () => {\n const context = useContext(SegmentedControlContext)\n\n if (!context) {\n throw Error('useSegmentedControlContext must be used within a SegmentedControlContext Provider')\n }\n\n return context\n}\n","import { RadioGroup } from '@base-ui/react/radio-group'\nimport { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { useMergeRefs } from '@spark-ui/hooks/use-merge-refs'\nimport { Children, type ComponentProps, isValidElement, Ref, useRef, useState } from 'react'\n\nimport type { SegmentedControlStylesProps } from './SegmentedControl.styles'\nimport { rootStyles } from './SegmentedControl.styles'\nimport { SegmentedControlContext } from './SegmentedControlContext'\n\nexport interface SegmentedControlProps\n extends Omit<ComponentProps<typeof RadioGroup>, 'value' | 'defaultValue' | 'onValueChange'>,\n SegmentedControlStylesProps {\n /**\n * The controlled selected value.\n */\n value?: string\n /**\n * The uncontrolled default selected value.\n */\n defaultValue?: string\n /**\n * Callback fired when the selected value changes.\n */\n onValueChange?: (value: string) => void\n ref?: Ref<HTMLDivElement>\n}\n\nconst getFirstItemValue = (children: React.ReactNode): string | null => {\n let firstValue: string | null = null\n\n Children.forEach(children, child => {\n if (firstValue !== null) return\n if (isValidElement(child) && typeof (child.props as { value?: string }).value === 'string') {\n firstValue = (child.props as { value: string }).value\n }\n })\n\n return firstValue\n}\n\nexport const SegmentedControl = ({\n value,\n defaultValue,\n onValueChange,\n className,\n children,\n ref,\n ...rest\n}: SegmentedControlProps) => {\n const containerRef = useRef<HTMLDivElement | null>(null)\n const mergedRef = useMergeRefs(containerRef, ref)\n\n const firstValue = getFirstItemValue(children)\n\n const isControlled = value !== undefined\n const [internalValue, setInternalValue] = useState<string | null>(\n () => defaultValue ?? firstValue\n )\n const checkedValue = isControlled ? (value ?? null) : internalValue\n\n const handleValueChange = (newValue: unknown) => {\n const next = newValue as string\n\n if (!isControlled) {\n setInternalValue(next)\n }\n\n onValueChange?.(next)\n }\n\n const { labelId, description, isRequired, isInvalid, name } = useFormFieldControl()\n\n return (\n <SegmentedControlContext.Provider\n value={{\n checkedValue,\n containerRef,\n }}\n >\n <RadioGroup\n ref={mergedRef}\n value={isControlled ? value : undefined}\n defaultValue={!isControlled ? (defaultValue ?? firstValue ?? undefined) : undefined}\n onValueChange={handleValueChange}\n data-spark-component=\"segmented-control\"\n className={rootStyles({ className })}\n aria-labelledby={labelId}\n aria-describedby={description}\n aria-required={isRequired || undefined}\n aria-invalid={isInvalid || undefined}\n name={name}\n {...rest}\n >\n {children}\n </RadioGroup>\n </SegmentedControlContext.Provider>\n )\n}\n\nSegmentedControl.displayName = 'SegmentedControl'\n","import { type ComponentProps, type CSSProperties, Ref, useEffect, useMemo, useState } from 'react'\n\nimport { indicatorStyles } from './SegmentedControl.styles'\nimport { useSegmentedControlContext } from './SegmentedControlContext'\n\ninterface IndicatorRect {\n left: number\n top: number\n width: number\n height: number\n}\n\nexport interface SegmentedControlIndicatorProps extends ComponentProps<'span'> {\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const SegmentedControlIndicator = ({\n className,\n ref,\n ...rest\n}: SegmentedControlIndicatorProps) => {\n const { checkedValue, containerRef } = useSegmentedControlContext()\n const [rect, setRect] = useState<IndicatorRect | null>(null)\n\n const selector = useMemo(\n () => (checkedValue ? `[data-value=\"${CSS.escape(checkedValue)}\"]` : null),\n [checkedValue]\n )\n\n useEffect(() => {\n const container = containerRef.current\n\n if (!container) {\n return\n }\n\n const selectedItem = selector ? container.querySelector<HTMLElement>(selector) : null\n\n const update = () => {\n const currentContainer = containerRef.current\n if (!currentContainer || !selector) {\n setRect(null)\n\n return\n }\n\n const currentSelected = currentContainer.querySelector<HTMLElement>(selector)\n if (!currentSelected) {\n setRect(null)\n\n return\n }\n\n const containerRect = currentContainer.getBoundingClientRect()\n const itemRect = currentSelected.getBoundingClientRect()\n\n // Storybook canvas \"zoom\" can be implemented via `transform: scale()`.\n // In that case, `getBoundingClientRect()` returns *scaled* values, but CSS positioning/sizing\n // expects unscaled layout pixels. We infer the scale factor from offset sizes and normalize.\n const scaleX =\n currentSelected.offsetWidth > 0 ? itemRect.width / currentSelected.offsetWidth : 1\n const scaleY =\n currentSelected.offsetHeight > 0 ? itemRect.height / currentSelected.offsetHeight : 1\n\n // `getBoundingClientRect()` is border-box; absolute positioning is relative to the padding box.\n setRect({\n left: (itemRect.left - containerRect.left) / scaleX - currentContainer.clientLeft,\n top: (itemRect.top - containerRect.top) / scaleY - currentContainer.clientTop,\n width: itemRect.width / scaleX,\n height: itemRect.height / scaleY,\n })\n }\n\n update()\n\n const ro =\n typeof ResizeObserver !== 'undefined'\n ? new ResizeObserver(() => {\n update()\n })\n : null\n\n ro?.observe(container)\n if (selectedItem) ro?.observe(selectedItem)\n\n window.addEventListener('resize', update, { passive: true })\n window.visualViewport?.addEventListener('resize', update, { passive: true })\n\n return () => {\n ro?.disconnect()\n window.removeEventListener('resize', update)\n window.visualViewport?.removeEventListener('resize', update)\n }\n }, [containerRef, selector])\n\n if (!rect) return null\n\n const style: CSSProperties = {\n left: rect.left,\n top: rect.top,\n width: rect.width,\n height: rect.height,\n }\n\n return (\n <span\n ref={ref}\n data-spark-component=\"segmented-control-indicator\"\n aria-hidden\n className={indicatorStyles({ className })}\n style={style}\n {...rest}\n />\n )\n}\n\nSegmentedControlIndicator.displayName = 'SegmentedControl.Indicator'\n","import { Radio } from '@base-ui/react/radio'\nimport { Children, type ComponentProps, Ref } from 'react'\n\nimport { itemStyles } from './SegmentedControl.styles'\n\nexport interface SegmentedControlItemProps\n extends Omit<ComponentProps<typeof Radio.Root>, 'value'> {\n /**\n * A unique value that identifies this item within the segmented control.\n */\n value: string\n /**\n * When true, prevents the user from interacting with this item.\n * @default false\n */\n disabled?: boolean\n ref?: Ref<HTMLElement>\n}\n\nexport const SegmentedControlItem = ({\n value,\n disabled = false,\n children,\n className,\n ref,\n ...rest\n}: SegmentedControlItemProps) => {\n const content = Children.toArray(children).map((child, index) => {\n if (typeof child === 'string' || typeof child === 'number') {\n return (\n <span key={`text-${index}`} data-spark-segmented-control-text>\n {child}\n </span>\n )\n }\n\n return child\n })\n\n return (\n <Radio.Root\n ref={ref}\n data-spark-component=\"segmented-control-item\"\n data-value={value}\n value={value}\n disabled={disabled}\n className={itemStyles({ className })}\n {...rest}\n >\n {content}\n </Radio.Root>\n )\n}\n\nSegmentedControlItem.displayName = 'SegmentedControl.Item'\n","import { SegmentedControl as Root } from './SegmentedControl'\nimport { SegmentedControlIndicator as Indicator } from './SegmentedControlIndicator'\nimport { SegmentedControlItem as Item } from './SegmentedControlItem'\n\nexport const SegmentedControl: typeof Root & {\n Item: typeof Item\n Indicator: typeof Indicator\n} = Object.assign(Root, {\n Item,\n Indicator,\n})\n\nSegmentedControl.displayName = 'SegmentedControl'\nItem.displayName = 'SegmentedControl.Item'\nIndicator.displayName = 'SegmentedControl.Indicator'\n\nexport type { SegmentedControlProps } from './SegmentedControl'\nexport type { SegmentedControlItemProps } from './SegmentedControlItem'\nexport type { SegmentedControlIndicatorProps } from './SegmentedControlIndicator'\n"],"names":["rootStyles","cva","itemStyles","indicatorStyles","SegmentedControlContext","createContext","useSegmentedControlContext","context","useContext","getFirstItemValue","children","firstValue","Children","child","isValidElement","SegmentedControl","value","defaultValue","onValueChange","className","ref","rest","containerRef","useRef","mergedRef","useMergeRefs","isControlled","internalValue","setInternalValue","useState","checkedValue","handleValueChange","newValue","next","labelId","description","isRequired","isInvalid","name","useFormFieldControl","jsx","RadioGroup","SegmentedControlIndicator","rect","setRect","selector","useMemo","useEffect","container","selectedItem","update","currentContainer","currentSelected","containerRect","itemRect","scaleX","scaleY","ro","style","SegmentedControlItem","disabled","content","index","Radio","Root","Item","Indicator"],"mappings":"iVAEaA,EAAaC,EAAAA,IAAI,CAC5B,qBACA,+CACA,mCACA,kBACA,qCACF,CAAC,EAEYC,EAAaD,EAAAA,IAAI,CAC5B,2DACA,oDACA,8BACA,iBACA,6BACA,cACA,iCACA,eACA,0BACA,+DACA,yCAGA,iHACF,CAAC,EAEYE,EAAkBF,EAAAA,IAAI,CACjC,kBACA,iBACA,gDACA,uCACA,8DACA,qBACF,CAAC,EC3BYG,EAA0BC,EAAAA,cACr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B,YAAc,wBClD5B,MAAM5C,EAGT,OAAO,OAAOiD,EAAM,CAAA,KACtBC,EAAA,UACAC,CACF,CAAC,EAEDnD,EAAiB,YAAc,mBAC/BkD,EAAK,YAAc,wBACnBC,EAAU,YAAc"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as h } from "react/jsx-runtime";
|
|
2
2
|
import { RadioGroup as E } from "@base-ui/react/radio-group";
|
|
3
|
-
import { useFormFieldControl as
|
|
4
|
-
import { useMergeRefs as
|
|
5
|
-
import { createContext as
|
|
6
|
-
import { cva as
|
|
7
|
-
import { Radio as
|
|
8
|
-
const
|
|
3
|
+
import { useFormFieldControl as L } from "@spark-ui/components/form-field";
|
|
4
|
+
import { useMergeRefs as q } from "@spark-ui/hooks/use-merge-refs";
|
|
5
|
+
import { createContext as _, useContext as j, useRef as F, useState as R, Children as I, isValidElement as O, useMemo as $, useEffect as B } from "react";
|
|
6
|
+
import { cva as x } from "class-variance-authority";
|
|
7
|
+
import { Radio as H } from "@base-ui/react/radio";
|
|
8
|
+
const M = x([
|
|
9
9
|
"default:self-start",
|
|
10
10
|
"group inline-grid grid-flow-col auto-cols-fr",
|
|
11
11
|
"relative items-stretch min-w-max",
|
|
12
12
|
"rounded-xl p-sm",
|
|
13
13
|
"bg-surface border-sm border-outline"
|
|
14
|
-
]),
|
|
14
|
+
]), P = x([
|
|
15
15
|
"relative z-raised min-h-sz-44 focus-visible:outline-none",
|
|
16
|
-
"flex flex-none items-center justify-center
|
|
16
|
+
"flex flex-none items-center justify-center gap-md",
|
|
17
17
|
"default:px-lg default:py-md",
|
|
18
18
|
"rounded-[20px]",
|
|
19
19
|
"cursor-pointer select-none",
|
|
@@ -23,151 +23,163 @@ const W = p([
|
|
|
23
23
|
"focus-visible:u-outline",
|
|
24
24
|
"data-disabled:cursor-not-allowed data-disabled:opacity-dim-3",
|
|
25
25
|
"data-checked:text-on-support-container",
|
|
26
|
-
"
|
|
27
|
-
|
|
26
|
+
// Avoid layout shift: simulate "bold" without changing font metrics.
|
|
27
|
+
// Apply only to wrapped text nodes (not arbitrary nested JSX like Tag).
|
|
28
|
+
"data-checked:[&>[data-spark-segmented-control-text]]:[text-shadow:0.35px_0_currentColor,-0.35px_0_currentColor]"
|
|
29
|
+
]), W = x([
|
|
28
30
|
"absolute z-base",
|
|
29
31
|
"rounded-[20px]",
|
|
30
32
|
"bg-support-container border-md border-support",
|
|
31
33
|
"group-has-focus-visible:border-focus",
|
|
32
34
|
"transition-[left,top,width,height] duration-200 ease-in-out",
|
|
33
35
|
"pointer-events-none"
|
|
34
|
-
]),
|
|
36
|
+
]), V = _(
|
|
35
37
|
{}
|
|
36
|
-
),
|
|
37
|
-
const e =
|
|
38
|
+
), A = () => {
|
|
39
|
+
const e = j(V);
|
|
38
40
|
if (!e)
|
|
39
41
|
throw Error("useSegmentedControlContext must be used within a SegmentedControlContext Provider");
|
|
40
42
|
return e;
|
|
41
|
-
},
|
|
42
|
-
let
|
|
43
|
-
return
|
|
44
|
-
|
|
45
|
-
}),
|
|
46
|
-
},
|
|
43
|
+
}, G = (e) => {
|
|
44
|
+
let o = null;
|
|
45
|
+
return I.forEach(e, (n) => {
|
|
46
|
+
o === null && O(n) && typeof n.props.value == "string" && (o = n.props.value);
|
|
47
|
+
}), o;
|
|
48
|
+
}, k = ({
|
|
47
49
|
value: e,
|
|
48
|
-
defaultValue:
|
|
49
|
-
onValueChange:
|
|
50
|
-
className:
|
|
51
|
-
children:
|
|
52
|
-
ref:
|
|
50
|
+
defaultValue: o,
|
|
51
|
+
onValueChange: n,
|
|
52
|
+
className: d,
|
|
53
|
+
children: s,
|
|
54
|
+
ref: r,
|
|
53
55
|
...c
|
|
54
56
|
}) => {
|
|
55
|
-
const
|
|
56
|
-
() =>
|
|
57
|
-
),
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
}, { labelId:
|
|
61
|
-
return /* @__PURE__ */
|
|
62
|
-
|
|
57
|
+
const t = F(null), f = q(t, r), p = G(s), u = e !== void 0, [i, g] = R(
|
|
58
|
+
() => o ?? p
|
|
59
|
+
), m = u ? e ?? null : i, a = (N) => {
|
|
60
|
+
const y = N;
|
|
61
|
+
u || g(y), n?.(y);
|
|
62
|
+
}, { labelId: v, description: l, isRequired: C, isInvalid: b, name: z } = L();
|
|
63
|
+
return /* @__PURE__ */ h(
|
|
64
|
+
V.Provider,
|
|
63
65
|
{
|
|
64
66
|
value: {
|
|
65
|
-
checkedValue:
|
|
66
|
-
containerRef:
|
|
67
|
+
checkedValue: m,
|
|
68
|
+
containerRef: t
|
|
67
69
|
},
|
|
68
|
-
children: /* @__PURE__ */
|
|
70
|
+
children: /* @__PURE__ */ h(
|
|
69
71
|
E,
|
|
70
72
|
{
|
|
71
|
-
ref:
|
|
72
|
-
value:
|
|
73
|
-
defaultValue:
|
|
74
|
-
onValueChange:
|
|
73
|
+
ref: f,
|
|
74
|
+
value: u ? e : void 0,
|
|
75
|
+
defaultValue: u ? void 0 : o ?? p ?? void 0,
|
|
76
|
+
onValueChange: a,
|
|
75
77
|
"data-spark-component": "segmented-control",
|
|
76
|
-
className:
|
|
77
|
-
"aria-labelledby":
|
|
78
|
-
"aria-describedby":
|
|
79
|
-
"aria-required":
|
|
80
|
-
"aria-invalid":
|
|
81
|
-
name:
|
|
78
|
+
className: M({ className: d }),
|
|
79
|
+
"aria-labelledby": v,
|
|
80
|
+
"aria-describedby": l,
|
|
81
|
+
"aria-required": C || void 0,
|
|
82
|
+
"aria-invalid": b || void 0,
|
|
83
|
+
name: z,
|
|
82
84
|
...c,
|
|
83
|
-
children:
|
|
85
|
+
children: s
|
|
84
86
|
}
|
|
85
87
|
)
|
|
86
88
|
}
|
|
87
89
|
);
|
|
88
90
|
};
|
|
89
|
-
|
|
90
|
-
const
|
|
91
|
+
k.displayName = "SegmentedControl";
|
|
92
|
+
const w = ({
|
|
91
93
|
className: e,
|
|
92
|
-
ref:
|
|
93
|
-
...
|
|
94
|
+
ref: o,
|
|
95
|
+
...n
|
|
94
96
|
}) => {
|
|
95
|
-
const { checkedValue:
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
if (!
|
|
102
|
-
c(null);
|
|
97
|
+
const { checkedValue: d, containerRef: s } = A(), [r, c] = R(null), t = $(
|
|
98
|
+
() => d ? `[data-value="${CSS.escape(d)}"]` : null,
|
|
99
|
+
[d]
|
|
100
|
+
);
|
|
101
|
+
if (B(() => {
|
|
102
|
+
const p = s.current;
|
|
103
|
+
if (!p)
|
|
103
104
|
return;
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
105
|
+
const u = t ? p.querySelector(t) : null, i = () => {
|
|
106
|
+
const m = s.current;
|
|
107
|
+
if (!m || !t) {
|
|
108
|
+
c(null);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
111
|
+
const a = m.querySelector(t);
|
|
112
|
+
if (!a) {
|
|
113
|
+
c(null);
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
116
|
+
const v = m.getBoundingClientRect(), l = a.getBoundingClientRect(), C = a.offsetWidth > 0 ? l.width / a.offsetWidth : 1, b = a.offsetHeight > 0 ? l.height / a.offsetHeight : 1;
|
|
117
|
+
c({
|
|
118
|
+
left: (l.left - v.left) / C - m.clientLeft,
|
|
119
|
+
top: (l.top - v.top) / b - m.clientTop,
|
|
120
|
+
width: l.width / C,
|
|
121
|
+
height: l.height / b
|
|
122
|
+
});
|
|
123
|
+
};
|
|
124
|
+
i();
|
|
125
|
+
const g = typeof ResizeObserver < "u" ? new ResizeObserver(() => {
|
|
126
|
+
i();
|
|
127
|
+
}) : null;
|
|
128
|
+
return g?.observe(p), u && g?.observe(u), window.addEventListener("resize", i, { passive: !0 }), window.visualViewport?.addEventListener("resize", i, { passive: !0 }), () => {
|
|
129
|
+
g?.disconnect(), window.removeEventListener("resize", i), window.visualViewport?.removeEventListener("resize", i);
|
|
130
|
+
};
|
|
131
|
+
}, [s, t]), !r) return null;
|
|
132
|
+
const f = {
|
|
133
|
+
left: r.left,
|
|
134
|
+
top: r.top,
|
|
135
|
+
width: r.width,
|
|
136
|
+
height: r.height
|
|
118
137
|
};
|
|
119
|
-
return /* @__PURE__ */
|
|
138
|
+
return /* @__PURE__ */ h(
|
|
120
139
|
"span",
|
|
121
140
|
{
|
|
122
|
-
ref:
|
|
141
|
+
ref: o,
|
|
123
142
|
"data-spark-component": "segmented-control-indicator",
|
|
124
143
|
"aria-hidden": !0,
|
|
125
|
-
className:
|
|
126
|
-
style:
|
|
127
|
-
...
|
|
144
|
+
className: W({ className: e }),
|
|
145
|
+
style: f,
|
|
146
|
+
...n
|
|
128
147
|
}
|
|
129
148
|
);
|
|
130
149
|
};
|
|
131
|
-
|
|
132
|
-
const
|
|
150
|
+
w.displayName = "SegmentedControl.Indicator";
|
|
151
|
+
const S = ({
|
|
133
152
|
value: e,
|
|
134
|
-
disabled:
|
|
135
|
-
children:
|
|
136
|
-
className:
|
|
137
|
-
ref:
|
|
138
|
-
...
|
|
139
|
-
}) =>
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
]
|
|
160
|
-
}
|
|
161
|
-
);
|
|
162
|
-
h.displayName = "SegmentedControl.Item";
|
|
163
|
-
const K = Object.assign(x, {
|
|
164
|
-
Item: h,
|
|
165
|
-
Indicator: g
|
|
153
|
+
disabled: o = !1,
|
|
154
|
+
children: n,
|
|
155
|
+
className: d,
|
|
156
|
+
ref: s,
|
|
157
|
+
...r
|
|
158
|
+
}) => {
|
|
159
|
+
const c = I.toArray(n).map((t, f) => typeof t == "string" || typeof t == "number" ? /* @__PURE__ */ h("span", { "data-spark-segmented-control-text": !0, children: t }, `text-${f}`) : t);
|
|
160
|
+
return /* @__PURE__ */ h(
|
|
161
|
+
H.Root,
|
|
162
|
+
{
|
|
163
|
+
ref: s,
|
|
164
|
+
"data-spark-component": "segmented-control-item",
|
|
165
|
+
"data-value": e,
|
|
166
|
+
value: e,
|
|
167
|
+
disabled: o,
|
|
168
|
+
className: P({ className: d }),
|
|
169
|
+
...r,
|
|
170
|
+
children: c
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
};
|
|
174
|
+
S.displayName = "SegmentedControl.Item";
|
|
175
|
+
const T = Object.assign(k, {
|
|
176
|
+
Item: S,
|
|
177
|
+
Indicator: w
|
|
166
178
|
});
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
179
|
+
T.displayName = "SegmentedControl";
|
|
180
|
+
S.displayName = "SegmentedControl.Item";
|
|
181
|
+
w.displayName = "SegmentedControl.Indicator";
|
|
170
182
|
export {
|
|
171
|
-
|
|
183
|
+
T as SegmentedControl
|
|
172
184
|
};
|
|
173
185
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../src/segmented-control/SegmentedControl.styles.ts","../../src/segmented-control/SegmentedControlContext.tsx","../../src/segmented-control/SegmentedControl.tsx","../../src/segmented-control/SegmentedControlIndicator.tsx","../../src/segmented-control/SegmentedControlItem.tsx","../../src/segmented-control/index.ts"],"sourcesContent":["import { cva, VariantProps } from 'class-variance-authority'\n\nexport const rootStyles = cva([\n 'default:self-start',\n 'group inline-grid grid-flow-col auto-cols-fr',\n 'relative items-stretch min-w-max',\n 'rounded-xl p-sm',\n 'bg-surface border-sm border-outline',\n])\n\nexport const itemStyles = cva([\n 'relative z-raised min-h-sz-44 focus-visible:outline-none',\n 'flex flex-none items-center justify-center flex-col',\n 'default:px-lg default:py-md',\n 'rounded-[20px]',\n 'cursor-pointer select-none',\n 'font-medium',\n 'transition-colors duration-150',\n 'outline-none',\n 'focus-visible:u-outline',\n 'data-disabled:cursor-not-allowed data-disabled:opacity-dim-3',\n 'data-checked:text-on-support-container',\n 'data-checked:font-bold',\n])\n\nexport const indicatorStyles = cva([\n 'absolute z-base',\n 'rounded-[20px]',\n 'bg-support-container border-md border-support',\n 'group-has-focus-visible:border-focus',\n 'transition-[left,top,width,height] duration-200 ease-in-out',\n 'pointer-events-none',\n])\n\nexport type SegmentedControlStylesProps = VariantProps<typeof itemStyles>\n","import { createContext, RefObject, useContext } from 'react'\n\nexport interface SegmentedControlContextInterface {\n checkedValue: string | null\n containerRef: RefObject<HTMLDivElement | null>\n}\n\nexport const SegmentedControlContext = createContext<SegmentedControlContextInterface>(\n {} as SegmentedControlContextInterface\n)\n\nexport const useSegmentedControlContext = () => {\n const context = useContext(SegmentedControlContext)\n\n if (!context) {\n throw Error('useSegmentedControlContext must be used within a SegmentedControlContext Provider')\n }\n\n return context\n}\n","import { RadioGroup } from '@base-ui/react/radio-group'\nimport { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { useMergeRefs } from '@spark-ui/hooks/use-merge-refs'\nimport { Children, type ComponentProps, isValidElement, Ref, useRef, useState } from 'react'\n\nimport type { SegmentedControlStylesProps } from './SegmentedControl.styles'\nimport { rootStyles } from './SegmentedControl.styles'\nimport { SegmentedControlContext } from './SegmentedControlContext'\n\nexport interface SegmentedControlProps\n extends Omit<ComponentProps<typeof RadioGroup>, 'value' | 'defaultValue' | 'onValueChange'>,\n SegmentedControlStylesProps {\n /**\n * The controlled selected value.\n */\n value?: string\n /**\n * The uncontrolled default selected value.\n */\n defaultValue?: string\n /**\n * Callback fired when the selected value changes.\n */\n onValueChange?: (value: string) => void\n ref?: Ref<HTMLDivElement>\n}\n\nconst getFirstItemValue = (children: React.ReactNode): string | null => {\n let firstValue: string | null = null\n\n Children.forEach(children, child => {\n if (firstValue !== null) return\n if (isValidElement(child) && typeof (child.props as { value?: string }).value === 'string') {\n firstValue = (child.props as { value: string }).value\n }\n })\n\n return firstValue\n}\n\nexport const SegmentedControl = ({\n value,\n defaultValue,\n onValueChange,\n className,\n children,\n ref,\n ...rest\n}: SegmentedControlProps) => {\n const containerRef = useRef<HTMLDivElement | null>(null)\n const mergedRef = useMergeRefs(containerRef, ref)\n\n const firstValue = getFirstItemValue(children)\n\n const isControlled = value !== undefined\n const [internalValue, setInternalValue] = useState<string | null>(\n () => defaultValue ?? firstValue\n )\n const checkedValue = isControlled ? (value ?? null) : internalValue\n\n const handleValueChange = (newValue: unknown) => {\n const next = newValue as string\n\n if (!isControlled) {\n setInternalValue(next)\n }\n\n onValueChange?.(next)\n }\n\n const { labelId, description, isRequired, isInvalid, name } = useFormFieldControl()\n\n return (\n <SegmentedControlContext.Provider\n value={{\n checkedValue,\n containerRef,\n }}\n >\n <RadioGroup\n ref={mergedRef}\n value={isControlled ? value : undefined}\n defaultValue={!isControlled ? (defaultValue ?? firstValue ?? undefined) : undefined}\n onValueChange={handleValueChange}\n data-spark-component=\"segmented-control\"\n className={rootStyles({ className })}\n aria-labelledby={labelId}\n aria-describedby={description}\n aria-required={isRequired || undefined}\n aria-invalid={isInvalid || undefined}\n name={name}\n {...rest}\n >\n {children}\n </RadioGroup>\n </SegmentedControlContext.Provider>\n )\n}\n\nSegmentedControl.displayName = 'SegmentedControl'\n","import { type ComponentProps, type CSSProperties, Ref, useEffect, useState } from 'react'\n\nimport { indicatorStyles } from './SegmentedControl.styles'\nimport { useSegmentedControlContext } from './SegmentedControlContext'\n\ninterface IndicatorRect {\n left: number\n top: number\n width: number\n height: number\n}\n\nexport interface SegmentedControlIndicatorProps extends ComponentProps<'span'> {\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const SegmentedControlIndicator = ({\n className,\n ref,\n ...rest\n}: SegmentedControlIndicatorProps) => {\n const { checkedValue, containerRef } = useSegmentedControlContext()\n const [rect, setRect] = useState<IndicatorRect | null>(null)\n\n useEffect(() => {\n const container = containerRef.current\n\n if (!container) {\n return\n }\n\n const selectedItem = checkedValue\n ? container.querySelector<HTMLElement>(`[data-value=\"${checkedValue}\"]`)\n : null\n\n if (!selectedItem) {\n setRect(null)\n\n return\n }\n\n const containerRect = container.getBoundingClientRect()\n const itemRect = selectedItem.getBoundingClientRect()\n\n const rootBorderWidth = 1\n\n setRect({\n left: itemRect.left - containerRect.left - rootBorderWidth,\n top: itemRect.top - containerRect.top - rootBorderWidth,\n width: itemRect.width,\n height: itemRect.height,\n })\n }, [checkedValue, containerRef])\n\n if (!rect) return null\n\n const style: CSSProperties = {\n left: rect.left,\n top: rect.top,\n width: rect.width,\n height: rect.height,\n }\n\n return (\n <span\n ref={ref}\n data-spark-component=\"segmented-control-indicator\"\n aria-hidden\n className={indicatorStyles({ className })}\n style={style}\n {...rest}\n />\n )\n}\n\nSegmentedControlIndicator.displayName = 'SegmentedControl.Indicator'\n","import { Radio } from '@base-ui/react/radio'\nimport { type ComponentProps, Ref } from 'react'\n\nimport { itemStyles } from './SegmentedControl.styles'\n\nexport interface SegmentedControlItemProps\n extends Omit<ComponentProps<typeof Radio.Root>, 'value'> {\n /**\n * A unique value that identifies this item within the segmented control.\n */\n value: string\n /**\n * When true, prevents the user from interacting with this item.\n * @default false\n */\n disabled?: boolean\n ref?: Ref<HTMLElement>\n}\n\nexport const SegmentedControlItem = ({\n value,\n disabled = false,\n children,\n className,\n ref,\n ...rest\n}: SegmentedControlItemProps) => {\n return (\n <Radio.Root\n ref={ref}\n data-spark-component=\"segmented-control-item\"\n data-value={value}\n value={value}\n disabled={disabled}\n className={itemStyles({ className })}\n {...rest}\n >\n {children}\n <span\n aria-hidden=\"true\"\n className=\"bg-success pointer-events-none h-0 overflow-hidden font-bold content-[attr(data-text)/'']\"\n >\n {children}\n </span>\n </Radio.Root>\n )\n}\n\nSegmentedControlItem.displayName = 'SegmentedControl.Item'\n","import { SegmentedControl as Root } from './SegmentedControl'\nimport { SegmentedControlIndicator as Indicator } from './SegmentedControlIndicator'\nimport { SegmentedControlItem as Item } from './SegmentedControlItem'\n\nexport const SegmentedControl: typeof Root & {\n Item: typeof Item\n Indicator: typeof Indicator\n} = Object.assign(Root, {\n Item,\n Indicator,\n})\n\nSegmentedControl.displayName = 'SegmentedControl'\nItem.displayName = 'SegmentedControl.Item'\nIndicator.displayName = 'SegmentedControl.Indicator'\n\nexport type { SegmentedControlProps } from './SegmentedControl'\nexport type { SegmentedControlItemProps } from './SegmentedControlItem'\nexport type { SegmentedControlIndicatorProps } from './SegmentedControlIndicator'\n"],"names":["rootStyles","cva","itemStyles","indicatorStyles","SegmentedControlContext","createContext","useSegmentedControlContext","context","useContext","getFirstItemValue","children","firstValue","Children","child","isValidElement","SegmentedControl","value","defaultValue","onValueChange","className","ref","rest","containerRef","useRef","mergedRef","useMergeRefs","isControlled","internalValue","setInternalValue","useState","checkedValue","handleValueChange","newValue","next","labelId","description","isRequired","isInvalid","name","useFormFieldControl","jsx","RadioGroup","SegmentedControlIndicator","rect","setRect","useEffect","container","selectedItem","containerRect","itemRect","rootBorderWidth","style","SegmentedControlItem","disabled","jsxs","Radio","Root","Item","Indicator"],"mappings":";;;;;;;AAEO,MAAMA,IAAaC,EAAI;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC,GAEYC,IAAaD,EAAI;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC,GAEYE,IAAkBF,EAAI;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC,GCzBYG,IAA0BC;AAAA,EACrC,CAAA;AACF,GAEaC,IAA6B,MAAM;AAC9C,QAAMC,IAAUC,EAAWJ,CAA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A,MACrB,eAAW;AAAA,MACX,WAAWjB,EAAgB,EAAE,WAAAgB,GAAW;AAAA,MACxC,OAAAgC;AAAA,MACC,GAAG9B;AAAA,IAAA;AAAA,EAAA;AAGV;AAEAqB,EAA0B,cAAc;ACxDjC,MAAMU,IAAuB,CAAC;AAAA,EACnC,OAAApC;AAAA,EACA,UAAAqC,IAAW;AAAA,EACX,UAAA3C;AAAA,EACA,WAAAS;AAAA,EACA,KAAAC;AAAA,EACA,GAAGC;AACL,MAEI,gBAAAiC;AAAA,EAACC,EAAM;AAAA,EAAN;AAAA,IACC,KAAAnC;AAAA,IACA,wBAAqB;AAAA,IACrB,cAAYJ;AAAA,IACZ,OAAAA;AAAA,IACA,UAAAqC;AAAA,IACA,WAAWnD,EAAW,EAAE,WAAAiB,GAAW;AAAA,IAClC,GAAGE;AAAA,IAEH,UAAA;AAAA,MAAAX;AAAA,MACD,gBAAA8B;AAAA,QAAC;AAAA,QAAA;AAAA,UACC,eAAY;AAAA,UACZ,WAAU;AAAA,UAET,UAAA9B;AAAA,QAAA;AAAA,MAAA;AAAA,IACH;AAAA,EAAA;AAAA;AAKN0C,EAAqB,cAAc;AC5C5B,MAAMrC,IAGT,OAAO,OAAOyC,GAAM;AAAA,EAAA,MACtBC;AAAAA,EAAA,WACAC;AACF,CAAC;AAED3C,EAAiB,cAAc;AAC/B0C,EAAK,cAAc;AACnBC,EAAU,cAAc;"}
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../src/segmented-control/SegmentedControl.styles.ts","../../src/segmented-control/SegmentedControlContext.tsx","../../src/segmented-control/SegmentedControl.tsx","../../src/segmented-control/SegmentedControlIndicator.tsx","../../src/segmented-control/SegmentedControlItem.tsx","../../src/segmented-control/index.ts"],"sourcesContent":["import { cva, VariantProps } from 'class-variance-authority'\n\nexport const rootStyles = cva([\n 'default:self-start',\n 'group inline-grid grid-flow-col auto-cols-fr',\n 'relative items-stretch min-w-max',\n 'rounded-xl p-sm',\n 'bg-surface border-sm border-outline',\n])\n\nexport const itemStyles = cva([\n 'relative z-raised min-h-sz-44 focus-visible:outline-none',\n 'flex flex-none items-center justify-center gap-md',\n 'default:px-lg default:py-md',\n 'rounded-[20px]',\n 'cursor-pointer select-none',\n 'font-medium',\n 'transition-colors duration-150',\n 'outline-none',\n 'focus-visible:u-outline',\n 'data-disabled:cursor-not-allowed data-disabled:opacity-dim-3',\n 'data-checked:text-on-support-container',\n // Avoid layout shift: simulate \"bold\" without changing font metrics.\n // Apply only to wrapped text nodes (not arbitrary nested JSX like Tag).\n 'data-checked:[&>[data-spark-segmented-control-text]]:[text-shadow:0.35px_0_currentColor,-0.35px_0_currentColor]',\n])\n\nexport const indicatorStyles = cva([\n 'absolute z-base',\n 'rounded-[20px]',\n 'bg-support-container border-md border-support',\n 'group-has-focus-visible:border-focus',\n 'transition-[left,top,width,height] duration-200 ease-in-out',\n 'pointer-events-none',\n])\n\nexport type SegmentedControlStylesProps = VariantProps<typeof itemStyles>\n","import { createContext, RefObject, useContext } from 'react'\n\nexport interface SegmentedControlContextInterface {\n checkedValue: string | null\n containerRef: RefObject<HTMLDivElement | null>\n}\n\nexport const SegmentedControlContext = createContext<SegmentedControlContextInterface>(\n {} as SegmentedControlContextInterface\n)\n\nexport const useSegmentedControlContext = () => {\n const context = useContext(SegmentedControlContext)\n\n if (!context) {\n throw Error('useSegmentedControlContext must be used within a SegmentedControlContext Provider')\n }\n\n return context\n}\n","import { RadioGroup } from '@base-ui/react/radio-group'\nimport { useFormFieldControl } from '@spark-ui/components/form-field'\nimport { useMergeRefs } from '@spark-ui/hooks/use-merge-refs'\nimport { Children, type ComponentProps, isValidElement, Ref, useRef, useState } from 'react'\n\nimport type { SegmentedControlStylesProps } from './SegmentedControl.styles'\nimport { rootStyles } from './SegmentedControl.styles'\nimport { SegmentedControlContext } from './SegmentedControlContext'\n\nexport interface SegmentedControlProps\n extends Omit<ComponentProps<typeof RadioGroup>, 'value' | 'defaultValue' | 'onValueChange'>,\n SegmentedControlStylesProps {\n /**\n * The controlled selected value.\n */\n value?: string\n /**\n * The uncontrolled default selected value.\n */\n defaultValue?: string\n /**\n * Callback fired when the selected value changes.\n */\n onValueChange?: (value: string) => void\n ref?: Ref<HTMLDivElement>\n}\n\nconst getFirstItemValue = (children: React.ReactNode): string | null => {\n let firstValue: string | null = null\n\n Children.forEach(children, child => {\n if (firstValue !== null) return\n if (isValidElement(child) && typeof (child.props as { value?: string }).value === 'string') {\n firstValue = (child.props as { value: string }).value\n }\n })\n\n return firstValue\n}\n\nexport const SegmentedControl = ({\n value,\n defaultValue,\n onValueChange,\n className,\n children,\n ref,\n ...rest\n}: SegmentedControlProps) => {\n const containerRef = useRef<HTMLDivElement | null>(null)\n const mergedRef = useMergeRefs(containerRef, ref)\n\n const firstValue = getFirstItemValue(children)\n\n const isControlled = value !== undefined\n const [internalValue, setInternalValue] = useState<string | null>(\n () => defaultValue ?? firstValue\n )\n const checkedValue = isControlled ? (value ?? null) : internalValue\n\n const handleValueChange = (newValue: unknown) => {\n const next = newValue as string\n\n if (!isControlled) {\n setInternalValue(next)\n }\n\n onValueChange?.(next)\n }\n\n const { labelId, description, isRequired, isInvalid, name } = useFormFieldControl()\n\n return (\n <SegmentedControlContext.Provider\n value={{\n checkedValue,\n containerRef,\n }}\n >\n <RadioGroup\n ref={mergedRef}\n value={isControlled ? value : undefined}\n defaultValue={!isControlled ? (defaultValue ?? firstValue ?? undefined) : undefined}\n onValueChange={handleValueChange}\n data-spark-component=\"segmented-control\"\n className={rootStyles({ className })}\n aria-labelledby={labelId}\n aria-describedby={description}\n aria-required={isRequired || undefined}\n aria-invalid={isInvalid || undefined}\n name={name}\n {...rest}\n >\n {children}\n </RadioGroup>\n </SegmentedControlContext.Provider>\n )\n}\n\nSegmentedControl.displayName = 'SegmentedControl'\n","import { type ComponentProps, type CSSProperties, Ref, useEffect, useMemo, useState } from 'react'\n\nimport { indicatorStyles } from './SegmentedControl.styles'\nimport { useSegmentedControlContext } from './SegmentedControlContext'\n\ninterface IndicatorRect {\n left: number\n top: number\n width: number\n height: number\n}\n\nexport interface SegmentedControlIndicatorProps extends ComponentProps<'span'> {\n ref?: Ref<HTMLSpanElement>\n}\n\nexport const SegmentedControlIndicator = ({\n className,\n ref,\n ...rest\n}: SegmentedControlIndicatorProps) => {\n const { checkedValue, containerRef } = useSegmentedControlContext()\n const [rect, setRect] = useState<IndicatorRect | null>(null)\n\n const selector = useMemo(\n () => (checkedValue ? `[data-value=\"${CSS.escape(checkedValue)}\"]` : null),\n [checkedValue]\n )\n\n useEffect(() => {\n const container = containerRef.current\n\n if (!container) {\n return\n }\n\n const selectedItem = selector ? container.querySelector<HTMLElement>(selector) : null\n\n const update = () => {\n const currentContainer = containerRef.current\n if (!currentContainer || !selector) {\n setRect(null)\n\n return\n }\n\n const currentSelected = currentContainer.querySelector<HTMLElement>(selector)\n if (!currentSelected) {\n setRect(null)\n\n return\n }\n\n const containerRect = currentContainer.getBoundingClientRect()\n const itemRect = currentSelected.getBoundingClientRect()\n\n // Storybook canvas \"zoom\" can be implemented via `transform: scale()`.\n // In that case, `getBoundingClientRect()` returns *scaled* values, but CSS positioning/sizing\n // expects unscaled layout pixels. We infer the scale factor from offset sizes and normalize.\n const scaleX =\n currentSelected.offsetWidth > 0 ? itemRect.width / currentSelected.offsetWidth : 1\n const scaleY =\n currentSelected.offsetHeight > 0 ? itemRect.height / currentSelected.offsetHeight : 1\n\n // `getBoundingClientRect()` is border-box; absolute positioning is relative to the padding box.\n setRect({\n left: (itemRect.left - containerRect.left) / scaleX - currentContainer.clientLeft,\n top: (itemRect.top - containerRect.top) / scaleY - currentContainer.clientTop,\n width: itemRect.width / scaleX,\n height: itemRect.height / scaleY,\n })\n }\n\n update()\n\n const ro =\n typeof ResizeObserver !== 'undefined'\n ? new ResizeObserver(() => {\n update()\n })\n : null\n\n ro?.observe(container)\n if (selectedItem) ro?.observe(selectedItem)\n\n window.addEventListener('resize', update, { passive: true })\n window.visualViewport?.addEventListener('resize', update, { passive: true })\n\n return () => {\n ro?.disconnect()\n window.removeEventListener('resize', update)\n window.visualViewport?.removeEventListener('resize', update)\n }\n }, [containerRef, selector])\n\n if (!rect) return null\n\n const style: CSSProperties = {\n left: rect.left,\n top: rect.top,\n width: rect.width,\n height: rect.height,\n }\n\n return (\n <span\n ref={ref}\n data-spark-component=\"segmented-control-indicator\"\n aria-hidden\n className={indicatorStyles({ className })}\n style={style}\n {...rest}\n />\n )\n}\n\nSegmentedControlIndicator.displayName = 'SegmentedControl.Indicator'\n","import { Radio } from '@base-ui/react/radio'\nimport { Children, type ComponentProps, Ref } from 'react'\n\nimport { itemStyles } from './SegmentedControl.styles'\n\nexport interface SegmentedControlItemProps\n extends Omit<ComponentProps<typeof Radio.Root>, 'value'> {\n /**\n * A unique value that identifies this item within the segmented control.\n */\n value: string\n /**\n * When true, prevents the user from interacting with this item.\n * @default false\n */\n disabled?: boolean\n ref?: Ref<HTMLElement>\n}\n\nexport const SegmentedControlItem = ({\n value,\n disabled = false,\n children,\n className,\n ref,\n ...rest\n}: SegmentedControlItemProps) => {\n const content = Children.toArray(children).map((child, index) => {\n if (typeof child === 'string' || typeof child === 'number') {\n return (\n <span key={`text-${index}`} data-spark-segmented-control-text>\n {child}\n </span>\n )\n }\n\n return child\n })\n\n return (\n <Radio.Root\n ref={ref}\n data-spark-component=\"segmented-control-item\"\n data-value={value}\n value={value}\n disabled={disabled}\n className={itemStyles({ className })}\n {...rest}\n >\n {content}\n </Radio.Root>\n )\n}\n\nSegmentedControlItem.displayName = 'SegmentedControl.Item'\n","import { SegmentedControl as Root } from './SegmentedControl'\nimport { SegmentedControlIndicator as Indicator } from './SegmentedControlIndicator'\nimport { SegmentedControlItem as Item } from './SegmentedControlItem'\n\nexport const SegmentedControl: typeof Root & {\n Item: typeof Item\n Indicator: typeof Indicator\n} = Object.assign(Root, {\n Item,\n Indicator,\n})\n\nSegmentedControl.displayName = 'SegmentedControl'\nItem.displayName = 'SegmentedControl.Item'\nIndicator.displayName = 'SegmentedControl.Indicator'\n\nexport type { SegmentedControlProps } from './SegmentedControl'\nexport type { SegmentedControlItemProps } from './SegmentedControlItem'\nexport type { SegmentedControlIndicatorProps } from './SegmentedControlIndicator'\n"],"names":["rootStyles","cva","itemStyles","indicatorStyles","SegmentedControlContext","createContext","useSegmentedControlContext","context","useContext","getFirstItemValue","children","firstValue","Children","child","isValidElement","SegmentedControl","value","defaultValue","onValueChange","className","ref","rest","containerRef","useRef","mergedRef","useMergeRefs","isControlled","internalValue","setInternalValue","useState","checkedValue","handleValueChange","newValue","next","labelId","description","isRequired","isInvalid","name","useFormFieldControl","jsx","RadioGroup","SegmentedControlIndicator","rect","setRect","selector","useMemo","useEffect","container","selectedItem","update","currentContainer","currentSelected","containerRect","itemRect","scaleX","scaleY","ro","style","SegmentedControlItem","disabled","content","index","Radio","Root","Item","Indicator"],"mappings":";;;;;;;AAEO,MAAMA,IAAaC,EAAI;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC,GAEYC,IAAaD,EAAI;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA,EAGA;AACF,CAAC,GAEYE,IAAkBF,EAAI;AAAA,EACjC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC,GC3BYG,IAA0BC;AAAA,EACrC,CAAA;AACF,GAEaC,IAA6B,MAAM;AAC9C,QAAMC,IAAUC,EAAWJ,CAAuB;AAElD,MAAI,CAACG;AACH,UAAM,MAAM,mFAAmF;AAGjG,SAAOA;AACT,GCQME,IAAoB,CAACC,MAA6C;AACtE,MAAIC,IAA4B;AAEhC,SAAAC,EAAS,QAAQF,GAAU,CAAAG,MAAS;AAClC,IAAIF,MAAe,QACfG,EAAeD,CAAK,KAAK,OAAQA,EAAM,MAA6B,SAAU,aAChF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AAqB;AAAA,MACrB,cAAYJ;AAAA,MACZ,OAAAA;AAAA,MACA,UAAA4C;AAAA,MACA,WAAW1D,EAAW,EAAE,WAAAiB,GAAW;AAAA,MAClC,GAAGE;AAAA,MAEH,UAAAwC;AAAA,IAAA;AAAA,EAAA;AAGP;AAEAF,EAAqB,cAAc;AClD5B,MAAM5C,IAGT,OAAO,OAAOiD,GAAM;AAAA,EAAA,MACtBC;AAAAA,EAAA,WACAC;AACF,CAAC;AAEDnD,EAAiB,cAAc;AAC/BkD,EAAK,cAAc;AACnBC,EAAU,cAAc;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@spark-ui/components",
|
|
3
|
-
"version": "17.2.1
|
|
3
|
+
"version": "17.2.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Spark (Leboncoin design system) components.",
|
|
6
6
|
"exports": {
|
|
@@ -54,9 +54,9 @@
|
|
|
54
54
|
"@react-aria/toast": "^3.0.0-beta.18",
|
|
55
55
|
"@react-stately/numberfield": "3.9.11",
|
|
56
56
|
"@react-stately/toast": "^3.0.0-beta.7",
|
|
57
|
-
"@spark-ui/hooks": "^17.2.1
|
|
58
|
-
"@spark-ui/icons": "^17.2.1
|
|
59
|
-
"@spark-ui/internal-utils": "^17.2.1
|
|
57
|
+
"@spark-ui/hooks": "^17.2.1",
|
|
58
|
+
"@spark-ui/icons": "^17.2.1",
|
|
59
|
+
"@spark-ui/internal-utils": "^17.2.1",
|
|
60
60
|
"@zag-js/pagination": "1.30.0",
|
|
61
61
|
"@zag-js/react": "1.30.0",
|
|
62
62
|
"class-variance-authority": "0.7.1",
|