@ews-admin/global-design-system 1.5.0 → 1.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/dist/components/DropdownMultiSelect/DropdownMultiSelect.d.ts.map +1 -1
- package/dist/components/Input/Input.d.ts.map +1 -1
- package/dist/components/Logo/Logo.d.ts.map +1 -1
- package/dist/components/Modal/Modal.d.ts.map +1 -1
- package/dist/components/MultiSearchAutocomplete/MultiSearchAutocomplete.d.ts +1 -1
- package/dist/components/MultiSearchAutocomplete/MultiSearchAutocomplete.d.ts.map +1 -1
- package/dist/components/PhoneInput/PhoneInput.d.ts.map +1 -1
- package/dist/hooks/useSelectField.d.ts +1 -1
- package/dist/hooks/useSelectField.d.ts.map +1 -1
- package/dist/index.css +5 -3
- package/dist/index.d.ts +4 -4
- package/dist/index.esm.css +5 -3
- package/dist/index.esm.js +141 -111
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +141 -111
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/Input/Input.tsx +25 -0
- package/src/components/PhoneInput/PhoneInput.tsx +16 -2
- package/src/utils/env-config.ts +2 -2
package/dist/index.js
CHANGED
|
@@ -3,13 +3,13 @@
|
|
|
3
3
|
var jsxRuntime = require('react/jsx-runtime');
|
|
4
4
|
var React = require('react');
|
|
5
5
|
|
|
6
|
-
function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e))
|
|
6
|
+
function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e))for(t=0;t<e.length;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);else for(t in e)e[t]&&(n&&(n+=" "),n+=t);return n}function clsx(){for(var e,t,f=0,n="";f<arguments.length;)(e=arguments[f++])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
|
|
7
7
|
|
|
8
8
|
const LOCAL_PORTS = {
|
|
9
9
|
bff: 8082,
|
|
10
10
|
loginBff: 8080,
|
|
11
11
|
app: 3000,
|
|
12
|
-
login:
|
|
12
|
+
login: 4001,
|
|
13
13
|
dashboard: 3002,
|
|
14
14
|
admin: 3008,
|
|
15
15
|
};
|
|
@@ -64,7 +64,7 @@ function createEnvConfig(env, overrides) {
|
|
|
64
64
|
* Available country codes supported by the platform
|
|
65
65
|
*/
|
|
66
66
|
const COUNTRY_CODES = [
|
|
67
|
-
{ code: "+221", country: "SN" },
|
|
67
|
+
{ code: "+221", country: "SN" },
|
|
68
68
|
{ code: "+235", country: "TD" }, // Chad
|
|
69
69
|
];
|
|
70
70
|
/**
|
|
@@ -32545,7 +32545,7 @@ const UserIcon = ({ size = 24, color = "currentColor", className = "", ...props
|
|
|
32545
32545
|
return jsxRuntime.jsx(User, { size: size, color: color, className: className, ...props });
|
|
32546
32546
|
};
|
|
32547
32547
|
|
|
32548
|
-
const Input = React.forwardRef(({ className, variant = "default", size = "md", label, helperText, error, leftIcon, rightIcon, fullWidth = false, showPasswordToggle = false, required = false, countryCodeSelect, leftAddon, rightAddon, id, type = "text", ...props }, ref) => {
|
|
32548
|
+
const Input = React.forwardRef(({ className, variant = "default", size = "md", label, helperText, error, leftIcon, rightIcon, fullWidth = false, showPasswordToggle = false, required = false, countryCodeSelect, leftAddon, rightAddon, id, type = "text", onChange, onBlur, ...props }, ref) => {
|
|
32549
32549
|
const inputId = id || `input-${Math.random().toString(36).substr(2, 9)}`;
|
|
32550
32550
|
const hasError = Boolean(error);
|
|
32551
32551
|
const actualVariant = hasError ? "error" : variant;
|
|
@@ -32554,6 +32554,24 @@ const Input = React.forwardRef(({ className, variant = "default", size = "md", l
|
|
|
32554
32554
|
const isPasswordInput = type === "password";
|
|
32555
32555
|
const shouldShowPasswordToggle = showPasswordToggle && isPasswordInput;
|
|
32556
32556
|
const actualType = isPasswordInput && showPassword ? "text" : type;
|
|
32557
|
+
// Normalize spaces for text-like inputs
|
|
32558
|
+
const shouldNormalize = type !== "password" && type !== "number" && type !== "checkbox";
|
|
32559
|
+
const handleChange = (e) => {
|
|
32560
|
+
if (shouldNormalize) {
|
|
32561
|
+
e.target.value = e.target.value.replace(/^\s+/, "").replace(/\s{2,}/g, " ");
|
|
32562
|
+
}
|
|
32563
|
+
onChange?.(e);
|
|
32564
|
+
};
|
|
32565
|
+
const handleBlur = (e) => {
|
|
32566
|
+
if (shouldNormalize && onChange) {
|
|
32567
|
+
const trimmed = e.target.value.replace(/\s+$/, "");
|
|
32568
|
+
if (trimmed !== e.target.value) {
|
|
32569
|
+
e.target.value = trimmed;
|
|
32570
|
+
onChange(e);
|
|
32571
|
+
}
|
|
32572
|
+
}
|
|
32573
|
+
onBlur?.(e);
|
|
32574
|
+
};
|
|
32557
32575
|
// Country code dropdown state
|
|
32558
32576
|
const [isDropdownOpen, setIsDropdownOpen] = React.useState(false);
|
|
32559
32577
|
const dropdownRef = React.useRef(null);
|
|
@@ -32604,7 +32622,7 @@ const Input = React.forwardRef(({ className, variant = "default", size = "md", l
|
|
|
32604
32622
|
countryCodeSelect.onChange(item.code);
|
|
32605
32623
|
setIsDropdownOpen(false);
|
|
32606
32624
|
}, className: cn("px-3 py-2 text-sm cursor-pointer transition-colors", isSelected && "bg-ews-primary text-white", !isSelected && "hover:bg-ews-gray-50"), children: [jsxRuntime.jsx("span", { className: "font-medium", children: item.code }), item.country && (jsxRuntime.jsx("span", { className: cn("ml-2 text-xs", isSelected ? "text-white/80" : "text-ews-gray-500"), children: item.country }))] }, item.code));
|
|
32607
|
-
}) }))] }) })), leftIcon && !countryCodeSelect && !leftAddon && (jsxRuntime.jsx("div", { className: "flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none", children: jsxRuntime.jsx("span", { className: cn("text-ews-gray-400", iconSizes[size]), children: leftIcon }) })), leftAddon && !countryCodeSelect && !leftIcon && (jsxRuntime.jsx("div", { className: "flex absolute inset-y-0 left-0 items-center pointer-events-none overflow-hidden rounded-l-md", children: jsxRuntime.jsx("span", { className: "flex items-center h-full px-3 text-sm font-medium whitespace-nowrap bg-ews-gray-50 border-r border-ews-gray-300 text-ews-gray-600", children: leftAddon }) })), jsxRuntime.jsx("input", { id: inputId, type: actualType, className: cn(baseStyles, variants[actualVariant], sizes[size], countryCodeSelect && "pl-24", leftIcon && !countryCodeSelect && !leftAddon && "pl-10", leftAddon && !countryCodeSelect && !leftIcon && "pl-16", (rightIcon || shouldShowPasswordToggle) && "pr-10", rightAddon && !rightIcon && !shouldShowPasswordToggle && "pr-16", className), ref: ref, ...props }), rightAddon && !rightIcon && !shouldShowPasswordToggle && (jsxRuntime.jsx("div", { className: "flex absolute inset-y-0 right-0 items-center pr-3 pointer-events-none", children: jsxRuntime.jsx("span", { className: "text-sm font-medium text-ews-gray-500", children: rightAddon }) })), rightIcon && !shouldShowPasswordToggle && (jsxRuntime.jsx("div", { className: "flex absolute inset-y-0 right-0 items-center pr-3 pointer-events-none", children: jsxRuntime.jsx("span", { className: cn("text-ews-gray-400", iconSizes[size]), children: rightIcon }) })), shouldShowPasswordToggle && (jsxRuntime.jsx("button", { type: "button", className: "flex absolute inset-y-0 right-0 items-center pr-3", onClick: () => setShowPassword(!showPassword), tabIndex: -1, children: jsxRuntime.jsx("span", { className: cn("transition-colors text-ews-gray-400 hover:text-ews-gray-600", iconSizes[size]), children: showPassword ? jsxRuntime.jsx(EyeOff, { size: 16 }) : jsxRuntime.jsx(Eye, { size: 16 }) }) }))] }), (error || helperText) && (jsxRuntime.jsx("p", { className: cn("text-sm", error ? "text-ews-error" : "text-ews-gray-500"), children: error || helperText }))] }));
|
|
32625
|
+
}) }))] }) })), leftIcon && !countryCodeSelect && !leftAddon && (jsxRuntime.jsx("div", { className: "flex absolute inset-y-0 left-0 items-center pl-3 pointer-events-none", children: jsxRuntime.jsx("span", { className: cn("text-ews-gray-400", iconSizes[size]), children: leftIcon }) })), leftAddon && !countryCodeSelect && !leftIcon && (jsxRuntime.jsx("div", { className: "flex absolute inset-y-0 left-0 items-center pointer-events-none overflow-hidden rounded-l-md", children: jsxRuntime.jsx("span", { className: "flex items-center h-full px-3 text-sm font-medium whitespace-nowrap bg-ews-gray-50 border-r border-ews-gray-300 text-ews-gray-600", children: leftAddon }) })), jsxRuntime.jsx("input", { id: inputId, type: actualType, className: cn(baseStyles, variants[actualVariant], sizes[size], countryCodeSelect && "pl-24", leftIcon && !countryCodeSelect && !leftAddon && "pl-10", leftAddon && !countryCodeSelect && !leftIcon && "pl-16", (rightIcon || shouldShowPasswordToggle) && "pr-10", rightAddon && !rightIcon && !shouldShowPasswordToggle && "pr-16", className), ref: ref, onChange: handleChange, onBlur: handleBlur, ...props }), rightAddon && !rightIcon && !shouldShowPasswordToggle && (jsxRuntime.jsx("div", { className: "flex absolute inset-y-0 right-0 items-center pr-3 pointer-events-none", children: jsxRuntime.jsx("span", { className: "text-sm font-medium text-ews-gray-500", children: rightAddon }) })), rightIcon && !shouldShowPasswordToggle && (jsxRuntime.jsx("div", { className: "flex absolute inset-y-0 right-0 items-center pr-3 pointer-events-none", children: jsxRuntime.jsx("span", { className: cn("text-ews-gray-400", iconSizes[size]), children: rightIcon }) })), shouldShowPasswordToggle && (jsxRuntime.jsx("button", { type: "button", className: "flex absolute inset-y-0 right-0 items-center pr-3", onClick: () => setShowPassword(!showPassword), tabIndex: -1, children: jsxRuntime.jsx("span", { className: cn("transition-colors text-ews-gray-400 hover:text-ews-gray-600", iconSizes[size]), children: showPassword ? jsxRuntime.jsx(EyeOff, { size: 16 }) : jsxRuntime.jsx(Eye, { size: 16 }) }) }))] }), (error || helperText) && (jsxRuntime.jsx("p", { className: cn("text-sm", error ? "text-ews-error" : "text-ews-gray-500"), children: error || helperText }))] }));
|
|
32608
32626
|
});
|
|
32609
32627
|
Input.displayName = "Input";
|
|
32610
32628
|
|
|
@@ -32921,23 +32939,29 @@ var isWeb = typeof window !== 'undefined' &&
|
|
|
32921
32939
|
typeof document !== 'undefined';
|
|
32922
32940
|
|
|
32923
32941
|
function cloneObject(data) {
|
|
32942
|
+
let copy;
|
|
32943
|
+
const isArray = Array.isArray(data);
|
|
32944
|
+
const isFileListInstance = typeof FileList !== 'undefined' ? data instanceof FileList : false;
|
|
32924
32945
|
if (data instanceof Date) {
|
|
32925
|
-
|
|
32946
|
+
copy = new Date(data);
|
|
32926
32947
|
}
|
|
32927
|
-
|
|
32928
|
-
|
|
32929
|
-
|
|
32948
|
+
else if (!(isWeb && (data instanceof Blob || isFileListInstance)) &&
|
|
32949
|
+
(isArray || isObject(data))) {
|
|
32950
|
+
copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
|
|
32951
|
+
if (!isArray && !isPlainObject(data)) {
|
|
32952
|
+
copy = data;
|
|
32953
|
+
}
|
|
32954
|
+
else {
|
|
32955
|
+
for (const key in data) {
|
|
32956
|
+
if (data.hasOwnProperty(key)) {
|
|
32957
|
+
copy[key] = cloneObject(data[key]);
|
|
32958
|
+
}
|
|
32959
|
+
}
|
|
32960
|
+
}
|
|
32930
32961
|
}
|
|
32931
|
-
|
|
32932
|
-
if (!isArray && !(isObject(data) && isPlainObject(data))) {
|
|
32962
|
+
else {
|
|
32933
32963
|
return data;
|
|
32934
32964
|
}
|
|
32935
|
-
const copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
|
|
32936
|
-
for (const key in data) {
|
|
32937
|
-
if (Object.prototype.hasOwnProperty.call(data, key)) {
|
|
32938
|
-
copy[key] = cloneObject(data[key]);
|
|
32939
|
-
}
|
|
32940
|
-
}
|
|
32941
32965
|
return copy;
|
|
32942
32966
|
}
|
|
32943
32967
|
|
|
@@ -32963,8 +32987,6 @@ var get = (object, path, defaultValue) => {
|
|
|
32963
32987
|
|
|
32964
32988
|
var isBoolean = (value) => typeof value === 'boolean';
|
|
32965
32989
|
|
|
32966
|
-
var isFunction = (value) => typeof value === 'function';
|
|
32967
|
-
|
|
32968
32990
|
var set = (object, path, value) => {
|
|
32969
32991
|
let index = -1;
|
|
32970
32992
|
const tempPath = isKey(path) ? [path] : stringToPath(path);
|
|
@@ -32992,21 +33014,50 @@ var set = (object, path, value) => {
|
|
|
32992
33014
|
|
|
32993
33015
|
const EVENTS = {
|
|
32994
33016
|
BLUR: 'blur',
|
|
32995
|
-
|
|
33017
|
+
FOCUS_OUT: 'focusout',
|
|
33018
|
+
CHANGE: 'change',
|
|
33019
|
+
};
|
|
32996
33020
|
const VALIDATION_MODE = {
|
|
33021
|
+
onBlur: 'onBlur',
|
|
33022
|
+
onChange: 'onChange',
|
|
33023
|
+
onSubmit: 'onSubmit',
|
|
33024
|
+
onTouched: 'onTouched',
|
|
32997
33025
|
all: 'all',
|
|
32998
33026
|
};
|
|
32999
33027
|
|
|
33028
|
+
const HookFormContext = React.createContext(null);
|
|
33029
|
+
HookFormContext.displayName = 'HookFormContext';
|
|
33000
33030
|
/**
|
|
33001
|
-
*
|
|
33002
|
-
*
|
|
33003
|
-
|
|
33004
|
-
|
|
33005
|
-
|
|
33006
|
-
|
|
33007
|
-
*
|
|
33031
|
+
* This custom hook allows you to access the form context. useFormContext is intended to be used in deeply nested structures, where it would become inconvenient to pass the context as a prop. To be used with {@link FormProvider}.
|
|
33032
|
+
*
|
|
33033
|
+
* @remarks
|
|
33034
|
+
* [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
|
|
33035
|
+
*
|
|
33036
|
+
* @returns return all useForm methods
|
|
33037
|
+
*
|
|
33038
|
+
* @example
|
|
33039
|
+
* ```tsx
|
|
33040
|
+
* function App() {
|
|
33041
|
+
* const methods = useForm();
|
|
33042
|
+
* const onSubmit = data => console.log(data);
|
|
33043
|
+
*
|
|
33044
|
+
* return (
|
|
33045
|
+
* <FormProvider {...methods} >
|
|
33046
|
+
* <form onSubmit={methods.handleSubmit(onSubmit)}>
|
|
33047
|
+
* <NestedInput />
|
|
33048
|
+
* <input type="submit" />
|
|
33049
|
+
* </form>
|
|
33050
|
+
* </FormProvider>
|
|
33051
|
+
* );
|
|
33052
|
+
* }
|
|
33053
|
+
*
|
|
33054
|
+
* function NestedInput() {
|
|
33055
|
+
* const { register } = useFormContext(); // retrieve all hook methods
|
|
33056
|
+
* return <input {...register("test")} />;
|
|
33057
|
+
* }
|
|
33058
|
+
* ```
|
|
33008
33059
|
*/
|
|
33009
|
-
const
|
|
33060
|
+
const useFormContext = () => React.useContext(HookFormContext);
|
|
33010
33061
|
|
|
33011
33062
|
var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
|
|
33012
33063
|
const result = {
|
|
@@ -33060,8 +33111,8 @@ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayou
|
|
|
33060
33111
|
* ```
|
|
33061
33112
|
*/
|
|
33062
33113
|
function useFormState(props) {
|
|
33063
|
-
const
|
|
33064
|
-
const { control =
|
|
33114
|
+
const methods = useFormContext();
|
|
33115
|
+
const { control = methods.control, disabled, name, exact } = props || {};
|
|
33065
33116
|
const [formState, updateFormState] = React.useState(control._formState);
|
|
33066
33117
|
const _localProxyFormState = React.useRef({
|
|
33067
33118
|
isDirty: false,
|
|
@@ -33095,11 +33146,14 @@ var isString = (value) => typeof value === 'string';
|
|
|
33095
33146
|
|
|
33096
33147
|
var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
|
|
33097
33148
|
if (isString(names)) {
|
|
33149
|
+
isGlobal && _names.watch.add(names);
|
|
33098
33150
|
return get(formValues, names, defaultValue);
|
|
33099
33151
|
}
|
|
33100
33152
|
if (Array.isArray(names)) {
|
|
33101
|
-
return names.map((fieldName) => (
|
|
33153
|
+
return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName),
|
|
33154
|
+
get(formValues, fieldName)));
|
|
33102
33155
|
}
|
|
33156
|
+
isGlobal && (_names.watchAll = true);
|
|
33103
33157
|
return formValues;
|
|
33104
33158
|
};
|
|
33105
33159
|
|
|
@@ -33107,10 +33161,10 @@ var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
|
|
|
33107
33161
|
|
|
33108
33162
|
function deepEqual(object1, object2, _internal_visited = new WeakSet()) {
|
|
33109
33163
|
if (isPrimitive(object1) || isPrimitive(object2)) {
|
|
33110
|
-
return
|
|
33164
|
+
return object1 === object2;
|
|
33111
33165
|
}
|
|
33112
33166
|
if (isDateObject(object1) && isDateObject(object2)) {
|
|
33113
|
-
return
|
|
33167
|
+
return object1.getTime() === object2.getTime();
|
|
33114
33168
|
}
|
|
33115
33169
|
const keys1 = Object.keys(object1);
|
|
33116
33170
|
const keys2 = Object.keys(object2);
|
|
@@ -33133,7 +33187,7 @@ function deepEqual(object1, object2, _internal_visited = new WeakSet()) {
|
|
|
33133
33187
|
(isObject(val1) && isObject(val2)) ||
|
|
33134
33188
|
(Array.isArray(val1) && Array.isArray(val2))
|
|
33135
33189
|
? !deepEqual(val1, val2, _internal_visited)
|
|
33136
|
-
:
|
|
33190
|
+
: val1 !== val2) {
|
|
33137
33191
|
return false;
|
|
33138
33192
|
}
|
|
33139
33193
|
}
|
|
@@ -33158,73 +33212,38 @@ function deepEqual(object1, object2, _internal_visited = new WeakSet()) {
|
|
|
33158
33212
|
* ```
|
|
33159
33213
|
*/
|
|
33160
33214
|
function useWatch(props) {
|
|
33161
|
-
const
|
|
33162
|
-
const { control =
|
|
33215
|
+
const methods = useFormContext();
|
|
33216
|
+
const { control = methods.control, name, defaultValue, disabled, exact, compute, } = props || {};
|
|
33163
33217
|
const _defaultValue = React.useRef(defaultValue);
|
|
33164
33218
|
const _compute = React.useRef(compute);
|
|
33165
33219
|
const _computeFormValues = React.useRef(undefined);
|
|
33166
|
-
const _prevControl = React.useRef(control);
|
|
33167
|
-
const _prevName = React.useRef(name);
|
|
33168
33220
|
_compute.current = compute;
|
|
33169
|
-
const
|
|
33170
|
-
|
|
33171
|
-
|
|
33172
|
-
|
|
33173
|
-
|
|
33174
|
-
|
|
33175
|
-
|
|
33176
|
-
|
|
33177
|
-
|
|
33178
|
-
|
|
33179
|
-
|
|
33180
|
-
|
|
33181
|
-
|
|
33182
|
-
|
|
33183
|
-
|
|
33184
|
-
|
|
33221
|
+
const defaultValueMemo = React.useMemo(() => control._getWatch(name, _defaultValue.current), [control, name]);
|
|
33222
|
+
const [value, updateValue] = React.useState(_compute.current ? _compute.current(defaultValueMemo) : defaultValueMemo);
|
|
33223
|
+
useIsomorphicLayoutEffect(() => control._subscribe({
|
|
33224
|
+
name,
|
|
33225
|
+
formState: {
|
|
33226
|
+
values: true,
|
|
33227
|
+
},
|
|
33228
|
+
exact,
|
|
33229
|
+
callback: (formState) => {
|
|
33230
|
+
if (!disabled) {
|
|
33231
|
+
const formValues = generateWatchOutput(name, control._names, formState.values || control._formValues, false, _defaultValue.current);
|
|
33232
|
+
if (_compute.current) {
|
|
33233
|
+
const computedFormValues = _compute.current(formValues);
|
|
33234
|
+
if (!deepEqual(computedFormValues, _computeFormValues.current)) {
|
|
33235
|
+
updateValue(computedFormValues);
|
|
33236
|
+
_computeFormValues.current = computedFormValues;
|
|
33237
|
+
}
|
|
33238
|
+
}
|
|
33239
|
+
else {
|
|
33240
|
+
updateValue(formValues);
|
|
33185
33241
|
}
|
|
33186
33242
|
}
|
|
33187
|
-
|
|
33188
|
-
|
|
33189
|
-
}
|
|
33190
|
-
}
|
|
33191
|
-
}, [control._formValues, control._names, disabled, name]);
|
|
33192
|
-
useIsomorphicLayoutEffect(() => {
|
|
33193
|
-
if (_prevControl.current !== control ||
|
|
33194
|
-
!deepEqual(_prevName.current, name)) {
|
|
33195
|
-
_prevControl.current = control;
|
|
33196
|
-
_prevName.current = name;
|
|
33197
|
-
refreshValue();
|
|
33198
|
-
}
|
|
33199
|
-
return control._subscribe({
|
|
33200
|
-
name,
|
|
33201
|
-
formState: {
|
|
33202
|
-
values: true,
|
|
33203
|
-
},
|
|
33204
|
-
exact,
|
|
33205
|
-
callback: (formState) => {
|
|
33206
|
-
refreshValue(formState.values);
|
|
33207
|
-
},
|
|
33208
|
-
});
|
|
33209
|
-
}, [control, exact, name, refreshValue]);
|
|
33243
|
+
},
|
|
33244
|
+
}), [control, disabled, name, exact]);
|
|
33210
33245
|
React.useEffect(() => control._removeUnmounted());
|
|
33211
|
-
|
|
33212
|
-
// latest value so callers (like useController) see the correct value
|
|
33213
|
-
// immediately on the same render.
|
|
33214
|
-
// Optimize: Check control reference first before expensive deepEqual
|
|
33215
|
-
const controlChanged = _prevControl.current !== control;
|
|
33216
|
-
const prevName = _prevName.current;
|
|
33217
|
-
// Cache the computed output to avoid duplicate calls within the same render
|
|
33218
|
-
// We include shouldReturnImmediate in deps to ensure proper recomputation
|
|
33219
|
-
const computedOutput = React.useMemo(() => {
|
|
33220
|
-
if (disabled) {
|
|
33221
|
-
return null;
|
|
33222
|
-
}
|
|
33223
|
-
const nameChanged = !controlChanged && !deepEqual(prevName, name);
|
|
33224
|
-
const shouldReturnImmediate = controlChanged || nameChanged;
|
|
33225
|
-
return shouldReturnImmediate ? getCurrentOutput() : null;
|
|
33226
|
-
}, [disabled, controlChanged, name, prevName, getCurrentOutput]);
|
|
33227
|
-
return computedOutput !== null ? computedOutput : value;
|
|
33246
|
+
return value;
|
|
33228
33247
|
}
|
|
33229
33248
|
|
|
33230
33249
|
/**
|
|
@@ -33252,20 +33271,20 @@ function useWatch(props) {
|
|
|
33252
33271
|
* ```
|
|
33253
33272
|
*/
|
|
33254
33273
|
function useController(props) {
|
|
33255
|
-
const
|
|
33256
|
-
const { name, disabled, control =
|
|
33274
|
+
const methods = useFormContext();
|
|
33275
|
+
const { name, disabled, control = methods.control, shouldUnregister, defaultValue, } = props;
|
|
33257
33276
|
const isArrayField = isNameInFieldArray(control._names.array, name);
|
|
33258
33277
|
const defaultValueMemo = React.useMemo(() => get(control._formValues, name, get(control._defaultValues, name, defaultValue)), [control, name, defaultValue]);
|
|
33259
33278
|
const value = useWatch({
|
|
33260
33279
|
control,
|
|
33261
33280
|
name,
|
|
33262
33281
|
defaultValue: defaultValueMemo,
|
|
33263
|
-
exact,
|
|
33282
|
+
exact: true,
|
|
33264
33283
|
});
|
|
33265
33284
|
const formState = useFormState({
|
|
33266
33285
|
control,
|
|
33267
33286
|
name,
|
|
33268
|
-
exact,
|
|
33287
|
+
exact: true,
|
|
33269
33288
|
});
|
|
33270
33289
|
const _props = React.useRef(props);
|
|
33271
33290
|
const _previousNameRef = React.useRef(undefined);
|
|
@@ -33313,12 +33332,12 @@ function useController(props) {
|
|
|
33313
33332
|
}), [name, control._formValues]);
|
|
33314
33333
|
const ref = React.useCallback((elm) => {
|
|
33315
33334
|
const field = get(control._fields, name);
|
|
33316
|
-
if (field &&
|
|
33335
|
+
if (field && elm) {
|
|
33317
33336
|
field._f.ref = {
|
|
33318
|
-
focus: () =>
|
|
33319
|
-
select: () =>
|
|
33320
|
-
setCustomValidity: (message) =>
|
|
33321
|
-
reportValidity: () =>
|
|
33337
|
+
focus: () => elm.focus && elm.focus(),
|
|
33338
|
+
select: () => elm.select && elm.select(),
|
|
33339
|
+
setCustomValidity: (message) => elm.setCustomValidity(message),
|
|
33340
|
+
reportValidity: () => elm.reportValidity(),
|
|
33322
33341
|
};
|
|
33323
33342
|
}
|
|
33324
33343
|
}, [control._fields, name]);
|
|
@@ -33352,7 +33371,7 @@ function useController(props) {
|
|
|
33352
33371
|
};
|
|
33353
33372
|
updateMounted(name, true);
|
|
33354
33373
|
if (_shouldUnregisterField) {
|
|
33355
|
-
const value = cloneObject(get(control._options.defaultValues, name
|
|
33374
|
+
const value = cloneObject(get(control._options.defaultValues, name));
|
|
33356
33375
|
set(control._defaultValues, name, value);
|
|
33357
33376
|
if (isUndefined(get(control._formValues, name))) {
|
|
33358
33377
|
set(control._formValues, name, value);
|
|
@@ -33425,9 +33444,6 @@ function useController(props) {
|
|
|
33425
33444
|
*/
|
|
33426
33445
|
const Controller = (props) => props.render(useController(props));
|
|
33427
33446
|
|
|
33428
|
-
const HookFormContext = React.createContext(null);
|
|
33429
|
-
HookFormContext.displayName = 'HookFormContext';
|
|
33430
|
-
|
|
33431
33447
|
function useSelectField({ name, control, options: _options, rules, defaultValue, }) {
|
|
33432
33448
|
const { field, fieldState: { error, invalid }, } = useController({
|
|
33433
33449
|
name,
|
|
@@ -33951,7 +33967,14 @@ const PhoneInput = React.forwardRef(({ countryCode, onCountryCodeChange, onChang
|
|
|
33951
33967
|
// when the user changes the dropdown without retyping the number.
|
|
33952
33968
|
const el = nativeRef.current;
|
|
33953
33969
|
if (el && onChange) {
|
|
33954
|
-
|
|
33970
|
+
let numeric = formatNumeric(el.value);
|
|
33971
|
+
// Strip new country code digits if already present at the start
|
|
33972
|
+
// (e.g. local part "221778384499" when switching to +221).
|
|
33973
|
+
const newCodeDigits = formatNumeric(newCode);
|
|
33974
|
+
if (newCodeDigits && numeric.startsWith(newCodeDigits)) {
|
|
33975
|
+
numeric = numeric.slice(newCodeDigits.length);
|
|
33976
|
+
el.value = numeric;
|
|
33977
|
+
}
|
|
33955
33978
|
const fullValue = numeric ? `${newCode}${numeric}` : "";
|
|
33956
33979
|
// Pass the value string directly — RHF's Controller field.onChange
|
|
33957
33980
|
// accepts raw values, avoiding unreliable fake-event parsing.
|
|
@@ -33969,7 +33992,14 @@ const PhoneInput = React.forwardRef(({ countryCode, onCountryCodeChange, onChang
|
|
|
33969
33992
|
}, [value]);
|
|
33970
33993
|
const handleChange = (e) => {
|
|
33971
33994
|
// Enforce digits-only in the displayed field.
|
|
33972
|
-
|
|
33995
|
+
let numeric = formatNumeric(e.target.value);
|
|
33996
|
+
// Strip country code digits if user typed or pasted the full number
|
|
33997
|
+
// (e.g. typed "+221778384499" → formatNumeric gives "221778384499"
|
|
33998
|
+
// which would produce "+221221778384499" without this guard).
|
|
33999
|
+
const codeDigits = formatNumeric(activeCode);
|
|
34000
|
+
if (codeDigits && numeric.startsWith(codeDigits)) {
|
|
34001
|
+
numeric = numeric.slice(codeDigits.length);
|
|
34002
|
+
}
|
|
33973
34003
|
if (e.target.value !== numeric) {
|
|
33974
34004
|
e.target.value = numeric;
|
|
33975
34005
|
}
|
|
@@ -34077,8 +34107,8 @@ const PROMED_THEME = {
|
|
|
34077
34107
|
const MED_THEME = {
|
|
34078
34108
|
name: "MED",
|
|
34079
34109
|
colors: {
|
|
34080
|
-
primary: "#3BA1A1",
|
|
34081
|
-
secondary: "#6B73FF",
|
|
34110
|
+
primary: "#3BA1A1",
|
|
34111
|
+
secondary: "#6B73FF",
|
|
34082
34112
|
primaryHover: "#308181",
|
|
34083
34113
|
secondaryHover: "#5a61e6",
|
|
34084
34114
|
primaryLight: "#a8d5d5",
|