@engagebay/engagebay-form-module 1.0.7-beta.1 → 1.0.7-beta.2
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/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React, { useContext } from "react";
|
|
2
2
|
import { RegisterOptions } from "react-hook-form";
|
|
3
3
|
import { FormContext } from "../context/FormContext";
|
|
4
|
-
import { FormFieldComponentPropSchema } from "../schema/FormFieldSchema";
|
|
4
|
+
import { FormFieldComponentPropSchema, FormFieldPatternsImpl } from "../schema/FormFieldSchema";
|
|
5
5
|
import { Input } from "@headlessui/react";
|
|
6
6
|
import RenderFormField from "../util/RenderFormField";
|
|
7
7
|
import { handleChange, registerFormField } from "../util";
|
|
@@ -11,7 +11,12 @@ const UrlField: React.FC<FormFieldComponentPropSchema> = (
|
|
|
11
11
|
) => {
|
|
12
12
|
const formContext = useContext(FormContext);
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
// Apply URL pattern by default unless the consumer has already set a formFieldPattern
|
|
15
|
+
const fieldConfigWithUrlPattern = props.fieldConfig.formFieldPattern
|
|
16
|
+
? props.fieldConfig
|
|
17
|
+
: { ...props.fieldConfig, formFieldPattern: [FormFieldPatternsImpl.URL] };
|
|
18
|
+
|
|
19
|
+
let registerOptions: RegisterOptions = registerFormField(fieldConfigWithUrlPattern);
|
|
15
20
|
|
|
16
21
|
let hookProps = formContext.register(props.fieldConfig.name, registerOptions);
|
|
17
22
|
|
|
@@ -47,7 +52,7 @@ const UrlField: React.FC<FormFieldComponentPropSchema> = (
|
|
|
47
52
|
};
|
|
48
53
|
|
|
49
54
|
return (
|
|
50
|
-
<RenderFormField fieldConfig={
|
|
55
|
+
<RenderFormField fieldConfig={fieldConfigWithUrlPattern} getInput={getInput} />
|
|
51
56
|
);
|
|
52
57
|
};
|
|
53
58
|
export default UrlField;
|
|
@@ -102,15 +102,15 @@ const RenderListOptions = forwardRef<HTMLUListElement, RenderListOptionsProps>(
|
|
|
102
102
|
|
|
103
103
|
const filteredList = query
|
|
104
104
|
? resultList.filter((item) => {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
const normalizedLabel = fieldConfig.dropdownFieldConfig
|
|
106
|
+
?.isCaseSensitive
|
|
107
|
+
? item.label
|
|
108
|
+
: item.label.toLowerCase();
|
|
109
109
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
return normalizedLabel
|
|
111
|
+
.replace(/\s+/g, "")
|
|
112
|
+
.includes(caseSensitive.replace(/\s+/g, ""));
|
|
113
|
+
})
|
|
114
114
|
: resultList;
|
|
115
115
|
|
|
116
116
|
let nullGroupOptions: any[] = [];
|
|
@@ -169,10 +169,11 @@ const RenderListOptions = forwardRef<HTMLUListElement, RenderListOptionsProps>(
|
|
|
169
169
|
key={option.value}
|
|
170
170
|
disabled={option.isDisabled}
|
|
171
171
|
onClick={() => setTimeout(resetToDefault, 300)}
|
|
172
|
-
className={`form-listbox-option ${
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
172
|
+
className={`form-listbox-option ${
|
|
173
|
+
selected
|
|
174
|
+
? " bg-gray-100 text-gray-900"
|
|
175
|
+
: "hover:bg-gray-100 text-gray-700"
|
|
176
|
+
}`}
|
|
176
177
|
value={option.value}
|
|
177
178
|
>
|
|
178
179
|
{fieldConfig.fieldOptionWrapper ? (
|
|
@@ -181,8 +182,9 @@ const RenderListOptions = forwardRef<HTMLUListElement, RenderListOptionsProps>(
|
|
|
181
182
|
<>
|
|
182
183
|
<div className="flex items-center justify-between gap-x-1.5">
|
|
183
184
|
<span
|
|
184
|
-
className={`block truncate w-full ${fieldConfig.customClassNames?.optionClassName} space-x-2 ${
|
|
185
|
-
|
|
185
|
+
className={`block truncate w-full ${fieldConfig.customClassNames?.optionClassName} space-x-2 ${
|
|
186
|
+
selected ? "font-medium" : "font-normal"
|
|
187
|
+
}`}
|
|
186
188
|
>
|
|
187
189
|
{option.icon && (
|
|
188
190
|
<span className="listbox-svg">{option.icon}</span>
|
|
@@ -204,7 +206,7 @@ const RenderListOptions = forwardRef<HTMLUListElement, RenderListOptionsProps>(
|
|
|
204
206
|
)}
|
|
205
207
|
</span>
|
|
206
208
|
{isTypeahead &&
|
|
207
|
-
|
|
209
|
+
!fieldConfig.dropdownFieldConfig?.isSuggestionBox ? (
|
|
208
210
|
<input
|
|
209
211
|
type="checkbox"
|
|
210
212
|
className="form-checkbox"
|
|
@@ -322,7 +324,7 @@ const RenderListOptions = forwardRef<HTMLUListElement, RenderListOptionsProps>(
|
|
|
322
324
|
fill="currentColor"
|
|
323
325
|
aria-hidden="true"
|
|
324
326
|
data-slot="icon"
|
|
325
|
-
className="h-5 w-5 text-gray-400"
|
|
327
|
+
className="h-4.5 w-4.5 text-gray-400"
|
|
326
328
|
>
|
|
327
329
|
<path
|
|
328
330
|
fillRule="evenodd"
|
|
@@ -403,28 +405,28 @@ export function renderListBoxValue(
|
|
|
403
405
|
{values.length > 1
|
|
404
406
|
? `${values.length} selected`
|
|
405
407
|
: listOptions.find((option) => option.value == value[0])?.label ||
|
|
406
|
-
|
|
408
|
+
values[0]}
|
|
407
409
|
</span>
|
|
408
410
|
{getDeleteButton()}
|
|
409
411
|
</span>
|
|
410
412
|
) : (
|
|
411
413
|
Array.isArray(values) &&
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
414
|
+
values.map((opt: any) => {
|
|
415
|
+
const option = listOptions.find((option) => option.value == opt);
|
|
416
|
+
if (!option && values.length == 0) return getPlaceholder();
|
|
415
417
|
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
418
|
+
return (
|
|
419
|
+
<span key={option?.value} className="form-selected-badge">
|
|
420
|
+
<Tippy content={option?.label} delay={500}>
|
|
421
|
+
<span className="form-selected-badge-name">
|
|
422
|
+
{option?.label}
|
|
423
|
+
</span>
|
|
424
|
+
</Tippy>
|
|
423
425
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
426
|
+
{getDeleteButton(opt)}
|
|
427
|
+
</span>
|
|
428
|
+
);
|
|
429
|
+
})
|
|
428
430
|
);
|
|
429
431
|
};
|
|
430
432
|
const getDeleteButton = (option?: string) => {
|