@hozo/primitives 0.3.0 → 0.5.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 +67 -0
- package/README.md +1 -1
- package/dist/button-host-attributes.d.ts +20 -0
- package/dist/button-host-attributes.d.ts.map +1 -0
- package/dist/button-host-attributes.js +47 -0
- package/dist/button-host-attributes.js.map +1 -0
- package/dist/button-host-props.native.d.ts +8 -0
- package/dist/button-host-props.native.d.ts.map +1 -0
- package/dist/button-host-props.native.js +20 -0
- package/dist/button-host-props.native.js.map +1 -0
- package/dist/foundation.d.ts +45 -4
- package/dist/foundation.d.ts.map +1 -1
- package/dist/foundation.js +52 -6
- package/dist/foundation.js.map +1 -1
- package/dist/foundation.native.d.ts +34 -7
- package/dist/foundation.native.d.ts.map +1 -1
- package/dist/foundation.native.js +21 -5
- package/dist/foundation.native.js.map +1 -1
- package/dist/generated/button-dom-props.d.ts +11 -0
- package/dist/generated/button-dom-props.d.ts.map +1 -0
- package/dist/generated/button-dom-props.js +155 -0
- package/dist/generated/button-dom-props.js.map +1 -0
- package/dist/generated/button-props.d.ts +3 -0
- package/dist/generated/button-props.d.ts.map +1 -0
- package/dist/generated/button-props.js +5 -0
- package/dist/generated/button-props.js.map +1 -0
- package/dist/generated/button-props.native.d.ts +2 -0
- package/dist/generated/button-props.native.d.ts.map +1 -0
- package/dist/generated/button-props.native.js +2 -0
- package/dist/generated/button-props.native.js.map +1 -0
- package/dist/generated/inherited-leaves.d.ts +2 -0
- package/dist/generated/inherited-leaves.d.ts.map +1 -0
- package/dist/generated/inherited-leaves.js +4 -0
- package/dist/generated/inherited-leaves.js.map +1 -0
- package/dist/generated/native-disabled.d.ts +2 -0
- package/dist/generated/native-disabled.d.ts.map +1 -0
- package/dist/generated/native-disabled.js +2 -0
- package/dist/generated/native-disabled.js.map +1 -0
- package/dist/generated/text-input-dom-props.d.ts +7 -0
- package/dist/generated/text-input-dom-props.d.ts.map +1 -0
- package/dist/generated/text-input-dom-props.js +130 -0
- package/dist/generated/text-input-dom-props.js.map +1 -0
- package/dist/generated/text-input.native.d.ts +1 -1
- package/dist/generated/text-input.native.d.ts.map +1 -1
- package/dist/generated/text-input.native.js +1 -1
- package/dist/generated/text-input.native.js.map +1 -1
- package/dist/generated/text.d.ts +1 -1
- package/dist/generated/text.d.ts.map +1 -1
- package/dist/generated/text.js +4 -1
- package/dist/generated/text.js.map +1 -1
- package/dist/generated/view-dom-props.d.ts +8 -0
- package/dist/generated/view-dom-props.d.ts.map +1 -0
- package/dist/generated/view-dom-props.js +241 -0
- package/dist/generated/view-dom-props.js.map +1 -0
- package/dist/inherited-leaves.native.d.ts +28 -0
- package/dist/inherited-leaves.native.d.ts.map +1 -0
- package/dist/inherited-leaves.native.js +49 -0
- package/dist/inherited-leaves.native.js.map +1 -0
- package/dist/inherited-text-scope.d.ts +8 -0
- package/dist/inherited-text-scope.d.ts.map +1 -0
- package/dist/inherited-text-scope.js +10 -0
- package/dist/inherited-text-scope.js.map +1 -0
- package/dist/link.d.ts +4 -3
- package/dist/link.d.ts.map +1 -1
- package/dist/link.js +9 -1
- package/dist/link.js.map +1 -1
- package/dist/link.native.d.ts +1 -1
- package/dist/link.native.d.ts.map +1 -1
- package/dist/link.native.js +7 -1
- package/dist/link.native.js.map +1 -1
- package/dist/native-disabled.d.ts +13 -0
- package/dist/native-disabled.d.ts.map +1 -0
- package/dist/native-disabled.js +13 -0
- package/dist/native-disabled.js.map +1 -0
- package/dist/presence.native.d.ts.map +1 -1
- package/dist/presence.native.js +1 -1
- package/dist/presence.native.js.map +1 -1
- package/dist/pressable.d.ts.map +1 -1
- package/dist/pressable.js +8 -1
- package/dist/pressable.js.map +1 -1
- package/dist/pressable.native.d.ts +23 -2
- package/dist/pressable.native.d.ts.map +1 -1
- package/dist/pressable.native.js +57 -46
- package/dist/pressable.native.js.map +1 -1
- package/dist/text-color-transition.native.d.ts +12 -0
- package/dist/text-color-transition.native.d.ts.map +1 -0
- package/dist/text-color-transition.native.js +87 -0
- package/dist/text-color-transition.native.js.map +1 -0
- package/dist/text-input-props.native.d.ts +10 -0
- package/dist/text-input-props.native.d.ts.map +1 -0
- package/dist/text-input-props.native.js +15 -0
- package/dist/text-input-props.native.js.map +1 -0
- package/dist/text-input.native.d.ts +19 -0
- package/dist/text-input.native.d.ts.map +1 -0
- package/dist/text-input.native.js +32 -0
- package/dist/text-input.native.js.map +1 -0
- package/package.json +35 -7
- package/src/button-host-attributes.ts +56 -0
- package/src/button-host-props.native.ts +22 -0
- package/src/foundation.native.tsx +59 -8
- package/src/foundation.tsx +119 -5
- package/src/generated/button-dom-props.ts +159 -0
- package/src/generated/button-props.native.ts +1 -0
- package/src/generated/button-props.ts +4 -0
- package/src/generated/inherited-leaves.ts +3 -0
- package/src/generated/native-disabled.ts +1 -0
- package/src/generated/text-input-dom-props.ts +128 -0
- package/src/generated/text-input.native.ts +1 -4
- package/src/generated/text.ts +5 -0
- package/src/generated/view-dom-props.ts +267 -0
- package/src/inherited-leaves.native.tsx +83 -0
- package/src/inherited-text-scope.tsx +27 -0
- package/src/link.native.tsx +17 -13
- package/src/link.ts +12 -0
- package/src/native-disabled.ts +23 -0
- package/src/presence.native.tsx +1 -1
- package/src/pressable.native.tsx +90 -42
- package/src/pressable.ts +8 -1
- package/src/text-color-transition.native.ts +96 -0
- package/src/text-input-props.native.ts +26 -0
- package/src/text-input.native.tsx +57 -0
- package/dist/generated/animated.d.ts +0 -2
- package/dist/generated/animated.d.ts.map +0 -1
- package/dist/generated/animated.js +0 -3
- package/dist/generated/animated.js.map +0 -1
- package/dist/presence-context.d.ts +0 -15
- package/dist/presence-context.d.ts.map +0 -1
- package/dist/presence-context.js +0 -11
- package/dist/presence-context.js.map +0 -1
- package/dist/runtime-transition.native.d.ts +0 -30
- package/dist/runtime-transition.native.d.ts.map +0 -1
- package/dist/runtime-transition.native.js +0 -183
- package/dist/runtime-transition.native.js.map +0 -1
- package/src/generated/animated.ts +0 -6
- package/src/presence-context.ts +0 -27
- package/src/runtime-transition.native.tsx +0 -244
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hozo/primitives",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Canonical universal UI primitives for Hozo applications.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
@@ -32,14 +32,26 @@
|
|
|
32
32
|
"types": "./dist/index.d.ts",
|
|
33
33
|
"default": "./dist/index.js"
|
|
34
34
|
},
|
|
35
|
-
"./
|
|
36
|
-
"types": "./dist/
|
|
37
|
-
"default": "./dist/
|
|
35
|
+
"./windowing": {
|
|
36
|
+
"types": "./dist/windowing.d.ts",
|
|
37
|
+
"default": "./dist/windowing.js"
|
|
38
38
|
},
|
|
39
39
|
"./generated/backdrop-filter": {
|
|
40
40
|
"types": "./dist/generated/backdrop-filter.d.ts",
|
|
41
41
|
"default": "./dist/generated/backdrop-filter.js"
|
|
42
42
|
},
|
|
43
|
+
"./generated/button-dom-props": {
|
|
44
|
+
"types": "./dist/generated/button-dom-props.d.ts",
|
|
45
|
+
"default": "./dist/generated/button-dom-props.js"
|
|
46
|
+
},
|
|
47
|
+
"./generated/button-props": {
|
|
48
|
+
"react-native": {
|
|
49
|
+
"types": "./dist/generated/button-props.native.d.ts",
|
|
50
|
+
"default": "./dist/generated/button-props.native.js"
|
|
51
|
+
},
|
|
52
|
+
"types": "./dist/generated/button-props.d.ts",
|
|
53
|
+
"default": "./dist/generated/button-props.js"
|
|
54
|
+
},
|
|
43
55
|
"./generated/container": {
|
|
44
56
|
"types": "./dist/generated/container.d.ts",
|
|
45
57
|
"default": "./dist/generated/container.js"
|
|
@@ -56,6 +68,10 @@
|
|
|
56
68
|
"types": "./dist/generated/grid.d.ts",
|
|
57
69
|
"default": "./dist/generated/grid.js"
|
|
58
70
|
},
|
|
71
|
+
"./generated/inherited-leaves": {
|
|
72
|
+
"types": "./dist/generated/inherited-leaves.d.ts",
|
|
73
|
+
"default": "./dist/generated/inherited-leaves.js"
|
|
74
|
+
},
|
|
59
75
|
"./generated/link": {
|
|
60
76
|
"react-native": {
|
|
61
77
|
"types": "./dist/generated/link.native.d.ts",
|
|
@@ -64,6 +80,10 @@
|
|
|
64
80
|
"types": "./dist/generated/link.d.ts",
|
|
65
81
|
"default": "./dist/generated/link.js"
|
|
66
82
|
},
|
|
83
|
+
"./generated/native-disabled": {
|
|
84
|
+
"types": "./dist/generated/native-disabled.d.ts",
|
|
85
|
+
"default": "./dist/generated/native-disabled.js"
|
|
86
|
+
},
|
|
67
87
|
"./generated/pressable": {
|
|
68
88
|
"react-native": {
|
|
69
89
|
"types": "./dist/generated/pressable.native.d.ts",
|
|
@@ -104,6 +124,10 @@
|
|
|
104
124
|
"types": "./dist/generated/text-input.d.ts",
|
|
105
125
|
"default": "./dist/generated/text-input.js"
|
|
106
126
|
},
|
|
127
|
+
"./generated/text-input-dom-props": {
|
|
128
|
+
"types": "./dist/generated/text-input-dom-props.d.ts",
|
|
129
|
+
"default": "./dist/generated/text-input-dom-props.js"
|
|
130
|
+
},
|
|
107
131
|
"./generated/text-size": {
|
|
108
132
|
"types": "./dist/generated/text-size.d.ts",
|
|
109
133
|
"default": "./dist/generated/text-size.js"
|
|
@@ -116,6 +140,10 @@
|
|
|
116
140
|
"types": "./dist/generated/view.d.ts",
|
|
117
141
|
"default": "./dist/generated/view.js"
|
|
118
142
|
},
|
|
143
|
+
"./generated/view-dom-props": {
|
|
144
|
+
"types": "./dist/generated/view-dom-props.d.ts",
|
|
145
|
+
"default": "./dist/generated/view-dom-props.js"
|
|
146
|
+
},
|
|
119
147
|
"./package.json": "./package.json"
|
|
120
148
|
},
|
|
121
149
|
"files": [
|
|
@@ -131,12 +159,12 @@
|
|
|
131
159
|
"provenance": true
|
|
132
160
|
},
|
|
133
161
|
"dependencies": {
|
|
134
|
-
"@hozo/behaviors": "^0.
|
|
135
|
-
"@hozo/engine": "^0.
|
|
162
|
+
"@hozo/behaviors": "^0.5.0",
|
|
163
|
+
"@hozo/engine": "^0.5.0"
|
|
136
164
|
},
|
|
137
165
|
"peerDependencies": {
|
|
138
166
|
"react": "^19.0.0",
|
|
139
|
-
"react-native": ">=0.
|
|
167
|
+
"react-native": ">=0.87"
|
|
140
168
|
},
|
|
141
169
|
"peerDependenciesMeta": {
|
|
142
170
|
"react-native": {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/** The documented DOM metadata channel; never forward arbitrary leftover props. */
|
|
2
|
+
export interface ButtonDataProps {
|
|
3
|
+
[name: `data-${string}`]: string | number | boolean | undefined
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export function buttonDataProps(props: ButtonDataProps): ButtonDataProps {
|
|
7
|
+
const data: ButtonDataProps = {}
|
|
8
|
+
for (const name in props) {
|
|
9
|
+
if (Object.hasOwn(props, name) && name.startsWith('data-')) {
|
|
10
|
+
data[name as `data-${string}`] = props[name as `data-${string}`]
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return data
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* What a wrapper hands a Button to make it a trigger, by platform.
|
|
18
|
+
*
|
|
19
|
+
* `Tooltip` clones its child with a ref to position against, the handlers
|
|
20
|
+
* that open it, and -- on the Web -- `aria-describedby` naming the bubble.
|
|
21
|
+
* A Button that dropped them was a trigger nothing could hear (#1137).
|
|
22
|
+
* `Toolbar` hands its items a roving `tabIndex` on the Web, and a Button
|
|
23
|
+
* that dropped it left every item a tab stop of its own.
|
|
24
|
+
* Still a list rather than "every leftover prop": the rule above stands,
|
|
25
|
+
* and these are the ones a known wrapper writes.
|
|
26
|
+
*/
|
|
27
|
+
export const BUTTON_TRIGGER_PROPS_WEB = [
|
|
28
|
+
'ref',
|
|
29
|
+
'onFocus',
|
|
30
|
+
'onBlur',
|
|
31
|
+
'onKeyDown',
|
|
32
|
+
'onPointerEnter',
|
|
33
|
+
'onPointerLeave',
|
|
34
|
+
'aria-describedby',
|
|
35
|
+
'tabIndex',
|
|
36
|
+
] as const
|
|
37
|
+
|
|
38
|
+
export const BUTTON_TRIGGER_PROPS_NATIVE = [
|
|
39
|
+
'ref',
|
|
40
|
+
'onFocus',
|
|
41
|
+
'onBlur',
|
|
42
|
+
'onHoverIn',
|
|
43
|
+
'onHoverOut',
|
|
44
|
+
'onLongPress',
|
|
45
|
+
] as const
|
|
46
|
+
|
|
47
|
+
export function buttonTriggerProps(
|
|
48
|
+
props: Record<string, unknown>,
|
|
49
|
+
names: readonly string[],
|
|
50
|
+
): Record<string, unknown> {
|
|
51
|
+
const out: Record<string, unknown> = {}
|
|
52
|
+
for (const name of names) {
|
|
53
|
+
if (Object.hasOwn(props, name)) out[name] = props[name]
|
|
54
|
+
}
|
|
55
|
+
return out
|
|
56
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
let warned = false
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Preserve evaluation/identity of authored props, but name the platform
|
|
5
|
+
* boundary: RN has no DOM dataset. Metadata is not an accessibility label
|
|
6
|
+
* or nativeID. Do not fabricate either from an application's data channel.
|
|
7
|
+
* The compiler uses this for opaque spreads; the fallback uses it too.
|
|
8
|
+
*/
|
|
9
|
+
export function hozoButtonProps<T>(props: T): T {
|
|
10
|
+
if (!warned && props !== null && typeof props === 'object') {
|
|
11
|
+
for (const name in props) {
|
|
12
|
+
if (Object.hasOwn(props, name) && name.startsWith('data-')) {
|
|
13
|
+
warned = true
|
|
14
|
+
console.warn(
|
|
15
|
+
'[hozo] Button data-* metadata requires a Web DOM dataset; React Native does not consume it. nativeID remains available on both platforms. No data values are mapped to accessibility props.',
|
|
16
|
+
)
|
|
17
|
+
break
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
return props
|
|
22
|
+
}
|
|
@@ -1,19 +1,29 @@
|
|
|
1
1
|
import { hozoTextChildren } from '@hozo/behaviors'
|
|
2
2
|
import { HozoTextSizeContext } from '@hozo/engine'
|
|
3
|
-
import React, { type ComponentType, type ReactNode, type Ref } from 'react'
|
|
3
|
+
import React, { type ComponentRef, type ComponentType, type ReactNode, type Ref } from 'react'
|
|
4
4
|
import {
|
|
5
5
|
type AccessibilityRole,
|
|
6
|
-
type
|
|
6
|
+
type AccessibilityState,
|
|
7
7
|
Pressable as RNPressable,
|
|
8
8
|
type PressableProps as RNPressableProps,
|
|
9
9
|
Text as RNText,
|
|
10
|
+
TextInput as RNTextInput,
|
|
10
11
|
type TextProps as RNTextProps,
|
|
11
12
|
type StyleProp,
|
|
12
13
|
StyleSheet,
|
|
13
14
|
type TextStyle,
|
|
14
15
|
type ViewStyle,
|
|
15
16
|
} from 'react-native'
|
|
17
|
+
import {
|
|
18
|
+
BUTTON_TRIGGER_PROPS_NATIVE,
|
|
19
|
+
type ButtonDataProps,
|
|
20
|
+
buttonDataProps,
|
|
21
|
+
buttonTriggerProps,
|
|
22
|
+
} from './button-host-attributes.ts'
|
|
23
|
+
import { hozoButtonProps } from './button-host-props.native.ts'
|
|
16
24
|
import { HozoLink } from './link.native.tsx'
|
|
25
|
+
import { nativeDisabledProps } from './native-disabled.ts'
|
|
26
|
+
import { type NativeTextInputProps, nativeTextInputProps } from './text-input-props.native.ts'
|
|
17
27
|
|
|
18
28
|
export type {
|
|
19
29
|
HozoResponderEvent,
|
|
@@ -24,10 +34,15 @@ export type {
|
|
|
24
34
|
} from '@hozo/engine'
|
|
25
35
|
export type {
|
|
26
36
|
ImageProps,
|
|
27
|
-
TextInputProps,
|
|
28
37
|
ViewProps,
|
|
29
38
|
} from 'react-native'
|
|
30
|
-
export { Image,
|
|
39
|
+
export { Image, View } from 'react-native'
|
|
40
|
+
export type TextInputProps = NativeTextInputProps & { ref?: Ref<ComponentRef<typeof RNTextInput>> }
|
|
41
|
+
|
|
42
|
+
/** The canonical disabled contract also applies outside compiler-owned JSX. */
|
|
43
|
+
export function TextInput({ ref, ...props }: TextInputProps) {
|
|
44
|
+
return <RNTextInput {...nativeTextInputProps(props)} ref={ref} />
|
|
45
|
+
}
|
|
31
46
|
export type {
|
|
32
47
|
HozoImageSource,
|
|
33
48
|
HozoImageSourceObject,
|
|
@@ -60,7 +75,11 @@ export interface PressableProps extends RNPressableProps {
|
|
|
60
75
|
* A caller needs it to hand the control to something else: `Dialog`'s
|
|
61
76
|
* `restoreFocusTo` is where this came up (#462).
|
|
62
77
|
*/
|
|
63
|
-
|
|
78
|
+
// Derived from the installed peer's Pressable rather than spelled out:
|
|
79
|
+
// its ref type has changed between minors (0.86 a View instance, later a
|
|
80
|
+
// HostInstance), and this stays exactly what that Pressable accepts (and
|
|
81
|
+
// Dialog can restore).
|
|
82
|
+
ref?: Ref<ComponentRef<typeof RNPressable>>
|
|
64
83
|
href?: string
|
|
65
84
|
external?: boolean
|
|
66
85
|
replace?: boolean
|
|
@@ -80,6 +99,7 @@ export function Pressable({
|
|
|
80
99
|
download: _download,
|
|
81
100
|
...props
|
|
82
101
|
}: PressableProps) {
|
|
102
|
+
props = nativeDisabledProps(props)
|
|
83
103
|
if (href === undefined) return <RNPressable {...props} />
|
|
84
104
|
|
|
85
105
|
const Link = HozoLink as unknown as ComponentType<
|
|
@@ -99,6 +119,7 @@ export interface LinkProps {
|
|
|
99
119
|
rel?: string
|
|
100
120
|
download?: boolean | string
|
|
101
121
|
onPress?: (event: { defaultPrevented?: boolean }) => void
|
|
122
|
+
disabled?: boolean
|
|
102
123
|
style?: StyleProp<TextStyle>
|
|
103
124
|
testID?: string
|
|
104
125
|
nativeID?: string
|
|
@@ -128,7 +149,7 @@ export function Link({
|
|
|
128
149
|
)
|
|
129
150
|
}
|
|
130
151
|
|
|
131
|
-
export interface ButtonProps {
|
|
152
|
+
export interface ButtonProps extends ButtonDataProps {
|
|
132
153
|
className?: string
|
|
133
154
|
children?: ReactNode
|
|
134
155
|
onPress?: RNPressableProps['onPress']
|
|
@@ -144,6 +165,25 @@ export interface ButtonProps {
|
|
|
144
165
|
download?: boolean | string
|
|
145
166
|
style?: StyleProp<ViewStyle>
|
|
146
167
|
testID?: string
|
|
168
|
+
nativeID?: string
|
|
169
|
+
/**
|
|
170
|
+
* What a wrapper writes to make this a trigger -- `Tooltip` measures the
|
|
171
|
+
* ref and opens on hover or a long press (#1137). Forwarded to the
|
|
172
|
+
* Pressable as given.
|
|
173
|
+
*/
|
|
174
|
+
ref?: Ref<ComponentRef<typeof RNPressable>>
|
|
175
|
+
onFocus?: RNPressableProps['onFocus']
|
|
176
|
+
onBlur?: RNPressableProps['onBlur']
|
|
177
|
+
onHoverIn?: RNPressableProps['onHoverIn']
|
|
178
|
+
onHoverOut?: RNPressableProps['onHoverOut']
|
|
179
|
+
onLongPress?: RNPressableProps['onLongPress']
|
|
180
|
+
/** As the Web half: `expanded` and the rest, `disabled` merged with the prop. */
|
|
181
|
+
accessibilityState?: AccessibilityState
|
|
182
|
+
/**
|
|
183
|
+
* Accepted so one source type-checks on both platforms, and dropped: React
|
|
184
|
+
* Native has no relationship between views to carry it (#1704).
|
|
185
|
+
*/
|
|
186
|
+
'aria-controls'?: string
|
|
147
187
|
}
|
|
148
188
|
|
|
149
189
|
export type ButtonNativeProps = ButtonProps
|
|
@@ -160,14 +200,23 @@ export function Button({
|
|
|
160
200
|
prefetch,
|
|
161
201
|
style,
|
|
162
202
|
testID,
|
|
203
|
+
nativeID,
|
|
204
|
+
accessibilityState: state,
|
|
205
|
+
'aria-controls': _controls,
|
|
206
|
+
...metadata
|
|
163
207
|
}: ButtonProps) {
|
|
208
|
+
const off = state?.disabled === true ? true : disabled
|
|
164
209
|
const shared = {
|
|
165
|
-
|
|
210
|
+
...hozoButtonProps(buttonDataProps(metadata)),
|
|
211
|
+
...buttonTriggerProps(metadata, BUTTON_TRIGGER_PROPS_NATIVE),
|
|
212
|
+
disabled: off,
|
|
166
213
|
accessibilityLabel,
|
|
167
214
|
accessibilityHint,
|
|
168
|
-
accessibilityState:
|
|
215
|
+
accessibilityState:
|
|
216
|
+
state === undefined && off === undefined ? undefined : { ...state, disabled: off },
|
|
169
217
|
style,
|
|
170
218
|
testID,
|
|
219
|
+
nativeID,
|
|
171
220
|
}
|
|
172
221
|
if (href !== undefined) {
|
|
173
222
|
const NativeLink = HozoLink as unknown as ComponentType<
|
|
@@ -192,3 +241,5 @@ export function Button({
|
|
|
192
241
|
</RNPressable>
|
|
193
242
|
)
|
|
194
243
|
}
|
|
244
|
+
// A label a pressable can hand its text styles to (#876); see `hozoTextStyle`.
|
|
245
|
+
;(Text as { hozoLabelText?: boolean }).hozoLabelText = true
|
package/src/foundation.tsx
CHANGED
|
@@ -14,7 +14,10 @@ import {
|
|
|
14
14
|
import {
|
|
15
15
|
type AriaRole,
|
|
16
16
|
type CSSProperties,
|
|
17
|
+
type FocusEventHandler,
|
|
18
|
+
type KeyboardEventHandler,
|
|
17
19
|
type MouseEventHandler,
|
|
20
|
+
type PointerEventHandler,
|
|
18
21
|
type ReactNode,
|
|
19
22
|
type Ref,
|
|
20
23
|
useCallback,
|
|
@@ -22,6 +25,12 @@ import {
|
|
|
22
25
|
useRef,
|
|
23
26
|
useState,
|
|
24
27
|
} from 'react'
|
|
28
|
+
import {
|
|
29
|
+
BUTTON_TRIGGER_PROPS_WEB,
|
|
30
|
+
type ButtonDataProps,
|
|
31
|
+
buttonDataProps,
|
|
32
|
+
buttonTriggerProps,
|
|
33
|
+
} from './button-host-attributes.ts'
|
|
25
34
|
import { HozoLink } from './link.ts'
|
|
26
35
|
import { HozoPressable, type HozoPressableProps } from './pressable.ts'
|
|
27
36
|
import { HozoTextInput, type HozoTextInputProps } from './text-input.ts'
|
|
@@ -193,6 +202,16 @@ export interface ImageProps extends UniversalProps {
|
|
|
193
202
|
defaultSource?: HozoImageSource
|
|
194
203
|
alt?: string
|
|
195
204
|
accessibilityLabel?: string
|
|
205
|
+
/**
|
|
206
|
+
* The image's intrinsic size, so the browser reserves its box before the
|
|
207
|
+
* file arrives (#1674). React Native's `Image` takes the same two props.
|
|
208
|
+
*/
|
|
209
|
+
width?: number
|
|
210
|
+
height?: number
|
|
211
|
+
/** Web only; React Native ignores them. */
|
|
212
|
+
loading?: 'eager' | 'lazy'
|
|
213
|
+
decoding?: 'async' | 'auto' | 'sync'
|
|
214
|
+
fetchPriority?: 'auto' | 'high' | 'low'
|
|
196
215
|
onLoad?: (event: unknown) => void
|
|
197
216
|
onError?: (event: unknown) => void
|
|
198
217
|
ref?: Ref<HTMLImageElement>
|
|
@@ -233,6 +252,11 @@ export function Image({
|
|
|
233
252
|
defaultSource,
|
|
234
253
|
alt,
|
|
235
254
|
accessibilityLabel,
|
|
255
|
+
width,
|
|
256
|
+
height,
|
|
257
|
+
loading,
|
|
258
|
+
decoding,
|
|
259
|
+
fetchPriority,
|
|
236
260
|
onLoad,
|
|
237
261
|
onError,
|
|
238
262
|
onLayout,
|
|
@@ -241,14 +265,54 @@ export function Image({
|
|
|
241
265
|
}: ImageProps) {
|
|
242
266
|
const { setRef } = useLayoutRef<HTMLImageElement>(onLayout, ref)
|
|
243
267
|
const [failedSource, setFailedSource] = useState<HozoImageSource>()
|
|
244
|
-
const
|
|
245
|
-
|
|
268
|
+
const primary = webImageSource(src)
|
|
269
|
+
const fallback = webImageSource(defaultSource)
|
|
270
|
+
const webSrc = (failedSource === src ? undefined : primary) ?? fallback
|
|
271
|
+
// A server-rendered `<img>` starts loading before React hydrates, so its
|
|
272
|
+
// `error` event may already have fired when `onError` is attached (#1156).
|
|
273
|
+
// `complete && naturalWidth === 0` spots that, and `decode()` separates a
|
|
274
|
+
// broken load from a widthless SVG that some browsers report as 0px wide.
|
|
275
|
+
// The caller's `onError` is not synthesized here because the native error
|
|
276
|
+
// event has already come and gone before hydration.
|
|
277
|
+
const stateRef = useRef({ src, primary, fallback, failedSource })
|
|
278
|
+
stateRef.current = { src, primary, fallback, failedSource }
|
|
279
|
+
const imageRef = useCallback(
|
|
280
|
+
(node: HTMLImageElement | null) => {
|
|
281
|
+
setRef(node)
|
|
282
|
+
const current = stateRef.current
|
|
283
|
+
if (
|
|
284
|
+
node &&
|
|
285
|
+
current.primary &&
|
|
286
|
+
current.fallback &&
|
|
287
|
+
current.failedSource !== current.src &&
|
|
288
|
+
node.complete &&
|
|
289
|
+
node.naturalWidth === 0
|
|
290
|
+
) {
|
|
291
|
+
const failed = current.src
|
|
292
|
+
if (typeof node.decode === 'function') {
|
|
293
|
+
node.decode().then(undefined, () => {
|
|
294
|
+
if (stateRef.current.src === failed) setFailedSource(failed)
|
|
295
|
+
})
|
|
296
|
+
} else {
|
|
297
|
+
setFailedSource(failed)
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
},
|
|
301
|
+
[setRef],
|
|
302
|
+
)
|
|
246
303
|
return (
|
|
247
304
|
<img
|
|
248
|
-
ref={
|
|
305
|
+
ref={imageRef}
|
|
249
306
|
className={className}
|
|
250
307
|
src={webSrc}
|
|
251
308
|
alt={alt ?? accessibilityLabel ?? ''}
|
|
309
|
+
// Forwarded as the compiled `<img>` forwards them, so a page renders
|
|
310
|
+
// the same with or without the compiler (#1674).
|
|
311
|
+
width={width}
|
|
312
|
+
height={height}
|
|
313
|
+
loading={loading}
|
|
314
|
+
decoding={decoding}
|
|
315
|
+
fetchPriority={fetchPriority}
|
|
252
316
|
onLoad={onLoad}
|
|
253
317
|
onError={(event) => {
|
|
254
318
|
setFailedSource(src)
|
|
@@ -283,13 +347,14 @@ export interface LinkProps {
|
|
|
283
347
|
replace?: boolean
|
|
284
348
|
prefetch?: boolean
|
|
285
349
|
onPress?: MouseEventHandler<HTMLAnchorElement>
|
|
350
|
+
disabled?: boolean
|
|
286
351
|
}
|
|
287
352
|
|
|
288
353
|
export function Link({ children, ...props }: LinkProps) {
|
|
289
354
|
return <HozoLink {...props}>{children}</HozoLink>
|
|
290
355
|
}
|
|
291
356
|
|
|
292
|
-
export interface ButtonProps {
|
|
357
|
+
export interface ButtonProps extends ButtonDataProps {
|
|
293
358
|
className?: string
|
|
294
359
|
children?: ReactNode
|
|
295
360
|
onPress?: MouseEventHandler<HTMLElement>
|
|
@@ -304,13 +369,41 @@ export interface ButtonProps {
|
|
|
304
369
|
rel?: string
|
|
305
370
|
download?: boolean | string
|
|
306
371
|
testID?: string
|
|
372
|
+
/** Stable host ID: DOM id on Web, nativeID on React Native. */
|
|
373
|
+
nativeID?: string
|
|
374
|
+
/**
|
|
375
|
+
* What a wrapper writes to make this a trigger -- `Tooltip` positions
|
|
376
|
+
* against the ref, opens on these handlers, and names its bubble with
|
|
377
|
+
* `aria-describedby` (#1137). Forwarded to the element as given.
|
|
378
|
+
*/
|
|
379
|
+
ref?: Ref<HTMLElement>
|
|
380
|
+
onFocus?: FocusEventHandler<HTMLElement>
|
|
381
|
+
onBlur?: FocusEventHandler<HTMLElement>
|
|
382
|
+
onKeyDown?: KeyboardEventHandler<HTMLElement>
|
|
383
|
+
onPointerEnter?: PointerEventHandler<HTMLElement>
|
|
384
|
+
onPointerLeave?: PointerEventHandler<HTMLElement>
|
|
385
|
+
'aria-describedby'?: string
|
|
386
|
+
/** A roving tab stop, as `Toolbar` hands its items. */
|
|
387
|
+
tabIndex?: number
|
|
388
|
+
/**
|
|
389
|
+
* The same state `View` and `Pressable` take: a menu or disclosure trigger
|
|
390
|
+
* says whether what it opens is open with `expanded` (#1704). Becomes
|
|
391
|
+
* `aria-*` on the Web and `accessibilityState` on React Native.
|
|
392
|
+
* `disabled` here disables the button as the `disabled` prop does.
|
|
393
|
+
*/
|
|
394
|
+
accessibilityState?: UniversalProps['accessibilityState']
|
|
395
|
+
/**
|
|
396
|
+
* The id of what this button opens or changes, beside `expanded`. Web
|
|
397
|
+
* only: React Native has no relationship between views to put it in, and
|
|
398
|
+
* dropping it changes nothing that can be seen or pressed there.
|
|
399
|
+
*/
|
|
400
|
+
'aria-controls'?: string
|
|
307
401
|
}
|
|
308
402
|
|
|
309
403
|
export function Button({
|
|
310
404
|
className,
|
|
311
405
|
children,
|
|
312
406
|
onPress,
|
|
313
|
-
disabled,
|
|
314
407
|
accessibilityLabel,
|
|
315
408
|
accessibilityHint,
|
|
316
409
|
href,
|
|
@@ -321,10 +414,27 @@ export function Button({
|
|
|
321
414
|
rel,
|
|
322
415
|
download,
|
|
323
416
|
testID,
|
|
417
|
+
nativeID,
|
|
418
|
+
accessibilityState: state,
|
|
419
|
+
'aria-controls': controls,
|
|
420
|
+
disabled: disabledProp,
|
|
421
|
+
...metadata
|
|
324
422
|
}: ButtonProps) {
|
|
423
|
+
// Either spelling disables it, as the compiled element does.
|
|
424
|
+
const disabled = state?.disabled === true ? true : disabledProp
|
|
425
|
+
const data = {
|
|
426
|
+
...buttonDataProps(metadata),
|
|
427
|
+
...buttonTriggerProps(metadata, BUTTON_TRIGGER_PROPS_WEB),
|
|
428
|
+
'aria-selected': state?.selected,
|
|
429
|
+
'aria-checked': state?.checked,
|
|
430
|
+
'aria-busy': state?.busy,
|
|
431
|
+
'aria-expanded': state?.expanded,
|
|
432
|
+
'aria-controls': controls,
|
|
433
|
+
}
|
|
325
434
|
if (href != null) {
|
|
326
435
|
return (
|
|
327
436
|
<HozoLink
|
|
437
|
+
{...data}
|
|
328
438
|
href={href}
|
|
329
439
|
external={external}
|
|
330
440
|
replace={replace}
|
|
@@ -337,6 +447,7 @@ export function Button({
|
|
|
337
447
|
accessibilityHint={accessibilityHint}
|
|
338
448
|
disabled={disabled}
|
|
339
449
|
testID={testID}
|
|
450
|
+
nativeID={nativeID}
|
|
340
451
|
onPress={onPress as MouseEventHandler<HTMLAnchorElement>}
|
|
341
452
|
>
|
|
342
453
|
{children}
|
|
@@ -347,14 +458,17 @@ export function Button({
|
|
|
347
458
|
<>
|
|
348
459
|
{hozoViewBase()}
|
|
349
460
|
<button
|
|
461
|
+
{...data}
|
|
350
462
|
type="button"
|
|
351
463
|
className={className}
|
|
352
464
|
disabled={disabled}
|
|
353
465
|
data-hozo-disabled={disabled ? '' : undefined}
|
|
466
|
+
aria-disabled={disabled}
|
|
354
467
|
data-hozo-pressable={onPress && !disabled ? '' : undefined}
|
|
355
468
|
aria-label={accessibilityLabel}
|
|
356
469
|
aria-description={accessibilityHint}
|
|
357
470
|
data-testid={testID}
|
|
471
|
+
id={nativeID}
|
|
358
472
|
onClick={onPress as MouseEventHandler<HTMLButtonElement>}
|
|
359
473
|
>
|
|
360
474
|
{children}
|