@ews-admin/global-design-system 1.1.27 → 1.6.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/index.js CHANGED
@@ -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,29 +32939,23 @@ var isWeb = typeof window !== 'undefined' &&
32921
32939
  typeof document !== 'undefined';
32922
32940
 
32923
32941
  function cloneObject(data) {
32924
- let copy;
32925
- const isArray = Array.isArray(data);
32926
- const isFileListInstance = typeof FileList !== 'undefined' ? data instanceof FileList : false;
32927
32942
  if (data instanceof Date) {
32928
- copy = new Date(data);
32943
+ return new Date(data);
32929
32944
  }
32930
- else if (!(isWeb && (data instanceof Blob || isFileListInstance)) &&
32931
- (isArray || isObject(data))) {
32932
- copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
32933
- if (!isArray && !isPlainObject(data)) {
32934
- copy = data;
32935
- }
32936
- else {
32937
- for (const key in data) {
32938
- if (data.hasOwnProperty(key)) {
32939
- copy[key] = cloneObject(data[key]);
32940
- }
32941
- }
32942
- }
32945
+ const isFileListInstance = typeof FileList !== 'undefined' && data instanceof FileList;
32946
+ if (isWeb && (data instanceof Blob || isFileListInstance)) {
32947
+ return data;
32943
32948
  }
32944
- else {
32949
+ const isArray = Array.isArray(data);
32950
+ if (!isArray && !(isObject(data) && isPlainObject(data))) {
32945
32951
  return data;
32946
32952
  }
32953
+ const copy = isArray ? [] : Object.create(Object.getPrototypeOf(data));
32954
+ for (const key in data) {
32955
+ if (Object.prototype.hasOwnProperty.call(data, key)) {
32956
+ copy[key] = cloneObject(data[key]);
32957
+ }
32958
+ }
32947
32959
  return copy;
32948
32960
  }
32949
32961
 
@@ -32969,6 +32981,8 @@ var get = (object, path, defaultValue) => {
32969
32981
 
32970
32982
  var isBoolean = (value) => typeof value === 'boolean';
32971
32983
 
32984
+ var isFunction = (value) => typeof value === 'function';
32985
+
32972
32986
  var set = (object, path, value) => {
32973
32987
  let index = -1;
32974
32988
  const tempPath = isKey(path) ? [path] : stringToPath(path);
@@ -32996,45 +33010,21 @@ var set = (object, path, value) => {
32996
33010
 
32997
33011
  const EVENTS = {
32998
33012
  BLUR: 'blur',
32999
- CHANGE: 'change',
33000
- };
33013
+ CHANGE: 'change'};
33001
33014
  const VALIDATION_MODE = {
33002
33015
  all: 'all',
33003
33016
  };
33004
33017
 
33005
- const HookFormContext = React.createContext(null);
33006
- HookFormContext.displayName = 'HookFormContext';
33007
33018
  /**
33008
- * 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}.
33009
- *
33010
- * @remarks
33011
- * [API](https://react-hook-form.com/docs/useformcontext) • [Demo](https://codesandbox.io/s/react-hook-form-v7-form-context-ytudi)
33012
- *
33013
- * @returns return all useForm methods
33014
- *
33015
- * @example
33016
- * ```tsx
33017
- * function App() {
33018
- * const methods = useForm();
33019
- * const onSubmit = data => console.log(data);
33020
- *
33021
- * return (
33022
- * <FormProvider {...methods} >
33023
- * <form onSubmit={methods.handleSubmit(onSubmit)}>
33024
- * <NestedInput />
33025
- * <input type="submit" />
33026
- * </form>
33027
- * </FormProvider>
33028
- * );
33029
- * }
33030
- *
33031
- * function NestedInput() {
33032
- * const { register } = useFormContext(); // retrieve all hook methods
33033
- * return <input {...register("test")} />;
33034
- * }
33035
- * ```
33019
+ * Separate context for `control` to prevent unnecessary rerenders.
33020
+ * Internal hooks that only need control use this instead of full form context.
33021
+ */
33022
+ const HookFormControlContext = React.createContext(null);
33023
+ HookFormControlContext.displayName = 'HookFormControlContext';
33024
+ /**
33025
+ * @internal Internal hook to access only control from context.
33036
33026
  */
33037
- const useFormContext = () => React.useContext(HookFormContext);
33027
+ const useFormControlContext = () => React.useContext(HookFormControlContext);
33038
33028
 
33039
33029
  var getProxyFormState = (formState, control, localProxyFormState, isRoot = true) => {
33040
33030
  const result = {
@@ -33088,8 +33078,8 @@ const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayou
33088
33078
  * ```
33089
33079
  */
33090
33080
  function useFormState(props) {
33091
- const methods = useFormContext();
33092
- const { control = methods.control, disabled, name, exact } = props || {};
33081
+ const formControl = useFormControlContext();
33082
+ const { control = formControl, disabled, name, exact } = props || {};
33093
33083
  const [formState, updateFormState] = React.useState(control._formState);
33094
33084
  const _localProxyFormState = React.useRef({
33095
33085
  isDirty: false,
@@ -33135,10 +33125,10 @@ var isPrimitive = (value) => isNullOrUndefined(value) || !isObjectType(value);
33135
33125
 
33136
33126
  function deepEqual(object1, object2, _internal_visited = new WeakSet()) {
33137
33127
  if (isPrimitive(object1) || isPrimitive(object2)) {
33138
- return object1 === object2;
33128
+ return Object.is(object1, object2);
33139
33129
  }
33140
33130
  if (isDateObject(object1) && isDateObject(object2)) {
33141
- return object1.getTime() === object2.getTime();
33131
+ return Object.is(object1.getTime(), object2.getTime());
33142
33132
  }
33143
33133
  const keys1 = Object.keys(object1);
33144
33134
  const keys2 = Object.keys(object2);
@@ -33161,7 +33151,7 @@ function deepEqual(object1, object2, _internal_visited = new WeakSet()) {
33161
33151
  (isObject(val1) && isObject(val2)) ||
33162
33152
  (Array.isArray(val1) && Array.isArray(val2))
33163
33153
  ? !deepEqual(val1, val2, _internal_visited)
33164
- : val1 !== val2) {
33154
+ : !Object.is(val1, val2)) {
33165
33155
  return false;
33166
33156
  }
33167
33157
  }
@@ -33186,8 +33176,8 @@ function deepEqual(object1, object2, _internal_visited = new WeakSet()) {
33186
33176
  * ```
33187
33177
  */
33188
33178
  function useWatch(props) {
33189
- const methods = useFormContext();
33190
- const { control = methods.control, name, defaultValue, disabled, exact, compute, } = props || {};
33179
+ const formControl = useFormControlContext();
33180
+ const { control = formControl, name, defaultValue, disabled, exact, compute, } = props || {};
33191
33181
  const _defaultValue = React.useRef(defaultValue);
33192
33182
  const _compute = React.useRef(compute);
33193
33183
  const _computeFormValues = React.useRef(undefined);
@@ -33280,20 +33270,20 @@ function useWatch(props) {
33280
33270
  * ```
33281
33271
  */
33282
33272
  function useController(props) {
33283
- const methods = useFormContext();
33284
- const { name, disabled, control = methods.control, shouldUnregister, defaultValue, } = props;
33273
+ const formControl = useFormControlContext();
33274
+ const { name, disabled, control = formControl, shouldUnregister, defaultValue, exact = true, } = props;
33285
33275
  const isArrayField = isNameInFieldArray(control._names.array, name);
33286
33276
  const defaultValueMemo = React.useMemo(() => get(control._formValues, name, get(control._defaultValues, name, defaultValue)), [control, name, defaultValue]);
33287
33277
  const value = useWatch({
33288
33278
  control,
33289
33279
  name,
33290
33280
  defaultValue: defaultValueMemo,
33291
- exact: true,
33281
+ exact,
33292
33282
  });
33293
33283
  const formState = useFormState({
33294
33284
  control,
33295
33285
  name,
33296
- exact: true,
33286
+ exact,
33297
33287
  });
33298
33288
  const _props = React.useRef(props);
33299
33289
  const _previousNameRef = React.useRef(undefined);
@@ -33341,12 +33331,12 @@ function useController(props) {
33341
33331
  }), [name, control._formValues]);
33342
33332
  const ref = React.useCallback((elm) => {
33343
33333
  const field = get(control._fields, name);
33344
- if (field && elm) {
33334
+ if (field && field._f && elm) {
33345
33335
  field._f.ref = {
33346
- focus: () => elm.focus && elm.focus(),
33347
- select: () => elm.select && elm.select(),
33348
- setCustomValidity: (message) => elm.setCustomValidity(message),
33349
- reportValidity: () => elm.reportValidity(),
33336
+ focus: () => isFunction(elm.focus) && elm.focus(),
33337
+ select: () => isFunction(elm.select) && elm.select(),
33338
+ setCustomValidity: (message) => isFunction(elm.setCustomValidity) && elm.setCustomValidity(message),
33339
+ reportValidity: () => isFunction(elm.reportValidity) && elm.reportValidity(),
33350
33340
  };
33351
33341
  }
33352
33342
  }, [control._fields, name]);
@@ -33453,6 +33443,9 @@ function useController(props) {
33453
33443
  */
33454
33444
  const Controller = (props) => props.render(useController(props));
33455
33445
 
33446
+ const HookFormContext = React.createContext(null);
33447
+ HookFormContext.displayName = 'HookFormContext';
33448
+
33456
33449
  function useSelectField({ name, control, options: _options, rules, defaultValue, }) {
33457
33450
  const { field, fieldState: { error, invalid }, } = useController({
33458
33451
  name,