@fuf-stack/uniform 0.3.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/FieldArray/index.cjs +13 -0
- package/dist/FieldArray/index.cjs.map +1 -0
- package/dist/FieldArray/index.d.cts +8 -0
- package/dist/FieldArray/index.d.ts +8 -0
- package/dist/FieldArray/index.js +13 -0
- package/dist/FieldArray/index.js.map +1 -0
- package/dist/FieldArray-DUvn98Fe.d.cts +27 -0
- package/dist/FieldArray-DUvn98Fe.d.ts +27 -0
- package/dist/Form/index.cjs +2 -2
- package/dist/Form/index.js +1 -1
- package/dist/Grid/index.cjs +2 -2
- package/dist/Grid/index.js +1 -1
- package/dist/Input/index.cjs +3 -3
- package/dist/Input/index.d.cts +2 -2
- package/dist/Input/index.d.ts +2 -2
- package/dist/Input/index.js +2 -2
- package/dist/{Input-B_rP1h4X.d.cts → Input-B6dNQiiD.d.cts} +3 -1
- package/dist/{Input-B_rP1h4X.d.ts → Input-B6dNQiiD.d.ts} +3 -1
- package/dist/RadioGroup/index.cjs +13 -0
- package/dist/RadioGroup/index.cjs.map +1 -0
- package/dist/RadioGroup/index.d.cts +7 -0
- package/dist/RadioGroup/index.d.ts +7 -0
- package/dist/RadioGroup/index.js +13 -0
- package/dist/RadioGroup/index.js.map +1 -0
- package/dist/RadioGroup-BU4K9cnS.d.cts +40 -0
- package/dist/RadioGroup-BU4K9cnS.d.ts +40 -0
- package/dist/Select/index.cjs +13 -0
- package/dist/Select/index.cjs.map +1 -0
- package/dist/Select/index.d.cts +8 -0
- package/dist/Select/index.d.ts +8 -0
- package/dist/Select/index.js +13 -0
- package/dist/Select/index.js.map +1 -0
- package/dist/Select-Mp6Y00dT.d.cts +40 -0
- package/dist/Select-Mp6Y00dT.d.ts +40 -0
- package/dist/SubmitButton/index.cjs +2 -2
- package/dist/SubmitButton/index.js +1 -1
- package/dist/Switch/index.cjs +13 -0
- package/dist/Switch/index.cjs.map +1 -0
- package/dist/Switch/index.d.cts +7 -0
- package/dist/Switch/index.d.ts +7 -0
- package/dist/Switch/index.js +13 -0
- package/dist/Switch/index.js.map +1 -0
- package/dist/Switch-DmjDKgKs.d.cts +20 -0
- package/dist/Switch-DmjDKgKs.d.ts +20 -0
- package/dist/TextArea/index.cjs +13 -0
- package/dist/TextArea/index.cjs.map +1 -0
- package/dist/TextArea/index.d.cts +8 -0
- package/dist/TextArea/index.d.ts +8 -0
- package/dist/TextArea/index.js +13 -0
- package/dist/TextArea/index.js.map +1 -0
- package/dist/TextArea-B-sKvTkd.d.cts +25 -0
- package/dist/TextArea-B-sKvTkd.d.ts +25 -0
- package/dist/{chunk-3DMR7T4D.js → chunk-2Z3YMYNN.js} +8 -6
- package/dist/chunk-2Z3YMYNN.js.map +1 -0
- package/dist/chunk-4IT2WVQK.cjs +76 -0
- package/dist/chunk-4IT2WVQK.cjs.map +1 -0
- package/dist/{chunk-TEJGV6NC.js → chunk-5FMJUJ7H.js} +2 -2
- package/dist/chunk-5FMJUJ7H.js.map +1 -0
- package/dist/{chunk-ZPFKVKGV.cjs → chunk-6GN255GP.cjs} +4 -4
- package/dist/chunk-6GN255GP.cjs.map +1 -0
- package/dist/chunk-6NZVSPFX.js +76 -0
- package/dist/chunk-6NZVSPFX.js.map +1 -0
- package/dist/{chunk-XUKBLFTR.cjs → chunk-AGAYQTFD.cjs} +4 -4
- package/dist/chunk-AGAYQTFD.cjs.map +1 -0
- package/dist/chunk-BIJVBXOG.js +205 -0
- package/dist/chunk-BIJVBXOG.js.map +1 -0
- package/dist/{chunk-4BELEHDQ.cjs → chunk-BNTEIMNY.cjs} +5 -5
- package/dist/chunk-BNTEIMNY.cjs.map +1 -0
- package/dist/chunk-CRKMTDKU.js +239 -0
- package/dist/chunk-CRKMTDKU.js.map +1 -0
- package/dist/chunk-EXYTFHEJ.js +81 -0
- package/dist/chunk-EXYTFHEJ.js.map +1 -0
- package/dist/{chunk-22AA557I.cjs → chunk-HT3LKDHX.cjs} +4 -4
- package/dist/chunk-HT3LKDHX.cjs.map +1 -0
- package/dist/chunk-I22ICCUC.cjs +205 -0
- package/dist/chunk-I22ICCUC.cjs.map +1 -0
- package/dist/chunk-I26DVRVR.js +287 -0
- package/dist/chunk-I26DVRVR.js.map +1 -0
- package/dist/{chunk-6XKDXQ4A.js → chunk-KFRKKWZT.js} +3 -3
- package/dist/chunk-KFRKKWZT.js.map +1 -0
- package/dist/chunk-NVJKXQ5W.cjs +239 -0
- package/dist/chunk-NVJKXQ5W.cjs.map +1 -0
- package/dist/chunk-OS4SMYPO.cjs +287 -0
- package/dist/chunk-OS4SMYPO.cjs.map +1 -0
- package/dist/{chunk-FNVT6LS4.js → chunk-OV5RMSYD.js} +2 -2
- package/dist/{chunk-22AA557I.cjs.map → chunk-OV5RMSYD.js.map} +1 -1
- package/dist/{chunk-4MEKDDB2.js → chunk-PDCEKC3G.js} +2 -2
- package/dist/chunk-PDCEKC3G.js.map +1 -0
- package/dist/{chunk-2O53LMR3.cjs → chunk-VO7ZM3KY.cjs} +11 -9
- package/dist/chunk-VO7ZM3KY.cjs.map +1 -0
- package/dist/chunk-XY7ZZARS.cjs +81 -0
- package/dist/chunk-XY7ZZARS.cjs.map +1 -0
- package/dist/hooks/index.d.cts +2 -2
- package/dist/hooks/index.d.ts +2 -2
- package/dist/index.cjs +27 -7
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +29 -9
- package/dist/partials/FieldCopyTestIdButton/index.cjs +2 -2
- package/dist/partials/FieldCopyTestIdButton/index.js +1 -1
- package/package.json +41 -17
- package/dist/chunk-2O53LMR3.cjs.map +0 -1
- package/dist/chunk-3DMR7T4D.js.map +0 -1
- package/dist/chunk-4BELEHDQ.cjs.map +0 -1
- package/dist/chunk-4MEKDDB2.js.map +0 -1
- package/dist/chunk-6XKDXQ4A.js.map +0 -1
- package/dist/chunk-FNVT6LS4.js.map +0 -1
- package/dist/chunk-TEJGV6NC.js.map +0 -1
- package/dist/chunk-XUKBLFTR.cjs.map +0 -1
- package/dist/chunk-ZPFKVKGV.cjs.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/RadioGroup/RadioGroup.tsx","../src/RadioGroup/Variants/RadioBox.tsx","../src/RadioGroup/Variants/RadioButton.tsx","../src/RadioGroup/index.ts"],"sourcesContent":["import type { ReactElement, ReactNode } from 'react';\n\nimport { Controller } from 'react-hook-form';\n\nimport { ButtonGroup as NextButtonGroup } from '@nextui-org/button';\nimport { RadioGroup as NextRadioGroup, Radio } from '@nextui-org/radio';\n\nimport { cn } from '@fuf-stack/pixel-utils';\n\nimport { slugify } from '../helpers';\nimport { useFormContext } from '../hooks';\nimport { FieldCopyTestIdButton } from '../partials/FieldCopyTestIdButton';\nimport { FieldValidationError } from '../partials/FieldValidationError';\nimport { RadioBox } from './Variants/RadioBox';\nimport { RadioButton } from './Variants/RadioButton';\n\nexport interface RadioGroupOption {\n /** Description of the value. Works with variant radioBox. */\n description?: React.ReactNode;\n /** disables the option */\n disabled?: boolean;\n /** option label */\n label?: React.ReactNode;\n /** option icon */\n icon?: ReactNode;\n /** HTML data-testid attribute of the option */\n testId?: string;\n /** option value */\n value: string;\n}\n\nexport interface RadioGroupProps {\n /** CSS class name */\n className?: string;\n /** Determines if the Buttons are disabled or not. */\n disabled?: boolean;\n /** determines orientation of the Buttons. */\n inline?: boolean;\n /** Label displayed next to the RadioButton. */\n label?: ReactNode;\n /** Name the RadioButtons are registered at in HTML forms (react-hook-form). */\n name: string;\n /** Radio button configuration. */\n options: RadioGroupOption[];\n /** Id to grab element in internal tests. */\n testId?: string;\n /** How the RadioGroup should look like. */\n variant?: 'default' | 'radioBox' | 'radioButton';\n}\n\n/**\n * RadioGroup component based on [NextUI RadioGroup](https://nextui.org/docs/components/radio-group)\n */\nconst RadioGroup = ({\n className = undefined,\n disabled = false,\n inline = false,\n label = undefined,\n name,\n options,\n testId: _testId = undefined,\n variant = 'default',\n}: RadioGroupProps): ReactElement => {\n const { control, getFieldState, getValues } = useFormContext();\n\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={({ field: { onChange, disabled: isDisabled, onBlur, ref } }) => {\n let RadioComponents: ReactNode;\n switch (variant) {\n case 'radioBox':\n RadioComponents = options.map((option) => (\n <RadioBox\n key={option.value}\n data-testid={slugify(\n `${testId}_option_${option.testId || option.value}`,\n )}\n isDisabled={isDisabled || option.disabled}\n value={option.value}\n onChange={onChange}\n description={option.description}\n icon={option.icon}\n >\n {option.label ? option.label : option.value}\n </RadioBox>\n ));\n break;\n case 'radioButton':\n RadioComponents = options.map((option) => (\n <RadioButton\n key={option.value}\n data-testid={slugify(\n `${testId}_option_${option.testId || option.value}`,\n )}\n isDisabled={isDisabled || option.disabled}\n value={option.value}\n onChange={onChange}\n // TODO: how to do the classNames properly (make selected option darker with same color)\n className={cn(\n `${getValues()[name] !== option.value ? 'bg-opacity-50' : ''}`,\n )}\n >\n {option.label ? option.label : option.value}\n </RadioButton>\n ));\n break;\n default:\n RadioComponents = options.map((option) => (\n <Radio\n key={option.value}\n data-testid={slugify(\n `${testId}_option_${option.testId || option.value}`,\n )}\n isDisabled={isDisabled || option.disabled}\n value={option.value}\n onChange={onChange}\n >\n {option.label ? option.label : option.value}\n </Radio>\n ));\n }\n\n return (\n <NextRadioGroup\n className={className}\n data-testid={testId}\n errorMessage={error && <FieldValidationError error={error} />}\n isDisabled={isDisabled}\n isInvalid={invalid}\n isRequired={required}\n label={\n label && (\n // eslint-disable-next-line jsx-a11y/label-has-associated-control\n <label className={`${invalid ? 'text-danger' : ''}`}>\n {label}\n <FieldCopyTestIdButton testId={testId} />\n </label>\n )\n }\n orientation={inline ? 'horizontal' : 'vertical'}\n onBlur={onBlur}\n onChange={onChange}\n name={name}\n ref={ref}\n >\n {variant === 'radioButton' ? (\n // TODO: NextButtonGroup uses ref to modify Button style, but we wrap it, so it does not work at the moment.\n <NextButtonGroup>{RadioComponents}</NextButtonGroup>\n ) : (\n RadioComponents\n )}\n </NextRadioGroup>\n );\n }}\n />\n );\n};\n\nexport default RadioGroup;\n","import type { RadioProps as NextRadioProps } from '@nextui-org/radio';\nimport type { ReactNode } from 'react';\n\nimport { useRadio } from '@nextui-org/radio';\nimport { VisuallyHidden } from '@react-aria/visually-hidden';\n\nimport { cn } from '@fuf-stack/pixel-utils';\n\ninterface RadioProps extends NextRadioProps {\n /** icon for the option */\n icon?: ReactNode;\n}\n\nexport const RadioBox = ({ icon = undefined, ...props }: RadioProps) => {\n const {\n children,\n Component,\n description,\n getBaseProps,\n getControlProps,\n getInputProps,\n getLabelProps,\n getLabelWrapperProps,\n getWrapperProps,\n isDisabled,\n } = useRadio(props);\n\n return (\n <Component\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...getBaseProps()}\n className={cn(\n 'group inline-flex flex-auto cursor-pointer items-center justify-between gap-4 rounded-lg border-2 border-default p-4 hover:bg-content2 data-[selected=true]:border-primary',\n {\n // disabled styles\n 'pointer-events-none opacity-disabled': isDisabled,\n },\n )}\n >\n <VisuallyHidden>\n {/* eslint-disable-next-line react/jsx-props-no-spreading */}\n <input {...getInputProps()} />\n </VisuallyHidden>\n {/* eslint-disable-next-line react/jsx-props-no-spreading */}\n <span {...getWrapperProps()}>\n {/* eslint-disable-next-line react/jsx-props-no-spreading */}\n <span {...getControlProps()} />\n </span>\n {icon}\n <div\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...getLabelWrapperProps()}\n className={cn(getLabelWrapperProps().className, 'grow')}\n >\n {/* eslint-disable-next-line react/jsx-props-no-spreading */}\n {children && <span {...getLabelProps()}>{children}</span>}\n {description && (\n <span className=\"text-small text-foreground opacity-70\">\n {description}\n </span>\n )}\n </div>\n </Component>\n );\n};\n\nexport default RadioBox;\n","import { cn } from '@fuf-stack/pixel-utils';\nimport { Button } from '@fuf-stack/pixels';\n\ninterface RadioButtonProps {\n /** label of the value. */\n children: React.ReactNode;\n /** CSS class name */\n className?: string;\n /** disables the option */\n isDisabled?: boolean;\n /** Callback function. Executed if the option is clicked. */\n onChange: (...event: unknown[]) => void;\n /** value of the option. */\n value: string;\n}\n\nexport const RadioButton = ({\n className = undefined,\n value,\n isDisabled = false,\n onChange,\n children,\n}: RadioButtonProps) => {\n return (\n <Button\n key={`index_${value}`}\n className={cn(className)}\n disabled={isDisabled}\n onClick={() => {\n return onChange(value);\n }}\n >\n {children}\n </Button>\n );\n};\n\nexport default RadioButton;\n","import RadioGroup from './RadioGroup';\n\nexport type { RadioGroupProps } from './RadioGroup';\n\nexport { RadioGroup };\n\nexport default RadioGroup;\n"],"mappings":";;;;;;;;;;;;;;AAEA,SAAS,kBAAkB;AAE3B,SAAS,eAAe,uBAAuB;AAC/C,SAAS,cAAc,gBAAgB,aAAa;AAEpD,SAAS,MAAAA,WAAU;;;ACJnB,SAAS,gBAAgB;AACzB,SAAS,sBAAsB;AAE/B,SAAS,UAAU;AAmCX,cAQF,YARE;AA5BD,IAAM,WAAW,CAAC,EAAE,OAAO,QAAW,GAAG,MAAM,MAAkB;AACtE,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,SAAS,KAAK;AAElB,SACE;AAAA,IAAC;AAAA;AAAA,MAEE,GAAG,aAAa;AAAA,MACjB,WAAW;AAAA,QACT;AAAA,QACA;AAAA;AAAA,UAEE,wCAAwC;AAAA,QAC1C;AAAA,MACF;AAAA,MAEA;AAAA,4BAAC,kBAEC,8BAAC,WAAO,GAAG,cAAc,GAAG,GAC9B;AAAA,QAEA,oBAAC,UAAM,GAAG,gBAAgB,GAExB,8BAAC,UAAM,GAAG,gBAAgB,GAAG,GAC/B;AAAA,QACC;AAAA,QACD;AAAA,UAAC;AAAA;AAAA,YAEE,GAAG,qBAAqB;AAAA,YACzB,WAAW,GAAG,qBAAqB,EAAE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AE,IAC9C;AAAA;AAAA,cACD,gBAAAD,KAAC,iCAAsB,QAAgB;AAAA,eACzC;AAAA,YAGJ,aAAa,SAAS,eAAe;AAAA,YACrC;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YAEC,sBAAY;AAAA;AAAA,cAEX,gBAAAA,KAAC,mBAAiB,2BAAgB;AAAA,gBAElC;AAAA;AAAA,QAEJ;AAAA,MAEJ;AAAA;AAAA,EACF;AAEJ;AAEA,IAAO,qBAAQ;;;AG7Jf,IAAOG,sBAAQ;","names":["cn","cn","jsx","jsx","jsxs","cn","RadioGroup_default"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
var _chunkWQRM7G4Ccjs = require('./chunk-WQRM7G4C.cjs');
|
|
@@ -9,7 +9,7 @@ var _chunkBBB4FEY6cjs = require('./chunk-BBB4FEY6.cjs');
|
|
|
9
9
|
// src/Form/Form.tsx
|
|
10
10
|
var _react = require('react');
|
|
11
11
|
var _reacthookform = require('react-hook-form');
|
|
12
|
-
var
|
|
12
|
+
var _pixelutils = require('@fuf-stack/pixel-utils');
|
|
13
13
|
|
|
14
14
|
// src/Form/subcomponents/FormDebugViewer.tsx
|
|
15
15
|
|
|
@@ -56,7 +56,7 @@ var FormDebugViewer = ({ className = void 0 }) => {
|
|
|
56
56
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
57
57
|
_pixels.Card,
|
|
58
58
|
{
|
|
59
|
-
className:
|
|
59
|
+
className: _pixelutils.cn.call(void 0, className),
|
|
60
60
|
header: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "div", { className: "flex w-full flex-row justify-between", children: [
|
|
61
61
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-lg", children: "Debug Mode" }),
|
|
62
62
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
@@ -136,7 +136,7 @@ var Form = ({
|
|
|
136
136
|
/* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
137
137
|
"form",
|
|
138
138
|
{
|
|
139
|
-
className:
|
|
139
|
+
className: _pixelutils.cn.call(void 0, "flex-grow", className),
|
|
140
140
|
"data-testid": _chunkBBB4FEY6cjs.slugify.call(void 0, testId || name || ""),
|
|
141
141
|
name,
|
|
142
142
|
onSubmit: methods.handleSubmit(onSubmit),
|
|
@@ -156,4 +156,4 @@ var Form_default2 = Form_default;
|
|
|
156
156
|
|
|
157
157
|
|
|
158
158
|
exports.Form_default = Form_default; exports.Form_default2 = Form_default2;
|
|
159
|
-
//# sourceMappingURL=chunk-
|
|
159
|
+
//# sourceMappingURL=chunk-BNTEIMNY.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/Form/Form.tsx","../src/Form/subcomponents/FormDebugViewer.tsx","../src/Form/index.ts"],"names":["useEffect","cn","jsx","jsxs","Form_default"],"mappings":";;;;;;;;;AAIA,SAAS,aAAAA,kBAAiB;AAC1B,SAAS,eAAe;AAExB,SAAS,MAAAC,WAAU;;;ACLnB,SAAS,WAAW,gBAAgB;AACpC,SAAS,eAAe;AACxB,SAAS,aAAa;AAEtB,SAAS,UAAU;AACnB,SAAS,QAAQ,MAAM,MAAM,uBAAuB;AAgDtC,cASN,YATM;AAvCd,IAAM,yBAAyB;AAG/B,IAAM,kBAAkB,CAAC,EAAE,YAAY,OAAU,MAA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A;AAEJ;AAEA,IAAO,eAAQ;;;AEzGf,IAAOE,gBAAQ","sourcesContent":["import type { VetoInstance } from '@fuf-stack/veto';\nimport type { ReactNode } from 'react';\nimport type { FieldValues, SubmitHandler } from 'react-hook-form';\n\nimport { useEffect } from 'react';\nimport { useForm } from 'react-hook-form';\n\nimport { cn } from '@fuf-stack/pixel-utils';\n\nimport { slugify } from '../helpers';\nimport FormProvider from './subcomponents/FormContext';\nimport FormDebugViewer from './subcomponents/FormDebugViewer';\n\n/**\n * recursively removes all fields that are null or undefined before\n * the form data is passed to the veto validation function\n */\nexport const removeNullishFields = (obj: Record<string, unknown>) => {\n return JSON.parse(\n JSON.stringify(obj, (_key, value) => {\n return value === null ? undefined : value;\n }),\n );\n};\n\nexport interface FormProps {\n /** form children */\n children: ReactNode | ReactNode[];\n /** CSS class name */\n className?: string | string[];\n /** initial form values */\n initialValues?: FieldValues;\n /** name of the form */\n name?: string;\n /** form submit handler */\n onSubmit: SubmitHandler<FieldValues>;\n /** HTML data-testid attribute used in e2e tests */\n testId?: string;\n /** veto validation schema */\n validation?: VetoInstance;\n /** when the validation should be triggered */\n validationTrigger?:\n | 'onChange'\n | 'onBlur'\n | 'onSubmit'\n | 'onTouched'\n | 'all'\n | 'all-instant';\n}\n\n/**\n * Form component that has to wrap every uniform\n */\nconst Form = ({\n children,\n className = undefined,\n initialValues = undefined,\n name = undefined,\n onSubmit,\n testId = undefined,\n validation = undefined,\n validationTrigger = 'all',\n}: FormProps) => {\n const methods = useForm(\n validation\n ? {\n defaultValues: initialValues,\n resolver: async (values) => {\n const { data, errors, ...rest } = await validation.validateAsync(\n removeNullishFields(values),\n );\n // https://github.com/react-hook-form/resolvers/blob/master/zod/src/zod.ts\n return { values: data || {}, errors: errors || {}, ...rest };\n },\n // set rhf mode\n // see: https://react-hook-form.com/docs/useform#mode\n mode: validationTrigger === 'all-instant' ? 'all' : validationTrigger,\n }\n : {\n defaultValues: initialValues,\n },\n );\n\n useEffect(\n () => {\n if (validationTrigger === 'all-instant') {\n methods.trigger();\n }\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [validationTrigger],\n );\n\n return (\n // eslint-disable-next-line react/jsx-props-no-spreading\n <FormProvider {...methods} validation={validation}>\n <div className=\"flex w-full flex-row justify-between gap-6\">\n <form\n className={cn('flex-grow', className)}\n data-testid={slugify(testId || name || '')}\n name={name}\n onSubmit={methods.handleSubmit(onSubmit)}\n >\n {children}\n </form>\n <FormDebugViewer className=\"w-96 flex-shrink\" />\n </div>\n </FormProvider>\n );\n};\n\nexport default Form;\n","import type { VetoError } from '@fuf-stack/veto';\n\nimport { useEffect, useState } from 'react';\nimport { FaTimes } from 'react-icons/fa';\nimport { FaBug } from 'react-icons/fa6';\n\nimport { cn } from '@fuf-stack/pixel-utils';\nimport { Button, Card, Json, useLocalStorage } from '@fuf-stack/pixels';\n\nimport { useFormContext } from '../../hooks';\n\ninterface FormDebugViewerProps {\n /** CSS class name */\n className?: string;\n}\n\nconst LOCALSTORAGE_DEBUG_KEY = 'uniform:form-debug-enabled';\n\n/** Renders a form debug panel with information about the current form state */\nconst FormDebugViewer = ({ className = undefined }: FormDebugViewerProps) => {\n const {\n watch,\n formState: { dirtyFields, isValid, isSubmitting },\n validation,\n } = useFormContext();\n\n const [debug, setDebug] = useLocalStorage(LOCALSTORAGE_DEBUG_KEY, false);\n\n const [validationErrors, setValidationErrors] = useState<\n VetoError['errors'] | null\n >(null);\n\n const formValues = watch();\n\n useEffect(\n () => {\n const updateValidationErrors = async () => {\n if (validation) {\n const validateResult = await validation?.validateAsync(formValues);\n setValidationErrors(validateResult?.errors);\n }\n };\n updateValidationErrors();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [JSON.stringify(formValues)],\n );\n\n if (!debug) {\n return (\n <Button\n ariaLabel=\"Enable form debug mode\"\n onClick={() => setDebug(!debug)}\n className=\"absolute bottom-2.5 right-2.5 w-5 text-default-400\"\n variant=\"light\"\n icon={<FaBug />}\n />\n );\n }\n\n return (\n <Card\n className={cn(className)}\n header={\n <div className=\"flex w-full flex-row justify-between\">\n <span className=\"text-lg\">Debug Mode</span>\n <Button\n icon={<FaTimes className=\"text-danger\" />}\n onClick={() => setDebug(false)}\n size=\"sm\"\n variant=\"flat\"\n />\n </div>\n }\n >\n <Json\n value={{\n values: formValues,\n errors: validationErrors,\n dirtyFields,\n isValid,\n isSubmitting,\n }}\n />\n </Card>\n );\n};\nexport default FormDebugViewer;\n","import Form from './Form';\n\nexport type { FormProps } from './Form';\n\nexport { Form };\n\nexport default Form;\n"]}
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FieldCopyTestIdButton_default
|
|
3
|
+
} from "./chunk-OV5RMSYD.js";
|
|
4
|
+
import {
|
|
5
|
+
FieldValidationError_default
|
|
6
|
+
} from "./chunk-DBLODROX.js";
|
|
7
|
+
import {
|
|
8
|
+
useFormContext
|
|
9
|
+
} from "./chunk-BCMPSLSG.js";
|
|
10
|
+
|
|
11
|
+
// src/Select/Select.tsx
|
|
12
|
+
import { Controller } from "react-hook-form";
|
|
13
|
+
import ReactSelect, { components } from "react-select";
|
|
14
|
+
import { useSelect } from "@nextui-org/select";
|
|
15
|
+
import { cn, tv } from "@fuf-stack/pixel-utils";
|
|
16
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
17
|
+
var InputComponent = (props) => {
|
|
18
|
+
const testId = `${props.selectProps["data-testid"]}_input`;
|
|
19
|
+
return /* @__PURE__ */ jsx(components.Input, { "data-testid": testId, ...props });
|
|
20
|
+
};
|
|
21
|
+
var OptionComponent = (props) => {
|
|
22
|
+
const testId = `${props.selectProps["data-testid"]}_option_${props?.data?.testId ?? props?.data?.value}`;
|
|
23
|
+
return /* @__PURE__ */ jsx("div", { "data-testid": testId, children: /* @__PURE__ */ jsx(components.Option, { ...props }) });
|
|
24
|
+
};
|
|
25
|
+
var DropdownIndicatorComponent = (props) => {
|
|
26
|
+
const testId = props?.selectProps["data-testid"];
|
|
27
|
+
return /* @__PURE__ */ jsx("div", { "data-testid": `${testId}_dropdown`, children: /* @__PURE__ */ jsx(components.DropdownIndicator, { ...props }) });
|
|
28
|
+
};
|
|
29
|
+
var selectVariants = tv({
|
|
30
|
+
slots: {
|
|
31
|
+
clearIndicator: "rounded-md p-1 text-neutral-500 hover:cursor-pointer hover:bg-gray-200 hover:text-neutral-800 hover:dark:bg-default-200 hover:dark:text-default-500",
|
|
32
|
+
control: "rounded-lg border-2 border-gray-200 shadow-sm !duration-150 transition-background hover:border-gray-400 motion-reduce:transition-none dark:border-default-200 hover:dark:border-default-400 focus:dark:border-default-400",
|
|
33
|
+
crossIcon: "",
|
|
34
|
+
downChevron: "",
|
|
35
|
+
dropdownIndicator: "rounded-md p-1 text-neutral-500 hover:cursor-pointer hover:bg-gray-200 hover:text-black hover:dark:bg-default-200 hover:dark:text-default-500",
|
|
36
|
+
group: "",
|
|
37
|
+
groupHeading: "mb-1 ml-3 mt-2 text-sm text-neutral-500",
|
|
38
|
+
indicatorsContainer: "gap-1 p-1",
|
|
39
|
+
indicatorSeparator: "bg-gray-300 dark:bg-default-300",
|
|
40
|
+
input: "py-0.5 pl-1",
|
|
41
|
+
loadingIndicator: "",
|
|
42
|
+
loadingMessage: "",
|
|
43
|
+
menu: "mt-2 rounded-xl border border-gray-200 bg-default-50 p-1 shadow-sm dark:border-gray-900 dark:bg-default-50",
|
|
44
|
+
menuList: "",
|
|
45
|
+
// ensure menu has same z-index as modal so it is visible when rendered in modal
|
|
46
|
+
// see: https://github.com/nextui-org/nextui/blob/main/packages/core/theme/src/components/modal.ts (see z-50)
|
|
47
|
+
menuPortal: "!z-50",
|
|
48
|
+
multiValue: "items-center gap-1.5 rounded bg-gray-100 py-0.5 pl-2 pr-1 dark:bg-default-100",
|
|
49
|
+
multiValueContainer: "",
|
|
50
|
+
multiValueLabel: "py-0.5 leading-6",
|
|
51
|
+
multiValueRemove: "rounded text-neutral-500 hover:cursor-pointer hover:border-gray-300 hover:text-neutral-800 hover:dark:bg-default-200 hover:dark:text-default-500",
|
|
52
|
+
noOptionsMessage: "rounded-sm bg-gray-50 p-2 text-neutral-500 dark:bg-default-100",
|
|
53
|
+
option: "rounded px-3 py-2 hover:cursor-pointer",
|
|
54
|
+
placeholder: "py-0.5 pl-1 text-neutral-500",
|
|
55
|
+
selectContainer: "",
|
|
56
|
+
singleValue: "!ml-1 !leading-7",
|
|
57
|
+
valueContainer: "gap-1 p-1"
|
|
58
|
+
},
|
|
59
|
+
variants: {
|
|
60
|
+
invalid: {
|
|
61
|
+
true: {
|
|
62
|
+
control: "border-danger hover:border-danger dark:border-danger hover:dark:border-danger"
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
focused: {
|
|
66
|
+
true: {
|
|
67
|
+
option: "bg-gray-100 active:bg-gray-200 dark:bg-default-100 dark:active:bg-default-200"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
optionSelected: {
|
|
71
|
+
true: { option: "bg-gray-300 dark:bg-default-300" }
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
var Select = ({
|
|
76
|
+
className = void 0,
|
|
77
|
+
clearable = true,
|
|
78
|
+
disabled = false,
|
|
79
|
+
filterOption = void 0,
|
|
80
|
+
inputValue = void 0,
|
|
81
|
+
label: _label = void 0,
|
|
82
|
+
loading = false,
|
|
83
|
+
multiSelect = false,
|
|
84
|
+
name,
|
|
85
|
+
onInputChange = void 0,
|
|
86
|
+
options,
|
|
87
|
+
placeholder = void 0,
|
|
88
|
+
testId: _testId = void 0
|
|
89
|
+
}) => {
|
|
90
|
+
const { control, getFieldState } = useFormContext();
|
|
91
|
+
const { error, invalid, required, testId } = getFieldState(name, _testId);
|
|
92
|
+
const {
|
|
93
|
+
label,
|
|
94
|
+
getLabelProps,
|
|
95
|
+
getTriggerProps,
|
|
96
|
+
getValueProps,
|
|
97
|
+
getHelperWrapperProps,
|
|
98
|
+
getErrorMessageProps
|
|
99
|
+
} = useSelect({
|
|
100
|
+
isLoading: loading,
|
|
101
|
+
isInvalid: invalid,
|
|
102
|
+
isRequired: required,
|
|
103
|
+
isDisabled: disabled,
|
|
104
|
+
errorMessage: JSON.stringify(error),
|
|
105
|
+
label: _label,
|
|
106
|
+
labelPlacement: "outside",
|
|
107
|
+
children: []
|
|
108
|
+
});
|
|
109
|
+
const {
|
|
110
|
+
clearIndicator: clearIndicatorSlot,
|
|
111
|
+
control: controlSlot,
|
|
112
|
+
dropdownIndicator: dropdownIndicatorSlot,
|
|
113
|
+
groupHeading: groupHeadingSlot,
|
|
114
|
+
indicatorsContainer: indicatorContainerSlot,
|
|
115
|
+
indicatorSeparator: indicatorSeparatorSlot,
|
|
116
|
+
input: inputSlot,
|
|
117
|
+
menu: menuSlot,
|
|
118
|
+
menuPortal: menuPortalSlot,
|
|
119
|
+
multiValue: multiValueSlot,
|
|
120
|
+
multiValueLabel: multiValueLabelSlot,
|
|
121
|
+
multiValueRemove: multiValueRemoveSlot,
|
|
122
|
+
noOptionsMessage: noOptionsMessageSlot,
|
|
123
|
+
option: optionSlot,
|
|
124
|
+
placeholder: placeholderSlot,
|
|
125
|
+
singleValue: singleValueSlot,
|
|
126
|
+
valueContainer: valueContainerSlot
|
|
127
|
+
} = selectVariants({ invalid });
|
|
128
|
+
return /* @__PURE__ */ jsx(
|
|
129
|
+
Controller,
|
|
130
|
+
{
|
|
131
|
+
control,
|
|
132
|
+
name,
|
|
133
|
+
render: ({
|
|
134
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
135
|
+
field: { onChange, value, ref, onBlur }
|
|
136
|
+
}) => /* @__PURE__ */ jsxs("div", { className: cn(className, "mt-2"), "data-testid": `${testId}_select`, children: [
|
|
137
|
+
label && /* @__PURE__ */ jsxs(
|
|
138
|
+
"label",
|
|
139
|
+
{
|
|
140
|
+
htmlFor: `react-select-${name}-input`,
|
|
141
|
+
className: `${getLabelProps().className} !pointer-events-auto !static -mb-1 ml-1`,
|
|
142
|
+
children: [
|
|
143
|
+
label,
|
|
144
|
+
/* @__PURE__ */ jsx(FieldCopyTestIdButton_default, { testId })
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
),
|
|
148
|
+
/* @__PURE__ */ jsx(
|
|
149
|
+
ReactSelect,
|
|
150
|
+
{
|
|
151
|
+
"aria-errormessage": "",
|
|
152
|
+
"aria-invalid": invalid,
|
|
153
|
+
"data-testid": `${testId}_select`,
|
|
154
|
+
...() => {
|
|
155
|
+
const { className: _className, ...rest } = getTriggerProps();
|
|
156
|
+
return rest;
|
|
157
|
+
},
|
|
158
|
+
"aria-labelledby": getTriggerProps()["aria-labelledby"]?.split(" ")[1],
|
|
159
|
+
classNames: {
|
|
160
|
+
control: ({ isFocused }) => (
|
|
161
|
+
// border focus style
|
|
162
|
+
controlSlot({
|
|
163
|
+
className: !invalid && isFocused && "!border-primary"
|
|
164
|
+
})
|
|
165
|
+
),
|
|
166
|
+
placeholder: () => placeholderSlot(),
|
|
167
|
+
input: () => inputSlot(),
|
|
168
|
+
valueContainer: () => valueContainerSlot(),
|
|
169
|
+
singleValue: () => singleValueSlot({
|
|
170
|
+
className: `${getValueProps().className}`
|
|
171
|
+
}),
|
|
172
|
+
multiValue: () => multiValueSlot(),
|
|
173
|
+
multiValueLabel: () => multiValueLabelSlot({
|
|
174
|
+
className: `${getValueProps().className}`
|
|
175
|
+
}),
|
|
176
|
+
multiValueRemove: () => multiValueRemoveSlot(),
|
|
177
|
+
indicatorsContainer: () => indicatorContainerSlot(),
|
|
178
|
+
clearIndicator: () => clearIndicatorSlot(),
|
|
179
|
+
indicatorSeparator: () => indicatorSeparatorSlot(),
|
|
180
|
+
dropdownIndicator: () => dropdownIndicatorSlot(),
|
|
181
|
+
menu: () => menuSlot(),
|
|
182
|
+
groupHeading: () => groupHeadingSlot(),
|
|
183
|
+
option: ({ isFocused, isSelected }) => optionSlot({
|
|
184
|
+
focused: isFocused,
|
|
185
|
+
optionSelected: isSelected
|
|
186
|
+
}),
|
|
187
|
+
noOptionsMessage: () => noOptionsMessageSlot(),
|
|
188
|
+
menuPortal: () => menuPortalSlot()
|
|
189
|
+
},
|
|
190
|
+
components: {
|
|
191
|
+
Input: InputComponent,
|
|
192
|
+
Option: OptionComponent,
|
|
193
|
+
DropdownIndicator: DropdownIndicatorComponent
|
|
194
|
+
},
|
|
195
|
+
filterOption,
|
|
196
|
+
instanceId: name,
|
|
197
|
+
inputValue,
|
|
198
|
+
isClearable: clearable,
|
|
199
|
+
isDisabled: disabled,
|
|
200
|
+
isLoading: loading,
|
|
201
|
+
isMulti: multiSelect,
|
|
202
|
+
options,
|
|
203
|
+
placeholder,
|
|
204
|
+
unstyled: true,
|
|
205
|
+
onChange: (option) => {
|
|
206
|
+
if (multiSelect) {
|
|
207
|
+
const transformedOptions = [];
|
|
208
|
+
option?.forEach((o) => {
|
|
209
|
+
transformedOptions.push(o.value);
|
|
210
|
+
});
|
|
211
|
+
onChange(transformedOptions);
|
|
212
|
+
} else {
|
|
213
|
+
onChange(option && option.value);
|
|
214
|
+
}
|
|
215
|
+
},
|
|
216
|
+
onInputChange,
|
|
217
|
+
menuPortalTarget: document.getElementById("modal_body")?.parentNode?.parentNode || document.body,
|
|
218
|
+
value: options.find((option) => option.value === value),
|
|
219
|
+
onBlur,
|
|
220
|
+
name,
|
|
221
|
+
ref
|
|
222
|
+
}
|
|
223
|
+
),
|
|
224
|
+
error && // eslint-disable-next-line react/jsx-props-no-spreading
|
|
225
|
+
/* @__PURE__ */ jsx("div", { ...getHelperWrapperProps(), children: /* @__PURE__ */ jsx("div", { ...getErrorMessageProps(), children: /* @__PURE__ */ jsx(FieldValidationError_default, { error }) }) })
|
|
226
|
+
] })
|
|
227
|
+
}
|
|
228
|
+
);
|
|
229
|
+
};
|
|
230
|
+
var Select_default = Select;
|
|
231
|
+
|
|
232
|
+
// src/Select/index.ts
|
|
233
|
+
var Select_default2 = Select_default;
|
|
234
|
+
|
|
235
|
+
export {
|
|
236
|
+
Select_default,
|
|
237
|
+
Select_default2
|
|
238
|
+
};
|
|
239
|
+
//# sourceMappingURL=chunk-CRKMTDKU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/Select/Select.tsx","../src/Select/index.ts"],"sourcesContent":["import type { Props } from 'react-select';\n\nimport { Controller } from 'react-hook-form';\nimport ReactSelect, { components } from 'react-select';\n\nimport { useSelect } from '@nextui-org/select';\n\nimport { cn, tv } from '@fuf-stack/pixel-utils';\n\nimport { useFormContext } from '../hooks';\nimport { FieldCopyTestIdButton } from '../partials/FieldCopyTestIdButton';\nimport { FieldValidationError } from '../partials/FieldValidationError';\n\ntype SelectOption = {\n /** option label */\n label?: React.ReactNode;\n /** option value */\n value: string;\n};\n\nexport interface SelectProps {\n /** CSS class name */\n className?: string; // string;\n /** Determine if the */\n clearable?: boolean;\n /** Set the select to disabled state. */\n disabled?: boolean;\n\n filterOption?:\n | undefined\n | ((option?: SelectOption, inputValue?: string) => boolean);\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\nexport const selectVariants = tv({\n slots: {\n clearIndicator:\n 'rounded-md p-1 text-neutral-500 hover:cursor-pointer hover:bg-gray-200 hover:text-neutral-800 hover:dark:bg-default-200 hover:dark:text-default-500',\n control:\n 'rounded-lg border-2 border-gray-200 shadow-sm !duration-150 transition-background hover:border-gray-400 motion-reduce:transition-none dark:border-default-200 hover:dark:border-default-400 focus:dark:border-default-400',\n crossIcon: '',\n downChevron: '',\n dropdownIndicator:\n 'rounded-md p-1 text-neutral-500 hover:cursor-pointer hover:bg-gray-200 hover:text-black hover:dark:bg-default-200 hover:dark:text-default-500',\n group: '',\n groupHeading: 'mb-1 ml-3 mt-2 text-sm text-neutral-500',\n indicatorsContainer: 'gap-1 p-1',\n indicatorSeparator: 'bg-gray-300 dark:bg-default-300',\n input: 'py-0.5 pl-1',\n loadingIndicator: '',\n loadingMessage: '',\n menu: 'mt-2 rounded-xl border border-gray-200 bg-default-50 p-1 shadow-sm dark:border-gray-900 dark:bg-default-50',\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:\n 'items-center gap-1.5 rounded bg-gray-100 py-0.5 pl-2 pr-1 dark:bg-default-100',\n multiValueContainer: '',\n multiValueLabel: 'py-0.5 leading-6',\n multiValueRemove:\n 'rounded text-neutral-500 hover:cursor-pointer hover:border-gray-300 hover:text-neutral-800 hover:dark:bg-default-200 hover:dark:text-default-500',\n noOptionsMessage:\n 'rounded-sm bg-gray-50 p-2 text-neutral-500 dark:bg-default-100',\n option: 'rounded px-3 py-2 hover:cursor-pointer',\n placeholder: 'py-0.5 pl-1 text-neutral-500',\n selectContainer: '',\n singleValue: '!ml-1 !leading-7',\n valueContainer: 'gap-1 p-1',\n },\n variants: {\n invalid: {\n true: {\n control:\n 'border-danger hover:border-danger dark:border-danger hover:dark:border-danger',\n },\n },\n focused: {\n true: {\n option:\n 'bg-gray-100 active:bg-gray-200 dark:bg-default-100 dark:active:bg-default-200',\n },\n },\n optionSelected: {\n true: { option: 'bg-gray-300 dark:bg-default-300' },\n },\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 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 {\n label,\n getLabelProps,\n getTriggerProps,\n getValueProps,\n getHelperWrapperProps,\n getErrorMessageProps,\n } = useSelect({\n isLoading: loading,\n isInvalid: invalid,\n isRequired: required,\n isDisabled: disabled,\n errorMessage: JSON.stringify(error),\n label: _label,\n labelPlacement: 'outside',\n children: [],\n });\n\n const {\n clearIndicator: clearIndicatorSlot,\n control: controlSlot,\n dropdownIndicator: dropdownIndicatorSlot,\n groupHeading: groupHeadingSlot,\n indicatorsContainer: indicatorContainerSlot,\n indicatorSeparator: indicatorSeparatorSlot,\n input: inputSlot,\n menu: menuSlot,\n menuPortal: menuPortalSlot,\n multiValue: multiValueSlot,\n multiValueLabel: multiValueLabelSlot,\n multiValueRemove: multiValueRemoveSlot,\n noOptionsMessage: noOptionsMessageSlot,\n option: optionSlot,\n placeholder: placeholderSlot,\n singleValue: singleValueSlot,\n valueContainer: valueContainerSlot,\n } = selectVariants({ invalid });\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 className={cn(className, 'mt-2')} data-testid={`${testId}_select`}>\n {label && (\n <label\n htmlFor={`react-select-${name}-input`} // {getTriggerProps().id}\n className={`${getLabelProps().className} !pointer-events-auto !static -mb-1 ml-1`}\n >\n {label}\n <FieldCopyTestIdButton testId={testId} />\n </label>\n )}\n <ReactSelect\n aria-errormessage=\"\"\n aria-invalid={invalid}\n // Does not affect the testId of the select, but is needed to pass it to sub-components\n data-testid={`${testId}_select`}\n // eslint-disable-next-line react/jsx-props-no-spreading\n {...() => {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars, @typescript-eslint/naming-convention\n const { className: _className, ...rest } = getTriggerProps();\n return rest;\n }}\n aria-labelledby={\n getTriggerProps()['aria-labelledby']?.split(' ')[1]\n }\n classNames={{\n control: ({ isFocused }) =>\n // border focus style\n controlSlot({\n className: !invalid && isFocused && '!border-primary',\n }),\n placeholder: () => placeholderSlot(),\n input: () => inputSlot(),\n valueContainer: () => valueContainerSlot(),\n singleValue: () =>\n singleValueSlot({\n className: `${getValueProps().className}`,\n }),\n multiValue: () => multiValueSlot(),\n multiValueLabel: () =>\n multiValueLabelSlot({\n className: `${getValueProps().className}`,\n }),\n multiValueRemove: () => multiValueRemoveSlot(),\n indicatorsContainer: () => indicatorContainerSlot(),\n clearIndicator: () => clearIndicatorSlot(),\n indicatorSeparator: () => indicatorSeparatorSlot(),\n dropdownIndicator: () => dropdownIndicatorSlot(),\n menu: () => menuSlot(),\n groupHeading: () => groupHeadingSlot(),\n option: ({ isFocused, isSelected }) =>\n optionSlot({\n focused: isFocused,\n optionSelected: isSelected,\n }),\n noOptionsMessage: () => noOptionsMessageSlot(),\n menuPortal: () => menuPortalSlot(),\n }}\n components={{\n Input: InputComponent,\n Option: OptionComponent,\n DropdownIndicator: DropdownIndicatorComponent,\n }}\n filterOption={filterOption}\n instanceId={name}\n inputValue={inputValue}\n isClearable={clearable}\n isDisabled={disabled}\n isLoading={loading}\n isMulti={multiSelect}\n options={options}\n placeholder={placeholder}\n unstyled\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 onInputChange={onInputChange}\n // attach menu modal or body so it works in card and modal\n menuPortalTarget={\n (document.getElementById('modal_body')?.parentNode\n ?.parentNode as HTMLElement) || document.body\n }\n value={options.find((option) => option.value === value)}\n onBlur={onBlur}\n name={name}\n ref={ref}\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":";;;;;;;;;;;AAEA,SAAS,kBAAkB;AAC3B,OAAO,eAAe,kBAAkB;AAExC,SAAS,iBAAiB;AAE1B,SAAS,IAAI,UAAU;AAiDd,cAuJG,YAvJH;AALT,IAAM,iBAA0C,CAAC,UAAU;AAGzD,QAAM,SAAS,GAAG,MAAM,YAAY,aAAa,CAAC;AAElD,SAAO,oBAAC,WAAW,OAAX,EAAiB,eAAa,QAAS,GAAG,OAAO;AAC3D;AAEA,IAAM,kBAA4C,CAAC,UAAU;AAG3D,QAAM,SAAS,GAAG,MAAM,YAAY,aAAa,CAAC,WAAW,OAAO,MAAM,UAAU,OAAO,MAAM,KAAK;AACtG,SACE,oBAAC,SAAI,eAAa,QAEhB,8BAAC,WAAW,QAAX,EAAmB,GAA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A,YACb,YAAY;AAAA,YACZ,WAAW;AAAA,YACX,SAAS;AAAA,YACT;AAAA,YACA;AAAA,YACA,UAAQ;AAAA,YACR,UAAU,CAAC,WAAW;AACpB,kBAAI,aAAa;AACf,sBAAM,qBAA+B,CAAC;AAEtC,wBAAQ,QAAQ,CAAC,MAAyB;AACxC,qCAAmB,KAAK,EAAE,KAAK;AAAA,gBACjC,CAAC;AACD,yBAAS,kBAAkB;AAAA,cAC7B,OAAO;AAEL,yBAAS,UAAU,OAAO,KAAK;AAAA,cACjC;AAAA,YACF;AAAA,YACA;AAAA,YAEA,kBACG,SAAS,eAAe,YAAY,GAAG,YACpC,cAA8B,SAAS;AAAA,YAE7C,OAAO,QAAQ,KAAK,CAAC,WAAW,OAAO,UAAU,KAAK;AAAA,YACtD;AAAA,YACA;AAAA,YACA;AAAA;AAAA,QACF;AAAA,QACC;AAAA,QAEC,oBAAC,SAAK,GAAG,sBAAsB,GAE7B,8BAAC,SAAK,GAAG,qBAAqB,GAC5B,8BAAC,gCAAqB,OAAc,GACtC,GACF;AAAA,SAEJ;AAAA;AAAA,EAEJ;AAEJ;AAEA,IAAO,iBAAQ;;;ACtTf,IAAOA,kBAAQ;","names":["Select_default"]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FieldCopyTestIdButton_default
|
|
3
|
+
} from "./chunk-OV5RMSYD.js";
|
|
4
|
+
import {
|
|
5
|
+
FieldValidationError_default
|
|
6
|
+
} from "./chunk-DBLODROX.js";
|
|
7
|
+
import {
|
|
8
|
+
useFormContext
|
|
9
|
+
} from "./chunk-BCMPSLSG.js";
|
|
10
|
+
|
|
11
|
+
// src/Switch/Switch.tsx
|
|
12
|
+
import { Controller } from "react-hook-form";
|
|
13
|
+
import { useInput } from "@nextui-org/input";
|
|
14
|
+
import { Switch as NextSwitch } from "@nextui-org/switch";
|
|
15
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
16
|
+
var Switch = ({
|
|
17
|
+
className,
|
|
18
|
+
disabled = false,
|
|
19
|
+
label: _label = void 0,
|
|
20
|
+
name,
|
|
21
|
+
testId: _testId = void 0
|
|
22
|
+
}) => {
|
|
23
|
+
const { control, getFieldState } = useFormContext();
|
|
24
|
+
const { error, required, testId, invalid } = getFieldState(name, _testId);
|
|
25
|
+
const { label, getInputProps, getHelperWrapperProps, getErrorMessageProps } = useInput({
|
|
26
|
+
errorMessage: JSON.stringify(error),
|
|
27
|
+
isInvalid: invalid,
|
|
28
|
+
isRequired: required,
|
|
29
|
+
label: _label,
|
|
30
|
+
labelPlacement: "outside",
|
|
31
|
+
placeholder: " "
|
|
32
|
+
});
|
|
33
|
+
return /* @__PURE__ */ jsx(
|
|
34
|
+
Controller,
|
|
35
|
+
{
|
|
36
|
+
name,
|
|
37
|
+
control,
|
|
38
|
+
disabled,
|
|
39
|
+
render: ({
|
|
40
|
+
field: { disabled: isDisabled, value, ref, onBlur, onChange }
|
|
41
|
+
}) => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
42
|
+
/* @__PURE__ */ jsxs(
|
|
43
|
+
NextSwitch,
|
|
44
|
+
{
|
|
45
|
+
"aria-describedby": getInputProps()["aria-describedby"],
|
|
46
|
+
required,
|
|
47
|
+
isSelected: !!value,
|
|
48
|
+
className,
|
|
49
|
+
classNames: {
|
|
50
|
+
label: `text-bold block text-ellipsis text-small ${invalid ? "text-danger" : ""}`
|
|
51
|
+
},
|
|
52
|
+
"data-testid": testId,
|
|
53
|
+
isDisabled,
|
|
54
|
+
value,
|
|
55
|
+
onChange,
|
|
56
|
+
onBlur,
|
|
57
|
+
name,
|
|
58
|
+
ref,
|
|
59
|
+
children: [
|
|
60
|
+
label,
|
|
61
|
+
!!required && !!_label && /* @__PURE__ */ jsx("span", { className: "!text-danger", children: " *" }),
|
|
62
|
+
/* @__PURE__ */ jsx(FieldCopyTestIdButton_default, { testId })
|
|
63
|
+
]
|
|
64
|
+
}
|
|
65
|
+
),
|
|
66
|
+
error && // eslint-disable-next-line react/jsx-props-no-spreading
|
|
67
|
+
/* @__PURE__ */ jsx("div", { ...getHelperWrapperProps(), children: /* @__PURE__ */ jsx("div", { ...getErrorMessageProps(), children: /* @__PURE__ */ jsx(FieldValidationError_default, { error }) }) })
|
|
68
|
+
] })
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
};
|
|
72
|
+
var Switch_default = Switch;
|
|
73
|
+
|
|
74
|
+
// src/Switch/index.ts
|
|
75
|
+
var Switch_default2 = Switch_default;
|
|
76
|
+
|
|
77
|
+
export {
|
|
78
|
+
Switch_default,
|
|
79
|
+
Switch_default2
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=chunk-EXYTFHEJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/Switch/Switch.tsx","../src/Switch/index.ts"],"sourcesContent":["import { Controller } from 'react-hook-form';\n\nimport { useInput } from '@nextui-org/input';\nimport { Switch as NextSwitch } from '@nextui-org/switch';\n\nimport { useFormContext } from '../hooks';\nimport { FieldCopyTestIdButton } from '../partials/FieldCopyTestIdButton';\nimport { FieldValidationError } from '../partials/FieldValidationError';\n\nexport interface SwitchProps {\n /** CSS class name */\n className: string;\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,\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 return (\n <Controller\n name={name}\n control={control}\n disabled={disabled}\n render={({\n field: { disabled: isDisabled, value, ref, onBlur, onChange },\n }) => (\n <>\n <NextSwitch\n aria-describedby={getInputProps()['aria-describedby']}\n required={required}\n isSelected={!!value}\n className={className}\n classNames={{\n label: `text-bold block text-ellipsis text-small ${invalid ? 'text-danger' : ''}`,\n }}\n data-testid={testId}\n isDisabled={isDisabled}\n value={value}\n onChange={onChange}\n onBlur={onBlur}\n name={name}\n ref={ref}\n >\n {label}\n {!!required && !!_label && (\n <span className=\"!text-danger\">{' \\u002A'}</span>\n )}\n <FieldCopyTestIdButton testId={testId} />\n </NextSwitch>\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 </>\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"],"mappings":";;;;;;;;;;;AAAA,SAAS,kBAAkB;AAE3B,SAAS,gBAAgB;AACzB,SAAS,UAAU,kBAAkB;AAkD7B,mBAmBM,KAlBJ,YADF;AA5BR,IAAM,SAAS,CAAC;AAAA,EACd;AAAA,EACA,WAAW;AAAA,EACX,OAAO,SAAS;AAAA,EAChB;AAAA,EACA,QAAQ,UAAU;AACpB,MAAmB;AACjB,QAAM,EAAE,SAAS,cAAc,IAAI,eAAe;AAClD,QAAM,EAAE,OAAO,UAAU,QAAQ,QAAQ,IAAI,cAAc,MAAM,OAAO;AAExE,QAAM,EAAE,OAAO,eAAe,uBAAuB,qBAAqB,IACxE,SAAS;AAAA,IACP,cAAc,KAAK,UAAU,KAAK;AAAA,IAClC,WAAW;AAAA,IACX,YAAY;AAAA,IACZ,OAAO;AAAA,IACP,gBAAgB;AAAA,IAChB,aAAa;AAAA,EACf,CAAC;AAEH,SACE;AAAA,IAAC;AAAA;AAAA,MACC;AAAA,MACA;AAAA,MACA;AAAA,MACA,QAAQ,CAAC;AAAA,QACP,OAAO,EAAE,UAAU,YAAY,OAAO,KAAK,QAAQ,SAAS;AAAA,MAC9D,MACE,iCACE;AAAA;AAAA,UAAC;AAAA;AAAA,YACC,oBAAkB,cAAc,EAAE,kBAAkB;AAAA,YACpD;AAAA,YACA,YAAY,CAAC,CAAC;AAAA,YACd;AAAA,YACA,YAAY;AAAA,cACV,OAAO,4CAA4C,UAAU,gBAAgB,EAAE;AAAA,YACjF;AAAA,YACA,eAAa;AAAA,YACb;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YAEC;AAAA;AAAA,cACA,CAAC,CAAC,YAAY,CAAC,CAAC,UACf,oBAAC,UAAK,WAAU,gBAAgB,gBAAU;AAAA,cAE5C,oBAAC,iCAAsB,QAAgB;AAAA;AAAA;AAAA,QACzC;AAAA,QACC;AAAA,QAEC,oBAAC,SAAK,GAAG,sBAAsB,GAE7B,8BAAC,SAAK,GAAG,qBAAqB,GAC5B,8BAAC,gCAAqB,OAAc,GACtC,GACF;AAAA,SAEJ;AAAA;AAAA,EAEJ;AAEJ;AAEA,IAAO,iBAAQ;;;ACrFf,IAAOA,kBAAQ;","names":["Switch_default"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true})
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/partials/FieldCopyTestIdButton/FieldCopyTestIdButton.tsx
|
|
2
2
|
var _fa6 = require('react-icons/fa6');
|
|
3
|
-
var
|
|
3
|
+
var _pixelutils = require('@fuf-stack/pixel-utils');
|
|
4
4
|
var _pixels = require('@fuf-stack/pixels');
|
|
5
5
|
var _jsxruntime = require('react/jsx-runtime');
|
|
6
6
|
var LOCALSTORAGE_DEBUG_KEY = "uniform:form-debug-enabled";
|
|
@@ -20,7 +20,7 @@ var FieldCopyTestIdButton = ({
|
|
|
20
20
|
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
21
21
|
_pixels.Button,
|
|
22
22
|
{
|
|
23
|
-
className:
|
|
23
|
+
className: _pixelutils.cn.call(void 0, className, "pointer-events-auto"),
|
|
24
24
|
variant: "light",
|
|
25
25
|
onClick: copyToClipboard,
|
|
26
26
|
icon: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _fa6.FaBullseye, {}),
|
|
@@ -37,4 +37,4 @@ var FieldCopyTestIdButton_default2 = FieldCopyTestIdButton_default;
|
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
exports.FieldCopyTestIdButton_default = FieldCopyTestIdButton_default; exports.FieldCopyTestIdButton_default2 = FieldCopyTestIdButton_default2;
|
|
40
|
-
//# sourceMappingURL=chunk-
|
|
40
|
+
//# sourceMappingURL=chunk-HT3LKDHX.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/partials/FieldCopyTestIdButton/FieldCopyTestIdButton.tsx","../src/partials/FieldCopyTestIdButton/index.ts"],"names":["FieldCopyTestIdButton_default"],"mappings":";AAAA,SAAS,kBAAkB;AAE3B,SAAS,UAAU;AACnB,SAAS,QAAQ,uBAAuB;AA8B5B;AAvBZ,IAAM,yBAAyB;AAE/B,IAAM,wBAAwB,CAAC;AAAA,EAC7B,YAAY;AAAA,EACZ;AACF,MAAkC;AAChC,QAAM,CAAC,KAAK,IAAI,gBAAgB,wBAAwB,KAAK;AAE7D,QAAM,kBAAkB,MAAM;AAC5B,cAAU,UAAU,UAAU,MAAM,EAAE,MAAM,CAAC,QAAQ;AACnD,cAAQ,MAAM,qCAAqC,GAAG;AAAA,IACxD,CAAC;AAAA,EACH;AAEA,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,WAAW,GAAG,WAAW,qBAAqB;AAAA,MAC9C,SAAQ;AAAA,MACR,SAAS;AAAA,MACT,MAAM,oBAAC,cAAW;AAAA,MAClB,MAAK;AAAA;AAAA,EACP;AAEJ;AACA,IAAO,gCAAQ;;;AChCf,IAAOA,iCAAQ","sourcesContent":["import { FaBullseye } from 'react-icons/fa6';\n\nimport { cn } from '@fuf-stack/pixel-utils';\nimport { Button, useLocalStorage } from '@fuf-stack/pixels';\n\nexport interface FieldCopyTestIdButtonProps {\n className?: string;\n testId: string;\n}\n\nconst LOCALSTORAGE_DEBUG_KEY = 'uniform:form-debug-enabled';\n\nconst FieldCopyTestIdButton = ({\n className = undefined,\n testId,\n}: FieldCopyTestIdButtonProps) => {\n const [debug] = useLocalStorage(LOCALSTORAGE_DEBUG_KEY, false);\n\n const copyToClipboard = () => {\n navigator.clipboard.writeText(testId).catch((err) => {\n console.error('Error copying TestId to clipboard', err);\n });\n };\n\n if (!debug) {\n return null;\n }\n\n return (\n <Button\n className={cn(className, 'pointer-events-auto')}\n variant=\"light\"\n onClick={copyToClipboard}\n icon={<FaBullseye />}\n size=\"sm\"\n />\n );\n};\nexport default FieldCopyTestIdButton;\n","import FieldCopyTestIdButton from './FieldCopyTestIdButton';\n\nexport type { FieldCopyTestIdButtonProps } from './FieldCopyTestIdButton';\n\nexport { FieldCopyTestIdButton };\n\nexport default FieldCopyTestIdButton;\n"]}
|