@fuf-stack/uniform 0.9.5 → 0.9.6
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/CheckboxGroup/index.cjs +3 -3
- package/dist/CheckboxGroup/index.d.cts +5 -2
- package/dist/CheckboxGroup/index.d.ts +5 -2
- package/dist/CheckboxGroup/index.js +2 -2
- package/dist/CheckboxGroup-o-qWkWe1.d.cts +130 -0
- package/dist/CheckboxGroup-o-qWkWe1.d.ts +130 -0
- package/dist/FieldArray/index.cjs +3 -3
- package/dist/FieldArray/index.js +2 -2
- package/dist/{FieldValidationError-BSXedjCA.d.cts → FieldValidationError-DAT12Ess.d.cts} +2 -1
- package/dist/{FieldValidationError-BSXedjCA.d.ts → FieldValidationError-DAT12Ess.d.ts} +2 -1
- package/dist/Input/index.cjs +3 -3
- package/dist/Input/index.js +2 -2
- package/dist/RadioGroup/index.cjs +3 -3
- package/dist/RadioGroup/index.d.cts +5 -2
- package/dist/RadioGroup/index.d.ts +5 -2
- package/dist/RadioGroup/index.js +2 -2
- package/dist/RadioGroup-D_kiBt0M.d.cts +162 -0
- package/dist/RadioGroup-D_kiBt0M.d.ts +162 -0
- package/dist/Select/index.cjs +3 -3
- package/dist/Select/index.d.cts +3 -3
- package/dist/Select/index.d.ts +3 -3
- package/dist/Select/index.js +2 -2
- package/dist/Select-BhS4z0Pj.d.cts +317 -0
- package/dist/Select-BhS4z0Pj.d.ts +317 -0
- package/dist/Switch/index.cjs +3 -3
- package/dist/Switch/index.d.cts +5 -2
- package/dist/Switch/index.d.ts +5 -2
- package/dist/Switch/index.js +2 -2
- package/dist/Switch-Fdldj8LV.d.cts +126 -0
- package/dist/Switch-Fdldj8LV.d.ts +126 -0
- package/dist/TextArea/index.cjs +3 -3
- package/dist/TextArea/index.js +2 -2
- package/dist/{chunk-OCR2UWG2.cjs → chunk-4RTJ5XR2.cjs} +3 -3
- package/dist/{chunk-OCR2UWG2.cjs.map → chunk-4RTJ5XR2.cjs.map} +1 -1
- package/dist/{chunk-YUAJN6HW.cjs → chunk-6HMMXOSV.cjs} +48 -15
- package/dist/chunk-6HMMXOSV.cjs.map +1 -0
- package/dist/{chunk-FMQNL3RT.js → chunk-F7GG67YU.js} +2 -2
- package/dist/{chunk-W24WP5YE.cjs → chunk-HFMFDBEV.cjs} +46 -14
- package/dist/chunk-HFMFDBEV.cjs.map +1 -0
- package/dist/{chunk-NHPQEYYN.js → chunk-HOCRJOEU.js} +2 -2
- package/dist/{chunk-TNELIBCV.cjs → chunk-JDRMKZ35.cjs} +4 -4
- package/dist/{chunk-TNELIBCV.cjs.map → chunk-JDRMKZ35.cjs.map} +1 -1
- package/dist/{chunk-4AHVJWTB.js → chunk-JG5VQZ4V.js} +46 -14
- package/dist/chunk-JG5VQZ4V.js.map +1 -0
- package/dist/{chunk-5UHHZ7KY.cjs → chunk-JRFKYVXY.cjs} +3 -3
- package/dist/{chunk-5UHHZ7KY.cjs.map → chunk-JRFKYVXY.cjs.map} +1 -1
- package/dist/chunk-LDW7K7LW.js +231 -0
- package/dist/chunk-LDW7K7LW.js.map +1 -0
- package/dist/{chunk-INTLZONV.cjs → chunk-NQ4JZ7AK.cjs} +37 -15
- package/dist/chunk-NQ4JZ7AK.cjs.map +1 -0
- package/dist/{chunk-QVBZ5RLN.cjs → chunk-NXTXKBTP.cjs} +104 -113
- package/dist/chunk-NXTXKBTP.cjs.map +1 -0
- package/dist/{chunk-QTL5FREE.cjs → chunk-OHJYXA6R.cjs} +7 -5
- package/dist/chunk-OHJYXA6R.cjs.map +1 -0
- package/dist/{chunk-AVKEYJH7.js → chunk-PFX4YRWI.js} +38 -16
- package/dist/chunk-PFX4YRWI.js.map +1 -0
- package/dist/{chunk-DTSX7YON.js → chunk-SCTH3FAO.js} +2 -2
- package/dist/{chunk-DBLODROX.js → chunk-WKM2D7LF.js} +7 -5
- package/dist/chunk-WKM2D7LF.js.map +1 -0
- package/dist/{chunk-ARUVDZFG.js → chunk-YSZW33OV.js} +48 -15
- package/dist/chunk-YSZW33OV.js.map +1 -0
- package/dist/index.cjs +9 -9
- package/dist/index.d.cts +8 -8
- package/dist/index.d.ts +8 -8
- package/dist/index.js +10 -10
- package/dist/partials/FieldValidationError/index.cjs +2 -2
- package/dist/partials/FieldValidationError/index.d.cts +2 -2
- package/dist/partials/FieldValidationError/index.d.ts +2 -2
- package/dist/partials/FieldValidationError/index.js +1 -1
- package/package.json +4 -4
- package/dist/CheckboxGroup-BYsQ0A0q.d.cts +0 -32
- package/dist/CheckboxGroup-BYsQ0A0q.d.ts +0 -32
- package/dist/RadioGroup-BU4K9cnS.d.cts +0 -40
- package/dist/RadioGroup-BU4K9cnS.d.ts +0 -40
- package/dist/Select-C08Oftdr.d.cts +0 -184
- package/dist/Select-C08Oftdr.d.ts +0 -184
- package/dist/Switch-OkO3GdPy.d.cts +0 -20
- package/dist/Switch-OkO3GdPy.d.ts +0 -20
- package/dist/chunk-4AHVJWTB.js.map +0 -1
- package/dist/chunk-ARUVDZFG.js.map +0 -1
- package/dist/chunk-AVKEYJH7.js.map +0 -1
- package/dist/chunk-DBLODROX.js.map +0 -1
- package/dist/chunk-I5M2A3MN.js +0 -240
- package/dist/chunk-I5M2A3MN.js.map +0 -1
- package/dist/chunk-INTLZONV.cjs.map +0 -1
- package/dist/chunk-QTL5FREE.cjs.map +0 -1
- package/dist/chunk-QVBZ5RLN.cjs.map +0 -1
- package/dist/chunk-W24WP5YE.cjs.map +0 -1
- package/dist/chunk-YUAJN6HW.cjs.map +0 -1
- /package/dist/{chunk-FMQNL3RT.js.map → chunk-F7GG67YU.js.map} +0 -0
- /package/dist/{chunk-NHPQEYYN.js.map → chunk-HOCRJOEU.js.map} +0 -0
- /package/dist/{chunk-DTSX7YON.js.map → chunk-SCTH3FAO.js.map} +0 -0
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var _chunkKMMS4G7Acjs = require('./chunk-KMMS4G7A.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkOHJYXA6Rcjs = require('./chunk-OHJYXA6R.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
var _chunkLDCRR7FPcjs = require('./chunk-LDCRR7FP.cjs');
|
|
@@ -44,7 +44,7 @@ var Input = ({
|
|
|
44
44
|
},
|
|
45
45
|
"data-testid": testId,
|
|
46
46
|
endContent,
|
|
47
|
-
errorMessage: error && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
47
|
+
errorMessage: error && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkOHJYXA6Rcjs.FieldValidationError_default, { error }),
|
|
48
48
|
isDisabled,
|
|
49
49
|
isInvalid: invalid,
|
|
50
50
|
isRequired: required,
|
|
@@ -78,4 +78,4 @@ var Input_default2 = Input_default;
|
|
|
78
78
|
|
|
79
79
|
|
|
80
80
|
exports.Input_default = Input_default; exports.Input_default2 = Input_default2;
|
|
81
|
-
//# sourceMappingURL=chunk-
|
|
81
|
+
//# sourceMappingURL=chunk-JRFKYVXY.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-JRFKYVXY.cjs","../src/Input/Input.tsx","../src/Input/index.ts"],"names":["Input_default"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACRA,gDAA2B;AAE3B,0CAAmC;AAEnC,oDAAmB;AA4DgB,+CAAA;AA9BnC,IAAM,MAAA,EAAQ,CAAC;AAAA,EACb,UAAA,EAAY,KAAA,CAAA;AAAA,EACZ,SAAA,EAAW,KAAA;AAAA,EACX,WAAA,EAAa,KAAA,CAAA;AAAA,EACb,MAAA,EAAQ,KAAA,CAAA;AAAA,EACR,IAAA;AAAA,EACA,YAAA,EAAc,GAAA;AAAA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A;AAAA,YACP,GAAA;AAAA,YACA,YAAA;AAAA,YACA,IAAA;AAAA,YACA,KAAA;AAAA,YACA,OAAA,EAAQ;AAAA,UAAA;AAAA,QACV,CAAA;AAAA,MAEJ;AAAA,IAAA;AAAA,EACF,CAAA;AAEJ,CAAA;AAEA,IAAO,cAAA,EAAQ,KAAA;ADtBf;AACA;AEnEA,IAAOA,eAAAA,EAAQ,aAAA;AFqEf;AACA;AACE;AACA;AACF,+EAAC","file":"/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-JRFKYVXY.cjs","sourcesContent":[null,"import type { ReactNode } from 'react';\n\nimport { Controller } from 'react-hook-form';\n\nimport { Input as NextInput } from '@nextui-org/input';\n\nimport { cn } from '@fuf-stack/pixel-utils';\n\nimport { useFormContext } from '../hooks';\nimport { FieldCopyTestIdButton } from '../partials/FieldCopyTestIdButton';\nimport { FieldValidationError } from '../partials/FieldValidationError';\n\nexport interface InputProps {\n /** CSS class name */\n className?: string;\n /** input field is disabled */\n disabled?: boolean;\n /** added content to the end of the input Field. */\n endContent?: ReactNode;\n /** form field label (set to false to disable label) */\n label?: string | false;\n /** form field name */\n name: string;\n /** form field placeholder */\n placeholder?: string;\n /** content added to the start of the input field */\n startContent?: ReactNode;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n /** input type */\n type?: 'number' | 'password';\n}\n\n/**\n * Input component based on [NextUI Input](https://nextui.org/docs/components/input)\n */\nconst Input = ({\n className = undefined,\n disabled = false,\n endContent = undefined,\n label = undefined,\n name,\n placeholder = ' ',\n startContent = undefined,\n testId: _testId = undefined,\n type = undefined,\n}: InputProps) => {\n const { control, getFieldState } = useFormContext();\n const { error, invalid, required, testId } = getFieldState(name, _testId);\n\n return (\n <Controller\n control={control}\n disabled={disabled}\n name={name}\n render={({\n field: { disabled: isDisabled, onChange, onBlur, value, ref },\n }) => {\n return (\n <NextInput\n className={cn(className)}\n classNames={{\n inputWrapper: 'group-data-[focus=true]:border-primary',\n }}\n data-testid={testId}\n endContent={endContent}\n errorMessage={error && <FieldValidationError error={error} />}\n isDisabled={isDisabled}\n isInvalid={invalid}\n isRequired={required}\n label={\n <>\n {label}\n <FieldCopyTestIdButton testId={testId} />\n </>\n }\n labelPlacement=\"outside\"\n name={name}\n onBlur={onBlur}\n onChange={onChange}\n placeholder={placeholder}\n radius=\"sm\"\n ref={ref}\n startContent={startContent}\n type={type}\n value={value}\n variant=\"bordered\"\n />\n );\n }}\n />\n );\n};\n\nexport default Input;\n","import Input from './Input';\n\nexport type { InputProps } from './Input';\n\nexport { Input };\n\nexport default Input;\n"]}
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FieldCopyTestIdButton_default
|
|
3
|
+
} from "./chunk-T3CCNJHK.js";
|
|
4
|
+
import {
|
|
5
|
+
FieldValidationError_default
|
|
6
|
+
} from "./chunk-WKM2D7LF.js";
|
|
7
|
+
import {
|
|
8
|
+
useFormContext
|
|
9
|
+
} from "./chunk-HWDQZO7X.js";
|
|
10
|
+
|
|
11
|
+
// src/Select/Select.tsx
|
|
12
|
+
import { useState } from "react";
|
|
13
|
+
import { Controller } from "react-hook-form";
|
|
14
|
+
import ReactSelect, { components } from "react-select";
|
|
15
|
+
import { useSelect } from "@nextui-org/select";
|
|
16
|
+
import { cn, tv, variantsToClassNames } from "@fuf-stack/pixel-utils";
|
|
17
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
18
|
+
var selectVariants = tv({
|
|
19
|
+
slots: {
|
|
20
|
+
base: "group",
|
|
21
|
+
clearIndicator: "rounded-md p-1 text-foreground-500 hover:cursor-pointer hover:bg-default-200 hover:text-foreground-800",
|
|
22
|
+
control: "rounded-lg border-2 border-default-200 !duration-150 transition-background hover:border-default-400 group-data-[invalid=true]:border-danger group-data-[invalid=true]:hover:border-danger motion-reduce:transition-none",
|
|
23
|
+
control_focused: "border-primary hover:border-primary",
|
|
24
|
+
crossIcon: "",
|
|
25
|
+
downChevron: "",
|
|
26
|
+
dropdownIndicator: "rounded-md p-1 text-foreground-500 hover:cursor-pointer hover:bg-default-200 hover:text-black",
|
|
27
|
+
group: "",
|
|
28
|
+
groupHeading: "mb-1 ml-3 mt-2 text-sm text-foreground-500",
|
|
29
|
+
indicatorsContainer: "gap-1 p-1",
|
|
30
|
+
indicatorSeparator: "bg-default-300",
|
|
31
|
+
input: "py-0.5 pl-1",
|
|
32
|
+
// See NextUI styles for group-data condition, e.g.: https://github.com/nextui-org/nextui/blob/main/packages/core/theme/src/components/select.ts
|
|
33
|
+
label: 'pointer-events-auto relative bottom-1.5 ml-1 text-small subpixel-antialiased group-data-[invalid=true]:!text-danger group-data-[required=true]:after:ml-0.5 group-data-[required=true]:after:text-danger group-data-[required=true]:after:content-["*"]',
|
|
34
|
+
loadingIndicator: "",
|
|
35
|
+
loadingMessage: "",
|
|
36
|
+
menu: "mt-2 rounded-xl border border-default-200 bg-content1 p-1 shadow-lg",
|
|
37
|
+
menuList: "",
|
|
38
|
+
// ensure menu has same z-index as modal so it is visible when rendered in modal
|
|
39
|
+
// see: https://github.com/nextui-org/nextui/blob/main/packages/core/theme/src/components/modal.ts (see z-50)
|
|
40
|
+
menuPortal: "!z-50",
|
|
41
|
+
multiValue: "items-center gap-1.5 rounded bg-default-100 py-0.5 pl-2 pr-1",
|
|
42
|
+
multiValueContainer: "",
|
|
43
|
+
multiValueLabel: "py-0.5 leading-6",
|
|
44
|
+
multiValueRemove: "rounded text-default-500 hover:cursor-pointer hover:border-default-300 hover:text-default-800",
|
|
45
|
+
noOptionsMessage: "rounded-sm p-2 text-foreground-500",
|
|
46
|
+
option_focused: "bg-default-100 active:bg-default-200",
|
|
47
|
+
option_selected: "bg-default-300",
|
|
48
|
+
option: "rounded px-3 py-2 hover:cursor-pointer",
|
|
49
|
+
placeholder: "py-0.5 pl-1 text-foreground-500",
|
|
50
|
+
selectContainer: "",
|
|
51
|
+
singleValue: "!ml-1 !leading-7",
|
|
52
|
+
valueContainer: "gap-1 p-1"
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
var InputComponent = (props) => {
|
|
56
|
+
const testId = `${props.selectProps["data-testid"]}_input`;
|
|
57
|
+
return /* @__PURE__ */ jsx(components.Input, { "data-testid": testId, ...props });
|
|
58
|
+
};
|
|
59
|
+
var OptionComponent = (props) => {
|
|
60
|
+
const testId = `${props.selectProps["data-testid"]}_option_${props?.data?.testId ?? props?.data?.value}`;
|
|
61
|
+
return /* @__PURE__ */ jsx("div", { "data-testid": testId, children: /* @__PURE__ */ jsx(components.Option, { ...props }) });
|
|
62
|
+
};
|
|
63
|
+
var DropdownIndicatorComponent = (props) => {
|
|
64
|
+
const testId = props?.selectProps["data-testid"];
|
|
65
|
+
return /* @__PURE__ */ jsx("div", { "data-testid": `${testId}_dropdown`, children: /* @__PURE__ */ jsx(components.DropdownIndicator, { ...props }) });
|
|
66
|
+
};
|
|
67
|
+
var Select = ({
|
|
68
|
+
className = void 0,
|
|
69
|
+
clearable = true,
|
|
70
|
+
disabled = false,
|
|
71
|
+
filterOption = void 0,
|
|
72
|
+
renderOptionLabel = void 0,
|
|
73
|
+
inputValue = void 0,
|
|
74
|
+
label: _label = void 0,
|
|
75
|
+
loading = false,
|
|
76
|
+
multiSelect = false,
|
|
77
|
+
name,
|
|
78
|
+
onInputChange = void 0,
|
|
79
|
+
options,
|
|
80
|
+
placeholder = void 0,
|
|
81
|
+
testId: _testId = void 0
|
|
82
|
+
}) => {
|
|
83
|
+
const { control, getFieldState } = useFormContext();
|
|
84
|
+
const { error, invalid, required, testId } = getFieldState(name, _testId);
|
|
85
|
+
const [isFocused, setIsFocused] = useState(false);
|
|
86
|
+
const variants = selectVariants();
|
|
87
|
+
const classNames = variantsToClassNames(variants, className, "base");
|
|
88
|
+
const {
|
|
89
|
+
getBaseProps,
|
|
90
|
+
getErrorMessageProps,
|
|
91
|
+
getHelperWrapperProps,
|
|
92
|
+
getLabelProps,
|
|
93
|
+
getTriggerProps,
|
|
94
|
+
getValueProps,
|
|
95
|
+
label
|
|
96
|
+
} = useSelect({
|
|
97
|
+
children: [],
|
|
98
|
+
classNames,
|
|
99
|
+
errorMessage: JSON.stringify(error),
|
|
100
|
+
isDisabled: disabled,
|
|
101
|
+
isInvalid: invalid,
|
|
102
|
+
isLoading: loading,
|
|
103
|
+
isRequired: required,
|
|
104
|
+
label: _label,
|
|
105
|
+
labelPlacement: "outside",
|
|
106
|
+
placeholder: " "
|
|
107
|
+
});
|
|
108
|
+
return /* @__PURE__ */ jsx(
|
|
109
|
+
Controller,
|
|
110
|
+
{
|
|
111
|
+
control,
|
|
112
|
+
name,
|
|
113
|
+
render: ({
|
|
114
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
115
|
+
field: { onChange, value, ref, onBlur }
|
|
116
|
+
}) => /* @__PURE__ */ jsxs(
|
|
117
|
+
"div",
|
|
118
|
+
{
|
|
119
|
+
...getBaseProps(),
|
|
120
|
+
className: cn(classNames.base),
|
|
121
|
+
"data-testid": testId,
|
|
122
|
+
"data-required": required,
|
|
123
|
+
children: [
|
|
124
|
+
label && /* @__PURE__ */ jsxs(
|
|
125
|
+
"label",
|
|
126
|
+
{
|
|
127
|
+
className: classNames.label,
|
|
128
|
+
"data-slot": "label",
|
|
129
|
+
htmlFor: `react-select-${name}-input`,
|
|
130
|
+
id: getLabelProps().id,
|
|
131
|
+
children: [
|
|
132
|
+
label,
|
|
133
|
+
/* @__PURE__ */ jsx(FieldCopyTestIdButton_default, { testId })
|
|
134
|
+
]
|
|
135
|
+
}
|
|
136
|
+
),
|
|
137
|
+
/* @__PURE__ */ jsx(
|
|
138
|
+
ReactSelect,
|
|
139
|
+
{
|
|
140
|
+
"aria-errormessage": "",
|
|
141
|
+
"aria-labelledby": getTriggerProps()["aria-labelledby"]?.split(" ")[1],
|
|
142
|
+
"aria-invalid": invalid,
|
|
143
|
+
classNames: {
|
|
144
|
+
control: () => cn(classNames.control, {
|
|
145
|
+
[classNames.control_focused]: isFocused && !invalid
|
|
146
|
+
}),
|
|
147
|
+
clearIndicator: () => classNames.clearIndicator,
|
|
148
|
+
dropdownIndicator: () => classNames.dropdownIndicator,
|
|
149
|
+
groupHeading: () => classNames.groupHeading,
|
|
150
|
+
indicatorsContainer: () => classNames.indicatorsContainer,
|
|
151
|
+
indicatorSeparator: () => classNames.indicatorSeparator,
|
|
152
|
+
input: () => classNames.input,
|
|
153
|
+
menu: () => classNames.menu,
|
|
154
|
+
menuList: () => classNames.menuList,
|
|
155
|
+
menuPortal: () => classNames.menuPortal,
|
|
156
|
+
multiValue: () => classNames.multiValue,
|
|
157
|
+
multiValueLabel: () => cn(classNames.multiValueLabel, `${getValueProps().className}`),
|
|
158
|
+
multiValueRemove: () => classNames.multiValueRemove,
|
|
159
|
+
noOptionsMessage: () => classNames.noOptionsMessage,
|
|
160
|
+
option: ({
|
|
161
|
+
isFocused: optionIsFocused,
|
|
162
|
+
isSelected: optionIsSelected
|
|
163
|
+
}) => cn(classNames.option, {
|
|
164
|
+
[classNames.option_focused]: optionIsFocused,
|
|
165
|
+
[classNames.option_selected]: optionIsSelected
|
|
166
|
+
}),
|
|
167
|
+
placeholder: () => classNames.placeholder,
|
|
168
|
+
singleValue: () => cn(classNames.singleValue, `${getValueProps().className}`),
|
|
169
|
+
valueContainer: () => classNames.valueContainer
|
|
170
|
+
},
|
|
171
|
+
components: {
|
|
172
|
+
Input: InputComponent,
|
|
173
|
+
Option: OptionComponent,
|
|
174
|
+
DropdownIndicator: DropdownIndicatorComponent
|
|
175
|
+
},
|
|
176
|
+
"data-testid": `${testId}_select`,
|
|
177
|
+
filterOption,
|
|
178
|
+
formatOptionLabel: renderOptionLabel,
|
|
179
|
+
inputValue,
|
|
180
|
+
instanceId: name,
|
|
181
|
+
isClearable: clearable,
|
|
182
|
+
isDisabled: disabled,
|
|
183
|
+
isLoading: loading,
|
|
184
|
+
isMulti: multiSelect,
|
|
185
|
+
name,
|
|
186
|
+
menuPosition: "fixed",
|
|
187
|
+
menuShouldBlockScroll: true,
|
|
188
|
+
options,
|
|
189
|
+
placeholder,
|
|
190
|
+
onBlur: (_e) => {
|
|
191
|
+
setIsFocused(false);
|
|
192
|
+
return onBlur();
|
|
193
|
+
},
|
|
194
|
+
onChange: (option) => {
|
|
195
|
+
if (multiSelect) {
|
|
196
|
+
const transformedOptions = [];
|
|
197
|
+
option?.forEach((o) => {
|
|
198
|
+
transformedOptions.push(o.value);
|
|
199
|
+
});
|
|
200
|
+
onChange(transformedOptions);
|
|
201
|
+
} else {
|
|
202
|
+
onChange(option && option.value);
|
|
203
|
+
}
|
|
204
|
+
},
|
|
205
|
+
onFocus: (_e) => {
|
|
206
|
+
setIsFocused(true);
|
|
207
|
+
},
|
|
208
|
+
onInputChange,
|
|
209
|
+
ref,
|
|
210
|
+
value: options.find((option) => option.value === value),
|
|
211
|
+
unstyled: true
|
|
212
|
+
}
|
|
213
|
+
),
|
|
214
|
+
error && // eslint-disable-next-line react/jsx-props-no-spreading
|
|
215
|
+
/* @__PURE__ */ jsx("div", { ...getHelperWrapperProps(), children: /* @__PURE__ */ jsx("div", { ...getErrorMessageProps(), children: /* @__PURE__ */ jsx(FieldValidationError_default, { error }) }) })
|
|
216
|
+
]
|
|
217
|
+
}
|
|
218
|
+
)
|
|
219
|
+
}
|
|
220
|
+
);
|
|
221
|
+
};
|
|
222
|
+
var Select_default = Select;
|
|
223
|
+
|
|
224
|
+
// src/Select/index.ts
|
|
225
|
+
var Select_default2 = Select_default;
|
|
226
|
+
|
|
227
|
+
export {
|
|
228
|
+
Select_default,
|
|
229
|
+
Select_default2
|
|
230
|
+
};
|
|
231
|
+
//# sourceMappingURL=chunk-LDW7K7LW.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/Select/Select.tsx","../src/Select/index.ts"],"sourcesContent":["import type { TVClassName, TVProps } from '@fuf-stack/pixel-utils';\nimport type { Props } from 'react-select';\n\nimport { useState } from 'react';\nimport { Controller } from 'react-hook-form';\nimport ReactSelect, { components } from 'react-select';\n\nimport { useSelect } from '@nextui-org/select';\n\nimport { cn, tv, variantsToClassNames } from '@fuf-stack/pixel-utils';\n\nimport { useFormContext } from '../hooks';\nimport { FieldCopyTestIdButton } from '../partials/FieldCopyTestIdButton';\nimport { FieldValidationError } from '../partials/FieldValidationError';\n\nexport const selectVariants = tv({\n slots: {\n base: 'group',\n clearIndicator:\n 'rounded-md p-1 text-foreground-500 hover:cursor-pointer hover:bg-default-200 hover:text-foreground-800',\n control:\n 'rounded-lg border-2 border-default-200 !duration-150 transition-background hover:border-default-400 group-data-[invalid=true]:border-danger group-data-[invalid=true]:hover:border-danger motion-reduce:transition-none',\n control_focused: 'border-primary hover:border-primary',\n crossIcon: '',\n downChevron: '',\n dropdownIndicator:\n 'rounded-md p-1 text-foreground-500 hover:cursor-pointer hover:bg-default-200 hover:text-black',\n group: '',\n groupHeading: 'mb-1 ml-3 mt-2 text-sm text-foreground-500',\n indicatorsContainer: 'gap-1 p-1',\n indicatorSeparator: 'bg-default-300',\n input: 'py-0.5 pl-1',\n // See NextUI styles for group-data condition, e.g.: https://github.com/nextui-org/nextui/blob/main/packages/core/theme/src/components/select.ts\n label:\n 'pointer-events-auto relative bottom-1.5 ml-1 text-small subpixel-antialiased group-data-[invalid=true]:!text-danger group-data-[required=true]:after:ml-0.5 group-data-[required=true]:after:text-danger group-data-[required=true]:after:content-[\"*\"]',\n loadingIndicator: '',\n loadingMessage: '',\n menu: 'mt-2 rounded-xl border border-default-200 bg-content1 p-1 shadow-lg',\n menuList: '',\n // ensure menu has same z-index as modal so it is visible when rendered in modal\n // see: https://github.com/nextui-org/nextui/blob/main/packages/core/theme/src/components/modal.ts (see z-50)\n menuPortal: '!z-50',\n multiValue: 'items-center gap-1.5 rounded bg-default-100 py-0.5 pl-2 pr-1',\n multiValueContainer: '',\n multiValueLabel: 'py-0.5 leading-6',\n multiValueRemove:\n 'rounded text-default-500 hover:cursor-pointer hover:border-default-300 hover:text-default-800',\n noOptionsMessage: 'rounded-sm p-2 text-foreground-500',\n option_focused: 'bg-default-100 active:bg-default-200',\n option_selected: 'bg-default-300',\n option: 'rounded px-3 py-2 hover:cursor-pointer',\n placeholder: 'py-0.5 pl-1 text-foreground-500',\n selectContainer: '',\n singleValue: '!ml-1 !leading-7',\n valueContainer: 'gap-1 p-1',\n },\n});\n\ntype SelectOption = {\n /** option label */\n label?: React.ReactNode;\n /** option value */\n value: string;\n};\n\ntype VariantProps = TVProps<typeof selectVariants>;\ntype ClassName = TVClassName<typeof selectVariants>;\n\nexport interface SelectProps extends VariantProps {\n /** CSS class name */\n className?: ClassName; // string;\n /** Determine if the */\n clearable?: boolean;\n /** Set the select to disabled state. */\n disabled?: boolean;\n /** Filter Select Options */\n filterOption?:\n | undefined\n | ((option?: SelectOption, inputValue?: string) => boolean);\n /** Format the label of the option */\n renderOptionLabel?: undefined | Props['formatOptionLabel'];\n /** The value of the search input */\n inputValue?: string;\n /** Label that should be associated with the select. */\n label?: React.ReactNode;\n /** Set the select to a loading state. */\n loading?: boolean;\n /** switch between single and multi select mode. */\n multiSelect?: boolean;\n /** The name for the Select component, used by react-hook-form */\n name: string;\n /** Placeholder that is displayed when nothing is selected */\n placeholder?: string;\n /** The options for the Select component */\n options: SelectOption[];\n /** Handle change events on the input */\n onInputChange?: Props['onInputChange'];\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n}\n\nconst InputComponent: typeof components.Input = (props) => {\n // @ts-expect-error data-testid is not a default prop\n // eslint-disable-next-line react/prop-types, react/destructuring-assignment\n const testId = `${props.selectProps['data-testid']}_input`;\n // eslint-disable-next-line react/jsx-props-no-spreading\n return <components.Input data-testid={testId} {...props} />;\n};\n\nconst OptionComponent: typeof components.Option = (props) => {\n // @ts-expect-error data-testid is not a default prop\n // eslint-disable-next-line react/prop-types, react/destructuring-assignment\n const testId = `${props.selectProps['data-testid']}_option_${props?.data?.testId ?? props?.data?.value}`;\n return (\n <div data-testid={testId}>\n {/* eslint-disable-next-line react/jsx-props-no-spreading */}\n <components.Option {...props} />\n </div>\n );\n};\n\nconst DropdownIndicatorComponent: typeof components.DropdownIndicator = (\n props,\n) => {\n // @ts-expect-error data-testid is not a default prop\n // eslint-disable-next-line react/prop-types\n const testId = props?.selectProps['data-testid'] as string;\n return (\n <div data-testid={`${testId}_dropdown`}>\n {/* eslint-disable-next-line react/jsx-props-no-spreading */}\n <components.DropdownIndicator {...props} />\n </div>\n );\n};\n\n/** Select component based on [NextUI Select](https://nextui.org/docs/components/select) and [React-Select](https://react-select.com/home) */\nconst Select = ({\n className = undefined,\n clearable = true,\n disabled = false,\n filterOption = undefined,\n renderOptionLabel = undefined,\n inputValue = undefined,\n label: _label = undefined,\n loading = false,\n multiSelect = false,\n name,\n onInputChange = undefined,\n options,\n placeholder = undefined,\n testId: _testId = undefined,\n}: SelectProps) => {\n const { control, getFieldState } = useFormContext();\n const { error, invalid, required, testId } = getFieldState(name, _testId);\n\n const [isFocused, setIsFocused] = useState(false);\n\n const variants = selectVariants();\n const classNames = variantsToClassNames(variants, className, 'base');\n\n const {\n getBaseProps,\n getErrorMessageProps,\n getHelperWrapperProps,\n getLabelProps,\n getTriggerProps,\n getValueProps,\n label,\n } = useSelect({\n children: [],\n classNames,\n errorMessage: JSON.stringify(error),\n isDisabled: disabled,\n isInvalid: invalid,\n isLoading: loading,\n isRequired: required,\n label: _label,\n labelPlacement: 'outside',\n placeholder: ' ',\n });\n\n return (\n <Controller\n control={control}\n name={name}\n render={({\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n field: { onChange, value, ref, onBlur },\n }) => (\n <div\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...getBaseProps()}\n className={cn(classNames.base)}\n data-testid={testId}\n // See NextUI styles for group-data condition (data-invalid), e.g.: https://github.com/nextui-org/nextui/blob/main/packages/components/select/src/use-select.ts\n data-required={required}\n >\n {label && (\n <label\n className={classNames.label}\n data-slot=\"label\"\n htmlFor={`react-select-${name}-input`}\n id={getLabelProps().id}\n >\n {label}\n <FieldCopyTestIdButton testId={testId} />\n </label>\n )}\n <ReactSelect\n aria-errormessage=\"\"\n aria-labelledby={\n getTriggerProps()['aria-labelledby']?.split(' ')[1]\n }\n aria-invalid={invalid}\n classNames={{\n control: () =>\n cn(classNames.control, {\n [classNames.control_focused]: isFocused && !invalid,\n }),\n clearIndicator: () => classNames.clearIndicator,\n dropdownIndicator: () => classNames.dropdownIndicator,\n groupHeading: () => classNames.groupHeading,\n indicatorsContainer: () => classNames.indicatorsContainer,\n indicatorSeparator: () => classNames.indicatorSeparator,\n input: () => classNames.input,\n menu: () => classNames.menu,\n menuList: () => classNames.menuList,\n menuPortal: () => classNames.menuPortal,\n multiValue: () => classNames.multiValue,\n multiValueLabel: () =>\n cn(classNames.multiValueLabel, `${getValueProps().className}`),\n multiValueRemove: () => classNames.multiValueRemove,\n noOptionsMessage: () => classNames.noOptionsMessage,\n option: ({\n isFocused: optionIsFocused,\n isSelected: optionIsSelected,\n }) =>\n cn(classNames.option, {\n [classNames.option_focused]: optionIsFocused,\n [classNames.option_selected]: optionIsSelected,\n }),\n placeholder: () => classNames.placeholder,\n singleValue: () =>\n cn(classNames.singleValue, `${getValueProps().className}`),\n valueContainer: () => classNames.valueContainer,\n }}\n components={{\n Input: InputComponent,\n Option: OptionComponent,\n DropdownIndicator: DropdownIndicatorComponent,\n }}\n // Does not affect the testId of the select, but is needed to pass it to sub-components\n data-testid={`${testId}_select`}\n filterOption={filterOption}\n formatOptionLabel={renderOptionLabel}\n inputValue={inputValue}\n instanceId={name}\n isClearable={clearable}\n isDisabled={disabled}\n isLoading={loading}\n isMulti={multiSelect}\n name={name}\n // set menuPosition to fixed so that menu can be rendered\n // inside Card / Modal components, menuShouldBlockScroll\n // prevents container scroll when menu is open\n menuPosition=\"fixed\"\n menuShouldBlockScroll\n options={options}\n placeholder={placeholder}\n onBlur={(_e) => {\n setIsFocused(false);\n return onBlur();\n }}\n onChange={(option) => {\n if (multiSelect) {\n const transformedOptions: string[] = [];\n // @ts-expect-error in this case option is an array.\n option?.forEach((o: { value: string }) => {\n transformedOptions.push(o.value);\n });\n onChange(transformedOptions);\n } else {\n // @ts-expect-error in this case option is of type SelectOption and has the property value.\n onChange(option && option.value);\n }\n }}\n onFocus={(_e) => {\n setIsFocused(true);\n }}\n onInputChange={onInputChange}\n ref={ref}\n // set complete option as value by current field value\n value={options.find((option) => option.value === value)}\n unstyled\n />\n {error && (\n // eslint-disable-next-line react/jsx-props-no-spreading\n <div {...getHelperWrapperProps()}>\n {/* eslint-disable-next-line react/jsx-props-no-spreading */}\n <div {...getErrorMessageProps()}>\n <FieldValidationError error={error} />\n </div>\n </div>\n )}\n </div>\n )}\n />\n );\n};\n\nexport default Select;\n","import Select from './Select';\n\nexport type { SelectProps } from './Select';\n\nexport { Select };\n\nexport default Select;\n"],"mappings":";;;;;;;;;;;AAGA,SAAS,gBAAgB;AACzB,SAAS,kBAAkB;AAC3B,OAAO,eAAe,kBAAkB;AAExC,SAAS,iBAAiB;AAE1B,SAAS,IAAI,IAAI,4BAA4B;AAiGpC,cA4FG,YA5FH;AA3FF,IAAM,iBAAiB,GAAG;AAAA,EAC/B,OAAO;AAAA,IACL,MAAM;AAAA,IACN,gBACE;AAAA,IACF,SACE;AAAA,IACF,iBAAiB;AAAA,IACjB,WAAW;AAAA,IACX,aAAa;AAAA,IACb,mBACE;AAAA,IACF,OAAO;AAAA,IACP,cAAc;AAAA,IACd,qBAAqB;AAAA,IACrB,oBAAoB;AAAA,IACpB,OAAO;AAAA;AAAA,IAEP,OACE;AAAA,IACF,kBAAkB;AAAA,IAClB,gBAAgB;AAAA,IAChB,MAAM;AAAA,IACN,UAAU;AAAA;AAAA;AAAA,IAGV,YAAY;AAAA,IACZ,YAAY;AAAA,IACZ,qBAAqB;AAAA,IACrB,iBAAiB;AAAA,IACjB,kBACE;AAAA,IACF,kBAAkB;AAAA,IAClB,gBAAgB;AAAA,IAChB,iBAAiB;AAAA,IACjB,QAAQ;AAAA,IACR,aAAa;AAAA,IACb,iBAAiB;AAAA,IACjB,a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AS,CAAC,OAAO;AACf,+BAAa,IAAI;AAAA,gBACnB;AAAA,gBACA;AAAA,gBACA;AAAA,gBAEA,OAAO,QAAQ,KAAK,CAAC,WAAW,OAAO,UAAU,KAAK;AAAA,gBACtD,UAAQ;AAAA;AAAA,YACV;AAAA,YACC;AAAA,YAEC,oBAAC,SAAK,GAAG,sBAAsB,GAE7B,8BAAC,SAAK,GAAG,qBAAqB,GAC5B,8BAAC,gCAAqB,OAAc,GACtC,GACF;AAAA;AAAA;AAAA,MAEJ;AAAA;AAAA,EAEJ;AAEJ;AAEA,IAAO,iBAAQ;;;AChTf,IAAOA,kBAAQ;","names":["Select_default"]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var _chunkKMMS4G7Acjs = require('./chunk-KMMS4G7A.cjs');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkOHJYXA6Rcjs = require('./chunk-OHJYXA6R.cjs');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
var _chunkLDCRR7FPcjs = require('./chunk-LDCRR7FP.cjs');
|
|
@@ -12,7 +12,22 @@ var _chunkLDCRR7FPcjs = require('./chunk-LDCRR7FP.cjs');
|
|
|
12
12
|
var _reacthookform = require('react-hook-form');
|
|
13
13
|
var _input = require('@nextui-org/input');
|
|
14
14
|
var _switch = require('@nextui-org/switch');
|
|
15
|
+
var _pixelutils = require('@fuf-stack/pixel-utils');
|
|
15
16
|
var _jsxruntime = require('react/jsx-runtime');
|
|
17
|
+
var switchVariants = _pixelutils.tv.call(void 0, {
|
|
18
|
+
slots: {
|
|
19
|
+
base: "",
|
|
20
|
+
endContent: "",
|
|
21
|
+
errorMessage: "ml-1 mt-1",
|
|
22
|
+
// See NextUI styles for group-data condition, e.g.: https://github.com/nextui-org/nextui/blob/main/packages/core/theme/src/components/select.ts
|
|
23
|
+
label: 'text-sm text-foreground subpixel-antialiased group-data-[invalid=true]:!text-danger group-data-[required=true]:after:ml-0.5 group-data-[required=true]:after:text-danger group-data-[required=true]:after:content-["*"]',
|
|
24
|
+
outerWrapper: "place-content-center",
|
|
25
|
+
startContent: "",
|
|
26
|
+
thumb: "",
|
|
27
|
+
thumbIcon: "",
|
|
28
|
+
wrapper: ""
|
|
29
|
+
}
|
|
30
|
+
});
|
|
16
31
|
var Switch = ({
|
|
17
32
|
className = void 0,
|
|
18
33
|
disabled = false,
|
|
@@ -30,6 +45,10 @@ var Switch = ({
|
|
|
30
45
|
labelPlacement: "outside",
|
|
31
46
|
placeholder: " "
|
|
32
47
|
});
|
|
48
|
+
const variants = switchVariants();
|
|
49
|
+
const classNames = _pixelutils.variantsToClassNames.call(void 0, variants, className, "outerWrapper");
|
|
50
|
+
console.log("getHelperWrapperProps()", getHelperWrapperProps());
|
|
51
|
+
console.log("getErrorMessageProps()", getErrorMessageProps());
|
|
33
52
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
34
53
|
_reacthookform.Controller,
|
|
35
54
|
{
|
|
@@ -38,33 +57,36 @@ var Switch = ({
|
|
|
38
57
|
disabled,
|
|
39
58
|
render: ({
|
|
40
59
|
field: { disabled: isDisabled, value, ref, onBlur, onChange }
|
|
41
|
-
}) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
60
|
+
}) => /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: classNames.outerWrapper, children: [
|
|
42
61
|
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
43
62
|
_switch.Switch,
|
|
44
63
|
{
|
|
45
64
|
"aria-describedby": getInputProps()["aria-describedby"],
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
classNames: {
|
|
50
|
-
label: `text-bold block text-ellipsis text-small ${invalid ? "text-danger" : ""}`
|
|
51
|
-
},
|
|
65
|
+
classNames,
|
|
66
|
+
"data-invalid": invalid,
|
|
67
|
+
"data-required": required,
|
|
52
68
|
"data-testid": testId,
|
|
53
69
|
isDisabled,
|
|
54
|
-
value,
|
|
55
|
-
onChange,
|
|
56
|
-
onBlur,
|
|
70
|
+
isSelected: !!value,
|
|
57
71
|
name,
|
|
72
|
+
onBlur,
|
|
73
|
+
onChange,
|
|
58
74
|
ref,
|
|
75
|
+
required,
|
|
76
|
+
value,
|
|
59
77
|
children: [
|
|
60
78
|
label,
|
|
61
|
-
!!required && !!_label && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "!text-danger", children: " *" }),
|
|
62
79
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkKMMS4G7Acjs.FieldCopyTestIdButton_default, { testId })
|
|
63
80
|
]
|
|
64
81
|
}
|
|
65
82
|
),
|
|
66
|
-
error &&
|
|
67
|
-
|
|
83
|
+
error && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "div", { className: classNames.errorMessage, children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
84
|
+
"div",
|
|
85
|
+
{
|
|
86
|
+
...getErrorMessageProps(),
|
|
87
|
+
children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkOHJYXA6Rcjs.FieldValidationError_default, { error })
|
|
88
|
+
}
|
|
89
|
+
) })
|
|
68
90
|
] })
|
|
69
91
|
}
|
|
70
92
|
);
|
|
@@ -78,4 +100,4 @@ var Switch_default2 = Switch_default;
|
|
|
78
100
|
|
|
79
101
|
|
|
80
102
|
exports.Switch_default = Switch_default; exports.Switch_default2 = Switch_default2;
|
|
81
|
-
//# sourceMappingURL=chunk-
|
|
103
|
+
//# sourceMappingURL=chunk-NQ4JZ7AK.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-NQ4JZ7AK.cjs","../src/Switch/Switch.tsx","../src/Switch/index.ts"],"names":["Switch_default"],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACRA,gDAA2B;AA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,kBAAA,6BAAA,8CAAC,EAAA,EAAqB,MAAA,CAAc;AAAA,UAAA;AAAA,QACtC,EAAA,CACF;AAAA,MAAA,EAAA,CAEJ;AAAA,IAAA;AAAA,EAEJ,CAAA;AAEJ,CAAA;AAEA,IAAO,eAAA,EAAQ,MAAA;ADxBf;AACA;AEzFA,IAAOA,gBAAAA,EAAQ,cAAA;AF2Ff;AACA;AACE;AACA;AACF,mFAAC","file":"/home/runner/work/uniform/uniform/packages/uniform/dist/chunk-NQ4JZ7AK.cjs","sourcesContent":[null,"import type { TVClassName, TVProps } from '@fuf-stack/pixel-utils';\n\nimport { Controller } from 'react-hook-form';\n\nimport { useInput } from '@nextui-org/input';\nimport { Switch as NextSwitch } from '@nextui-org/switch';\n\nimport { tv, variantsToClassNames } from '@fuf-stack/pixel-utils';\n\nimport { useFormContext } from '../hooks';\nimport { FieldCopyTestIdButton } from '../partials/FieldCopyTestIdButton';\nimport { FieldValidationError } from '../partials/FieldValidationError';\n\nexport const switchVariants = tv({\n slots: {\n base: '',\n endContent: '',\n errorMessage: 'ml-1 mt-1',\n // See NextUI styles for group-data condition, e.g.: https://github.com/nextui-org/nextui/blob/main/packages/core/theme/src/components/select.ts\n label:\n 'text-sm text-foreground subpixel-antialiased group-data-[invalid=true]:!text-danger group-data-[required=true]:after:ml-0.5 group-data-[required=true]:after:text-danger group-data-[required=true]:after:content-[\"*\"]',\n outerWrapper: 'place-content-center',\n startContent: '',\n thumb: '',\n thumbIcon: '',\n wrapper: '',\n },\n});\n\ntype VariantProps = TVProps<typeof switchVariants>;\ntype ClassName = TVClassName<typeof switchVariants>;\n\nexport interface SwitchProps extends VariantProps {\n /** CSS class name */\n className?: ClassName;\n /** whether the select should be disabled */\n disabled?: boolean;\n /** component displayed next to the switch. */\n label?: React.ReactNode;\n /** name the field is registered under */\n name: string;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n}\n\n/**\n * Switch component based on [NextUI Switch](https://nextui.org/docs/components/switch)\n */\nconst Switch = ({\n className = undefined,\n disabled = false,\n label: _label = undefined,\n name,\n testId: _testId = undefined,\n}: SwitchProps) => {\n const { control, getFieldState } = useFormContext();\n const { error, required, testId, invalid } = getFieldState(name, _testId);\n\n const { label, getInputProps, getHelperWrapperProps, getErrorMessageProps } =\n useInput({\n errorMessage: JSON.stringify(error),\n isInvalid: invalid,\n isRequired: required,\n label: _label,\n labelPlacement: 'outside',\n placeholder: ' ',\n });\n\n const variants = switchVariants();\n const classNames = variantsToClassNames(variants, className, 'outerWrapper');\n\n console.log('getHelperWrapperProps()', getHelperWrapperProps());\n console.log('getErrorMessageProps()', getErrorMessageProps());\n\n return (\n <Controller\n name={name}\n control={control}\n disabled={disabled}\n render={({\n field: { disabled: isDisabled, value, ref, onBlur, onChange },\n }) => (\n <div className={classNames.outerWrapper}>\n <NextSwitch\n aria-describedby={getInputProps()['aria-describedby']}\n classNames={classNames}\n // See NextUI styles for group-data condition (data-invalid), e.g.: https://github.com/nextui-org/nextui/blob/main/packages/components/select/src/use-select.ts\n data-invalid={invalid}\n data-required={required}\n data-testid={testId}\n isDisabled={isDisabled}\n isSelected={!!value}\n name={name}\n onBlur={onBlur}\n onChange={onChange}\n ref={ref}\n required={required}\n value={value}\n >\n {label}\n <FieldCopyTestIdButton testId={testId} />\n </NextSwitch>\n {error && (\n <div className={classNames.errorMessage}>\n <div\n /* eslint-disable-next-line react/jsx-props-no-spreading */\n {...getErrorMessageProps()}\n >\n <FieldValidationError error={error} />\n </div>\n </div>\n )}\n </div>\n )}\n />\n );\n};\n\nexport default Switch;\n","import Switch from './Switch';\n\nexport type { SwitchProps } from './Switch';\n\nexport { Switch };\n\nexport default Switch;\n"]}
|