@hozo/primitives 0.2.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.
package/src/pressable.ts CHANGED
@@ -2,11 +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,
11
+ Fragment,
10
12
  type HTMLAttributes,
11
13
  type KeyboardEvent,
12
14
  type MouseEvent,
@@ -236,6 +238,7 @@ export function HozoPressable({
236
238
  : {
237
239
  'aria-disabled': unavailable || undefined,
238
240
  'data-hozo-disabled': unavailable ? '' : undefined,
241
+ 'data-hozo-pressable': undefined,
239
242
  tabIndex: undefined,
240
243
  onClick: undefined,
241
244
  onKeyDown: undefined,
@@ -340,22 +343,29 @@ export function HozoPressable({
340
343
  resolvedChildren,
341
344
  )
342
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.
343
348
  return createElement(
344
- 'div',
345
- {
346
- ...common,
347
- ...interaction,
348
- onKeyDown: (event: KeyboardEvent<HTMLElement>) => {
349
- if (event.key === 'Enter' || event.key === ' ') pressIn(event)
350
- interaction.onKeyDown?.(event)
351
- onKeyDown?.(event as never)
352
- },
353
- onKeyUp: (event: KeyboardEvent<HTMLElement>) => {
354
- if (event.key === 'Enter' || event.key === ' ') pressOut(event)
355
- interaction.onKeyUp?.(event)
356
- onKeyUp?.(event as never)
357
- },
358
- } as unknown as HTMLAttributes<HTMLDivElement>,
359
- 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
+ ),
360
370
  )
361
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
 
package/src/view.ts CHANGED
@@ -1,11 +1,14 @@
1
1
  import {
2
2
  type HozoDomStyle,
3
3
  hozoDomStyle,
4
+ hozoViewBase,
5
+ hozoViewClassName,
4
6
  type ResponderProps,
5
7
  useResponderDomProps,
6
8
  } from '@hozo/engine'
7
9
  import {
8
10
  createElement,
11
+ Fragment,
9
12
  type HTMLAttributes,
10
13
  type ReactNode,
11
14
  type Ref,
@@ -142,30 +145,36 @@ export function HozoView({
142
145
  const state = accessibilityState
143
146
  const value = accessibilityValue
144
147
  return createElement(
145
- 'div',
146
- {
147
- ...props,
148
- ...responder,
149
- ref: setRef,
150
- role: accessibilityRole ?? role,
151
- style: hozoDomStyle(style),
152
- 'data-testid': testID,
153
- id: nativeID,
154
- 'data-hozo-pointer-events': pointerEvents,
155
- 'data-hozo-disabled': state?.disabled ? '' : dataHozoDisabled,
156
- 'aria-disabled': state?.disabled ? true : ariaDisabled,
157
- 'aria-selected': state?.selected,
158
- 'aria-checked': state?.checked,
159
- 'aria-busy': state?.busy,
160
- 'aria-expanded': state?.expanded,
161
- 'aria-valuemin': value?.min,
162
- 'aria-valuemax': value?.max,
163
- 'aria-valuenow': value?.now,
164
- 'aria-valuetext': value?.text,
165
- 'aria-live': accessibilityLiveRegion === 'none' ? undefined : accessibilityLiveRegion,
166
- 'aria-label': accessibilityLabel,
167
- 'aria-description': accessibilityHint,
168
- },
169
- children,
148
+ Fragment,
149
+ null,
150
+ hozoViewBase(),
151
+ createElement(
152
+ 'div',
153
+ {
154
+ ...props,
155
+ className: hozoViewClassName(props.className),
156
+ ...responder,
157
+ ref: setRef,
158
+ role: accessibilityRole ?? role,
159
+ style: hozoDomStyle(style),
160
+ 'data-testid': testID,
161
+ id: nativeID,
162
+ 'data-hozo-pointer-events': pointerEvents,
163
+ 'data-hozo-disabled': state?.disabled ? '' : dataHozoDisabled,
164
+ 'aria-disabled': state?.disabled ? true : ariaDisabled,
165
+ 'aria-selected': state?.selected,
166
+ 'aria-checked': state?.checked,
167
+ 'aria-busy': state?.busy,
168
+ 'aria-expanded': state?.expanded,
169
+ 'aria-valuemin': value?.min,
170
+ 'aria-valuemax': value?.max,
171
+ 'aria-valuenow': value?.now,
172
+ 'aria-valuetext': value?.text,
173
+ 'aria-live': accessibilityLiveRegion === 'none' ? undefined : accessibilityLiveRegion,
174
+ 'aria-label': accessibilityLabel,
175
+ 'aria-description': accessibilityHint,
176
+ },
177
+ children,
178
+ ),
170
179
  )
171
180
  }