@creativecodeco/ui 0.0.4 → 0.0.5
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/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @creativecodeco/ui
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
4
|
|
|
5
5
|
> System Design CreativeCode.com.co
|
|
6
6
|
|
|
@@ -93,3 +93,5 @@ export default function RootLayout({ children }) {
|
|
|
93
93
|
## License
|
|
94
94
|
|
|
95
95
|
MIT © [CreativeCode.com.co](https://github.com/creativecodeco)
|
|
96
|
+
|
|
97
|
+
Web [CreativeCode.com.co](https://creativecode.com.co)
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { forwardRef, useCallback, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { forwardRef, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { FaSortDown } from 'react-icons/fa';
|
|
4
4
|
import { useOnClickOutside } from 'usehooks-ts';
|
|
5
5
|
import { TextBox } from '../../../ui/forms';
|
|
6
|
-
const DropDown = forwardRef(({ name, options = [], disabled, onChange, onTextChange, ...otherProps }, ref) => {
|
|
6
|
+
const DropDown = forwardRef(({ name, options = [], disabled, onChange, onTextChange, value, ...otherProps }, ref) => {
|
|
7
7
|
const [label, setLabel] = useState('');
|
|
8
8
|
const [open, setOpen] = useState(false);
|
|
9
9
|
const [valueFilter, setValueFilter] = useState();
|
|
@@ -17,6 +17,14 @@ const DropDown = forwardRef(({ name, options = [], disabled, onChange, onTextCha
|
|
|
17
17
|
setOpen(false);
|
|
18
18
|
};
|
|
19
19
|
useOnClickOutside(refOutside, handleClickOutside);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
const option = options.find((option) => String(option.value) === String(value));
|
|
22
|
+
if (!option) {
|
|
23
|
+
setLabel('');
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
setLabel(option.label);
|
|
27
|
+
}, [value]);
|
|
20
28
|
const handleFocus = useCallback(() => {
|
|
21
29
|
if (disabled) {
|
|
22
30
|
return;
|
|
@@ -38,6 +46,6 @@ const DropDown = forwardRef(({ name, options = [], disabled, onChange, onTextCha
|
|
|
38
46
|
const filterOptions = useMemo(() => !valueFilter
|
|
39
47
|
? options
|
|
40
48
|
: options.filter(({ label }) => label.includes(valueFilter)), [valueFilter, options]);
|
|
41
|
-
return (_jsxs("div", { className: 'dropdown block', children: [_jsx(TextBox, { name: name, tabIndex: 0, ref: ref, disabled: disabled, rightButton: true, rightIcon: FaSortDown,
|
|
49
|
+
return (_jsxs("div", { className: 'dropdown block', children: [_jsx(TextBox, { name: name, tabIndex: 0, ref: ref, disabled: disabled, rightButton: true, rightIcon: FaSortDown, onFocus: handleFocus, onChange: handleChange, ...otherProps, value: label }), open && (_jsx("ul", { tabIndex: 0, className: 'dropdown-content z-[1] menu w-full bg-base-100', id: `options-${name}`, ref: refOutside, role: 'listitem', "data-testid": `options-${name}`, children: filterOptions.map((option) => (_jsx("li", { value: option.value, onClick: () => handleSelect(option), children: _jsx("a", { children: option.label }) }, option.value))) }))] }));
|
|
42
50
|
});
|
|
43
51
|
export default DropDown;
|