@x15ventures/x15-ui-library 3.14.0 → 3.15.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/autoGenerated/libraryThemes.js +12 -12
- package/dist/cjs/autoGenerated/libraryThemes.js.map +1 -1
- package/dist/cjs/autoGenerated/libraryThemes.json +12 -12
- package/dist/cjs/components/design/dialog/Dialog.js +1 -1
- package/dist/cjs/components/design/dialog/Dialog.js.map +1 -1
- package/dist/cjs/components/design/headerBar/HeaderBar.js +3 -1
- package/dist/cjs/components/design/headerBar/HeaderBar.js.map +1 -1
- package/dist/cjs/components/design/headerBar/headerBar.css +6 -1
- package/dist/cjs/components/design/skeleton/Skeleton.js +48 -0
- package/dist/cjs/components/design/skeleton/Skeleton.js.map +1 -0
- package/dist/cjs/components/design/skeleton/_skeletonVariables.css +0 -0
- package/dist/cjs/components/design/skeleton/skeleton.css +86 -0
- package/dist/cjs/components/form/formFields/formFieldWrapper/FormField.js +8 -5
- package/dist/cjs/components/form/formFields/formFieldWrapper/FormField.js.map +1 -1
- package/dist/cjs/components/form/formFields/formFieldWrapper/formFieldProps.js.map +1 -1
- package/dist/cjs/components/form/formFields/subComponents/inputs/autocomplete/Autocomplete.js +15 -11
- package/dist/cjs/components/form/formFields/subComponents/inputs/autocomplete/Autocomplete.js.map +1 -1
- package/dist/cjs/components/form/formFields/subComponents/inputs/checkbox/InputCheckbox.js +37 -15
- package/dist/cjs/components/form/formFields/subComponents/inputs/checkbox/InputCheckbox.js.map +1 -1
- package/dist/cjs/components/form/formFields/subComponents/inputs/checkbox/inputCheckbox.css +4 -4
- package/dist/cjs/components/form/formFields/subComponents/inputs/checkbox/inputCheckboxProps.js.map +1 -1
- package/dist/cjs/components/form/formFields/subComponents/inputs/file/dragAndDrop/DragAndDropFileUpload.js +9 -9
- package/dist/cjs/components/form/formFields/subComponents/inputs/file/dragAndDrop/DragAndDropFileUpload.js.map +1 -1
- package/dist/cjs/components/form/formFields/subComponents/inputs/radio/styled/StyledRadioGroup.js +14 -4
- package/dist/cjs/components/form/formFields/subComponents/inputs/radio/styled/StyledRadioGroup.js.map +1 -1
- package/dist/cjs/components/form/formFields/subComponents/inputs/text/InputText.js +23 -17
- package/dist/cjs/components/form/formFields/subComponents/inputs/text/InputText.js.map +1 -1
- package/dist/cjs/components/form/formFields/subComponents/select/Select.js +6 -5
- package/dist/cjs/components/form/formFields/subComponents/select/Select.js.map +1 -1
- package/dist/cjs/components/form/formFields/subComponents/textarea/Textarea.js +55 -83
- package/dist/cjs/components/form/formFields/subComponents/textarea/Textarea.js.map +1 -1
- package/dist/cjs/components/form/formFields/subComponents/textarea/textarea.css +20 -0
- package/dist/cjs/components/form/hookFormWrapper/HookFormWrapper.js +22 -5
- package/dist/cjs/components/form/hookFormWrapper/HookFormWrapper.js.map +1 -1
- package/dist/cjs/components/form/validation/ValidationMessages.js +36 -38
- package/dist/cjs/components/form/validation/ValidationMessages.js.map +1 -1
- package/dist/cjs/components/index.js +7 -0
- package/dist/cjs/components/index.js.map +1 -1
- package/dist/cjs/exampleUIs/exampleComponents/DemoContactForm.js +1 -2
- package/dist/cjs/exampleUIs/exampleComponents/DemoContactForm.js.map +1 -1
- package/dist/cjs/helpers/index.js +12 -0
- package/dist/cjs/helpers/index.js.map +1 -1
- package/dist/cjs/helpers/stringHelpers.js +48 -2
- package/dist/cjs/helpers/stringHelpers.js.map +1 -1
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/interfaces/headerText.interface.js.map +1 -1
- package/dist/cjs/package.json +137 -151
- package/dist/cjs/styles/index.css +36 -25
- package/dist/cjs/styles/shared/_allPartials.css +22 -25
- package/dist/cjs/styles/shared/forms/_forms.css +22 -25
- package/dist/cjs/styles/variables/cssVars/_darkModeVariables.css +3 -0
- package/dist/cjs/styles/variables/cssVars/_designVariables.css +11 -0
- package/dist/components/design/dialog/Dialog.d.ts.map +1 -1
- package/dist/components/design/dialog/Dialog.test.d.ts +5 -0
- package/dist/components/design/dialog/Dialog.test.d.ts.map +1 -0
- package/dist/components/design/headerBar/HeaderBar.d.ts.map +1 -1
- package/dist/components/design/skeleton/Skeleton.d.ts +27 -0
- package/dist/components/design/skeleton/Skeleton.d.ts.map +1 -0
- package/dist/components/form/formFields/formFieldWrapper/FormField.d.ts.map +1 -1
- package/dist/components/form/formFields/formFieldWrapper/formFieldProps.d.ts +7 -2
- package/dist/components/form/formFields/formFieldWrapper/formFieldProps.d.ts.map +1 -1
- package/dist/components/form/formFields/subComponents/inputs/autocomplete/Autocomplete.d.ts.map +1 -1
- package/dist/components/form/formFields/subComponents/inputs/checkbox/InputCheckbox.d.ts.map +1 -1
- package/dist/components/form/formFields/subComponents/inputs/checkbox/InputCheckbox.test.d.ts +5 -0
- package/dist/components/form/formFields/subComponents/inputs/checkbox/InputCheckbox.test.d.ts.map +1 -0
- package/dist/components/form/formFields/subComponents/inputs/checkbox/inputCheckboxProps.d.ts +8 -6
- package/dist/components/form/formFields/subComponents/inputs/checkbox/inputCheckboxProps.d.ts.map +1 -1
- package/dist/components/form/formFields/subComponents/inputs/file/dragAndDrop/DragAndDropFileUpload.d.ts.map +1 -1
- package/dist/components/form/formFields/subComponents/inputs/radio/styled/StyledRadioGroup.d.ts.map +1 -1
- package/dist/components/form/formFields/subComponents/inputs/text/InputText.d.ts.map +1 -1
- package/dist/components/form/formFields/subComponents/nestedFormContext.test.d.ts +5 -0
- package/dist/components/form/formFields/subComponents/nestedFormContext.test.d.ts.map +1 -0
- package/dist/components/form/formFields/subComponents/select/Select.d.ts.map +1 -1
- package/dist/components/form/formFields/subComponents/textarea/Textarea.d.ts +4 -3
- package/dist/components/form/formFields/subComponents/textarea/Textarea.d.ts.map +1 -1
- package/dist/components/form/hookFormWrapper/HookFormWrapper.d.ts +3 -0
- package/dist/components/form/hookFormWrapper/HookFormWrapper.d.ts.map +1 -1
- package/dist/components/form/hookFormWrapper/HookFormWrapper.test.d.ts +5 -0
- package/dist/components/form/hookFormWrapper/HookFormWrapper.test.d.ts.map +1 -0
- package/dist/components/form/validation/ValidationMessages.d.ts +8 -1
- package/dist/components/form/validation/ValidationMessages.d.ts.map +1 -1
- package/dist/components/form/validation/ValidationMessages.test.d.ts +5 -0
- package/dist/components/form/validation/ValidationMessages.test.d.ts.map +1 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.d.ts.map +1 -1
- package/dist/esm/autoGenerated/libraryThemes.js +12 -12
- package/dist/esm/autoGenerated/libraryThemes.js.map +1 -1
- package/dist/esm/autoGenerated/libraryThemes.json +12 -12
- package/dist/esm/components/design/dialog/Dialog.js +1 -1
- package/dist/esm/components/design/dialog/Dialog.js.map +1 -1
- package/dist/esm/components/design/headerBar/HeaderBar.js +3 -1
- package/dist/esm/components/design/headerBar/HeaderBar.js.map +1 -1
- package/dist/esm/components/design/headerBar/headerBar.css +6 -1
- package/dist/esm/components/design/skeleton/Skeleton.js +40 -0
- package/dist/esm/components/design/skeleton/Skeleton.js.map +1 -0
- package/dist/esm/components/design/skeleton/_skeletonVariables.css +0 -0
- package/dist/esm/components/design/skeleton/skeleton.css +86 -0
- package/dist/esm/components/form/formFields/formFieldWrapper/FormField.js +8 -5
- package/dist/esm/components/form/formFields/formFieldWrapper/FormField.js.map +1 -1
- package/dist/esm/components/form/formFields/formFieldWrapper/formFieldProps.js.map +1 -1
- package/dist/esm/components/form/formFields/subComponents/inputs/autocomplete/Autocomplete.js +16 -12
- package/dist/esm/components/form/formFields/subComponents/inputs/autocomplete/Autocomplete.js.map +1 -1
- package/dist/esm/components/form/formFields/subComponents/inputs/checkbox/InputCheckbox.js +37 -15
- package/dist/esm/components/form/formFields/subComponents/inputs/checkbox/InputCheckbox.js.map +1 -1
- package/dist/esm/components/form/formFields/subComponents/inputs/checkbox/inputCheckbox.css +4 -4
- package/dist/esm/components/form/formFields/subComponents/inputs/checkbox/inputCheckboxProps.js.map +1 -1
- package/dist/esm/components/form/formFields/subComponents/inputs/file/dragAndDrop/DragAndDropFileUpload.js +8 -8
- package/dist/esm/components/form/formFields/subComponents/inputs/file/dragAndDrop/DragAndDropFileUpload.js.map +1 -1
- package/dist/esm/components/form/formFields/subComponents/inputs/radio/styled/StyledRadioGroup.js +16 -6
- package/dist/esm/components/form/formFields/subComponents/inputs/radio/styled/StyledRadioGroup.js.map +1 -1
- package/dist/esm/components/form/formFields/subComponents/inputs/text/InputText.js +23 -17
- package/dist/esm/components/form/formFields/subComponents/inputs/text/InputText.js.map +1 -1
- package/dist/esm/components/form/formFields/subComponents/select/Select.js +6 -5
- package/dist/esm/components/form/formFields/subComponents/select/Select.js.map +1 -1
- package/dist/esm/components/form/formFields/subComponents/textarea/Textarea.js +50 -78
- package/dist/esm/components/form/formFields/subComponents/textarea/Textarea.js.map +1 -1
- package/dist/esm/components/form/formFields/subComponents/textarea/textarea.css +20 -0
- package/dist/esm/components/form/hookFormWrapper/HookFormWrapper.js +22 -5
- package/dist/esm/components/form/hookFormWrapper/HookFormWrapper.js.map +1 -1
- package/dist/esm/components/form/validation/ValidationMessages.js +36 -38
- package/dist/esm/components/form/validation/ValidationMessages.js.map +1 -1
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/components/index.js.map +1 -1
- package/dist/esm/exampleUIs/exampleComponents/DemoContactForm.js +1 -2
- package/dist/esm/exampleUIs/exampleComponents/DemoContactForm.js.map +1 -1
- package/dist/esm/helpers/index.js +1 -1
- package/dist/esm/helpers/index.js.map +1 -1
- package/dist/esm/helpers/stringHelpers.js +44 -0
- package/dist/esm/helpers/stringHelpers.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/interfaces/headerText.interface.js.map +1 -1
- package/dist/esm/package.json +137 -151
- package/dist/esm/styles/index.css +36 -25
- package/dist/esm/styles/shared/_allPartials.css +22 -25
- package/dist/esm/styles/shared/forms/_forms.css +22 -25
- package/dist/esm/styles/variables/cssVars/_darkModeVariables.css +3 -0
- package/dist/esm/styles/variables/cssVars/_designVariables.css +11 -0
- package/dist/exampleUIs/exampleComponents/DemoContactForm.d.ts.map +1 -1
- package/dist/helpers/index.d.ts +1 -1
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/stringHelpers.d.ts +17 -0
- package/dist/helpers/stringHelpers.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/interfaces/headerText.interface.d.ts +1 -0
- package/dist/interfaces/headerText.interface.d.ts.map +1 -1
- package/dist/package.json +137 -151
- package/package.json +137 -151
- package/dist/cjs/components/form/formFields/utilities/formUtilities.js +0 -22
- package/dist/cjs/components/form/formFields/utilities/formUtilities.js.map +0 -1
- package/dist/components/form/formFields/utilities/formUtilities.d.ts +0 -18
- package/dist/components/form/formFields/utilities/formUtilities.d.ts.map +0 -1
- package/dist/esm/components/form/formFields/utilities/formUtilities.js +0 -16
- package/dist/esm/components/form/formFields/utilities/formUtilities.js.map +0 -1
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
.skeleton {
|
|
2
|
+
display: inline-flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
align-items: stretch;
|
|
5
|
+
gap: var(--skeletonLineGap, 8px);
|
|
6
|
+
vertical-align: middle;
|
|
7
|
+
inline-size: var(--skeletonWidth, 100%);
|
|
8
|
+
max-inline-size: 100%;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
.skeletonBar {
|
|
12
|
+
inline-size: 100%;
|
|
13
|
+
block-size: var(--skeletonHeight, var(--skeletonLineHeight, 1em));
|
|
14
|
+
background-color: var(--skeletonBg, #eef2f4);
|
|
15
|
+
border-radius: var(--skeletonBorderRadius, 3px);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/* Variants */
|
|
19
|
+
.skeleton_text .skeletonBar:last-child:not(:only-child) {
|
|
20
|
+
inline-size: var(--skeletonLastLineWidth, 60%);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.skeleton_block .skeletonBar {
|
|
24
|
+
block-size: var(--skeletonHeight, var(--skeletonBlockHeight, 120px));
|
|
25
|
+
border-radius: 0;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.skeleton_rounded .skeletonBar {
|
|
29
|
+
block-size: var(--skeletonHeight, var(--skeletonBlockHeight, 120px));
|
|
30
|
+
border-radius: var(--skeletonRoundedBorderRadius, 8px);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.skeleton_circle {
|
|
34
|
+
inline-size: var(--skeletonWidth, var(--skeletonCircleSize, 40px));
|
|
35
|
+
}
|
|
36
|
+
.skeleton_circle .skeletonBar {
|
|
37
|
+
block-size: auto;
|
|
38
|
+
aspect-ratio: 1;
|
|
39
|
+
border-radius: 50%;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/* Appearance */
|
|
43
|
+
.skeleton_opaque .skeletonBar {
|
|
44
|
+
background-color: var(--skeletonOpaqueBg, #d3dee4);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.skeleton_wave .skeletonBar {
|
|
48
|
+
position: relative;
|
|
49
|
+
overflow: hidden;
|
|
50
|
+
}
|
|
51
|
+
.skeleton_wave .skeletonBar::after {
|
|
52
|
+
content: "";
|
|
53
|
+
position: absolute;
|
|
54
|
+
inset: 0;
|
|
55
|
+
transform: translateX(-100%);
|
|
56
|
+
background-image: linear-gradient(90deg, transparent, var(--skeletonHighlight, #f6f8fa), transparent);
|
|
57
|
+
animation: skeletonWave var(--skeletonAnimationDuration, 1.6s) linear infinite;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.skeleton_pulse .skeletonBar {
|
|
61
|
+
opacity: 1;
|
|
62
|
+
animation: skeletonPulse var(--skeletonAnimationDuration, 1.6s) ease-in-out infinite alternate;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@keyframes skeletonWave {
|
|
66
|
+
to {
|
|
67
|
+
transform: translateX(100%);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
@keyframes skeletonPulse {
|
|
71
|
+
from {
|
|
72
|
+
opacity: 1;
|
|
73
|
+
}
|
|
74
|
+
to {
|
|
75
|
+
opacity: 0.3;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
@media (prefers-reduced-motion: reduce) {
|
|
79
|
+
.skeleton_wave .skeletonBar::after {
|
|
80
|
+
display: none;
|
|
81
|
+
}
|
|
82
|
+
.skeleton_pulse .skeletonBar {
|
|
83
|
+
animation: none;
|
|
84
|
+
opacity: 1;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -19,7 +19,8 @@ export const FormField = ({
|
|
|
19
19
|
validation,
|
|
20
20
|
customContent,
|
|
21
21
|
customCssClasses,
|
|
22
|
-
separateLabelAndField = false
|
|
22
|
+
separateLabelAndField = false,
|
|
23
|
+
formContext
|
|
23
24
|
}) => {
|
|
24
25
|
const [isTouched, setIsTouched] = useState(false);
|
|
25
26
|
const wrapperCssClass = `
|
|
@@ -64,9 +65,9 @@ export const FormField = ({
|
|
|
64
65
|
case 'select':
|
|
65
66
|
return /*#__PURE__*/React.createElement(Select, fieldProps);
|
|
66
67
|
case 'checkbox':
|
|
67
|
-
|
|
68
|
+
throw new Error('Checkboxes require special handling. Please use the InputCheckbox component instead.');
|
|
68
69
|
case 'file':
|
|
69
|
-
|
|
70
|
+
throw new Error('File inputs require special handling. Please use the DragAndDropFileUpload component instead.');
|
|
70
71
|
case 'password':
|
|
71
72
|
return /*#__PURE__*/React.createElement(InputText, fieldProps);
|
|
72
73
|
case 'date':
|
|
@@ -85,7 +86,9 @@ export const FormField = ({
|
|
|
85
86
|
isRequired: validation && typeof validation.required !== 'undefined',
|
|
86
87
|
customContent
|
|
87
88
|
};
|
|
88
|
-
return /*#__PURE__*/React.createElement(HookFormWrapper,
|
|
89
|
+
return /*#__PURE__*/React.createElement(HookFormWrapper, {
|
|
90
|
+
formContext: formContext
|
|
91
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
89
92
|
className: wrapperCssClass,
|
|
90
93
|
title: wrapperHoverText()
|
|
91
94
|
}, /*#__PURE__*/React.createElement("label", {
|
|
@@ -94,7 +97,7 @@ export const FormField = ({
|
|
|
94
97
|
htmlFor: field.id
|
|
95
98
|
}, (!label?.position || label.position === 'left' || separateLabelAndField) && /*#__PURE__*/React.createElement(FormFieldLabel, labelProps), !separateLabelAndField && /*#__PURE__*/React.createElement("span", {
|
|
96
99
|
className: "inputContainer"
|
|
97
|
-
}, getFieldElement(), label?.position === 'inset' && /*#__PURE__*/React.createElement(FormFieldLabel, labelProps)), label?.position === 'right' && /*#__PURE__*/React.createElement(FormFieldLabel, labelProps), showSpinner && /*#__PURE__*/React.createElement(Spinner, null),
|
|
100
|
+
}, getFieldElement(), label?.position === 'inset' && /*#__PURE__*/React.createElement(FormFieldLabel, labelProps)), label?.position === 'right' && /*#__PURE__*/React.createElement(FormFieldLabel, labelProps), showSpinner && /*#__PURE__*/React.createElement(Spinner, null), /*#__PURE__*/React.createElement(ValidationMessages, {
|
|
98
101
|
name: field.name,
|
|
99
102
|
validation: validation
|
|
100
103
|
})), separateLabelAndField && /*#__PURE__*/React.createElement("div", {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"FormField.js","names":["React","useState","HookFormWrapper","FormFieldLabel","InputText","ValidationMessages","Spinner","InputSearch","InputDate","Select","Textarea","Autocomplete","FormField","label","field","layout","showSpinner","validation","customContent","customCssClasses","separateLabelAndField","isTouched","setIsTouched","wrapperCssClass","type","wrapper","position","wrapperHoverText","hide","undefined","placeholder","text","getFieldElement","fieldType","toLowerCase","fieldProps","defaultValue","onTouched","createElement","Error","labelProps","inputId","id","isRequired","required","className","title","labelId","htmlFor","name"],"sources":["../../../../../../src/components/form/formFields/formFieldWrapper/FormField.tsx"],"sourcesContent":["'use client';\n\nimport React, {
|
|
1
|
+
{"version":3,"file":"FormField.js","names":["React","useState","HookFormWrapper","FormFieldLabel","InputText","ValidationMessages","Spinner","InputSearch","InputDate","Select","Textarea","Autocomplete","FormField","label","field","layout","showSpinner","validation","customContent","customCssClasses","separateLabelAndField","formContext","isTouched","setIsTouched","wrapperCssClass","type","wrapper","position","wrapperHoverText","hide","undefined","placeholder","text","getFieldElement","fieldType","toLowerCase","fieldProps","defaultValue","onTouched","createElement","Error","labelProps","inputId","id","isRequired","required","className","title","labelId","htmlFor","name"],"sources":["../../../../../../src/components/form/formFields/formFieldWrapper/FormField.tsx"],"sourcesContent":["'use client';\n\nimport React, { useState } from 'react';\nimport { HookFormWrapper } from '../../hookFormWrapper/HookFormWrapper';\nimport { FormFieldLabel } from '../subComponents/labels/FormFieldLabel';\nimport { FormFieldProps } from './formFieldProps';\nimport { InputText } from '../subComponents/inputs/text/InputText';\nimport { ValidationMessages } from '../../validation/ValidationMessages';\nimport { Spinner } from '../../../design/spinner/Spinner';\nimport { InputSearch } from '../subComponents/inputs/search/InputSearch';\nimport { InputDate } from '../subComponents/inputs/date/InputDate';\nimport { Select } from '../subComponents/select/Select';\nimport { Textarea } from '../subComponents/textarea/Textarea';\nimport { Autocomplete } from '../subComponents/inputs/autocomplete/Autocomplete';\n\nexport const FormField: React.FC<FormFieldProps> = (\n {\n label,\n field,\n layout = 'stacked',\n showSpinner,\n validation,\n customContent,\n customCssClasses,\n separateLabelAndField = false,\n formContext\n }\n) => {\n const [isTouched, setIsTouched] = useState(false);\n\n const wrapperCssClass = `\n formField \n ${ layout } \n ${ field.type }_Field \n ${ customCssClasses?.wrapper || '' } \n ${ isTouched ? 'touched' : '' } \n ${ typeof validation !== 'undefined' ? 'withValidation' : '' } \n ${ label?.position === 'inset' ? 'insetLabel' : '' }\n `;\n\n const wrapperHoverText = (): string | undefined => {\n if (!label.hide) {\n return undefined;\n }\n\n if (field.placeholder) {\n return field.placeholder;\n }\n\n if (typeof label.text === 'string') {\n return label.text;\n }\n\n return undefined;\n };\n\n const getFieldElement = () => {\n const fieldType = field.type.toLowerCase();\n const fieldProps = {\n field: {\n ...field,\n ...(fieldType !== 'checkbox' ? { defaultValue: field.defaultValue || '' } : {}),\n onTouched: () => setIsTouched(true)\n },\n label,\n showSpinner,\n validation,\n customContent\n };\n\n switch (fieldType) {\n case 'textarea':\n return <Textarea { ...fieldProps } />;\n case 'select':\n return <Select { ...fieldProps } />;\n case 'checkbox':\n throw new Error('Checkboxes require special handling. Please use the InputCheckbox component instead.');\n case 'file':\n throw new Error('File inputs require special handling. Please use the DragAndDropFileUpload component instead.');\n case 'password':\n return <InputText { ...fieldProps } />;\n case 'date':\n return <InputDate { ...fieldProps } />;\n case 'search':\n return <InputSearch { ...fieldProps } />;\n case 'combobox':\n return <Autocomplete { ...fieldProps } />;\n default:\n return <InputText { ...fieldProps } />;\n }\n };\n\n const labelProps = {\n ...label,\n inputId: field.id,\n isRequired: validation && typeof validation.required !== 'undefined',\n customContent\n };\n\n return (\n <HookFormWrapper formContext={ formContext }>\n <div\n className={ wrapperCssClass }\n title={ wrapperHoverText() }\n >\n <label\n id={ label.labelId || `${ field.id }_label` }\n className={ `${ customCssClasses?.label || '' } ${ showSpinner ? 'withSpinner' : '' } ${ label.hide ? 'hiddenLabel' : '' }` }\n htmlFor={ field.id }\n >\n\n { (!label?.position || label.position === 'left' || separateLabelAndField)\n && <FormFieldLabel { ...labelProps } /> }\n\n {\n !separateLabelAndField && (\n <span className=\"inputContainer\">\n {\n getFieldElement()\n }\n { label?.position === 'inset'\n && <FormFieldLabel { ...labelProps } /> }\n </span>\n )\n }\n\n { label?.position === 'right'\n && <FormFieldLabel { ...labelProps } /> }\n\n {\n showSpinner && <Spinner />\n }\n\n <ValidationMessages name={ field.name } validation={ validation } />\n </label>\n\n {\n separateLabelAndField && (\n <div className=\"inputContainer\">\n {\n getFieldElement()\n }\n </div>\n )\n }\n </div>\n </HookFormWrapper>\n );\n};\n\nexport default FormField;\n"],"mappings":"AAAA,YAAY;;AAEZ,OAAOA,KAAK,IAAIC,QAAQ,QAAQ,OAAO;AACvC,SAASC,eAAe,QAAQ,uCAAuC;AACvE,SAASC,cAAc,QAAQ,wCA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AY,CAAE,CAC9D,CAAC,EAGNG,qBAAqB,iBACnBpB,KAAA,CAAAuC,aAAA;IAAKO,SAAS,EAAC;EAAgB,GAE3Bb,eAAe,CAAC,CAEf,CAGN,CACU,CAAC;AAEtB,CAAC;AAED,eAAerB,SAAS","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"formFieldProps.js","names":[],"sources":["../../../../../../src/components/form/formFields/formFieldWrapper/formFieldProps.ts"],"sourcesContent":["/* eslint-disable no-unused-vars */\n\nimport {\n ChangeEvent
|
|
1
|
+
{"version":3,"file":"formFieldProps.js","names":[],"sources":["../../../../../../src/components/form/formFields/formFieldWrapper/formFieldProps.ts"],"sourcesContent":["/* eslint-disable no-unused-vars */\n\nimport {\n ChangeEvent,\n ChangeEventHandler,\n FormEventHandler,\n KeyboardEvent,\n ReactElement,\n ReactEventHandler,\n ReactNode,\n} from 'react';\n\nimport type {\n InputHTMLAttributes,\n SelectHTMLAttributes,\n TextareaHTMLAttributes,\n} from 'react';\n\nimport {\n FieldValues,\n Message,\n UseFormReturn,\n Validate,\n ValidationRule\n} from 'react-hook-form';\nimport { GenericFunction } from '../../../../interfaces';\nimport { KeyboardEventHandler } from '../../../../interfaces/generic.interface';\n\n/**\n * Custom content props for additional elements around the label or field.\n */\nexport interface CustomContentProps {\n /** Element or text to display before the label. */\n preLabel?: ReactElement | string;\n /** Element or text to display after the label. */\n postLabel?: ReactElement | string;\n /** Element or text to display before the field. */\n preField?: ReactElement | string;\n /** Element or text to display after the field. */\n postField?: ReactElement | string;\n}\n\n/**\n * Props for the label element.\n */\nexport interface LabelProps {\n /** Text or element for the label. */\n text: string | ReactNode | ReactElement;\n /** The ID of the input the label is associated with. */\n inputId?: string;\n /** The ID of the label element. */\n labelId?: string;\n /** Whether to hide the label visually. */\n hide?: boolean;\n /** Position of the label relative to the field. */\n position?: 'inset' | 'left' | 'right' | string;\n /** Tooltip for the label. */\n labelTooltip?: {\n /** Text for the tooltip. */\n text: string;\n /** Optional icon for the tooltip. */\n icon?: ReactElement | string;\n };\n /** Screen reader instructions for the label. */\n srInstruction?: string;\n /** Whether the field is required. */\n isRequired?: boolean;\n /** Custom content for the label. */\n customContent?: CustomContentProps;\n}\n\n/**\n * Type for a single select option.\n */\nexport type SelectOptionObjectType = {\n /** Label of the option. */\n label: string;\n /** Value of the option. */\n value: string | number | boolean;\n};\n\n/**\n * Type for select options, which can be an object or string.\n */\nexport type SelectOptionType = SelectOptionObjectType | string;\n\n/**\n * Type for a single combobox (autocomplete) option.\n */\nexport type ComboboxOptionObjectType = {\n /** Label of the option. */\n label: string;\n /** Value of the option. */\n value: string | number | boolean;\n /** Additional data associated with the option. */\n data?: Record<string, unknown>;\n};\n\nexport type ComboboxOption = ComboboxOptionObjectType | string;\n\n// Everything we want to *override* with our own definitions in FieldProps\nexport type OverriddenKeys =\n | 'type'\n | 'id'\n | 'name'\n | 'placeholder'\n | 'defaultValue'\n | 'onChange'\n | 'onBlur'\n | 'onInput'\n | 'onKeyDown'\n | 'disabled'\n | 'readOnly'\n | 'min'\n | 'max';\n\n// All the native props we want to mix in, minus the ones we override\nexport type NativeFieldProps =\n & Omit<InputHTMLAttributes<HTMLInputElement>, OverriddenKeys>\n & Omit<SelectHTMLAttributes<HTMLSelectElement>, OverriddenKeys>\n & Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, OverriddenKeys>;\n\n/**\n * Props for the field element.\n */\nexport interface FieldProps extends NativeFieldProps {\n /** The type of the input field. */\n type: string;\n /** The ID of the input field. */\n id: string;\n /** The name of the input field. */\n name: string;\n /** Placeholder text for the input field. */\n placeholder?: string;\n /** Default value for the input field. */\n defaultValue?: string | number | readonly string[];\n /** Handler for the change event. */\n onChange?: ChangeEventHandler | ((\n event: ChangeEvent<HTMLInputElement> | KeyboardEvent<HTMLSelectElement> | KeyboardEvent<HTMLTextAreaElement>\n ) => void | GenericFunction);\n /** Handler for the blur event. */\n onBlur?: GenericFunction;\n /** Handler for the input event. */\n onInput?: FormEventHandler<\n HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement\n >;\n /** Handler for the keydown event. */\n onKeyDown?: KeyboardEventHandler | ((\n event: KeyboardEvent<HTMLInputElement> | KeyboardEvent<HTMLSelectElement> | KeyboardEvent<HTMLTextAreaElement>\n ) => void | GenericFunction);\n /** Handler for marking the field as touched. */\n onTouched?: GenericFunction;\n /** Whether to include an empty option in a dropdown. */\n includeEmptyOption?: boolean;\n /** Label for the empty option. */\n emptyOptionLabel?: string;\n /** Options for a dropdown field. */\n options?: SelectOptionType[] | ComboboxOption[];\n /** Auto-complete behaviour for the field. */\n autoComplete?: string;\n /** Whether the field allows editing and interaction. Note: Setting this to true makes it invisible to screen reader users. */\n disabled?: boolean;\n /** Setting to true prevents editing and interaction whilst still making the value visible to screen reader users. */\n readonly?: boolean;\n /** Minimum value or length. */\n min?: string | number;\n /** Maximum value or length. */\n max?: string | number;\n /**\n * Whether to enforce grapheme-aware max-length handling (used by textarea).\n * Uses `field.maxLength` (native field prop) as the source for the UI/input limit.\n * Keep `field.maxLength` and `validation.maxLength` aligned to avoid mixed UX/validation behaviour.\n */\n enforceMaxLength?: boolean;\n}\n\n/**\n * Validation rules for fields.\n */\nexport type CustomValidate<TFieldValue> = (\n value: TFieldValue,\n formValues?: unknown\n) => boolean | string | Promise<boolean | string>;\n\n/**\n * Props for validation rules.\n */\n\nexport type MinMaxRule<T> = T extends boolean\n ? ValidationRule<boolean>\n : ValidationRule<number | string>;\n\nexport interface ValidationProps<\n TFieldValue = unknown | string | boolean,\n TFormValues = unknown\n> {\n /** Whether the field is required. */\n required?: Message | ValidationRule<boolean>;\n /** Minimum value or length. */\n min?: MinMaxRule<TFieldValue>;\n /** Maximum value or length. */\n max?: MinMaxRule<TFieldValue>;\n /**\n * Maximum length validation rule.\n * Used for validation outcome/messages, while textarea UI/input limiting is driven by `field.maxLength`.\n * If both are provided, keep them equal.\n */\n maxLength?: ValidationRule<number>;\n /** Minimum length of the field. */\n minLength?: ValidationRule<number>;\n /** Regex pattern for validation. */\n pattern?: ValidationRule<RegExp>;\n /** Custom validation logic. */\n validate?: CustomValidate<TFieldValue> | Record<string, CustomValidate<TFieldValue>> | Validate<TFieldValue, TFormValues>;\n}\n\nexport type ValidationKey = keyof ValidationProps<unknown, unknown>; // Restrict to known keys\n\n/**\n * Custom CSS classes for the field components.\n */\nexport interface CustomFieldCssClassesProps {\n /** CSS class for the label. */\n label?: string;\n /** CSS class for the input field. */\n input?: string;\n /** CSS class for the wrapper. */\n wrapper?: string;\n}\n\n/**\n * Props for a form field component.\n */\nexport interface FormFieldProps {\n /** Props for the label. */\n label: LabelProps;\n /** Props for the field. */\n field: FieldProps;\n /** Layout style of the form field. */\n layout?: 'stacked' | 'horizontal' | string;\n /** Validation rules for the field. */\n validation?: ValidationProps;\n /** Whether to show a spinner. */\n showSpinner?: boolean;\n /** Custom CSS classes for the field. */\n customCssClasses?: CustomFieldCssClassesProps;\n /** Custom content for the field. */\n customContent?: CustomContentProps;\n /** Override the default nesting of the input inside the label. */\n separateLabelAndField?: boolean;\n /** An existing form context to use when React context cannot reach this field, e.g. across a Next.js client boundary. */\n formContext?: UseFormReturn<FieldValues, any, FieldValues>;\n}\n\nexport type TextareaFieldProps = Omit<FieldProps, 'onSelect'> & {\n onSelect?: ReactEventHandler<HTMLTextAreaElement>;\n};\n"],"mappings":"","ignoreList":[]}
|
package/dist/esm/components/form/formFields/subComponents/inputs/autocomplete/Autocomplete.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import React, { useState, useRef, useMemo } from 'react';
|
|
3
|
+
import React, { useState, useRef, useMemo, useCallback } from 'react';
|
|
4
4
|
import { useFormContext } from 'react-hook-form';
|
|
5
5
|
import { useDebouncedCallback } from 'use-debounce';
|
|
6
6
|
import { useOnClickOutside, usePopupKeys } from '../../../../../../hooks';
|
|
@@ -24,7 +24,7 @@ export const Autocomplete = ({
|
|
|
24
24
|
const [isOpen, setIsOpen] = useState(false);
|
|
25
25
|
const [filteredOptions, setFilteredOptions] = useState(field.options || []);
|
|
26
26
|
const [selectedOption, setSelectedOption] = useState(null);
|
|
27
|
-
const
|
|
27
|
+
const inputElement = useRef(null);
|
|
28
28
|
useOnClickOutside(wrapperElement, () => setIsOpen(false));
|
|
29
29
|
usePopupKeys(wrapperElement, () => setIsOpen(false));
|
|
30
30
|
const filterOptions = useDebouncedCallback(searchTerm => {
|
|
@@ -43,15 +43,20 @@ export const Autocomplete = ({
|
|
|
43
43
|
setIsOpen(true);
|
|
44
44
|
onInputChange(searchTerm);
|
|
45
45
|
}, debounceTime);
|
|
46
|
-
const handleInputChange = event => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
};
|
|
46
|
+
const handleInputChange = useCallback(event => {
|
|
47
|
+
inputElement.current = event.target;
|
|
48
|
+
filterOptions(event.target.value.toLowerCase());
|
|
49
|
+
}, [filterOptions]);
|
|
51
50
|
const handleOptionSelect = option => {
|
|
52
51
|
const displayValue = typeof option === 'string' ? option : JSON.stringify(option.label);
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
// The registered input is uncontrolled, so write to both the DOM and form state.
|
|
53
|
+
if (inputElement.current) {
|
|
54
|
+
inputElement.current.value = displayValue;
|
|
55
|
+
}
|
|
56
|
+
setValue(field.name, displayValue, {
|
|
57
|
+
shouldValidate: true,
|
|
58
|
+
shouldDirty: true
|
|
59
|
+
});
|
|
55
60
|
setSelectedOption(option);
|
|
56
61
|
setIsOpen(false);
|
|
57
62
|
onOptionSelect(option);
|
|
@@ -68,8 +73,7 @@ export const Autocomplete = ({
|
|
|
68
73
|
'aria-haspopup': 'listbox',
|
|
69
74
|
role: 'combobox',
|
|
70
75
|
onFocus: () => setIsOpen(true),
|
|
71
|
-
onChange: handleInputChange
|
|
72
|
-
defaultValue: inputValue
|
|
76
|
+
onChange: handleInputChange
|
|
73
77
|
},
|
|
74
78
|
label,
|
|
75
79
|
validation,
|
|
@@ -77,7 +81,7 @@ export const Autocomplete = ({
|
|
|
77
81
|
customCssClasses,
|
|
78
82
|
customContent
|
|
79
83
|
};
|
|
80
|
-
}, [field, isOpen, optionsContainerId, validation, showSpinner, customCssClasses, customContent, handleInputChange
|
|
84
|
+
}, [field, isOpen, optionsContainerId, label, validation, showSpinner, customCssClasses, customContent, handleInputChange]);
|
|
81
85
|
return /*#__PURE__*/React.createElement("div", {
|
|
82
86
|
ref: wrapperElement,
|
|
83
87
|
className: `autocompleteWrapper ${isOpen ? 'open' : 'closed'}`
|
package/dist/esm/components/form/formFields/subComponents/inputs/autocomplete/Autocomplete.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Autocomplete.js","names":["React","useState","useRef","useMemo","useFormContext","useDebouncedCallback","useOnClickOutside","usePopupKeys","InputText","Autocomplete","field","label","validation","showSpinner","customCssClasses","customContent","onOptionSelect","onInputChange","debounceTime","setValue","wrapperElement","isOpen","setIsOpen","filteredOptions","setFilteredOptions","options","selectedOption","setSelectedOption","inputValue","setInputValue","filterOptions","searchTerm","matchingOptions","filter","option","toLowerCase","includes","JSON","stringify","handleInputChange","event","newValue","target","value","handleOptionSelect","displayValue","name","optionsContainerId","id","comboBoxFieldProps","type","role","onFocus","onChange","defaultValue","createElement","ref","className","tabIndex","length","map","optionId","key","onClick"],"sources":["../../../../../../../../src/components/form/formFields/subComponents/inputs/autocomplete/Autocomplete.tsx"],"sourcesContent":["'use client';\n\nimport React, { useState, useRef, useMemo } from 'react';\nimport { useFormContext } from 'react-hook-form';\nimport { useDebouncedCallback } from 'use-debounce';\nimport { ComboboxOption, FieldProps, FormFieldProps } from '../../../formFieldWrapper/formFieldProps';\nimport { useOnClickOutside, usePopupKeys } from '../../../../../../hooks';\n\nimport { InputText, InputTextProps } from '../text/InputText';\n\nimport './autocomplete.scss';\n\n\nexport interface ComboboxFieldProps extends React.InputHTMLAttributes<HTMLInputElement>, Omit<FormFieldProps, 'field'> {\n field: Omit<FieldProps, 'type' | 'options'> & {\n options?: ComboboxOption[] | string[];\n };\n /* eslint-disable-next-line no-unused-vars */\n onOptionSelect?: (option: ComboboxOption | string) => void;\n /* eslint-disable-next-line no-unused-vars */\n onInputChange?: (inputValue: string) => void;\n debounceTime?: number;\n}\n\nexport const Autocomplete: React.FC<ComboboxFieldProps> = (\n {\n field,\n label,\n validation,\n showSpinner,\n customCssClasses,\n customContent,\n onOptionSelect = () => {},\n onInputChange = () => {},\n debounceTime = 500,\n }\n) => {\n const { setValue } = useFormContext();\n\n const wrapperElement = useRef<HTMLDivElement>(null);\n const [isOpen, setIsOpen] = useState(false);\n const [filteredOptions, setFilteredOptions] = useState<(string | ComboboxOption)[]>(field.options || []);\n const [selectedOption, setSelectedOption] = useState<ComboboxOption | string | null>(null);\n const [inputValue, setInputValue] = useState('');\n\n useOnClickOutside(wrapperElement, () => setIsOpen(false));\n usePopupKeys(wrapperElement, () => setIsOpen(false));\n\n const filterOptions = useDebouncedCallback((searchTerm: string) => {\n const matchingOptions: (string | ComboboxOption)[] = field.options ? field.options.filter((option) => {\n if (typeof option === 'string') {\n return option.toLowerCase().includes(searchTerm);\n }\n if (typeof option.label === 'string') {\n return option.label.toLowerCase().includes(searchTerm);\n }\n // For non-string labels, convert to JSON string and check\n return JSON.stringify(option.label).toLowerCase().includes(searchTerm);\n }) : [];\n setSelectedOption(null);\n setFilteredOptions(matchingOptions);\n setIsOpen(true);\n onInputChange(searchTerm);\n }, debounceTime);\n\n const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {\n const newValue = event.target.value;\n setInputValue(newValue);\n filterOptions(newValue.toLowerCase());\n };\n\n const handleOptionSelect = (option: ComboboxOption | string) => {\n const displayValue = typeof option === 'string' ? option : JSON.stringify(option.label);\n setInputValue(displayValue);\n setValue(field.name, displayValue);\n setSelectedOption(option);\n setIsOpen(false);\n onOptionSelect(option);\n };\n\n const optionsContainerId = `${ field.id || field.name }Options`;\n\n const comboBoxFieldProps: InputTextProps = useMemo(() => {\n return {\n field: {\n ...field,\n type: 'search',\n 'aria-autocomplete': 'both',\n 'aria-expanded': isOpen,\n 'aria-controls': optionsContainerId,\n 'aria-haspopup': 'listbox',\n role: 'combobox',\n onFocus: () => setIsOpen(true),\n onChange: handleInputChange,\n defaultValue: inputValue,\n },\n label,\n validation,\n showSpinner,\n customCssClasses,\n customContent,\n };\n }, [field, isOpen, optionsContainerId, validation, showSpinner, customCssClasses, customContent, handleInputChange, selectedOption]);\n \n return (\n <div ref={ wrapperElement } className={ `autocompleteWrapper ${ isOpen ? 'open' : 'closed' }` }>\n <InputText { ...comboBoxFieldProps } />\n\n {\n isOpen && filteredOptions && (\n <div tabIndex={ -1 } className=\"autocompleteOptions\">\n {\n filteredOptions.length === 0 ?\n (\n <div aria-selected=\"false\" role=\"listbox\" id={ optionsContainerId }>\n No results found\n </div>\n )\n :\n (\n <ul className=\"noBullet\" role=\"listbox\" id={ optionsContainerId }>\n {\n filteredOptions.map((option) => {\n const optionId = `${ optionsContainerId }_${ option }`;\n\n return (\n <li\n key={ optionId }\n aria-selected={ option === selectedOption ? 'true' : 'false' }\n role=\"option\"\n data-option={ option }\n >\n <button className={ option === selectedOption ? 'selected' : '' } type=\"button\" id={ optionId } onClick={ () => handleOptionSelect(option) }>\n { typeof option === 'string' ? option : option.label }\n </button>\n </li>\n );\n })\n }\n </ul>\n )\n }\n </div>\n )\n }\n </div>\n );\n};\n\nexport default Autocomplete;"],"mappings":"AAAA,YAAY;;AAEZ,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,MAAM,EAAEC,OAAO,QAAQ,OAAO;AACxD,SAASC,cAAc,QAAQ,iBAAiB;AAChD,SAASC,oBAAoB,QAAQ,cAAc;AAEnD,SAASC,iBAAiB,EAAEC,YAAY,QAAQ,yBAAyB;AAEzE,SAASC,SAAS,QAAwB,mBAAmB;AAE7D,OAAO,qBAAqB;AAc5B,OAAO,MAAMC,YAA0C,GAAGA,CACxD;EACEC,KAAK;EACLC,KAAK;EAC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;MAAQE,SAAS,EAAGvB,MAAM,KAAKR,cAAc,GAAG,UAAU,GAAG,EAAI;MAACwB,IAAI,EAAC,QAAQ;MAACF,EAAE,EAAGa,QAAU;MAACE,OAAO,EAAGA,CAAA,KAAMnB,kBAAkB,CAACV,MAAM;IAAG,GACxI,OAAOA,MAAM,KAAK,QAAQ,GAAGA,MAAM,GAAGA,MAAM,CAACvB,KACzC,CACN,CAAC;EAET,CAAC,CAED,CAGP,CAGN,CAAC;AAEV,CAAC;AAED,eAAeF,YAAY","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"Autocomplete.js","names":["React","useState","useRef","useMemo","useCallback","useFormContext","useDebouncedCallback","useOnClickOutside","usePopupKeys","InputText","Autocomplete","field","label","validation","showSpinner","customCssClasses","customContent","onOptionSelect","onInputChange","debounceTime","setValue","wrapperElement","isOpen","setIsOpen","filteredOptions","setFilteredOptions","options","selectedOption","setSelectedOption","inputElement","filterOptions","searchTerm","matchingOptions","filter","option","toLowerCase","includes","JSON","stringify","handleInputChange","event","current","target","value","handleOptionSelect","displayValue","name","shouldValidate","shouldDirty","optionsContainerId","id","comboBoxFieldProps","type","role","onFocus","onChange","createElement","ref","className","tabIndex","length","map","optionId","key","onClick"],"sources":["../../../../../../../../src/components/form/formFields/subComponents/inputs/autocomplete/Autocomplete.tsx"],"sourcesContent":["'use client';\n\nimport React, { useState, useRef, useMemo, useCallback } from 'react';\nimport { useFormContext } from 'react-hook-form';\nimport { useDebouncedCallback } from 'use-debounce';\nimport { ComboboxOption, FieldProps, FormFieldProps } from '../../../formFieldWrapper/formFieldProps';\nimport { useOnClickOutside, usePopupKeys } from '../../../../../../hooks';\n\nimport { InputText, InputTextProps } from '../text/InputText';\n\nimport './autocomplete.scss';\n\n\nexport interface ComboboxFieldProps extends React.InputHTMLAttributes<HTMLInputElement>, Omit<FormFieldProps, 'field'> {\n field: Omit<FieldProps, 'type' | 'options'> & {\n options?: ComboboxOption[] | string[];\n };\n /* eslint-disable-next-line no-unused-vars */\n onOptionSelect?: (option: ComboboxOption | string) => void;\n /* eslint-disable-next-line no-unused-vars */\n onInputChange?: (inputValue: string) => void;\n debounceTime?: number;\n}\n\nexport const Autocomplete: React.FC<ComboboxFieldProps> = (\n {\n field,\n label,\n validation,\n showSpinner,\n customCssClasses,\n customContent,\n onOptionSelect = () => {},\n onInputChange = () => {},\n debounceTime = 500,\n }\n) => {\n const { setValue } = useFormContext();\n\n const wrapperElement = useRef<HTMLDivElement>(null);\n const [isOpen, setIsOpen] = useState(false);\n const [filteredOptions, setFilteredOptions] = useState<(string | ComboboxOption)[]>(field.options || []);\n const [selectedOption, setSelectedOption] = useState<ComboboxOption | string | null>(null);\n const inputElement = useRef<HTMLInputElement | null>(null);\n\n useOnClickOutside(wrapperElement, () => setIsOpen(false));\n usePopupKeys(wrapperElement, () => setIsOpen(false));\n\n const filterOptions = useDebouncedCallback((searchTerm: string) => {\n const matchingOptions: (string | ComboboxOption)[] = field.options ? field.options.filter((option) => {\n if (typeof option === 'string') {\n return option.toLowerCase().includes(searchTerm);\n }\n if (typeof option.label === 'string') {\n return option.label.toLowerCase().includes(searchTerm);\n }\n // For non-string labels, convert to JSON string and check\n return JSON.stringify(option.label).toLowerCase().includes(searchTerm);\n }) : [];\n setSelectedOption(null);\n setFilteredOptions(matchingOptions);\n setIsOpen(true);\n onInputChange(searchTerm);\n }, debounceTime);\n\n const handleInputChange = useCallback((event: React.ChangeEvent<HTMLInputElement>) => {\n inputElement.current = event.target;\n filterOptions(event.target.value.toLowerCase());\n }, [filterOptions]);\n\n const handleOptionSelect = (option: ComboboxOption | string) => {\n const displayValue = typeof option === 'string' ? option : JSON.stringify(option.label);\n // The registered input is uncontrolled, so write to both the DOM and form state.\n if (inputElement.current) {\n inputElement.current.value = displayValue;\n }\n setValue(field.name, displayValue, { shouldValidate: true, shouldDirty: true });\n setSelectedOption(option);\n setIsOpen(false);\n onOptionSelect(option);\n };\n\n const optionsContainerId = `${ field.id || field.name }Options`;\n\n const comboBoxFieldProps: InputTextProps = useMemo(() => {\n return {\n field: {\n ...field,\n type: 'search',\n 'aria-autocomplete': 'both',\n 'aria-expanded': isOpen,\n 'aria-controls': optionsContainerId,\n 'aria-haspopup': 'listbox',\n role: 'combobox',\n onFocus: () => setIsOpen(true),\n onChange: handleInputChange,\n },\n label,\n validation,\n showSpinner,\n customCssClasses,\n customContent,\n };\n }, [field, isOpen, optionsContainerId, label, validation, showSpinner, customCssClasses, customContent, handleInputChange]);\n \n return (\n <div ref={ wrapperElement } className={ `autocompleteWrapper ${ isOpen ? 'open' : 'closed' }` }>\n <InputText { ...comboBoxFieldProps } />\n\n {\n isOpen && filteredOptions && (\n <div tabIndex={ -1 } className=\"autocompleteOptions\">\n {\n filteredOptions.length === 0 ?\n (\n <div aria-selected=\"false\" role=\"listbox\" id={ optionsContainerId }>\n No results found\n </div>\n )\n :\n (\n <ul className=\"noBullet\" role=\"listbox\" id={ optionsContainerId }>\n {\n filteredOptions.map((option) => {\n const optionId = `${ optionsContainerId }_${ option }`;\n\n return (\n <li\n key={ optionId }\n aria-selected={ option === selectedOption ? 'true' : 'false' }\n role=\"option\"\n data-option={ option }\n >\n <button className={ option === selectedOption ? 'selected' : '' } type=\"button\" id={ optionId } onClick={ () => handleOptionSelect(option) }>\n { typeof option === 'string' ? option : option.label }\n </button>\n </li>\n );\n })\n }\n </ul>\n )\n }\n </div>\n )\n }\n </div>\n );\n};\n\nexport default Autocomplete;"],"mappings":"AAAA,YAAY;;AAEZ,OAAOA,KAAK,IAAIC,QAAQ,EAAEC,MAAM,EAAEC,OAAO,EAAEC,WAAW,QAAQ,OAAO;AACrE,SAASC,cAAc,QAAQ,iBAAiB;AAChD,SAASC,oBAAoB,QAAQ,cAAc;AAEnD,SAASC,iBAAiB,EAAEC,YAAY,QAAQ,yBAAyB;AAEzE,SAASC,SAAS,QAAwB,mBAAmB;AAE7D,OAAO,qBAAqB;AAc5B,OAAO,MAAMC,YAA0C,GAAGA,CACxD;EACEC,KAAK;EACLC,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,cAAc,GAAG,MAAM,GAAG,OAAS;MAC9D0B,IAAI,EAAC,QAAQ;MACb,eAAcnB;IAAQ,gBAEtBlC,KAAA,CAAAwD,aAAA;MAAQE,SAAS,EAAGxB,MAAM,KAAKP,cAAc,GAAG,UAAU,GAAG,EAAI;MAACyB,IAAI,EAAC,QAAQ;MAACF,EAAE,EAAGY,QAAU;MAACE,OAAO,EAAGA,CAAA,KAAMpB,kBAAkB,CAACV,MAAM;IAAG,GACxI,OAAOA,MAAM,KAAK,QAAQ,GAAGA,MAAM,GAAGA,MAAM,CAACtB,KACzC,CACN,CAAC;EAET,CAAC,CAED,CAGP,CAGN,CAAC;AAEV,CAAC;AAED,eAAeF,YAAY","ignoreList":[]}
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
import React, { useState } from 'react';
|
|
3
|
+
import React, { useEffect, useState } from 'react';
|
|
4
4
|
import { useFormContext } from 'react-hook-form';
|
|
5
|
-
import { NoHookFormContext } from '../../../utilities/formUtilities';
|
|
6
5
|
import { HookFormWrapper } from '../../../../hookFormWrapper/HookFormWrapper';
|
|
7
6
|
import { FormFieldLabel } from '../../labels/FormFieldLabel';
|
|
8
7
|
import { ValidationMessages } from '../../../../validation/ValidationMessages';
|
|
9
8
|
import { Spinner } from '../../../../../design/spinner/Spinner';
|
|
10
9
|
import { Icon } from '../../../../../design/icons/basicIcon/Icon';
|
|
11
10
|
import './inputCheckbox.css';
|
|
12
|
-
export const InputCheckbox = ({
|
|
11
|
+
export const InputCheckbox = props => /*#__PURE__*/React.createElement(HookFormWrapper, {
|
|
12
|
+
formContext: props.formContext
|
|
13
|
+
}, /*#__PURE__*/React.createElement(InputCheckboxField, props));
|
|
14
|
+
const InputCheckboxField = ({
|
|
13
15
|
label,
|
|
14
16
|
field: {
|
|
15
17
|
id,
|
|
16
18
|
name,
|
|
19
|
+
value,
|
|
17
20
|
defaultChecked,
|
|
18
21
|
onBlur = () => {},
|
|
19
22
|
onChange = () => {},
|
|
@@ -21,16 +24,27 @@ export const InputCheckbox = ({
|
|
|
21
24
|
},
|
|
22
25
|
validation,
|
|
23
26
|
showSpinner,
|
|
27
|
+
icons,
|
|
24
28
|
customCssClasses,
|
|
25
29
|
customContent
|
|
26
30
|
}) => {
|
|
27
31
|
const [isTouched, setIsTouched] = useState(false);
|
|
28
32
|
const {
|
|
29
33
|
register,
|
|
30
|
-
getFieldState
|
|
31
|
-
|
|
32
|
-
;
|
|
34
|
+
getFieldState,
|
|
35
|
+
setValue
|
|
36
|
+
} = useFormContext();
|
|
33
37
|
const fieldState = getFieldState(name);
|
|
38
|
+
|
|
39
|
+
// Initialize the form value with defaultChecked on mount
|
|
40
|
+
useEffect(() => {
|
|
41
|
+
if (defaultChecked) {
|
|
42
|
+
setValue(name, true, {
|
|
43
|
+
shouldValidate: false,
|
|
44
|
+
shouldDirty: false
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}, [name, setValue, defaultChecked, value]);
|
|
34
48
|
const wrapperCssClass = `formField checkBoxField ${customCssClasses?.wrapper || ''} ${isTouched ? 'touched' : ''}`;
|
|
35
49
|
const inputCssClass = `${customCssClasses?.input || ''}${fieldState?.invalid ? ' invalidField' : ''}`;
|
|
36
50
|
const isRequired = validation && typeof validation.required !== 'undefined';
|
|
@@ -50,19 +64,26 @@ export const InputCheckbox = ({
|
|
|
50
64
|
isRequired,
|
|
51
65
|
customContent
|
|
52
66
|
};
|
|
67
|
+
const checkedIcon = icons?.checked ?? /*#__PURE__*/React.createElement(Icon, {
|
|
68
|
+
icon: "checkbox-checked"
|
|
69
|
+
});
|
|
70
|
+
const uncheckedIcon = icons?.unchecked ?? /*#__PURE__*/React.createElement(Icon, {
|
|
71
|
+
icon: "checkbox-unchecked"
|
|
72
|
+
});
|
|
53
73
|
const inputProps = {
|
|
54
74
|
type: 'checkbox',
|
|
55
75
|
id,
|
|
76
|
+
value: String(value),
|
|
56
77
|
className: inputCssClass,
|
|
57
|
-
defaultChecked,
|
|
58
78
|
'aria-required': isRequired,
|
|
59
79
|
...register(name, {
|
|
60
80
|
onChange,
|
|
61
81
|
onBlur: HandleOnBlur,
|
|
82
|
+
value: defaultChecked ? true : value,
|
|
62
83
|
...validation
|
|
63
84
|
})
|
|
64
85
|
};
|
|
65
|
-
return /*#__PURE__*/React.createElement(
|
|
86
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
66
87
|
className: wrapperCssClass
|
|
67
88
|
}, /*#__PURE__*/React.createElement("label", {
|
|
68
89
|
id: label.labelId || `${id}_label`,
|
|
@@ -71,15 +92,16 @@ export const InputCheckbox = ({
|
|
|
71
92
|
}, label.position === 'left' && /*#__PURE__*/React.createElement(FormFieldLabel, labelProps), /*#__PURE__*/React.createElement("div", {
|
|
72
93
|
className: "inputContainer"
|
|
73
94
|
}, /*#__PURE__*/React.createElement("input", inputProps), /*#__PURE__*/React.createElement("span", {
|
|
74
|
-
className: "checkboxIcons"
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
95
|
+
className: "checkboxIcons",
|
|
96
|
+
"aria-hidden": "true"
|
|
97
|
+
}, /*#__PURE__*/React.createElement("span", {
|
|
98
|
+
className: "checkboxIcon checkboxIconUnchecked"
|
|
99
|
+
}, uncheckedIcon), /*#__PURE__*/React.createElement("span", {
|
|
100
|
+
className: "checkboxIcon checkboxIconChecked"
|
|
101
|
+
}, checkedIcon))), (!label?.position || label?.position === 'right') && /*#__PURE__*/React.createElement(FormFieldLabel, labelProps), showSpinner && /*#__PURE__*/React.createElement(Spinner, null), /*#__PURE__*/React.createElement(ValidationMessages, {
|
|
80
102
|
name: name,
|
|
81
103
|
validation: validation
|
|
82
|
-
})))
|
|
104
|
+
})));
|
|
83
105
|
};
|
|
84
106
|
export const CheckboxInput = props => /*#__PURE__*/React.createElement(InputCheckbox, props);
|
|
85
107
|
//# sourceMappingURL=InputCheckbox.js.map
|
package/dist/esm/components/form/formFields/subComponents/inputs/checkbox/InputCheckbox.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InputCheckbox.js","names":["React","
|
|
1
|
+
{"version":3,"file":"InputCheckbox.js","names":["React","useEffect","useState","useFormContext","HookFormWrapper","FormFieldLabel","ValidationMessages","Spinner","Icon","InputCheckbox","props","createElement","formContext","InputCheckboxField","label","field","id","name","value","defaultChecked","onBlur","onChange","onTouched","validation","showSpinner","icons","customCssClasses","customContent","isTouched","setIsTouched","register","getFieldState","setValue","fieldState","shouldValidate","shouldDirty","wrapperCssClass","wrapper","inputCssClass","input","invalid","isRequired","required","HandleOnBlur","event","target","labelProps","inputId","checkedIcon","checked","icon","uncheckedIcon","unchecked","inputProps","type","String","className","labelId","htmlFor","position","CheckboxInput"],"sources":["../../../../../../../../src/components/form/formFields/subComponents/inputs/checkbox/InputCheckbox.tsx"],"sourcesContent":["'use client';\n\nimport React, { useEffect, useState } from 'react';\nimport { useFormContext } from 'react-hook-form';\nimport { HookFormWrapper } from '../../../../hookFormWrapper/HookFormWrapper';\nimport { FormFieldLabel } from '../../labels/FormFieldLabel';\nimport { ValidationMessages } from '../../../../validation/ValidationMessages';\nimport { Spinner } from '../../../../../design/spinner/Spinner';\nimport { Icon } from '../../../../../design/icons/basicIcon/Icon';\n\nimport { InputCheckboxProps } from './inputCheckboxProps';\n\nimport './inputCheckbox.scss';\n\nexport const InputCheckbox: React.FC<InputCheckboxProps> = (props) => (\n <HookFormWrapper formContext={ props.formContext }>\n <InputCheckboxField { ...props } />\n </HookFormWrapper>\n);\n\nconst InputCheckboxField: React.FC<InputCheckboxProps> = (\n {\n label,\n field: {\n id,\n name,\n value,\n defaultChecked,\n onBlur = () => {},\n onChange = () => {},\n onTouched = () => {}\n },\n validation,\n showSpinner,\n icons,\n customCssClasses,\n customContent\n }\n) => {\n const [isTouched, setIsTouched] = useState(false);\n const { register, getFieldState, setValue } = useFormContext();\n const fieldState = getFieldState(name);\n\n // Initialize the form value with defaultChecked on mount\n useEffect(() => {\n if (defaultChecked) {\n setValue(name, true, { shouldValidate: false, shouldDirty: false });\n }\n }, [name, setValue, defaultChecked, value]);\n\n const wrapperCssClass = `formField checkBoxField ${ customCssClasses?.wrapper || '' } ${ isTouched ? 'touched' : '' }`;\n\n const inputCssClass = `${ customCssClasses?.input || '' }${ fieldState?.invalid ? ' invalidField' : '' }`;\n\n const isRequired = validation && typeof validation.required !== 'undefined';\n\n const HandleOnBlur = (event: React.FocusEvent<HTMLInputElement>) => {\n const { target } = event;\n setIsTouched(true);\n if (target) {\n onTouched();\n onBlur(event);\n }\n };\n\n const labelProps = {\n ...label,\n inputId: id,\n isRequired,\n customContent\n };\n\n const checkedIcon = icons?.checked ?? <Icon icon=\"checkbox-checked\" />;\n const uncheckedIcon = icons?.unchecked ?? <Icon icon=\"checkbox-unchecked\" />;\n\n const inputProps = {\n type: 'checkbox',\n id,\n value: String(value),\n className: inputCssClass,\n 'aria-required': isRequired,\n ...register(\n name,\n {\n onChange,\n onBlur: HandleOnBlur,\n value: defaultChecked ? true : value,\n ...validation\n }\n )\n };\n\n return (\n <div\n className={ wrapperCssClass }\n >\n <label\n id={ label.labelId || `${ id }_label` }\n className={ `${ customCssClasses?.label || '' } ${ showSpinner ? 'withSpinner' : '' }` }\n htmlFor={ id }\n >\n\n { label.position === 'left'\n && <FormFieldLabel { ...labelProps } /> }\n\n <div className=\"inputContainer\">\n <input { ...inputProps } />\n { /* The input conveys the checked state, so the icons are decorative. */ }\n <span className=\"checkboxIcons\" aria-hidden=\"true\">\n <span className=\"checkboxIcon checkboxIconUnchecked\">{ uncheckedIcon }</span>\n <span className=\"checkboxIcon checkboxIconChecked\">{ checkedIcon }</span>\n </span>\n </div>\n\n { (!label?.position || label?.position === 'right')\n && <FormFieldLabel { ...labelProps } /> }\n\n {\n showSpinner && <Spinner />\n }\n\n <ValidationMessages name={ name } validation={ validation } />\n </label>\n </div>\n );\n};\n\nexport const CheckboxInput: React.FC<InputCheckboxProps> = (props) => <InputCheckbox {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AAa,EAAMC,KAAS,CAAC","ignoreList":[]}
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
.checkBoxField .inputContainer input[type=checkbox] ~ .checkboxIcons .icon {
|
|
29
29
|
font-size: 24px;
|
|
30
30
|
}
|
|
31
|
-
.checkBoxField .inputContainer input[type=checkbox] ~ .checkboxIcons .
|
|
31
|
+
.checkBoxField .inputContainer input[type=checkbox] ~ .checkboxIcons .checkboxIconUnchecked {
|
|
32
32
|
display: block;
|
|
33
33
|
}
|
|
34
|
-
.checkBoxField .inputContainer input[type=checkbox] ~ .checkboxIcons .
|
|
34
|
+
.checkBoxField .inputContainer input[type=checkbox] ~ .checkboxIcons .checkboxIconChecked {
|
|
35
35
|
display: none;
|
|
36
36
|
}
|
|
37
|
-
.checkBoxField .inputContainer input[type=checkbox][checked] ~ .checkboxIcons .
|
|
37
|
+
.checkBoxField .inputContainer input[type=checkbox][checked] ~ .checkboxIcons .checkboxIconUnchecked, .checkBoxField .inputContainer input[type=checkbox]:checked ~ .checkboxIcons .checkboxIconUnchecked {
|
|
38
38
|
display: none;
|
|
39
39
|
}
|
|
40
|
-
.checkBoxField .inputContainer input[type=checkbox][checked] ~ .checkboxIcons .
|
|
40
|
+
.checkBoxField .inputContainer input[type=checkbox][checked] ~ .checkboxIcons .checkboxIconChecked, .checkBoxField .inputContainer input[type=checkbox]:checked ~ .checkboxIcons .checkboxIconChecked {
|
|
41
41
|
display: block;
|
|
42
42
|
}
|
package/dist/esm/components/form/formFields/subComponents/inputs/checkbox/inputCheckboxProps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inputCheckboxProps.js","names":[],"sources":["../../../../../../../../src/components/form/formFields/subComponents/inputs/checkbox/inputCheckboxProps.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"inputCheckboxProps.js","names":[],"sources":["../../../../../../../../src/components/form/formFields/subComponents/inputs/checkbox/inputCheckboxProps.ts"],"sourcesContent":["import { ReactElement, ReactNode } from 'react';\nimport {\n CustomContentProps,\n CustomFieldCssClassesProps,\n FieldProps,\n FormFieldProps,\n LabelProps,\n ValidationProps\n} from '../../../formFieldWrapper/formFieldProps';\n\nexport interface InputCheckboxLabelProps extends Omit<LabelProps, 'hide' | 'position'> {\n position?: 'left' | 'right';\n}\n\nexport interface InputCheckboxIconsProps {\n checked: string | ReactNode | ReactElement;\n unchecked: string | ReactNode | ReactElement;\n}\n\nexport interface InputCheckboxFieldProps extends Omit<FieldProps, 'type' | 'placeholder' | 'value' | 'defaultValue' | 'referenceDate' | 'includeEmptyOption' | 'options'> {\n value: boolean | string;\n defaultChecked?: boolean;\n defaultValue?: boolean | string | number | readonly string[];\n}\n\nexport interface InputCheckboxValidationProps<TFieldValue = unknown, TFormValues = unknown>\n extends Omit<ValidationProps<TFieldValue, TFormValues>, 'validate'> {\n}\n\nexport interface InputCheckboxProps extends Omit<FormFieldProps, 'label' | 'field' | 'layout' | 'validation'> {\n label: InputCheckboxLabelProps,\n field: InputCheckboxFieldProps,\n validation?: InputCheckboxValidationProps;\n showSpinner?: boolean;\n icons?: InputCheckboxIconsProps;\n customCssClasses?: CustomFieldCssClassesProps;\n customContent?: CustomContentProps;\n}\n"],"mappings":"","ignoreList":[]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
|
-
/* eslint-disable no-unused-vars */
|
|
4
3
|
import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
5
4
|
import { arrowUpFromBracket } from '@x15ventures/x15-ui-library-icons/iconDefinitions';
|
|
6
5
|
import { SvgIcon } from '@x15ventures/x15-ui-library-icons/svgIcon/SvgIcon';
|
|
@@ -10,12 +9,14 @@ import { Spinner } from '../../../../../../design/spinner/Spinner';
|
|
|
10
9
|
import { FormFieldLabel } from '../../../../subComponents/labels/FormFieldLabel';
|
|
11
10
|
import { InputFile } from '../../../../subComponents/inputs/file/InputFile';
|
|
12
11
|
import { ValidationMessages } from '../../../../../validation/ValidationMessages';
|
|
13
|
-
import { NoHookFormContext } from '../../../../utilities/formUtilities';
|
|
14
12
|
import { generateButtonClass } from '../../../../../buttons/button.helpers';
|
|
15
13
|
import { FileAttachmentsList } from '../fileAttachmentList/FileAttachmentsList';
|
|
16
14
|
import { DEFAULT_UPLOAD_FILE_EXTENSIONS, DEFAULT_UPLOAD_FILE_TYPES, BLACKLISTED_FILE_TYPES } from '../../../../../../../constants';
|
|
17
15
|
import './dragAndDropFileUpload.css';
|
|
18
|
-
export const DragAndDropFileUpload = ({
|
|
16
|
+
export const DragAndDropFileUpload = props => /*#__PURE__*/React.createElement(HookFormWrapper, {
|
|
17
|
+
formContext: props.formContext
|
|
18
|
+
}, /*#__PURE__*/React.createElement(DragAndDropFileUploadField, props));
|
|
19
|
+
const DragAndDropFileUploadField = ({
|
|
19
20
|
label,
|
|
20
21
|
field,
|
|
21
22
|
showSpinner,
|
|
@@ -45,9 +46,8 @@ export const DragAndDropFileUpload = ({
|
|
|
45
46
|
}) => {
|
|
46
47
|
const {
|
|
47
48
|
setValue,
|
|
48
|
-
trigger
|
|
49
|
-
|
|
50
|
-
} = useFormContext() || NoHookFormContext;
|
|
49
|
+
trigger
|
|
50
|
+
} = useFormContext();
|
|
51
51
|
const [activeFileList, setFileList] = useState(fileList || []);
|
|
52
52
|
const [isTouched, setIsTouched] = useState(false);
|
|
53
53
|
const [isDragActive, setIsDragActive] = useState(false);
|
|
@@ -144,7 +144,7 @@ export const DragAndDropFileUpload = ({
|
|
|
144
144
|
${showSpinner ? 'withSpinner' : ''}
|
|
145
145
|
${label.hide ? 'hiddenLabel' : ''}
|
|
146
146
|
`;
|
|
147
|
-
return /*#__PURE__*/React.createElement(
|
|
147
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
148
148
|
className: wrapperCssClass,
|
|
149
149
|
onDragOver: e => {
|
|
150
150
|
e.preventDefault();
|
|
@@ -203,7 +203,7 @@ export const DragAndDropFileUpload = ({
|
|
|
203
203
|
files: activeFileList,
|
|
204
204
|
onFilesRemoved: handleFilesEdited,
|
|
205
205
|
onFilesEdited: handleFilesEdited
|
|
206
|
-
}))
|
|
206
|
+
}));
|
|
207
207
|
};
|
|
208
208
|
export default {
|
|
209
209
|
DragAndDropFileUpload
|