@ews-admin/global-design-system 1.1.11 → 1.1.13
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/README.md +3 -3
- package/dist/components/Button/Button.d.ts +1 -1
- package/dist/components/Button/Button.d.ts.map +1 -1
- package/dist/index.css +1 -1
- package/dist/index.d.ts +15 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.css +1 -1
- package/dist/index.esm.js +36 -11
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +37 -10
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts +13 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/Button/Button.tsx +20 -18
- package/src/components/Modal/Modal.tsx +2 -2
- package/src/index.ts +9 -1
- package/src/utils/index.ts +21 -0
package/dist/index.js
CHANGED
|
@@ -65,16 +65,35 @@ function debounce(func, wait) {
|
|
|
65
65
|
function generateId(prefix = "ews") {
|
|
66
66
|
return `${prefix}-${Math.random().toString(36).substr(2, 9)}`;
|
|
67
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* Utility function to format numeric input by removing non-digit characters
|
|
70
|
+
* @param value - String value to format
|
|
71
|
+
* @returns String with only numeric characters
|
|
72
|
+
*/
|
|
73
|
+
const formatNumeric = (value) => {
|
|
74
|
+
return value.replace(/\D/g, "");
|
|
75
|
+
};
|
|
76
|
+
/**
|
|
77
|
+
* Utility function to validate phone numbers
|
|
78
|
+
* Validates phone numbers with 1-15 digits, starting with a non-zero digit
|
|
79
|
+
* @param value - Phone number string to validate
|
|
80
|
+
* @returns Boolean indicating if the phone number is valid
|
|
81
|
+
*/
|
|
82
|
+
function isValidPhoneNumber(value) {
|
|
83
|
+
const trimmedValue = value.trim();
|
|
84
|
+
const phoneRegex = /^[0-9]\d{1,14}$/;
|
|
85
|
+
return phoneRegex.test(trimmedValue);
|
|
86
|
+
}
|
|
68
87
|
|
|
69
|
-
const Button = React.forwardRef(({ className, variant = "primary", size = "md", loading = false, fullWidth = false, leftIcon, rightIcon, children, disabled, ...props }, ref) => {
|
|
70
|
-
const baseStyles = "inline-flex items-center justify-center font-medium rounded-md transition-colors focus:outline-none
|
|
88
|
+
const Button = React.forwardRef(({ className, variant = "ews-primary", size = "md", loading = false, fullWidth = false, leftIcon, rightIcon, children, disabled, ...props }, ref) => {
|
|
89
|
+
const baseStyles = "inline-flex items-center justify-center font-medium rounded-md transition-colors focus:outline-none disabled:opacity-50 disabled:pointer-events-none";
|
|
71
90
|
const variants = {
|
|
72
|
-
primary: "bg-ews-primary text-white hover:bg-ews-primary-hover
|
|
73
|
-
secondary: "bg-ews-secondary text-white hover:bg-ews-secondary-hover
|
|
74
|
-
success: "bg-ews-success text-white hover:bg-ews-success-hover
|
|
75
|
-
warning: "bg-ews-warning text-white hover:bg-ews-warning-hover
|
|
76
|
-
error: "bg-ews-error text-white hover:bg-ews-error-hover
|
|
77
|
-
|
|
91
|
+
"ews-primary": "bg-ews-primary text-white hover:bg-ews-primary-hover",
|
|
92
|
+
"ews-secondary": "bg-ews-secondary text-white hover:bg-ews-secondary-hover",
|
|
93
|
+
success: "bg-ews-success text-white hover:bg-ews-success-hover",
|
|
94
|
+
warning: "bg-ews-warning text-white hover:bg-ews-warning-hover",
|
|
95
|
+
error: "bg-ews-error text-white hover:bg-ews-error-hover",
|
|
96
|
+
outline: "bg-transparent text-sm font-medium text-ews-primary hover:text-ews-primary/80",
|
|
78
97
|
};
|
|
79
98
|
const sizes = {
|
|
80
99
|
sm: "px-3 py-1.5 text-sm",
|
|
@@ -86,7 +105,7 @@ const Button = React.forwardRef(({ className, variant = "primary", size = "md",
|
|
|
86
105
|
md: "h-5 w-5",
|
|
87
106
|
lg: "h-6 w-6",
|
|
88
107
|
};
|
|
89
|
-
return (jsxRuntime.jsxs("button", { className: cn(baseStyles, variants[variant], sizes[size], fullWidth && "w-full", className), ref: ref, disabled: disabled || loading, ...props, children: [loading && (jsxRuntime.jsxs("svg", { className: "
|
|
108
|
+
return (jsxRuntime.jsxs("button", { className: cn(baseStyles, variants[variant], sizes[size], fullWidth && "w-full", className), ref: ref, disabled: disabled || loading, ...props, children: [loading && (jsxRuntime.jsxs("svg", { className: "mr-2 -ml-1 w-4 h-4 animate-spin", xmlns: "http://www.w3.org/2000/svg", fill: "none", viewBox: "0 0 24 24", children: [jsxRuntime.jsx("circle", { className: "opacity-25", cx: "12", cy: "12", r: "10", stroke: "currentColor", strokeWidth: "4" }), jsxRuntime.jsx("path", { className: "opacity-75", fill: "currentColor", d: "M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z" })] })), !loading && leftIcon && (jsxRuntime.jsx("span", { className: cn("flex items-center mr-2", iconSizes[size]), children: leftIcon })), children, !loading && rightIcon && (jsxRuntime.jsx("span", { className: cn("flex items-center ml-2", iconSizes[size]), children: rightIcon }))] }));
|
|
90
109
|
});
|
|
91
110
|
Button.displayName = "Button";
|
|
92
111
|
|
|
@@ -1125,6 +1144,7 @@ function useController(props) {
|
|
|
1125
1144
|
exact: true,
|
|
1126
1145
|
});
|
|
1127
1146
|
const _props = React.useRef(props);
|
|
1147
|
+
const _previousNameRef = React.useRef(undefined);
|
|
1128
1148
|
const _registerProps = React.useRef(control.register(name, {
|
|
1129
1149
|
...props.rules,
|
|
1130
1150
|
value,
|
|
@@ -1190,6 +1210,10 @@ function useController(props) {
|
|
|
1190
1210
|
}), [name, disabled, formState.disabled, onChange, onBlur, ref, value]);
|
|
1191
1211
|
React.useEffect(() => {
|
|
1192
1212
|
const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
|
|
1213
|
+
const previousName = _previousNameRef.current;
|
|
1214
|
+
if (previousName && previousName !== name && !isArrayField) {
|
|
1215
|
+
control.unregister(previousName);
|
|
1216
|
+
}
|
|
1193
1217
|
control.register(name, {
|
|
1194
1218
|
..._props.current.rules,
|
|
1195
1219
|
...(isBoolean(_props.current.disabled)
|
|
@@ -1211,6 +1235,7 @@ function useController(props) {
|
|
|
1211
1235
|
}
|
|
1212
1236
|
}
|
|
1213
1237
|
!isArrayField && control.register(name);
|
|
1238
|
+
_previousNameRef.current = name;
|
|
1214
1239
|
return () => {
|
|
1215
1240
|
(isArrayField
|
|
1216
1241
|
? _shouldUnregisterField && !control._state.action
|
|
@@ -1565,7 +1590,7 @@ const Modal = ({ isOpen, onClose, title, children, variant = "info", primaryActi
|
|
|
1565
1590
|
onClose();
|
|
1566
1591
|
}
|
|
1567
1592
|
};
|
|
1568
|
-
return (jsxRuntime.jsxs("div", { className: "flex fixed inset-0 z-50 justify-center items-center", children: [jsxRuntime.jsx("div", { className: "absolute inset-0 backdrop-blur-sm bg-black/50", onClick: handleOverlayClick }), jsxRuntime.jsxs("div", { className: cn("relative mx-4 w-full max-w-md bg-white rounded-lg shadow-xl transition-all transform", "duration-200 animate-in fade-in-0 zoom-in-95", className), role: "dialog", "aria-modal": "true", "aria-labelledby": "modal-title", children: [jsxRuntime.jsxs("div", { className: cn("flex items-center justify-between p-6 border-b", variantStyles.borderColor), children: [jsxRuntime.jsxs("div", { className: "flex items-center space-x-3", children: [jsxRuntime.jsx("div", { className: cn("p-2 rounded-full", variantStyles.iconBg), children: variantStyles.icon }), jsxRuntime.jsx("h2", { id: "modal-title", className: cn("text-lg font-semibold", variantStyles.titleColor), children: title })] }), jsxRuntime.jsx("button", { onClick: onClose, className: "p-1 text-gray-400 transition-colors hover:text-gray-600", "aria-label": "Close modal", children: jsxRuntime.jsx(X, { className: "w-5 h-5" }) })] }), jsxRuntime.jsx("div", { className: cn("p-6", contentClassName), children: jsxRuntime.jsx("div", { className: "leading-relaxed text-gray-700", children: error && variant === "error" ? (jsxRuntime.jsxs("div", { className: "space-y-3", children: [jsxRuntime.jsx("p", { children: error.message }), error.fields && error.fields.length > 0 && (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("p", { className: "font-semibold text-gray-900", children: "Erreurs de champ:" }), jsxRuntime.jsx("ul", { className: "mt-2 space-y-1", children: error.fields.map((field, index) => (jsxRuntime.jsxs("li", { className: "text-ews-error", children: ["\u2022 ", field.path, ": ", field.message] }, index))) })] }))] })) : (children) }) }), (primaryAction || secondaryAction) && (jsxRuntime.jsxs("div", { className: "flex justify-end items-center p-6 pt-0 space-x-3", children: [secondaryAction && (jsxRuntime.jsx(Button, { variant: "
|
|
1593
|
+
return (jsxRuntime.jsxs("div", { className: "flex fixed inset-0 z-50 justify-center items-center", children: [jsxRuntime.jsx("div", { className: "absolute inset-0 backdrop-blur-sm bg-black/50", onClick: handleOverlayClick }), jsxRuntime.jsxs("div", { className: cn("relative mx-4 w-full max-w-md bg-white rounded-lg shadow-xl transition-all transform", "duration-200 animate-in fade-in-0 zoom-in-95", className), role: "dialog", "aria-modal": "true", "aria-labelledby": "modal-title", children: [jsxRuntime.jsxs("div", { className: cn("flex items-center justify-between p-6 border-b", variantStyles.borderColor), children: [jsxRuntime.jsxs("div", { className: "flex items-center space-x-3", children: [jsxRuntime.jsx("div", { className: cn("p-2 rounded-full", variantStyles.iconBg), children: variantStyles.icon }), jsxRuntime.jsx("h2", { id: "modal-title", className: cn("text-lg font-semibold", variantStyles.titleColor), children: title })] }), jsxRuntime.jsx("button", { onClick: onClose, className: "p-1 text-gray-400 transition-colors hover:text-gray-600", "aria-label": "Close modal", children: jsxRuntime.jsx(X, { className: "w-5 h-5" }) })] }), jsxRuntime.jsx("div", { className: cn("p-6", contentClassName), children: jsxRuntime.jsx("div", { className: "leading-relaxed text-gray-700", children: error && variant === "error" ? (jsxRuntime.jsxs("div", { className: "space-y-3", children: [jsxRuntime.jsx("p", { children: error.message }), error.fields && error.fields.length > 0 && (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx("p", { className: "font-semibold text-gray-900", children: "Erreurs de champ:" }), jsxRuntime.jsx("ul", { className: "mt-2 space-y-1", children: error.fields.map((field, index) => (jsxRuntime.jsxs("li", { className: "text-ews-error", children: ["\u2022 ", field.path, ": ", field.message] }, index))) })] }))] })) : (children) }) }), (primaryAction || secondaryAction) && (jsxRuntime.jsxs("div", { className: "flex justify-end items-center p-6 pt-0 space-x-3", children: [secondaryAction && (jsxRuntime.jsx(Button, { variant: "outline", onClick: onSecondaryAction || onClose, disabled: isLoading, children: secondaryAction })), primaryAction && (jsxRuntime.jsx(Button, { variant: variant === "error" ? "error" : "ews-primary", onClick: onPrimaryAction, loading: isLoading, children: primaryAction }))] }))] })] }));
|
|
1569
1594
|
};
|
|
1570
1595
|
|
|
1571
1596
|
const Logo = ({ size = "md", showTagline: _showTagline = true, iconOnly = false, variant = "normal", className, onClick, }) => {
|
|
@@ -1785,7 +1810,9 @@ exports.cn = cn;
|
|
|
1785
1810
|
exports.debounce = debounce;
|
|
1786
1811
|
exports.formatCurrency = formatCurrency;
|
|
1787
1812
|
exports.formatDate = formatDate;
|
|
1813
|
+
exports.formatNumeric = formatNumeric;
|
|
1788
1814
|
exports.generateId = generateId;
|
|
1815
|
+
exports.isValidPhoneNumber = isValidPhoneNumber;
|
|
1789
1816
|
exports.useDebounce = useDebounce;
|
|
1790
1817
|
exports.useDebouncedCallback = useDebouncedCallback;
|
|
1791
1818
|
exports.useSelectField = useSelectField;
|