@udixio/ui-react 2.9.17 → 2.9.19

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.
@@ -1,4 +1,5 @@
1
1
  import { default as React, CSSProperties, RefObject } from 'react';
2
+ import IntrinsicElements = React.JSX.IntrinsicElements;
2
3
  export type Position = 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
3
4
  export interface AnchorPositionerProps {
4
5
  anchorRef: RefObject<HTMLElement | null>;
@@ -7,5 +8,5 @@ export interface AnchorPositionerProps {
7
8
  style?: CSSProperties;
8
9
  className?: string;
9
10
  }
10
- export declare const AnchorPositioner: ({ anchorRef, position, children, style, }: AnchorPositionerProps) => import("react/jsx-runtime").JSX.Element;
11
+ export declare const AnchorPositioner: ({ anchorRef, position, children, style, ...restProps }: AnchorPositionerProps & IntrinsicElements["div"]) => import("react/jsx-runtime").JSX.Element;
11
12
  //# sourceMappingURL=AnchorPositioner.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AnchorPositioner.d.ts","sourceRoot":"","sources":["../../../src/lib/components/AnchorPositioner.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,aAAa,EACb,SAAS,EAIV,MAAM,OAAO,CAAC;AAGf,MAAM,MAAM,QAAQ,GAChB,KAAK,GACL,QAAQ,GACR,MAAM,GACN,OAAO,GACP,UAAU,GACV,WAAW,GACX,aAAa,GACb,cAAc,CAAC;AAEnB,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IACzC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,gBAAgB,GAAI,2CAK9B,qBAAqB,4CAmGvB,CAAC"}
1
+ {"version":3,"file":"AnchorPositioner.d.ts","sourceRoot":"","sources":["../../../src/lib/components/AnchorPositioner.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EACZ,aAAa,EACb,SAAS,EAIV,MAAM,OAAO,CAAC;AAGf,OAAO,iBAAiB,GAAG,KAAK,CAAC,GAAG,CAAC,iBAAiB,CAAC;AAEvD,MAAM,MAAM,QAAQ,GAChB,KAAK,GACL,QAAQ,GACR,MAAM,GACN,OAAO,GACP,UAAU,GACV,WAAW,GACX,aAAa,GACb,cAAc,CAAC;AAEnB,MAAM,WAAW,qBAAqB;IACpC,SAAS,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC;IACzC,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAC;IAC1B,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,eAAO,MAAM,gBAAgB,GAAI,wDAM9B,qBAAqB,GAAG,iBAAiB,CAAC,KAAK,CAAC,4CA0GlD,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"TextField.d.ts","sourceRoot":"","sources":["../../../src/lib/components/TextField.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS,GAAI,6PAuBvB,UAAU,CAAC,kBAAkB,CAAC,4CAuUhC,CAAC"}
1
+ {"version":3,"file":"TextField.d.ts","sourceRoot":"","sources":["../../../src/lib/components/TextField.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS,GAAI,6PAuBvB,UAAU,CAAC,kBAAkB,CAAC,4CAwVhC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@udixio/ui-react",
3
- "version": "2.9.17",
3
+ "version": "2.9.19",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -6,6 +6,8 @@ import React, {
6
6
  useState,
7
7
  } from 'react';
8
8
  import { SyncedFixedWrapper } from '../effects';
9
+ import { createPortal } from 'react-dom';
10
+ import IntrinsicElements = React.JSX.IntrinsicElements;
9
11
 
10
12
  export type Position =
11
13
  | 'top'
@@ -30,7 +32,8 @@ export const AnchorPositioner = ({
30
32
  position = 'bottom',
31
33
  children,
32
34
  style,
33
- }: AnchorPositionerProps) => {
35
+ ...restProps
36
+ }: AnchorPositionerProps & IntrinsicElements['div']) => {
34
37
  const uniqueId = useId();
35
38
  const anchorName = `--anchor-${uniqueId.replace(/:/g, '')}`;
36
39
  const [supportsAnchor, setSupportsAnchor] = useState(false);
@@ -76,7 +79,12 @@ export const AnchorPositioner = ({
76
79
  ...style,
77
80
  } as any;
78
81
 
79
- return <div style={floatingStyles}>{children}</div>;
82
+ return createPortal(
83
+ <div style={floatingStyles} {...restProps}>
84
+ {children}
85
+ </div>,
86
+ document.body,
87
+ );
80
88
  }
81
89
 
82
90
  const fallbackStyles: CSSProperties = {
@@ -126,7 +134,9 @@ export const AnchorPositioner = ({
126
134
 
127
135
  return (
128
136
  <SyncedFixedWrapper targetRef={anchorRef}>
129
- <div style={fallbackStyles}>{children}</div>
137
+ <div style={fallbackStyles} {...restProps}>
138
+ {children}
139
+ </div>
130
140
  </SyncedFixedWrapper>
131
141
  );
132
142
  };
@@ -65,6 +65,7 @@ export const TextField = ({
65
65
 
66
66
  const textFieldRef = useRef<HTMLDivElement>(null);
67
67
  const calendarTriggerRef = useRef<HTMLDivElement>(null);
68
+ const datePickerRef = useRef<HTMLDivElement>(null);
68
69
 
69
70
  const hasSupportingText =
70
71
  showSupportingText ?? (!!errorText?.length || !!supportingText?.length);
@@ -79,13 +80,17 @@ export const TextField = ({
79
80
  }
80
81
  };
81
82
 
82
- const handleOnFocus = (
83
- e: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement>,
84
- ) => {
85
- setIsFocused(true);
86
- setShowErrorIcon(false);
87
- restProps.onFocus?.(e);
88
- };
83
+ useEffect(() => {
84
+ if (isFocused) {
85
+ setShowErrorIcon(false);
86
+ restProps.onFocus?.(e);
87
+ } else {
88
+ if (errorText?.length) {
89
+ setShowErrorIcon(true);
90
+ }
91
+ restProps.onBlur?.(e);
92
+ }
93
+ }, [isFocused]);
89
94
 
90
95
  const handleChange = (
91
96
  event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>,
@@ -103,16 +108,6 @@ export const TextField = ({
103
108
  }
104
109
  };
105
110
 
106
- const handleBlur = (
107
- e: React.FocusEvent<HTMLInputElement | HTMLTextAreaElement>,
108
- ) => {
109
- setIsFocused(false);
110
- if (errorText?.length) {
111
- setShowErrorIcon(true);
112
- }
113
- restProps.onBlur?.(e);
114
- };
115
-
116
111
  // Date Picker Logic
117
112
  const isDateInput = type === 'date';
118
113
  const [showDatePicker, setShowDatePicker] = useState(false);
@@ -132,6 +127,14 @@ export const TextField = ({
132
127
  setShowDatePicker(true);
133
128
  };
134
129
 
130
+ useEffect(() => {
131
+ if (showDatePicker) {
132
+ setIsFocused(true);
133
+ } else {
134
+ setIsFocused(false);
135
+ }
136
+ }, [showDatePicker]);
137
+
135
138
  const handleDateConfirm = () => {
136
139
  const newValue = tempDate ? tempDate.toLocaleDateString('en-CA') : '';
137
140
 
@@ -272,8 +275,8 @@ export const TextField = ({
272
275
  id={id}
273
276
  name={name}
274
277
  placeholder={isFocused ? (placeholder ?? undefined) : ''}
275
- onFocus={handleOnFocus}
276
- onBlur={handleBlur}
278
+ onFocus={() => setIsFocused(true)}
279
+ onBlur={() => setIsFocused(false)}
277
280
  disabled={disabled}
278
281
  autoComplete={autoComplete}
279
282
  aria-invalid={!!errorText?.length}
@@ -342,12 +345,26 @@ export const TextField = ({
342
345
 
343
346
  {isDateInput && showDatePicker && (
344
347
  <>
345
- <div
346
- className="fixed inset-0 z-40 bg-transparent"
347
- onClick={() => setShowDatePicker(false)}
348
- />
349
- <AnchorPositioner anchorRef={textFieldRef} position="bottom">
350
- <div className="z-50 shadow-xl rounded-[28px] bg-surface-container-high overflow-hidden">
348
+ <AnchorPositioner
349
+ onBlur={(e) => {
350
+ console.log(
351
+ datePickerRef.current,
352
+ !datePickerRef.current?.contains(e.relatedTarget),
353
+ );
354
+ if (
355
+ datePickerRef.current &&
356
+ !datePickerRef.current?.contains(e.relatedTarget)
357
+ ) {
358
+ setShowDatePicker(false);
359
+ }
360
+ }}
361
+ anchorRef={textFieldRef}
362
+ position="bottom"
363
+ >
364
+ <div
365
+ ref={datePickerRef}
366
+ className="z-50 shadow-xl rounded-[28px] bg-surface-container-high overflow-hidden"
367
+ >
351
368
  <DatePicker
352
369
  className={''}
353
370
  value={tempDate}