@skalfa/skalfa-component 1.0.0
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/LICENSE +21 -0
- package/README.md +79 -0
- package/dist/accordion/Accordion.component.d.ts +13 -0
- package/dist/accordion/Accordion.component.js +25 -0
- package/dist/breadcrumb/Breadcrumb.component.d.ts +14 -0
- package/dist/breadcrumb/Breadcrumb.component.js +21 -0
- package/dist/button/Button.component.d.ts +21 -0
- package/dist/button/Button.component.js +19 -0
- package/dist/card/AlertCard.component.d.ts +11 -0
- package/dist/card/AlertCard.component.js +9 -0
- package/dist/card/Card.component.d.ts +5 -0
- package/dist/card/Card.component.js +9 -0
- package/dist/card/DashboardCard.component.d.ts +9 -0
- package/dist/card/DashboardCard.component.js +13 -0
- package/dist/card/GalleryCard.component.d.ts +7 -0
- package/dist/card/GalleryCard.component.js +13 -0
- package/dist/card/ProductCard.component.d.ts +9 -0
- package/dist/card/ProductCard.component.js +13 -0
- package/dist/card/ProfileCard.component.d.ts +10 -0
- package/dist/card/ProfileCard.component.js +13 -0
- package/dist/carousel/Carousel.component.d.ts +13 -0
- package/dist/carousel/Carousel.component.js +37 -0
- package/dist/chip/Chip.component.d.ts +6 -0
- package/dist/chip/Chip.component.js +12 -0
- package/dist/index.d.ts +56 -0
- package/dist/index.js +85 -0
- package/dist/input/Checkbox.component.d.ts +13 -0
- package/dist/input/Checkbox.component.js +23 -0
- package/dist/input/Input.component.d.ts +23 -0
- package/dist/input/Input.component.js +134 -0
- package/dist/input/InputCheckbox.component.d.ts +27 -0
- package/dist/input/InputCheckbox.component.js +53 -0
- package/dist/input/InputCurrency.component.d.ts +21 -0
- package/dist/input/InputCurrency.component.js +30 -0
- package/dist/input/InputDate.component.d.ts +24 -0
- package/dist/input/InputDate.component.js +107 -0
- package/dist/input/InputDatetime.component.d.ts +17 -0
- package/dist/input/InputDatetime.component.js +75 -0
- package/dist/input/InputDocument.component.d.ts +22 -0
- package/dist/input/InputDocument.component.js +88 -0
- package/dist/input/InputImage.component.d.ts +23 -0
- package/dist/input/InputImage.component.js +260 -0
- package/dist/input/InputMap.component.d.ts +25 -0
- package/dist/input/InputMap.component.js +103 -0
- package/dist/input/InputNumber.component.d.ts +19 -0
- package/dist/input/InputNumber.component.js +40 -0
- package/dist/input/InputOtp.component.d.ts +14 -0
- package/dist/input/InputOtp.component.js +65 -0
- package/dist/input/InputPassword.component.d.ts +17 -0
- package/dist/input/InputPassword.component.js +59 -0
- package/dist/input/InputRadio.component.d.ts +27 -0
- package/dist/input/InputRadio.component.js +56 -0
- package/dist/input/InputTime.component.d.ts +23 -0
- package/dist/input/InputTime.component.js +73 -0
- package/dist/input/InputValues.component.d.ts +9 -0
- package/dist/input/InputValues.component.js +19 -0
- package/dist/input/Radio.component.d.ts +12 -0
- package/dist/input/Radio.component.js +22 -0
- package/dist/input/Select.component.d.ts +47 -0
- package/dist/input/Select.component.js +275 -0
- package/dist/modal/BottomSheet.component.d.ts +12 -0
- package/dist/modal/BottomSheet.component.js +161 -0
- package/dist/modal/FloatingPage.component.d.ts +12 -0
- package/dist/modal/FloatingPage.component.js +27 -0
- package/dist/modal/Modal.component.d.ts +12 -0
- package/dist/modal/Modal.component.js +27 -0
- package/dist/modal/ModalConfirm.component.d.ts +26 -0
- package/dist/modal/ModalConfirm.component.js +68 -0
- package/dist/modal/Toast.component.d.ts +11 -0
- package/dist/modal/Toast.component.js +58 -0
- package/dist/nav/Bottombar.component.d.ts +12 -0
- package/dist/nav/Bottombar.component.js +32 -0
- package/dist/nav/Footer.component.d.ts +37 -0
- package/dist/nav/Footer.component.js +49 -0
- package/dist/nav/Headbar.component.d.ts +14 -0
- package/dist/nav/Headbar.component.js +32 -0
- package/dist/nav/Navbar.component.d.ts +22 -0
- package/dist/nav/Navbar.component.js +26 -0
- package/dist/nav/Sidebar.component.d.ts +33 -0
- package/dist/nav/Sidebar.component.js +87 -0
- package/dist/nav/Tabbar.component.d.ts +13 -0
- package/dist/nav/Tabbar.component.js +17 -0
- package/dist/nav/Wizard.component.d.ts +9 -0
- package/dist/nav/Wizard.component.js +24 -0
- package/dist/src/accordion/Accordion.component.d.ts +13 -0
- package/dist/src/accordion/Accordion.component.js +25 -0
- package/dist/src/breadcrumb/Breadcrumb.component.d.ts +14 -0
- package/dist/src/breadcrumb/Breadcrumb.component.js +21 -0
- package/dist/src/button/Button.component.d.ts +21 -0
- package/dist/src/button/Button.component.js +19 -0
- package/dist/src/card/AlertCard.component.d.ts +11 -0
- package/dist/src/card/AlertCard.component.js +9 -0
- package/dist/src/card/Card.component.d.ts +5 -0
- package/dist/src/card/Card.component.js +9 -0
- package/dist/src/card/DashboardCard.component.d.ts +9 -0
- package/dist/src/card/DashboardCard.component.js +13 -0
- package/dist/src/card/GalleryCard.component.d.ts +7 -0
- package/dist/src/card/GalleryCard.component.js +13 -0
- package/dist/src/card/ProductCard.component.d.ts +9 -0
- package/dist/src/card/ProductCard.component.js +13 -0
- package/dist/src/card/ProfileCard.component.d.ts +10 -0
- package/dist/src/card/ProfileCard.component.js +13 -0
- package/dist/src/carousel/Carousel.component.d.ts +13 -0
- package/dist/src/carousel/Carousel.component.js +37 -0
- package/dist/src/chip/Chip.component.d.ts +6 -0
- package/dist/src/chip/Chip.component.js +12 -0
- package/dist/src/index.d.ts +13 -0
- package/dist/src/index.js +29 -0
- package/dist/src/input/Checkbox.component.d.ts +13 -0
- package/dist/src/input/Checkbox.component.js +23 -0
- package/dist/src/input/Input.component.d.ts +23 -0
- package/dist/src/input/Input.component.js +134 -0
- package/dist/src/input/InputCheckbox.component.d.ts +27 -0
- package/dist/src/input/InputCheckbox.component.js +53 -0
- package/dist/src/input/InputCurrency.component.d.ts +21 -0
- package/dist/src/input/InputCurrency.component.js +30 -0
- package/dist/src/input/InputDate.component.d.ts +24 -0
- package/dist/src/input/InputDate.component.js +107 -0
- package/dist/src/input/InputDatetime.component.d.ts +17 -0
- package/dist/src/input/InputDatetime.component.js +75 -0
- package/dist/src/input/InputDocument.component.d.ts +22 -0
- package/dist/src/input/InputDocument.component.js +88 -0
- package/dist/src/input/InputImage.component.d.ts +23 -0
- package/dist/src/input/InputImage.component.js +260 -0
- package/dist/src/input/InputMap.component.d.ts +25 -0
- package/dist/src/input/InputMap.component.js +101 -0
- package/dist/src/input/InputNumber.component.d.ts +19 -0
- package/dist/src/input/InputNumber.component.js +40 -0
- package/dist/src/input/InputOtp.component.d.ts +14 -0
- package/dist/src/input/InputOtp.component.js +65 -0
- package/dist/src/input/InputPassword.component.d.ts +17 -0
- package/dist/src/input/InputPassword.component.js +59 -0
- package/dist/src/input/InputRadio.component.d.ts +27 -0
- package/dist/src/input/InputRadio.component.js +56 -0
- package/dist/src/input/InputTime.component.d.ts +23 -0
- package/dist/src/input/InputTime.component.js +73 -0
- package/dist/src/input/InputValues.component.d.ts +9 -0
- package/dist/src/input/InputValues.component.js +19 -0
- package/dist/src/input/Radio.component.d.ts +12 -0
- package/dist/src/input/Radio.component.js +22 -0
- package/dist/src/input/Select.component.d.ts +47 -0
- package/dist/src/input/Select.component.js +275 -0
- package/dist/src/modal/BottomSheet.component.d.ts +12 -0
- package/dist/src/modal/BottomSheet.component.js +161 -0
- package/dist/src/modal/FloatingPage.component.d.ts +12 -0
- package/dist/src/modal/FloatingPage.component.js +27 -0
- package/dist/src/modal/Modal.component.d.ts +12 -0
- package/dist/src/modal/Modal.component.js +27 -0
- package/dist/src/modal/ModalConfirm.component.d.ts +26 -0
- package/dist/src/modal/ModalConfirm.component.js +68 -0
- package/dist/src/modal/Toast.component.d.ts +11 -0
- package/dist/src/modal/Toast.component.js +58 -0
- package/dist/src/nav/Bottombar.component.d.ts +12 -0
- package/dist/src/nav/Bottombar.component.js +32 -0
- package/dist/src/nav/Footer.component.d.ts +37 -0
- package/dist/src/nav/Footer.component.js +49 -0
- package/dist/src/nav/Headbar.component.d.ts +14 -0
- package/dist/src/nav/Headbar.component.js +32 -0
- package/dist/src/nav/Navbar.component.d.ts +22 -0
- package/dist/src/nav/Navbar.component.js +26 -0
- package/dist/src/nav/Sidebar.component.d.ts +33 -0
- package/dist/src/nav/Sidebar.component.js +87 -0
- package/dist/src/nav/Tabbar.component.d.ts +13 -0
- package/dist/src/nav/Tabbar.component.js +17 -0
- package/dist/src/nav/Wizard.component.d.ts +9 -0
- package/dist/src/nav/Wizard.component.js +24 -0
- package/dist/src/supervision/FormSupervision.component.d.ts +93 -0
- package/dist/src/supervision/FormSupervision.component.js +168 -0
- package/dist/src/supervision/TableSupervision.component.d.ts +78 -0
- package/dist/src/supervision/TableSupervision.component.js +273 -0
- package/dist/src/table/ControlBar.component.d.ts +34 -0
- package/dist/src/table/ControlBar.component.js +205 -0
- package/dist/src/table/FilterComponent.d.ts +45 -0
- package/dist/src/table/FilterComponent.js +132 -0
- package/dist/src/table/Pagination.component.d.ts +8 -0
- package/dist/src/table/Pagination.component.js +32 -0
- package/dist/src/table/Table.component.d.ts +61 -0
- package/dist/src/table/Table.component.js +101 -0
- package/dist/src/typography/TypographyArticle.component.d.ts +8 -0
- package/dist/src/typography/TypographyArticle.component.js +7 -0
- package/dist/src/typography/TypographyColumn.component.d.ts +6 -0
- package/dist/src/typography/TypographyColumn.component.js +7 -0
- package/dist/src/typography/TypographyContent.component.d.ts +6 -0
- package/dist/src/typography/TypographyContent.component.js +7 -0
- package/dist/src/typography/TypographyTips.component.d.ts +6 -0
- package/dist/src/typography/TypographyTips.component.js +7 -0
- package/dist/src/wrap/Draggable.component.d.ts +34 -0
- package/dist/src/wrap/Draggable.component.js +214 -0
- package/dist/src/wrap/Image.component.d.ts +2 -0
- package/dist/src/wrap/Image.component.js +13 -0
- package/dist/src/wrap/OutsideClick.component.d.ts +6 -0
- package/dist/src/wrap/OutsideClick.component.js +34 -0
- package/dist/src/wrap/ScrollContainer.component.d.ts +10 -0
- package/dist/src/wrap/ScrollContainer.component.js +54 -0
- package/dist/src/wrap/ShortcutProvider.d.ts +1 -0
- package/dist/src/wrap/ShortcutProvider.js +42 -0
- package/dist/src/wrap/Swipe.component.d.ts +14 -0
- package/dist/src/wrap/Swipe.component.js +61 -0
- package/dist/supervision/FormSupervision.component.d.ts +93 -0
- package/dist/supervision/FormSupervision.component.js +168 -0
- package/dist/supervision/TableSupervision.component.d.ts +78 -0
- package/dist/supervision/TableSupervision.component.js +273 -0
- package/dist/table/ControlBar.component.d.ts +34 -0
- package/dist/table/ControlBar.component.js +205 -0
- package/dist/table/FilterComponent.d.ts +45 -0
- package/dist/table/FilterComponent.js +132 -0
- package/dist/table/Pagination.component.d.ts +8 -0
- package/dist/table/Pagination.component.js +32 -0
- package/dist/table/Table.component.d.ts +61 -0
- package/dist/table/Table.component.js +101 -0
- package/dist/typography/TypographyArticle.component.d.ts +8 -0
- package/dist/typography/TypographyArticle.component.js +7 -0
- package/dist/typography/TypographyColumn.component.d.ts +6 -0
- package/dist/typography/TypographyColumn.component.js +7 -0
- package/dist/typography/TypographyContent.component.d.ts +6 -0
- package/dist/typography/TypographyContent.component.js +7 -0
- package/dist/typography/TypographyTips.component.d.ts +6 -0
- package/dist/typography/TypographyTips.component.js +7 -0
- package/dist/wrap/Draggable.component.d.ts +1 -0
- package/dist/wrap/Draggable.component.js +214 -0
- package/dist/wrap/Image.component.d.ts +2 -0
- package/dist/wrap/Image.component.js +13 -0
- package/dist/wrap/OutsideClick.component.d.ts +6 -0
- package/dist/wrap/OutsideClick.component.js +34 -0
- package/dist/wrap/ScrollContainer.component.d.ts +10 -0
- package/dist/wrap/ScrollContainer.component.js +54 -0
- package/dist/wrap/ShortcutProvider.d.ts +1 -0
- package/dist/wrap/ShortcutProvider.js +42 -0
- package/dist/wrap/Swipe.component.d.ts +14 -0
- package/dist/wrap/Swipe.component.js +61 -0
- package/package.json +44 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { ApiType, ValidationRules } from "@utils";
|
|
3
|
+
export interface SelectOptionProps {
|
|
4
|
+
label: string | ReactNode;
|
|
5
|
+
value: string | number;
|
|
6
|
+
searchable?: string[];
|
|
7
|
+
customLabel?: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
export interface SelectProps {
|
|
10
|
+
name: string;
|
|
11
|
+
label?: string;
|
|
12
|
+
placeholder?: string;
|
|
13
|
+
tip?: string | ReactNode;
|
|
14
|
+
leftIcon?: any;
|
|
15
|
+
rightIcon?: any;
|
|
16
|
+
value?: string | number | (string | number)[];
|
|
17
|
+
invalid?: string;
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
validations?: ValidationRules;
|
|
20
|
+
multiple?: boolean;
|
|
21
|
+
autoFocus?: boolean;
|
|
22
|
+
clearable?: boolean;
|
|
23
|
+
options?: SelectOptionProps[];
|
|
24
|
+
searchable?: boolean;
|
|
25
|
+
serverOptionControl?: ApiType & {
|
|
26
|
+
cacheName?: string | false;
|
|
27
|
+
};
|
|
28
|
+
idbOptionControl?: {
|
|
29
|
+
store: string;
|
|
30
|
+
labelKey: string;
|
|
31
|
+
valueKey: string;
|
|
32
|
+
};
|
|
33
|
+
serverSearchable?: boolean;
|
|
34
|
+
includedOptions?: SelectOptionProps[];
|
|
35
|
+
exceptOptions?: (string | number)[];
|
|
36
|
+
tempOptions?: SelectOptionProps[];
|
|
37
|
+
newOption?: SelectOptionProps;
|
|
38
|
+
maxShowOption?: number;
|
|
39
|
+
onChange?: (value: string | number | (string | number)[], data?: any) => any;
|
|
40
|
+
register?: (name: string, validations?: ValidationRules) => void;
|
|
41
|
+
unregister?: (name: string) => void;
|
|
42
|
+
onFocus?: () => void;
|
|
43
|
+
onBlur?: () => void;
|
|
44
|
+
/** Use custom class with: "label::", "tip::", "error::", "icon::", "suggest::", "suggest-item::". */
|
|
45
|
+
className?: string;
|
|
46
|
+
}
|
|
47
|
+
export declare function SelectComponent({ name, label, placeholder, tip, leftIcon, rightIcon, value, invalid, disabled, validations, multiple, autoFocus, clearable, options, searchable, serverOptionControl, idbOptionControl, serverSearchable, includedOptions, exceptOptions, tempOptions, newOption, maxShowOption, register, unregister, onChange, onFocus, onBlur, className, }: SelectProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.SelectComponent = SelectComponent;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const react_fontawesome_1 = require("@fortawesome/react-fontawesome");
|
|
8
|
+
const free_solid_svg_icons_1 = require("@fortawesome/free-solid-svg-icons");
|
|
9
|
+
const _utils_1 = require("@utils");
|
|
10
|
+
;
|
|
11
|
+
function SelectComponent({ name, label, placeholder, tip, leftIcon, rightIcon, value, invalid, disabled, validations, multiple, autoFocus, clearable, options = [], searchable, serverOptionControl, idbOptionControl, serverSearchable, includedOptions = [], exceptOptions = [], tempOptions, newOption, maxShowOption = 10, register, unregister, onChange, onFocus, onBlur, className = "", }) {
|
|
12
|
+
const [inputShowValue, setInputShowValue] = (0, react_1.useState)("");
|
|
13
|
+
const [keydown, setKeydown] = (0, react_1.useState)(false);
|
|
14
|
+
const [useTemp, setUseTemp] = (0, react_1.useState)(true);
|
|
15
|
+
const [dataOptions, setDataOptions] = (0, react_1.useState)([]);
|
|
16
|
+
const [filteredOptions, setFilteredOptions] = (0, react_1.useState)([]);
|
|
17
|
+
const [loadingOption, setLoadingOption] = (0, react_1.useState)(false);
|
|
18
|
+
const [activeOption, setActiveOption] = (0, react_1.useState)(0);
|
|
19
|
+
const [showOption, setShowOption] = (0, react_1.useState)(false);
|
|
20
|
+
const [keyword, setKeyword] = (0, react_1.useState)("");
|
|
21
|
+
const [keywordSearch] = (0, _utils_1.useLazySearch)(keyword);
|
|
22
|
+
// =========================>
|
|
23
|
+
// ## Initial
|
|
24
|
+
// =========================>
|
|
25
|
+
const inputHandler = (0, _utils_1.useInputHandler)(name, value, validations, register, unregister, false);
|
|
26
|
+
const randomId = (0, _utils_1.useInputRandomId)();
|
|
27
|
+
// =========================>
|
|
28
|
+
// ## Invalid handler
|
|
29
|
+
// =========================>
|
|
30
|
+
const [invalidMessage] = (0, _utils_1.useValidation)(inputHandler.value, validations, invalid, inputHandler.idle);
|
|
31
|
+
// =========================>
|
|
32
|
+
// ## change value handler
|
|
33
|
+
// =========================>
|
|
34
|
+
(0, react_1.useEffect)(() => {
|
|
35
|
+
if (value) {
|
|
36
|
+
inputHandler.setValue(value);
|
|
37
|
+
Array.isArray(dataOptions) && setInputShowValue((newOption ? [newOption, ...dataOptions] : dataOptions)?.find((option) => option.value == value)?.label || "");
|
|
38
|
+
inputHandler.setIdle(false);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
inputHandler.setValue("");
|
|
42
|
+
setInputShowValue("");
|
|
43
|
+
}
|
|
44
|
+
}, [value, dataOptions]);
|
|
45
|
+
// =========================>
|
|
46
|
+
// ## options handler
|
|
47
|
+
// =========================>
|
|
48
|
+
(0, react_1.useEffect)(() => {
|
|
49
|
+
options?.length && setDataOptions([...options, ...includedOptions].filter((op) => !exceptOptions?.includes(op.value)));
|
|
50
|
+
}, [options]);
|
|
51
|
+
const filterOption = (e) => {
|
|
52
|
+
if (dataOptions?.length) {
|
|
53
|
+
let newFilteredOptions = [];
|
|
54
|
+
if (searchable && !serverSearchable) {
|
|
55
|
+
if (e.target.value) {
|
|
56
|
+
newFilteredOptions = dataOptions.filter((Option) => Option.label?.toLowerCase().indexOf(e.target.value.toLowerCase()) > -1).slice(0, maxShowOption);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
newFilteredOptions = dataOptions.slice(0, maxShowOption);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
newFilteredOptions = dataOptions;
|
|
64
|
+
}
|
|
65
|
+
setActiveOption(-1);
|
|
66
|
+
setFilteredOptions(newFilteredOptions);
|
|
67
|
+
setShowOption(true);
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const onKeyDownOption = (e) => {
|
|
71
|
+
if (dataOptions?.length) {
|
|
72
|
+
if (e.keyCode === 13) {
|
|
73
|
+
const resultValue = filteredOptions?.at(activeOption);
|
|
74
|
+
setActiveOption(-1);
|
|
75
|
+
setFilteredOptions([]);
|
|
76
|
+
setShowOption(false);
|
|
77
|
+
if (!multiple) {
|
|
78
|
+
setInputShowValue(resultValue?.label || inputShowValue);
|
|
79
|
+
inputHandler.setValue(resultValue?.value || inputShowValue);
|
|
80
|
+
serverSearchable && setKeyword(resultValue?.label || keyword);
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
if (resultValue?.value) {
|
|
84
|
+
searchable ? setInputShowValue(resultValue.label) : searchable && setInputShowValue("");
|
|
85
|
+
serverSearchable && setKeyword(resultValue.label);
|
|
86
|
+
const values = Array.isArray(inputHandler.value) ? Array().concat(inputHandler.value)?.filter((val) => val != resultValue?.value) : [];
|
|
87
|
+
if (values.find((val) => val == resultValue?.value)) {
|
|
88
|
+
inputHandler.setValue(values);
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
inputHandler.setValue([...Array().concat(values), resultValue.value]);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
e.preventDefault();
|
|
96
|
+
}
|
|
97
|
+
else if (e.keyCode === 38) {
|
|
98
|
+
if (activeOption === 0)
|
|
99
|
+
return;
|
|
100
|
+
setActiveOption(activeOption - 1);
|
|
101
|
+
}
|
|
102
|
+
else if (e.keyCode === 40) {
|
|
103
|
+
if (activeOption + 1 >= (filteredOptions?.length || 0))
|
|
104
|
+
return;
|
|
105
|
+
setActiveOption(activeOption + 1);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const fetchOptions = async () => {
|
|
110
|
+
setLoadingOption(true);
|
|
111
|
+
const serverControl = {
|
|
112
|
+
...serverOptionControl,
|
|
113
|
+
params: serverSearchable ? { search: keywordSearch, ...(serverOptionControl?.params || {}) } : (serverOptionControl?.params || {}),
|
|
114
|
+
headers: { "X-Option": 1 }
|
|
115
|
+
};
|
|
116
|
+
const getCacheOptions = await _utils_1.cavity.get(serverOptionControl?.cacheName || `option_${serverOptionControl?.path}`);
|
|
117
|
+
const cacheOptions = (getCacheOptions?.data || []);
|
|
118
|
+
if (cacheOptions?.length) {
|
|
119
|
+
setDataOptions([...cacheOptions, ...includedOptions].filter((op) => !exceptOptions?.includes(op.value)));
|
|
120
|
+
setLoadingOption(false);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
const mutateOptions = await (0, _utils_1.api)(serverControl || {});
|
|
124
|
+
setDataOptions([...(mutateOptions?.data?.data || []), ...(includedOptions || [])].filter((op) => !exceptOptions?.includes(op.value)));
|
|
125
|
+
setShowOption(true);
|
|
126
|
+
if (serverOptionControl?.cacheName != false) {
|
|
127
|
+
_utils_1.cavity.set({
|
|
128
|
+
key: serverOptionControl?.cacheName || `option_${serverOptionControl?.path}`,
|
|
129
|
+
data: mutateOptions?.data,
|
|
130
|
+
expired: 5,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
setLoadingOption(false);
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
const fetchIdbOptions = async () => {
|
|
137
|
+
setLoadingOption(true);
|
|
138
|
+
if (idbOptionControl?.store) {
|
|
139
|
+
const idb = _utils_1.registry.get("idb");
|
|
140
|
+
if (!idb) {
|
|
141
|
+
throw new Error("IndexedDB (IDB) extension is not installed.");
|
|
142
|
+
}
|
|
143
|
+
const getIdbOptions = await (await idb.query(idbOptionControl?.store)).get();
|
|
144
|
+
const rows = getIdbOptions.map((row) => {
|
|
145
|
+
const value = row[idbOptionControl.valueKey] || row["id"];
|
|
146
|
+
const label = row[idbOptionControl.labelKey] || row["id"];
|
|
147
|
+
return {
|
|
148
|
+
label,
|
|
149
|
+
value,
|
|
150
|
+
...row,
|
|
151
|
+
};
|
|
152
|
+
});
|
|
153
|
+
setDataOptions(rows);
|
|
154
|
+
setLoadingOption(false);
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
(0, react_1.useEffect)(() => {
|
|
158
|
+
if (!serverSearchable) {
|
|
159
|
+
if (serverOptionControl?.path || serverOptionControl?.url) {
|
|
160
|
+
fetchOptions();
|
|
161
|
+
}
|
|
162
|
+
else if (idbOptionControl?.store) {
|
|
163
|
+
fetchIdbOptions();
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
!options && setDataOptions([]);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}, [serverOptionControl?.path, serverOptionControl?.url]);
|
|
170
|
+
(0, react_1.useEffect)(() => {
|
|
171
|
+
if (serverSearchable) {
|
|
172
|
+
if (serverOptionControl?.path || serverOptionControl?.url) {
|
|
173
|
+
fetchOptions();
|
|
174
|
+
}
|
|
175
|
+
else {
|
|
176
|
+
!options && setDataOptions([]);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}, [keywordSearch, serverOptionControl?.path, serverOptionControl?.url]);
|
|
180
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsxs)("div", { className: "input-container", children: [(0, jsx_runtime_1.jsxs)("label", { htmlFor: randomId, className: (0, _utils_1.cn)("input-label", disabled && "input-label-disabled", inputHandler.focus && "input-label-focus", invalidMessage && "input-label-error", (0, _utils_1.pcn)(className, "label"), disabled && (0, _utils_1.pcn)(className, "label", "disabled"), inputHandler.focus && (0, _utils_1.pcn)(className, "label", "focus"), invalidMessage && (0, _utils_1.pcn)(className, "label", "error")), children: [label, validations && _utils_1.validation.hasRules(validations, "required") && (0, jsx_runtime_1.jsx)("span", { className: "text-danger ml-1", children: "*" })] }), tip && ((0, jsx_runtime_1.jsx)("small", { className: (0, _utils_1.cn)("input-tip", disabled && "input-tip-disabled", (0, _utils_1.pcn)(className, "tip"), disabled && (0, _utils_1.pcn)(className, "tip", "disabled")), children: tip })), (0, jsx_runtime_1.jsxs)("div", { className: "relative", children: [(0, jsx_runtime_1.jsx)("input", { type: "hidden", value: !multiple ? String(inputHandler.value) : Array().concat(inputHandler.value).map((val) => String(val)), name: name }), (0, jsx_runtime_1.jsx)("input", { type: "text", readOnly: !searchable, id: randomId, placeholder: !inputHandler.value || (Array.isArray(inputHandler.value) && !inputHandler.value.length) ? placeholder : "", disabled: disabled, className: (0, _utils_1.cn)("input cursor-pointer", leftIcon && "input-with-left-icon", rightIcon && "input-with-right-icon", invalidMessage && "input-error", (0, _utils_1.pcn)(className, "input"), invalidMessage && (0, _utils_1.pcn)(className, "input", "error")), value: (useTemp && tempOptions ? tempOptions.at(0)?.label : serverSearchable ? keyword : inputShowValue), onChange: (e) => {
|
|
181
|
+
setUseTemp(false);
|
|
182
|
+
searchable && setInputShowValue(e.target.value);
|
|
183
|
+
serverSearchable && setKeyword(e.target.value);
|
|
184
|
+
inputHandler.setIdle(false);
|
|
185
|
+
dataOptions?.length && filterOption(e);
|
|
186
|
+
}, onFocus: (e) => {
|
|
187
|
+
setUseTemp(false);
|
|
188
|
+
inputHandler.setFocus(true);
|
|
189
|
+
onFocus?.();
|
|
190
|
+
dataOptions?.length && filterOption(e);
|
|
191
|
+
searchable && e.target.select();
|
|
192
|
+
}, onBlur: (e) => {
|
|
193
|
+
setUseTemp(false);
|
|
194
|
+
const value = e.target.value;
|
|
195
|
+
const valueOption = dataOptions?.find((option) => option.label?.toLowerCase() == value?.toLowerCase());
|
|
196
|
+
if (!keydown) {
|
|
197
|
+
if (!multiple) {
|
|
198
|
+
setTimeout(() => {
|
|
199
|
+
if (valueOption?.value) {
|
|
200
|
+
setInputShowValue(valueOption.label);
|
|
201
|
+
inputHandler.setValue(valueOption.value);
|
|
202
|
+
serverSearchable && setKeyword(valueOption.label);
|
|
203
|
+
onChange?.(valueOption.value, valueOption);
|
|
204
|
+
}
|
|
205
|
+
else {
|
|
206
|
+
setInputShowValue("");
|
|
207
|
+
serverSearchable && setKeyword("");
|
|
208
|
+
inputHandler.setValue("");
|
|
209
|
+
onChange?.("");
|
|
210
|
+
}
|
|
211
|
+
}, 140);
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
setInputShowValue("");
|
|
215
|
+
serverSearchable && setKeyword("");
|
|
216
|
+
onChange?.("");
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
setTimeout(() => {
|
|
220
|
+
inputHandler.setFocus(false);
|
|
221
|
+
}, 100);
|
|
222
|
+
onBlur?.();
|
|
223
|
+
}, onKeyDown: (e) => {
|
|
224
|
+
dataOptions?.length && onKeyDownOption(e);
|
|
225
|
+
}, autoComplete: "off", autoFocus: autoFocus }), (multiple && !searchable || (searchable && !inputHandler.focus)) && ((0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)("select-multiple-values", leftIcon ? "select-multiple-values-left-icon" : "select-multiple-values-no-icon"), style: { maxWidth: `calc(100% - ${leftIcon ? "5.2rem" : "3.2rem"})` }, children: (0, jsx_runtime_1.jsx)("div", { className: "input-values-container", children: multiple && typeof inputHandler.value != "string" && Array().concat(inputHandler.value)?.map((item, key) => {
|
|
226
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "input-values-item", children: [(0, jsx_runtime_1.jsx)("span", { children: dataOptions?.find((option) => option.value == item)?.label }), (0, jsx_runtime_1.jsx)(react_fontawesome_1.FontAwesomeIcon, { icon: free_solid_svg_icons_1.faTimes, className: "input-values-delete", onClick: () => {
|
|
227
|
+
const values = Array().concat(inputHandler.value);
|
|
228
|
+
const index = values.findIndex((val) => val == item);
|
|
229
|
+
inputHandler.setValue(values.filter((_, val) => val != index));
|
|
230
|
+
if (!values.filter((_, val) => val != index)?.length) {
|
|
231
|
+
setInputShowValue("");
|
|
232
|
+
serverSearchable && setKeyword("");
|
|
233
|
+
onChange?.("");
|
|
234
|
+
}
|
|
235
|
+
} })] }, key));
|
|
236
|
+
}) }) })), leftIcon && ((0, jsx_runtime_1.jsx)(react_fontawesome_1.FontAwesomeIcon, { className: (0, _utils_1.cn)("input-icon", "input-icon-left", disabled && "input-icon-disabled", inputHandler.focus && "input-icon-focus", (0, _utils_1.pcn)(className, "icon"), disabled && (0, _utils_1.pcn)(className, "icon", "disabled"), inputHandler.focus && (0, _utils_1.pcn)(className, "icon", "focus")), icon: leftIcon })), !multiple && clearable && inputHandler.value && ((0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)("input-icon", "input-icon-clear", disabled && "input-icon-disabled", (0, _utils_1.pcn)(className, "icon"), disabled && (0, _utils_1.pcn)(className, "icon", "disabled")), onClick: () => {
|
|
237
|
+
setInputShowValue("");
|
|
238
|
+
inputHandler.setValue("");
|
|
239
|
+
onChange?.("");
|
|
240
|
+
}, children: (0, jsx_runtime_1.jsx)(react_fontawesome_1.FontAwesomeIcon, { icon: free_solid_svg_icons_1.faTimes }) })), (0, jsx_runtime_1.jsx)("label", { htmlFor: randomId, className: (0, _utils_1.cn)("input-icon", "input-icon-right", "select-icon-dropdown", disabled && "input-icon-disabled", (0, _utils_1.pcn)(className, "icon"), disabled && (0, _utils_1.pcn)(className, "icon", "disabled")), children: (0, jsx_runtime_1.jsx)(react_fontawesome_1.FontAwesomeIcon, { icon: free_solid_svg_icons_1.faChevronDown }) })] }), !!dataOptions?.length && showOption && !loadingOption && !!filteredOptions?.length && ((0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)("ul", { className: (0, _utils_1.cn)("input-suggest-container scroll-sm", inputHandler.focus && "input-suggest-container-active", (0, _utils_1.pcn)(className, "suggest")), children: (newOption ? [newOption, ...filteredOptions] : filteredOptions).map((option, key) => {
|
|
241
|
+
const selected = !!((typeof inputHandler.value == "string" || typeof inputHandler.value == "number") && inputHandler.value == option.value) ||
|
|
242
|
+
(Array.isArray(inputHandler.value) && Array().concat(inputHandler.value).find((val) => val == option.value));
|
|
243
|
+
return ((0, jsx_runtime_1.jsxs)("li", { className: (0, _utils_1.cn)("input-suggest", (key == activeOption || selected) && "input-suggest-active", (0, _utils_1.pcn)(className, "suggest-item"), (key == activeOption || selected) && (0, _utils_1.pcn)(className, "suggest-item", "active")), onMouseDown: () => {
|
|
244
|
+
setKeydown(true);
|
|
245
|
+
setTimeout(() => inputHandler.setFocus(true), 110);
|
|
246
|
+
}, onMouseUp: () => {
|
|
247
|
+
setKeydown(false);
|
|
248
|
+
setActiveOption(key);
|
|
249
|
+
setFilteredOptions([]);
|
|
250
|
+
setShowOption(false);
|
|
251
|
+
if (!multiple) {
|
|
252
|
+
setInputShowValue(option.label);
|
|
253
|
+
serverSearchable && setKeyword(option.label);
|
|
254
|
+
inputHandler.setValue(option.value);
|
|
255
|
+
onChange?.(option.value, option);
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
const values = Array.isArray(inputHandler.value)
|
|
259
|
+
? Array().concat(inputHandler.value).filter((val) => val != option.value)
|
|
260
|
+
: [];
|
|
261
|
+
setInputShowValue("");
|
|
262
|
+
serverSearchable && setKeyword("");
|
|
263
|
+
if (Array.isArray(inputHandler.value) && Array().concat(inputHandler.value).find((val) => val == option.value)) {
|
|
264
|
+
inputHandler.setValue(values);
|
|
265
|
+
onChange?.(values);
|
|
266
|
+
}
|
|
267
|
+
else {
|
|
268
|
+
inputHandler.setValue([...Array().concat(values), option.value]);
|
|
269
|
+
onChange?.([...Array().concat(values), option.value]);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
setTimeout(() => inputHandler.setFocus(false), 120);
|
|
273
|
+
}, children: [selected && ((0, jsx_runtime_1.jsx)(react_fontawesome_1.FontAwesomeIcon, { icon: free_solid_svg_icons_1.faCheck, className: "select-suggest-check" })), option.label] }, key));
|
|
274
|
+
}) }) })), invalidMessage && ((0, jsx_runtime_1.jsx)("small", { className: (0, _utils_1.cn)("input-error-message", (0, _utils_1.pcn)(className, "error")), children: invalidMessage }))] }) }));
|
|
275
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
export type BottomSheetProps = {
|
|
3
|
+
show: boolean;
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
size?: string | number;
|
|
7
|
+
maxSize?: string | number;
|
|
8
|
+
footer?: ReactNode;
|
|
9
|
+
/** Use custom class with: "backdrop::", "footer::". */
|
|
10
|
+
className?: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const BottomSheetComponent: import("react").ComponentType<BottomSheetProps>;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.BottomSheetComponent = void 0;
|
|
8
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const react_1 = require("react");
|
|
10
|
+
const dynamic_1 = __importDefault(require("next/dynamic"));
|
|
11
|
+
const _utils_1 = require("@utils");
|
|
12
|
+
function sizeToPx(value) {
|
|
13
|
+
if (typeof window === "undefined")
|
|
14
|
+
return 0;
|
|
15
|
+
if (value === undefined || value === null)
|
|
16
|
+
return 0;
|
|
17
|
+
if (typeof value === "number")
|
|
18
|
+
return value;
|
|
19
|
+
const v = value.trim();
|
|
20
|
+
if (v.endsWith("vh")) {
|
|
21
|
+
const n = parseFloat(v.replace("vh", ""));
|
|
22
|
+
return (n / 100) * window.innerHeight;
|
|
23
|
+
}
|
|
24
|
+
if (v.endsWith("px")) {
|
|
25
|
+
return parseFloat(v.replace("px", ""));
|
|
26
|
+
}
|
|
27
|
+
return parseFloat(v) || 0;
|
|
28
|
+
}
|
|
29
|
+
const BottomSheet = ({ show, children, onClose, size = 500, maxSize, footer, className = "", }) => {
|
|
30
|
+
const scrollRef = (0, react_1.useRef)(null);
|
|
31
|
+
const sheetRef = (0, react_1.useRef)(null);
|
|
32
|
+
const startY = (0, react_1.useRef)(0);
|
|
33
|
+
const lastY = (0, react_1.useRef)(0);
|
|
34
|
+
const dragging = (0, react_1.useRef)(false);
|
|
35
|
+
const [offset, setOffset] = (0, react_1.useState)(0);
|
|
36
|
+
const [isExpanded, setIsExpanded] = (0, react_1.useState)(false);
|
|
37
|
+
const [scrollLocked, setScrollLocked] = (0, react_1.useState)(false);
|
|
38
|
+
const [contentScrollable, setContentScrollable] = (0, react_1.useState)(false);
|
|
39
|
+
const realMaxSize = maxSize ?? size;
|
|
40
|
+
const clamp = (v) => {
|
|
41
|
+
const max = window.innerHeight;
|
|
42
|
+
return Math.max(-200, Math.min(v, max));
|
|
43
|
+
};
|
|
44
|
+
const animateTo = (target, onFinish) => {
|
|
45
|
+
lastY.current = target;
|
|
46
|
+
setOffset(clamp(target));
|
|
47
|
+
onFinish?.();
|
|
48
|
+
};
|
|
49
|
+
(0, react_1.useEffect)(() => {
|
|
50
|
+
if (show) {
|
|
51
|
+
lastY.current = 0;
|
|
52
|
+
setOffset(0);
|
|
53
|
+
setIsExpanded(false);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const t = setTimeout(() => {
|
|
57
|
+
lastY.current = 0;
|
|
58
|
+
setOffset(0);
|
|
59
|
+
setIsExpanded(false);
|
|
60
|
+
}, 250);
|
|
61
|
+
return () => clearTimeout(t);
|
|
62
|
+
}
|
|
63
|
+
}, [show]);
|
|
64
|
+
const onStart = (clientY) => {
|
|
65
|
+
const sc = scrollRef.current;
|
|
66
|
+
if (sc && sc.scrollTop < 0) {
|
|
67
|
+
setScrollLocked(true);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
setScrollLocked(false);
|
|
71
|
+
dragging.current = true;
|
|
72
|
+
startY.current = clientY;
|
|
73
|
+
lastY.current = offset;
|
|
74
|
+
};
|
|
75
|
+
const onMove = (clientY) => {
|
|
76
|
+
if (scrollLocked)
|
|
77
|
+
return;
|
|
78
|
+
if (!dragging.current)
|
|
79
|
+
return;
|
|
80
|
+
const diff = clientY - startY.current;
|
|
81
|
+
setOffset(clamp(lastY.current + diff));
|
|
82
|
+
};
|
|
83
|
+
const onEnd = () => {
|
|
84
|
+
if (scrollLocked) {
|
|
85
|
+
setScrollLocked(false);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (!dragging.current)
|
|
89
|
+
return;
|
|
90
|
+
dragging.current = false;
|
|
91
|
+
const current = offset;
|
|
92
|
+
const thresholdDown = 120;
|
|
93
|
+
const thresholdUp = -40;
|
|
94
|
+
if (!isExpanded && current < thresholdUp && maxSize !== undefined) {
|
|
95
|
+
setIsExpanded(true);
|
|
96
|
+
animateTo(0);
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (isExpanded && current > thresholdDown) {
|
|
100
|
+
setIsExpanded(false);
|
|
101
|
+
animateTo(0);
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (!isExpanded && current > thresholdDown) {
|
|
105
|
+
animateTo(window.innerHeight, () => {
|
|
106
|
+
onClose();
|
|
107
|
+
lastY.current = 0;
|
|
108
|
+
setOffset(0);
|
|
109
|
+
});
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
animateTo(0);
|
|
113
|
+
};
|
|
114
|
+
const collapsedPx = sizeToPx(size);
|
|
115
|
+
const expandedPx = sizeToPx(realMaxSize);
|
|
116
|
+
const topPx = isExpanded ? window.innerHeight - expandedPx : window.innerHeight - collapsedPx;
|
|
117
|
+
const bindTouch = {
|
|
118
|
+
onTouchStart: (e) => onStart(e.touches[0].clientY),
|
|
119
|
+
onTouchMove: (e) => onMove(e.touches[0].clientY),
|
|
120
|
+
onTouchEnd: () => onEnd(),
|
|
121
|
+
};
|
|
122
|
+
const bindMouse = {
|
|
123
|
+
onMouseDown: (e) => onStart(e.clientY),
|
|
124
|
+
onMouseMove: (e) => dragging.current && onMove(e.clientY),
|
|
125
|
+
onMouseUp: () => onEnd(),
|
|
126
|
+
onMouseLeave: () => onEnd(),
|
|
127
|
+
};
|
|
128
|
+
(0, react_1.useEffect)(() => {
|
|
129
|
+
const sc = scrollRef.current;
|
|
130
|
+
if (!sc)
|
|
131
|
+
return;
|
|
132
|
+
const canScroll = sc.scrollHeight > sc.clientHeight;
|
|
133
|
+
setContentScrollable(canScroll);
|
|
134
|
+
}, [show, size, maxSize]);
|
|
135
|
+
(0, react_1.useEffect)(() => {
|
|
136
|
+
if (show) {
|
|
137
|
+
history.pushState({ bottomsheet: true }, "");
|
|
138
|
+
}
|
|
139
|
+
}, [show]);
|
|
140
|
+
(0, react_1.useEffect)(() => {
|
|
141
|
+
const onPopState = (event) => {
|
|
142
|
+
if (show) {
|
|
143
|
+
event.preventDefault();
|
|
144
|
+
onClose();
|
|
145
|
+
history.pushState({}, "");
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
window.addEventListener("popstate", onPopState);
|
|
149
|
+
return () => window.removeEventListener("popstate", onPopState);
|
|
150
|
+
}, [show, onClose]);
|
|
151
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)("modal-backdrop", !show && "translate-y-full", (0, _utils_1.pcn)(className, "backdrop")), onClick: onClose }), (0, jsx_runtime_1.jsx)("div", { ref: sheetRef, className: "bottom-sheet", style: {
|
|
152
|
+
top: show ? `${topPx}px` : "150vh",
|
|
153
|
+
transform: `translateY(${offset}px)`,
|
|
154
|
+
touchAction: "none",
|
|
155
|
+
}, ...bindTouch, ...bindMouse, children: (0, jsx_runtime_1.jsxs)("div", { className: "bottom-sheet-container", children: [(0, jsx_runtime_1.jsx)("div", { className: "bottom-sheet-handle-wrapper", children: (0, jsx_runtime_1.jsx)("div", { className: "bottom-sheet-handle" }) }), (0, jsx_runtime_1.jsx)("div", { ref: scrollRef, className: "overflow-y-auto", style: {
|
|
156
|
+
height: isExpanded ? realMaxSize : size,
|
|
157
|
+
touchAction: contentScrollable ? "auto" : "none",
|
|
158
|
+
overscrollBehaviorY: "contain",
|
|
159
|
+
}, children: children })] }) }), show && footer && ((0, jsx_runtime_1.jsx)("div", { className: "bottom-sheet-footer", children: footer }))] }));
|
|
160
|
+
};
|
|
161
|
+
exports.BottomSheetComponent = (0, dynamic_1.default)(() => Promise.resolve(BottomSheet), { ssr: false });
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
export interface FloatingPageProps {
|
|
3
|
+
show: boolean;
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
title?: string | ReactNode;
|
|
6
|
+
children?: any;
|
|
7
|
+
tip?: string | ReactNode;
|
|
8
|
+
footer?: string | ReactNode;
|
|
9
|
+
/** Use custom class with: "backdrop::", "header::", "footer::". */
|
|
10
|
+
className?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function FloatingPageComponent({ show, onClose, title, children, tip, footer, className, }: FloatingPageProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.FloatingPageComponent = FloatingPageComponent;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const free_solid_svg_icons_1 = require("@fortawesome/free-solid-svg-icons");
|
|
8
|
+
const _components_1 = require("@components");
|
|
9
|
+
const _utils_1 = require("@utils");
|
|
10
|
+
;
|
|
11
|
+
function FloatingPageComponent({ show, onClose, title, children, tip, footer, className = "", }) {
|
|
12
|
+
(0, react_1.useEffect)(() => {
|
|
13
|
+
if (show) {
|
|
14
|
+
document.getElementsByTagName("body")[0].style.overflow = "hidden";
|
|
15
|
+
_utils_1.shortcut.register("escape", () => {
|
|
16
|
+
onClose?.();
|
|
17
|
+
}, "Kembali");
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
document.getElementsByTagName("body")[0].style.removeProperty("overflow");
|
|
21
|
+
}
|
|
22
|
+
return () => {
|
|
23
|
+
_utils_1.shortcut.unregister("escape");
|
|
24
|
+
};
|
|
25
|
+
}, [show]);
|
|
26
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)("modal-backdrop", !show && "opacity-0 scale-0 -translate-y-full", (0, _utils_1.pcn)(className, "backdrop")), onClick: () => onClose() }), (0, jsx_runtime_1.jsxs)("div", { className: (0, _utils_1.cn)("floating-page", !show && "top-[200vh] md:top-0 md:-right-[200vw]", (0, _utils_1.pcn)(className, "base")), children: [(0, jsx_runtime_1.jsxs)("div", { className: (0, _utils_1.cn)("modal-header", (0, _utils_1.pcn)(className, "header")), children: [title && ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("h6", { className: "modal-title", children: title }), tip && (0, jsx_runtime_1.jsx)("p", { className: "modal-tip", children: tip })] })), (0, jsx_runtime_1.jsx)(_components_1.ButtonComponent, { icon: free_solid_svg_icons_1.faTimes, variant: "simple", paint: "danger", onClick: () => onClose() })] }), show && children, footer && ((0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)("modal-footer absolute bottom-0 w-full", (0, _utils_1.pcn)(className, "footer")), children: show && footer }))] })] }));
|
|
27
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
export interface ModalProps {
|
|
3
|
+
show: boolean;
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
title?: string | ReactNode;
|
|
6
|
+
children?: any;
|
|
7
|
+
tip?: string | ReactNode;
|
|
8
|
+
footer?: string | ReactNode;
|
|
9
|
+
/** Use custom class with: "backdrop::", "header::", "footer::". */
|
|
10
|
+
className?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function ModalComponent({ show, onClose, title, children, tip, footer, className, }: ModalProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ModalComponent = ModalComponent;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const free_solid_svg_icons_1 = require("@fortawesome/free-solid-svg-icons");
|
|
8
|
+
const _utils_1 = require("@utils");
|
|
9
|
+
const _components_1 = require("@components");
|
|
10
|
+
;
|
|
11
|
+
function ModalComponent({ show, onClose, title, children, tip, footer, className = "", }) {
|
|
12
|
+
(0, react_1.useEffect)(() => {
|
|
13
|
+
if (show) {
|
|
14
|
+
document.getElementsByTagName("body")[0].style.overflow = "hidden";
|
|
15
|
+
_utils_1.shortcut.register("escape", () => {
|
|
16
|
+
onClose?.();
|
|
17
|
+
}, "Kembali");
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
document.getElementsByTagName("body")[0].style.removeProperty("overflow");
|
|
21
|
+
}
|
|
22
|
+
return () => {
|
|
23
|
+
_utils_1.shortcut.unregister("escape");
|
|
24
|
+
};
|
|
25
|
+
}, [show]);
|
|
26
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)("modal-backdrop", !show && "opacity-0 scale-0 -translate-y-full", (0, _utils_1.pcn)(className, "backdrop")), onClick: () => onClose() }), (0, jsx_runtime_1.jsxs)("div", { className: (0, _utils_1.cn)("modal", !show && "-translate-y-full opacity-0 scale-y-0", (0, _utils_1.pcn)(className, "base")), children: [title && ((0, jsx_runtime_1.jsxs)("div", { className: (0, _utils_1.cn)("modal-header", (0, _utils_1.pcn)(className, "header")), children: [(0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)("h6", { className: "modal-title", children: title }), tip && (0, jsx_runtime_1.jsx)("p", { className: "modal-tip", children: tip })] }), (0, jsx_runtime_1.jsx)(_components_1.ButtonComponent, { icon: free_solid_svg_icons_1.faTimes, variant: "simple", paint: "danger", onClick: () => onClose() })] })), show && children, footer && ((0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)("modal-footer", (0, _utils_1.pcn)(className, "footer")), children: show && footer }))] })] }));
|
|
27
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { ApiType } from "@utils";
|
|
3
|
+
import { ButtonProps } from "@components";
|
|
4
|
+
type SubmitIDB = {
|
|
5
|
+
idb: {
|
|
6
|
+
store: string;
|
|
7
|
+
id: string | number;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
export interface ModalConfirmProps {
|
|
11
|
+
show: boolean;
|
|
12
|
+
onClose: () => void;
|
|
13
|
+
title?: string | ReactNode;
|
|
14
|
+
children?: any;
|
|
15
|
+
icon?: any;
|
|
16
|
+
footer?: string | ReactNode;
|
|
17
|
+
submitControl?: ButtonProps & {
|
|
18
|
+
onSubmit?: ApiType | SubmitIDB | (() => void);
|
|
19
|
+
onSuccess?: () => void;
|
|
20
|
+
onError?: () => void;
|
|
21
|
+
};
|
|
22
|
+
/** Use custom class with: "backdrop::", "header::", "footer::". */
|
|
23
|
+
className?: string;
|
|
24
|
+
}
|
|
25
|
+
export declare function ModalConfirmComponent({ show, title, children, icon, footer, submitControl, onClose, className, }: ModalConfirmProps): import("react").JSX.Element;
|
|
26
|
+
export {};
|