@zauru-sdk/components 6.5.6 → 6.7.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/CHANGELOG.md +22 -0
- package/dist/DiscountHistory/RejectionPercentageHistoryList.d.ts +24 -0
- package/dist/DiscountHistory/index.d.ts +1 -0
- package/dist/Form/Checkbox/index.d.ts +2 -0
- package/dist/esm/DiscountHistory/RejectionPercentageHistoryList.js +62 -0
- package/dist/esm/DiscountHistory/index.js +1 -0
- package/dist/esm/Form/Checkbox/index.js +7 -4
- package/dist/esm/index.js +1 -0
- package/dist/index.d.ts +1 -0
- package/package.json +8 -8
- package/src/DiscountHistory/RejectionPercentageHistoryList.tsx +158 -0
- package/src/DiscountHistory/index.ts +1 -0
- package/src/Form/Checkbox/index.tsx +33 -2
- package/src/index.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,28 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [6.7.0](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/components@6.6.0...@zauru-sdk/components@6.7.0) (2026-09-18)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
* descuento sucesivo en porcentajes de rechazo ([c437bbd](https://github.com/intuitiva/zauru-typescript-sdk/commit/c437bbd6a1305fd417c4ac55f8e07eb244f2fe3d))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
# [6.6.0](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/components@6.5.6...@zauru-sdk/components@6.6.0) (2026-09-18)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
### Features
|
|
21
|
+
|
|
22
|
+
* registrar reglas automáticas de % rechazo en el historial ([4784849](https://github.com/intuitiva/zauru-typescript-sdk/commit/4784849904f9ac6570e60543895a858dece8e039))
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
6
28
|
## [6.5.6](https://github.com/intuitiva/zauru-typescript-sdk/compare/@zauru-sdk/components@6.5.5...@zauru-sdk/components@6.5.6) (2026-09-17)
|
|
7
29
|
|
|
8
30
|
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
export type RejectionPercentageHistoryItem = {
|
|
2
|
+
discount: number;
|
|
3
|
+
description?: string;
|
|
4
|
+
agency_id?: number;
|
|
5
|
+
employee_id?: number;
|
|
6
|
+
employee_name?: string;
|
|
7
|
+
created_at?: string;
|
|
8
|
+
type?: string;
|
|
9
|
+
successive?: boolean;
|
|
10
|
+
};
|
|
11
|
+
type NamedRecord = {
|
|
12
|
+
id?: number;
|
|
13
|
+
name?: string;
|
|
14
|
+
};
|
|
15
|
+
export type RejectionPercentageHistoryListProps = {
|
|
16
|
+
items: RejectionPercentageHistoryItem[];
|
|
17
|
+
employees?: NamedRecord[];
|
|
18
|
+
agencies?: NamedRecord[];
|
|
19
|
+
actorLabel?: string;
|
|
20
|
+
emptyText?: string;
|
|
21
|
+
className?: string;
|
|
22
|
+
};
|
|
23
|
+
export declare const RejectionPercentageHistoryList: ({ items, employees, agencies, actorLabel, emptyText, className, }: RejectionPercentageHistoryListProps) => import("react/jsx-runtime").JSX.Element;
|
|
24
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./RejectionPercentageHistoryList.js";
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { isAutomaticRejectionRuleHistoryType, toFixedIfNeeded, } from "@zauru-sdk/common";
|
|
3
|
+
const formatHistoryDate = (value) => {
|
|
4
|
+
if (!value)
|
|
5
|
+
return "";
|
|
6
|
+
const date = new Date(value);
|
|
7
|
+
if (Number.isNaN(date.getTime()))
|
|
8
|
+
return value;
|
|
9
|
+
return new Intl.DateTimeFormat("es-GT", {
|
|
10
|
+
day: "2-digit",
|
|
11
|
+
month: "2-digit",
|
|
12
|
+
year: "numeric",
|
|
13
|
+
hour: "2-digit",
|
|
14
|
+
minute: "2-digit",
|
|
15
|
+
hour12: false,
|
|
16
|
+
})
|
|
17
|
+
.format(date)
|
|
18
|
+
.replace(",", "");
|
|
19
|
+
};
|
|
20
|
+
const formatSignedPercentage = (value, forceSign) => {
|
|
21
|
+
const formatted = toFixedIfNeeded(Math.abs(value));
|
|
22
|
+
if (value < 0)
|
|
23
|
+
return `-${formatted}%`;
|
|
24
|
+
if (forceSign && value > 0)
|
|
25
|
+
return `+${formatted}%`;
|
|
26
|
+
return `${formatted}%`;
|
|
27
|
+
};
|
|
28
|
+
const findName = (records, id) => {
|
|
29
|
+
if (id == null)
|
|
30
|
+
return undefined;
|
|
31
|
+
return records?.find((record) => record.id === id)?.name;
|
|
32
|
+
};
|
|
33
|
+
export const RejectionPercentageHistoryList = ({ items, employees, agencies, actorLabel = "Empleado", emptyText = "No hay historial de porcentajes registrado", className = "", }) => {
|
|
34
|
+
if (!items.length) {
|
|
35
|
+
return _jsx("p", { className: "text-gray-500 italic", children: emptyText });
|
|
36
|
+
}
|
|
37
|
+
return (_jsx("div", { className: `space-y-3 max-h-60 overflow-y-auto ${className}`.trim(), children: items.map((item, index) => {
|
|
38
|
+
const isAutomatic = isAutomaticRejectionRuleHistoryType(item.type);
|
|
39
|
+
const isSuccessive = item.successive === true;
|
|
40
|
+
const employeeName = item.employee_name?.trim() ||
|
|
41
|
+
findName(employees, item.employee_id) ||
|
|
42
|
+
(item.employee_id != null ? `ID: ${item.employee_id}` : "No especificado");
|
|
43
|
+
const agencyName = findName(agencies, item.agency_id) ||
|
|
44
|
+
(item.agency_id != null ? `ID: ${item.agency_id}` : "No especificada");
|
|
45
|
+
const description = item.description || "Sin descripción";
|
|
46
|
+
return (_jsxs("div", { className: isSuccessive
|
|
47
|
+
? "border border-amber-200 rounded-lg p-3 bg-amber-50"
|
|
48
|
+
: isAutomatic
|
|
49
|
+
? "border border-indigo-200 rounded-lg p-3 bg-indigo-50"
|
|
50
|
+
: "border border-gray-100 rounded-lg p-3 bg-gray-50", children: [_jsxs("div", { className: "flex justify-between items-start gap-3 mb-2", children: [_jsxs("div", { className: "flex items-center gap-2 min-w-0", children: [_jsx("span", { className: isSuccessive
|
|
51
|
+
? "font-semibold text-amber-800"
|
|
52
|
+
: isAutomatic
|
|
53
|
+
? "font-semibold text-indigo-800"
|
|
54
|
+
: "font-semibold text-blue-600", children: formatSignedPercentage(Number(item.discount) || 0, isAutomatic) }), isSuccessive ? (_jsx("span", { className: "shrink-0 whitespace-nowrap rounded-full bg-amber-100 px-2 py-0.5 text-xs font-medium text-amber-800", children: "Sucesivo" })) : null, isAutomatic ? (_jsx("span", { className: "shrink-0 whitespace-nowrap rounded-full bg-indigo-100 px-2 py-0.5 text-xs font-medium text-indigo-800", children: "Autom\u00E1tico" })) : null] }), item.created_at ? (_jsx("span", { className: "text-xs text-gray-500 shrink-0", children: formatHistoryDate(item.created_at) })) : null] }), _jsx("p", { className: isSuccessive
|
|
55
|
+
? "text-sm text-amber-900 mb-1"
|
|
56
|
+
: isAutomatic
|
|
57
|
+
? "text-sm text-indigo-900 mb-1"
|
|
58
|
+
: "text-sm text-gray-700 mb-1", title: description, children: description }), _jsxs("div", { className: "flex justify-between gap-3 text-xs text-gray-500", children: [_jsx("span", { className: "min-w-0", children: isAutomatic
|
|
59
|
+
? "Aplicado por el sistema"
|
|
60
|
+
: `${actorLabel}: ${employeeName}` }), _jsxs("span", { className: "shrink-0", children: ["Agencia: ", agencyName] })] })] }, `${item.created_at ?? "entry"}-${item.type ?? "manual"}-${index}`));
|
|
61
|
+
}) }));
|
|
62
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./RejectionPercentageHistoryList.js";
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { QuestionMarkIconSVG } from "@zauru-sdk/icons";
|
|
2
3
|
import { useEffect, useState } from "react";
|
|
3
4
|
import { useFormContext } from "react-hook-form";
|
|
4
5
|
export const CheckBox = (props) => {
|
|
5
|
-
const { id, name, defaultValue = false, onChange, disabled = false, label, required = false, } = props;
|
|
6
|
+
const { id, name, defaultValue = false, onChange, disabled = false, label, required = false, helpText, helpAriaLabel = "Más información", } = props;
|
|
6
7
|
const [checked, setChecked] = useState(defaultValue);
|
|
8
|
+
const [showHelp, setShowHelp] = useState(false);
|
|
7
9
|
useEffect(() => {
|
|
8
10
|
setChecked(defaultValue);
|
|
9
11
|
}, [defaultValue]);
|
|
@@ -27,9 +29,10 @@ export const CheckBox = (props) => {
|
|
|
27
29
|
: undefined; // Solo usar register si está disponible
|
|
28
30
|
const color = error ? "red" : "gray";
|
|
29
31
|
const borderColor = disabled ? "border-gray-300" : `border-${color}-500`;
|
|
30
|
-
const inputComponent = (_jsx("input", { type: "checkbox", id: id ?? name, checked: checked, className: `form-checkbox h-4 w-4 text-indigo-600 ${borderColor} focus:border-indigo-500 focus:ring-indigo-500`, disabled: disabled, ...(register ?? {}), name: name, onChange: handleInputChange }));
|
|
31
|
-
|
|
32
|
+
const inputComponent = (_jsx("input", { type: "checkbox", id: id ?? name, checked: checked, className: `form-checkbox h-4 w-4 text-indigo-600 ${borderColor} ${disabled ? "cursor-not-allowed" : "cursor-pointer"} focus:border-indigo-500 focus:ring-indigo-500`, disabled: disabled, ...(register ?? {}), name: name, onChange: handleInputChange }));
|
|
33
|
+
const helpButton = helpText ? (_jsxs("div", { className: "relative ml-2 shrink-0", children: [_jsx("button", { type: "button", className: "cursor-pointer inline-flex items-center justify-center text-gray-500 hover:text-indigo-600 focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500 focus-visible:ring-offset-1 rounded-full", "aria-label": helpAriaLabel, "aria-expanded": showHelp, onMouseEnter: () => setShowHelp(true), onMouseLeave: () => setShowHelp(false), onFocus: () => setShowHelp(true), onBlur: () => setShowHelp(false), children: _jsx(QuestionMarkIconSVG, {}) }), showHelp ? (_jsx("div", { className: "absolute z-50 left-1/2 -translate-x-1/2 bottom-full mb-2 w-72 max-w-[min(18rem,calc(100vw-2rem))] rounded border border-gray-200 bg-white p-2 text-left text-sm text-black shadow motion-reduce:transition-none", children: helpText })) : null] })) : null;
|
|
34
|
+
if (!error && !label && !helpText) {
|
|
32
35
|
return inputComponent;
|
|
33
36
|
}
|
|
34
|
-
return (_jsxs("div", { className: "col-span-6 sm:col-span-3", children: [_jsxs("div", { className: `flex items-center ${borderColor}`, children: [inputComponent, label && (_jsxs("label", { htmlFor: id ?? name, className: `ml-2 block text-sm font-medium text-${color}-700 dark:text-${color}-500`, children: [label, required && _jsx("span", { className: "text-red-500", children: "*" })] }))] }), error && (_jsxs("p", { className: `mt-2 text-sm text-${color}-600 dark:text-${color}-500`, children: [_jsx("span", { className: "font-medium", children: "Oops!" }), " ", error.message?.toString()] }))] }));
|
|
37
|
+
return (_jsxs("div", { className: "col-span-6 sm:col-span-3", children: [_jsxs("div", { className: `flex items-center ${borderColor}`, children: [inputComponent, label && (_jsxs("label", { htmlFor: id ?? name, className: `ml-2 block text-sm font-medium text-${color}-700 dark:text-${color}-500`, children: [label, required && _jsx("span", { className: "text-red-500", children: "*" })] })), helpButton] }), error && (_jsxs("p", { className: `mt-2 text-sm text-${color}-600 dark:text-${color}-500`, children: [_jsx("span", { className: "font-medium", children: "Oops!" }), " ", error.message?.toString()] }))] }));
|
|
35
38
|
};
|
package/dist/esm/index.js
CHANGED
package/dist/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zauru-sdk/components",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.7.0",
|
|
4
4
|
"description": "Componentes reutilizables en las WebApps de Zauru.",
|
|
5
5
|
"main": "./dist/esm/index.js",
|
|
6
6
|
"module": "./dist/esm/index.js",
|
|
@@ -44,12 +44,12 @@
|
|
|
44
44
|
"@reduxjs/toolkit": "^2.2.1",
|
|
45
45
|
"@remix-run/node": "^2.8.1",
|
|
46
46
|
"@remix-run/react": "^2.8.1",
|
|
47
|
-
"@zauru-sdk/common": "^6.
|
|
48
|
-
"@zauru-sdk/hooks": "^6.3.
|
|
49
|
-
"@zauru-sdk/icons": "^6.
|
|
50
|
-
"@zauru-sdk/redux": "^6.5.
|
|
51
|
-
"@zauru-sdk/types": "^6.
|
|
52
|
-
"@zauru-sdk/utils": "^6.
|
|
47
|
+
"@zauru-sdk/common": "^6.8.0",
|
|
48
|
+
"@zauru-sdk/hooks": "^6.3.13",
|
|
49
|
+
"@zauru-sdk/icons": "^6.1.0",
|
|
50
|
+
"@zauru-sdk/redux": "^6.5.11",
|
|
51
|
+
"@zauru-sdk/types": "^6.18.0",
|
|
52
|
+
"@zauru-sdk/utils": "^6.18.0",
|
|
53
53
|
"browser-image-compression": "^2.0.2",
|
|
54
54
|
"framer-motion": "^12.0.0",
|
|
55
55
|
"jsonwebtoken": "^9.0.2",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"styled-components": "^5.3.5",
|
|
63
63
|
"zod": "^3.23.8"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "c5b785baa29fdd2ab7f42a9077ba5cbe5c7c9707"
|
|
66
66
|
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import {
|
|
3
|
+
isAutomaticRejectionRuleHistoryType,
|
|
4
|
+
toFixedIfNeeded,
|
|
5
|
+
} from "@zauru-sdk/common";
|
|
6
|
+
|
|
7
|
+
export type RejectionPercentageHistoryItem = {
|
|
8
|
+
discount: number;
|
|
9
|
+
description?: string;
|
|
10
|
+
agency_id?: number;
|
|
11
|
+
employee_id?: number;
|
|
12
|
+
employee_name?: string;
|
|
13
|
+
created_at?: string;
|
|
14
|
+
type?: string;
|
|
15
|
+
successive?: boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
type NamedRecord = {
|
|
19
|
+
id?: number;
|
|
20
|
+
name?: string;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type RejectionPercentageHistoryListProps = {
|
|
24
|
+
items: RejectionPercentageHistoryItem[];
|
|
25
|
+
employees?: NamedRecord[];
|
|
26
|
+
agencies?: NamedRecord[];
|
|
27
|
+
actorLabel?: string;
|
|
28
|
+
emptyText?: string;
|
|
29
|
+
className?: string;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const formatHistoryDate = (value?: string): string => {
|
|
33
|
+
if (!value) return "";
|
|
34
|
+
const date = new Date(value);
|
|
35
|
+
if (Number.isNaN(date.getTime())) return value;
|
|
36
|
+
return new Intl.DateTimeFormat("es-GT", {
|
|
37
|
+
day: "2-digit",
|
|
38
|
+
month: "2-digit",
|
|
39
|
+
year: "numeric",
|
|
40
|
+
hour: "2-digit",
|
|
41
|
+
minute: "2-digit",
|
|
42
|
+
hour12: false,
|
|
43
|
+
})
|
|
44
|
+
.format(date)
|
|
45
|
+
.replace(",", "");
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const formatSignedPercentage = (
|
|
49
|
+
value: number,
|
|
50
|
+
forceSign: boolean,
|
|
51
|
+
): string => {
|
|
52
|
+
const formatted = toFixedIfNeeded(Math.abs(value));
|
|
53
|
+
if (value < 0) return `-${formatted}%`;
|
|
54
|
+
if (forceSign && value > 0) return `+${formatted}%`;
|
|
55
|
+
return `${formatted}%`;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const findName = (
|
|
59
|
+
records: NamedRecord[] | undefined,
|
|
60
|
+
id: number | undefined,
|
|
61
|
+
): string | undefined => {
|
|
62
|
+
if (id == null) return undefined;
|
|
63
|
+
return records?.find((record) => record.id === id)?.name;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export const RejectionPercentageHistoryList = ({
|
|
67
|
+
items,
|
|
68
|
+
employees,
|
|
69
|
+
agencies,
|
|
70
|
+
actorLabel = "Empleado",
|
|
71
|
+
emptyText = "No hay historial de porcentajes registrado",
|
|
72
|
+
className = "",
|
|
73
|
+
}: RejectionPercentageHistoryListProps) => {
|
|
74
|
+
if (!items.length) {
|
|
75
|
+
return <p className="text-gray-500 italic">{emptyText}</p>;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<div className={`space-y-3 max-h-60 overflow-y-auto ${className}`.trim()}>
|
|
80
|
+
{items.map((item, index) => {
|
|
81
|
+
const isAutomatic = isAutomaticRejectionRuleHistoryType(item.type);
|
|
82
|
+
const isSuccessive = item.successive === true;
|
|
83
|
+
const employeeName =
|
|
84
|
+
item.employee_name?.trim() ||
|
|
85
|
+
findName(employees, item.employee_id) ||
|
|
86
|
+
(item.employee_id != null ? `ID: ${item.employee_id}` : "No especificado");
|
|
87
|
+
const agencyName =
|
|
88
|
+
findName(agencies, item.agency_id) ||
|
|
89
|
+
(item.agency_id != null ? `ID: ${item.agency_id}` : "No especificada");
|
|
90
|
+
const description = item.description || "Sin descripción";
|
|
91
|
+
|
|
92
|
+
return (
|
|
93
|
+
<div
|
|
94
|
+
key={`${item.created_at ?? "entry"}-${item.type ?? "manual"}-${index}`}
|
|
95
|
+
className={
|
|
96
|
+
isSuccessive
|
|
97
|
+
? "border border-amber-200 rounded-lg p-3 bg-amber-50"
|
|
98
|
+
: isAutomatic
|
|
99
|
+
? "border border-indigo-200 rounded-lg p-3 bg-indigo-50"
|
|
100
|
+
: "border border-gray-100 rounded-lg p-3 bg-gray-50"
|
|
101
|
+
}
|
|
102
|
+
>
|
|
103
|
+
<div className="flex justify-between items-start gap-3 mb-2">
|
|
104
|
+
<div className="flex items-center gap-2 min-w-0">
|
|
105
|
+
<span
|
|
106
|
+
className={
|
|
107
|
+
isSuccessive
|
|
108
|
+
? "font-semibold text-amber-800"
|
|
109
|
+
: isAutomatic
|
|
110
|
+
? "font-semibold text-indigo-800"
|
|
111
|
+
: "font-semibold text-blue-600"
|
|
112
|
+
}
|
|
113
|
+
>
|
|
114
|
+
{formatSignedPercentage(Number(item.discount) || 0, isAutomatic)}
|
|
115
|
+
</span>
|
|
116
|
+
{isSuccessive ? (
|
|
117
|
+
<span className="shrink-0 whitespace-nowrap rounded-full bg-amber-100 px-2 py-0.5 text-xs font-medium text-amber-800">
|
|
118
|
+
Sucesivo
|
|
119
|
+
</span>
|
|
120
|
+
) : null}
|
|
121
|
+
{isAutomatic ? (
|
|
122
|
+
<span className="shrink-0 whitespace-nowrap rounded-full bg-indigo-100 px-2 py-0.5 text-xs font-medium text-indigo-800">
|
|
123
|
+
Automático
|
|
124
|
+
</span>
|
|
125
|
+
) : null}
|
|
126
|
+
</div>
|
|
127
|
+
{item.created_at ? (
|
|
128
|
+
<span className="text-xs text-gray-500 shrink-0">
|
|
129
|
+
{formatHistoryDate(item.created_at)}
|
|
130
|
+
</span>
|
|
131
|
+
) : null}
|
|
132
|
+
</div>
|
|
133
|
+
<p
|
|
134
|
+
className={
|
|
135
|
+
isSuccessive
|
|
136
|
+
? "text-sm text-amber-900 mb-1"
|
|
137
|
+
: isAutomatic
|
|
138
|
+
? "text-sm text-indigo-900 mb-1"
|
|
139
|
+
: "text-sm text-gray-700 mb-1"
|
|
140
|
+
}
|
|
141
|
+
title={description}
|
|
142
|
+
>
|
|
143
|
+
{description}
|
|
144
|
+
</p>
|
|
145
|
+
<div className="flex justify-between gap-3 text-xs text-gray-500">
|
|
146
|
+
<span className="min-w-0">
|
|
147
|
+
{isAutomatic
|
|
148
|
+
? "Aplicado por el sistema"
|
|
149
|
+
: `${actorLabel}: ${employeeName}`}
|
|
150
|
+
</span>
|
|
151
|
+
<span className="shrink-0">Agencia: {agencyName}</span>
|
|
152
|
+
</div>
|
|
153
|
+
</div>
|
|
154
|
+
);
|
|
155
|
+
})}
|
|
156
|
+
</div>
|
|
157
|
+
);
|
|
158
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./RejectionPercentageHistoryList.js";
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { QuestionMarkIconSVG } from "@zauru-sdk/icons";
|
|
1
2
|
import React, { useEffect, useState } from "react";
|
|
2
3
|
import { useFormContext } from "react-hook-form";
|
|
3
4
|
|
|
@@ -13,6 +14,8 @@ type Props = {
|
|
|
13
14
|
disabled?: boolean;
|
|
14
15
|
borderColor?: string;
|
|
15
16
|
required?: boolean;
|
|
17
|
+
helpText?: string;
|
|
18
|
+
helpAriaLabel?: string;
|
|
16
19
|
};
|
|
17
20
|
|
|
18
21
|
export const CheckBox = (props: Props) => {
|
|
@@ -24,9 +27,12 @@ export const CheckBox = (props: Props) => {
|
|
|
24
27
|
disabled = false,
|
|
25
28
|
label,
|
|
26
29
|
required = false,
|
|
30
|
+
helpText,
|
|
31
|
+
helpAriaLabel = "Más información",
|
|
27
32
|
} = props;
|
|
28
33
|
|
|
29
34
|
const [checked, setChecked] = useState(defaultValue);
|
|
35
|
+
const [showHelp, setShowHelp] = useState(false);
|
|
30
36
|
|
|
31
37
|
useEffect(() => {
|
|
32
38
|
setChecked(defaultValue);
|
|
@@ -63,7 +69,9 @@ export const CheckBox = (props: Props) => {
|
|
|
63
69
|
type="checkbox"
|
|
64
70
|
id={id ?? name}
|
|
65
71
|
checked={checked}
|
|
66
|
-
className={`form-checkbox h-4 w-4 text-indigo-600 ${borderColor}
|
|
72
|
+
className={`form-checkbox h-4 w-4 text-indigo-600 ${borderColor} ${
|
|
73
|
+
disabled ? "cursor-not-allowed" : "cursor-pointer"
|
|
74
|
+
} focus:border-indigo-500 focus:ring-indigo-500`}
|
|
67
75
|
disabled={disabled}
|
|
68
76
|
{...(register ?? {})}
|
|
69
77
|
name={name}
|
|
@@ -71,7 +79,29 @@ export const CheckBox = (props: Props) => {
|
|
|
71
79
|
/>
|
|
72
80
|
);
|
|
73
81
|
|
|
74
|
-
|
|
82
|
+
const helpButton = helpText ? (
|
|
83
|
+
<div className="relative ml-2 shrink-0">
|
|
84
|
+
<button
|
|
85
|
+
type="button"
|
|
86
|
+
className="cursor-pointer inline-flex items-center justify-center text-gray-500 hover:text-indigo-600 focus:outline-none focus-visible:ring-2 focus-visible:ring-indigo-500 focus-visible:ring-offset-1 rounded-full"
|
|
87
|
+
aria-label={helpAriaLabel}
|
|
88
|
+
aria-expanded={showHelp}
|
|
89
|
+
onMouseEnter={() => setShowHelp(true)}
|
|
90
|
+
onMouseLeave={() => setShowHelp(false)}
|
|
91
|
+
onFocus={() => setShowHelp(true)}
|
|
92
|
+
onBlur={() => setShowHelp(false)}
|
|
93
|
+
>
|
|
94
|
+
<QuestionMarkIconSVG />
|
|
95
|
+
</button>
|
|
96
|
+
{showHelp ? (
|
|
97
|
+
<div className="absolute z-50 left-1/2 -translate-x-1/2 bottom-full mb-2 w-72 max-w-[min(18rem,calc(100vw-2rem))] rounded border border-gray-200 bg-white p-2 text-left text-sm text-black shadow motion-reduce:transition-none">
|
|
98
|
+
{helpText}
|
|
99
|
+
</div>
|
|
100
|
+
) : null}
|
|
101
|
+
</div>
|
|
102
|
+
) : null;
|
|
103
|
+
|
|
104
|
+
if (!error && !label && !helpText) {
|
|
75
105
|
return inputComponent;
|
|
76
106
|
}
|
|
77
107
|
|
|
@@ -88,6 +118,7 @@ export const CheckBox = (props: Props) => {
|
|
|
88
118
|
{required && <span className="text-red-500">*</span>}
|
|
89
119
|
</label>
|
|
90
120
|
)}
|
|
121
|
+
{helpButton}
|
|
91
122
|
</div>
|
|
92
123
|
{error && (
|
|
93
124
|
<p className={`mt-2 text-sm text-${color}-600 dark:text-${color}-500`}>
|
package/src/index.ts
CHANGED