@hozo/primitives 0.1.0 → 0.3.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.
Files changed (76) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +24 -2
  3. package/dist/flat-list.native.d.ts +8 -8
  4. package/dist/flat-list.native.d.ts.map +1 -1
  5. package/dist/flat-list.native.js +55 -25
  6. package/dist/flat-list.native.js.map +1 -1
  7. package/dist/foundation.d.ts +7 -4
  8. package/dist/foundation.d.ts.map +1 -1
  9. package/dist/foundation.js +33 -16
  10. package/dist/foundation.js.map +1 -1
  11. package/dist/foundation.native.d.ts +16 -2
  12. package/dist/foundation.native.d.ts.map +1 -1
  13. package/dist/foundation.native.js.map +1 -1
  14. package/dist/index.d.ts +6 -3
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.js +7 -9
  17. package/dist/index.js.map +1 -1
  18. package/dist/index.native.d.ts +1 -0
  19. package/dist/index.native.d.ts.map +1 -1
  20. package/dist/index.native.js +1 -0
  21. package/dist/index.native.js.map +1 -1
  22. package/dist/link.native.d.ts +16 -7
  23. package/dist/link.native.d.ts.map +1 -1
  24. package/dist/link.native.js +9 -5
  25. package/dist/link.native.js.map +1 -1
  26. package/dist/presence-context.d.ts +15 -0
  27. package/dist/presence-context.d.ts.map +1 -0
  28. package/dist/presence-context.js +11 -0
  29. package/dist/presence-context.js.map +1 -0
  30. package/dist/presence.d.ts +12 -0
  31. package/dist/presence.d.ts.map +1 -0
  32. package/dist/presence.js +45 -0
  33. package/dist/presence.js.map +1 -0
  34. package/dist/presence.native.d.ts +8 -0
  35. package/dist/presence.native.d.ts.map +1 -0
  36. package/dist/presence.native.js +66 -0
  37. package/dist/presence.native.js.map +1 -0
  38. package/dist/pressable.d.ts +9 -2
  39. package/dist/pressable.d.ts.map +1 -1
  40. package/dist/pressable.js +9 -6
  41. package/dist/pressable.js.map +1 -1
  42. package/dist/pressable.native.d.ts.map +1 -1
  43. package/dist/pressable.native.js +181 -195
  44. package/dist/pressable.native.js.map +1 -1
  45. package/dist/runtime-container.native.d.ts +11 -9
  46. package/dist/runtime-container.native.d.ts.map +1 -1
  47. package/dist/runtime-container.native.js +8 -6
  48. package/dist/runtime-container.native.js.map +1 -1
  49. package/dist/runtime-transition.native.d.ts +16 -1
  50. package/dist/runtime-transition.native.d.ts.map +1 -1
  51. package/dist/runtime-transition.native.js +34 -7
  52. package/dist/runtime-transition.native.js.map +1 -1
  53. package/dist/text-input.d.ts +319 -3
  54. package/dist/text-input.d.ts.map +1 -1
  55. package/dist/text-input.js +4 -3
  56. package/dist/text-input.js.map +1 -1
  57. package/dist/view.d.ts +11 -2
  58. package/dist/view.d.ts.map +1 -1
  59. package/dist/view.js +7 -6
  60. package/dist/view.js.map +1 -1
  61. package/package.json +4 -3
  62. package/src/flat-list.native.tsx +69 -47
  63. package/src/foundation.native.tsx +16 -1
  64. package/src/foundation.tsx +66 -25
  65. package/src/index.native.ts +2 -0
  66. package/src/index.ts +209 -219
  67. package/src/link.native.tsx +29 -18
  68. package/src/presence-context.ts +27 -0
  69. package/src/presence.native.tsx +81 -0
  70. package/src/presence.tsx +55 -0
  71. package/src/pressable.native.tsx +251 -243
  72. package/src/pressable.ts +92 -79
  73. package/src/runtime-container.native.tsx +30 -15
  74. package/src/runtime-transition.native.tsx +68 -7
  75. package/src/text-input.ts +74 -72
  76. package/src/view.ts +76 -61
