pesona-ui 1.0.30 → 1.0.31
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/index.cjs.js +58 -68
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +58 -68
- package/dist/index.esm.js.map +1 -1
- package/dist/types/components/Form/Select/SelectMultiple.d.ts +3 -4
- package/dist/types/components/Form/Select/SelectWithSearch.d.ts +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -8189,55 +8189,41 @@ const useDropdownPositionAndScroll = (isOpen, dropdownOptionsRef) => {
|
|
|
8189
8189
|
}, [isOpen, dropdownOptionsRef]);
|
|
8190
8190
|
};
|
|
8191
8191
|
|
|
8192
|
-
const Select = React.forwardRef((
|
|
8192
|
+
const Select = React.forwardRef((props, ref) => {
|
|
8193
|
+
const { name, label, message, selectLabel = 'Select an option', size = 'md', floatingLabel = false, error, options, value = '', onChange, onBlur, required, disabled, } = props;
|
|
8193
8194
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
8194
|
-
const [internalValue, setInternalValue] = React.useState(value);
|
|
8195
8195
|
const dropdownRef = React.useRef(null);
|
|
8196
8196
|
const dropdownOptionsRef = React.useRef(null);
|
|
8197
8197
|
const selectRef = React.useRef(null);
|
|
8198
|
-
// Update internal value when value prop changes
|
|
8199
|
-
React.useEffect(() => {
|
|
8200
|
-
setInternalValue(value);
|
|
8201
|
-
}, [value]);
|
|
8202
|
-
// Expose selectRef to parent via forwardRef
|
|
8203
8198
|
React.useImperativeHandle(ref, () => selectRef.current);
|
|
8204
|
-
|
|
8199
|
+
React.useEffect(() => setIsOpen(false), []);
|
|
8200
|
+
useOutsideClick([dropdownRef], () => {
|
|
8201
|
+
setIsOpen(false);
|
|
8202
|
+
selectRef.current?.blur(); // Trigger onBlur RHF
|
|
8203
|
+
});
|
|
8204
|
+
useDropdownPositionAndScroll(isOpen, dropdownOptionsRef);
|
|
8205
|
+
const displayText = value
|
|
8206
|
+
? options.find((opt) => opt.value === value)?.label
|
|
8207
|
+
: selectLabel;
|
|
8205
8208
|
const handleOptionClick = (optionValue) => {
|
|
8206
|
-
|
|
8207
|
-
|
|
8208
|
-
|
|
8209
|
-
|
|
8210
|
-
|
|
8209
|
+
const syntheticEvent = {
|
|
8210
|
+
target: {
|
|
8211
|
+
name,
|
|
8212
|
+
value: optionValue,
|
|
8213
|
+
},
|
|
8214
|
+
};
|
|
8215
|
+
onChange?.(syntheticEvent);
|
|
8216
|
+
// Change the select value to trigger onChange in RHF
|
|
8211
8217
|
if (selectRef.current) {
|
|
8212
|
-
selectRef.current.value = optionValue
|
|
8218
|
+
selectRef.current.value = String(optionValue);
|
|
8213
8219
|
selectRef.current.dispatchEvent(new Event('change', { bubbles: true }));
|
|
8214
8220
|
}
|
|
8215
8221
|
setIsOpen(false);
|
|
8216
8222
|
};
|
|
8217
|
-
useOutsideClick([dropdownRef], () => {
|
|
8218
|
-
setIsOpen(false);
|
|
8219
|
-
selectRef.current?.blur();
|
|
8220
|
-
});
|
|
8221
|
-
useDropdownPositionAndScroll(isOpen, dropdownOptionsRef);
|
|
8222
|
-
React.useEffect(() => {
|
|
8223
|
-
return () => {
|
|
8224
|
-
setIsOpen(false);
|
|
8225
|
-
};
|
|
8226
|
-
}, []);
|
|
8227
|
-
const displayText = internalValue
|
|
8228
|
-
? options.find((option) => option.value === internalValue)?.label
|
|
8229
|
-
: selectLabel || 'Select an option';
|
|
8230
8223
|
return (React.createElement(React.Fragment, null,
|
|
8231
|
-
React.createElement("select", { ref: selectRef, name: name, value:
|
|
8232
|
-
position: 'absolute',
|
|
8233
|
-
left: '-9999px',
|
|
8234
|
-
opacity: 0,
|
|
8235
|
-
pointerEvents: 'none',
|
|
8236
|
-
width: '1px',
|
|
8237
|
-
height: '1px',
|
|
8238
|
-
}, tabIndex: -1, "aria-hidden": "true" },
|
|
8224
|
+
React.createElement("select", { ref: selectRef, name: name, value: value, onChange: onChange, onBlur: onBlur, required: required, disabled: disabled, style: { position: 'absolute', left: '-9999px' }, tabIndex: -1, "aria-hidden": "true" },
|
|
8239
8225
|
React.createElement("option", { value: "" }, "Select an option"),
|
|
8240
|
-
options.map((
|
|
8226
|
+
options.map((opt) => (React.createElement("option", { key: opt.value, value: opt.value }, opt.label)))),
|
|
8241
8227
|
label && !floatingLabel && (React.createElement("label", { htmlFor: name },
|
|
8242
8228
|
label,
|
|
8243
8229
|
" ",
|
|
@@ -8246,7 +8232,7 @@ const Select = React.forwardRef(({ name, label, message, selectLabel, size = 'md
|
|
|
8246
8232
|
React.createElement("div", { className: `dropdown-header ${isOpen ? 'open' : ''} ${disabled ? 'disabled' : ''}`, onClick: () => !disabled && setIsOpen(!isOpen), "aria-haspopup": "listbox", "aria-expanded": isOpen },
|
|
8247
8233
|
React.createElement("span", { className: "label" }, displayText),
|
|
8248
8234
|
React.createElement(FiChevronDown, { className: "arrow" })),
|
|
8249
|
-
isOpen && (React.createElement("div", { className:
|
|
8235
|
+
isOpen && (React.createElement("div", { className: "dropdown-options scrollbar", ref: dropdownOptionsRef, role: "listbox" }, options.map((opt) => (React.createElement("div", { key: opt.value, className: `option ${opt.value === value ? 'selected' : ''}`, onClick: () => handleOptionClick(opt.value), role: "option", "aria-selected": opt.value === value }, opt.label)))))),
|
|
8250
8236
|
label && floatingLabel && (React.createElement("label", { htmlFor: name },
|
|
8251
8237
|
label,
|
|
8252
8238
|
" ",
|
|
@@ -8599,15 +8585,12 @@ const RadioButtonGroup = React.forwardRef(({ name, label, message, size = 'md',
|
|
|
8599
8585
|
});
|
|
8600
8586
|
RadioButtonGroup.displayName = 'RadioButtonGroup';
|
|
8601
8587
|
|
|
8602
|
-
const SelectMultiple = React.forwardRef(({ name, label, message, selectLabel, floatingLabel = false, error, options, value = [], onChange,
|
|
8588
|
+
const SelectMultiple = React.forwardRef(({ name, label, message, selectLabel, floatingLabel = false, error, options, value = [], onChange, required, disabled, className, }, ref) => {
|
|
8603
8589
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
8604
8590
|
const [selectedValues, setSelectedValues] = React.useState(value);
|
|
8605
8591
|
const dropdownRef = React.useRef(null);
|
|
8606
8592
|
const dropdownOptionsRef = React.useRef(null);
|
|
8607
|
-
|
|
8608
|
-
// expose to RHF
|
|
8609
|
-
React.useImperativeHandle(ref, () => inputRef.current);
|
|
8610
|
-
// update when external value changes
|
|
8593
|
+
// Update selectedValues hanya jika value dari props berubah
|
|
8611
8594
|
React.useEffect(() => {
|
|
8612
8595
|
if (JSON.stringify(value) !== JSON.stringify(selectedValues)) {
|
|
8613
8596
|
setSelectedValues(value);
|
|
@@ -8618,16 +8601,14 @@ const SelectMultiple = React.forwardRef(({ name, label, message, selectLabel, fl
|
|
|
8618
8601
|
? selectedValues.filter((val) => val !== optionValue)
|
|
8619
8602
|
: [...selectedValues, optionValue];
|
|
8620
8603
|
setSelectedValues(newSelectedValues);
|
|
8621
|
-
onChange
|
|
8622
|
-
|
|
8623
|
-
name,
|
|
8624
|
-
|
|
8625
|
-
|
|
8626
|
-
});
|
|
8604
|
+
if (onChange) {
|
|
8605
|
+
onChange({
|
|
8606
|
+
target: { name, value: newSelectedValues },
|
|
8607
|
+
});
|
|
8608
|
+
}
|
|
8627
8609
|
};
|
|
8628
8610
|
useOutsideClick([dropdownRef], () => {
|
|
8629
8611
|
setIsOpen(false);
|
|
8630
|
-
inputRef.current?.blur();
|
|
8631
8612
|
});
|
|
8632
8613
|
useDropdownPositionAndScroll(isOpen, dropdownOptionsRef);
|
|
8633
8614
|
const selectedLabels = selectedValues
|
|
@@ -8635,13 +8616,12 @@ const SelectMultiple = React.forwardRef(({ name, label, message, selectLabel, fl
|
|
|
8635
8616
|
.filter(Boolean)
|
|
8636
8617
|
.join(', ');
|
|
8637
8618
|
return (React.createElement(React.Fragment, null,
|
|
8638
|
-
React.createElement("input", { type: "hidden", name: name, value: selectedValues.join(','), ref: inputRef, onBlur: onBlur, required: required }),
|
|
8639
8619
|
label && !floatingLabel && (React.createElement("label", { htmlFor: name },
|
|
8640
8620
|
label,
|
|
8641
8621
|
" ",
|
|
8642
8622
|
required && React.createElement("span", { className: "text-danger" }, "*"))),
|
|
8643
8623
|
React.createElement("div", { className: `dropdown-select-container ${className || ''}`, ref: dropdownRef },
|
|
8644
|
-
React.createElement("div", { className: `dropdown-header ${isOpen ? 'open' : ''} ${disabled ? 'disabled' : ''}`, onClick: () => !disabled && setIsOpen(!isOpen) },
|
|
8624
|
+
React.createElement("div", { className: `dropdown-header ${isOpen ? 'open' : ''} ${disabled ? 'disabled' : ''}`, onClick: () => !disabled && setIsOpen(!isOpen), ref: ref },
|
|
8645
8625
|
React.createElement("span", { className: "label" }, selectedLabels || selectLabel || 'Select an option'),
|
|
8646
8626
|
React.createElement(FiChevronDown, { className: `arrow ${isOpen ? 'open' : ''}` })),
|
|
8647
8627
|
isOpen && !disabled && (React.createElement("div", { className: "dropdown-options scrollbar", ref: dropdownOptionsRef, role: "listbox" }, options?.map((option) => (React.createElement("div", { key: option.value, className: `option ${selectedValues.includes(option.value) ? 'selected' : ''}` },
|
|
@@ -8654,39 +8634,49 @@ const SelectMultiple = React.forwardRef(({ name, label, message, selectLabel, fl
|
|
|
8654
8634
|
});
|
|
8655
8635
|
SelectMultiple.displayName = 'SelectMultiple';
|
|
8656
8636
|
|
|
8657
|
-
const SelectWithSearch = React.forwardRef((
|
|
8637
|
+
const SelectWithSearch = React.forwardRef((props, ref) => {
|
|
8638
|
+
const { name, label, message, selectLabel = 'Select an option', size = 'md', floatingLabel = false, error, options = [], value = '', onChange, required, disabled, selectSearch = '', setSelectSearch, isLoading = false, } = props;
|
|
8658
8639
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
8659
8640
|
const dropdownRef = React.useRef(null);
|
|
8660
8641
|
const dropdownOptionsRef = React.useRef(null);
|
|
8642
|
+
const selectRef = React.useRef(null);
|
|
8643
|
+
React.useImperativeHandle(ref, () => selectRef.current);
|
|
8644
|
+
useOutsideClick([dropdownRef], () => setIsOpen(false));
|
|
8645
|
+
useDropdownPositionAndScroll(isOpen, dropdownOptionsRef);
|
|
8646
|
+
const displayText = value
|
|
8647
|
+
? options.find((opt) => opt.value === value)?.label
|
|
8648
|
+
: selectLabel;
|
|
8661
8649
|
const handleOptionClick = (optionValue) => {
|
|
8662
|
-
|
|
8663
|
-
|
|
8664
|
-
|
|
8665
|
-
|
|
8650
|
+
const syntheticEvent = {
|
|
8651
|
+
target: {
|
|
8652
|
+
name,
|
|
8653
|
+
value: optionValue,
|
|
8654
|
+
},
|
|
8655
|
+
};
|
|
8656
|
+
onChange?.(syntheticEvent);
|
|
8657
|
+
// Change the select value to trigger onChange in RHF
|
|
8658
|
+
if (selectRef.current) {
|
|
8659
|
+
selectRef.current.value = String(optionValue);
|
|
8660
|
+
selectRef.current.dispatchEvent(new Event('change', { bubbles: true }));
|
|
8666
8661
|
}
|
|
8667
8662
|
setIsOpen(false);
|
|
8668
8663
|
};
|
|
8669
|
-
useOutsideClick([dropdownRef], () => setIsOpen(false));
|
|
8670
|
-
useDropdownPositionAndScroll(isOpen, dropdownOptionsRef);
|
|
8671
|
-
React.useEffect(() => {
|
|
8672
|
-
return () => setIsOpen(false);
|
|
8673
|
-
}, []);
|
|
8674
|
-
const displayText = value
|
|
8675
|
-
? options.find((option) => option.value === value)?.label
|
|
8676
|
-
: selectLabel || 'Select an option';
|
|
8677
8664
|
return (React.createElement(React.Fragment, null,
|
|
8665
|
+
React.createElement("select", { ref: selectRef, name: name, value: value, onChange: onChange, style: { position: 'absolute', left: '-9999px' }, tabIndex: -1, "aria-hidden": "true" },
|
|
8666
|
+
React.createElement("option", { value: "" }, "Select an option"),
|
|
8667
|
+
options.map((opt) => (React.createElement("option", { key: opt.value, value: opt.value }, opt.label)))),
|
|
8678
8668
|
label && !floatingLabel && (React.createElement("label", { htmlFor: name },
|
|
8679
8669
|
label,
|
|
8680
8670
|
" ",
|
|
8681
8671
|
required && React.createElement("span", { className: "text-danger" }, "*"))),
|
|
8682
8672
|
React.createElement("div", { className: `dropdown-select-container ${size}`, ref: dropdownRef },
|
|
8683
|
-
React.createElement("div", { className: `dropdown-header ${isOpen ? 'open' : ''} ${disabled ? 'disabled' : ''}`, onClick: () => !disabled && setIsOpen(!isOpen),
|
|
8673
|
+
React.createElement("div", { className: `dropdown-header ${isOpen ? 'open' : ''} ${disabled ? 'disabled' : ''}`, onClick: () => !disabled && setIsOpen(!isOpen), "aria-haspopup": "listbox", "aria-expanded": isOpen },
|
|
8684
8674
|
React.createElement("span", { className: "label" }, displayText),
|
|
8685
8675
|
React.createElement(FiChevronDown, { className: "arrow" })),
|
|
8686
|
-
isOpen && (React.createElement("div", { className:
|
|
8676
|
+
isOpen && (React.createElement("div", { className: "dropdown-options scrollbar", ref: dropdownOptionsRef, role: "listbox" },
|
|
8687
8677
|
React.createElement("div", { className: "search-input" },
|
|
8688
|
-
React.createElement(Input, { name: "search", placeholder: "Ketik untuk mencari..", type: "search",
|
|
8689
|
-
isLoading ? (React.createElement("div", { className: "p-10 text-center" }, "Loading options...")) : options.length === 0 ? (React.createElement("div", { className: "p-10 text-center" }, "Tidak ada hasil ditemukan")) : (options.map((
|
|
8678
|
+
React.createElement(Input, { name: "search", placeholder: "Ketik untuk mencari..", type: "search", autoFocus: true, value: selectSearch, onChange: (e) => setSelectSearch?.(e.currentTarget.value) })),
|
|
8679
|
+
isLoading ? (React.createElement("div", { className: "p-10 text-center" }, "Loading options...")) : options.length === 0 ? (React.createElement("div", { className: "p-10 text-center" }, "Tidak ada hasil ditemukan")) : (options.map((opt) => (React.createElement("div", { key: opt.value, className: `option ${value === opt.value ? 'selected' : ''}`, onClick: () => handleOptionClick(opt.value), role: "option", "aria-selected": value === opt.value }, opt.label))))))),
|
|
8690
8680
|
label && floatingLabel && (React.createElement("label", { htmlFor: name },
|
|
8691
8681
|
label,
|
|
8692
8682
|
" ",
|