@hozo/primitives 0.1.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/LICENSE +21 -0
- package/README.md +54 -0
- package/dist/flat-list.native.d.ts +17 -0
- package/dist/flat-list.native.d.ts.map +1 -0
- package/dist/flat-list.native.js +89 -0
- package/dist/flat-list.native.js.map +1 -0
- package/dist/foundation.d.ts +104 -0
- package/dist/foundation.d.ts.map +1 -0
- package/dist/foundation.js +115 -0
- package/dist/foundation.js.map +1 -0
- package/dist/foundation.native.d.ts +59 -0
- package/dist/foundation.native.d.ts.map +1 -0
- package/dist/foundation.native.js +40 -0
- package/dist/foundation.native.js.map +1 -0
- package/dist/generated/animated.d.ts +2 -0
- package/dist/generated/animated.d.ts.map +1 -0
- package/dist/generated/animated.js +3 -0
- package/dist/generated/animated.js.map +1 -0
- package/dist/generated/backdrop-filter.d.ts +2 -0
- package/dist/generated/backdrop-filter.d.ts.map +1 -0
- package/dist/generated/backdrop-filter.js +3 -0
- package/dist/generated/backdrop-filter.js.map +1 -0
- package/dist/generated/container.d.ts +2 -0
- package/dist/generated/container.d.ts.map +1 -0
- package/dist/generated/container.js +3 -0
- package/dist/generated/container.js.map +1 -0
- package/dist/generated/flat-list.d.ts +2 -0
- package/dist/generated/flat-list.d.ts.map +1 -0
- package/dist/generated/flat-list.js +2 -0
- package/dist/generated/flat-list.js.map +1 -0
- package/dist/generated/flat-list.native.d.ts +3 -0
- package/dist/generated/flat-list.native.d.ts.map +1 -0
- package/dist/generated/flat-list.native.js +2 -0
- package/dist/generated/flat-list.native.js.map +1 -0
- package/dist/generated/grid.d.ts +3 -0
- package/dist/generated/grid.d.ts.map +1 -0
- package/dist/generated/grid.js +4 -0
- package/dist/generated/grid.js.map +1 -0
- package/dist/generated/link.d.ts +2 -0
- package/dist/generated/link.d.ts.map +1 -0
- package/dist/generated/link.js +2 -0
- package/dist/generated/link.js.map +1 -0
- package/dist/generated/link.native.d.ts +2 -0
- package/dist/generated/link.native.d.ts.map +1 -0
- package/dist/generated/link.native.js +2 -0
- package/dist/generated/link.native.js.map +1 -0
- package/dist/generated/pressable.d.ts +2 -0
- package/dist/generated/pressable.d.ts.map +1 -0
- package/dist/generated/pressable.js +2 -0
- package/dist/generated/pressable.js.map +1 -0
- package/dist/generated/pressable.native.d.ts +2 -0
- package/dist/generated/pressable.native.d.ts.map +1 -0
- package/dist/generated/pressable.native.js +2 -0
- package/dist/generated/pressable.native.js.map +1 -0
- package/dist/generated/refresh-control.d.ts +2 -0
- package/dist/generated/refresh-control.d.ts.map +1 -0
- package/dist/generated/refresh-control.js +2 -0
- package/dist/generated/refresh-control.js.map +1 -0
- package/dist/generated/refresh-control.native.d.ts +2 -0
- package/dist/generated/refresh-control.native.d.ts.map +1 -0
- package/dist/generated/refresh-control.native.js +2 -0
- package/dist/generated/refresh-control.native.js.map +1 -0
- package/dist/generated/scroll-view.d.ts +2 -0
- package/dist/generated/scroll-view.d.ts.map +1 -0
- package/dist/generated/scroll-view.js +2 -0
- package/dist/generated/scroll-view.js.map +1 -0
- package/dist/generated/scroll-view.native.d.ts +2 -0
- package/dist/generated/scroll-view.native.d.ts.map +1 -0
- package/dist/generated/scroll-view.native.js +2 -0
- package/dist/generated/scroll-view.native.js.map +1 -0
- package/dist/generated/spaced.d.ts +2 -0
- package/dist/generated/spaced.d.ts.map +1 -0
- package/dist/generated/spaced.js +3 -0
- package/dist/generated/spaced.js.map +1 -0
- package/dist/generated/text-input.d.ts +2 -0
- package/dist/generated/text-input.d.ts.map +1 -0
- package/dist/generated/text-input.js +2 -0
- package/dist/generated/text-input.js.map +1 -0
- package/dist/generated/text-input.native.d.ts +2 -0
- package/dist/generated/text-input.native.d.ts.map +1 -0
- package/dist/generated/text-input.native.js +2 -0
- package/dist/generated/text-input.native.js.map +1 -0
- package/dist/generated/text-size.d.ts +2 -0
- package/dist/generated/text-size.d.ts.map +1 -0
- package/dist/generated/text-size.js +3 -0
- package/dist/generated/text-size.js.map +1 -0
- package/dist/generated/text.d.ts +2 -0
- package/dist/generated/text.d.ts.map +1 -0
- package/dist/generated/text.js +5 -0
- package/dist/generated/text.js.map +1 -0
- package/dist/generated/view.d.ts +2 -0
- package/dist/generated/view.d.ts.map +1 -0
- package/dist/generated/view.js +2 -0
- package/dist/generated/view.js.map +1 -0
- package/dist/generated/view.native.d.ts +2 -0
- package/dist/generated/view.native.d.ts.map +1 -0
- package/dist/generated/view.native.js +2 -0
- package/dist/generated/view.native.js.map +1 -0
- package/dist/index.d.ts +188 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +718 -0
- package/dist/index.js.map +1 -0
- package/dist/index.native.d.ts +22 -0
- package/dist/index.native.d.ts.map +1 -0
- package/dist/index.native.js +8 -0
- package/dist/index.native.js.map +1 -0
- package/dist/link.d.ts +320 -0
- package/dist/link.d.ts.map +1 -0
- package/dist/link.js +69 -0
- package/dist/link.js.map +1 -0
- package/dist/link.native.d.ts +33 -0
- package/dist/link.native.d.ts.map +1 -0
- package/dist/link.native.js +44 -0
- package/dist/link.native.js.map +1 -0
- package/dist/pressable.d.ts +65 -0
- package/dist/pressable.d.ts.map +1 -0
- package/dist/pressable.js +202 -0
- package/dist/pressable.js.map +1 -0
- package/dist/pressable.native.d.ts +55 -0
- package/dist/pressable.native.d.ts.map +1 -0
- package/dist/pressable.native.js +405 -0
- package/dist/pressable.native.js.map +1 -0
- package/dist/runtime-backdrop.native.d.ts +8 -0
- package/dist/runtime-backdrop.native.d.ts.map +1 -0
- package/dist/runtime-backdrop.native.js +12 -0
- package/dist/runtime-backdrop.native.js.map +1 -0
- package/dist/runtime-container.native.d.ts +41 -0
- package/dist/runtime-container.native.d.ts.map +1 -0
- package/dist/runtime-container.native.js +61 -0
- package/dist/runtime-container.native.js.map +1 -0
- package/dist/runtime-grid.d.ts +37 -0
- package/dist/runtime-grid.d.ts.map +1 -0
- package/dist/runtime-grid.js +139 -0
- package/dist/runtime-grid.js.map +1 -0
- package/dist/runtime-grid.native.d.ts +26 -0
- package/dist/runtime-grid.native.d.ts.map +1 -0
- package/dist/runtime-grid.native.js +76 -0
- package/dist/runtime-grid.native.js.map +1 -0
- package/dist/runtime-measured.d.ts +20 -0
- package/dist/runtime-measured.d.ts.map +1 -0
- package/dist/runtime-measured.js +42 -0
- package/dist/runtime-measured.js.map +1 -0
- package/dist/runtime-spacing.d.ts +9 -0
- package/dist/runtime-spacing.d.ts.map +1 -0
- package/dist/runtime-spacing.js +35 -0
- package/dist/runtime-spacing.js.map +1 -0
- package/dist/runtime-spacing.native.d.ts +12 -0
- package/dist/runtime-spacing.native.d.ts.map +1 -0
- package/dist/runtime-spacing.native.js +64 -0
- package/dist/runtime-spacing.native.js.map +1 -0
- package/dist/runtime-text-size.native.d.ts +29 -0
- package/dist/runtime-text-size.native.d.ts.map +1 -0
- package/dist/runtime-text-size.native.js +51 -0
- package/dist/runtime-text-size.native.js.map +1 -0
- package/dist/runtime-transition.native.d.ts +15 -0
- package/dist/runtime-transition.native.d.ts.map +1 -0
- package/dist/runtime-transition.native.js +156 -0
- package/dist/runtime-transition.native.js.map +1 -0
- package/dist/text-input.d.ts +40 -0
- package/dist/text-input.d.ts.map +1 -0
- package/dist/text-input.js +54 -0
- package/dist/text-input.js.map +1 -0
- package/dist/view.d.ts +42 -0
- package/dist/view.d.ts.map +1 -0
- package/dist/view.js +84 -0
- package/dist/view.js.map +1 -0
- package/dist/view.native.d.ts +8 -0
- package/dist/view.native.d.ts.map +1 -0
- package/dist/view.native.js +5 -0
- package/dist/view.native.js.map +1 -0
- package/dist/windowing.d.ts +149 -0
- package/dist/windowing.d.ts.map +1 -0
- package/dist/windowing.js +336 -0
- package/dist/windowing.js.map +1 -0
- package/package.json +160 -0
- package/src/flat-list.native.tsx +158 -0
- package/src/foundation.native.tsx +179 -0
- package/src/foundation.tsx +323 -0
- package/src/generated/animated.ts +6 -0
- package/src/generated/backdrop-filter.ts +5 -0
- package/src/generated/container.ts +7 -0
- package/src/generated/flat-list.native.ts +6 -0
- package/src/generated/flat-list.ts +7 -0
- package/src/generated/grid.ts +4 -0
- package/src/generated/link.native.ts +1 -0
- package/src/generated/link.ts +1 -0
- package/src/generated/pressable.native.ts +5 -0
- package/src/generated/pressable.ts +5 -0
- package/src/generated/refresh-control.native.ts +4 -0
- package/src/generated/refresh-control.ts +1 -0
- package/src/generated/scroll-view.native.ts +4 -0
- package/src/generated/scroll-view.ts +1 -0
- package/src/generated/spaced.ts +2 -0
- package/src/generated/text-input.native.ts +4 -0
- package/src/generated/text-input.ts +1 -0
- package/src/generated/text-size.ts +7 -0
- package/src/generated/text.ts +8 -0
- package/src/generated/view.native.ts +1 -0
- package/src/generated/view.ts +1 -0
- package/src/index.native.ts +24 -0
- package/src/index.ts +1111 -0
- package/src/link.native.tsx +77 -0
- package/src/link.ts +125 -0
- package/src/pressable.native.tsx +538 -0
- package/src/pressable.ts +358 -0
- package/src/runtime-backdrop.native.tsx +22 -0
- package/src/runtime-container.native.tsx +105 -0
- package/src/runtime-grid.native.tsx +143 -0
- package/src/runtime-grid.ts +198 -0
- package/src/runtime-measured.ts +42 -0
- package/src/runtime-spacing.native.tsx +75 -0
- package/src/runtime-spacing.ts +37 -0
- package/src/runtime-text-size.native.tsx +79 -0
- package/src/runtime-transition.native.tsx +183 -0
- package/src/text-input.ts +129 -0
- package/src/view.native.ts +7 -0
- package/src/view.ts +165 -0
- package/src/windowing.ts +415 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { hozoTextChildren } from '@hozo/behaviors'
|
|
2
|
+
import { HozoTextSizeContext } from '@hozo/engine'
|
|
3
|
+
import React, { type ComponentType, type ReactNode } from 'react'
|
|
4
|
+
import {
|
|
5
|
+
type AccessibilityRole,
|
|
6
|
+
Pressable as RNPressable,
|
|
7
|
+
type PressableProps as RNPressableProps,
|
|
8
|
+
Text as RNText,
|
|
9
|
+
type TextProps as RNTextProps,
|
|
10
|
+
type StyleProp,
|
|
11
|
+
StyleSheet,
|
|
12
|
+
type TextStyle,
|
|
13
|
+
type ViewStyle,
|
|
14
|
+
} from 'react-native'
|
|
15
|
+
import { HozoLink } from './link.native.tsx'
|
|
16
|
+
|
|
17
|
+
export type {
|
|
18
|
+
HozoResponderEvent,
|
|
19
|
+
HozoResponderTouch,
|
|
20
|
+
HozoTouchHistory,
|
|
21
|
+
HozoTouchTrack,
|
|
22
|
+
ResponderProps,
|
|
23
|
+
} from '@hozo/engine'
|
|
24
|
+
export type {
|
|
25
|
+
ImageProps,
|
|
26
|
+
TextInputProps,
|
|
27
|
+
ViewProps,
|
|
28
|
+
} from 'react-native'
|
|
29
|
+
export { Image, TextInput, View } from 'react-native'
|
|
30
|
+
export type {
|
|
31
|
+
HozoImageSource,
|
|
32
|
+
HozoImageSourceObject,
|
|
33
|
+
HozoLayoutEvent,
|
|
34
|
+
HozoLayoutRectangle,
|
|
35
|
+
HozoStyle,
|
|
36
|
+
UniversalProps,
|
|
37
|
+
} from './foundation.tsx'
|
|
38
|
+
|
|
39
|
+
export type TextProps = RNTextProps
|
|
40
|
+
|
|
41
|
+
export function Text({ children, style, ...props }: TextProps) {
|
|
42
|
+
const size = StyleSheet.flatten(style)?.fontSize
|
|
43
|
+
const text = React.createElement(RNText, { style, ...props }, children)
|
|
44
|
+
if (size === undefined) return text
|
|
45
|
+
return <HozoTextSizeContext.Provider value={size}>{text}</HozoTextSizeContext.Provider>
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface PressableProps extends RNPressableProps {
|
|
49
|
+
href?: string
|
|
50
|
+
external?: boolean
|
|
51
|
+
replace?: boolean
|
|
52
|
+
prefetch?: boolean
|
|
53
|
+
target?: string
|
|
54
|
+
rel?: string
|
|
55
|
+
download?: boolean | string
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export function Pressable({
|
|
59
|
+
href,
|
|
60
|
+
external,
|
|
61
|
+
replace,
|
|
62
|
+
prefetch,
|
|
63
|
+
target: _target,
|
|
64
|
+
rel: _rel,
|
|
65
|
+
download: _download,
|
|
66
|
+
...props
|
|
67
|
+
}: PressableProps) {
|
|
68
|
+
if (href === undefined) return <RNPressable {...props} />
|
|
69
|
+
|
|
70
|
+
const Link = HozoLink as unknown as ComponentType<
|
|
71
|
+
{ href: string; external?: boolean; replace?: boolean; prefetch?: boolean } & RNPressableProps
|
|
72
|
+
>
|
|
73
|
+
return <Link href={href} external={external} replace={replace} prefetch={prefetch} {...props} />
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface LinkProps {
|
|
77
|
+
className?: string
|
|
78
|
+
children?: ReactNode
|
|
79
|
+
href: string
|
|
80
|
+
external?: boolean
|
|
81
|
+
replace?: boolean
|
|
82
|
+
prefetch?: boolean
|
|
83
|
+
target?: string
|
|
84
|
+
rel?: string
|
|
85
|
+
download?: boolean | string
|
|
86
|
+
onPress?: (event: { defaultPrevented?: boolean }) => void
|
|
87
|
+
style?: StyleProp<TextStyle>
|
|
88
|
+
testID?: string
|
|
89
|
+
nativeID?: string
|
|
90
|
+
accessibilityLabel?: string
|
|
91
|
+
accessibilityHint?: string
|
|
92
|
+
accessibilityRole?: AccessibilityRole
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function Link({
|
|
96
|
+
href,
|
|
97
|
+
external,
|
|
98
|
+
replace,
|
|
99
|
+
prefetch,
|
|
100
|
+
target: _target,
|
|
101
|
+
rel: _rel,
|
|
102
|
+
download: _download,
|
|
103
|
+
...props
|
|
104
|
+
}: LinkProps) {
|
|
105
|
+
const NativeLink = HozoLink as unknown as ComponentType<
|
|
106
|
+
{ href: string; external?: boolean; replace?: boolean; prefetch?: boolean } & Omit<
|
|
107
|
+
LinkProps,
|
|
108
|
+
'href' | 'external' | 'replace' | 'prefetch'
|
|
109
|
+
>
|
|
110
|
+
>
|
|
111
|
+
return (
|
|
112
|
+
<NativeLink href={href} external={external} replace={replace} prefetch={prefetch} {...props} />
|
|
113
|
+
)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface ButtonProps {
|
|
117
|
+
className?: string
|
|
118
|
+
children?: ReactNode
|
|
119
|
+
onPress?: RNPressableProps['onPress']
|
|
120
|
+
disabled?: boolean
|
|
121
|
+
accessibilityLabel?: string
|
|
122
|
+
accessibilityHint?: string
|
|
123
|
+
href?: string
|
|
124
|
+
external?: boolean
|
|
125
|
+
replace?: boolean
|
|
126
|
+
prefetch?: boolean
|
|
127
|
+
target?: string
|
|
128
|
+
rel?: string
|
|
129
|
+
download?: boolean | string
|
|
130
|
+
style?: StyleProp<ViewStyle>
|
|
131
|
+
testID?: string
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export type ButtonNativeProps = ButtonProps
|
|
135
|
+
|
|
136
|
+
export function Button({
|
|
137
|
+
children,
|
|
138
|
+
onPress,
|
|
139
|
+
disabled,
|
|
140
|
+
accessibilityLabel,
|
|
141
|
+
accessibilityHint,
|
|
142
|
+
href,
|
|
143
|
+
external,
|
|
144
|
+
replace,
|
|
145
|
+
prefetch,
|
|
146
|
+
style,
|
|
147
|
+
testID,
|
|
148
|
+
}: ButtonProps) {
|
|
149
|
+
const shared = {
|
|
150
|
+
disabled,
|
|
151
|
+
accessibilityLabel,
|
|
152
|
+
accessibilityHint,
|
|
153
|
+
accessibilityState: disabled === undefined ? undefined : { disabled },
|
|
154
|
+
style,
|
|
155
|
+
testID,
|
|
156
|
+
}
|
|
157
|
+
if (href !== undefined) {
|
|
158
|
+
const NativeLink = HozoLink as unknown as ComponentType<
|
|
159
|
+
{ href: string; children?: ReactNode } & Omit<ButtonProps, 'href' | 'children'>
|
|
160
|
+
>
|
|
161
|
+
return (
|
|
162
|
+
<NativeLink
|
|
163
|
+
href={href}
|
|
164
|
+
external={external}
|
|
165
|
+
replace={replace}
|
|
166
|
+
prefetch={prefetch}
|
|
167
|
+
onPress={onPress}
|
|
168
|
+
{...shared}
|
|
169
|
+
>
|
|
170
|
+
{children}
|
|
171
|
+
</NativeLink>
|
|
172
|
+
)
|
|
173
|
+
}
|
|
174
|
+
return (
|
|
175
|
+
<RNPressable accessibilityRole="button" onPress={onPress} {...shared}>
|
|
176
|
+
{hozoTextChildren(children)}
|
|
177
|
+
</RNPressable>
|
|
178
|
+
)
|
|
179
|
+
}
|
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
// Canonical authored primitives. The compiler normally lowers these to a
|
|
2
|
+
// platform element, but these implementations keep uncompiled and partially
|
|
3
|
+
// compiled source useful instead of turning compilation into a runtime
|
|
4
|
+
// requirement.
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
type HozoDomStyle,
|
|
8
|
+
hozoDomStyle,
|
|
9
|
+
type ResponderProps,
|
|
10
|
+
useResponderDomProps,
|
|
11
|
+
} from '@hozo/engine'
|
|
12
|
+
import {
|
|
13
|
+
type AriaRole,
|
|
14
|
+
type CSSProperties,
|
|
15
|
+
type MouseEventHandler,
|
|
16
|
+
type ReactNode,
|
|
17
|
+
useEffect,
|
|
18
|
+
useRef,
|
|
19
|
+
useState,
|
|
20
|
+
} from 'react'
|
|
21
|
+
import { HozoLink } from './link.ts'
|
|
22
|
+
import { HozoPressable, type HozoPressableProps } from './pressable.ts'
|
|
23
|
+
import { HozoTextInput, type HozoTextInputProps } from './text-input.ts'
|
|
24
|
+
|
|
25
|
+
export type {
|
|
26
|
+
HozoResponderEvent,
|
|
27
|
+
HozoResponderTouch,
|
|
28
|
+
HozoTouchHistory,
|
|
29
|
+
HozoTouchTrack,
|
|
30
|
+
ResponderProps,
|
|
31
|
+
} from '@hozo/engine'
|
|
32
|
+
|
|
33
|
+
export interface HozoLayoutRectangle {
|
|
34
|
+
x: number
|
|
35
|
+
y: number
|
|
36
|
+
width: number
|
|
37
|
+
height: number
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface HozoLayoutEvent {
|
|
41
|
+
nativeEvent: { layout: HozoLayoutRectangle }
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export type HozoStyle = HozoDomStyle
|
|
45
|
+
|
|
46
|
+
export interface UniversalProps {
|
|
47
|
+
role?: AriaRole
|
|
48
|
+
style?: HozoStyle
|
|
49
|
+
testID?: string
|
|
50
|
+
nativeID?: string
|
|
51
|
+
pointerEvents?: 'auto' | 'none' | 'box-none' | 'box-only'
|
|
52
|
+
accessibilityState?: {
|
|
53
|
+
disabled?: boolean
|
|
54
|
+
selected?: boolean
|
|
55
|
+
checked?: boolean | 'mixed'
|
|
56
|
+
busy?: boolean
|
|
57
|
+
expanded?: boolean
|
|
58
|
+
}
|
|
59
|
+
accessibilityValue?: { min?: number; max?: number; now?: number; text?: string }
|
|
60
|
+
accessibilityLiveRegion?: 'none' | 'polite' | 'assertive'
|
|
61
|
+
accessibilityLabel?: string
|
|
62
|
+
accessibilityHint?: string
|
|
63
|
+
onLayout?: (event: HozoLayoutEvent) => void
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function universalDomProps(props: UniversalProps) {
|
|
67
|
+
const state = props.accessibilityState
|
|
68
|
+
const value = props.accessibilityValue
|
|
69
|
+
return {
|
|
70
|
+
role: props.role,
|
|
71
|
+
style: hozoDomStyle(props.style),
|
|
72
|
+
'data-testid': props.testID,
|
|
73
|
+
id: props.nativeID,
|
|
74
|
+
'data-hozo-pointer-events': props.pointerEvents,
|
|
75
|
+
'data-hozo-disabled': state?.disabled ? '' : undefined,
|
|
76
|
+
'aria-disabled': state?.disabled,
|
|
77
|
+
'aria-selected': state?.selected,
|
|
78
|
+
'aria-checked': state?.checked,
|
|
79
|
+
'aria-busy': state?.busy,
|
|
80
|
+
'aria-expanded': state?.expanded,
|
|
81
|
+
'aria-valuemin': value?.min,
|
|
82
|
+
'aria-valuemax': value?.max,
|
|
83
|
+
'aria-valuenow': value?.now,
|
|
84
|
+
'aria-valuetext': value?.text,
|
|
85
|
+
'aria-live':
|
|
86
|
+
props.accessibilityLiveRegion === 'none' ? undefined : props.accessibilityLiveRegion,
|
|
87
|
+
'aria-label': props.accessibilityLabel,
|
|
88
|
+
'aria-description': props.accessibilityHint,
|
|
89
|
+
} as const
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function useLayoutRef<T extends HTMLElement>(onLayout?: (event: HozoLayoutEvent) => void) {
|
|
93
|
+
const elementRef = useRef<T>(null)
|
|
94
|
+
const callbackRef = useRef(onLayout)
|
|
95
|
+
callbackRef.current = onLayout
|
|
96
|
+
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
const element = elementRef.current
|
|
99
|
+
if (!element || !callbackRef.current) return
|
|
100
|
+
|
|
101
|
+
let previous = ''
|
|
102
|
+
const emit = () => {
|
|
103
|
+
const rect = element.getBoundingClientRect()
|
|
104
|
+
const layout = {
|
|
105
|
+
x: element.offsetLeft,
|
|
106
|
+
y: element.offsetTop,
|
|
107
|
+
width: rect.width,
|
|
108
|
+
height: rect.height,
|
|
109
|
+
}
|
|
110
|
+
const key = `${layout.x}:${layout.y}:${layout.width}:${layout.height}`
|
|
111
|
+
if (key === previous) return
|
|
112
|
+
previous = key
|
|
113
|
+
callbackRef.current?.({ nativeEvent: { layout } })
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
emit()
|
|
117
|
+
if (typeof ResizeObserver === 'undefined') return
|
|
118
|
+
const observer = new ResizeObserver(emit)
|
|
119
|
+
observer.observe(element)
|
|
120
|
+
return () => observer.disconnect()
|
|
121
|
+
}, [])
|
|
122
|
+
|
|
123
|
+
return elementRef
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
export interface ViewProps extends UniversalProps, ResponderProps {
|
|
127
|
+
className?: string
|
|
128
|
+
children?: ReactNode
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export function View({ className, children, onLayout, ...universal }: ViewProps) {
|
|
132
|
+
const ref = useLayoutRef<HTMLDivElement>(onLayout)
|
|
133
|
+
const responder = useResponderDomProps(ref, universal)
|
|
134
|
+
return (
|
|
135
|
+
<div ref={ref} className={className} {...universalDomProps(universal)} {...responder}>
|
|
136
|
+
{children}
|
|
137
|
+
</div>
|
|
138
|
+
)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export interface TextProps extends UniversalProps {
|
|
142
|
+
className?: string
|
|
143
|
+
children?: ReactNode
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function Text({ className, children, onLayout, ...universal }: TextProps) {
|
|
147
|
+
const ref = useLayoutRef<HTMLSpanElement>(onLayout)
|
|
148
|
+
return (
|
|
149
|
+
<span ref={ref} className={className} {...universalDomProps(universal)}>
|
|
150
|
+
{children}
|
|
151
|
+
</span>
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export interface ImageProps extends UniversalProps {
|
|
156
|
+
className?: string
|
|
157
|
+
src: HozoImageSource
|
|
158
|
+
defaultSource?: HozoImageSource
|
|
159
|
+
alt?: string
|
|
160
|
+
accessibilityLabel?: string
|
|
161
|
+
onLoad?: (event: unknown) => void
|
|
162
|
+
onError?: (event: unknown) => void
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export interface HozoImageSourceObject {
|
|
166
|
+
uri?: string
|
|
167
|
+
default?: string
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export type HozoImageSource =
|
|
171
|
+
| string
|
|
172
|
+
| number
|
|
173
|
+
| HozoImageSourceObject
|
|
174
|
+
| readonly HozoImageSourceObject[]
|
|
175
|
+
|
|
176
|
+
function webImageSource(source?: HozoImageSource): string | undefined {
|
|
177
|
+
if (typeof source === 'string') return source
|
|
178
|
+
if (!source || typeof source !== 'object') return undefined
|
|
179
|
+
if (Array.isArray(source)) {
|
|
180
|
+
for (const candidate of source) {
|
|
181
|
+
const resolved = webImageSource(candidate)
|
|
182
|
+
if (resolved) return resolved
|
|
183
|
+
}
|
|
184
|
+
return undefined
|
|
185
|
+
}
|
|
186
|
+
const object = source as HozoImageSourceObject
|
|
187
|
+
return typeof object.uri === 'string'
|
|
188
|
+
? object.uri
|
|
189
|
+
: typeof object.default === 'string'
|
|
190
|
+
? object.default
|
|
191
|
+
: undefined
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export function Image({
|
|
195
|
+
className,
|
|
196
|
+
src,
|
|
197
|
+
defaultSource,
|
|
198
|
+
alt,
|
|
199
|
+
accessibilityLabel,
|
|
200
|
+
onLoad,
|
|
201
|
+
onError,
|
|
202
|
+
onLayout,
|
|
203
|
+
...universal
|
|
204
|
+
}: ImageProps) {
|
|
205
|
+
const ref = useLayoutRef<HTMLImageElement>(onLayout)
|
|
206
|
+
const [failedSource, setFailedSource] = useState<HozoImageSource>()
|
|
207
|
+
const webSrc =
|
|
208
|
+
(failedSource === src ? undefined : webImageSource(src)) ?? webImageSource(defaultSource)
|
|
209
|
+
return (
|
|
210
|
+
<img
|
|
211
|
+
ref={ref}
|
|
212
|
+
className={className}
|
|
213
|
+
src={webSrc}
|
|
214
|
+
alt={alt ?? accessibilityLabel ?? ''}
|
|
215
|
+
onLoad={onLoad}
|
|
216
|
+
onError={(event) => {
|
|
217
|
+
setFailedSource(src)
|
|
218
|
+
onError?.(event)
|
|
219
|
+
}}
|
|
220
|
+
{...universalDomProps(universal)}
|
|
221
|
+
/>
|
|
222
|
+
)
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
export {
|
|
226
|
+
HozoPressable as Pressable,
|
|
227
|
+
type HozoPressableProps as PressableProps,
|
|
228
|
+
HozoTextInput as TextInput,
|
|
229
|
+
type HozoTextInputProps as TextInputProps,
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export interface LinkProps {
|
|
233
|
+
className?: string
|
|
234
|
+
children?: ReactNode
|
|
235
|
+
style?: CSSProperties
|
|
236
|
+
testID?: string
|
|
237
|
+
nativeID?: string
|
|
238
|
+
accessibilityLabel?: string
|
|
239
|
+
accessibilityHint?: string
|
|
240
|
+
'aria-hidden'?: boolean
|
|
241
|
+
href: string
|
|
242
|
+
target?: '_blank' | '_self' | '_parent' | '_top' | string
|
|
243
|
+
rel?: string
|
|
244
|
+
download?: boolean | string
|
|
245
|
+
external?: boolean
|
|
246
|
+
replace?: boolean
|
|
247
|
+
prefetch?: boolean
|
|
248
|
+
onPress?: MouseEventHandler<HTMLAnchorElement>
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export function Link({ children, ...props }: LinkProps) {
|
|
252
|
+
return <HozoLink {...props}>{children}</HozoLink>
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export interface ButtonProps {
|
|
256
|
+
className?: string
|
|
257
|
+
children?: ReactNode
|
|
258
|
+
onPress?: MouseEventHandler<HTMLElement>
|
|
259
|
+
disabled?: boolean
|
|
260
|
+
accessibilityLabel?: string
|
|
261
|
+
accessibilityHint?: string
|
|
262
|
+
href?: string
|
|
263
|
+
external?: boolean
|
|
264
|
+
replace?: boolean
|
|
265
|
+
prefetch?: boolean
|
|
266
|
+
target?: '_blank' | '_self' | '_parent' | '_top' | string
|
|
267
|
+
rel?: string
|
|
268
|
+
download?: boolean | string
|
|
269
|
+
testID?: string
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
export function Button({
|
|
273
|
+
className,
|
|
274
|
+
children,
|
|
275
|
+
onPress,
|
|
276
|
+
disabled,
|
|
277
|
+
accessibilityLabel,
|
|
278
|
+
accessibilityHint,
|
|
279
|
+
href,
|
|
280
|
+
external,
|
|
281
|
+
replace,
|
|
282
|
+
prefetch,
|
|
283
|
+
target,
|
|
284
|
+
rel,
|
|
285
|
+
download,
|
|
286
|
+
testID,
|
|
287
|
+
}: ButtonProps) {
|
|
288
|
+
if (href != null) {
|
|
289
|
+
return (
|
|
290
|
+
<HozoLink
|
|
291
|
+
href={href}
|
|
292
|
+
external={external}
|
|
293
|
+
replace={replace}
|
|
294
|
+
prefetch={prefetch}
|
|
295
|
+
target={target}
|
|
296
|
+
rel={rel}
|
|
297
|
+
download={download}
|
|
298
|
+
className={className}
|
|
299
|
+
accessibilityLabel={accessibilityLabel}
|
|
300
|
+
accessibilityHint={accessibilityHint}
|
|
301
|
+
disabled={disabled}
|
|
302
|
+
testID={testID}
|
|
303
|
+
onPress={onPress as MouseEventHandler<HTMLAnchorElement>}
|
|
304
|
+
>
|
|
305
|
+
{children}
|
|
306
|
+
</HozoLink>
|
|
307
|
+
)
|
|
308
|
+
}
|
|
309
|
+
return (
|
|
310
|
+
<button
|
|
311
|
+
type="button"
|
|
312
|
+
className={className}
|
|
313
|
+
disabled={disabled}
|
|
314
|
+
data-hozo-disabled={disabled ? '' : undefined}
|
|
315
|
+
aria-label={accessibilityLabel}
|
|
316
|
+
aria-description={accessibilityHint}
|
|
317
|
+
data-testid={testID}
|
|
318
|
+
onClick={onPress as MouseEventHandler<HTMLButtonElement>}
|
|
319
|
+
>
|
|
320
|
+
{children}
|
|
321
|
+
</button>
|
|
322
|
+
)
|
|
323
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { HozoLink, type HozoLinkProps } from '../link.native.tsx'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { HozoLink, type HozoLinkProps } from '../link.ts'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { HozoRefreshControl, type HozoRefreshControlProps } from '../index.ts'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { HozoScrollView, type HozoScrollViewProps } from '../index.ts'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { HozoTextInput, type HozoTextInputProps } from '../text-input.ts'
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Native-only: the Web backend lowers `Text` to an element and never asks
|
|
2
|
+
// for this. One implementation under every condition rather than a Web file
|
|
3
|
+
// that could only lie about what it is.
|
|
4
|
+
export {
|
|
5
|
+
HozoText,
|
|
6
|
+
type HozoTextProps,
|
|
7
|
+
type HozoTransition,
|
|
8
|
+
} from '../pressable.native.tsx'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { HozoView, type HozoViewProps } from '../view.native.ts'
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { HozoView, type HozoViewProps } from '../view.ts'
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as ReactNative from 'react-native'
|
|
2
|
+
|
|
3
|
+
import { HozoFlatList } from './flat-list.native.tsx'
|
|
4
|
+
|
|
5
|
+
export * from './foundation.native.tsx'
|
|
6
|
+
|
|
7
|
+
export type { HozoFlatListLayout, HozoFlatListRenderInfo, HozoScrollEvent } from './index.ts'
|
|
8
|
+
|
|
9
|
+
export type HozoScrollViewProps = ReactNative.ScrollViewProps
|
|
10
|
+
export type HozoRefreshControlProps = ReactNative.RefreshControlProps
|
|
11
|
+
|
|
12
|
+
export const HozoScrollView = ReactNative.ScrollView
|
|
13
|
+
export const HozoRefreshControl = ReactNative.RefreshControl
|
|
14
|
+
|
|
15
|
+
export {
|
|
16
|
+
HozoFlatList,
|
|
17
|
+
type HozoFlatListHandle,
|
|
18
|
+
type HozoFlatListProps,
|
|
19
|
+
} from './flat-list.native.tsx'
|
|
20
|
+
|
|
21
|
+
export type { HozoFlatListRenderInfo as FlatListRenderInfo } from './index.ts'
|
|
22
|
+
export { HozoFlatList as FlatList, HozoScrollView as ScrollView }
|
|
23
|
+
export type FlatListProps<T> = import('./flat-list.native.tsx').HozoFlatListProps<T>
|
|
24
|
+
export type ScrollViewProps = HozoScrollViewProps
|