@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,25 @@
|
|
|
1
|
+
import { ValidationRules } from "@utils";
|
|
2
|
+
export interface ValueMapProps {
|
|
3
|
+
lat: number | null;
|
|
4
|
+
lng: number | null;
|
|
5
|
+
address?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface InputMapProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "onChange"> {
|
|
8
|
+
label?: string;
|
|
9
|
+
tip?: string | React.ReactNode;
|
|
10
|
+
leftIcon?: any;
|
|
11
|
+
rightIcon?: any;
|
|
12
|
+
value?: any;
|
|
13
|
+
invalid?: string;
|
|
14
|
+
validations?: ValidationRules;
|
|
15
|
+
onChange?: (value: any) => any;
|
|
16
|
+
register?: (name: string, validations?: ValidationRules) => void;
|
|
17
|
+
unregister?: (name: string) => void;
|
|
18
|
+
className?: string;
|
|
19
|
+
}
|
|
20
|
+
export declare function InputMapComponent({ label, tip, leftIcon, rightIcon, value, invalid, validations, register, unregister, onChange, className, ...props }: InputMapProps): import("react").JSX.Element;
|
|
21
|
+
export interface MapPickerProps {
|
|
22
|
+
value?: any;
|
|
23
|
+
onChange?: (value: any) => any;
|
|
24
|
+
}
|
|
25
|
+
export declare const InputMapPickerComponent: React.FC<MapPickerProps>;
|
|
@@ -0,0 +1,101 @@
|
|
|
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.InputMapPickerComponent = void 0;
|
|
8
|
+
exports.InputMapComponent = InputMapComponent;
|
|
9
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
10
|
+
const react_1 = require("react");
|
|
11
|
+
const axios_1 = __importDefault(require("axios"));
|
|
12
|
+
const react_fontawesome_1 = require("@fortawesome/react-fontawesome");
|
|
13
|
+
const free_solid_svg_icons_1 = require("@fortawesome/free-solid-svg-icons");
|
|
14
|
+
const api_1 = require("@react-google-maps/api");
|
|
15
|
+
const _utils_1 = require("@utils");
|
|
16
|
+
const _components_1 = require("@components");
|
|
17
|
+
function InputMapComponent({ label, tip, leftIcon, rightIcon, value, invalid, validations, register, unregister, onChange, className = "", ...props }) {
|
|
18
|
+
const { isSm } = (0, _utils_1.useResponsive)();
|
|
19
|
+
// =========================>
|
|
20
|
+
// ## Invalid handler
|
|
21
|
+
// =========================>
|
|
22
|
+
const inputHandler = (0, _utils_1.useInputHandler)(props.name, value, validations, register, unregister, false);
|
|
23
|
+
const randomId = (0, _utils_1.useInputRandomId)();
|
|
24
|
+
// =========================>
|
|
25
|
+
// ## Invalid handler
|
|
26
|
+
// =========================>
|
|
27
|
+
const [invalidMessage] = (0, _utils_1.useValidation)(inputHandler.value, validations, invalid, inputHandler.idle);
|
|
28
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)("div", { className: "input-container", children: [label && ((0, jsx_runtime_1.jsxs)("label", { htmlFor: randomId, className: (0, _utils_1.cn)("input-label", props.disabled && "input-label-disabled", inputHandler.focus && "input-label-focus", !!invalidMessage && "input-label-error", (0, _utils_1.pcn)(className, "label")), 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", props.disabled && "input-tip-disabled", (0, _utils_1.pcn)(className, "tip")), children: tip })), (0, jsx_runtime_1.jsx)(_components_1.OutsideClickComponent, { onOutsideClick: !isSm ? () => inputHandler.setFocus(false) : undefined, children: (0, jsx_runtime_1.jsxs)("div", { className: "relative", children: [(0, jsx_runtime_1.jsx)("input", { ...props, id: randomId, className: (0, _utils_1.cn)("input", leftIcon && "input-with-left-icon", rightIcon && "input-with-right-icon", (0, _utils_1.pcn)(className, "input"), !!invalidMessage && "input-error"), value: inputHandler.value?.address || "", readOnly: true, onFocus: (e) => {
|
|
29
|
+
props.onFocus?.(e);
|
|
30
|
+
inputHandler.setFocus(true);
|
|
31
|
+
inputHandler.setIdle(false);
|
|
32
|
+
}, autoComplete: "off" }), leftIcon && ((0, jsx_runtime_1.jsx)(react_fontawesome_1.FontAwesomeIcon, { className: (0, _utils_1.cn)("input-icon", "input-icon-left", props.disabled && "input-icon-disabled", inputHandler.focus && "input-icon-focus", (0, _utils_1.pcn)(className, "icon")), icon: leftIcon })), rightIcon && ((0, jsx_runtime_1.jsx)(react_fontawesome_1.FontAwesomeIcon, { className: (0, _utils_1.cn)("input-icon", "input-icon-right", props.disabled && "input-icon-disabled", inputHandler.focus && "input-icon-focus", (0, _utils_1.pcn)(className, "icon")), icon: rightIcon })), !isSm && inputHandler.focus && ((0, jsx_runtime_1.jsx)("div", { className: "input-map-suggest-container", style: { height: 300 }, children: (0, jsx_runtime_1.jsx)(exports.InputMapPickerComponent, { value: inputHandler.value, onChange: (e) => {
|
|
33
|
+
inputHandler.setValue(e);
|
|
34
|
+
onChange?.(e);
|
|
35
|
+
} }) }))] }) }), invalidMessage && ((0, jsx_runtime_1.jsx)("small", { className: (0, _utils_1.cn)("input-error-message", (0, _utils_1.pcn)(className, "error")), children: invalidMessage }))] }), isSm && ((0, jsx_runtime_1.jsx)(_components_1.BottomSheetComponent, { show: inputHandler.focus, onClose: () => inputHandler.setFocus(false), size: 450, footer: (0, jsx_runtime_1.jsx)("div", { className: "p-4", children: (0, jsx_runtime_1.jsx)(_components_1.ButtonComponent, { label: "Selesai", variant: "outline", onClick: () => inputHandler.setFocus(false), block: true }) }), children: (0, jsx_runtime_1.jsx)("div", { className: "p-4", children: (0, jsx_runtime_1.jsx)(exports.InputMapPickerComponent, { onChange: (e) => {
|
|
36
|
+
inputHandler.setValue(e);
|
|
37
|
+
onChange?.(e);
|
|
38
|
+
} }) }) }))] }));
|
|
39
|
+
}
|
|
40
|
+
const InputMapPickerComponent = ({ onChange, value }) => {
|
|
41
|
+
const mapRef = (0, react_1.useRef)(null);
|
|
42
|
+
const [addressLoading, setAddressLoading] = (0, react_1.useState)(false);
|
|
43
|
+
const [drag, setDrag] = (0, react_1.useState)(false);
|
|
44
|
+
// =========================>
|
|
45
|
+
// ## Map Events
|
|
46
|
+
// =========================>
|
|
47
|
+
const setCurrentPosition = () => {
|
|
48
|
+
if (navigator.geolocation) {
|
|
49
|
+
navigator.geolocation.getCurrentPosition((pos) => {
|
|
50
|
+
const newPos = {
|
|
51
|
+
lat: pos.coords.latitude,
|
|
52
|
+
lng: pos.coords.longitude,
|
|
53
|
+
address: "",
|
|
54
|
+
};
|
|
55
|
+
onChange?.(newPos);
|
|
56
|
+
mapRef.current?.panTo(new google.maps.LatLng(newPos.lat, newPos.lng));
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const handleDragEnd = (0, react_1.useCallback)(() => {
|
|
61
|
+
if (mapRef.current) {
|
|
62
|
+
const center = mapRef.current.getCenter();
|
|
63
|
+
if (center) {
|
|
64
|
+
onChange?.({
|
|
65
|
+
lat: center.lat(),
|
|
66
|
+
lng: center.lng(),
|
|
67
|
+
address: "",
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
setDrag(false);
|
|
71
|
+
}
|
|
72
|
+
}, []);
|
|
73
|
+
// =========================>
|
|
74
|
+
// ## Reverse Geocode
|
|
75
|
+
// =========================>
|
|
76
|
+
(0, react_1.useEffect)(() => {
|
|
77
|
+
if (value?.lat && value?.lng) {
|
|
78
|
+
setAddressLoading(true);
|
|
79
|
+
onChange?.((prev) => ({ ...prev, address: "" }));
|
|
80
|
+
axios_1.default.get(`https://api.geoapify.com/v1/geocode/reverse?lat=${value?.lat}&lon=${value?.lng}&apiKey=${process.env.NEXT_PUBLIC_GEOAPIFY_KEY}`)
|
|
81
|
+
.then((res) => {
|
|
82
|
+
if (res.status === 200 && !res.data.error) {
|
|
83
|
+
const data = res.data.features?.at(0)?.properties;
|
|
84
|
+
const address = (data?.address_line1 || "") + " " + (data?.address_line2 || "");
|
|
85
|
+
onChange?.((prev) => ({ ...prev, address }));
|
|
86
|
+
onChange?.({ ...value, address });
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
.finally(() => setAddressLoading(false));
|
|
90
|
+
}
|
|
91
|
+
}, [value?.lat, value?.lng]);
|
|
92
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "relative w-full", children: [(0, jsx_runtime_1.jsx)(api_1.LoadScript, { googleMapsApiKey: process.env.NEXT_PUBLIC_MAP_KEY || "", children: (0, jsx_runtime_1.jsx)(api_1.GoogleMap, { mapContainerStyle: { width: "100%", height: "100%" }, center: {
|
|
93
|
+
lat: value?.lat || -6.208,
|
|
94
|
+
lng: value?.lng || 106.689,
|
|
95
|
+
}, zoom: 18, options: {
|
|
96
|
+
streetViewControl: false,
|
|
97
|
+
mapTypeControl: false,
|
|
98
|
+
fullscreenControl: false,
|
|
99
|
+
}, onLoad: (map) => { mapRef.current = map; }, onDrag: () => setDrag(true), onDragEnd: handleDragEnd }) }), (0, jsx_runtime_1.jsx)("div", { className: "absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 pointer-events-none", children: (0, jsx_runtime_1.jsx)(react_fontawesome_1.FontAwesomeIcon, { icon: free_solid_svg_icons_1.faLocationDot, className: (0, _utils_1.cn)("input-map-marker", drag && "input-map-marker-drag") }) }), (0, jsx_runtime_1.jsx)("div", { className: "input-map-badge-left", children: addressLoading && !value?.address ? ((0, jsx_runtime_1.jsx)("div", { className: "py-4 w-[200px]" })) : ((0, jsx_runtime_1.jsx)("span", { className: "text-sm", children: value?.address })) }), (0, jsx_runtime_1.jsx)("div", { className: "input-map-badge-right", onClick: () => setCurrentPosition(), children: (0, jsx_runtime_1.jsx)(react_fontawesome_1.FontAwesomeIcon, { icon: free_solid_svg_icons_1.faLocationCrosshairs, className: "text-lg" }) })] }));
|
|
100
|
+
};
|
|
101
|
+
exports.InputMapPickerComponent = InputMapPickerComponent;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import React, { InputHTMLAttributes, ReactNode } from "react";
|
|
2
|
+
import { ValidationRules } from "@utils";
|
|
3
|
+
export interface InputNumberProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "onChange"> {
|
|
4
|
+
label?: string;
|
|
5
|
+
tip?: string | ReactNode;
|
|
6
|
+
leftIcon?: any;
|
|
7
|
+
rightIcon?: any;
|
|
8
|
+
value?: number;
|
|
9
|
+
invalid?: string;
|
|
10
|
+
validations?: ValidationRules;
|
|
11
|
+
min?: number;
|
|
12
|
+
max?: number;
|
|
13
|
+
onChange?: (value: number) => any;
|
|
14
|
+
register?: (name: string, validations?: ValidationRules) => void;
|
|
15
|
+
unregister?: (name: string) => void;
|
|
16
|
+
/** Use custom class with: "label::", "tip::", "error::", "icon::", "suggest::", "suggest-item::". */
|
|
17
|
+
className?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare function InputNumberComponent({ label, tip, leftIcon, rightIcon, value, invalid, validations, min, max, onChange, register, unregister, className, ...props }: InputNumberProps): React.JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.InputNumberComponent = InputNumberComponent;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_fontawesome_1 = require("@fortawesome/react-fontawesome");
|
|
7
|
+
const free_solid_svg_icons_1 = require("@fortawesome/free-solid-svg-icons");
|
|
8
|
+
const _utils_1 = require("@utils");
|
|
9
|
+
function InputNumberComponent({ label, tip, leftIcon, rightIcon, value, invalid, validations, min, max, onChange, register, unregister, className = "", ...props }) {
|
|
10
|
+
// =========================>
|
|
11
|
+
// ## Initial
|
|
12
|
+
// =========================>
|
|
13
|
+
const inputHandler = (0, _utils_1.useInputHandler)(props.name, value, validations, register, unregister, false);
|
|
14
|
+
const randomId = (0, _utils_1.useInputRandomId)();
|
|
15
|
+
// =========================>
|
|
16
|
+
// ## Invalid handler
|
|
17
|
+
// =========================>
|
|
18
|
+
const [invalidMessage] = (0, _utils_1.useValidation)(inputHandler.value, validations, invalid, inputHandler.idle);
|
|
19
|
+
// =========================>
|
|
20
|
+
// ## Change value handler
|
|
21
|
+
// =========================>
|
|
22
|
+
const handleInputChange = (e) => {
|
|
23
|
+
const newValue = e.target.value;
|
|
24
|
+
const regex = /^-?\d*\.?\d*$/;
|
|
25
|
+
if (regex.test(newValue)) {
|
|
26
|
+
inputHandler.setValue(newValue);
|
|
27
|
+
inputHandler.setIdle(false);
|
|
28
|
+
onChange?.(Number(newValue));
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
const handleBlur = (e) => {
|
|
32
|
+
props.onBlur?.(e);
|
|
33
|
+
setTimeout(() => inputHandler.setFocus(false), 100);
|
|
34
|
+
};
|
|
35
|
+
const handleFocus = (e) => {
|
|
36
|
+
props.onFocus?.(e);
|
|
37
|
+
inputHandler.setFocus(true);
|
|
38
|
+
};
|
|
39
|
+
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", props.disabled && "input-label-disabled", inputHandler.focus && "input-label-focus", !!invalidMessage && "input-label-error", (0, _utils_1.pcn)(className, "label"), props.disabled && (0, _utils_1.pcn)(className, "label", "disabled"), inputHandler.focus && (0, _utils_1.pcn)(className, "label", "focus"), !!invalidMessage && (0, _utils_1.pcn)(className, "label", "focus")), 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", props.disabled && "input-tip-disabled", (0, _utils_1.pcn)(className, "tip"), props.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", { ...props, id: randomId, className: (0, _utils_1.cn)("input", leftIcon && "input-with-left-icon", rightIcon && "input-with-right-icon", (0, _utils_1.pcn)(className, "input"), !!invalidMessage && "input-error", !!invalidMessage && (0, _utils_1.pcn)(className, "input", "error")), value: inputHandler.value, onChange: handleInputChange, onFocus: handleFocus, onBlur: handleBlur, autoComplete: "off", min: min, max: max }), leftIcon && ((0, jsx_runtime_1.jsx)(react_fontawesome_1.FontAwesomeIcon, { className: (0, _utils_1.cn)("input-icon", "input-icon-left", props.disabled && "input-icon-disabled", inputHandler.focus && "input-icon-focus", (0, _utils_1.pcn)(className, "icon"), props.disabled && (0, _utils_1.pcn)(className, "icon", "disabled"), inputHandler.focus && (0, _utils_1.pcn)(className, "icon", "focus")), icon: leftIcon })), (0, jsx_runtime_1.jsx)("label", { htmlFor: randomId, className: (0, _utils_1.cn)("input-icon", "input-icon-right", props.disabled && "input-icon-disabled", inputHandler.focus && "input-icon-focus", (0, _utils_1.pcn)(className, "icon"), props.disabled && (0, _utils_1.pcn)(className, "icon", "disabled"), inputHandler.focus && (0, _utils_1.pcn)(className, "icon", "focus")), children: (0, jsx_runtime_1.jsxs)("div", { className: "input-number-sort-container", children: [(0, jsx_runtime_1.jsx)(react_fontawesome_1.FontAwesomeIcon, { className: "input-number-sort-up", icon: free_solid_svg_icons_1.faSortUp, onClick: () => inputHandler.setValue(String(Number(inputHandler.value) + 1)) }), (0, jsx_runtime_1.jsx)(react_fontawesome_1.FontAwesomeIcon, { className: "input-number-sort-down", icon: free_solid_svg_icons_1.faSortDown, onClick: () => inputHandler.setValue(String(Number(inputHandler.value) - 1)) })] }) })] }), invalidMessage && ((0, jsx_runtime_1.jsx)("small", { className: (0, _utils_1.cn)("input-error-message", (0, _utils_1.pcn)(className, "error")), children: invalidMessage }))] }) }));
|
|
40
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { FC, ReactNode } from "react";
|
|
2
|
+
export interface InputOtpProps {
|
|
3
|
+
label?: string;
|
|
4
|
+
tip?: string | ReactNode;
|
|
5
|
+
name: string;
|
|
6
|
+
disabled?: boolean;
|
|
7
|
+
value?: string;
|
|
8
|
+
invalid?: string;
|
|
9
|
+
length?: number;
|
|
10
|
+
onChange?: (value: string) => any;
|
|
11
|
+
/** Use custom class with: "label::", "tip::", "error::". */
|
|
12
|
+
className?: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const InputOtpComponent: FC<InputOtpProps>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.InputOtpComponent = void 0;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const _utils_1 = require("@utils");
|
|
8
|
+
const InputOtpComponent = ({ label, tip, name, disabled, value, invalid, length = 6, onChange, className = "", }) => {
|
|
9
|
+
const [isFocus, setIsFocus] = (0, react_1.useState)(false);
|
|
10
|
+
const inputsRef = (0, react_1.useRef)([]);
|
|
11
|
+
const [otp, setOtp] = (0, react_1.useState)((value || "").split("").concat(Array(length).fill("")).slice(0, length));
|
|
12
|
+
(0, react_1.useEffect)(() => {
|
|
13
|
+
const handleFocusChange = () => {
|
|
14
|
+
const anyFocused = inputsRef.current.some((input) => input === document.activeElement);
|
|
15
|
+
setIsFocus(anyFocused);
|
|
16
|
+
};
|
|
17
|
+
window.addEventListener("focusin", handleFocusChange);
|
|
18
|
+
window.addEventListener("focusout", handleFocusChange);
|
|
19
|
+
return () => {
|
|
20
|
+
window.removeEventListener("focusin", handleFocusChange);
|
|
21
|
+
window.removeEventListener("focusout", handleFocusChange);
|
|
22
|
+
};
|
|
23
|
+
}, []);
|
|
24
|
+
const emitChange = (newOtp) => {
|
|
25
|
+
const val = newOtp.join("");
|
|
26
|
+
onChange?.(val);
|
|
27
|
+
};
|
|
28
|
+
const handleChange = (val, index) => {
|
|
29
|
+
if (!/^[0-9]?$/.test(val))
|
|
30
|
+
return;
|
|
31
|
+
const newOtp = [...otp];
|
|
32
|
+
newOtp[index] = val;
|
|
33
|
+
setOtp(newOtp);
|
|
34
|
+
emitChange(newOtp);
|
|
35
|
+
(val && index < length - 1) && inputsRef.current[index + 1]?.focus();
|
|
36
|
+
};
|
|
37
|
+
const handleKeyDown = (e, index) => {
|
|
38
|
+
if (e.key === "Backspace") {
|
|
39
|
+
if (otp[index]) {
|
|
40
|
+
const newOtp = [...otp];
|
|
41
|
+
newOtp[index] = "";
|
|
42
|
+
setOtp(newOtp);
|
|
43
|
+
emitChange(newOtp);
|
|
44
|
+
}
|
|
45
|
+
else if (index > 0) {
|
|
46
|
+
inputsRef.current[index - 1]?.focus();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
const handlePaste = (e) => {
|
|
51
|
+
e.preventDefault();
|
|
52
|
+
const paste = e.clipboardData.getData("text").trim();
|
|
53
|
+
if (!/^[0-9]+$/.test(paste))
|
|
54
|
+
return;
|
|
55
|
+
const pasted = paste.slice(0, length).split("");
|
|
56
|
+
const newOtp = [...otp];
|
|
57
|
+
for (let i = 0; i < pasted.length; i++)
|
|
58
|
+
newOtp[i] = pasted[i];
|
|
59
|
+
setOtp(newOtp);
|
|
60
|
+
emitChange(newOtp);
|
|
61
|
+
inputsRef.current[Math.min(pasted.length, length - 1)]?.focus();
|
|
62
|
+
};
|
|
63
|
+
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.jsx)("label", { className: (0, _utils_1.cn)("input-label", disabled && "input-label-disabled", isFocus && "input-label-focus", !!invalid && "input-label-error", (0, _utils_1.pcn)(className, "label"), disabled && (0, _utils_1.pcn)(className, "label", "disabled"), isFocus && (0, _utils_1.pcn)(className, "label", "focus"), !!invalid && (0, _utils_1.pcn)(className, "label", "error")), children: label }), 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: (0, _utils_1.cn)("input input-otp-box", isFocus && "input-otp-box-focus", !!invalid && "input-error"), children: [(0, jsx_runtime_1.jsx)("div", { className: "input-otp-digits-container", children: otp.map((digit, index) => ((0, jsx_runtime_1.jsx)("input", { type: "text", ref: (el) => { inputsRef.current[index] = el; }, inputMode: "numeric", maxLength: 1, value: digit, onChange: (e) => handleChange(e.target.value, index), onKeyDown: (e) => handleKeyDown(e, index), onPaste: handlePaste, className: "input-otp-cell", placeholder: "-", autoFocus: index === 0 }, index))) }), (0, jsx_runtime_1.jsx)("input", { type: "hidden", name: name, value: otp.join("") })] }), invalid && ((0, jsx_runtime_1.jsx)("small", { className: (0, _utils_1.cn)("input-error-message", (0, _utils_1.pcn)(className, "error")), children: invalid }))] }) }));
|
|
64
|
+
};
|
|
65
|
+
exports.InputOtpComponent = InputOtpComponent;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { InputHTMLAttributes, ReactNode } from "react";
|
|
2
|
+
import { ValidationRules } from "@utils";
|
|
3
|
+
export interface InputPasswordProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "onChange"> {
|
|
4
|
+
label?: string;
|
|
5
|
+
tip?: string | ReactNode;
|
|
6
|
+
leftIcon?: any;
|
|
7
|
+
rightIcon?: any;
|
|
8
|
+
value?: string;
|
|
9
|
+
invalid?: string;
|
|
10
|
+
validations?: ValidationRules;
|
|
11
|
+
onChange?: (value: string, confirm?: string) => any;
|
|
12
|
+
register?: (name: string, validations?: ValidationRules) => void;
|
|
13
|
+
unregister?: (name: string) => void;
|
|
14
|
+
/** Use custom class with: "label::", "tip::", "error::", "icon::". */
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function InputPasswordComponent({ label, tip, leftIcon, rightIcon, value, invalid, validations, register, unregister, onChange, className, ...props }: InputPasswordProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.InputPasswordComponent = InputPasswordComponent;
|
|
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 _utils_1 = require("@utils");
|
|
9
|
+
function InputPasswordComponent({ label, tip, leftIcon, rightIcon, value, invalid, validations, register, unregister, onChange, className = "", ...props }) {
|
|
10
|
+
const [password, setPassword] = (0, react_1.useState)("");
|
|
11
|
+
const [confirmPassword, setConfirmPassword] = (0, react_1.useState)("");
|
|
12
|
+
const [strength, setStrength] = (0, react_1.useState)("");
|
|
13
|
+
// =========================>
|
|
14
|
+
// ## Initial
|
|
15
|
+
// =========================>
|
|
16
|
+
const inputHandler = (0, _utils_1.useInputHandler)(props.name, value, validations, register, unregister, false);
|
|
17
|
+
const randomId = (0, _utils_1.useInputRandomId)();
|
|
18
|
+
const randomConfirmId = (0, _utils_1.useInputRandomId)();
|
|
19
|
+
// =========================>
|
|
20
|
+
// ## Invalid handler
|
|
21
|
+
// =========================>
|
|
22
|
+
const [invalidMessage] = (0, _utils_1.useValidation)(inputHandler.value, validations, invalid, inputHandler.idle);
|
|
23
|
+
// =========================>
|
|
24
|
+
// ## Password strength handler
|
|
25
|
+
// =========================>
|
|
26
|
+
(0, react_1.useEffect)(() => {
|
|
27
|
+
if (!password)
|
|
28
|
+
return setStrength("");
|
|
29
|
+
const hasLetter = /[A-Za-z]/.test(password);
|
|
30
|
+
const hasNumber = /\d/.test(password);
|
|
31
|
+
const hasSymbol = /[^A-Za-z0-9]/.test(password);
|
|
32
|
+
if (hasLetter && !hasNumber && !hasSymbol)
|
|
33
|
+
setStrength("weak");
|
|
34
|
+
else if (hasLetter && hasNumber && !hasSymbol)
|
|
35
|
+
setStrength("strong");
|
|
36
|
+
else if (hasLetter && hasNumber && hasSymbol)
|
|
37
|
+
setStrength("excellent");
|
|
38
|
+
else
|
|
39
|
+
setStrength("weak");
|
|
40
|
+
}, [password]);
|
|
41
|
+
// =========================>
|
|
42
|
+
// ## Check match confirm password
|
|
43
|
+
// =========================>
|
|
44
|
+
const isConfirmMismatch = confirmPassword && password !== confirmPassword;
|
|
45
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "input-container", children: [label && ((0, jsx_runtime_1.jsxs)("label", { htmlFor: randomId, className: (0, _utils_1.cn)("input-label", props.disabled && "input-label-disabled", inputHandler.focus && "input-label-focus", !!invalidMessage && "input-label-error", (0, _utils_1.pcn)(className, "label")), 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", props.disabled && "input-tip-disabled", (0, _utils_1.pcn)(className, "tip")), children: tip })), (0, jsx_runtime_1.jsxs)("div", { className: "relative", children: [(0, jsx_runtime_1.jsx)("input", { ...props, type: "password", id: randomId, className: (0, _utils_1.cn)("input", leftIcon && "input-with-left-icon", rightIcon && "input-with-right-icon", !!invalidMessage && "input-error", (0, _utils_1.pcn)(className, "base")), value: password, onChange: (e) => {
|
|
46
|
+
setPassword(e.target.value);
|
|
47
|
+
inputHandler.setIdle(false);
|
|
48
|
+
onChange?.(e.target.value, confirmPassword);
|
|
49
|
+
}, onFocus: (e) => {
|
|
50
|
+
props.onFocus?.(e);
|
|
51
|
+
inputHandler.setFocus(true);
|
|
52
|
+
}, onBlur: (e) => {
|
|
53
|
+
props.onBlur?.(e);
|
|
54
|
+
setTimeout(() => inputHandler.setFocus(false), 100);
|
|
55
|
+
}, autoComplete: "off" }), leftIcon && ((0, jsx_runtime_1.jsx)(react_fontawesome_1.FontAwesomeIcon, { className: (0, _utils_1.cn)("input-icon", "input-icon-left", (0, _utils_1.pcn)(className, "icon")), icon: leftIcon })), rightIcon && ((0, jsx_runtime_1.jsx)(react_fontawesome_1.FontAwesomeIcon, { className: (0, _utils_1.cn)("input-icon", "input-icon-right", (0, _utils_1.pcn)(className, "icon")), icon: rightIcon }))] }), invalidMessage && ((0, jsx_runtime_1.jsx)("small", { className: "input-error-message", children: invalidMessage })), strength && ((0, jsx_runtime_1.jsxs)("div", { className: "flex items-center gap-2 mt-1", children: [(0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)("password-strength-bar", strength === "weak" && "password-strength-bar-weak", strength === "strong" && "password-strength-bar-strong", strength === "excellent" && "password-strength-bar-excellent") }), (0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)("password-strength-bar", strength === "weak" && "password-strength-bar-empty", strength === "strong" && "password-strength-bar-strong", strength === "excellent" && "password-strength-bar-excellent") }), (0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)("password-strength-bar", (strength === "weak" || strength === "strong") && "password-strength-bar-empty", strength === "excellent" && "password-strength-bar-excellent") }), (0, jsx_runtime_1.jsx)("span", { className: (0, _utils_1.cn)("password-strength-text", strength === "weak" && "password-strength-text-weak", strength === "strong" && "password-strength-text-strong", strength === "excellent" && "password-strength-text-excellent"), children: strength === "weak" ? "Weak" : strength === "strong" ? "Strong" : "Excellent" })] })), (0, jsx_runtime_1.jsxs)("div", { className: "input-password-confirm-wrapper", children: [(0, jsx_runtime_1.jsx)("label", { htmlFor: randomConfirmId, className: (0, _utils_1.cn)("input-label", (0, _utils_1.pcn)(className, "label")), children: "Password Confirm" }), (0, jsx_runtime_1.jsx)("div", { className: "relative", children: (0, jsx_runtime_1.jsx)("input", { ...props, id: randomConfirmId, type: "password", className: (0, _utils_1.cn)("input", leftIcon && "input-with-left-icon", rightIcon && "input-with-right-icon", (0, _utils_1.pcn)(className, "base"), isConfirmMismatch && "input-error"), value: confirmPassword, onChange: (e) => {
|
|
56
|
+
setConfirmPassword(e.target.value);
|
|
57
|
+
onChange?.(password, e.target.value);
|
|
58
|
+
}, autoComplete: "off" }) })] }), isConfirmMismatch && ((0, jsx_runtime_1.jsx)("small", { className: "input-error-message", children: "Password confirmation not match" }))] }));
|
|
59
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import { ApiType, ValidationRules } from "@utils";
|
|
3
|
+
export type InputRadioOptionProps = {
|
|
4
|
+
value: string | number;
|
|
5
|
+
label: string;
|
|
6
|
+
};
|
|
7
|
+
export type InputRadioProps = {
|
|
8
|
+
name: string;
|
|
9
|
+
label?: string;
|
|
10
|
+
tip?: string | ReactNode;
|
|
11
|
+
vertical?: boolean;
|
|
12
|
+
value?: string | number;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
invalid?: string;
|
|
15
|
+
options?: InputRadioOptionProps[];
|
|
16
|
+
serverOptionControl?: ApiType;
|
|
17
|
+
customOptions?: any;
|
|
18
|
+
validations?: ValidationRules;
|
|
19
|
+
onChange?: (value: string | number) => any;
|
|
20
|
+
register?: (name: string, validations?: ValidationRules) => void;
|
|
21
|
+
unregister?: (name: string) => void;
|
|
22
|
+
/** Use custom class with: "label::", "tip::", "error::", "icon::", "suggest::", "suggest-item::". */
|
|
23
|
+
className?: string;
|
|
24
|
+
/** Use custom class with: "label::", "checked::", "error::". */
|
|
25
|
+
classNameCheckbox?: string;
|
|
26
|
+
};
|
|
27
|
+
export declare function InputRadioComponent({ name, label, tip, vertical, value, disabled, invalid, options, serverOptionControl, customOptions, validations, onChange, register, unregister, className, classNameCheckbox, }: InputRadioProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.InputRadioComponent = InputRadioComponent;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const _utils_1 = require("@utils");
|
|
8
|
+
const _components_1 = require("@components");
|
|
9
|
+
function InputRadioComponent({ name, label, tip, vertical, value, disabled, invalid, options, serverOptionControl, customOptions, validations, onChange, register, unregister, className = "", classNameCheckbox = "", }) {
|
|
10
|
+
const [dataOptions, setDataOptions] = (0, react_1.useState)([]);
|
|
11
|
+
const [loading, setLoading] = (0, react_1.useState)(false);
|
|
12
|
+
// =========================>
|
|
13
|
+
// ## Initial
|
|
14
|
+
// =========================>
|
|
15
|
+
const inputHandler = (0, _utils_1.useInputHandler)(name, value, validations, register, unregister, false);
|
|
16
|
+
// =========================>
|
|
17
|
+
// ## Invalid handler
|
|
18
|
+
// =========================>
|
|
19
|
+
const [invalidMessage] = (0, _utils_1.useValidation)(inputHandler.value, validations, invalid, inputHandler.idle);
|
|
20
|
+
// =========================>
|
|
21
|
+
// ## Fetch option
|
|
22
|
+
// =========================>
|
|
23
|
+
(0, react_1.useEffect)(() => {
|
|
24
|
+
const fetchOptions = async () => {
|
|
25
|
+
setLoading(true);
|
|
26
|
+
const mutateOptions = await (0, _utils_1.api)(serverOptionControl || {});
|
|
27
|
+
if (mutateOptions?.status == 200) {
|
|
28
|
+
customOptions
|
|
29
|
+
? setDataOptions([customOptions, ...mutateOptions.data])
|
|
30
|
+
: setDataOptions(mutateOptions.data);
|
|
31
|
+
setLoading(false);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
if (serverOptionControl?.path || serverOptionControl?.url) {
|
|
35
|
+
fetchOptions();
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
!options && setDataOptions([]);
|
|
39
|
+
}
|
|
40
|
+
}, [serverOptionControl?.path, serverOptionControl?.url]);
|
|
41
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsxs)("div", { className: "input-container w-full", children: [(0, jsx_runtime_1.jsxs)("label", { className: (0, _utils_1.cn)("input-label", disabled && "input-label-disabled", !!invalidMessage && "input-label-error", (0, _utils_1.pcn)(className, "label"), disabled && (0, _utils_1.pcn)(className, "label", "disabled"), !!invalidMessage && (0, _utils_1.pcn)(className, "label", "focus")), 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: (0, _utils_1.cn)("input input-radio-list", vertical && "input-radio-list-vertical", (0, _utils_1.pcn)(className, "input"), !!invalidMessage && "input-error", !!invalidMessage && (0, _utils_1.pcn)(className, "input", "error")), children: [loading && (vertical ? [1, 2, 3, 4, 5, 6, 7, 8, 9] : [1, 2, 3]).map((_, key) => {
|
|
42
|
+
return (0, jsx_runtime_1.jsx)("div", { className: "w-1/3 h-6 rounded-lg" }, key);
|
|
43
|
+
}), (options || dataOptions) &&
|
|
44
|
+
(options || dataOptions)?.map((option, key) => {
|
|
45
|
+
return ((0, jsx_runtime_1.jsx)(_components_1.RadioComponent, { label: option.label, name: `option[${option.value}]#${name}`, checked: inputHandler.value == option.value, disabled: disabled, className: classNameCheckbox, onChange: () => {
|
|
46
|
+
if (inputHandler.value == option.value) {
|
|
47
|
+
inputHandler.setValue("");
|
|
48
|
+
onChange?.("");
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
inputHandler.setValue(option.value || "");
|
|
52
|
+
onChange?.(option.value || "");
|
|
53
|
+
}
|
|
54
|
+
} }, key));
|
|
55
|
+
})] }), invalidMessage && ((0, jsx_runtime_1.jsx)("small", { className: (0, _utils_1.cn)("input-error-message", (0, _utils_1.pcn)(className, "error")), children: invalidMessage }))] }) }));
|
|
56
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { FC, InputHTMLAttributes, ReactNode } from "react";
|
|
2
|
+
import { ValidationRules } from "@utils";
|
|
3
|
+
export interface InputTimeProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "onChange"> {
|
|
4
|
+
label?: string;
|
|
5
|
+
tip?: string | ReactNode;
|
|
6
|
+
leftIcon?: any;
|
|
7
|
+
rightIcon?: any;
|
|
8
|
+
value?: string;
|
|
9
|
+
invalid?: string;
|
|
10
|
+
validations?: ValidationRules;
|
|
11
|
+
onChange?: (value: string) => any;
|
|
12
|
+
register?: (name: string, validations?: ValidationRules) => void;
|
|
13
|
+
unregister?: (name: string) => void;
|
|
14
|
+
/** Use custom class with: "label::", "tip::", "error::", "icon::". */
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
export declare function InputTimeComponent({ label, tip, leftIcon, rightIcon, value, invalid, validations, register, unregister, onChange, className, ...props }: InputTimeProps): import("react").JSX.Element;
|
|
18
|
+
interface InputTimePickerProps {
|
|
19
|
+
onChange?: (time: string) => void;
|
|
20
|
+
rightElement?: ReactNode;
|
|
21
|
+
}
|
|
22
|
+
export declare const InputTimePickerComponent: FC<InputTimePickerProps>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.InputTimePickerComponent = void 0;
|
|
5
|
+
exports.InputTimeComponent = InputTimeComponent;
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const react_1 = require("react");
|
|
8
|
+
const react_fontawesome_1 = require("@fortawesome/react-fontawesome");
|
|
9
|
+
const _utils_1 = require("@utils");
|
|
10
|
+
const _components_1 = require("@components");
|
|
11
|
+
function InputTimeComponent({ label, tip, leftIcon, rightIcon, value, invalid, validations, register, unregister, onChange, className = "", ...props }) {
|
|
12
|
+
const { isSm } = (0, _utils_1.useResponsive)();
|
|
13
|
+
// =========================>
|
|
14
|
+
// ## Initial
|
|
15
|
+
// =========================>
|
|
16
|
+
const inputHandler = (0, _utils_1.useInputHandler)(props.name, value, validations, register, unregister, false);
|
|
17
|
+
const randomId = (0, _utils_1.useInputRandomId)();
|
|
18
|
+
// =========================>
|
|
19
|
+
// ## Invalid handler
|
|
20
|
+
// =========================>
|
|
21
|
+
const [invalidMessage] = (0, _utils_1.useValidation)(inputHandler.value, validations, invalid, inputHandler.idle);
|
|
22
|
+
return ((0, jsx_runtime_1.jsxs)(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", props.disabled && "input-label-disabled", inputHandler.focus && "input-label-focus", !!invalidMessage && "input-label-error", (0, _utils_1.pcn)(className, "label")), 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", props.disabled && "input-tip-disabled", (0, _utils_1.pcn)(className, "tip")), children: tip })), (0, jsx_runtime_1.jsx)(_components_1.OutsideClickComponent, { onOutsideClick: !isSm ? () => inputHandler.setFocus(false) : undefined, children: (0, jsx_runtime_1.jsxs)("div", { className: "relative", children: [(0, jsx_runtime_1.jsx)("input", { ...props, id: randomId, className: (0, _utils_1.cn)("input", leftIcon && "input-with-left-icon", rightIcon && "input-with-right-icon", (0, _utils_1.pcn)(className, "input"), !!invalidMessage && "input-error"), value: inputHandler.value, onChange: (e) => {
|
|
23
|
+
inputHandler.setValue(e.target.value);
|
|
24
|
+
inputHandler.setIdle(false);
|
|
25
|
+
onChange?.(e.target.value);
|
|
26
|
+
}, onFocus: (e) => {
|
|
27
|
+
props.onFocus?.(e);
|
|
28
|
+
inputHandler.setFocus(true);
|
|
29
|
+
}, autoComplete: "off", inputMode: isSm ? "none" : undefined }), leftIcon && ((0, jsx_runtime_1.jsx)(react_fontawesome_1.FontAwesomeIcon, { className: (0, _utils_1.cn)("input-icon", "input-icon-left", props.disabled && "input-icon-disabled", inputHandler.focus && "input-icon-focus", (0, _utils_1.pcn)(className, "icon")), icon: leftIcon })), rightIcon && ((0, jsx_runtime_1.jsx)(react_fontawesome_1.FontAwesomeIcon, { className: (0, _utils_1.cn)("input-icon", "input-icon-right", props.disabled && "input-icon-disabled", inputHandler.focus && "input-icon-focus", (0, _utils_1.pcn)(className, "icon")), icon: rightIcon })), !isSm && inputHandler.focus && ((0, jsx_runtime_1.jsx)("div", { className: "input-time-picker-popover", children: (0, jsx_runtime_1.jsx)(exports.InputTimePickerComponent, { onChange: (time) => {
|
|
30
|
+
inputHandler.setValue(time);
|
|
31
|
+
onChange?.(time);
|
|
32
|
+
} }) }))] }) }), invalidMessage && ((0, jsx_runtime_1.jsx)("small", { className: (0, _utils_1.cn)("input-error-message", (0, _utils_1.pcn)(className, "error")), children: invalidMessage }))] }), isSm && ((0, jsx_runtime_1.jsx)(_components_1.BottomSheetComponent, { show: inputHandler.focus, onClose: () => inputHandler.setFocus(false), size: 380, footer: (0, jsx_runtime_1.jsx)("div", { className: "p-4", children: (0, jsx_runtime_1.jsx)(_components_1.ButtonComponent, { label: "Selesai", variant: "outline", onClick: () => inputHandler.setFocus(false), block: true }) }), children: (0, jsx_runtime_1.jsx)("div", { className: "p-4", children: (0, jsx_runtime_1.jsx)(exports.InputTimePickerComponent, { onChange: (time) => {
|
|
33
|
+
inputHandler.setValue(time);
|
|
34
|
+
onChange?.(time);
|
|
35
|
+
} }) }) }))] }));
|
|
36
|
+
}
|
|
37
|
+
;
|
|
38
|
+
const InputTimePickerComponent = ({ onChange, rightElement, }) => {
|
|
39
|
+
const [hour, setHour] = (0, react_1.useState)(0);
|
|
40
|
+
const [minute, setMinute] = (0, react_1.useState)(0);
|
|
41
|
+
const [second, setSecond] = (0, react_1.useState)(0);
|
|
42
|
+
const hours = Array.from({ length: 24 }, (_, i) => String(i).padStart(2, "0"));
|
|
43
|
+
const minutes = Array.from({ length: 60 }, (_, i) => String(i).padStart(2, "0"));
|
|
44
|
+
const seconds = Array.from({ length: 60 }, (_, i) => String(i).padStart(2, "0"));
|
|
45
|
+
const handleSelect = (type, val) => {
|
|
46
|
+
if (type === "h")
|
|
47
|
+
setHour(Number(val));
|
|
48
|
+
if (type === "m")
|
|
49
|
+
setMinute(Number(val));
|
|
50
|
+
if (type === "s")
|
|
51
|
+
setSecond(Number(val));
|
|
52
|
+
};
|
|
53
|
+
(0, react_1.useEffect)(() => {
|
|
54
|
+
const formatted = `${String(hour).padStart(2, "0")}:${String(minute).padStart(2, "0")}:${String(second).padStart(2, "0")}`;
|
|
55
|
+
onChange?.(formatted);
|
|
56
|
+
}, [hour, minute, second]);
|
|
57
|
+
const renderColumn = (items, type, activeValue) => ((0, jsx_runtime_1.jsx)("div", { className: "flex-1 overflow-y-auto text-center input-scroll", children: items.map((item) => {
|
|
58
|
+
const active = Number(item) === activeValue;
|
|
59
|
+
return ((0, jsx_runtime_1.jsx)("div", { onClick: () => handleSelect(type, item), className: (0, _utils_1.cn)("p-2 cursor-pointer rounded text-sm", active ? "bg-primary text-background font-semibold" : "hover:bg-light-primary"), children: item }, item));
|
|
60
|
+
}) }));
|
|
61
|
+
const timeSlots = (0, react_1.useMemo)(() => {
|
|
62
|
+
const newTimeSlots = [];
|
|
63
|
+
for (let i = 0; i <= 24 * 60; i += 30) {
|
|
64
|
+
const hours = Math.floor(i / 60);
|
|
65
|
+
const minutes = i % 60;
|
|
66
|
+
const label = `${String(hours).padStart(2, "0")}:${String(minutes).padStart(2, "0")}`;
|
|
67
|
+
newTimeSlots.push(label);
|
|
68
|
+
}
|
|
69
|
+
return newTimeSlots;
|
|
70
|
+
}, []);
|
|
71
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "w-full max-h-[260] flex gap-2", children: [(0, jsx_runtime_1.jsx)("div", { className: "w-1/3 overflow-y-auto bg-background rounded-[6px] input-scroll", children: timeSlots.map((time) => ((0, jsx_runtime_1.jsx)("div", { className: "p-2 text-sm rounded cursor-pointer hover:bg-light-primary text-center", onClick: () => onChange?.(time), children: time }, time))) }), (0, jsx_runtime_1.jsxs)("div", { className: "w-2/3 flex gap-2", children: [renderColumn(hours, "h", hour), renderColumn(minutes, "m", minute), renderColumn(seconds, "s", second)] }), rightElement && (0, jsx_runtime_1.jsx)("div", { children: rightElement })] }));
|
|
72
|
+
};
|
|
73
|
+
exports.InputTimePickerComponent = InputTimePickerComponent;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
|
+
export declare function InputValues({ value, className, onDelete, isFocus, onFocus, style, }: {
|
|
3
|
+
value?: string[] | number[];
|
|
4
|
+
className?: string;
|
|
5
|
+
onDelete?: (val: string | number, index: string | number) => void;
|
|
6
|
+
isFocus?: boolean;
|
|
7
|
+
onFocus?: () => void;
|
|
8
|
+
style?: CSSProperties;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.InputValues = InputValues;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const free_solid_svg_icons_1 = require("@fortawesome/free-solid-svg-icons");
|
|
6
|
+
const react_fontawesome_1 = require("@fortawesome/react-fontawesome");
|
|
7
|
+
const _utils_1 = require("@utils");
|
|
8
|
+
function InputValues({ value, className, onDelete, isFocus, onFocus, style, }) {
|
|
9
|
+
if (isFocus) {
|
|
10
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: !!value?.length && ((0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)("input-values-dropdown", className), onClick: () => onFocus?.(), children: value?.map((item, key) => {
|
|
11
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "input-values-item", children: [(0, jsx_runtime_1.jsx)("span", { className: "", children: item }), (0, jsx_runtime_1.jsx)(react_fontawesome_1.FontAwesomeIcon, { icon: free_solid_svg_icons_1.faTimes, className: "input-values-delete", onClick: () => onDelete?.(item, key) })] }, key));
|
|
12
|
+
}) })) }));
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)("input-values-preview", className), style: style, onClick: () => onFocus?.(), children: (0, jsx_runtime_1.jsx)("div", { className: "input-values-container", children: value?.map((item, key) => {
|
|
16
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "input-values-item", children: [(0, jsx_runtime_1.jsx)("span", { children: item }), (0, jsx_runtime_1.jsx)(react_fontawesome_1.FontAwesomeIcon, { icon: free_solid_svg_icons_1.faTimes, className: "input-values-delete", onClick: () => onDelete?.(item, key) })] }, key));
|
|
17
|
+
}) }) }) }));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface RadioProps {
|
|
2
|
+
name: string;
|
|
3
|
+
label?: string;
|
|
4
|
+
value?: string;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
checked?: boolean;
|
|
7
|
+
invalid?: string;
|
|
8
|
+
onChange?: () => void;
|
|
9
|
+
/** Use custom class with: "label::", "checked::", "error::". */
|
|
10
|
+
className?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function RadioComponent({ name, label, value, disabled, checked, invalid, onChange, className, }: RadioProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.RadioComponent = RadioComponent;
|
|
5
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
6
|
+
const react_1 = require("react");
|
|
7
|
+
const _utils_1 = require("@utils");
|
|
8
|
+
;
|
|
9
|
+
function RadioComponent({ name, label, value, disabled, checked, invalid, onChange, className = "", }) {
|
|
10
|
+
// =========================>
|
|
11
|
+
// ## initial
|
|
12
|
+
// =========================>
|
|
13
|
+
const randomId = (0, _utils_1.useInputRandomId)();
|
|
14
|
+
const [invalidMessage, setInvalidMessage] = (0, react_1.useState)("");
|
|
15
|
+
// =========================>
|
|
16
|
+
// ## invalid handler
|
|
17
|
+
// =========================>
|
|
18
|
+
(0, react_1.useEffect)(() => {
|
|
19
|
+
setInvalidMessage(invalid || "");
|
|
20
|
+
}, [invalid]);
|
|
21
|
+
return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsxs)("div", { className: "radio-container", children: [(0, jsx_runtime_1.jsx)("input", { type: "checkbox", className: "hidden", id: randomId, name: name, onChange: onChange, defaultChecked: checked, value: value, disabled: disabled }), (0, jsx_runtime_1.jsxs)("label", { htmlFor: randomId, className: (0, _utils_1.cn)("radio-wrapper", disabled && "radio-wrapper-disabled"), children: [(0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)("radio-input", checked && "radio-input-checked", checked && (0, _utils_1.pcn)(className, "checked"), (0, _utils_1.pcn)(className, "input")) }), (0, jsx_runtime_1.jsx)("div", { className: (0, _utils_1.cn)("radio-label", checked && "radio-label-checked", (0, _utils_1.pcn)(className, "label"), checked && (0, _utils_1.pcn)(className, "label", "checked"), disabled && (0, _utils_1.pcn)(className, "label", "disabled")), children: label })] }), invalidMessage && ((0, jsx_runtime_1.jsx)("small", { className: (0, _utils_1.cn)("input-error-message", (0, _utils_1.pcn)(className, "error")), children: invalidMessage }))] }) }));
|
|
22
|
+
}
|