package/src/pressable.ts CHANGED
@@ -2,12 +2,13 @@ import {
2
2
  type HozoDomStyle,
3
3
  hozoDomStyle,
4
4
  hozoInteractive,
5
+ hozoViewBase,
5
6
  type ResponderProps,
6
7
  useResponderDomProps,
7
8
  } from '@hozo/engine'
8
9
  import {
9
10
  createElement,
10
- forwardRef,
11
+ Fragment,
11
12
  type HTMLAttributes,
12
13
  type KeyboardEvent,
13
14
  type MouseEvent,
@@ -43,6 +44,12 @@ type DivProps = Omit<
43
44
  >
44
45
 
45
46
  export interface HozoPressableProps extends DivProps, ResponderProps {
47
+ /**
48
+ * Declared here rather than supplied by `forwardRef`. React 19 takes `ref`
49
+ * as an ordinary prop, so a plain function gets it only if its props say so
50
+ * -- and it must be destructured, or `...props` would carry it onward.
51
+ */
52
+ ref?: Ref<HTMLElement>
46
53
  children?: ReactNode | ((state: HozoPressableState) => ReactNode)
47
54
  style?: HozoDomStyle | ((state: HozoPressableState) => HozoDomStyle)
48
55
  onPress?: (event: MouseEvent<HTMLElement>) => void
@@ -102,67 +109,65 @@ function dataAttributes(dataSet: HozoPressableProps['dataSet']) {
102
109
  }
103
110
 
104
111
  /** A value-level Pressable for component props and animation wrappers. */
105
- export const HozoPressable = forwardRef<HTMLElement, HozoPressableProps>(function HozoPressable(
106
- {
107
- accessibilityActions: _accessibilityActions,
108
- accessibilityHint,
109
- accessibilityLabel,
110
- accessibilityLiveRegion,
111
- accessibilityRole,
112
- accessibilityState,
113
- accessibilityValue,
114
- accessible: _accessible,
115
- android_ripple: _androidRipple,
116
- children,
117
- dataSet,
118
- disabled,
119
- download,
120
- external,
121
- hitSlop: _hitSlop,
122
- href,
123
- nativeID,
124
- onAccessibilityAction: _onAccessibilityAction,
125
- onBlur,
126
- onClick,
127
- onFocus,
128
- onHoverIn,
129
- onHoverOut,
130
- onPointerCancel,
131
- onPointerDown,
132
- onPointerEnter,
133
- onPointerLeave,
134
- onPointerUp,
135
- onPress,
136
- onPressIn,
137
- onPressOut,
138
- onKeyDown,
139
- onKeyUp,
140
- onLostPointerCapture,
141
- onLayout,
142
- onMoveShouldSetResponder,
143
- onMoveShouldSetResponderCapture,
144
- onResponderEnd,
145
- onResponderGrant,
146
- onResponderMove,
147
- onResponderReject,
148
- onResponderRelease,
149
- onResponderStart,
150
- onResponderTerminate,
151
- onResponderTerminationRequest,
152
- onStartShouldSetResponder,
153
- onStartShouldSetResponderCapture,
154
- pointerEvents,
155
- prefetch,
156
- rel,
157
- replace,
158
- role,
159
- style,
160
- target,
161
- testID,
162
- ...props
163
- },
164
- forwardedRef,
165
- ) {
112
+ export function HozoPressable({
113
+ ref: forwardedRef,
114
+ accessibilityActions: _accessibilityActions,
115
+ accessibilityHint,
116
+ accessibilityLabel,
117
+ accessibilityLiveRegion,
118
+ accessibilityRole,
119
+ accessibilityState,
120
+ accessibilityValue,
121
+ accessible: _accessible,
122
+ android_ripple: _androidRipple,
123
+ children,
124
+ dataSet,
125
+ disabled,
126
+ download,
127
+ external,
128
+ hitSlop: _hitSlop,
129
+ href,
130
+ nativeID,
131
+ onAccessibilityAction: _onAccessibilityAction,
132
+ onBlur,
133
+ onClick,
134
+ onFocus,
135
+ onHoverIn,
136
+ onHoverOut,
137
+ onPointerCancel,
138
+ onPointerDown,
139
+ onPointerEnter,
140
+ onPointerLeave,
141
+ onPointerUp,
142
+ onPress,
143
+ onPressIn,
144
+ onPressOut,
145
+ onKeyDown,
146
+ onKeyUp,
147
+ onLostPointerCapture,
148
+ onLayout,
149
+ onMoveShouldSetResponder,
150
+ onMoveShouldSetResponderCapture,
151
+ onResponderEnd,
152
+ onResponderGrant,
153
+ onResponderMove,
154
+ onResponderReject,
155
+ onResponderRelease,
156
+ onResponderStart,
157
+ onResponderTerminate,
158
+ onResponderTerminationRequest,
159
+ onStartShouldSetResponder,
160
+ onStartShouldSetResponderCapture,
161
+ pointerEvents,
162
+ prefetch,
163
+ rel,
164
+ replace,
165
+ role,
166
+ style,
167
+ target,
168
+ testID,
169
+ ...props
170
+ }: HozoPressableProps) {
166
171
  const elementRef = useRef<HTMLElement>(null)
167
172
  const layoutCallback = useRef(onLayout)
168
173
  layoutCallback.current = onLayout
@@ -233,6 +238,7 @@ export const HozoPressable = forwardRef<HTMLElement, HozoPressableProps>(functio
233
238
  : {
234
239
  'aria-disabled': unavailable || undefined,
235
240
  'data-hozo-disabled': unavailable ? '' : undefined,
241
+ 'data-hozo-pressable': undefined,
236
242
  tabIndex: undefined,
237
243
  onClick: undefined,
238
244
  onKeyDown: undefined,
@@ -337,22 +343,29 @@ export const HozoPressable = forwardRef<HTMLElement, HozoPressableProps>(functio
337
343
  resolvedChildren,
338
344
  )
339
345
  }
346
+ // The base stylesheet carries the pointer cursor for `data-hozo-pressable`.
347
+ // Always in a fragment, so gaining a handler never remounts the element.
340
348
  return createElement(
341
- 'div',
342
- {
343
- ...common,
344
- ...interaction,
345
- onKeyDown: (event: KeyboardEvent<HTMLElement>) => {
346
- if (event.key === 'Enter' || event.key === ' ') pressIn(event)
347
- interaction.onKeyDown?.(event)
348
- onKeyDown?.(event as never)
349
- },
350
- onKeyUp: (event: KeyboardEvent<HTMLElement>) => {
351
- if (event.key === 'Enter' || event.key === ' ') pressOut(event)
352
- interaction.onKeyUp?.(event)
353
- onKeyUp?.(event as never)
354
- },
355
- } as unknown as HTMLAttributes<HTMLDivElement>,
356
- resolvedChildren,
349
+ Fragment,
350
+ null,
351
+ hozoViewBase(),
352
+ createElement(
353
+ 'div',
354
+ {
355
+ ...common,
356
+ ...interaction,
357
+ onKeyDown: (event: KeyboardEvent<HTMLElement>) => {
358
+ if (event.key === 'Enter' || event.key === ' ') pressIn(event)
359
+ interaction.onKeyDown?.(event)
360
+ onKeyDown?.(event as never)
361
+ },
362
+ onKeyUp: (event: KeyboardEvent<HTMLElement>) => {
363
+ if (event.key === 'Enter' || event.key === ' ') pressOut(event)
364
+ interaction.onKeyUp?.(event)
365
+ onKeyUp?.(event as never)
366
+ },
367
+ } as unknown as HTMLAttributes<HTMLDivElement>,
368
+ resolvedChildren,
369
+ ),
357
370
  )
358
- })
371
+ }
@@ -16,8 +16,16 @@
16
16
  // component boundary between the provider and the read, and adding a View
17
17
  // to do that would change the layout the query is measuring.
18
18
 
19
- import { createContext, type ReactNode, useContext, useMemo, useState } from 'react'
20
- import { type LayoutChangeEvent, View, type ViewProps } from 'react-native'
19
+ import {
20
+ type ComponentPropsWithRef,
21
+ createContext,
22
+ type ElementType,
23
+ type ReactNode,
24
+ useContext,
25
+ useMemo,
26
+ useState,
27
+ } from 'react'
28
+ import { type LayoutChangeEvent, View } from 'react-native'
21
29
 
22
30
  import { keepIfSettled } from './runtime-measured.ts'
23
31
 
@@ -39,24 +47,29 @@ export type HozoContainerWidths = Readonly<Record<string, number | undefined>>
39
47
 
40
48
  const HozoContainerContext = createContext<HozoContainerWidths>({})
41
49
 
42
- export interface HozoContainerProps extends ViewProps {
43
- /** `@container/main` -- the name `@sm/main:` addresses. */
44
- hozoContainerName?: string
45
- children?: ReactNode
46
- }
50
+ export type HozoContainerProps<Host extends ElementType = typeof View> =
51
+ ComponentPropsWithRef<Host> & {
52
+ /** Compiler-selected host: measurement must not turn a control into a View. */
53
+ hozoContainerComponent?: Host
54
+ /** `@container/main` -- the name `@sm/main:` addresses. */
55
+ hozoContainerName?: string
56
+ }
47
57
 
48
58
  /**
49
- * A View that measures itself and hands its width to its subtree.
59
+ * Measures the existing host and hands its width to its subtree.
50
60
  *
51
- * The compiler renders an element here instead of a View when its classes
52
- * declared it a container.
61
+ * A provider adds no layout node. The host keeps its own style/children
62
+ * callbacks, refs and events rather than asking a replacement View to
63
+ * approximate them. An ordinary container still defaults to View.
53
64
  */
54
- export function HozoContainer({
65
+ export function HozoContainer<Host extends ElementType = typeof View>({
66
+ hozoContainerComponent,
55
67
  hozoContainerName,
56
68
  onLayout,
57
69
  children,
58
70
  ...rest
59
- }: HozoContainerProps): ReactNode {
71
+ }: HozoContainerProps<Host>): ReactNode {
72
+ const Component: ElementType = hozoContainerComponent ?? View
60
73
  const [width, setWidth] = useState<number | undefined>(undefined)
61
74
  const outer = useContext(HozoContainerContext)
62
75
 
@@ -82,9 +95,11 @@ export function HozoContainer({
82
95
  }
83
96
 
84
97
  return (
85
- <View {...rest} onLayout={measure}>
86
- <HozoContainerContext.Provider value={widths}>{children}</HozoContainerContext.Provider>
87
- </View>
98
+ <HozoContainerContext.Provider value={widths}>
99
+ <Component {...rest} onLayout={measure}>
100
+ {children}
101
+ </Component>
102
+ </HozoContainerContext.Provider>
88
103
  )
89
104
  }
90
105
 
@@ -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({ style, hozoTransition, children, ...props }: HozoAnimatedProps) {
67
- const flat = useMemo(() => StyleSheet.flatten(style) ?? {}, [style])
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
- const from = useRef<ViewStyle>(flat)
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
- {children}
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 const HozoTextInput = forwardRef<HTMLInputElement | HTMLTextAreaElement, HozoTextInputProps>(
60
- function HozoTextInput(
61
- {
62
- accessibilityHint,
63
- accessibilityLabel,
64
- accessibilityLabelledBy,
65
- blurOnSubmit,
66
- cursorColor,
67
- editable,
68
- hitSlop: _hitSlop,
69
- inputMode,
70
- keyboardAppearance: _keyboardAppearance,
71
- keyboardType,
72
- multiline,
73
- nativeID,
74
- numberOfLines,
75
- onChange,
76
- onChangeText,
77
- onKeyPress,
78
- onSubmitEditing,
79
- placeholderTextColor: _placeholderTextColor,
80
- readOnly,
81
- returnKeyType,
82
- secureTextEntry,
83
- selectionColor,
84
- style,
85
- testID,
86
- value,
87
- ...props
88
- },
89
- ref,
90
- ) {
91
- const change = (event: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {
92
- onChange?.(event)
93
- onChangeText?.(event.currentTarget.value)
94
- }
95
- const keyDown = (event: KeyboardEvent<HTMLInputElement | HTMLTextAreaElement>) => {
96
- onKeyPress?.(event)
97
- if (event.key !== 'Enter' || !onSubmitEditing) return
98
- if (!multiline || blurOnSubmit) {
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
- return createElement(multiline ? 'textarea' : 'input', {
123
- ...shared,
124
- ref,
125
- rows: multiline ? numberOfLines : undefined,
126
- type: multiline ? undefined : secureTextEntry ? 'password' : props.type,
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
+ }