@ews-admin/global-design-system 1.7.0 → 1.9.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/hooks/useSelectField.d.ts +1 -1
- package/dist/hooks/useSelectField.d.ts.map +1 -1
- package/dist/index.css +3 -5
- package/dist/index.d.ts +4 -4
- package/dist/index.esm.css +3 -5
- package/dist/index.esm.js +7 -543
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +9 -545
- package/dist/index.js.map +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/package.json +4 -6
- package/src/components/Input/Input.tsx +4 -0
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import React, { forwardRef, createElement, useState, useRef, useEffect, useId, useCallback, createContext, useContext } from 'react';
|
|
3
|
+
import { useController, Controller } from 'react-hook-form';
|
|
3
4
|
|
|
4
|
-
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<
|
|
5
|
+
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)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
|
|
5
6
|
|
|
6
7
|
const LOCAL_PORTS = {
|
|
7
8
|
bff: 8082,
|
|
@@ -62,7 +63,7 @@ function createEnvConfig(env, overrides) {
|
|
|
62
63
|
* Available country codes supported by the platform
|
|
63
64
|
*/
|
|
64
65
|
const COUNTRY_CODES = [
|
|
65
|
-
{ code: "+221", country: "SN" },
|
|
66
|
+
{ code: "+221", country: "SN" }, // Senegal
|
|
66
67
|
{ code: "+235", country: "TD" }, // Chad
|
|
67
68
|
];
|
|
68
69
|
/**
|
|
@@ -32606,11 +32607,11 @@ const Input = React.forwardRef(({ className, variant = "default", size = "md", l
|
|
|
32606
32607
|
if (label) {
|
|
32607
32608
|
// Render checkbox with built-in label
|
|
32608
32609
|
return (jsx("div", { className: cn("space-y-1", fullWidth ? "w-full" : "w-auto"), children: jsxs("div", { className: "flex items-start space-x-3", children: [jsx("input", { id: inputId, type: actualType, className: cn("mt-0.5", // Slight top margin to align with first line of text
|
|
32609
|
-
className), ref: ref, ...props }), jsxs("div", { className: "flex-1", children: [jsxs("label", { htmlFor: inputId, className: "block text-sm font-medium cursor-pointer text-ews-gray-700", children: [label, required && jsx("span", { className: "ml-1 text-ews-error", children: "*" })] }), (error || helperText) && (jsx("p", { className: cn("mt-1 text-sm", error ? "text-ews-error" : "text-ews-gray-500"), children: error || helperText }))] })] }) }));
|
|
32610
|
+
className), ref: ref, onChange: onChange, onBlur: onBlur, ...props }), jsxs("div", { className: "flex-1", children: [jsxs("label", { htmlFor: inputId, className: "block text-sm font-medium cursor-pointer text-ews-gray-700", children: [label, required && jsx("span", { className: "ml-1 text-ews-error", children: "*" })] }), (error || helperText) && (jsx("p", { className: cn("mt-1 text-sm", error ? "text-ews-error" : "text-ews-gray-500"), children: error || helperText }))] })] }) }));
|
|
32610
32611
|
}
|
|
32611
32612
|
else {
|
|
32612
32613
|
// Render just the checkbox for external label usage
|
|
32613
|
-
return (jsx("input", { id: inputId, type: actualType, className: cn(className), ref: ref, ...props }));
|
|
32614
|
+
return (jsx("input", { id: inputId, type: actualType, className: cn(className), ref: ref, onChange: onChange, onBlur: onBlur, ...props }));
|
|
32614
32615
|
}
|
|
32615
32616
|
}
|
|
32616
32617
|
// Default rendering for non-checkbox inputs
|
|
@@ -32905,543 +32906,6 @@ function useDebouncedCallback(callback, delay) {
|
|
|
32905
32906
|
return debouncedCallback;
|
|
32906
32907
|
}
|
|
32907
32908
|
|
|
32908
|
-
var isCheckBoxInput = (element) => element.type === 'checkbox';
|
|
32909
|
-
|
|
32910
|
-
var isDateObject = (value) => value instanceof Date;
|
|
32911
|
-
|
|
32912
|
-
var isNullOrUndefined = (value) => value == null;
|
|
32913
|
-
|
|
32914
|
-
const isObjectType = (value) => typeof value === 'object';
|
|
32915
|
-
var isObject = (value) => !isNullOrUndefined(value) &&
|
|
32916
|
-
!Array.isArray(value) &&
|
|
32917
|
-
isObjectType(value) &&
|
|
32918
|
-
!isDateObject(value);
|
|
32919
|
-
|
|
32920
|
-
var getEventValue = (event) => isObject(event) && event.target
|
|
32921
|
-
? isCheckBoxInput(event.target)
|
|
32922
|
-
? event.target.checked
|
|
32923
|
-
: event.target.value
|
|
32924
|
-
: event;
|
|
32925
|
-
|
|
32926
|
-
var getNodeParentName = (name) => name.substring(0, name.search(/\.\d+(\.|$)/)) || name;
|
|
32927
|
-
|
|
32928
|
-
var isNameInFieldArray = (names, name) => names.has(getNodeParentName(name));
|
|
32929
|
-
|
|
32930
|
-
var isPlainObject = (tempObject) => {
|
|
32931
|
-
const prototypeCopy = tempObject.constructor && tempObject.constructor.prototype;
|
|
32932
|
-
return (isObject(prototypeCopy) && prototypeCopy.hasOwnProperty('isPrototypeOf'));
|
|
32933
|
-
};
|
|
32934
|
-
|
|
32935
|
-
var isWeb = typeof window !== 'undefined' &&
|
|
32936
|
-
typeof window.HTMLElement !== 'undefined' &&
|
|
32937
|
-
typeof document !== 'undefined';
|
|
32938
|
-
|
|
32939
|
-
function cloneObject(data) {
|
|
32940
|
-
let copy;
|
|
32941
|
-
const isArray = Array.isArray(data);
|
|
32942
|
-
const isFileListInstance = typeof FileList !== 'undefined' ? data instanceof FileList : false;
|
|
32943
|
-
if (data instanceof Date) {
|
|
32944
|
-
copy = new Date(data);
|
|
32945
|
-
}
|
|
32946
|
-
else if (!(isWeb && (data instanceof Blob || isFileListInstance)) &&
|
|
32947
|
-
(isArray || isObject(data))) {
|
|
32948
|
-
copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
|
|
32949
|
-
if (!isArray && !isPlainObject(data)) {
|
|
32950
|
-
copy = data;
|
|
32951
|
-
}
|
|
32952
|
-
else {
|
|
32953
|
-
for (const key in data) {
|
|
32954
|
-
if (data.hasOwnProperty(key)) {
|
|
32955
|
-
copy[key] = cloneObject(data[key]);
|
|
32956
|
-
}
|
|
32957
|
-
}
|
|
32958
|
-
}
|
|
32959
|
-
}
|
|
32960
|
-
else {
|
|
32961
|
-
return data;
|
|
32962
|
-
}
|
|
32963
|
-
return copy;
|
|
32964
|
-
}
|
|
32965
|
-
|
|
32966
|
-
var isKey = (value) => /^\w*$/.test(value);
|
|
32967
|
-
|
|
32968
|
-
var isUndefined = (val) => val === undefined;
|
|
32969
|
-
|
|
32970
|
-
var compact = (value) => Array.isArray(value) ? value.filter(Boolean) : [];
|
|
32971
|
-
|
|
32972
|
-
var stringToPath = (input) => compact(input.replace(/["|']|\]/g, '').split(/\.|\[/));
|
|
32973
|
-
|
|
32974
|
-
var get = (object, path, defaultValue) => {
|
|
32975
|
-
if (!path || !isObject(object)) {
|
|
32976
|
-
return defaultValue;
|
|
32977
|
-
}
|
|
32978
|
-
const result = (isKey(path) ? [path] : stringToPath(path)).reduce((result, key) => isNullOrUndefined(result) ? result : result[key], object);
|
|
32979
|
-
return isUndefined(result) || result === object
|
|
32980
|
-
? isUndefined(object[path])
|
|
32981
|
-
? defaultValue
|
|
32982
|
-
: object[path]
|
|
32983
|
-
: result;
|
|
32984
|
-
};
|
|
32985
|
-
|
|
32986
|
-
var isBoolean = (value) => typeof value === 'boolean';
|
|
32987
|
-
|
|
32988
|
-
var set = (object, path, value) => {
|
|
32989
|
-
let index = -1;
|
|
32990
|
-
const tempPath = isKey(path) ? [path] : stringToPath(path);
|
|
32991
|
-
const length = tempPath.length;
|
|
32992
|
-
const lastIndex = length - 1;
|
|
32993
|
-
while (++index < length) {
|
|
32994
|
-
const key = tempPath[index];
|
|
32995
|
-
let newValue = value;
|
|
32996
|
-
if (index !== lastIndex) {
|
|
32997
|
-
const objValue = object[key];
|
|
32998
|
-
newValue =
|
|
32999
|
-
isObject(objValue) || Array.isArray(objValue)
|
|
33000
|
-
? objValue
|
|
33001
|
-
: !isNaN(+tempPath[index + 1])
|
|
33002
|
-
? []
|
|
33003
|
-
: {};
|
|
33004
|
-
}
|
|
33005
|
-
if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
|
|
33006
|
-
return;
|
|
33007
|
-
}
|
|
33008
|
-
object[key] = newValue;
|
|
33009
|
-
object = object[key];
|
|
33010
|
-
}
|
|
33011
|
-
};
|
|
33012
|
-
|
|
33013
|
-
const EVENTS = {
|
|
33014
|
-
BLUR: 'blur',
|
|
33015
|
-
FOCUS_OUT: 'focusout',
|
|
33016
|
-
CHANGE: 'change',
|
|
33017
|
-
};
|
|
33018
|
-
const VALIDATION_MODE = {
|
|
33019
|
-
onBlur: 'onBlur',
|
|
33020
|
-
onChange: 'onChange',
|
|
33021
|
-
onSubmit: 'onSubmit',
|
|
33022
|
-
onTouched: 'onTouched',
|
|
33023
|
-
all: 'all',
|
|
33024
|
-
};
|
|
33025
|
-
|
|
33026
|
-
const HookFormContext = React.createContext(null);
|
|
33027
|
-
HookFormContext.displayName = 'HookFormContext';
|
|
33028
|
-
/**
|
|
33029
|
-
* 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}.
|
|
33030
|
-
*
|
|
33031
|
-
* @remarks
|
|
33032
|
-
* [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
|
|
33033
|
-
*
|
|
33034
|
-
* @returns return all useForm methods
|
|
33035
|
-
*
|
|
33036
|
-
* @example
|
|
33037
|
-
* ```tsx
|
|
33038
|
-
* function App() {
|
|
33039
|
-
* const methods = useForm();
|
|
33040
|
-
* const onSubmit = data => console.log(data);
|
|
33041
|
-
*
|
|
33042
|
-
* return (
|
|
33043
|
-
* <FormProvider {...methods} >
|
|
33044
|
-
* <form onSubmit={methods.handleSubmit(onSubmit)}>
|
|
33045
|
-
* <NestedInput />
|
|
33046
|
-
* <input type="submit" />
|
|
33047
|
-
* </form>
|
|
33048
|
-
* </FormProvider>
|
|
33049
|
-
* );
|
|
33050
|
-
* }
|
|
33051
|
-
*
|
|
33052
|
-
* function NestedInput() {
|
|
33053
|
-
* const { register } = useFormContext(); // retrieve all hook methods
|
|
33054
|
-
* return <input {...register("test")} />;
|
|
33055
|
-
* }
|
|
33056
|
-
* ```
|
|
33057
|
-
*/
|
|
33058
|
-
const useFormContext = () => React.useContext(HookFormContext);
|
|
33059
|
-
|
|
33060
|
-
var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
|
|
33061
|
-
const result = {
|
|
33062
|
-
defaultValues: control._defaultValues,
|
|
33063
|
-
};
|
|
33064
|
-
for (const key in formState) {
|
|
33065
|
-
Object.defineProperty(result, key, {
|
|
33066
|
-
get: () => {
|
|
33067
|
-
const _key = key;
|
|
33068
|
-
if (control._proxyFormState[_key] !== VALIDATION_MODE.all) {
|
|
33069
|
-
control._proxyFormState[_key] = !isRoot || VALIDATION_MODE.all;
|
|
33070
|
-
}
|
|
33071
|
-
localProxyFormState && (localProxyFormState[_key] = true);
|
|
33072
|
-
return formState[_key];
|
|
33073
|
-
},
|
|
33074
|
-
});
|
|
33075
|
-
}
|
|
33076
|
-
return result;
|
|
33077
|
-
};
|
|
33078
|
-
|
|
33079
|
-
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
|
|
33080
|
-
|
|
33081
|
-
/**
|
|
33082
|
-
* This custom hook allows you to subscribe to each form state, and isolate the re-render at the custom hook level. It has its scope in terms of form state subscription, so it would not affect other useFormState and useForm. Using this hook can reduce the re-render impact on large and complex form application.
|
|
33083
|
-
*
|
|
33084
|
-
* @remarks
|
|
33085
|
-
* [API](https://react-hook-form.com/docs/useformstate) • [Demo](https://codesandbox.io/s/useformstate-75xly)
|
|
33086
|
-
*
|
|
33087
|
-
* @param props - include options on specify fields to subscribe. {@link UseFormStateReturn}
|
|
33088
|
-
*
|
|
33089
|
-
* @example
|
|
33090
|
-
* ```tsx
|
|
33091
|
-
* function App() {
|
|
33092
|
-
* const { register, handleSubmit, control } = useForm({
|
|
33093
|
-
* defaultValues: {
|
|
33094
|
-
* firstName: "firstName"
|
|
33095
|
-
* }});
|
|
33096
|
-
* const { dirtyFields } = useFormState({
|
|
33097
|
-
* control
|
|
33098
|
-
* });
|
|
33099
|
-
* const onSubmit = (data) => console.log(data);
|
|
33100
|
-
*
|
|
33101
|
-
* return (
|
|
33102
|
-
* <form onSubmit={handleSubmit(onSubmit)}>
|
|
33103
|
-
* <input {...register("firstName")} placeholder="First Name" />
|
|
33104
|
-
* {dirtyFields.firstName && <p>Field is dirty.</p>}
|
|
33105
|
-
* <input type="submit" />
|
|
33106
|
-
* </form>
|
|
33107
|
-
* );
|
|
33108
|
-
* }
|
|
33109
|
-
* ```
|
|
33110
|
-
*/
|
|
33111
|
-
function useFormState(props) {
|
|
33112
|
-
const methods = useFormContext();
|
|
33113
|
-
const { control = methods.control, disabled, name, exact } = props || {};
|
|
33114
|
-
const [formState, updateFormState] = React.useState(control._formState);
|
|
33115
|
-
const _localProxyFormState = React.useRef({
|
|
33116
|
-
isDirty: false,
|
|
33117
|
-
isLoading: false,
|
|
33118
|
-
dirtyFields: false,
|
|
33119
|
-
touchedFields: false,
|
|
33120
|
-
validatingFields: false,
|
|
33121
|
-
isValidating: false,
|
|
33122
|
-
isValid: false,
|
|
33123
|
-
errors: false,
|
|
33124
|
-
});
|
|
33125
|
-
useIsomorphicLayoutEffect(() => control._subscribe({
|
|
33126
|
-
name,
|
|
33127
|
-
formState: _localProxyFormState.current,
|
|
33128
|
-
exact,
|
|
33129
|
-
callback: (formState) => {
|
|
33130
|
-
!disabled &&
|
|
33131
|
-
updateFormState({
|
|
33132
|
-
...control._formState,
|
|
33133
|
-
...formState,
|
|
33134
|
-
});
|
|
33135
|
-
},
|
|
33136
|
-
}), [name, disabled, exact]);
|
|
33137
|
-
React.useEffect(() => {
|
|
33138
|
-
_localProxyFormState.current.isValid && control._setValid(true);
|
|
33139
|
-
}, [control]);
|
|
33140
|
-
return React.useMemo(() => getProxyFormState(formState, control, _localProxyFormState.current, false), [formState, control]);
|
|
33141
|
-
}
|
|
33142
|
-
|
|
33143
|
-
var isString = (value) => typeof value === 'string';
|
|
33144
|
-
|
|
33145
|
-
var generateWatchOutput = (names, _names, formValues, isGlobal, defaultValue) => {
|
|
33146
|
-
if (isString(names)) {
|
|
33147
|
-
isGlobal && _names.watch.add(names);
|
|
33148
|
-
return get(formValues, names, defaultValue);
|
|
33149
|
-
}
|
|
33150
|
-
if (Array.isArray(names)) {
|
|
33151
|
-
return names.map((fieldName) => (isGlobal && _names.watch.add(fieldName),
|
|
33152
|
-
get(formValues, fieldName)));
|
|
33153
|
-
}
|
|
33154
|
-
isGlobal && (_names.watchAll = true);
|
|
33155
|
-
return formValues;
|
|
33156
|
-
};
|
|
33157
|
-
|
|
33158
|
-
var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
|
|
33159
|
-
|
|
33160
|
-
function deepEqual(object1, object2, _internal_visited = new WeakSet()) {
|
|
33161
|
-
if (isPrimitive(object1) || isPrimitive(object2)) {
|
|
33162
|
-
return object1 === object2;
|
|
33163
|
-
}
|
|
33164
|
-
if (isDateObject(object1) && isDateObject(object2)) {
|
|
33165
|
-
return object1.getTime() === object2.getTime();
|
|
33166
|
-
}
|
|
33167
|
-
const keys1 = Object.keys(object1);
|
|
33168
|
-
const keys2 = Object.keys(object2);
|
|
33169
|
-
if (keys1.length !== keys2.length) {
|
|
33170
|
-
return false;
|
|
33171
|
-
}
|
|
33172
|
-
if (_internal_visited.has(object1) || _internal_visited.has(object2)) {
|
|
33173
|
-
return true;
|
|
33174
|
-
}
|
|
33175
|
-
_internal_visited.add(object1);
|
|
33176
|
-
_internal_visited.add(object2);
|
|
33177
|
-
for (const key of keys1) {
|
|
33178
|
-
const val1 = object1[key];
|
|
33179
|
-
if (!keys2.includes(key)) {
|
|
33180
|
-
return false;
|
|
33181
|
-
}
|
|
33182
|
-
if (key !== 'ref') {
|
|
33183
|
-
const val2 = object2[key];
|
|
33184
|
-
if ((isDateObject(val1) && isDateObject(val2)) ||
|
|
33185
|
-
(isObject(val1) && isObject(val2)) ||
|
|
33186
|
-
(Array.isArray(val1) && Array.isArray(val2))
|
|
33187
|
-
? !deepEqual(val1, val2, _internal_visited)
|
|
33188
|
-
: val1 !== val2) {
|
|
33189
|
-
return false;
|
|
33190
|
-
}
|
|
33191
|
-
}
|
|
33192
|
-
}
|
|
33193
|
-
return true;
|
|
33194
|
-
}
|
|
33195
|
-
|
|
33196
|
-
/**
|
|
33197
|
-
* Custom hook to subscribe to field change and isolate re-rendering at the component level.
|
|
33198
|
-
*
|
|
33199
|
-
* @remarks
|
|
33200
|
-
*
|
|
33201
|
-
* [API](https://react-hook-form.com/docs/usewatch) • [Demo](https://codesandbox.io/s/react-hook-form-v7-ts-usewatch-h9i5e)
|
|
33202
|
-
*
|
|
33203
|
-
* @example
|
|
33204
|
-
* ```tsx
|
|
33205
|
-
* const { control } = useForm();
|
|
33206
|
-
* const values = useWatch({
|
|
33207
|
-
* name: "fieldName"
|
|
33208
|
-
* control,
|
|
33209
|
-
* })
|
|
33210
|
-
* ```
|
|
33211
|
-
*/
|
|
33212
|
-
function useWatch(props) {
|
|
33213
|
-
const methods = useFormContext();
|
|
33214
|
-
const { control = methods.control, name, defaultValue, disabled, exact, compute, } = props || {};
|
|
33215
|
-
const _defaultValue = React.useRef(defaultValue);
|
|
33216
|
-
const _compute = React.useRef(compute);
|
|
33217
|
-
const _computeFormValues = React.useRef(undefined);
|
|
33218
|
-
_compute.current = compute;
|
|
33219
|
-
const defaultValueMemo = React.useMemo(() => control._getWatch(name, _defaultValue.current), [control, name]);
|
|
33220
|
-
const [value, updateValue] = React.useState(_compute.current ? _compute.current(defaultValueMemo) : defaultValueMemo);
|
|
33221
|
-
useIsomorphicLayoutEffect(() => control._subscribe({
|
|
33222
|
-
name,
|
|
33223
|
-
formState: {
|
|
33224
|
-
values: true,
|
|
33225
|
-
},
|
|
33226
|
-
exact,
|
|
33227
|
-
callback: (formState) => {
|
|
33228
|
-
if (!disabled) {
|
|
33229
|
-
const formValues = generateWatchOutput(name, control._names, formState.values || control._formValues, false, _defaultValue.current);
|
|
33230
|
-
if (_compute.current) {
|
|
33231
|
-
const computedFormValues = _compute.current(formValues);
|
|
33232
|
-
if (!deepEqual(computedFormValues, _computeFormValues.current)) {
|
|
33233
|
-
updateValue(computedFormValues);
|
|
33234
|
-
_computeFormValues.current = computedFormValues;
|
|
33235
|
-
}
|
|
33236
|
-
}
|
|
33237
|
-
else {
|
|
33238
|
-
updateValue(formValues);
|
|
33239
|
-
}
|
|
33240
|
-
}
|
|
33241
|
-
},
|
|
33242
|
-
}), [control, disabled, name, exact]);
|
|
33243
|
-
React.useEffect(() => control._removeUnmounted());
|
|
33244
|
-
return value;
|
|
33245
|
-
}
|
|
33246
|
-
|
|
33247
|
-
/**
|
|
33248
|
-
* Custom hook to work with controlled component, this function provide you with both form and field level state. Re-render is isolated at the hook level.
|
|
33249
|
-
*
|
|
33250
|
-
* @remarks
|
|
33251
|
-
* [API](https://react-hook-form.com/docs/usecontroller) • [Demo](https://codesandbox.io/s/usecontroller-0o8px)
|
|
33252
|
-
*
|
|
33253
|
-
* @param props - the path name to the form field value, and validation rules.
|
|
33254
|
-
*
|
|
33255
|
-
* @returns field properties, field and form state. {@link UseControllerReturn}
|
|
33256
|
-
*
|
|
33257
|
-
* @example
|
|
33258
|
-
* ```tsx
|
|
33259
|
-
* function Input(props) {
|
|
33260
|
-
* const { field, fieldState, formState } = useController(props);
|
|
33261
|
-
* return (
|
|
33262
|
-
* <div>
|
|
33263
|
-
* <input {...field} placeholder={props.name} />
|
|
33264
|
-
* <p>{fieldState.isTouched && "Touched"}</p>
|
|
33265
|
-
* <p>{formState.isSubmitted ? "submitted" : ""}</p>
|
|
33266
|
-
* </div>
|
|
33267
|
-
* );
|
|
33268
|
-
* }
|
|
33269
|
-
* ```
|
|
33270
|
-
*/
|
|
33271
|
-
function useController(props) {
|
|
33272
|
-
const methods = useFormContext();
|
|
33273
|
-
const { name, disabled, control = methods.control, shouldUnregister, defaultValue, } = props;
|
|
33274
|
-
const isArrayField = isNameInFieldArray(control._names.array, name);
|
|
33275
|
-
const defaultValueMemo = React.useMemo(() => get(control._formValues, name, get(control._defaultValues, name, defaultValue)), [control, name, defaultValue]);
|
|
33276
|
-
const value = useWatch({
|
|
33277
|
-
control,
|
|
33278
|
-
name,
|
|
33279
|
-
defaultValue: defaultValueMemo,
|
|
33280
|
-
exact: true,
|
|
33281
|
-
});
|
|
33282
|
-
const formState = useFormState({
|
|
33283
|
-
control,
|
|
33284
|
-
name,
|
|
33285
|
-
exact: true,
|
|
33286
|
-
});
|
|
33287
|
-
const _props = React.useRef(props);
|
|
33288
|
-
const _previousNameRef = React.useRef(undefined);
|
|
33289
|
-
const _registerProps = React.useRef(control.register(name, {
|
|
33290
|
-
...props.rules,
|
|
33291
|
-
value,
|
|
33292
|
-
...(isBoolean(props.disabled) ? { disabled: props.disabled } : {}),
|
|
33293
|
-
}));
|
|
33294
|
-
_props.current = props;
|
|
33295
|
-
const fieldState = React.useMemo(() => Object.defineProperties({}, {
|
|
33296
|
-
invalid: {
|
|
33297
|
-
enumerable: true,
|
|
33298
|
-
get: () => !!get(formState.errors, name),
|
|
33299
|
-
},
|
|
33300
|
-
isDirty: {
|
|
33301
|
-
enumerable: true,
|
|
33302
|
-
get: () => !!get(formState.dirtyFields, name),
|
|
33303
|
-
},
|
|
33304
|
-
isTouched: {
|
|
33305
|
-
enumerable: true,
|
|
33306
|
-
get: () => !!get(formState.touchedFields, name),
|
|
33307
|
-
},
|
|
33308
|
-
isValidating: {
|
|
33309
|
-
enumerable: true,
|
|
33310
|
-
get: () => !!get(formState.validatingFields, name),
|
|
33311
|
-
},
|
|
33312
|
-
error: {
|
|
33313
|
-
enumerable: true,
|
|
33314
|
-
get: () => get(formState.errors, name),
|
|
33315
|
-
},
|
|
33316
|
-
}), [formState, name]);
|
|
33317
|
-
const onChange = React.useCallback((event) => _registerProps.current.onChange({
|
|
33318
|
-
target: {
|
|
33319
|
-
value: getEventValue(event),
|
|
33320
|
-
name: name,
|
|
33321
|
-
},
|
|
33322
|
-
type: EVENTS.CHANGE,
|
|
33323
|
-
}), [name]);
|
|
33324
|
-
const onBlur = React.useCallback(() => _registerProps.current.onBlur({
|
|
33325
|
-
target: {
|
|
33326
|
-
value: get(control._formValues, name),
|
|
33327
|
-
name: name,
|
|
33328
|
-
},
|
|
33329
|
-
type: EVENTS.BLUR,
|
|
33330
|
-
}), [name, control._formValues]);
|
|
33331
|
-
const ref = React.useCallback((elm) => {
|
|
33332
|
-
const field = get(control._fields, name);
|
|
33333
|
-
if (field && elm) {
|
|
33334
|
-
field._f.ref = {
|
|
33335
|
-
focus: () => elm.focus && elm.focus(),
|
|
33336
|
-
select: () => elm.select && elm.select(),
|
|
33337
|
-
setCustomValidity: (message) => elm.setCustomValidity(message),
|
|
33338
|
-
reportValidity: () => elm.reportValidity(),
|
|
33339
|
-
};
|
|
33340
|
-
}
|
|
33341
|
-
}, [control._fields, name]);
|
|
33342
|
-
const field = React.useMemo(() => ({
|
|
33343
|
-
name,
|
|
33344
|
-
value,
|
|
33345
|
-
...(isBoolean(disabled) || formState.disabled
|
|
33346
|
-
? { disabled: formState.disabled || disabled }
|
|
33347
|
-
: {}),
|
|
33348
|
-
onChange,
|
|
33349
|
-
onBlur,
|
|
33350
|
-
ref,
|
|
33351
|
-
}), [name, disabled, formState.disabled, onChange, onBlur, ref, value]);
|
|
33352
|
-
React.useEffect(() => {
|
|
33353
|
-
const _shouldUnregisterField = control._options.shouldUnregister || shouldUnregister;
|
|
33354
|
-
const previousName = _previousNameRef.current;
|
|
33355
|
-
if (previousName && previousName !== name && !isArrayField) {
|
|
33356
|
-
control.unregister(previousName);
|
|
33357
|
-
}
|
|
33358
|
-
control.register(name, {
|
|
33359
|
-
..._props.current.rules,
|
|
33360
|
-
...(isBoolean(_props.current.disabled)
|
|
33361
|
-
? { disabled: _props.current.disabled }
|
|
33362
|
-
: {}),
|
|
33363
|
-
});
|
|
33364
|
-
const updateMounted = (name, value) => {
|
|
33365
|
-
const field = get(control._fields, name);
|
|
33366
|
-
if (field && field._f) {
|
|
33367
|
-
field._f.mount = value;
|
|
33368
|
-
}
|
|
33369
|
-
};
|
|
33370
|
-
updateMounted(name, true);
|
|
33371
|
-
if (_shouldUnregisterField) {
|
|
33372
|
-
const value = cloneObject(get(control._options.defaultValues, name));
|
|
33373
|
-
set(control._defaultValues, name, value);
|
|
33374
|
-
if (isUndefined(get(control._formValues, name))) {
|
|
33375
|
-
set(control._formValues, name, value);
|
|
33376
|
-
}
|
|
33377
|
-
}
|
|
33378
|
-
!isArrayField && control.register(name);
|
|
33379
|
-
_previousNameRef.current = name;
|
|
33380
|
-
return () => {
|
|
33381
|
-
(isArrayField
|
|
33382
|
-
? _shouldUnregisterField && !control._state.action
|
|
33383
|
-
: _shouldUnregisterField)
|
|
33384
|
-
? control.unregister(name)
|
|
33385
|
-
: updateMounted(name, false);
|
|
33386
|
-
};
|
|
33387
|
-
}, [name, control, isArrayField, shouldUnregister]);
|
|
33388
|
-
React.useEffect(() => {
|
|
33389
|
-
control._setDisabledField({
|
|
33390
|
-
disabled,
|
|
33391
|
-
name,
|
|
33392
|
-
});
|
|
33393
|
-
}, [disabled, name, control]);
|
|
33394
|
-
return React.useMemo(() => ({
|
|
33395
|
-
field,
|
|
33396
|
-
formState,
|
|
33397
|
-
fieldState,
|
|
33398
|
-
}), [field, formState, fieldState]);
|
|
33399
|
-
}
|
|
33400
|
-
|
|
33401
|
-
/**
|
|
33402
|
-
* Component based on `useController` hook to work with controlled component.
|
|
33403
|
-
*
|
|
33404
|
-
* @remarks
|
|
33405
|
-
* [API](https://react-hook-form.com/docs/usecontroller/controller) • [Demo](https://codesandbox.io/s/react-hook-form-v6-controller-ts-jwyzw) • [Video](https://www.youtube.com/watch?v=N2UNk_UCVyA)
|
|
33406
|
-
*
|
|
33407
|
-
* @param props - the path name to the form field value, and validation rules.
|
|
33408
|
-
*
|
|
33409
|
-
* @returns provide field handler functions, field and form state.
|
|
33410
|
-
*
|
|
33411
|
-
* @example
|
|
33412
|
-
* ```tsx
|
|
33413
|
-
* function App() {
|
|
33414
|
-
* const { control } = useForm<FormValues>({
|
|
33415
|
-
* defaultValues: {
|
|
33416
|
-
* test: ""
|
|
33417
|
-
* }
|
|
33418
|
-
* });
|
|
33419
|
-
*
|
|
33420
|
-
* return (
|
|
33421
|
-
* <form>
|
|
33422
|
-
* <Controller
|
|
33423
|
-
* control={control}
|
|
33424
|
-
* name="test"
|
|
33425
|
-
* render={({ field: { onChange, onBlur, value, ref }, formState, fieldState }) => (
|
|
33426
|
-
* <>
|
|
33427
|
-
* <input
|
|
33428
|
-
* onChange={onChange} // send value to hook form
|
|
33429
|
-
* onBlur={onBlur} // notify when input is touched
|
|
33430
|
-
* value={value} // return updated value
|
|
33431
|
-
* ref={ref} // set ref for focus management
|
|
33432
|
-
* />
|
|
33433
|
-
* <p>{formState.isSubmitted ? "submitted" : ""}</p>
|
|
33434
|
-
* <p>{fieldState.isTouched ? "touched" : ""}</p>
|
|
33435
|
-
* </>
|
|
33436
|
-
* )}
|
|
33437
|
-
* />
|
|
33438
|
-
* </form>
|
|
33439
|
-
* );
|
|
33440
|
-
* }
|
|
33441
|
-
* ```
|
|
33442
|
-
*/
|
|
33443
|
-
const Controller = (props) => props.render(useController(props));
|
|
33444
|
-
|
|
33445
32909
|
function useSelectField({ name, control, options: _options, rules, defaultValue, }) {
|
|
33446
32910
|
const { field, fieldState: { error, invalid }, } = useController({
|
|
33447
32911
|
name,
|
|
@@ -34105,8 +33569,8 @@ const PROMED_THEME = {
|
|
|
34105
33569
|
const MED_THEME = {
|
|
34106
33570
|
name: "MED",
|
|
34107
33571
|
colors: {
|
|
34108
|
-
primary: "#3BA1A1",
|
|
34109
|
-
secondary: "#6B73FF",
|
|
33572
|
+
primary: "#3BA1A1", // Teal for patients (calming, trustworthy)
|
|
33573
|
+
secondary: "#6B73FF", // Soft purple-blue (suggested secondary for MED)
|
|
34110
33574
|
primaryHover: "#308181",
|
|
34111
33575
|
secondaryHover: "#5a61e6",
|
|
34112
33576
|
primaryLight: "#a8d5d5",
|