react-restyle-components 0.2.89 → 0.2.91
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/lib/src/core-components/__mocks__/styleMock.d.ts +2 -0
- package/lib/src/core-components/__mocks__/styleMock.d.ts.map +1 -0
- package/lib/src/core-components/__mocks__/styleMock.js +1 -0
- package/lib/src/core-components/index.d.ts +34 -0
- package/lib/src/core-components/index.d.ts.map +1 -0
- package/lib/src/core-components/index.js +33 -0
- package/lib/src/core-components/jest.config.d.ts +12 -0
- package/lib/src/core-components/jest.config.d.ts.map +1 -0
- package/lib/src/core-components/jest.config.js +10 -0
- package/lib/src/core-components/src/App.css +45 -0
- package/lib/src/core-components/src/App.d.ts +4 -0
- package/lib/src/core-components/src/App.d.ts.map +1 -0
- package/lib/src/core-components/src/App.js +9 -0
- package/lib/src/core-components/src/assets/styles/colors.css +217 -0
- package/lib/src/core-components/src/assets/styles/decorations.css +15 -0
- package/lib/src/core-components/src/assets/styles/fontface.css +17 -0
- package/lib/src/core-components/src/assets/styles/scrollbars.css +70 -0
- package/lib/src/core-components/src/assets/styles/typography.css +3 -0
- package/lib/src/core-components/src/atoms/button/Button.test.d.ts +2 -0
- package/lib/src/core-components/src/atoms/button/Button.test.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/button/Button.test.js +27 -0
- package/lib/src/core-components/src/atoms/button/Button.types.d.ts +26 -0
- package/lib/src/core-components/src/atoms/button/Button.types.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/button/Button.types.js +1 -0
- package/lib/src/core-components/src/atoms/button/button.component.d.ts +4 -0
- package/lib/src/core-components/src/atoms/button/button.component.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/button/button.component.js +18 -0
- package/lib/src/core-components/src/atoms/button/buttonGroup/buttonGroup.component.d.ts +7 -0
- package/lib/src/core-components/src/atoms/button/buttonGroup/buttonGroup.component.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/button/buttonGroup/buttonGroup.component.js +4 -0
- package/lib/src/core-components/src/atoms/check-box/checkBox.component.d.ts +10 -0
- package/lib/src/core-components/src/atoms/check-box/checkBox.component.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/check-box/checkBox.component.js +20 -0
- package/lib/src/core-components/src/atoms/check-box/checkBox.spec.d.ts +2 -0
- package/lib/src/core-components/src/atoms/check-box/checkBox.spec.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/check-box/checkBox.spec.js +32 -0
- package/lib/src/core-components/src/atoms/date-picker/date-picker.component.d.ts +12 -0
- package/lib/src/core-components/src/atoms/date-picker/date-picker.component.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/date-picker/date-picker.component.js +20 -0
- package/lib/src/core-components/src/atoms/form/form.component.d.ts +105 -0
- package/lib/src/core-components/src/atoms/form/form.component.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/form/form.component.js +87 -0
- package/lib/src/core-components/src/atoms/icons/icons.component.d.ts +11 -0
- package/lib/src/core-components/src/atoms/icons/icons.component.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/icons/icons.component.js +71 -0
- package/lib/src/core-components/src/atoms/input/input-otp.component.d.ts +14 -0
- package/lib/src/core-components/src/atoms/input/input-otp.component.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/input/input-otp.component.js +61 -0
- package/lib/src/core-components/src/atoms/input/input-otp.styles.css +35 -0
- package/lib/src/core-components/src/atoms/input/input-pin.component.d.ts +16 -0
- package/lib/src/core-components/src/atoms/input/input-pin.component.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/input/input-pin.component.js +76 -0
- package/lib/src/core-components/src/atoms/input/input.component.d.ts +18 -0
- package/lib/src/core-components/src/atoms/input/input.component.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/input/input.component.js +16 -0
- package/lib/src/core-components/src/atoms/input/input.styles.css +35 -0
- package/lib/src/core-components/src/atoms/input-dropdown/input-dropdown.component.d.ts +10 -0
- package/lib/src/core-components/src/atoms/input-dropdown/input-dropdown.component.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/input-dropdown/input-dropdown.component.js +44 -0
- package/lib/src/core-components/src/atoms/loader/loader.component.d.ts +6 -0
- package/lib/src/core-components/src/atoms/loader/loader.component.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/loader/loader.component.js +6 -0
- package/lib/src/core-components/src/atoms/pdf/pdf-images.components.d.ts +9 -0
- package/lib/src/core-components/src/atoms/pdf/pdf-images.components.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/pdf/pdf-images.components.js +7 -0
- package/lib/src/core-components/src/atoms/pdf/pdf-table.components.d.ts +11 -0
- package/lib/src/core-components/src/atoms/pdf/pdf-table.components.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/pdf/pdf-table.components.js +48 -0
- package/lib/src/core-components/src/atoms/pdf/pdf-typography.components.d.ts +21 -0
- package/lib/src/core-components/src/atoms/pdf/pdf-typography.components.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/pdf/pdf-typography.components.js +70 -0
- package/lib/src/core-components/src/atoms/pdf/pdf-wrapped-view.components.d.ts +53 -0
- package/lib/src/core-components/src/atoms/pdf/pdf-wrapped-view.components.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/pdf/pdf-wrapped-view.components.js +50 -0
- package/lib/src/core-components/src/atoms/radio/radio.component.d.ts +9 -0
- package/lib/src/core-components/src/atoms/radio/radio.component.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/radio/radio.component.js +20 -0
- package/lib/src/core-components/src/atoms/stepper/stepper.component.d.ts +9 -0
- package/lib/src/core-components/src/atoms/stepper/stepper.component.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/stepper/stepper.component.js +26 -0
- package/lib/src/core-components/src/atoms/tabs/tabs.component.d.ts +18 -0
- package/lib/src/core-components/src/atoms/tabs/tabs.component.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/tabs/tabs.component.js +19 -0
- package/lib/src/core-components/src/atoms/tabs/tabs.module.css +238 -0
- package/lib/src/core-components/src/atoms/timer/timer.component.d.ts +7 -0
- package/lib/src/core-components/src/atoms/timer/timer.component.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/timer/timer.component.js +76 -0
- package/lib/src/core-components/src/atoms/tooltip/Tooltip.types.d.ts +22 -0
- package/lib/src/core-components/src/atoms/tooltip/Tooltip.types.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/tooltip/Tooltip.types.js +1 -0
- package/lib/src/core-components/src/atoms/tooltip/tooltip.component.d.ts +10 -0
- package/lib/src/core-components/src/atoms/tooltip/tooltip.component.d.ts.map +1 -0
- package/lib/src/core-components/src/atoms/tooltip/tooltip.component.js +10 -0
- package/lib/src/core-components/src/helpers/constants.d.ts +4 -0
- package/lib/src/core-components/src/helpers/constants.d.ts.map +1 -0
- package/lib/src/core-components/src/helpers/constants.js +11 -0
- package/lib/src/core-components/src/hooks/index.d.ts +2 -0
- package/lib/src/core-components/src/hooks/index.d.ts.map +1 -0
- package/lib/src/core-components/src/hooks/index.js +1 -0
- package/lib/src/core-components/src/hooks/outside.hook.d.ts +2 -0
- package/lib/src/core-components/src/hooks/outside.hook.d.ts.map +1 -0
- package/lib/src/core-components/src/hooks/outside.hook.js +28 -0
- package/lib/src/core-components/src/index.css +118 -0
- package/lib/src/core-components/src/index.d.ts +2 -0
- package/lib/src/core-components/src/index.d.ts.map +1 -0
- package/lib/src/core-components/src/index.js +12 -0
- package/lib/src/core-components/src/library/assets/fonts/arima/arima-bold.ttf +0 -0
- package/lib/src/core-components/src/library/assets/fonts/arima/arima-regular.ttf +0 -0
- package/lib/src/core-components/src/library/assets/svg/CheckedBox.svg +14 -0
- package/lib/src/core-components/src/library/assets/svg/DownArrow.svg +14 -0
- package/lib/src/core-components/src/library/assets/svg/UnCheckbox.svg +3 -0
- package/lib/src/core-components/src/library/assets/svg/UpArrow.svg +14 -0
- package/lib/src/core-components/src/library/assets/svg/checkedRadio.svg +13 -0
- package/lib/src/core-components/src/library/assets/svg/datePicker.svg +3 -0
- package/lib/src/core-components/src/library/assets/svg/index.d.ts +10 -0
- package/lib/src/core-components/src/library/assets/svg/index.d.ts.map +1 -0
- package/lib/src/core-components/src/library/assets/svg/index.js +27 -0
- package/lib/src/core-components/src/library/assets/svg/timer copy.svg +3 -0
- package/lib/src/core-components/src/library/assets/svg/timer.svg +3 -0
- package/lib/src/core-components/src/library/assets/svg/uncheckRadio.svg +3 -0
- package/lib/src/core-components/src/molecules/auto-complete-filter-multiple-select-multiple-fields-display/auto-complete-filter-multiple-select-multiple-fields-display.component.d.ts +17 -0
- package/lib/src/core-components/src/molecules/auto-complete-filter-multiple-select-multiple-fields-display/auto-complete-filter-multiple-select-multiple-fields-display.component.d.ts.map +1 -0
- package/lib/src/core-components/src/molecules/auto-complete-filter-multiple-select-multiple-fields-display/auto-complete-filter-multiple-select-multiple-fields-display.component.js +101 -0
- package/lib/src/core-components/src/molecules/auto-complete-filter-single-select/auto-complete-filter-single-select.component.d.ts +13 -0
- package/lib/src/core-components/src/molecules/auto-complete-filter-single-select/auto-complete-filter-single-select.component.d.ts.map +1 -0
- package/lib/src/core-components/src/molecules/auto-complete-filter-single-select/auto-complete-filter-single-select.component.js +59 -0
- package/lib/src/core-components/src/molecules/auto-complete-filter-single-select-multiple-fields-display/auto-complete-filter-single-select-multiple-fields-display.component.d.ts +18 -0
- package/lib/src/core-components/src/molecules/auto-complete-filter-single-select-multiple-fields-display/auto-complete-filter-single-select-multiple-fields-display.component.d.ts.map +1 -0
- package/lib/src/core-components/src/molecules/auto-complete-filter-single-select-multiple-fields-display/auto-complete-filter-single-select-multiple-fields-display.component.js +109 -0
- package/lib/src/core-components/src/molecules/auto-complete-group-by/auto-complete-group-by.component.d.ts +10 -0
- package/lib/src/core-components/src/molecules/auto-complete-group-by/auto-complete-group-by.component.d.ts.map +1 -0
- package/lib/src/core-components/src/molecules/auto-complete-group-by/auto-complete-group-by.component.js +128 -0
- package/lib/src/core-components/src/molecules/auto-complete-group-by/auto-complete-group-by.component.test.d.ts +2 -0
- package/lib/src/core-components/src/molecules/auto-complete-group-by/auto-complete-group-by.component.test.d.ts.map +1 -0
- package/lib/src/core-components/src/molecules/auto-complete-group-by/auto-complete-group-by.component.test.js +9 -0
- package/lib/src/core-components/src/molecules/autocomplete/autocomplete.css +37 -0
- package/lib/src/core-components/src/molecules/autocomplete/autocomplete.d.ts +8 -0
- package/lib/src/core-components/src/molecules/autocomplete/autocomplete.d.ts.map +1 -0
- package/lib/src/core-components/src/molecules/autocomplete/autocomplete.js +108 -0
- package/lib/src/core-components/src/molecules/autocomplete/autocomplete.spec.d.ts +2 -0
- package/lib/src/core-components/src/molecules/autocomplete/autocomplete.spec.d.ts.map +1 -0
- package/lib/src/core-components/src/molecules/autocomplete/autocomplete.spec.js +79 -0
- package/lib/src/core-components/src/molecules/color-picker/color-picker.component.d.ts +6 -0
- package/lib/src/core-components/src/molecules/color-picker/color-picker.component.d.ts.map +1 -0
- package/lib/src/core-components/src/molecules/color-picker/color-picker.component.js +12 -0
- package/lib/src/core-components/src/molecules/color-picker/color-picker.css +24 -0
- package/lib/src/core-components/src/molecules/color-picker/color-picker.spec.d.ts +2 -0
- package/lib/src/core-components/src/molecules/color-picker/color-picker.spec.d.ts.map +1 -0
- package/lib/src/core-components/src/molecules/color-picker/color-picker.spec.js +7 -0
- package/lib/src/core-components/src/molecules/color-picker-modal/color-picker-modal.component.d.ts +15 -0
- package/lib/src/core-components/src/molecules/color-picker-modal/color-picker-modal.component.d.ts.map +1 -0
- package/lib/src/core-components/src/molecules/color-picker-modal/color-picker-modal.component.js +41 -0
- package/lib/src/core-components/src/molecules/color-picker-modal/color-picker-modal.css +45 -0
- package/lib/src/core-components/src/molecules/color-picker-modal/color-picker-modal.spec.d.ts +2 -0
- package/lib/src/core-components/src/molecules/color-picker-modal/color-picker-modal.spec.d.ts.map +1 -0
- package/lib/src/core-components/src/molecules/color-picker-modal/color-picker-modal.spec.js +7 -0
- package/lib/src/core-components/src/molecules/css-multiline-input/css-multiline-input.component.d.ts +11 -0
- package/lib/src/core-components/src/molecules/css-multiline-input/css-multiline-input.component.d.ts.map +1 -0
- package/lib/src/core-components/src/molecules/css-multiline-input/css-multiline-input.component.js +91 -0
- package/lib/src/core-components/src/molecules/css-multiline-input/css-properties.d.ts +8932 -0
- package/lib/src/core-components/src/molecules/css-multiline-input/css-properties.d.ts.map +1 -0
- package/lib/src/core-components/src/molecules/css-multiline-input/css-properties.js +161 -0
- package/lib/src/core-components/src/molecules/modal/modal.component.d.ts +10 -0
- package/lib/src/core-components/src/molecules/modal/modal.component.d.ts.map +1 -0
- package/lib/src/core-components/src/molecules/modal/modal.component.js +19 -0
- package/lib/src/core-components/src/molecules/modal-confirm/modal-confirm.component.d.ts +14 -0
- package/lib/src/core-components/src/molecules/modal-confirm/modal-confirm.component.d.ts.map +1 -0
- package/lib/src/core-components/src/molecules/modal-confirm/modal-confirm.component.js +21 -0
- package/lib/src/core-components/src/molecules/multi-select/multi-select.component.d.ts +9 -0
- package/lib/src/core-components/src/molecules/multi-select/multi-select.component.d.ts.map +1 -0
- package/lib/src/core-components/src/molecules/multi-select/multi-select.component.js +49 -0
- package/lib/src/core-components/src/molecules/multi-select-with-field/multi-select-with-field.component.d.ts +10 -0
- package/lib/src/core-components/src/molecules/multi-select-with-field/multi-select-with-field.component.d.ts.map +1 -0
- package/lib/src/core-components/src/molecules/multi-select-with-field/multi-select-with-field.component.js +58 -0
- package/lib/src/core-components/src/molecules/multi-selection-dropdown/multi-selection-dropdown.component.d.ts +9 -0
- package/lib/src/core-components/src/molecules/multi-selection-dropdown/multi-selection-dropdown.component.d.ts.map +1 -0
- package/lib/src/core-components/src/molecules/multi-selection-dropdown/multi-selection-dropdown.component.js +43 -0
- package/lib/src/core-components/src/reportWebVitals.d.ts +4 -0
- package/lib/src/core-components/src/reportWebVitals.d.ts.map +1 -0
- package/lib/src/core-components/src/reportWebVitals.js +12 -0
- package/lib/src/core-components/src/setupTests.d.ts +2 -0
- package/lib/src/core-components/src/setupTests.d.ts.map +1 -0
- package/lib/src/core-components/src/setupTests.js +5 -0
- package/lib/src/core-components/src/tc.module.css +1 -0
- package/lib/src/core-components/src/utils/index.d.ts +2 -0
- package/lib/src/core-components/src/utils/index.d.ts.map +1 -0
- package/lib/src/core-components/src/utils/index.js +1 -0
- package/lib/src/core-components/src/utils/utility.util.d.ts +3 -0
- package/lib/src/core-components/src/utils/utility.util.d.ts.map +1 -0
- package/lib/src/core-components/src/utils/utility.util.js +5 -0
- package/lib/src/core-utils/jest.config.d.ts +11 -0
- package/lib/src/core-utils/jest.config.d.ts.map +1 -0
- package/lib/src/core-utils/jest.config.js +9 -0
- package/lib/src/core-utils/src/calculation/calculation.spec.d.ts +2 -0
- package/lib/src/core-utils/src/calculation/calculation.spec.d.ts.map +1 -0
- package/lib/src/core-utils/src/calculation/calculation.spec.js +52 -0
- package/lib/src/core-utils/src/index.d.ts +8 -0
- package/lib/src/core-utils/src/index.d.ts.map +1 -0
- package/lib/src/core-utils/src/index.js +7 -0
- package/package.json +2 -2
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useRef, useEffect, useCallback } from 'react';
|
|
3
|
+
import s from '../../tc.module.css';
|
|
4
|
+
import { cn } from '../../utils';
|
|
5
|
+
const LI_ELEMENT_HEIGHT = 34;
|
|
6
|
+
export const Autocomplete = ({ value = '', onValueChange, options = [], }) => {
|
|
7
|
+
const [activeOption, setActiveOption] = useState(value === '' || options.indexOf(value) === -1 ? 0 : options.indexOf(value));
|
|
8
|
+
const [filteredOptions, setFilteredOptions] = useState(options);
|
|
9
|
+
const [shouldShowList, setShouldShowList] = useState(false);
|
|
10
|
+
const [searchValue, setSearchValue] = useState(value);
|
|
11
|
+
const inputRef = useRef(null);
|
|
12
|
+
const listRef = useRef(null);
|
|
13
|
+
const onInputChange = useCallback((event) => {
|
|
14
|
+
const input = event.target.value;
|
|
15
|
+
if (input != '') {
|
|
16
|
+
const newFilteredOptions = options.filter((option) => option.toLowerCase().indexOf(input.toLowerCase()) > -1);
|
|
17
|
+
setFilteredOptions(newFilteredOptions);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
setFilteredOptions(options);
|
|
21
|
+
}
|
|
22
|
+
setActiveOption(0);
|
|
23
|
+
setShouldShowList(true);
|
|
24
|
+
setSearchValue(input);
|
|
25
|
+
}, [
|
|
26
|
+
setActiveOption,
|
|
27
|
+
setFilteredOptions,
|
|
28
|
+
setShouldShowList,
|
|
29
|
+
setSearchValue,
|
|
30
|
+
onValueChange,
|
|
31
|
+
]);
|
|
32
|
+
const onOptionClick = useCallback((event) => {
|
|
33
|
+
const symbol = event.currentTarget.innerText || event.currentTarget.textContent || '';
|
|
34
|
+
setShouldShowList(false);
|
|
35
|
+
setActiveOption(0);
|
|
36
|
+
setFilteredOptions([]);
|
|
37
|
+
setSearchValue(symbol);
|
|
38
|
+
onValueChange(symbol);
|
|
39
|
+
}, [
|
|
40
|
+
setShouldShowList,
|
|
41
|
+
setActiveOption,
|
|
42
|
+
setFilteredOptions,
|
|
43
|
+
setSearchValue,
|
|
44
|
+
onValueChange,
|
|
45
|
+
]);
|
|
46
|
+
const onKeyDown = useCallback((event) => {
|
|
47
|
+
let selectedItem = '';
|
|
48
|
+
if (event.keyCode === 38) {
|
|
49
|
+
// arrow up
|
|
50
|
+
event.preventDefault();
|
|
51
|
+
if (activeOption === 0) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
selectedItem = filteredOptions[activeOption - 1];
|
|
56
|
+
setSearchValue(filteredOptions[activeOption - 1]);
|
|
57
|
+
setActiveOption(activeOption - 1);
|
|
58
|
+
listRef.current?.scroll({
|
|
59
|
+
top: LI_ELEMENT_HEIGHT * (activeOption - 1),
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else if (event.keyCode === 40) {
|
|
64
|
+
// arrow down
|
|
65
|
+
event.preventDefault();
|
|
66
|
+
if (activeOption === filteredOptions.length - 1) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
selectedItem = filteredOptions[activeOption + 1];
|
|
71
|
+
setSearchValue(filteredOptions[activeOption + 1]);
|
|
72
|
+
setActiveOption(activeOption + 1);
|
|
73
|
+
listRef.current?.scroll({
|
|
74
|
+
top: LI_ELEMENT_HEIGHT * (activeOption + 1),
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if (Object.keys(selectedItem)?.length > 0) {
|
|
79
|
+
onValueChange(selectedItem);
|
|
80
|
+
}
|
|
81
|
+
}, [
|
|
82
|
+
setActiveOption,
|
|
83
|
+
setSearchValue,
|
|
84
|
+
filteredOptions,
|
|
85
|
+
activeOption,
|
|
86
|
+
onValueChange,
|
|
87
|
+
]);
|
|
88
|
+
const renderList = () => {
|
|
89
|
+
return (_jsx(_Fragment, { children: shouldShowList ? (_jsx(_Fragment, { children: _jsx("div", { className: cn(s['flex'], s['absolute'], s['rounded-sm'], s['w-full']), style: { zIndex: 999 }, children: filteredOptions?.length > 0 ? (_jsx("ul", { role: "list", className: cn(s['flex'], s['flex-col'], s['gap-1'], s['bg-gray-200'], s['w-full']), id: "list", ref: listRef, children: filteredOptions?.map((option, index) => {
|
|
90
|
+
let className = cn(s['flex'], s['gap-2'], s['p-2']);
|
|
91
|
+
if (index === activeOption) {
|
|
92
|
+
className = cn(className, s['font-bold']);
|
|
93
|
+
}
|
|
94
|
+
return (_jsx("li", { className: className, role: "listitem", onClick: onOptionClick, children: option }, index));
|
|
95
|
+
}) })) : (_jsx("div", { className: cn(s['flex'], s['bg-gray-200'], s['w-full'], s['p-2']), children: _jsx("span", { children: "Not Found Result!!" }) })) }) })) : (_jsx(_Fragment, {})) }));
|
|
96
|
+
};
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
// this only works on click when inside timeout
|
|
99
|
+
setTimeout(() => {
|
|
100
|
+
inputRef.current?.select();
|
|
101
|
+
}, 0);
|
|
102
|
+
filteredOptions[0] && onValueChange(filteredOptions[0]);
|
|
103
|
+
// setShouldShowList(true);
|
|
104
|
+
}, []);
|
|
105
|
+
return (_jsx(_Fragment, { children: _jsxs("div", { className: cn(s['flex'], s['flex-col'], s['relative']), children: [_jsx("div", { className: cn(s['flex'], s['leading-4'], s['p-2'], s['focus:outline-none'], s['focus:ring'], s['w-full'], s['shadow-sm'], s['sm:text-base'], s['border'], s['rounded-md']), children: _jsx("input", { type: "text", role: "input", name: "autocomplete-input", className: cn(s['flex'], s['focus:outline-none']), placeholder: "Search...", onChange: onInputChange, onKeyDown: onKeyDown, value: searchValue, ref: inputRef, onClick: () => {
|
|
106
|
+
setShouldShowList(true);
|
|
107
|
+
} }) }), _jsx("div", { className: cn(s['flex']), children: renderList() })] }) }));
|
|
108
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"autocomplete.spec.d.ts","sourceRoot":"","sources":["../../../../../../src/core-components/src/molecules/autocomplete/autocomplete.spec.tsx"],"names":[],"mappings":"AAEA,OAAO,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { fireEvent, render, screen } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import { Autocomplete } from './autocomplete';
|
|
5
|
+
const TEST_OPTIONS = ['ONE', 'TWO', 'THREE', 'FOUR', 'FIVE'];
|
|
6
|
+
test('Render Autocomplete', () => {
|
|
7
|
+
render(_jsx(Autocomplete, { value: "", onValueChange: () => { }, options: TEST_OPTIONS }));
|
|
8
|
+
expect(screen.getByRole('input')).toBeInTheDocument();
|
|
9
|
+
// expect(screen.getByRole('list')).toBeInTheDocument();
|
|
10
|
+
});
|
|
11
|
+
test('Autocomplete with empty list', () => {
|
|
12
|
+
render(_jsx(Autocomplete, { value: "", onValueChange: () => { }, options: [] }));
|
|
13
|
+
expect(screen.getByRole('input')).toBeInTheDocument();
|
|
14
|
+
expect(screen.queryByRole('list')).not.toBeInTheDocument();
|
|
15
|
+
});
|
|
16
|
+
test('Autocomplete list arrow navigation', () => {
|
|
17
|
+
const onValueChange = jest.fn();
|
|
18
|
+
window.HTMLElement.prototype.scroll = function () { };
|
|
19
|
+
render(_jsx(Autocomplete, { value: "", onValueChange: onValueChange, options: TEST_OPTIONS }));
|
|
20
|
+
expect(onValueChange).toHaveBeenCalledWith('ONE');
|
|
21
|
+
fireEvent.keyDown(screen.getByRole('input'), { keyCode: 40 }); //down
|
|
22
|
+
expect(onValueChange).toHaveBeenCalledWith('TWO');
|
|
23
|
+
// expect(screen.getByText('TWO')).toHaveClass('active-option');
|
|
24
|
+
// expect(screen.getByText('THREE')).toBeInTheDocument();
|
|
25
|
+
fireEvent.keyDown(screen.getByRole('input'), { keyCode: 40 }); //down
|
|
26
|
+
expect(onValueChange).toHaveBeenCalledWith('THREE');
|
|
27
|
+
// expect(screen.getByText('THREE')).toHaveClass('active-option');
|
|
28
|
+
});
|
|
29
|
+
// test('Autocomplete list option click', () => {
|
|
30
|
+
// const onValueChange = jest.fn();
|
|
31
|
+
// render(
|
|
32
|
+
// <Autocomplete
|
|
33
|
+
// value=""
|
|
34
|
+
// onValueChange={onValueChange}
|
|
35
|
+
// options={TEST_OPTIONS}
|
|
36
|
+
// />
|
|
37
|
+
// );
|
|
38
|
+
// fireEvent.click(screen.getByText('FOUR'));
|
|
39
|
+
// expect(screen.getByRole('input')).toHaveValue('FOUR');
|
|
40
|
+
// expect(onValueChange).toHaveBeenCalledWith('FOUR');
|
|
41
|
+
// expect(screen.queryByRole('list')).not.toBeInTheDocument();
|
|
42
|
+
// });
|
|
43
|
+
test('Autocomplete search', () => {
|
|
44
|
+
const onValueChange = jest.fn();
|
|
45
|
+
render(_jsx(Autocomplete, { value: "", onValueChange: onValueChange, options: TEST_OPTIONS }));
|
|
46
|
+
fireEvent.change(screen.getByRole('input'), { target: { value: 'f' } });
|
|
47
|
+
for (let option of TEST_OPTIONS) {
|
|
48
|
+
if (option.toLowerCase().indexOf('f') > -1) {
|
|
49
|
+
expect(screen.getAllByRole('listitem')).toHaveLength(2);
|
|
50
|
+
expect(screen.queryByText(option)).toBeInTheDocument();
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
expect(screen.queryByText(option)).not.toBeInTheDocument();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
// test('Autocomplete search default value', () => {
|
|
58
|
+
// const onValueChange = jest.fn();
|
|
59
|
+
// render(
|
|
60
|
+
// <Autocomplete
|
|
61
|
+
// value="TWO"
|
|
62
|
+
// onValueChange={onValueChange}
|
|
63
|
+
// options={TEST_OPTIONS}
|
|
64
|
+
// />
|
|
65
|
+
// );
|
|
66
|
+
// expect(screen.getByText('TWO')).toHaveClass('active-option');
|
|
67
|
+
// });
|
|
68
|
+
test('Autocomplete search no result', () => {
|
|
69
|
+
const onValueChange = jest.fn();
|
|
70
|
+
render(_jsx(Autocomplete, { value: "", onValueChange: onValueChange, options: TEST_OPTIONS }));
|
|
71
|
+
fireEvent.change(screen.getByRole('input'), { target: { value: 'hello' } });
|
|
72
|
+
expect(screen.queryByRole('list')).not.toBeInTheDocument();
|
|
73
|
+
// expect(screen.getByText('No match')).toBeInTheDocument();
|
|
74
|
+
});
|
|
75
|
+
test('Autocomplete with value not in list', () => {
|
|
76
|
+
render(_jsx(Autocomplete, { value: "xxx", onValueChange: () => { }, options: TEST_OPTIONS }));
|
|
77
|
+
expect(screen.getByRole('input')).toBeInTheDocument();
|
|
78
|
+
// expect(screen.getByText('ONE')).toHaveClass('active-option');
|
|
79
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-picker.component.d.ts","sourceRoot":"","sources":["../../../../../../src/core-components/src/molecules/color-picker/color-picker.component.tsx"],"names":[],"mappings":"AAGA,OAAO,oBAAoB,CAAC;AAE5B,eAAO,MAAM,WAAW;;;6CAqBvB,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useRef, useState } from 'react';
|
|
3
|
+
import { HexColorPicker } from 'react-colorful';
|
|
4
|
+
import { useClickOutside } from '../../hooks';
|
|
5
|
+
import './color-picker.css';
|
|
6
|
+
export const ColorPicker = ({ color, onChange }) => {
|
|
7
|
+
const popover = useRef();
|
|
8
|
+
const [isOpen, toggle] = useState(false);
|
|
9
|
+
const close = useCallback(() => toggle(false), []);
|
|
10
|
+
useClickOutside(popover, close);
|
|
11
|
+
return (_jsxs("div", { className: "picker", children: [_jsx("div", { className: "swatch", style: { backgroundColor: color }, onClick: () => toggle(true) }), isOpen && (_jsx("div", { className: "popover", ref: popover, children: _jsx(HexColorPicker, { color: color, onChange: onChange }) }))] }));
|
|
12
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
.picker {
|
|
2
|
+
position: relative;
|
|
3
|
+
z-index: 999;
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.swatch {
|
|
7
|
+
width: 28px;
|
|
8
|
+
height: 28px;
|
|
9
|
+
border-radius: 8px;
|
|
10
|
+
border: 3px solid #fff;
|
|
11
|
+
box-shadow:
|
|
12
|
+
0 0 0 1px rgba(0, 0, 0, 0.1),
|
|
13
|
+
inset 0 0 0 1px rgba(0, 0, 0, 0.1);
|
|
14
|
+
cursor: pointer;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.popover {
|
|
18
|
+
position: absolute;
|
|
19
|
+
top: calc(100% + 2px);
|
|
20
|
+
left: 0;
|
|
21
|
+
border-radius: 9px;
|
|
22
|
+
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
|
|
23
|
+
z-index: 999;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-picker.spec.d.ts","sourceRoot":"","sources":["../../../../../../src/core-components/src/molecules/color-picker/color-picker.spec.tsx"],"names":[],"mappings":"AAEA,OAAO,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import { ColorPicker } from './color-picker.component';
|
|
5
|
+
test('Render Autocomplete', () => {
|
|
6
|
+
render(_jsx(ColorPicker, { color: "#000000", onChange: () => { } }));
|
|
7
|
+
});
|
package/lib/src/core-components/src/molecules/color-picker-modal/color-picker-modal.component.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import './color-picker-modal.css';
|
|
2
|
+
import '../../tc.module.css';
|
|
3
|
+
interface ColorPickerModalProps {
|
|
4
|
+
color: string;
|
|
5
|
+
isVisible?: boolean;
|
|
6
|
+
testId?: string;
|
|
7
|
+
tooltip?: string;
|
|
8
|
+
tooltipSide?: 'top' | 'bottom' | 'left' | 'right';
|
|
9
|
+
onChange: (color: string) => void;
|
|
10
|
+
onNoFill?: (bgColor: string, textColor: string) => void;
|
|
11
|
+
onClose?: (color?: string) => void;
|
|
12
|
+
}
|
|
13
|
+
export declare const ColorPickerModal: ({ color, isVisible, testId, tooltip, tooltipSide, onChange, onNoFill, onClose, }: ColorPickerModalProps) => import("react/jsx-runtime").JSX.Element;
|
|
14
|
+
export {};
|
|
15
|
+
//# sourceMappingURL=color-picker-modal.component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-picker-modal.component.d.ts","sourceRoot":"","sources":["../../../../../../src/core-components/src/molecules/color-picker-modal/color-picker-modal.component.tsx"],"names":[],"mappings":"AASA,OAAO,0BAA0B,CAAC;AAClC,OAAO,qBAAqB,CAAC;AAE7B,UAAU,qBAAqB;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,WAAW,CAAC,EAAE,KAAK,GAAG,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;IAClD,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IACxD,OAAO,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;CACpC;AAED,eAAO,MAAM,gBAAgB,qFAS1B,qBAAqB,4CAwGvB,CAAC"}
|
package/lib/src/core-components/src/molecules/color-picker-modal/color-picker-modal.component.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useRef, useState, useEffect } from 'react';
|
|
3
|
+
import { HexColorPicker } from 'react-colorful';
|
|
4
|
+
import { useClickOutside } from '../../hooks';
|
|
5
|
+
import { TooltipProvider, Tooltip } from '../../atoms/tooltip/tooltip.component';
|
|
6
|
+
import { DEFAULT_BG_COLOR, DEFAULT_TEXT_COLOR, STANDARD_COLORS, } from '../../helpers/constants';
|
|
7
|
+
import './color-picker-modal.css';
|
|
8
|
+
import '../../tc.module.css';
|
|
9
|
+
export const ColorPickerModal = ({ color, isVisible = false, testId = 'color-picker', tooltip = '', tooltipSide = 'bottom', onChange, onNoFill, onClose, }) => {
|
|
10
|
+
const popover = useRef();
|
|
11
|
+
const [currentColor, setCurrentColor] = useState(color);
|
|
12
|
+
const [isOpen, toggle] = useState(isVisible);
|
|
13
|
+
const close = useCallback(() => {
|
|
14
|
+
if (isOpen) {
|
|
15
|
+
toggle(false);
|
|
16
|
+
onClose && onClose(currentColor);
|
|
17
|
+
}
|
|
18
|
+
}, [isOpen, onClose, currentColor]);
|
|
19
|
+
useClickOutside(popover, close);
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
if (!isOpen) {
|
|
22
|
+
setCurrentColor(color || DEFAULT_BG_COLOR);
|
|
23
|
+
}
|
|
24
|
+
}, [color, isOpen]);
|
|
25
|
+
const handleColorChange = useCallback((color) => {
|
|
26
|
+
setCurrentColor(color);
|
|
27
|
+
onChange(color);
|
|
28
|
+
}, [onChange]);
|
|
29
|
+
const handleStandardColorClick = useCallback((color) => {
|
|
30
|
+
setCurrentColor(color);
|
|
31
|
+
onChange(color);
|
|
32
|
+
close();
|
|
33
|
+
}, [onChange, close]);
|
|
34
|
+
const handleNoFillClick = useCallback(() => {
|
|
35
|
+
onNoFill && onNoFill(DEFAULT_BG_COLOR, DEFAULT_TEXT_COLOR);
|
|
36
|
+
setCurrentColor(DEFAULT_BG_COLOR);
|
|
37
|
+
onChange(DEFAULT_BG_COLOR);
|
|
38
|
+
close();
|
|
39
|
+
}, [onNoFill, onChange, close]);
|
|
40
|
+
return (_jsxs("div", { className: "picker-modal", "data-testid": testId, children: [_jsx(TooltipProvider, { children: _jsx(Tooltip, { content: tooltip, className: 'text-white bg-black p-2', side: tooltipSide, children: _jsx("div", { "data-testid": "swatch", className: `${currentColor !== '' ? 'swatch-modal' : 'swatch-modal diagonal-line'} z-10`, style: { backgroundColor: currentColor }, onClick: () => toggle(true) }) }) }), isOpen && (_jsxs(_Fragment, { children: [_jsx("div", { className: "flex justify-center items-center overflow-x-hidden overflow-y-auto fixed inset-0 z-50 outline-none focus:outline-none ", children: _jsx("div", { className: "relative w-auto h-auto mx-auto my-auto bg-white rounded-md", children: _jsx("div", { className: "border-0 rounded-lg relative flex flex-col w-full outline-none focus:outline-none", children: _jsxs("div", { className: "flex flex-col w-full gap-4 justify-center items-center p-4 rounded-lg shadow-lg z-99 color-picker-modal", ref: popover, children: [_jsx(HexColorPicker, { "data-testid": "colorPicker", color: currentColor, onChange: handleColorChange }), _jsxs("div", { className: "flex flex-col mt-4", children: [_jsx("span", { className: "font-serif", children: "Standard Colors" }), _jsx("div", { className: "flex gap-2 mt-2", children: STANDARD_COLORS?.map((color) => (_jsx("div", { className: "rounded-full w-8 h-8 cursor-pointer gap-2", style: { backgroundColor: color }, onClick: () => handleStandardColorClick(color), "data-testid": `standard-color-${color}` }, color))) })] }), _jsx("div", { className: "flex justify-center bg-blue-600 mt-2 rounded-md p-2 mx-8 text-white hover:bg-blue-800 transition duration-300 ease-in-out hover:shadow-lg cursor-pointer", onClick: handleNoFillClick, "data-testid": "no-fill", children: _jsx("span", { className: "font-serif", children: "No Fill" }) })] }) }) }) }), _jsx("div", { className: "opacity-25 fixed inset-0 z-40 bg-black" })] }))] }));
|
|
41
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
.picker-modal {
|
|
2
|
+
position: relative;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.swatch-modal {
|
|
6
|
+
width: 28px;
|
|
7
|
+
height: 28px;
|
|
8
|
+
border-radius: 8px;
|
|
9
|
+
border: 3px solid #fff;
|
|
10
|
+
box-shadow:
|
|
11
|
+
0 0 0 1px rgba(0, 0, 0, 0.1),
|
|
12
|
+
inset 0 0 0 1px rgba(0, 0, 0, 0.1);
|
|
13
|
+
cursor: pointer;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.diagonal-line {
|
|
17
|
+
background-color: transparent;
|
|
18
|
+
background-image: gradient(
|
|
19
|
+
linear,
|
|
20
|
+
19.1% -7.9%,
|
|
21
|
+
81% 107.9%,
|
|
22
|
+
color-stop(0, transparent),
|
|
23
|
+
color-stop(0.48, transparent),
|
|
24
|
+
color-stop(0.5, #000),
|
|
25
|
+
color-stop(0.52, transparent),
|
|
26
|
+
color-stop(1, transparent)
|
|
27
|
+
);
|
|
28
|
+
background-image: repeating-linear-gradient(
|
|
29
|
+
130deg,
|
|
30
|
+
transparent 0%,
|
|
31
|
+
transparent 48%,
|
|
32
|
+
#000 50%,
|
|
33
|
+
transparent 52%,
|
|
34
|
+
transparent 100%
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.popover-modal {
|
|
39
|
+
position: absolute;
|
|
40
|
+
top: calc(100% + 2px);
|
|
41
|
+
left: 0;
|
|
42
|
+
border-radius: 9px;
|
|
43
|
+
box-shadow: 0 6px 12px rgba(0, 0, 0, 0.15);
|
|
44
|
+
z-index: 999;
|
|
45
|
+
}
|
package/lib/src/core-components/src/molecules/color-picker-modal/color-picker-modal.spec.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color-picker-modal.spec.d.ts","sourceRoot":"","sources":["../../../../../../src/core-components/src/molecules/color-picker-modal/color-picker-modal.spec.tsx"],"names":[],"mappings":"AAEA,OAAO,2BAA2B,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render } from '@testing-library/react';
|
|
3
|
+
import '@testing-library/jest-dom';
|
|
4
|
+
import { ColorPickerModal } from './color-picker-modal.component';
|
|
5
|
+
test('Render Autocomplete', () => {
|
|
6
|
+
render(_jsx(ColorPickerModal, { color: "#000000", onChange: () => { } }));
|
|
7
|
+
});
|
package/lib/src/core-components/src/molecules/css-multiline-input/css-multiline-input.component.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
interface CSSMultilineProps {
|
|
2
|
+
label?: string;
|
|
3
|
+
defaultValue?: string;
|
|
4
|
+
placeholder?: string;
|
|
5
|
+
className?: string;
|
|
6
|
+
style?: any;
|
|
7
|
+
onChange(item: any): void;
|
|
8
|
+
}
|
|
9
|
+
export declare const CSSMultiline: ({ label, defaultValue, className, style, placeholder, onChange, }: CSSMultilineProps) => import("react/jsx-runtime").JSX.Element;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=css-multiline-input.component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-multiline-input.component.d.ts","sourceRoot":"","sources":["../../../../../../src/core-components/src/molecules/css-multiline-input/css-multiline-input.component.tsx"],"names":[],"mappings":"AAOA,UAAU,iBAAiB;IACzB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,QAAQ,CAAC,IAAI,KAAA,GAAG,IAAI,CAAC;CACtB;AAWD,eAAO,MAAM,YAAY,sEAOtB,iBAAiB,4CA8HnB,CAAC"}
|
package/lib/src/core-components/src/molecules/css-multiline-input/css-multiline-input.component.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState, useRef } from 'react';
|
|
3
|
+
import * as Form from '../../atoms/form/form.component';
|
|
4
|
+
import { properties as propertiesObj } from './css-properties';
|
|
5
|
+
import s from '../../tc.module.css';
|
|
6
|
+
import { cn } from '../../utils';
|
|
7
|
+
const mapToArray = (arr) => {
|
|
8
|
+
const res = [];
|
|
9
|
+
arr.forEach(function (obj, index) {
|
|
10
|
+
const key = Object.keys(obj)[0];
|
|
11
|
+
const value = key;
|
|
12
|
+
res.push([value, obj[key]]);
|
|
13
|
+
});
|
|
14
|
+
return res;
|
|
15
|
+
};
|
|
16
|
+
const data = mapToArray(propertiesObj);
|
|
17
|
+
export const CSSMultiline = ({ label = 'Main Box CSS', defaultValue = '', className = '', style = {}, placeholder = "Like fontSize: 12,backgroundColor:'#000000',", onChange, }) => {
|
|
18
|
+
const value = useRef('');
|
|
19
|
+
const [properties, setProperties] = useState([]);
|
|
20
|
+
const [isListOpen, setIsListOpen] = useState(false);
|
|
21
|
+
useEffect(() => {
|
|
22
|
+
value.current = defaultValue;
|
|
23
|
+
setProperties(data);
|
|
24
|
+
}, [defaultValue]);
|
|
25
|
+
const useOutsideAlerter = (ref) => {
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
function handleClickOutside(event) {
|
|
28
|
+
if (ref.current && !ref.current.contains(event.target)) {
|
|
29
|
+
setIsListOpen(false);
|
|
30
|
+
onChange(value.current);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
34
|
+
return () => {
|
|
35
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
36
|
+
};
|
|
37
|
+
}, [ref]);
|
|
38
|
+
};
|
|
39
|
+
const wrapperRef = useRef(null);
|
|
40
|
+
useOutsideAlerter(wrapperRef);
|
|
41
|
+
const list = [];
|
|
42
|
+
const filter = (css) => {
|
|
43
|
+
let matchString = css?.split(',');
|
|
44
|
+
matchString = matchString[matchString?.length - 1];
|
|
45
|
+
matchString = matchString?.split(':')[0];
|
|
46
|
+
matchString = matchString?.split("'")[0];
|
|
47
|
+
if (css?.length == 0)
|
|
48
|
+
return setProperties(data);
|
|
49
|
+
else {
|
|
50
|
+
data?.map((item) => {
|
|
51
|
+
const innerItem = [];
|
|
52
|
+
const isItems = item[0]?.startsWith(matchString);
|
|
53
|
+
if (isItems)
|
|
54
|
+
innerItem.push(item[0]);
|
|
55
|
+
if (innerItem?.length > 0)
|
|
56
|
+
list.push([item[0], item[1]]);
|
|
57
|
+
});
|
|
58
|
+
setProperties(list);
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const onKeyUp = (e) => {
|
|
62
|
+
setIsListOpen(true);
|
|
63
|
+
};
|
|
64
|
+
return (_jsxs("div", { className: cn(s['flex'], s['flex-col'], s['w-full']), ref: wrapperRef, children: [_jsx(Form.MultilineInput, { label: label, style: { color: '#ffffff', backgroundColor: '#000000', ...style }, placeholder: placeholder, value: value.current, className: cn(className), onKeyUp: onKeyUp, onChange: (css) => {
|
|
65
|
+
value.current = css;
|
|
66
|
+
filter(css);
|
|
67
|
+
} }), isListOpen && (_jsx("div", { style: { marginTop: -10 }, children: _jsx("ul", { className: cn(s['flex'], s['flex-col'], s['max-h-40'], s['bg-black'], s['m-2'], s['text-white'], s['overflow-y-scroll']), children: properties?.map((item, index) => (_jsxs("li", { className: cn(s['flex'], s['flex-col'], s['gap-4'], s['p-2']), children: [_jsx("span", { className: cn(s['underline']), children: item[0] }), item[1]?.map((prop) => (_jsxs("li", { className: cn(s['flex'], s['-mt-2'], s['px-2'], s['h-8'], s['bg-slate-800'], s['rounded-md'], s['items-center'], s['cursor-pointer']), onClick: () => {
|
|
68
|
+
let existsString = value.current?.split(',');
|
|
69
|
+
if (value.current.includes(',')) {
|
|
70
|
+
existsString = existsString.map((item) => {
|
|
71
|
+
if (item?.includes(':'))
|
|
72
|
+
return item;
|
|
73
|
+
});
|
|
74
|
+
if (prop != 'number')
|
|
75
|
+
existsString.push(`${item[0]}:'${prop}',`);
|
|
76
|
+
else
|
|
77
|
+
existsString.push(`${item[0]}:1,`);
|
|
78
|
+
value.current = existsString
|
|
79
|
+
.join(',')
|
|
80
|
+
.replaceAll(',,', ',');
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
if (prop != 'number')
|
|
84
|
+
value.current = `${item[0]}:'${prop}',`;
|
|
85
|
+
else {
|
|
86
|
+
value.current = `${item[0]}:1,`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
filter(existsString.join(''));
|
|
90
|
+
}, children: [' ', prop, ' '] })))] }, index))) }) }))] }));
|
|
91
|
+
};
|