@fuf-stack/uniform 0.4.0 → 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/Input/index.cjs +3 -3
- package/dist/Input/index.js +2 -2
- 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/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-OYXZQOGU.js → chunk-2Z3YMYNN.js} +4 -4
- package/dist/chunk-4IT2WVQK.cjs +76 -0
- package/dist/chunk-4IT2WVQK.cjs.map +1 -0
- package/dist/chunk-6NZVSPFX.js +76 -0
- package/dist/chunk-6NZVSPFX.js.map +1 -0
- package/dist/chunk-BIJVBXOG.js +205 -0
- package/dist/chunk-BIJVBXOG.js.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-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-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-2CKPLOCK.cjs → chunk-VO7ZM3KY.cjs} +4 -4
- 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 +24 -4
- package/dist/index.d.cts +7 -1
- package/dist/index.d.ts +7 -1
- package/dist/index.js +26 -6
- package/package.json +38 -13
- /package/dist/{chunk-OYXZQOGU.js.map → chunk-2Z3YMYNN.js.map} +0 -0
- /package/dist/{chunk-2CKPLOCK.cjs.map → chunk-VO7ZM3KY.cjs.map} +0 -0
|
@@ -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,GAAG,OAAO,GAChC;AAEJ;AAEA,IAAM,6BAAkE,CACtE,UACG;AAGH,QAAM,SAAS,OAAO,YAAY,aAAa;AAC/C,SACE,oBAAC,SAAI,eAAa,GAAG,MAAM,aAEzB,8BAAC,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,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"]}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkHT3LKDHXcjs = require('./chunk-HT3LKDHX.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkQTL5FREEcjs = require('./chunk-QTL5FREE.cjs');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkWQRM7G4Ccjs = require('./chunk-WQRM7G4C.cjs');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkBBB4FEY6cjs = require('./chunk-BBB4FEY6.cjs');
|
|
13
|
+
|
|
14
|
+
// src/RadioGroup/RadioGroup.tsx
|
|
15
|
+
var _reacthookform = require('react-hook-form');
|
|
16
|
+
var _button = require('@nextui-org/button');
|
|
17
|
+
var _radio = require('@nextui-org/radio');
|
|
18
|
+
var _pixelutils = require('@fuf-stack/pixel-utils');
|
|
19
|
+
|
|
20
|
+
// src/RadioGroup/Variants/RadioBox.tsx
|
|
21
|
+
|
|
22
|
+
var _visuallyhidden = require('@react-aria/visually-hidden');
|
|
23
|
+
|
|
24
|
+
var _jsxruntime = require('react/jsx-runtime');
|
|
25
|
+
var RadioBox = ({ icon = void 0, ...props }) => {
|
|
26
|
+
const {
|
|
27
|
+
children,
|
|
28
|
+
Component,
|
|
29
|
+
description,
|
|
30
|
+
getBaseProps,
|
|
31
|
+
getControlProps,
|
|
32
|
+
getInputProps,
|
|
33
|
+
getLabelProps,
|
|
34
|
+
getLabelWrapperProps,
|
|
35
|
+
getWrapperProps,
|
|
36
|
+
isDisabled
|
|
37
|
+
} = _radio.useRadio.call(void 0, props);
|
|
38
|
+
return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
39
|
+
Component,
|
|
40
|
+
{
|
|
41
|
+
...getBaseProps(),
|
|
42
|
+
className: _pixelutils.cn.call(void 0,
|
|
43
|
+
"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",
|
|
44
|
+
{
|
|
45
|
+
// disabled styles
|
|
46
|
+
"pointer-events-none opacity-disabled": isDisabled
|
|
47
|
+
}
|
|
48
|
+
),
|
|
49
|
+
children: [
|
|
50
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _visuallyhidden.VisuallyHidden, { children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "input", { ...getInputProps() }) }),
|
|
51
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { ...getWrapperProps(), children: /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { ...getControlProps() }) }),
|
|
52
|
+
icon,
|
|
53
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
|
|
54
|
+
"div",
|
|
55
|
+
{
|
|
56
|
+
...getLabelWrapperProps(),
|
|
57
|
+
className: _pixelutils.cn.call(void 0, getLabelWrapperProps().className, "grow"),
|
|
58
|
+
children: [
|
|
59
|
+
children && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { ...getLabelProps(), children }),
|
|
60
|
+
description && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, "span", { className: "text-small text-foreground opacity-70", children: description })
|
|
61
|
+
]
|
|
62
|
+
}
|
|
63
|
+
)
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
// src/RadioGroup/Variants/RadioButton.tsx
|
|
70
|
+
|
|
71
|
+
var _pixels = require('@fuf-stack/pixels');
|
|
72
|
+
|
|
73
|
+
var RadioButton = ({
|
|
74
|
+
className = void 0,
|
|
75
|
+
value,
|
|
76
|
+
isDisabled = false,
|
|
77
|
+
onChange,
|
|
78
|
+
children
|
|
79
|
+
}) => {
|
|
80
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
81
|
+
_pixels.Button,
|
|
82
|
+
{
|
|
83
|
+
className: _pixelutils.cn.call(void 0, className),
|
|
84
|
+
disabled: isDisabled,
|
|
85
|
+
onClick: () => {
|
|
86
|
+
return onChange(value);
|
|
87
|
+
},
|
|
88
|
+
children
|
|
89
|
+
},
|
|
90
|
+
`index_${value}`
|
|
91
|
+
);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
// src/RadioGroup/RadioGroup.tsx
|
|
95
|
+
|
|
96
|
+
var RadioGroup = ({
|
|
97
|
+
className = void 0,
|
|
98
|
+
disabled = false,
|
|
99
|
+
inline = false,
|
|
100
|
+
label = void 0,
|
|
101
|
+
name,
|
|
102
|
+
options,
|
|
103
|
+
testId: _testId = void 0,
|
|
104
|
+
variant = "default"
|
|
105
|
+
}) => {
|
|
106
|
+
const { control, getFieldState, getValues } = _chunkWQRM7G4Ccjs.useFormContext.call(void 0, );
|
|
107
|
+
const { error, invalid, required, testId } = getFieldState(name, _testId);
|
|
108
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
109
|
+
_reacthookform.Controller,
|
|
110
|
+
{
|
|
111
|
+
control,
|
|
112
|
+
disabled,
|
|
113
|
+
name,
|
|
114
|
+
render: ({ field: { onChange, disabled: isDisabled, onBlur, ref } }) => {
|
|
115
|
+
let RadioComponents;
|
|
116
|
+
switch (variant) {
|
|
117
|
+
case "radioBox":
|
|
118
|
+
RadioComponents = options.map((option) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
119
|
+
RadioBox,
|
|
120
|
+
{
|
|
121
|
+
"data-testid": _chunkBBB4FEY6cjs.slugify.call(void 0,
|
|
122
|
+
`${testId}_option_${option.testId || option.value}`
|
|
123
|
+
),
|
|
124
|
+
isDisabled: isDisabled || option.disabled,
|
|
125
|
+
value: option.value,
|
|
126
|
+
onChange,
|
|
127
|
+
description: option.description,
|
|
128
|
+
icon: option.icon,
|
|
129
|
+
children: option.label ? option.label : option.value
|
|
130
|
+
},
|
|
131
|
+
option.value
|
|
132
|
+
));
|
|
133
|
+
break;
|
|
134
|
+
case "radioButton":
|
|
135
|
+
RadioComponents = options.map((option) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
136
|
+
RadioButton,
|
|
137
|
+
{
|
|
138
|
+
"data-testid": _chunkBBB4FEY6cjs.slugify.call(void 0,
|
|
139
|
+
`${testId}_option_${option.testId || option.value}`
|
|
140
|
+
),
|
|
141
|
+
isDisabled: isDisabled || option.disabled,
|
|
142
|
+
value: option.value,
|
|
143
|
+
onChange,
|
|
144
|
+
className: _pixelutils.cn.call(void 0,
|
|
145
|
+
`${getValues()[name] !== option.value ? "bg-opacity-50" : ""}`
|
|
146
|
+
),
|
|
147
|
+
children: option.label ? option.label : option.value
|
|
148
|
+
},
|
|
149
|
+
option.value
|
|
150
|
+
));
|
|
151
|
+
break;
|
|
152
|
+
default:
|
|
153
|
+
RadioComponents = options.map((option) => /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
154
|
+
_radio.Radio,
|
|
155
|
+
{
|
|
156
|
+
"data-testid": _chunkBBB4FEY6cjs.slugify.call(void 0,
|
|
157
|
+
`${testId}_option_${option.testId || option.value}`
|
|
158
|
+
),
|
|
159
|
+
isDisabled: isDisabled || option.disabled,
|
|
160
|
+
value: option.value,
|
|
161
|
+
onChange,
|
|
162
|
+
children: option.label ? option.label : option.value
|
|
163
|
+
},
|
|
164
|
+
option.value
|
|
165
|
+
));
|
|
166
|
+
}
|
|
167
|
+
return /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
|
|
168
|
+
_radio.RadioGroup,
|
|
169
|
+
{
|
|
170
|
+
className,
|
|
171
|
+
"data-testid": testId,
|
|
172
|
+
errorMessage: error && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkQTL5FREEcjs.FieldValidationError_default, { error }),
|
|
173
|
+
isDisabled,
|
|
174
|
+
isInvalid: invalid,
|
|
175
|
+
isRequired: required,
|
|
176
|
+
label: label && // eslint-disable-next-line jsx-a11y/label-has-associated-control
|
|
177
|
+
/* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "label", { className: `${invalid ? "text-danger" : ""}`, children: [
|
|
178
|
+
label,
|
|
179
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkHT3LKDHXcjs.FieldCopyTestIdButton_default, { testId })
|
|
180
|
+
] }),
|
|
181
|
+
orientation: inline ? "horizontal" : "vertical",
|
|
182
|
+
onBlur,
|
|
183
|
+
onChange,
|
|
184
|
+
name,
|
|
185
|
+
ref,
|
|
186
|
+
children: variant === "radioButton" ? (
|
|
187
|
+
// TODO: NextButtonGroup uses ref to modify Button style, but we wrap it, so it does not work at the moment.
|
|
188
|
+
/* @__PURE__ */ _jsxruntime.jsx.call(void 0, _button.ButtonGroup, { children: RadioComponents })
|
|
189
|
+
) : RadioComponents
|
|
190
|
+
}
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
);
|
|
195
|
+
};
|
|
196
|
+
var RadioGroup_default = RadioGroup;
|
|
197
|
+
|
|
198
|
+
// src/RadioGroup/index.ts
|
|
199
|
+
var RadioGroup_default2 = RadioGroup_default;
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
exports.RadioGroup_default = RadioGroup_default; exports.RadioGroup_default2 = RadioGroup_default2;
|
|
205
|
+
//# sourceMappingURL=chunk-I22ICCUC.cjs.map
|
|
@@ -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"],"names":["cn","jsx","jsxs","RadioGroup_default"],"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,qBAA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AAgB,EAAE,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,IAAOE,sBAAQ","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"]}
|
|
@@ -0,0 +1,287 @@
|
|
|
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
|
+
import {
|
|
11
|
+
slugify
|
|
12
|
+
} from "./chunk-V46BHM2U.js";
|
|
13
|
+
|
|
14
|
+
// src/FieldArray/FieldArray.tsx
|
|
15
|
+
import { useEffect as useEffect2 } from "react";
|
|
16
|
+
import { useFieldArray } from "react-hook-form";
|
|
17
|
+
import {
|
|
18
|
+
closestCenter,
|
|
19
|
+
DndContext,
|
|
20
|
+
KeyboardSensor,
|
|
21
|
+
PointerSensor,
|
|
22
|
+
useSensor,
|
|
23
|
+
useSensors
|
|
24
|
+
} from "@dnd-kit/core";
|
|
25
|
+
import {
|
|
26
|
+
restrictToVerticalAxis,
|
|
27
|
+
restrictToWindowEdges
|
|
28
|
+
} from "@dnd-kit/modifiers";
|
|
29
|
+
import {
|
|
30
|
+
SortableContext,
|
|
31
|
+
verticalListSortingStrategy
|
|
32
|
+
} from "@dnd-kit/sortable";
|
|
33
|
+
import { useInput as useInput2 } from "@nextui-org/input";
|
|
34
|
+
import { Button as Button2 } from "@fuf-stack/pixels";
|
|
35
|
+
|
|
36
|
+
// src/FieldArray/FieldArrayField.tsx
|
|
37
|
+
import { useEffect } from "react";
|
|
38
|
+
import { FaAngleDown, FaAngleUp, FaGripLines } from "react-icons/fa";
|
|
39
|
+
import { useSortable } from "@dnd-kit/sortable";
|
|
40
|
+
import { CSS } from "@dnd-kit/utilities";
|
|
41
|
+
import { useInput } from "@nextui-org/input";
|
|
42
|
+
import { Button } from "@fuf-stack/pixels";
|
|
43
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
44
|
+
var FieldArrayField = ({
|
|
45
|
+
children,
|
|
46
|
+
className = void 0,
|
|
47
|
+
field,
|
|
48
|
+
fields,
|
|
49
|
+
hideButtons = [],
|
|
50
|
+
id,
|
|
51
|
+
index,
|
|
52
|
+
insert,
|
|
53
|
+
lastNotDeletable = true,
|
|
54
|
+
move,
|
|
55
|
+
moveField,
|
|
56
|
+
name,
|
|
57
|
+
remove,
|
|
58
|
+
testId = void 0
|
|
59
|
+
}) => {
|
|
60
|
+
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id });
|
|
61
|
+
const style = {
|
|
62
|
+
transform: CSS.Translate.toString(transform),
|
|
63
|
+
transition
|
|
64
|
+
};
|
|
65
|
+
const { getFieldState, register, watch, trigger } = useFormContext();
|
|
66
|
+
const { error, invalid } = getFieldState(`${name}`, void 0);
|
|
67
|
+
const { getHelperWrapperProps, getErrorMessageProps } = useInput({
|
|
68
|
+
isInvalid: invalid,
|
|
69
|
+
errorMessage: JSON.stringify(error),
|
|
70
|
+
labelPlacement: "inside",
|
|
71
|
+
placeholder: " ",
|
|
72
|
+
classNames: { helperWrapper: "block" }
|
|
73
|
+
});
|
|
74
|
+
register(`${name}.${index}._errors`);
|
|
75
|
+
const formValues = watch();
|
|
76
|
+
useEffect(() => {
|
|
77
|
+
trigger(`${name}.${index}._errors`);
|
|
78
|
+
}, [JSON.stringify(formValues)]);
|
|
79
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
80
|
+
/* @__PURE__ */ jsxs("li", { ref: setNodeRef, style, className, children: [
|
|
81
|
+
!hideButtons.includes("move") && !hideButtons.includes("all") && /* @__PURE__ */ jsxs("div", { className: "mr-6 flex flex-row items-center", children: [
|
|
82
|
+
moveField.includes("drag-drop") && /* @__PURE__ */ jsx(
|
|
83
|
+
"div",
|
|
84
|
+
{
|
|
85
|
+
className: "mr-2 text-base text-xl",
|
|
86
|
+
"data-testid": slugify(`${name}_${index}_movebutton`),
|
|
87
|
+
...attributes,
|
|
88
|
+
...listeners,
|
|
89
|
+
children: /* @__PURE__ */ jsx(FaGripLines, {})
|
|
90
|
+
}
|
|
91
|
+
),
|
|
92
|
+
moveField.includes("button") && /* @__PURE__ */ jsxs("div", { className: "flex flex-col", children: [
|
|
93
|
+
/* @__PURE__ */ jsx(
|
|
94
|
+
Button,
|
|
95
|
+
{
|
|
96
|
+
testId: `${name}.${index}.up`,
|
|
97
|
+
disabled: index === 0,
|
|
98
|
+
onClick: () => move(index, index - 1),
|
|
99
|
+
className: "flex rounded-b-none rounded-t-md border border-gray-300 px-2 py-2 shadow-sm",
|
|
100
|
+
children: /* @__PURE__ */ jsx(FaAngleUp, {})
|
|
101
|
+
}
|
|
102
|
+
),
|
|
103
|
+
/* @__PURE__ */ jsx(
|
|
104
|
+
Button,
|
|
105
|
+
{
|
|
106
|
+
testId: `${name}.${index}.down`,
|
|
107
|
+
disabled: index === fields.length - 1,
|
|
108
|
+
onClick: () => move(index, index + 1),
|
|
109
|
+
className: "flex rounded-b-md rounded-t-none border border-gray-300 px-2 py-2 shadow-sm",
|
|
110
|
+
children: /* @__PURE__ */ jsx(FaAngleDown, {})
|
|
111
|
+
}
|
|
112
|
+
)
|
|
113
|
+
] })
|
|
114
|
+
] }),
|
|
115
|
+
/* @__PURE__ */ jsxs("div", { className: "w-full", children: [
|
|
116
|
+
/* @__PURE__ */ jsxs("div", { className: "mb-2 flex items-center", children: [
|
|
117
|
+
/* @__PURE__ */ jsx("div", { className: "flex-grow", "data-testid": testId, children }),
|
|
118
|
+
!hideButtons.includes("remove") && !hideButtons.includes("all") && (lastNotDeletable && fields.length === 1 ? null : /* @__PURE__ */ jsx(Button, { onClick: () => remove(index), className: "ml-1", children: /* @__PURE__ */ jsx(
|
|
119
|
+
"svg",
|
|
120
|
+
{
|
|
121
|
+
className: "h-4 w-4",
|
|
122
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
123
|
+
viewBox: "0 0 20 20",
|
|
124
|
+
fill: "currentColor",
|
|
125
|
+
"aria-hidden": "true",
|
|
126
|
+
children: /* @__PURE__ */ jsx(
|
|
127
|
+
"path",
|
|
128
|
+
{
|
|
129
|
+
fillRule: "evenodd",
|
|
130
|
+
d: "M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z",
|
|
131
|
+
clipRule: "evenodd"
|
|
132
|
+
}
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
) }))
|
|
136
|
+
] }),
|
|
137
|
+
!hideButtons.includes("insert") && !hideButtons.includes("all") && index !== fields.length - 1 ? /* @__PURE__ */ jsx(
|
|
138
|
+
Button,
|
|
139
|
+
{
|
|
140
|
+
className: "text-xs font-medium",
|
|
141
|
+
testId: `add-harbor-button-${index}`,
|
|
142
|
+
onClick: () => {
|
|
143
|
+
insert(index + 1, {});
|
|
144
|
+
},
|
|
145
|
+
children: "insert"
|
|
146
|
+
}
|
|
147
|
+
) : null
|
|
148
|
+
] }, `rest-${field.id}`)
|
|
149
|
+
] }),
|
|
150
|
+
error && typeof error[index] !== "undefined" && // @ts-expect-error rhf incompatibility
|
|
151
|
+
error[Number(index)]?._errors && // TODO: was String(). Check if Number is correct. (same below in FieldValidationError)
|
|
152
|
+
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
153
|
+
/* @__PURE__ */ jsx("div", { ...getHelperWrapperProps(), children: /* @__PURE__ */ jsx("div", { ...getErrorMessageProps(), children: /* @__PURE__ */ jsx(FieldValidationError_default, { error: error[Number(index)]?._errors }) }) })
|
|
154
|
+
] });
|
|
155
|
+
};
|
|
156
|
+
var FieldArrayField_default = FieldArrayField;
|
|
157
|
+
|
|
158
|
+
// src/FieldArray/FieldArray.tsx
|
|
159
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
160
|
+
var FieldArray = ({
|
|
161
|
+
children,
|
|
162
|
+
hideButtons = [],
|
|
163
|
+
label: _label = void 0,
|
|
164
|
+
lastNotDeletable = true,
|
|
165
|
+
name,
|
|
166
|
+
testId: _testId = void 0,
|
|
167
|
+
moveField = ["button"]
|
|
168
|
+
}) => {
|
|
169
|
+
const { control, getValues, getFieldState, register, trigger, watch } = useFormContext();
|
|
170
|
+
const { fields, append, remove, insert, move } = useFieldArray({
|
|
171
|
+
control,
|
|
172
|
+
name
|
|
173
|
+
});
|
|
174
|
+
const { error, testId, invalid, required } = getFieldState(name, _testId);
|
|
175
|
+
register(`${name}._errors`);
|
|
176
|
+
const formValues = watch();
|
|
177
|
+
useEffect2(() => {
|
|
178
|
+
trigger(`${name}._errors`);
|
|
179
|
+
}, [JSON.stringify(formValues)]);
|
|
180
|
+
const { label, getLabelProps, getHelperWrapperProps, getErrorMessageProps } = useInput2({
|
|
181
|
+
isInvalid: invalid,
|
|
182
|
+
isRequired: required,
|
|
183
|
+
errorMessage: JSON.stringify(error),
|
|
184
|
+
label: _label,
|
|
185
|
+
labelPlacement: "inside",
|
|
186
|
+
placeholder: " ",
|
|
187
|
+
classNames: { helperWrapper: "block" }
|
|
188
|
+
});
|
|
189
|
+
if (lastNotDeletable && fields.length === 0) {
|
|
190
|
+
append({});
|
|
191
|
+
}
|
|
192
|
+
const sensors = useSensors(
|
|
193
|
+
useSensor(PointerSensor),
|
|
194
|
+
useSensor(KeyboardSensor)
|
|
195
|
+
);
|
|
196
|
+
const handleDragEnd = (event) => {
|
|
197
|
+
const { active, over } = event;
|
|
198
|
+
if (active.id !== over?.id) {
|
|
199
|
+
const oldIndex = fields.findIndex((field) => field.id === active.id);
|
|
200
|
+
const newIndex = fields.findIndex((field) => field.id === over?.id);
|
|
201
|
+
move(oldIndex, newIndex);
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
return /* @__PURE__ */ jsx2(
|
|
205
|
+
DndContext,
|
|
206
|
+
{
|
|
207
|
+
sensors,
|
|
208
|
+
collisionDetection: closestCenter,
|
|
209
|
+
onDragEnd: handleDragEnd,
|
|
210
|
+
modifiers: [restrictToVerticalAxis, restrictToWindowEdges],
|
|
211
|
+
children: /* @__PURE__ */ jsx2(
|
|
212
|
+
SortableContext,
|
|
213
|
+
{
|
|
214
|
+
items: fields.map((field) => field.id),
|
|
215
|
+
strategy: verticalListSortingStrategy,
|
|
216
|
+
children: /* @__PURE__ */ jsxs2("ul", { "data-testid": testId, children: [
|
|
217
|
+
label && // eslint-disable-next-line jsx-a11y/label-has-associated-control
|
|
218
|
+
/* @__PURE__ */ jsx2(
|
|
219
|
+
"label",
|
|
220
|
+
{
|
|
221
|
+
...getLabelProps(),
|
|
222
|
+
className: `${getLabelProps().className} !pointer-events-auto !static !z-0 -mb-1 ml-1 !inline-block`,
|
|
223
|
+
children: label
|
|
224
|
+
}
|
|
225
|
+
),
|
|
226
|
+
/* @__PURE__ */ jsx2(FieldCopyTestIdButton_default, { testId }),
|
|
227
|
+
fields.map((field, index) => {
|
|
228
|
+
const duplicate = (i) => {
|
|
229
|
+
const values = getValues(name);
|
|
230
|
+
insert(i + 1, { ...values[i], id: null });
|
|
231
|
+
};
|
|
232
|
+
return /* @__PURE__ */ jsx2(
|
|
233
|
+
FieldArrayField_default,
|
|
234
|
+
{
|
|
235
|
+
id: field.id,
|
|
236
|
+
testId: `${testId}_${index}`,
|
|
237
|
+
className: "mb-3 mt-5 flex flex-row items-center",
|
|
238
|
+
field,
|
|
239
|
+
fields,
|
|
240
|
+
hideButtons,
|
|
241
|
+
index,
|
|
242
|
+
insert,
|
|
243
|
+
lastNotDeletable,
|
|
244
|
+
move,
|
|
245
|
+
moveField,
|
|
246
|
+
name,
|
|
247
|
+
remove,
|
|
248
|
+
children: children(
|
|
249
|
+
`${name}[${index}]`,
|
|
250
|
+
index,
|
|
251
|
+
fields.length,
|
|
252
|
+
move,
|
|
253
|
+
insert,
|
|
254
|
+
remove,
|
|
255
|
+
duplicate
|
|
256
|
+
)
|
|
257
|
+
},
|
|
258
|
+
field.id
|
|
259
|
+
);
|
|
260
|
+
}),
|
|
261
|
+
!hideButtons.includes("add") && !hideButtons.includes("all") && /* @__PURE__ */ jsx2(
|
|
262
|
+
Button2,
|
|
263
|
+
{
|
|
264
|
+
testId: `${testId}_append`,
|
|
265
|
+
size: "sm",
|
|
266
|
+
onClick: () => append({}),
|
|
267
|
+
children: "Add"
|
|
268
|
+
}
|
|
269
|
+
),
|
|
270
|
+
error?._errors && // eslint-disable-next-line react/jsx-props-no-spreading
|
|
271
|
+
/* @__PURE__ */ jsx2("div", { ...getHelperWrapperProps(), children: /* @__PURE__ */ jsx2("div", { ...getErrorMessageProps(), children: /* @__PURE__ */ jsx2(FieldValidationError_default, { error: error?._errors }) }) })
|
|
272
|
+
] })
|
|
273
|
+
}
|
|
274
|
+
)
|
|
275
|
+
}
|
|
276
|
+
);
|
|
277
|
+
};
|
|
278
|
+
var FieldArray_default = FieldArray;
|
|
279
|
+
|
|
280
|
+
// src/FieldArray/index.ts
|
|
281
|
+
var FieldArray_default2 = FieldArray_default;
|
|
282
|
+
|
|
283
|
+
export {
|
|
284
|
+
FieldArray_default,
|
|
285
|
+
FieldArray_default2
|
|
286
|
+
};
|
|
287
|
+
//# sourceMappingURL=chunk-I26DVRVR.js.map
|