@a-type/ui 6.0.9 → 6.0.10
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/liveUpdateTextField/LiveUpdateTextField.d.ts +2 -1
- package/dist/components/liveUpdateTextField/LiveUpdateTextField.js.map +1 -1
- package/dist/components/typography/typography.d.ts +1 -0
- package/dist/components/typography/typography.js +5 -0
- package/dist/components/typography/typography.js.map +1 -1
- package/package.json +1 -1
- package/src/components/liveUpdateTextField/LiveUpdateTextField.tsx +135 -133
- package/src/components/typography/typography.tsx +6 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FocusEvent, KeyboardEventHandler, MouseEventHandler, Ref } from 'react';
|
|
1
|
+
import { CSSProperties, FocusEvent, KeyboardEventHandler, MouseEventHandler, Ref } from 'react';
|
|
2
2
|
import { InputProps } from '../input/Input.js';
|
|
3
3
|
export type LiveUpdateTextFieldProps = {
|
|
4
4
|
value: string;
|
|
@@ -6,6 +6,7 @@ export type LiveUpdateTextFieldProps = {
|
|
|
6
6
|
onChange: (value: string) => void;
|
|
7
7
|
textArea?: boolean;
|
|
8
8
|
className?: string;
|
|
9
|
+
style?: CSSProperties;
|
|
9
10
|
onFocus?: (ev: FocusEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
10
11
|
onBlur?: (ev: FocusEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
11
12
|
autoComplete?: InputProps['autoComplete'];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiveUpdateTextField.js","sourceRoot":"","sources":["../../../src/components/liveUpdateTextField/LiveUpdateTextField.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;;;;AAEb,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,
|
|
1
|
+
{"version":3,"file":"LiveUpdateTextField.js","sourceRoot":"","sources":["../../../src/components/liveUpdateTextField/LiveUpdateTextField.ts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ACnB,aAAa,EAAE,iBAAiB,EAChC,IAAI,EAAE,IAAI,IACN,IAAI,EACP,CACF,CAAC;IACH,CAAC;AACF,CAAC,CAAC"}
|
|
@@ -31,3 +31,4 @@ export declare const H4: (props: TypographyProps) => import("react/jsx-runtime")
|
|
|
31
31
|
* @deprecated Use Heading with appropriate render and emphasis instead
|
|
32
32
|
*/
|
|
33
33
|
export declare const H5: (props: TypographyProps) => import("react/jsx-runtime").JSX.Element;
|
|
34
|
+
export declare const TextLink: (props: TypographyProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"typography.js","sourceRoot":"","sources":["../../../src/components/typography/typography.tsx"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AACrD,OAAO,GAAG,MAAM,yBAAyB,CAAC;AAW1C,MAAM,UAAU,IAAI,CAAC,EAUH;QAVG,EACpB,QAAQ,EACR,MAAM,EACN,SAAS,EACT,aAAa,EACb,MAAM,EACN,SAAS,EACT,IAAI,EACJ,IAAI,OAEa,EADd,IAAI,cATa,2FAUpB,CADO;IAEP,OAAO,SAAS,CAAC;QAChB,MAAM;QACN,cAAc,EAAE,MAAM;QACtB,KAAK,kCACD,IAAI,KACP,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,UAAU,EAAE,GAAG,CAAC,YAAY,EAAE,SAAS,CAAC,GAC5D;QACD,KAAK,EAAE;YACN,QAAQ;YACR,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;YACjC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;YACvC,aAAa,EAAE,aAAa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|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
{
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
{
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
import { debounce } from '@a-type/utils';
|
|
4
|
+
import {
|
|
5
|
+
CSSProperties,
|
|
6
|
+
FocusEvent,
|
|
7
|
+
KeyboardEventHandler,
|
|
8
|
+
MouseEventHandler,
|
|
9
|
+
Ref,
|
|
10
|
+
useCallback,
|
|
11
|
+
useEffect,
|
|
12
|
+
useMemo,
|
|
13
|
+
useRef,
|
|
14
|
+
useState,
|
|
15
|
+
} from 'react';
|
|
16
|
+
import { Input, InputProps } from '../input/Input.js';
|
|
17
|
+
import { TextArea } from '../textArea/TextArea.js';
|
|
18
|
+
|
|
19
|
+
export type LiveUpdateTextFieldProps = {
|
|
20
|
+
value: string;
|
|
21
|
+
debounceMs?: number;
|
|
22
|
+
onChange: (value: string) => void;
|
|
23
|
+
textArea?: boolean;
|
|
24
|
+
className?: string;
|
|
25
|
+
style?: CSSProperties;
|
|
26
|
+
onFocus?: (ev: FocusEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
27
|
+
onBlur?: (ev: FocusEvent<HTMLInputElement | HTMLTextAreaElement>) => void;
|
|
28
|
+
autoComplete?: InputProps['autoComplete'];
|
|
29
|
+
autoFocus?: InputProps['autoFocus'];
|
|
30
|
+
autoSelect?: InputProps['autoSelect'];
|
|
31
|
+
required?: boolean;
|
|
32
|
+
placeholder?: string;
|
|
33
|
+
type?: InputProps['type'];
|
|
34
|
+
id?: string;
|
|
35
|
+
onKeyDown?: KeyboardEventHandler;
|
|
36
|
+
onKeyUp?: KeyboardEventHandler;
|
|
37
|
+
onClick?: MouseEventHandler;
|
|
38
|
+
ref?: Ref<HTMLInputElement | HTMLTextAreaElement>;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* An extension of TextField which keeps a local realtime value in state and
|
|
43
|
+
* periodically reports changes to the parent. Use this to connect
|
|
44
|
+
* to the API and update a value from the field directly.
|
|
45
|
+
*
|
|
46
|
+
* This component is optimistic and will not respond to external changes while focused.
|
|
47
|
+
*/
|
|
48
|
+
export const LiveUpdateTextField = function LiveUpdateTextField({
|
|
49
|
+
ref,
|
|
50
|
+
value,
|
|
51
|
+
onChange,
|
|
52
|
+
debounceMs = 500,
|
|
53
|
+
onFocus,
|
|
54
|
+
onBlur,
|
|
55
|
+
textArea,
|
|
56
|
+
type,
|
|
57
|
+
...rest
|
|
58
|
+
}: LiveUpdateTextFieldProps) {
|
|
59
|
+
const [displayValue, setDisplayValue] = useState(value || '');
|
|
60
|
+
const ignoreUpdates = useRef(false);
|
|
61
|
+
const didChange = useRef(false);
|
|
62
|
+
|
|
63
|
+
const handleFocus = useCallback(
|
|
64
|
+
(ev: FocusEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
|
65
|
+
onFocus?.(ev);
|
|
66
|
+
ignoreUpdates.current = true;
|
|
67
|
+
},
|
|
68
|
+
[onFocus],
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
const handleBlur = useCallback(
|
|
72
|
+
(ev: FocusEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
|
73
|
+
onBlur?.(ev);
|
|
74
|
+
ignoreUpdates.current = false;
|
|
75
|
+
// immediately send update if the user typed anything.
|
|
76
|
+
// otherwise pull the latest remote value
|
|
77
|
+
if (didChange.current) {
|
|
78
|
+
onChange?.(displayValue);
|
|
79
|
+
} else {
|
|
80
|
+
setDisplayValue(value || '');
|
|
81
|
+
}
|
|
82
|
+
didChange.current = false;
|
|
83
|
+
},
|
|
84
|
+
[onBlur, displayValue, onChange, value],
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
useEffect(() => {
|
|
88
|
+
if (ignoreUpdates.current) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
setDisplayValue(value || '');
|
|
92
|
+
}, [value]);
|
|
93
|
+
|
|
94
|
+
// every once in a while, send an update to parent
|
|
95
|
+
const debouncedOnChange = useMemo(
|
|
96
|
+
() => debounce(onChange || (() => {}), debounceMs),
|
|
97
|
+
[onChange, debounceMs],
|
|
98
|
+
);
|
|
99
|
+
|
|
100
|
+
// update local state instantly and parent eventually
|
|
101
|
+
const handleValueChange = useCallback(
|
|
102
|
+
(value: string) => {
|
|
103
|
+
setDisplayValue(value);
|
|
104
|
+
debouncedOnChange(value);
|
|
105
|
+
didChange.current = true;
|
|
106
|
+
},
|
|
107
|
+
[debouncedOnChange],
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
if (textArea) {
|
|
111
|
+
return (
|
|
112
|
+
<TextArea
|
|
113
|
+
ref={ref as any}
|
|
114
|
+
onFocus={handleFocus}
|
|
115
|
+
onBlur={handleBlur}
|
|
116
|
+
value={displayValue}
|
|
117
|
+
onValueChange={handleValueChange}
|
|
118
|
+
autoSize
|
|
119
|
+
{...rest}
|
|
120
|
+
/>
|
|
121
|
+
);
|
|
122
|
+
} else {
|
|
123
|
+
return (
|
|
124
|
+
<Input
|
|
125
|
+
ref={ref as any}
|
|
126
|
+
onFocus={handleFocus}
|
|
127
|
+
onBlur={handleBlur}
|
|
128
|
+
value={displayValue}
|
|
129
|
+
onValueChange={handleValueChange}
|
|
130
|
+
type={type}
|
|
131
|
+
{...rest}
|
|
132
|
+
/>
|
|
133
|
+
);
|
|
134
|
+
}
|
|
135
|
+
};
|