infinity-ui-elements 1.8.61 → 1.8.63
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/components/Radio/Radio.d.ts.map +1 -1
- package/dist/components/Switch/Switch.d.ts +14 -0
- package/dist/components/Switch/Switch.d.ts.map +1 -1
- package/dist/components/Switch/Switch.stories.d.ts +11 -0
- package/dist/components/Switch/Switch.stories.d.ts.map +1 -1
- package/dist/components/TextField/TextField.d.ts +1 -0
- package/dist/components/TextField/TextField.d.ts.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.esm.js +123 -38
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +122 -37
- package/dist/index.js.map +1 -1
- package/dist/lib/icons.d.ts +2 -0
- package/dist/lib/icons.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -5,7 +5,7 @@ import { Slot } from '@radix-ui/react-slot';
|
|
|
5
5
|
import { PulseLoader, ClipLoader } from 'react-spinners';
|
|
6
6
|
import { clsx } from 'clsx';
|
|
7
7
|
import { twMerge } from 'tailwind-merge';
|
|
8
|
-
import { ExternalLink, Calendar, X, Loader2, Search,
|
|
8
|
+
import { ExternalLink, Calendar, X, Loader2, Search, ChevronDown } from 'lucide-react';
|
|
9
9
|
import { createPortal } from 'react-dom';
|
|
10
10
|
import Calendar$1 from 'react-calendar';
|
|
11
11
|
import 'react-calendar/dist/Calendar.css';
|
|
@@ -77,6 +77,14 @@ const iconRegistry = {
|
|
|
77
77
|
chevronUp: `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
78
78
|
<path d="M12 11.2727L6.55555 17L5 15.3637L12 8L19 15.3637L17.4445 17L12 11.2727Z" fill="#081416"/>
|
|
79
79
|
</svg>
|
|
80
|
+
`,
|
|
81
|
+
chevronLeft: `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
82
|
+
<path d="M11.2727 12L17 17.4445L15.3637 19L8 12L15.3637 5L17 6.55555L11.2727 12Z" fill="#081416"/>
|
|
83
|
+
</svg>
|
|
84
|
+
`,
|
|
85
|
+
chevronRight: `<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
86
|
+
<path d="M13.7272 12L8 6.55555L9.63635 5L17 12L9.63635 19L8 17.4445L13.7272 12Z" fill="#081416"/>
|
|
87
|
+
</svg>
|
|
80
88
|
`,
|
|
81
89
|
};
|
|
82
90
|
const Icon = ({ name, size = 24, className = "", style = {}, ...props }) => {
|
|
@@ -2843,8 +2851,6 @@ const textFieldVariants = cva("relative flex items-center gap-3 border rounded-l
|
|
|
2843
2851
|
validationState: {
|
|
2844
2852
|
none: `
|
|
2845
2853
|
border-action-outline-neutral-faded
|
|
2846
|
-
hover:border-action-outline-neutral-faded-hover
|
|
2847
|
-
hover:bg-action-fill-neutral-faded-hover
|
|
2848
2854
|
focus-within:border-action-outline-primary-default
|
|
2849
2855
|
focus-within:bg-white!
|
|
2850
2856
|
focus-within:ring-2
|
|
@@ -2869,11 +2875,16 @@ const textFieldVariants = cva("relative flex items-center gap-3 border rounded-l
|
|
|
2869
2875
|
cursor-not-allowed`,
|
|
2870
2876
|
false: "",
|
|
2871
2877
|
},
|
|
2878
|
+
isReadOnly: {
|
|
2879
|
+
true: "",
|
|
2880
|
+
false: "hover:border-action-outline-neutral-faded-hover hover:bg-action-fill-neutral-faded-hover",
|
|
2881
|
+
},
|
|
2872
2882
|
},
|
|
2873
2883
|
defaultVariants: {
|
|
2874
2884
|
size: "medium",
|
|
2875
2885
|
validationState: "none",
|
|
2876
2886
|
isDisabled: false,
|
|
2887
|
+
isReadOnly: false,
|
|
2877
2888
|
},
|
|
2878
2889
|
});
|
|
2879
2890
|
const TextField = React.forwardRef(({ label, helperText, errorText, successText, size = "medium", validationState = "none", isDisabled = false, isLoading = false, isRequired = false, isOptional = false, prefix, suffix, showClearButton = false, infoDescription, infoHeading, LinkComponent, linkText, linkHref, onLinkClick, onClear, containerClassName, labelClassName, inputClassName, className, value, onChange, ...props }, ref) => {
|
|
@@ -2923,13 +2934,14 @@ const TextField = React.forwardRef(({ label, helperText, errorText, successText,
|
|
|
2923
2934
|
size,
|
|
2924
2935
|
validationState: currentValidationState,
|
|
2925
2936
|
isDisabled,
|
|
2937
|
+
isReadOnly: props.readOnly,
|
|
2926
2938
|
}), isLoading && "text-field-loading", className), children: [prefix && (jsx("span", { className: cn("shrink-0 flex items-center", isDisabled
|
|
2927
2939
|
? "text-surface-ink-neutral-disabled"
|
|
2928
2940
|
: currentValidationState === "positive"
|
|
2929
2941
|
? "text-feedback-ink-positive-intense"
|
|
2930
2942
|
: currentValidationState === "negative"
|
|
2931
2943
|
? "text-feedback-ink-negative-subtle"
|
|
2932
|
-
: "text-surface-ink-neutral-muted"), children: prefix })), jsx("input", { ref: ref, value: inputValue, onChange: handleChange, disabled: isDisabled, required: isRequired, className: cn("
|
|
2944
|
+
: "text-surface-ink-neutral-muted"), children: prefix })), jsx("input", { ref: ref, value: inputValue, onChange: handleChange, disabled: isDisabled, required: isRequired, className: cn("w-full bg-transparent border-none outline-none text-surface-ink-neutral-normal placeholder:text-surface-ink-neutral-muted disabled:cursor-not-allowed disabled:text-surface-ink-neutral-disabled", inputClassName), ...props }), showClearButton && hasValue && !isDisabled && (jsx("button", { type: "button", onClick: handleClear, className: "shrink-0 flex items-center justify-center text-surface-ink-neutral-muted hover:text-surface-ink-neutral-normal transition-colors", tabIndex: -1, children: jsx("svg", { width: "16", height: "16", viewBox: "0 0 16 16", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: jsx("path", { d: "M12 4L4 12M4 4L12 12", stroke: "currentColor", strokeWidth: "1.5", strokeLinecap: "round" }) }) })), suffix && (jsx("span", { className: cn("shrink-0 flex items-center", isDisabled
|
|
2933
2945
|
? "text-surface-ink-neutral-disabled"
|
|
2934
2946
|
: currentValidationState === "positive"
|
|
2935
2947
|
? "text-feedback-ink-positive-intense"
|
|
@@ -3105,7 +3117,7 @@ const Select = React.forwardRef(({ className, options = [], value: controlledVal
|
|
|
3105
3117
|
// Build the suffix: include both the optional suffix and the chevron icon
|
|
3106
3118
|
const chevronIcon = (jsx(Icon, { name: isOpen ? "chevronUp" : "chevronDown", size: 16, className: "shrink-0 transition-colors" }));
|
|
3107
3119
|
const displaySuffix = suffix ? (jsxs(Fragment, { children: [suffix, chevronIcon] })) : (chevronIcon);
|
|
3108
|
-
return (jsxs("div", { ref: containerRef, className: "relative", children: [jsx(TextField, { ref: inputRef, label: label, helperText: helperText, errorText: errorText, successText: successText, validationState: validationState, isDisabled: isDisabled, isRequired: isRequired, isOptional: isOptional, isLoading: isLoading, size: size, prefix: displayPrefix, suffix: displaySuffix, showClearButton: showClearButton && hasValue && !isLoading, onClear: handleClear, placeholder: placeholder, value: displayValue, readOnly: true, containerClassName: containerClassName, labelClassName: labelClassName, className: cn("cursor-pointer", triggerClassName, className), inputClassName: "cursor-pointer", infoHeading: infoHeading, infoDescription: infoDescription, LinkComponent: LinkComponent, linkText: linkText, linkHref: linkHref, onLinkClick: onLinkClick, onClick: toggleOpen, onKeyDown: handleKeyDown, role: "combobox", "aria-haspopup": "listbox", "aria-expanded": isOpen, ...props }), isOpen && !isDisabled && !isLoading && (jsx("div", { ref: dropdownContainerRef, className: cn("absolute z-50 left-0 right-0", dropdownPlacement === "bottom"
|
|
3120
|
+
return (jsxs("div", { ref: containerRef, className: "relative w-full", children: [jsx(TextField, { ref: inputRef, label: label, helperText: helperText, errorText: errorText, successText: successText, validationState: validationState, isDisabled: isDisabled, isRequired: isRequired, isOptional: isOptional, isLoading: isLoading, size: size, prefix: displayPrefix, suffix: displaySuffix, showClearButton: showClearButton && hasValue && !isLoading, onClear: handleClear, placeholder: placeholder, value: displayValue, readOnly: true, containerClassName: cn("w-full", containerClassName), labelClassName: labelClassName, className: cn("cursor-pointer", triggerClassName, className), inputClassName: "cursor-pointer", infoHeading: infoHeading, infoDescription: infoDescription, LinkComponent: LinkComponent, linkText: linkText, linkHref: linkHref, onLinkClick: onLinkClick, onClick: toggleOpen, onKeyDown: handleKeyDown, role: "combobox", "aria-haspopup": "listbox", "aria-expanded": isOpen, ...props }), isOpen && !isDisabled && !isLoading && (jsx("div", { ref: dropdownContainerRef, className: cn("absolute z-50 left-0 right-0", dropdownPlacement === "bottom"
|
|
3109
3121
|
? "top-full mt-1"
|
|
3110
3122
|
: "bottom-full mb-1"), children: jsx(DropdownMenu, { items: menuItems, sectionHeading: sectionHeading, isEmpty: options.length === 0, emptyTitle: emptyTitle, emptyDescription: emptyDescription, emptyIcon: emptyIcon, disableFooter: true, onClose: () => handleOpenChange(false), className: menuClassName, width: widthStyle }) }))] }));
|
|
3111
3123
|
});
|
|
@@ -3227,21 +3239,21 @@ const Pagination = React.forwardRef(({ className, currentPage: controlledCurrent
|
|
|
3227
3239
|
return [];
|
|
3228
3240
|
};
|
|
3229
3241
|
const pageNumbers = getPageNumbers();
|
|
3230
|
-
return (jsxs("div", { ref: ref, className: cn(paginationVariants({ size }), className), ...props, children: [showRowsPerPage && (jsxs("div", { className: "flex items-center gap-3", children: [jsx("span", { className: "text-surface-ink-neutral-muted whitespace-nowrap", children: rowsPerPageLabel }), jsx("div", { className: "w-[80px]", children: jsx(Select, { value: rowsPerPage.toString(), options: rowsPerPageSelectOptions, onChange: handleRowsPerPageChange, size: selectSize, isDisabled: isDisabled, menuWidth: "auto" }) })] })), jsxs("div", { className: "flex items-center gap-3 ml-auto", children: [showPrevNext && (jsx(Button, { variant: "tertiary", color: "neutral", size: buttonSize, onClick: handlePrevPage, isDisabled: isPrevDisabled, leadingIcon: jsx(
|
|
3242
|
+
return (jsxs("div", { ref: ref, className: cn(paginationVariants({ size }), className), ...props, children: [showRowsPerPage && (jsxs("div", { className: "flex items-center gap-3", children: [jsx("span", { className: "text-surface-ink-neutral-muted whitespace-nowrap", children: rowsPerPageLabel }), jsx("div", { className: "w-[80px]", children: jsx(Select, { value: rowsPerPage.toString(), options: rowsPerPageSelectOptions, onChange: handleRowsPerPageChange, size: selectSize, isDisabled: isDisabled, menuWidth: "auto" }) })] })), jsxs("div", { className: "flex items-center gap-3 ml-auto", children: [showPrevNext && (jsx(Button, { variant: "tertiary", color: "neutral", size: buttonSize, onClick: handlePrevPage, isDisabled: isPrevDisabled, leadingIcon: jsx(Icon, { name: "chevronLeft", size: 16 }), "aria-label": "Previous page", children: prevLabel })), showPageJumper ? (
|
|
3231
3243
|
// Show page dropdown selector
|
|
3232
3244
|
jsxs("div", { className: "flex items-center gap-3", children: [jsx("div", { className: "w-[80px]", children: jsx(Select, { value: currentPage.toString(), options: pageOptions, onChange: (value) => handlePageChange(typeof value === "string" ? parseInt(value) : value), size: selectSize, isDisabled: isDisabled, menuWidth: "auto" }) }), jsxs("span", { className: "text-surface-ink-neutral-muted whitespace-nowrap", children: [ofLabel, " ", totalPages] })] })) : (
|
|
3233
3245
|
// Show numbered page buttons
|
|
3234
3246
|
showPageNumber &&
|
|
3235
|
-
pageNumbers.length > 0 && (jsx(ButtonGroup, { variant: "separated", size: buttonSize, isDisabled: isDisabled, value: currentPage, onChange: (value) => handlePageChange(value), children: pageNumbers.map((pageNum) => (jsx(Button, { value: pageNum, variant: "tertiary", color: "primary", "aria-label": `Page ${pageNum}`, "aria-current": pageNum === currentPage ? "page" : undefined, children: pageNum }, pageNum))) }))), showPrevNext && (jsx(Button, { variant: "tertiary", color: "neutral", size: buttonSize, onClick: handleNextPage, isDisabled: isNextDisabled, trailingIcon: jsx(
|
|
3247
|
+
pageNumbers.length > 0 && (jsx(ButtonGroup, { variant: "separated", size: buttonSize, isDisabled: isDisabled, value: currentPage, onChange: (value) => handlePageChange(value), children: pageNumbers.map((pageNum) => (jsx(Button, { value: pageNum, variant: "tertiary", color: "primary", "aria-label": `Page ${pageNum}`, "aria-current": pageNum === currentPage ? "page" : undefined, children: pageNum }, pageNum))) }))), showPrevNext && (jsx(Button, { variant: "tertiary", color: "neutral", size: buttonSize, onClick: handleNextPage, isDisabled: isNextDisabled, trailingIcon: jsx(Icon, { name: "chevronRight", size: 16 }), "aria-label": "Next page", children: nextLabel }))] })] }));
|
|
3236
3248
|
});
|
|
3237
3249
|
Pagination.displayName = "Pagination";
|
|
3238
3250
|
|
|
3239
3251
|
const radioVariants = cva("relative inline-flex items-center justify-center shrink-0 border transition-all cursor-pointer rounded-full", {
|
|
3240
3252
|
variants: {
|
|
3241
3253
|
size: {
|
|
3242
|
-
small: "w-[
|
|
3243
|
-
medium: "w-[
|
|
3244
|
-
large: "w-[
|
|
3254
|
+
small: "w-[10px] h-[10px] border-[1.5px]",
|
|
3255
|
+
medium: "w-[12px] h-[12px] border-[1.5px]",
|
|
3256
|
+
large: "w-[16px] h-[16px] border-[2px]",
|
|
3245
3257
|
},
|
|
3246
3258
|
validationState: {
|
|
3247
3259
|
none: "",
|
|
@@ -3366,17 +3378,20 @@ const Radio = React.forwardRef(({ label, errorText, size = "medium", validationS
|
|
|
3366
3378
|
small: {
|
|
3367
3379
|
gap: "gap-2",
|
|
3368
3380
|
labelSize: "text-body-small-regular",
|
|
3369
|
-
innerCircleSize:
|
|
3381
|
+
innerCircleSize: 4,
|
|
3382
|
+
boundingBoxSize: "w-[14px] h-[14px] p-1",
|
|
3370
3383
|
},
|
|
3371
3384
|
medium: {
|
|
3372
3385
|
gap: "gap-2.5",
|
|
3373
3386
|
labelSize: "text-body-medium-regular",
|
|
3374
|
-
innerCircleSize:
|
|
3387
|
+
innerCircleSize: 5,
|
|
3388
|
+
boundingBoxSize: "w-[16px] h-[16px] p-1",
|
|
3375
3389
|
},
|
|
3376
3390
|
large: {
|
|
3377
3391
|
gap: "gap-3",
|
|
3378
3392
|
labelSize: "text-body-large-regular",
|
|
3379
|
-
innerCircleSize:
|
|
3393
|
+
innerCircleSize: 7,
|
|
3394
|
+
boundingBoxSize: "w-[20px] h-[20px] p-1",
|
|
3380
3395
|
},
|
|
3381
3396
|
};
|
|
3382
3397
|
const config = sizeConfig[size];
|
|
@@ -3386,16 +3401,16 @@ const Radio = React.forwardRef(({ label, errorText, size = "medium", validationS
|
|
|
3386
3401
|
? "bg-action-outline-negative-faded"
|
|
3387
3402
|
: "bg-action-outline-primary-faded"), style: {
|
|
3388
3403
|
animation: "var(--animate-checkbox-ripple)",
|
|
3389
|
-
} })), jsx("div", { className: cn(radioVariants({
|
|
3390
|
-
|
|
3391
|
-
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3395
|
-
|
|
3396
|
-
|
|
3397
|
-
|
|
3398
|
-
|
|
3404
|
+
} })), jsx("div", { className: cn("inline-flex items-center justify-center shrink-0 box-border", config.boundingBoxSize), children: jsx("div", { className: cn(radioVariants({
|
|
3405
|
+
size,
|
|
3406
|
+
validationState,
|
|
3407
|
+
isChecked,
|
|
3408
|
+
isDisabled,
|
|
3409
|
+
isFocused,
|
|
3410
|
+
}), className), children: isChecked && (jsx("div", { className: "rounded-full bg-white transition-all box-border", style: {
|
|
3411
|
+
width: `${config.innerCircleSize}px`,
|
|
3412
|
+
height: `${config.innerCircleSize}px`,
|
|
3413
|
+
} })) }) })] }), label && (jsx("label", { className: cn(config.labelSize, "select-none inline-flex items-center", isDisabled
|
|
3399
3414
|
? "text-surface-ink-neutral-disabled"
|
|
3400
3415
|
: "text-surface-ink-neutral-normal", labelClassName), children: label }))] }), shouldShowError && (jsx(FormFooter, { helperText: errorText, validationState: "negative", size: size, isDisabled: isDisabled }))] }));
|
|
3401
3416
|
});
|
|
@@ -4172,31 +4187,73 @@ const switchVariants = cva("relative inline-flex items-center shrink-0 cursor-po
|
|
|
4172
4187
|
medium: "w-[28px] h-[16px]",
|
|
4173
4188
|
large: "w-[36px] h-[20px]",
|
|
4174
4189
|
},
|
|
4190
|
+
validationState: {
|
|
4191
|
+
none: "",
|
|
4192
|
+
error: "",
|
|
4193
|
+
},
|
|
4175
4194
|
isChecked: {
|
|
4176
|
-
true: "
|
|
4177
|
-
false: "
|
|
4195
|
+
true: "",
|
|
4196
|
+
false: "",
|
|
4178
4197
|
},
|
|
4179
4198
|
isDisabled: {
|
|
4180
4199
|
true: "cursor-not-allowed opacity-60",
|
|
4181
4200
|
false: "",
|
|
4182
4201
|
},
|
|
4202
|
+
isFocused: {
|
|
4203
|
+
true: "",
|
|
4204
|
+
false: "",
|
|
4205
|
+
},
|
|
4183
4206
|
},
|
|
4184
4207
|
compoundVariants: [
|
|
4208
|
+
// Unchecked state - none validation
|
|
4209
|
+
{
|
|
4210
|
+
isChecked: false,
|
|
4211
|
+
validationState: "none",
|
|
4212
|
+
isDisabled: false,
|
|
4213
|
+
class: "bg-surface-fill-neutral-subtle hover:bg-action-fill-neutral-faded",
|
|
4214
|
+
},
|
|
4215
|
+
// Checked state - none validation
|
|
4185
4216
|
{
|
|
4186
4217
|
isChecked: true,
|
|
4218
|
+
validationState: "none",
|
|
4187
4219
|
isDisabled: false,
|
|
4188
|
-
class: "hover:bg-action-fill-primary-hover
|
|
4220
|
+
class: "bg-action-fill-primary-default hover:bg-action-fill-primary-hover",
|
|
4189
4221
|
},
|
|
4222
|
+
// Checked state - error validation
|
|
4223
|
+
{
|
|
4224
|
+
isChecked: true,
|
|
4225
|
+
validationState: "error",
|
|
4226
|
+
isDisabled: false,
|
|
4227
|
+
class: "bg-action-fill-negative-default hover:bg-action-fill-negative-hover",
|
|
4228
|
+
},
|
|
4229
|
+
// Unchecked state - error validation
|
|
4190
4230
|
{
|
|
4191
4231
|
isChecked: false,
|
|
4232
|
+
validationState: "error",
|
|
4192
4233
|
isDisabled: false,
|
|
4193
|
-
class: "hover:bg-action-fill-neutral-faded",
|
|
4234
|
+
class: "bg-surface-fill-neutral-subtle hover:bg-action-fill-neutral-faded",
|
|
4235
|
+
},
|
|
4236
|
+
// Focused state - none validation
|
|
4237
|
+
{
|
|
4238
|
+
isFocused: true,
|
|
4239
|
+
validationState: "none",
|
|
4240
|
+
isDisabled: false,
|
|
4241
|
+
class: "ring-2 ring-action-outline-primary-faded",
|
|
4242
|
+
},
|
|
4243
|
+
// Focused state - error validation
|
|
4244
|
+
{
|
|
4245
|
+
isFocused: true,
|
|
4246
|
+
validationState: "error",
|
|
4247
|
+
isDisabled: false,
|
|
4248
|
+
class: "ring-2 ring-action-outline-negative-faded",
|
|
4194
4249
|
},
|
|
4195
4250
|
],
|
|
4196
4251
|
defaultVariants: {
|
|
4197
4252
|
size: "medium",
|
|
4253
|
+
validationState: "none",
|
|
4198
4254
|
isChecked: false,
|
|
4199
4255
|
isDisabled: false,
|
|
4256
|
+
isFocused: false,
|
|
4200
4257
|
},
|
|
4201
4258
|
});
|
|
4202
4259
|
const switchThumbVariants = cva("inline-block rounded-full bg-white shadow-sm transition-transform duration-200", {
|
|
@@ -4251,8 +4308,10 @@ const switchThumbVariants = cva("inline-block rounded-full bg-white shadow-sm tr
|
|
|
4251
4308
|
isChecked: false,
|
|
4252
4309
|
},
|
|
4253
4310
|
});
|
|
4254
|
-
const Switch = React.forwardRef(({ label, size = "medium", isDisabled = false, containerClassName, labelClassName, trackClassName, thumbClassName, className, checked, onChange, ...props }, ref) => {
|
|
4311
|
+
const Switch = React.forwardRef(({ label, errorText, size = "medium", validationState = "none", isDisabled = false, showErrorText = true, containerClassName, labelClassName, trackClassName, thumbClassName, className, checked, onChange, ...props }, ref) => {
|
|
4255
4312
|
const [internalChecked, setInternalChecked] = React.useState(false);
|
|
4313
|
+
const [showRipple, setShowRipple] = React.useState(false);
|
|
4314
|
+
const [isFocused, setIsFocused] = React.useState(false);
|
|
4256
4315
|
const inputRef = React.useRef(null);
|
|
4257
4316
|
// Use forwarded ref or internal ref
|
|
4258
4317
|
React.useImperativeHandle(ref, () => inputRef.current);
|
|
@@ -4265,17 +4324,35 @@ const Switch = React.forwardRef(({ label, size = "medium", isDisabled = false, c
|
|
|
4265
4324
|
setInternalChecked(e.target.checked);
|
|
4266
4325
|
}
|
|
4267
4326
|
};
|
|
4327
|
+
const triggerRipple = () => {
|
|
4328
|
+
if (!isDisabled) {
|
|
4329
|
+
setShowRipple(true);
|
|
4330
|
+
setTimeout(() => {
|
|
4331
|
+
setShowRipple(false);
|
|
4332
|
+
}, 360); // Match animation duration (0.36s)
|
|
4333
|
+
}
|
|
4334
|
+
};
|
|
4268
4335
|
const handleContainerClick = () => {
|
|
4269
4336
|
if (!isDisabled && inputRef.current) {
|
|
4337
|
+
triggerRipple();
|
|
4270
4338
|
inputRef.current.click();
|
|
4271
4339
|
}
|
|
4272
4340
|
};
|
|
4273
4341
|
const handleKeyDown = (e) => {
|
|
4274
4342
|
if ((e.key === " " || e.key === "Enter") && !isDisabled) {
|
|
4275
4343
|
e.preventDefault();
|
|
4344
|
+
triggerRipple();
|
|
4276
4345
|
inputRef.current?.click();
|
|
4277
4346
|
}
|
|
4278
4347
|
};
|
|
4348
|
+
const handleFocus = () => {
|
|
4349
|
+
if (!isDisabled) {
|
|
4350
|
+
setIsFocused(true);
|
|
4351
|
+
}
|
|
4352
|
+
};
|
|
4353
|
+
const handleBlur = () => {
|
|
4354
|
+
setIsFocused(false);
|
|
4355
|
+
};
|
|
4279
4356
|
// Size-based configurations
|
|
4280
4357
|
const sizeConfig = {
|
|
4281
4358
|
small: {
|
|
@@ -4292,16 +4369,24 @@ const Switch = React.forwardRef(({ label, size = "medium", isDisabled = false, c
|
|
|
4292
4369
|
},
|
|
4293
4370
|
};
|
|
4294
4371
|
const config = sizeConfig[size];
|
|
4295
|
-
|
|
4296
|
-
|
|
4297
|
-
|
|
4298
|
-
|
|
4299
|
-
|
|
4300
|
-
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4372
|
+
// Determine if we should show the error text
|
|
4373
|
+
const shouldShowError = errorText && showErrorText;
|
|
4374
|
+
return (jsxs("div", { className: cn("inline-flex flex-col", containerClassName), children: [jsxs("div", { className: cn("inline-flex items-center", config.gap, isDisabled ? "cursor-not-allowed" : "cursor-pointer"), onClick: handleContainerClick, onKeyDown: handleKeyDown, onFocus: handleFocus, onBlur: handleBlur, role: "switch", "aria-checked": isChecked, "aria-disabled": isDisabled, tabIndex: isDisabled ? -1 : 0, children: [jsx("input", { ref: inputRef, type: "checkbox", role: "switch", className: "sr-only", checked: isChecked, onChange: handleChange, disabled: isDisabled, ...props }), jsxs("div", { className: "relative inline-flex shrink-0", children: [showRipple && (jsx("div", { className: cn("absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 rounded-full pointer-events-none w-full h-full", validationState === "error"
|
|
4375
|
+
? "bg-action-outline-negative-faded"
|
|
4376
|
+
: "bg-action-outline-primary-faded"), style: {
|
|
4377
|
+
animation: "var(--animate-checkbox-ripple)",
|
|
4378
|
+
} })), jsx("div", { className: cn(switchVariants({
|
|
4379
|
+
size,
|
|
4380
|
+
validationState,
|
|
4381
|
+
isChecked,
|
|
4382
|
+
isDisabled,
|
|
4383
|
+
isFocused,
|
|
4384
|
+
}), trackClassName, className), children: jsx("span", { className: cn(switchThumbVariants({
|
|
4385
|
+
size,
|
|
4386
|
+
isChecked,
|
|
4387
|
+
}), thumbClassName) }) })] }), label && (jsx("label", { className: cn(config.labelSize, "select-none inline-flex items-center", isDisabled
|
|
4388
|
+
? "text-surface-ink-neutral-disabled"
|
|
4389
|
+
: "text-surface-ink-neutral-normal", labelClassName), children: label }))] }), shouldShowError && (jsx(FormFooter, { helperText: errorText, validationState: "negative", size: size, isDisabled: isDisabled }))] }));
|
|
4305
4390
|
});
|
|
4306
4391
|
Switch.displayName = "Switch";
|
|
4307
4392
|
|