@zauru-sdk/components 1.0.54 → 1.0.61
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/CHANGELOG.md +56 -0
- package/LICENCE.md +11 -11
- package/package.json +7 -7
- package/src/Alerts/ErrorBoundaryAlert/ErrorBoundaryAlert.tsx +66 -66
- package/src/Alerts/StaticAlert.tsx +121 -121
- package/src/Alerts/index.ts +2 -2
- package/src/BlockUI/BlockUI.tsx +50 -50
- package/src/BlockUI/index.tsx +1 -1
- package/src/Buttons/Button.tsx +90 -90
- package/src/Buttons/index.ts +1 -1
- package/src/Card/Card.tsx +24 -24
- package/src/Card/index.ts +1 -1
- package/src/Chat/ChatLayout.tsx +131 -131
- package/src/Chat/ChatMessageHistory.tsx +142 -142
- package/src/Chat/index.ts +2 -2
- package/src/ConnectionState/ConnectionState.tsx +27 -27
- package/src/ConnectionState/index.tsx +1 -1
- package/src/Containers/BodyContainer.tsx +14 -14
- package/src/Containers/ButtonSectionContainer.tsx +21 -21
- package/src/Containers/Container.tsx +39 -39
- package/src/Containers/DoubleContainer.tsx +48 -48
- package/src/Containers/MainContainer.tsx +17 -17
- package/src/Containers/OutletContainer.tsx +14 -14
- package/src/Containers/SubContainer.tsx +37 -37
- package/src/Containers/index.ts +7 -7
- package/src/DynamicTable/BasicPrintDynamicTable.tsx +73 -73
- package/src/DynamicTable/DynamicPrintTable.tsx +288 -288
- package/src/DynamicTable/DynamicTable.tsx +405 -405
- package/src/DynamicTable/GenericDynamicTable.tsx +456 -456
- package/src/DynamicTable/index.tsx +4 -4
- package/src/Footer/Footer.tsx +50 -50
- package/src/Footer/index.tsx +1 -1
- package/src/Form/Checkbox/index.tsx +96 -96
- package/src/Form/Checklist/index.tsx +35 -35
- package/src/Form/DatePicker/index.tsx +132 -132
- package/src/Form/DynamicBaculoForm/index.tsx +361 -361
- package/src/Form/FieldContainer/DoubleFieldContainer.tsx +35 -35
- package/src/Form/FieldContainer/QuadrupleFieldContainer.tsx +36 -36
- package/src/Form/FieldContainer/TripleFieldContainer.tsx +35 -35
- package/src/Form/FieldContainer/index.ts +3 -3
- package/src/Form/FileUpload/index.tsx +184 -184
- package/src/Form/FormButtons/index.tsx +78 -78
- package/src/Form/FormLayout/index.tsx +37 -37
- package/src/Form/SelectField/index.tsx +237 -237
- package/src/Form/TextArea/index.tsx +125 -125
- package/src/Form/TextField/index.tsx +194 -194
- package/src/Form/TimePicker/index.tsx +127 -127
- package/src/Form/YesNo/index.tsx +77 -77
- package/src/Form/index.ts +13 -13
- package/src/Labels/InfoLabel/index.tsx +21 -21
- package/src/Labels/index.tsx +1 -1
- package/src/Layouts/homeLayout/index.tsx +34 -34
- package/src/Layouts/index.ts +1 -1
- package/src/LineSeparator/LineSeparator.tsx +3 -3
- package/src/LineSeparator/index.tsx +1 -1
- package/src/Modal/Modal.tsx +104 -104
- package/src/Modal/index.tsx +1 -1
- package/src/NavBar/NavBar.tsx +223 -223
- package/src/NavBar/NavBar.types.ts +64 -64
- package/src/NavBar/NavBar.utils.ts +58 -58
- package/src/NavBar/index.tsx +5 -5
- package/src/ProgressBar/ProgressBar.tsx +25 -25
- package/src/ProgressBar/ProgressCircle.tsx +75 -75
- package/src/ProgressBar/index.tsx +2 -2
- package/src/Skeletons/LoadingInputSkeleton.tsx +12 -12
- package/src/Skeletons/index.ts +1 -1
- package/src/Tab/Tab.tsx +63 -63
- package/src/Tab/index.ts +1 -1
- package/src/Table/ZauruTable.tsx +265 -265
- package/src/Table/index.tsx +1 -1
- package/src/TaskList/TaskList.tsx +88 -88
- package/src/TaskList/index.ts +1 -1
- package/src/Titles/LabelArray.tsx +17 -17
- package/src/Titles/TableColumnTitle.tsx +9 -9
- package/src/Titles/TitleH1.tsx +10 -10
- package/src/Titles/TitleH2.tsx +10 -10
- package/src/Titles/TitleH3.tsx +10 -10
- package/src/Titles/index.ts +5 -5
- package/src/Tooltip/Tooltip.tsx +42 -42
- package/src/Tooltip/index.ts +1 -1
- package/src/WithTooltip/WithTooltip.tsx +21 -21
- package/src/WithTooltip/index.tsx +1 -1
- package/src/Wizards/StepWizard.tsx +88 -88
- package/src/Wizards/index.ts +1 -1
- package/src/Zendesk/Chat.tsx +83 -83
- package/src/Zendesk/index.ts +2 -2
- package/src/Zendesk/zendesk.config.ts +40 -40
- package/src/index.ts +24 -24
- package/src/postcss.config.mjs +5 -5
- package/src/tailwind.config.ts +10 -10
- package/src/tailwind.css +3 -3
- package/tsconfig.cjs.json +8 -8
- package/tsconfig.esm.json +11 -11
- package/tsconfig.json +17 -17
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from "./BasicPrintDynamicTable.js";
|
|
2
|
-
export * from "./DynamicPrintTable.js";
|
|
3
|
-
export * from "./DynamicTable.js";
|
|
4
|
-
export * from "./GenericDynamicTable.js";
|
|
1
|
+
export * from "./BasicPrintDynamicTable.js";
|
|
2
|
+
export * from "./DynamicPrintTable.js";
|
|
3
|
+
export * from "./DynamicTable.js";
|
|
4
|
+
export * from "./GenericDynamicTable.js";
|
package/src/Footer/Footer.tsx
CHANGED
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
import { ConnectionState } from "./../ConnectionState/index.js";
|
|
2
|
-
|
|
3
|
-
type FooterProps = {
|
|
4
|
-
href: string;
|
|
5
|
-
showConnection?: boolean;
|
|
6
|
-
selectedColor:
|
|
7
|
-
| "purple"
|
|
8
|
-
| "pink"
|
|
9
|
-
| "indigo"
|
|
10
|
-
| "cyan"
|
|
11
|
-
| "slate"
|
|
12
|
-
| "green"
|
|
13
|
-
| "red"
|
|
14
|
-
| "sky";
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
const COLORS = {
|
|
18
|
-
purple: "bg-purple-500",
|
|
19
|
-
pink: "bg-pink-500",
|
|
20
|
-
indigo: "bg-indigo-500",
|
|
21
|
-
cyan: "bg-cyan-500",
|
|
22
|
-
slate: "bg-slate-500",
|
|
23
|
-
green: "bg-green-500",
|
|
24
|
-
red: "bg-red-500",
|
|
25
|
-
sky: "bg-sky-500",
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export const Footer = ({
|
|
29
|
-
href,
|
|
30
|
-
selectedColor,
|
|
31
|
-
showConnection = false,
|
|
32
|
-
}: FooterProps) => {
|
|
33
|
-
const color = COLORS[selectedColor];
|
|
34
|
-
|
|
35
|
-
return (
|
|
36
|
-
<footer className={`inset-x-0 bottom-0 px-2 py-[20px] ${color}`}>
|
|
37
|
-
<div className="px-4 mx-auto flex flex-wrap items-center justify-center">
|
|
38
|
-
<p className="text-white text-[1.2rem]">
|
|
39
|
-
{`Creado en `} <a href={href}>Zauru</a>{" "}
|
|
40
|
-
{`con ❤️ ${new Date().getFullYear()} v.3.2`}
|
|
41
|
-
</p>
|
|
42
|
-
{showConnection && (
|
|
43
|
-
<div className="ml-5">
|
|
44
|
-
<ConnectionState />
|
|
45
|
-
</div>
|
|
46
|
-
)}
|
|
47
|
-
</div>
|
|
48
|
-
</footer>
|
|
49
|
-
);
|
|
50
|
-
};
|
|
1
|
+
import { ConnectionState } from "./../ConnectionState/index.js";
|
|
2
|
+
|
|
3
|
+
type FooterProps = {
|
|
4
|
+
href: string;
|
|
5
|
+
showConnection?: boolean;
|
|
6
|
+
selectedColor:
|
|
7
|
+
| "purple"
|
|
8
|
+
| "pink"
|
|
9
|
+
| "indigo"
|
|
10
|
+
| "cyan"
|
|
11
|
+
| "slate"
|
|
12
|
+
| "green"
|
|
13
|
+
| "red"
|
|
14
|
+
| "sky";
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const COLORS = {
|
|
18
|
+
purple: "bg-purple-500",
|
|
19
|
+
pink: "bg-pink-500",
|
|
20
|
+
indigo: "bg-indigo-500",
|
|
21
|
+
cyan: "bg-cyan-500",
|
|
22
|
+
slate: "bg-slate-500",
|
|
23
|
+
green: "bg-green-500",
|
|
24
|
+
red: "bg-red-500",
|
|
25
|
+
sky: "bg-sky-500",
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export const Footer = ({
|
|
29
|
+
href,
|
|
30
|
+
selectedColor,
|
|
31
|
+
showConnection = false,
|
|
32
|
+
}: FooterProps) => {
|
|
33
|
+
const color = COLORS[selectedColor];
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<footer className={`inset-x-0 bottom-0 px-2 py-[20px] ${color}`}>
|
|
37
|
+
<div className="px-4 mx-auto flex flex-wrap items-center justify-center">
|
|
38
|
+
<p className="text-white text-[1.2rem]">
|
|
39
|
+
{`Creado en `} <a href={href}>Zauru</a>{" "}
|
|
40
|
+
{`con ❤️ ${new Date().getFullYear()} v.3.2`}
|
|
41
|
+
</p>
|
|
42
|
+
{showConnection && (
|
|
43
|
+
<div className="ml-5">
|
|
44
|
+
<ConnectionState />
|
|
45
|
+
</div>
|
|
46
|
+
)}
|
|
47
|
+
</div>
|
|
48
|
+
</footer>
|
|
49
|
+
);
|
|
50
|
+
};
|
package/src/Footer/index.tsx
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "./Footer.js";
|
|
1
|
+
export * from "./Footer.js";
|
|
@@ -1,96 +1,96 @@
|
|
|
1
|
-
import { useAppSelector } from "@zauru-sdk/redux";
|
|
2
|
-
import React, { useEffect, useState } from "react";
|
|
3
|
-
|
|
4
|
-
type Props = {
|
|
5
|
-
id?: string;
|
|
6
|
-
name?: string;
|
|
7
|
-
formName?: string;
|
|
8
|
-
label?: string;
|
|
9
|
-
defaultValue?: boolean;
|
|
10
|
-
onChange?: (
|
|
11
|
-
value: boolean,
|
|
12
|
-
event: React.ChangeEvent<HTMLInputElement>
|
|
13
|
-
) => { stopUIChange: boolean } | void;
|
|
14
|
-
disabled?: boolean;
|
|
15
|
-
error?: string | undefined;
|
|
16
|
-
borderColor?: string;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
export const CheckboxWithoutValidation = (props: Props) => {
|
|
20
|
-
const {
|
|
21
|
-
id,
|
|
22
|
-
name,
|
|
23
|
-
defaultValue = false,
|
|
24
|
-
onChange,
|
|
25
|
-
disabled = false,
|
|
26
|
-
error,
|
|
27
|
-
label,
|
|
28
|
-
} = props;
|
|
29
|
-
|
|
30
|
-
const [checked, setChecked] = useState(defaultValue);
|
|
31
|
-
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
setChecked(defaultValue);
|
|
34
|
-
}, [defaultValue]);
|
|
35
|
-
|
|
36
|
-
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
37
|
-
const isChecked = event.target.checked;
|
|
38
|
-
if (onChange) {
|
|
39
|
-
const result = onChange(isChecked, event);
|
|
40
|
-
if (result?.stopUIChange) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
setChecked(isChecked);
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const color = error ? "red" : "gray";
|
|
48
|
-
const borderColor = disabled ? "border-gray-300" : `border-${color}-500`;
|
|
49
|
-
|
|
50
|
-
const inputComponent = (
|
|
51
|
-
<input
|
|
52
|
-
type="checkbox"
|
|
53
|
-
id={id ?? name}
|
|
54
|
-
name={name}
|
|
55
|
-
checked={checked}
|
|
56
|
-
onChange={handleInputChange}
|
|
57
|
-
className={`form-checkbox h-4 w-4 text-indigo-600 ${borderColor} focus:border-indigo-500 focus:ring-indigo-500`}
|
|
58
|
-
disabled={disabled}
|
|
59
|
-
/>
|
|
60
|
-
);
|
|
61
|
-
|
|
62
|
-
if (!error && !label) {
|
|
63
|
-
return inputComponent;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<div className="col-span-6 sm:col-span-3">
|
|
68
|
-
<div className={`flex items-center ${borderColor}`}>
|
|
69
|
-
{inputComponent}
|
|
70
|
-
{label && (
|
|
71
|
-
<label
|
|
72
|
-
htmlFor={id ?? name}
|
|
73
|
-
className={`ml-2 block text-sm font-medium text-${color}-700 dark:text-${color}-500`}
|
|
74
|
-
>
|
|
75
|
-
{label}
|
|
76
|
-
</label>
|
|
77
|
-
)}
|
|
78
|
-
</div>
|
|
79
|
-
{error && (
|
|
80
|
-
<p className={`mt-2 text-sm text-${color}-600 dark:text-${color}-500`}>
|
|
81
|
-
<span className="font-medium">Oops!</span> {error}
|
|
82
|
-
</p>
|
|
83
|
-
)}
|
|
84
|
-
</div>
|
|
85
|
-
);
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
//<reference> https://tailwindui.com/components/application-ui/forms/form-layouts
|
|
89
|
-
export const CheckBox = (props: Props) => {
|
|
90
|
-
const { formValidations } = useAppSelector((state) => state.formValidation);
|
|
91
|
-
const error = formValidations[props.formName ?? "-1"]?.[props.name ?? "-1"];
|
|
92
|
-
|
|
93
|
-
props = { ...props, error };
|
|
94
|
-
|
|
95
|
-
return <CheckboxWithoutValidation {...props} />;
|
|
96
|
-
};
|
|
1
|
+
import { useAppSelector } from "@zauru-sdk/redux";
|
|
2
|
+
import React, { useEffect, useState } from "react";
|
|
3
|
+
|
|
4
|
+
type Props = {
|
|
5
|
+
id?: string;
|
|
6
|
+
name?: string;
|
|
7
|
+
formName?: string;
|
|
8
|
+
label?: string;
|
|
9
|
+
defaultValue?: boolean;
|
|
10
|
+
onChange?: (
|
|
11
|
+
value: boolean,
|
|
12
|
+
event: React.ChangeEvent<HTMLInputElement>
|
|
13
|
+
) => { stopUIChange: boolean } | void;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
error?: string | undefined;
|
|
16
|
+
borderColor?: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const CheckboxWithoutValidation = (props: Props) => {
|
|
20
|
+
const {
|
|
21
|
+
id,
|
|
22
|
+
name,
|
|
23
|
+
defaultValue = false,
|
|
24
|
+
onChange,
|
|
25
|
+
disabled = false,
|
|
26
|
+
error,
|
|
27
|
+
label,
|
|
28
|
+
} = props;
|
|
29
|
+
|
|
30
|
+
const [checked, setChecked] = useState(defaultValue);
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
setChecked(defaultValue);
|
|
34
|
+
}, [defaultValue]);
|
|
35
|
+
|
|
36
|
+
const handleInputChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
37
|
+
const isChecked = event.target.checked;
|
|
38
|
+
if (onChange) {
|
|
39
|
+
const result = onChange(isChecked, event);
|
|
40
|
+
if (result?.stopUIChange) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
setChecked(isChecked);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const color = error ? "red" : "gray";
|
|
48
|
+
const borderColor = disabled ? "border-gray-300" : `border-${color}-500`;
|
|
49
|
+
|
|
50
|
+
const inputComponent = (
|
|
51
|
+
<input
|
|
52
|
+
type="checkbox"
|
|
53
|
+
id={id ?? name}
|
|
54
|
+
name={name}
|
|
55
|
+
checked={checked}
|
|
56
|
+
onChange={handleInputChange}
|
|
57
|
+
className={`form-checkbox h-4 w-4 text-indigo-600 ${borderColor} focus:border-indigo-500 focus:ring-indigo-500`}
|
|
58
|
+
disabled={disabled}
|
|
59
|
+
/>
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
if (!error && !label) {
|
|
63
|
+
return inputComponent;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return (
|
|
67
|
+
<div className="col-span-6 sm:col-span-3">
|
|
68
|
+
<div className={`flex items-center ${borderColor}`}>
|
|
69
|
+
{inputComponent}
|
|
70
|
+
{label && (
|
|
71
|
+
<label
|
|
72
|
+
htmlFor={id ?? name}
|
|
73
|
+
className={`ml-2 block text-sm font-medium text-${color}-700 dark:text-${color}-500`}
|
|
74
|
+
>
|
|
75
|
+
{label}
|
|
76
|
+
</label>
|
|
77
|
+
)}
|
|
78
|
+
</div>
|
|
79
|
+
{error && (
|
|
80
|
+
<p className={`mt-2 text-sm text-${color}-600 dark:text-${color}-500`}>
|
|
81
|
+
<span className="font-medium">Oops!</span> {error}
|
|
82
|
+
</p>
|
|
83
|
+
)}
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
//<reference> https://tailwindui.com/components/application-ui/forms/form-layouts
|
|
89
|
+
export const CheckBox = (props: Props) => {
|
|
90
|
+
const { formValidations } = useAppSelector((state) => state.formValidation);
|
|
91
|
+
const error = formValidations[props.formName ?? "-1"]?.[props.name ?? "-1"];
|
|
92
|
+
|
|
93
|
+
props = { ...props, error };
|
|
94
|
+
|
|
95
|
+
return <CheckboxWithoutValidation {...props} />;
|
|
96
|
+
};
|
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import { CheckboxWithoutValidation } from "../Checkbox/index.js";
|
|
3
|
-
|
|
4
|
-
export type ChecklistItem = {
|
|
5
|
-
id: string;
|
|
6
|
-
name: string;
|
|
7
|
-
label: string;
|
|
8
|
-
defaultValue?: boolean;
|
|
9
|
-
disabled?: boolean;
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
type ChecklistProps = {
|
|
13
|
-
items: ChecklistItem[];
|
|
14
|
-
onChange?: (name: string, value: boolean) => void;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
export const Checklist: React.FC<ChecklistProps> = ({ items, onChange }) => {
|
|
18
|
-
const handleCheckboxChange = (name: string, value: boolean) => {
|
|
19
|
-
if (onChange) {
|
|
20
|
-
onChange(name, value);
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
return (
|
|
25
|
-
<div>
|
|
26
|
-
{items.map((item) => (
|
|
27
|
-
<CheckboxWithoutValidation
|
|
28
|
-
key={item.id}
|
|
29
|
-
{...item}
|
|
30
|
-
onChange={(value) => handleCheckboxChange(item.name, value)}
|
|
31
|
-
/>
|
|
32
|
-
))}
|
|
33
|
-
</div>
|
|
34
|
-
);
|
|
35
|
-
};
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { CheckboxWithoutValidation } from "../Checkbox/index.js";
|
|
3
|
+
|
|
4
|
+
export type ChecklistItem = {
|
|
5
|
+
id: string;
|
|
6
|
+
name: string;
|
|
7
|
+
label: string;
|
|
8
|
+
defaultValue?: boolean;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
type ChecklistProps = {
|
|
13
|
+
items: ChecklistItem[];
|
|
14
|
+
onChange?: (name: string, value: boolean) => void;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const Checklist: React.FC<ChecklistProps> = ({ items, onChange }) => {
|
|
18
|
+
const handleCheckboxChange = (name: string, value: boolean) => {
|
|
19
|
+
if (onChange) {
|
|
20
|
+
onChange(name, value);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<div>
|
|
26
|
+
{items.map((item) => (
|
|
27
|
+
<CheckboxWithoutValidation
|
|
28
|
+
key={item.id}
|
|
29
|
+
{...item}
|
|
30
|
+
onChange={(value) => handleCheckboxChange(item.name, value)}
|
|
31
|
+
/>
|
|
32
|
+
))}
|
|
33
|
+
</div>
|
|
34
|
+
);
|
|
35
|
+
};
|
|
@@ -1,132 +1,132 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
|
2
|
-
import { CalendarIconSVG, CloseSvgIcon, IdeaIconSVG } from "@zauru-sdk/icons";
|
|
3
|
-
import { useAppSelector } from "@zauru-sdk/redux";
|
|
4
|
-
|
|
5
|
-
type Props = {
|
|
6
|
-
id?: string;
|
|
7
|
-
name: string;
|
|
8
|
-
formName?: string;
|
|
9
|
-
title?: string;
|
|
10
|
-
hint?: string;
|
|
11
|
-
helpText?: string;
|
|
12
|
-
defaultValue?: string;
|
|
13
|
-
onChange?: (value: string) => void;
|
|
14
|
-
isClearable?: boolean;
|
|
15
|
-
tabIndex?: number;
|
|
16
|
-
error?: string;
|
|
17
|
-
disabled?: boolean;
|
|
18
|
-
className?: string;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
export const FormDatePickerWithoutValidation = (props: Props) => {
|
|
22
|
-
const {
|
|
23
|
-
id,
|
|
24
|
-
name,
|
|
25
|
-
title,
|
|
26
|
-
defaultValue = "",
|
|
27
|
-
hint,
|
|
28
|
-
helpText,
|
|
29
|
-
onChange,
|
|
30
|
-
tabIndex,
|
|
31
|
-
error,
|
|
32
|
-
disabled = false,
|
|
33
|
-
className = "",
|
|
34
|
-
isClearable = false,
|
|
35
|
-
} = props;
|
|
36
|
-
|
|
37
|
-
const [value, setValue] = useState<string | null>(defaultValue);
|
|
38
|
-
const [showTooltip, setShowTooltip] = useState<boolean>(false);
|
|
39
|
-
|
|
40
|
-
const color = error ? "red" : "gray";
|
|
41
|
-
|
|
42
|
-
const isReadOnly = disabled;
|
|
43
|
-
const bgColor = isReadOnly ? "bg-gray-200" : `bg-${color}-50`;
|
|
44
|
-
const textColor = isReadOnly ? "text-gray-500" : `text-${color}-500`;
|
|
45
|
-
const borderColor = isReadOnly ? "border-gray-300" : `border-${color}-200`;
|
|
46
|
-
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
setValue(defaultValue);
|
|
49
|
-
}, [defaultValue]);
|
|
50
|
-
|
|
51
|
-
const clearValue = () => {
|
|
52
|
-
setValue("");
|
|
53
|
-
onChange && onChange("");
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
return (
|
|
57
|
-
<>
|
|
58
|
-
{title && (
|
|
59
|
-
<label
|
|
60
|
-
htmlFor={error ? `${name}-error` : `${name}-success`}
|
|
61
|
-
className={`block text-sm font-medium ${textColor} ${className}`}
|
|
62
|
-
>
|
|
63
|
-
{title}
|
|
64
|
-
</label>
|
|
65
|
-
)}
|
|
66
|
-
<div className="flex relative items-center">
|
|
67
|
-
<div className="absolute left-0 flex items-center pl-3 pointer-events-none">
|
|
68
|
-
<CalendarIconSVG />
|
|
69
|
-
</div>
|
|
70
|
-
<input
|
|
71
|
-
id={id}
|
|
72
|
-
name={name}
|
|
73
|
-
tabIndex={tabIndex}
|
|
74
|
-
type="date"
|
|
75
|
-
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
76
|
-
setValue(e.target.value);
|
|
77
|
-
onChange && onChange(e.target.value);
|
|
78
|
-
}}
|
|
79
|
-
value={value ?? ""}
|
|
80
|
-
pattern="\d{4}-\d{2}-\d{2}"
|
|
81
|
-
className={`${bgColor} ${borderColor} ${textColor} text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full pl-10 p-2.5`}
|
|
82
|
-
></input>
|
|
83
|
-
{value && isClearable && (
|
|
84
|
-
<button
|
|
85
|
-
type="button"
|
|
86
|
-
onClick={clearValue}
|
|
87
|
-
className="absolute right-0 mr-10"
|
|
88
|
-
>
|
|
89
|
-
<CloseSvgIcon />
|
|
90
|
-
</button>
|
|
91
|
-
)}
|
|
92
|
-
{helpText && (
|
|
93
|
-
<div className="flex items-center relative ml-3">
|
|
94
|
-
<div
|
|
95
|
-
className="relative cursor-pointer"
|
|
96
|
-
onMouseEnter={() => setShowTooltip(true)}
|
|
97
|
-
onMouseLeave={() => setShowTooltip(false)}
|
|
98
|
-
>
|
|
99
|
-
<IdeaIconSVG />
|
|
100
|
-
{showTooltip && (
|
|
101
|
-
<div className="absolute -left-48 top-0 mt-8 p-2 bg-white border rounded shadow text-black">
|
|
102
|
-
{helpText}
|
|
103
|
-
</div>
|
|
104
|
-
)}
|
|
105
|
-
</div>
|
|
106
|
-
</div>
|
|
107
|
-
)}
|
|
108
|
-
</div>
|
|
109
|
-
{error && (
|
|
110
|
-
<p className={`mt-2 text-sm text-${color}-600 dark:text-${color}-500`}>
|
|
111
|
-
<span className="font-medium">Oops!</span> {error}
|
|
112
|
-
</p>
|
|
113
|
-
)}
|
|
114
|
-
{!error && hint && (
|
|
115
|
-
<p
|
|
116
|
-
className={`mt-2 italic text-sm text-${color}-500 dark:text-${color}-400`}
|
|
117
|
-
>
|
|
118
|
-
{hint}
|
|
119
|
-
</p>
|
|
120
|
-
)}
|
|
121
|
-
</>
|
|
122
|
-
);
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
export const FormDatePicker = (props: Props) => {
|
|
126
|
-
const { formValidations } = useAppSelector((state) => state.formValidation);
|
|
127
|
-
const error = formValidations[props.formName ?? "-1"]?.[props.name ?? "-1"];
|
|
128
|
-
|
|
129
|
-
props = { ...props, error };
|
|
130
|
-
|
|
131
|
-
return <FormDatePickerWithoutValidation {...props} />;
|
|
132
|
-
};
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import { CalendarIconSVG, CloseSvgIcon, IdeaIconSVG } from "@zauru-sdk/icons";
|
|
3
|
+
import { useAppSelector } from "@zauru-sdk/redux";
|
|
4
|
+
|
|
5
|
+
type Props = {
|
|
6
|
+
id?: string;
|
|
7
|
+
name: string;
|
|
8
|
+
formName?: string;
|
|
9
|
+
title?: string;
|
|
10
|
+
hint?: string;
|
|
11
|
+
helpText?: string;
|
|
12
|
+
defaultValue?: string;
|
|
13
|
+
onChange?: (value: string) => void;
|
|
14
|
+
isClearable?: boolean;
|
|
15
|
+
tabIndex?: number;
|
|
16
|
+
error?: string;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
className?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const FormDatePickerWithoutValidation = (props: Props) => {
|
|
22
|
+
const {
|
|
23
|
+
id,
|
|
24
|
+
name,
|
|
25
|
+
title,
|
|
26
|
+
defaultValue = "",
|
|
27
|
+
hint,
|
|
28
|
+
helpText,
|
|
29
|
+
onChange,
|
|
30
|
+
tabIndex,
|
|
31
|
+
error,
|
|
32
|
+
disabled = false,
|
|
33
|
+
className = "",
|
|
34
|
+
isClearable = false,
|
|
35
|
+
} = props;
|
|
36
|
+
|
|
37
|
+
const [value, setValue] = useState<string | null>(defaultValue);
|
|
38
|
+
const [showTooltip, setShowTooltip] = useState<boolean>(false);
|
|
39
|
+
|
|
40
|
+
const color = error ? "red" : "gray";
|
|
41
|
+
|
|
42
|
+
const isReadOnly = disabled;
|
|
43
|
+
const bgColor = isReadOnly ? "bg-gray-200" : `bg-${color}-50`;
|
|
44
|
+
const textColor = isReadOnly ? "text-gray-500" : `text-${color}-500`;
|
|
45
|
+
const borderColor = isReadOnly ? "border-gray-300" : `border-${color}-200`;
|
|
46
|
+
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
setValue(defaultValue);
|
|
49
|
+
}, [defaultValue]);
|
|
50
|
+
|
|
51
|
+
const clearValue = () => {
|
|
52
|
+
setValue("");
|
|
53
|
+
onChange && onChange("");
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<>
|
|
58
|
+
{title && (
|
|
59
|
+
<label
|
|
60
|
+
htmlFor={error ? `${name}-error` : `${name}-success`}
|
|
61
|
+
className={`block text-sm font-medium ${textColor} ${className}`}
|
|
62
|
+
>
|
|
63
|
+
{title}
|
|
64
|
+
</label>
|
|
65
|
+
)}
|
|
66
|
+
<div className="flex relative items-center">
|
|
67
|
+
<div className="absolute left-0 flex items-center pl-3 pointer-events-none">
|
|
68
|
+
<CalendarIconSVG />
|
|
69
|
+
</div>
|
|
70
|
+
<input
|
|
71
|
+
id={id}
|
|
72
|
+
name={name}
|
|
73
|
+
tabIndex={tabIndex}
|
|
74
|
+
type="date"
|
|
75
|
+
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
76
|
+
setValue(e.target.value);
|
|
77
|
+
onChange && onChange(e.target.value);
|
|
78
|
+
}}
|
|
79
|
+
value={value ?? ""}
|
|
80
|
+
pattern="\d{4}-\d{2}-\d{2}"
|
|
81
|
+
className={`${bgColor} ${borderColor} ${textColor} text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full pl-10 p-2.5`}
|
|
82
|
+
></input>
|
|
83
|
+
{value && isClearable && (
|
|
84
|
+
<button
|
|
85
|
+
type="button"
|
|
86
|
+
onClick={clearValue}
|
|
87
|
+
className="absolute right-0 mr-10"
|
|
88
|
+
>
|
|
89
|
+
<CloseSvgIcon />
|
|
90
|
+
</button>
|
|
91
|
+
)}
|
|
92
|
+
{helpText && (
|
|
93
|
+
<div className="flex items-center relative ml-3">
|
|
94
|
+
<div
|
|
95
|
+
className="relative cursor-pointer"
|
|
96
|
+
onMouseEnter={() => setShowTooltip(true)}
|
|
97
|
+
onMouseLeave={() => setShowTooltip(false)}
|
|
98
|
+
>
|
|
99
|
+
<IdeaIconSVG />
|
|
100
|
+
{showTooltip && (
|
|
101
|
+
<div className="absolute -left-48 top-0 mt-8 p-2 bg-white border rounded shadow text-black">
|
|
102
|
+
{helpText}
|
|
103
|
+
</div>
|
|
104
|
+
)}
|
|
105
|
+
</div>
|
|
106
|
+
</div>
|
|
107
|
+
)}
|
|
108
|
+
</div>
|
|
109
|
+
{error && (
|
|
110
|
+
<p className={`mt-2 text-sm text-${color}-600 dark:text-${color}-500`}>
|
|
111
|
+
<span className="font-medium">Oops!</span> {error}
|
|
112
|
+
</p>
|
|
113
|
+
)}
|
|
114
|
+
{!error && hint && (
|
|
115
|
+
<p
|
|
116
|
+
className={`mt-2 italic text-sm text-${color}-500 dark:text-${color}-400`}
|
|
117
|
+
>
|
|
118
|
+
{hint}
|
|
119
|
+
</p>
|
|
120
|
+
)}
|
|
121
|
+
</>
|
|
122
|
+
);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export const FormDatePicker = (props: Props) => {
|
|
126
|
+
const { formValidations } = useAppSelector((state) => state.formValidation);
|
|
127
|
+
const error = formValidations[props.formName ?? "-1"]?.[props.name ?? "-1"];
|
|
128
|
+
|
|
129
|
+
props = { ...props, error };
|
|
130
|
+
|
|
131
|
+
return <FormDatePickerWithoutValidation {...props} />;
|
|
132
|
+
};
|