@hozo/primitives 0.1.0 → 0.2.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/CHANGELOG.md +15 -0
- package/README.md +7 -2
- package/dist/flat-list.native.d.ts +8 -8
- package/dist/flat-list.native.d.ts.map +1 -1
- package/dist/flat-list.native.js +55 -25
- package/dist/flat-list.native.js.map +1 -1
- package/dist/foundation.native.d.ts +16 -2
- package/dist/foundation.native.d.ts.map +1 -1
- package/dist/foundation.native.js.map +1 -1
- package/dist/index.d.ts +6 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -9
- package/dist/index.js.map +1 -1
- package/dist/index.native.d.ts +1 -0
- package/dist/index.native.d.ts.map +1 -1
- package/dist/index.native.js +1 -0
- package/dist/index.native.js.map +1 -1
- package/dist/presence-context.d.ts +15 -0
- package/dist/presence-context.d.ts.map +1 -0
- package/dist/presence-context.js +11 -0
- package/dist/presence-context.js.map +1 -0
- package/dist/presence.d.ts +12 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +45 -0
- package/dist/presence.js.map +1 -0
- package/dist/presence.native.d.ts +8 -0
- package/dist/presence.native.d.ts.map +1 -0
- package/dist/presence.native.js +66 -0
- package/dist/presence.native.js.map +1 -0
- package/dist/pressable.d.ts +9 -2
- package/dist/pressable.d.ts.map +1 -1
- package/dist/pressable.js +3 -3
- package/dist/pressable.js.map +1 -1
- package/dist/runtime-transition.native.d.ts +16 -1
- package/dist/runtime-transition.native.d.ts.map +1 -1
- package/dist/runtime-transition.native.js +34 -7
- package/dist/runtime-transition.native.js.map +1 -1
- package/dist/text-input.d.ts +319 -3
- package/dist/text-input.d.ts.map +1 -1
- package/dist/text-input.js +4 -3
- package/dist/text-input.js.map +1 -1
- package/dist/view.d.ts +295 -2
- package/dist/view.d.ts.map +1 -1
- package/dist/view.js +3 -3
- package/dist/view.js.map +1 -1
- package/package.json +4 -3
- package/src/flat-list.native.tsx +69 -47
- package/src/foundation.native.tsx +16 -1
- package/src/index.native.ts +2 -0
- package/src/index.ts +209 -219
- package/src/presence-context.ts +27 -0
- package/src/presence.native.tsx +81 -0
- package/src/presence.tsx +55 -0
- package/src/pressable.ts +66 -63
- package/src/runtime-transition.native.tsx +68 -7
- package/src/text-input.ts +74 -72
- package/src/view.ts +42 -36
package/src/pressable.ts
CHANGED
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
} from '@hozo/engine'
|
|
8
8
|
import {
|
|
9
9
|
createElement,
|
|
10
|
-
forwardRef,
|
|
11
10
|
type HTMLAttributes,
|
|
12
11
|
type KeyboardEvent,
|
|
13
12
|
type MouseEvent,
|
|
@@ -43,6 +42,12 @@ type DivProps = Omit<
|
|
|
43
42
|
>
|
|
44
43
|
|
|
45
44
|
export interface HozoPressableProps extends DivProps, ResponderProps {
|
|
45
|
+
/**
|
|
46
|
+
* Declared here rather than supplied by `forwardRef`. React 19 takes `ref`
|
|
47
|
+
* as an ordinary prop, so a plain function gets it only if its props say so
|
|
48
|
+
* -- and it must be destructured, or `...props` would carry it onward.
|
|
49
|
+
*/
|
|
50
|
+
ref?: Ref<HTMLElement>
|
|
46
51
|
children?: ReactNode | ((state: HozoPressableState) => ReactNode)
|
|
47
52
|
style?: HozoDomStyle | ((state: HozoPressableState) => HozoDomStyle)
|
|
48
53
|
onPress?: (event: MouseEvent<HTMLElement>) => void
|
|
@@ -102,67 +107,65 @@ function dataAttributes(dataSet: HozoPressableProps['dataSet']) {
|
|
|
102
107
|
}
|
|
103
108
|
|
|
104
109
|
/** A value-level Pressable for component props and animation wrappers. */
|
|
105
|
-
export
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
forwardedRef,
|
|
165
|
-
) {
|
|
110
|
+
export function HozoPressable({
|
|
111
|
+
ref: forwardedRef,
|
|
112
|
+
accessibilityActions: _accessibilityActions,
|
|
113
|
+
accessibilityHint,
|
|
114
|
+
accessibilityLabel,
|
|
115
|
+
accessibilityLiveRegion,
|
|
116
|
+
accessibilityRole,
|
|
117
|
+
accessibilityState,
|
|
118
|
+
accessibilityValue,
|
|
119
|
+
accessible: _accessible,
|
|
120
|
+
android_ripple: _androidRipple,
|
|
121
|
+
children,
|
|
122
|
+
dataSet,
|
|
123
|
+
disabled,
|
|
124
|
+
download,
|
|
125
|
+
external,
|
|
126
|
+
hitSlop: _hitSlop,
|
|
127
|
+
href,
|
|
128
|
+
nativeID,
|
|
129
|
+
onAccessibilityAction: _onAccessibilityAction,
|
|
130
|
+
onBlur,
|
|
131
|
+
onClick,
|
|
132
|
+
onFocus,
|
|
133
|
+
onHoverIn,
|
|
134
|
+
onHoverOut,
|
|
135
|
+
onPointerCancel,
|
|
136
|
+
onPointerDown,
|
|
137
|
+
onPointerEnter,
|
|
138
|
+
onPointerLeave,
|
|
139
|
+
onPointerUp,
|
|
140
|
+
onPress,
|
|
141
|
+
onPressIn,
|
|
142
|
+
onPressOut,
|
|
143
|
+
onKeyDown,
|
|
144
|
+
onKeyUp,
|
|
145
|
+
onLostPointerCapture,
|
|
146
|
+
onLayout,
|
|
147
|
+
onMoveShouldSetResponder,
|
|
148
|
+
onMoveShouldSetResponderCapture,
|
|
149
|
+
onResponderEnd,
|
|
150
|
+
onResponderGrant,
|
|
151
|
+
onResponderMove,
|
|
152
|
+
onResponderReject,
|
|
153
|
+
onResponderRelease,
|
|
154
|
+
onResponderStart,
|
|
155
|
+
onResponderTerminate,
|
|
156
|
+
onResponderTerminationRequest,
|
|
157
|
+
onStartShouldSetResponder,
|
|
158
|
+
onStartShouldSetResponderCapture,
|
|
159
|
+
pointerEvents,
|
|
160
|
+
prefetch,
|
|
161
|
+
rel,
|
|
162
|
+
replace,
|
|
163
|
+
role,
|
|
164
|
+
style,
|
|
165
|
+
target,
|
|
166
|
+
testID,
|
|
167
|
+
...props
|
|
168
|
+
}: HozoPressableProps) {
|
|
166
169
|
const elementRef = useRef<HTMLElement>(null)
|
|
167
170
|
const layoutCallback = useRef(onLayout)
|
|
168
171
|
layoutCallback.current = onLayout
|
|
@@ -355,4 +358,4 @@ export const HozoPressable = forwardRef<HTMLElement, HozoPressableProps>(functio
|
|
|
355
358
|
} as unknown as HTMLAttributes<HTMLDivElement>,
|
|
356
359
|
resolvedChildren,
|
|
357
360
|
)
|
|
358
|
-
}
|
|
361
|
+
}
|
|
@@ -20,8 +20,9 @@
|
|
|
20
20
|
// one `Animated.timing` would drag the fast ones onto the slow driver.
|
|
21
21
|
// They are separate animations for that reason and not for tidiness.
|
|
22
22
|
|
|
23
|
-
import { type ReactNode, useEffect, useMemo, useRef } from 'react'
|
|
23
|
+
import { type ReactNode, useContext, useEffect, useMemo, useRef, useState } from 'react'
|
|
24
24
|
import { Animated, Easing, type StyleProp, StyleSheet, type ViewStyle } from 'react-native'
|
|
25
|
+
import { PresenceContext } from './presence-context.ts'
|
|
25
26
|
|
|
26
27
|
export interface HozoTransitionSpec {
|
|
27
28
|
duration: number
|
|
@@ -59,12 +60,42 @@ function identity(key: string): number {
|
|
|
59
60
|
export interface HozoAnimatedProps {
|
|
60
61
|
style?: StyleProp<ViewStyle>
|
|
61
62
|
hozoTransition?: HozoTransitionSpec
|
|
63
|
+
/**
|
|
64
|
+
* The first frame of an enter animation, from a `starting:` class
|
|
65
|
+
* (decision 007). The element mounts at these values and transitions to
|
|
66
|
+
* `style`, which is what `@starting-style` does on Web. Read once, on
|
|
67
|
+
* mount: it is where the element enters from, not a style it keeps.
|
|
68
|
+
*/
|
|
69
|
+
hozoStarting?: StyleProp<ViewStyle>
|
|
70
|
+
/**
|
|
71
|
+
* The last frame of an exit animation, from a `data-[state=closed]:`
|
|
72
|
+
* class (decision 007, amendment 1). Laid over `style` while the
|
|
73
|
+
* enclosing `Presence` is closing, which is what the attribute selector
|
|
74
|
+
* does on Web; `Presence` removes the element when the transition to it
|
|
75
|
+
* ends.
|
|
76
|
+
*/
|
|
77
|
+
hozoExit?: StyleProp<ViewStyle>
|
|
62
78
|
children?: ReactNode
|
|
63
79
|
[key: string]: unknown
|
|
64
80
|
}
|
|
65
81
|
|
|
66
|
-
export function HozoAnimated({
|
|
67
|
-
|
|
82
|
+
export function HozoAnimated({
|
|
83
|
+
style,
|
|
84
|
+
hozoTransition,
|
|
85
|
+
hozoStarting,
|
|
86
|
+
hozoExit,
|
|
87
|
+
children,
|
|
88
|
+
...props
|
|
89
|
+
}: HozoAnimatedProps) {
|
|
90
|
+
const presence = useContext(PresenceContext)
|
|
91
|
+
// Only an element that has somewhere to leave to takes part. One without
|
|
92
|
+
// `hozoExit` neither waits for `Presence` nor makes it wait.
|
|
93
|
+
const exits = presence !== null && hozoExit != null
|
|
94
|
+
const leaving = exits && presence.state === 'closed'
|
|
95
|
+
const flat = useMemo(
|
|
96
|
+
() => StyleSheet.flatten(leaving ? [style, hozoExit] : style) ?? {},
|
|
97
|
+
[style, hozoExit, leaving],
|
|
98
|
+
)
|
|
68
99
|
|
|
69
100
|
// One progress value per animation rather than one per property. The
|
|
70
101
|
// properties change together -- they are the same rule flipping -- so
|
|
@@ -72,7 +103,14 @@ export function HozoAnimated({ style, hozoTransition, children, ...props }: Hozo
|
|
|
72
103
|
// value to its new one is both cheaper and impossible to get out of
|
|
73
104
|
// step with itself.
|
|
74
105
|
const progress = useRef(new Animated.Value(1)).current
|
|
75
|
-
|
|
106
|
+
// Without `hozoStarting` the first render has nothing to animate from --
|
|
107
|
+
// `from` and `to` are the same style, and the mount effect below runs an
|
|
108
|
+
// animation that moves nothing. With it, `from` is the starting frame
|
|
109
|
+
// laid over the style, so that same mount effect is the enter animation.
|
|
110
|
+
const [entersFrom] = useState<ViewStyle>(() =>
|
|
111
|
+
hozoStarting ? { ...flat, ...(StyleSheet.flatten(hozoStarting) ?? {}) } : flat,
|
|
112
|
+
)
|
|
113
|
+
const from = useRef<ViewStyle>(entersFrom)
|
|
76
114
|
const to = useRef<ViewStyle>(flat)
|
|
77
115
|
|
|
78
116
|
// What changed, computed during render so the effect below has nothing
|
|
@@ -90,6 +128,20 @@ export function HozoAnimated({ style, hozoTransition, children, ...props }: Hozo
|
|
|
90
128
|
previous.current = signature
|
|
91
129
|
}
|
|
92
130
|
|
|
131
|
+
// Registered for as long as it can exit, so `Presence` knows to wait for
|
|
132
|
+
// it and how long to wait before giving up.
|
|
133
|
+
const [id] = useState(() => Symbol('HozoAnimated'))
|
|
134
|
+
const register = exits ? presence.register : undefined
|
|
135
|
+
const exitMs = hozoTransition ? hozoTransition.duration + (hozoTransition.delay ?? 0) : 0
|
|
136
|
+
useEffect(() => register?.(id, exitMs), [register, id, exitMs])
|
|
137
|
+
// Read when the animation ends, which is after this render's values may
|
|
138
|
+
// have changed.
|
|
139
|
+
const leavingNow = useRef(leaving)
|
|
140
|
+
leavingNow.current = leaving
|
|
141
|
+
const done = presence?.done
|
|
142
|
+
const doneNow = useRef(done)
|
|
143
|
+
doneNow.current = done
|
|
144
|
+
|
|
93
145
|
// `signature` is read above rather than inside, and it is what says the
|
|
94
146
|
// style moved -- `hozoTransition` does not change when only the values
|
|
95
147
|
// do. Without it a style change starts no transition at all, which is
|
|
@@ -110,9 +162,11 @@ export function HozoAnimated({ style, hozoTransition, children, ...props }: Hozo
|
|
|
110
162
|
// before the text that sits on it is worse than both arriving late.
|
|
111
163
|
useNativeDriver: false,
|
|
112
164
|
})
|
|
113
|
-
animation.start()
|
|
165
|
+
animation.start(({ finished }) => {
|
|
166
|
+
if (finished && leavingNow.current) doneNow.current?.(id)
|
|
167
|
+
})
|
|
114
168
|
return () => animation.stop()
|
|
115
|
-
}, [progress, signature, hozoTransition])
|
|
169
|
+
}, [progress, signature, hozoTransition, id])
|
|
116
170
|
|
|
117
171
|
// biome-ignore lint/correctness/useExhaustiveDependencies: as above -- `signature` is what changed
|
|
118
172
|
const animated = useMemo(() => {
|
|
@@ -160,7 +214,14 @@ export function HozoAnimated({ style, hozoTransition, children, ...props }: Hozo
|
|
|
160
214
|
|
|
161
215
|
return (
|
|
162
216
|
<Animated.View style={animated as StyleProp<ViewStyle>} {...props}>
|
|
163
|
-
{
|
|
217
|
+
{exits ? (
|
|
218
|
+
// The state is this element's, as `data-state` on Web belongs to
|
|
219
|
+
// the one element `Presence` puts it on. Something nested further
|
|
220
|
+
// in does not leave with it.
|
|
221
|
+
<PresenceContext.Provider value={null}>{children}</PresenceContext.Provider>
|
|
222
|
+
) : (
|
|
223
|
+
children
|
|
224
|
+
)}
|
|
164
225
|
</Animated.View>
|
|
165
226
|
)
|
|
166
227
|
}
|
package/src/text-input.ts
CHANGED
|
@@ -3,10 +3,10 @@ import {
|
|
|
3
3
|
type ChangeEvent,
|
|
4
4
|
type ChangeEventHandler,
|
|
5
5
|
createElement,
|
|
6
|
-
forwardRef,
|
|
7
6
|
type InputHTMLAttributes,
|
|
8
7
|
type KeyboardEvent,
|
|
9
8
|
type ReactNode,
|
|
9
|
+
type Ref,
|
|
10
10
|
} from 'react'
|
|
11
11
|
|
|
12
12
|
type InputMode = 'none' | 'text' | 'decimal' | 'numeric' | 'tel' | 'search' | 'email' | 'url'
|
|
@@ -23,10 +23,12 @@ const INPUT_MODES: Record<string, InputMode> = {
|
|
|
23
23
|
|
|
24
24
|
type DomInputProps = Omit<
|
|
25
25
|
InputHTMLAttributes<HTMLInputElement>,
|
|
26
|
-
'children' | 'onChange' | 'onKeyDown' | 'readOnly' | 'size' | 'style' | 'value'
|
|
26
|
+
'autoCorrect' | 'children' | 'onChange' | 'onKeyDown' | 'readOnly' | 'size' | 'style' | 'value'
|
|
27
27
|
>
|
|
28
28
|
|
|
29
29
|
export interface HozoTextInputProps extends DomInputProps {
|
|
30
|
+
/** Declared here, because React 19 takes `ref` as an ordinary prop. */
|
|
31
|
+
ref?: Ref<HTMLInputElement | HTMLTextAreaElement>
|
|
30
32
|
children?: ReactNode
|
|
31
33
|
value?: string
|
|
32
34
|
style?: HozoDomStyle
|
|
@@ -40,6 +42,8 @@ export interface HozoTextInputProps extends DomInputProps {
|
|
|
40
42
|
onKeyPress?: (event: KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => void
|
|
41
43
|
onSubmitEditing?: (event: { nativeEvent: { text: string } }) => void
|
|
42
44
|
editable?: boolean
|
|
45
|
+
/** React Native uses a boolean; the DOM spells it as "on" / "off". */
|
|
46
|
+
autoCorrect?: boolean
|
|
43
47
|
readOnly?: boolean
|
|
44
48
|
multiline?: boolean
|
|
45
49
|
numberOfLines?: number
|
|
@@ -56,74 +60,72 @@ export interface HozoTextInputProps extends DomInputProps {
|
|
|
56
60
|
}
|
|
57
61
|
|
|
58
62
|
/** A value-level TextInput for factories and other code the JSX compiler cannot rewrite. */
|
|
59
|
-
export
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (
|
|
99
|
-
onSubmitEditing({ nativeEvent: { text: event.currentTarget.value } })
|
|
100
|
-
if (blurOnSubmit) event.currentTarget.blur()
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
const resolvedStyle = hozoDomStyle([
|
|
104
|
-
style,
|
|
105
|
-
cursorColor || selectionColor ? { caretColor: cursorColor ?? selectionColor } : undefined,
|
|
106
|
-
])
|
|
107
|
-
const shared = {
|
|
108
|
-
...props,
|
|
109
|
-
id: nativeID,
|
|
110
|
-
value,
|
|
111
|
-
readOnly: readOnly ?? (editable === undefined ? undefined : !editable),
|
|
112
|
-
inputMode: inputMode ?? (keyboardType ? INPUT_MODES[keyboardType] : undefined),
|
|
113
|
-
enterKeyHint: returnKeyType as InputHTMLAttributes<HTMLInputElement>['enterKeyHint'],
|
|
114
|
-
style: resolvedStyle,
|
|
115
|
-
'aria-label': accessibilityLabel,
|
|
116
|
-
'aria-description': accessibilityHint,
|
|
117
|
-
'aria-labelledby': accessibilityLabelledBy,
|
|
118
|
-
'data-testid': testID,
|
|
119
|
-
onChange: change,
|
|
120
|
-
onKeyDown: keyDown,
|
|
63
|
+
export function HozoTextInput({
|
|
64
|
+
ref,
|
|
65
|
+
autoCorrect,
|
|
66
|
+
accessibilityHint,
|
|
67
|
+
accessibilityLabel,
|
|
68
|
+
accessibilityLabelledBy,
|
|
69
|
+
blurOnSubmit,
|
|
70
|
+
cursorColor,
|
|
71
|
+
editable,
|
|
72
|
+
hitSlop: _hitSlop,
|
|
73
|
+
inputMode,
|
|
74
|
+
keyboardAppearance: _keyboardAppearance,
|
|
75
|
+
keyboardType,
|
|
76
|
+
multiline,
|
|
77
|
+
nativeID,
|
|
78
|
+
numberOfLines,
|
|
79
|
+
onChange,
|
|
80
|
+
onChangeText,
|
|
81
|
+
onKeyPress,
|
|
82
|
+
onSubmitEditing,
|
|
83
|
+
placeholderTextColor: _placeholderTextColor,
|
|
84
|
+
readOnly,
|
|
85
|
+
returnKeyType,
|
|
86
|
+
secureTextEntry,
|
|
87
|
+
selectionColor,
|
|
88
|
+
style,
|
|
89
|
+
testID,
|
|
90
|
+
value,
|
|
91
|
+
...props
|
|
92
|
+
}: HozoTextInputProps) {
|
|
93
|
+
const change = (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
|
94
|
+
onChange?.(event)
|
|
95
|
+
onChangeText?.(event.currentTarget.value)
|
|
96
|
+
}
|
|
97
|
+
const keyDown = (event: KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => {
|
|
98
|
+
onKeyPress?.(event)
|
|
99
|
+
if (event.key !== 'Enter' || !onSubmitEditing) return
|
|
100
|
+
if (!multiline || blurOnSubmit) {
|
|
101
|
+
onSubmitEditing({ nativeEvent: { text: event.currentTarget.value } })
|
|
102
|
+
if (blurOnSubmit) event.currentTarget.blur()
|
|
121
103
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
104
|
+
}
|
|
105
|
+
const resolvedStyle = hozoDomStyle([
|
|
106
|
+
style,
|
|
107
|
+
cursorColor || selectionColor ? { caretColor: cursorColor ?? selectionColor } : undefined,
|
|
108
|
+
])
|
|
109
|
+
const shared = {
|
|
110
|
+
...props,
|
|
111
|
+
autoCorrect: autoCorrect === undefined ? undefined : autoCorrect ? 'on' : 'off',
|
|
112
|
+
id: nativeID,
|
|
113
|
+
value,
|
|
114
|
+
readOnly: readOnly ?? (editable === undefined ? undefined : !editable),
|
|
115
|
+
inputMode: inputMode ?? (keyboardType ? INPUT_MODES[keyboardType] : undefined),
|
|
116
|
+
enterKeyHint: returnKeyType as InputHTMLAttributes<HTMLInputElement>['enterKeyHint'],
|
|
117
|
+
style: resolvedStyle,
|
|
118
|
+
'aria-label': accessibilityLabel,
|
|
119
|
+
'aria-description': accessibilityHint,
|
|
120
|
+
'aria-labelledby': accessibilityLabelledBy,
|
|
121
|
+
'data-testid': testID,
|
|
122
|
+
onChange: change,
|
|
123
|
+
onKeyDown: keyDown,
|
|
124
|
+
}
|
|
125
|
+
return createElement(multiline ? 'textarea' : 'input', {
|
|
126
|
+
...shared,
|
|
127
|
+
ref,
|
|
128
|
+
rows: multiline ? numberOfLines : undefined,
|
|
129
|
+
type: multiline ? undefined : secureTextEntry ? 'password' : props.type,
|
|
130
|
+
})
|
|
131
|
+
}
|
package/src/view.ts
CHANGED
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
} from '@hozo/engine'
|
|
7
7
|
import {
|
|
8
8
|
createElement,
|
|
9
|
-
forwardRef,
|
|
10
9
|
type HTMLAttributes,
|
|
11
10
|
type ReactNode,
|
|
12
11
|
type Ref,
|
|
@@ -42,6 +41,15 @@ export interface HozoViewProps
|
|
|
42
41
|
onLayout?: (event: HozoLayoutEvent) => void
|
|
43
42
|
collapsable?: boolean
|
|
44
43
|
'data-hozo-disabled'?: string
|
|
44
|
+
/**
|
|
45
|
+
* Declared here rather than supplied by `forwardRef`'s return type.
|
|
46
|
+
*
|
|
47
|
+
* React 19 takes `ref` as an ordinary prop, so the component is a plain
|
|
48
|
+
* function and nothing adds `ref` to its props on the way out. A caller's
|
|
49
|
+
* `ref` is accepted because this line says so, which is also why it has to
|
|
50
|
+
* be destructured below: `...props` would otherwise carry it to the `div`.
|
|
51
|
+
*/
|
|
52
|
+
ref?: Ref<HTMLDivElement>
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
function assignRef<T>(ref: Ref<T> | undefined, value: T | null) {
|
|
@@ -50,40 +58,38 @@ function assignRef<T>(ref: Ref<T> | undefined, value: T | null) {
|
|
|
50
58
|
}
|
|
51
59
|
|
|
52
60
|
/** A measured/responder-aware View for the Web paths that cannot be a plain div. */
|
|
53
|
-
export
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
forwardedRef,
|
|
86
|
-
) {
|
|
61
|
+
export function HozoView({
|
|
62
|
+
ref: forwardedRef,
|
|
63
|
+
children,
|
|
64
|
+
style,
|
|
65
|
+
testID,
|
|
66
|
+
nativeID,
|
|
67
|
+
pointerEvents,
|
|
68
|
+
accessibilityLabel,
|
|
69
|
+
accessibilityHint,
|
|
70
|
+
accessibilityRole,
|
|
71
|
+
accessibilityState,
|
|
72
|
+
accessibilityValue,
|
|
73
|
+
accessibilityLiveRegion,
|
|
74
|
+
onLayout,
|
|
75
|
+
collapsable: _collapsable,
|
|
76
|
+
role,
|
|
77
|
+
'aria-disabled': ariaDisabled,
|
|
78
|
+
'data-hozo-disabled': dataHozoDisabled,
|
|
79
|
+
onStartShouldSetResponder,
|
|
80
|
+
onStartShouldSetResponderCapture,
|
|
81
|
+
onMoveShouldSetResponder,
|
|
82
|
+
onMoveShouldSetResponderCapture,
|
|
83
|
+
onResponderGrant,
|
|
84
|
+
onResponderStart,
|
|
85
|
+
onResponderMove,
|
|
86
|
+
onResponderEnd,
|
|
87
|
+
onResponderRelease,
|
|
88
|
+
onResponderReject,
|
|
89
|
+
onResponderTerminate,
|
|
90
|
+
onResponderTerminationRequest,
|
|
91
|
+
...props
|
|
92
|
+
}: HozoViewProps) {
|
|
87
93
|
const elementRef = useRef<HTMLDivElement>(null)
|
|
88
94
|
const layoutCallback = useRef(onLayout)
|
|
89
95
|
layoutCallback.current = onLayout
|
|
@@ -162,4 +168,4 @@ export const HozoView = forwardRef<HTMLDivElement, HozoViewProps>(function HozoV
|
|
|
162
168
|
},
|
|
163
169
|
children,
|
|
164
170
|
)
|
|
165
|
-
}
|
|
171
|
+
}
|