@cdx-ui/primitives 0.0.1-beta.1 → 0.0.1-beta.11

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 (149) hide show
  1. package/README.md +21 -21
  2. package/lib/commonjs/index.js +24 -0
  3. package/lib/commonjs/index.js.map +1 -1
  4. package/lib/commonjs/list-item/context.js +11 -0
  5. package/lib/commonjs/list-item/context.js.map +1 -0
  6. package/lib/commonjs/list-item/createListItemContent.js +30 -0
  7. package/lib/commonjs/list-item/createListItemContent.js.map +1 -0
  8. package/lib/commonjs/list-item/createListItemDescription.js +25 -0
  9. package/lib/commonjs/list-item/createListItemDescription.js.map +1 -0
  10. package/lib/commonjs/list-item/createListItemLeadingSlot.js +34 -0
  11. package/lib/commonjs/list-item/createListItemLeadingSlot.js.map +1 -0
  12. package/lib/commonjs/list-item/createListItemMeta.js +25 -0
  13. package/lib/commonjs/list-item/createListItemMeta.js.map +1 -0
  14. package/lib/commonjs/list-item/createListItemRoot.js +142 -0
  15. package/lib/commonjs/list-item/createListItemRoot.js.map +1 -0
  16. package/lib/commonjs/list-item/createListItemSectionHeader.js +54 -0
  17. package/lib/commonjs/list-item/createListItemSectionHeader.js.map +1 -0
  18. package/lib/commonjs/list-item/createListItemTitle.js +25 -0
  19. package/lib/commonjs/list-item/createListItemTitle.js.map +1 -0
  20. package/lib/commonjs/list-item/createListItemTrailingSlot.js +28 -0
  21. package/lib/commonjs/list-item/createListItemTrailingSlot.js.map +1 -0
  22. package/lib/commonjs/list-item/index.js +55 -0
  23. package/lib/commonjs/list-item/index.js.map +1 -0
  24. package/lib/commonjs/list-item/types.js +6 -0
  25. package/lib/commonjs/list-item/types.js.map +1 -0
  26. package/lib/commonjs/radio/context.js +14 -0
  27. package/lib/commonjs/radio/context.js.map +1 -0
  28. package/lib/commonjs/radio/createRadioGroup.js +66 -0
  29. package/lib/commonjs/radio/createRadioGroup.js.map +1 -0
  30. package/lib/commonjs/radio/createRadioIndicator.js +43 -0
  31. package/lib/commonjs/radio/createRadioIndicator.js.map +1 -0
  32. package/lib/commonjs/radio/createRadioLabel.js +38 -0
  33. package/lib/commonjs/radio/createRadioLabel.js.map +1 -0
  34. package/lib/commonjs/radio/createRadioRoot.js +95 -0
  35. package/lib/commonjs/radio/createRadioRoot.js.map +1 -0
  36. package/lib/commonjs/radio/createRadioRoot.web.js +87 -0
  37. package/lib/commonjs/radio/createRadioRoot.web.js.map +1 -0
  38. package/lib/commonjs/radio/index.js +26 -0
  39. package/lib/commonjs/radio/index.js.map +1 -0
  40. package/lib/commonjs/radio/types.js +6 -0
  41. package/lib/commonjs/radio/types.js.map +1 -0
  42. package/lib/commonjs/radio/useRadioRoot.js +64 -0
  43. package/lib/commonjs/radio/useRadioRoot.js.map +1 -0
  44. package/lib/module/index.js +2 -0
  45. package/lib/module/index.js.map +1 -1
  46. package/lib/module/list-item/context.js +5 -0
  47. package/lib/module/list-item/context.js.map +1 -0
  48. package/lib/module/list-item/createListItemContent.js +24 -0
  49. package/lib/module/list-item/createListItemContent.js.map +1 -0
  50. package/lib/module/list-item/createListItemDescription.js +19 -0
  51. package/lib/module/list-item/createListItemDescription.js.map +1 -0
  52. package/lib/module/list-item/createListItemLeadingSlot.js +28 -0
  53. package/lib/module/list-item/createListItemLeadingSlot.js.map +1 -0
  54. package/lib/module/list-item/createListItemMeta.js +19 -0
  55. package/lib/module/list-item/createListItemMeta.js.map +1 -0
  56. package/lib/module/list-item/createListItemRoot.js +136 -0
  57. package/lib/module/list-item/createListItemRoot.js.map +1 -0
  58. package/lib/module/list-item/createListItemSectionHeader.js +48 -0
  59. package/lib/module/list-item/createListItemSectionHeader.js.map +1 -0
  60. package/lib/module/list-item/createListItemTitle.js +19 -0
  61. package/lib/module/list-item/createListItemTitle.js.map +1 -0
  62. package/lib/module/list-item/createListItemTrailingSlot.js +22 -0
  63. package/lib/module/list-item/createListItemTrailingSlot.js.map +1 -0
  64. package/lib/module/list-item/index.js +39 -0
  65. package/lib/module/list-item/index.js.map +1 -0
  66. package/lib/module/list-item/types.js +4 -0
  67. package/lib/module/list-item/types.js.map +1 -0
  68. package/lib/module/radio/context.js +7 -0
  69. package/lib/module/radio/context.js.map +1 -0
  70. package/lib/module/radio/createRadioGroup.js +61 -0
  71. package/lib/module/radio/createRadioGroup.js.map +1 -0
  72. package/lib/module/radio/createRadioIndicator.js +38 -0
  73. package/lib/module/radio/createRadioIndicator.js.map +1 -0
  74. package/lib/module/radio/createRadioLabel.js +33 -0
  75. package/lib/module/radio/createRadioLabel.js.map +1 -0
  76. package/lib/module/radio/createRadioRoot.js +90 -0
  77. package/lib/module/radio/createRadioRoot.js.map +1 -0
  78. package/lib/module/radio/createRadioRoot.web.js +82 -0
  79. package/lib/module/radio/createRadioRoot.web.js.map +1 -0
  80. package/lib/module/radio/index.js +22 -0
  81. package/lib/module/radio/index.js.map +1 -0
  82. package/lib/module/radio/types.js +4 -0
  83. package/lib/module/radio/types.js.map +1 -0
  84. package/lib/module/radio/useRadioRoot.js +60 -0
  85. package/lib/module/radio/useRadioRoot.js.map +1 -0
  86. package/lib/typescript/index.d.ts +2 -0
  87. package/lib/typescript/index.d.ts.map +1 -1
  88. package/lib/typescript/list-item/context.d.ts +6 -0
  89. package/lib/typescript/list-item/context.d.ts.map +1 -0
  90. package/lib/typescript/list-item/createListItemContent.d.ts +3 -0
  91. package/lib/typescript/list-item/createListItemContent.d.ts.map +1 -0
  92. package/lib/typescript/list-item/createListItemDescription.d.ts +3 -0
  93. package/lib/typescript/list-item/createListItemDescription.d.ts.map +1 -0
  94. package/lib/typescript/list-item/createListItemLeadingSlot.d.ts +4 -0
  95. package/lib/typescript/list-item/createListItemLeadingSlot.d.ts.map +1 -0
  96. package/lib/typescript/list-item/createListItemMeta.d.ts +3 -0
  97. package/lib/typescript/list-item/createListItemMeta.d.ts.map +1 -0
  98. package/lib/typescript/list-item/createListItemRoot.d.ts +4 -0
  99. package/lib/typescript/list-item/createListItemRoot.d.ts.map +1 -0
  100. package/lib/typescript/list-item/createListItemSectionHeader.d.ts +4 -0
  101. package/lib/typescript/list-item/createListItemSectionHeader.d.ts.map +1 -0
  102. package/lib/typescript/list-item/createListItemTitle.d.ts +3 -0
  103. package/lib/typescript/list-item/createListItemTitle.d.ts.map +1 -0
  104. package/lib/typescript/list-item/createListItemTrailingSlot.d.ts +3 -0
  105. package/lib/typescript/list-item/createListItemTrailingSlot.d.ts.map +1 -0
  106. package/lib/typescript/list-item/index.d.ts +16 -0
  107. package/lib/typescript/list-item/index.d.ts.map +1 -0
  108. package/lib/typescript/list-item/types.d.ts +86 -0
  109. package/lib/typescript/list-item/types.d.ts.map +1 -0
  110. package/lib/typescript/radio/context.d.ts +21 -0
  111. package/lib/typescript/radio/context.d.ts.map +1 -0
  112. package/lib/typescript/radio/createRadioGroup.d.ts +3 -0
  113. package/lib/typescript/radio/createRadioGroup.d.ts.map +1 -0
  114. package/lib/typescript/radio/createRadioIndicator.d.ts +5 -0
  115. package/lib/typescript/radio/createRadioIndicator.d.ts.map +1 -0
  116. package/lib/typescript/radio/createRadioLabel.d.ts +5 -0
  117. package/lib/typescript/radio/createRadioLabel.d.ts.map +1 -0
  118. package/lib/typescript/radio/createRadioRoot.d.ts +3 -0
  119. package/lib/typescript/radio/createRadioRoot.d.ts.map +1 -0
  120. package/lib/typescript/radio/createRadioRoot.web.d.ts +3 -0
  121. package/lib/typescript/radio/createRadioRoot.web.d.ts.map +1 -0
  122. package/lib/typescript/radio/index.d.ts +10 -0
  123. package/lib/typescript/radio/index.d.ts.map +1 -0
  124. package/lib/typescript/radio/types.d.ts +54 -0
  125. package/lib/typescript/radio/types.d.ts.map +1 -0
  126. package/lib/typescript/radio/useRadioRoot.d.ts +149 -0
  127. package/lib/typescript/radio/useRadioRoot.d.ts.map +1 -0
  128. package/package.json +5 -2
  129. package/src/index.ts +2 -0
  130. package/src/list-item/context.tsx +5 -0
  131. package/src/list-item/createListItemContent.tsx +23 -0
  132. package/src/list-item/createListItemDescription.tsx +19 -0
  133. package/src/list-item/createListItemLeadingSlot.tsx +30 -0
  134. package/src/list-item/createListItemMeta.tsx +17 -0
  135. package/src/list-item/createListItemRoot.tsx +163 -0
  136. package/src/list-item/createListItemSectionHeader.tsx +53 -0
  137. package/src/list-item/createListItemTitle.tsx +17 -0
  138. package/src/list-item/createListItemTrailingSlot.tsx +21 -0
  139. package/src/list-item/index.ts +88 -0
  140. package/src/list-item/types.ts +122 -0
  141. package/src/radio/context.tsx +21 -0
  142. package/src/radio/createRadioGroup.tsx +67 -0
  143. package/src/radio/createRadioIndicator.tsx +32 -0
  144. package/src/radio/createRadioLabel.tsx +28 -0
  145. package/src/radio/createRadioRoot.tsx +100 -0
  146. package/src/radio/createRadioRoot.web.tsx +81 -0
  147. package/src/radio/index.ts +37 -0
  148. package/src/radio/types.ts +67 -0
  149. package/src/radio/useRadioRoot.ts +69 -0
@@ -0,0 +1,149 @@
1
+ import type { IRadioProps } from './types';
2
+ interface UseRadioRootOptions {
3
+ useInputRefForAria?: boolean;
4
+ }
5
+ export declare function useRadioRoot(props: IRadioProps, ref?: React.Ref<unknown>, { useInputRefForAria }?: UseRadioRootOptions): {
6
+ combinedProps: {
7
+ value: string;
8
+ isDisabled?: boolean | undefined;
9
+ isHovered?: boolean;
10
+ isFocused?: boolean;
11
+ isPressed?: boolean;
12
+ isFocusVisible?: boolean;
13
+ children?: React.ReactNode;
14
+ onHoverIn?: null | ((event: import("react-native").MouseEvent) => void) | undefined;
15
+ onHoverOut?: null | ((event: import("react-native").MouseEvent) => void) | undefined;
16
+ onPress?: null | ((event: import("react-native").GestureResponderEvent) => void) | undefined;
17
+ onPressIn?: null | ((event: import("react-native").GestureResponderEvent) => void) | undefined;
18
+ onPressOut?: null | ((event: import("react-native").GestureResponderEvent) => void) | undefined;
19
+ onLongPress?: null | ((event: import("react-native").GestureResponderEvent) => void) | undefined;
20
+ onBlur?: null | ((event: import("react-native").NativeSyntheticEvent<import("react-native").TargetedEvent>) => void) | undefined;
21
+ onFocus?: null | ((event: import("react-native").NativeSyntheticEvent<import("react-native").TargetedEvent>) => void) | undefined;
22
+ cancelable?: null | boolean | undefined;
23
+ delayHoverIn?: number | null | undefined;
24
+ delayHoverOut?: number | null | undefined;
25
+ delayLongPress?: null | number | undefined;
26
+ disabled?: null | boolean | undefined;
27
+ hitSlop?: null | import("react-native").Insets | number | undefined;
28
+ pressRetentionOffset?: null | import("react-native").Insets | number | undefined;
29
+ android_disableSound?: null | boolean | undefined;
30
+ android_ripple?: null | import("react-native").PressableAndroidRippleConfig | undefined;
31
+ testOnly_pressed?: null | boolean | undefined;
32
+ style?: import("react-native").StyleProp<import("react-native").ViewStyle> | ((state: import("react-native").PressableStateCallbackType) => import("react-native").StyleProp<import("react-native").ViewStyle>) | undefined;
33
+ unstable_pressDelay?: number | undefined;
34
+ accessible?: boolean | undefined;
35
+ accessibilityActions?: ReadonlyArray<import("react-native").AccessibilityActionInfo> | undefined;
36
+ accessibilityLabel?: string | undefined;
37
+ 'aria-label'?: string | undefined;
38
+ accessibilityRole?: import("react-native").AccessibilityRole | undefined;
39
+ accessibilityState?: import("react-native").AccessibilityState | undefined;
40
+ 'aria-busy'?: boolean | undefined;
41
+ 'aria-checked'?: boolean | "mixed" | undefined;
42
+ 'aria-disabled'?: boolean | undefined;
43
+ 'aria-expanded'?: boolean | undefined;
44
+ 'aria-selected'?: boolean | undefined;
45
+ accessibilityHint?: string | undefined;
46
+ accessibilityValue?: import("react-native").AccessibilityValue | undefined;
47
+ 'aria-valuemax'?: import("react-native").AccessibilityValue["max"] | undefined;
48
+ 'aria-valuemin'?: import("react-native").AccessibilityValue["min"] | undefined;
49
+ 'aria-valuenow'?: import("react-native").AccessibilityValue["now"] | undefined;
50
+ 'aria-valuetext'?: import("react-native").AccessibilityValue["text"] | undefined;
51
+ onAccessibilityAction?: ((event: import("react-native").AccessibilityActionEvent) => void) | undefined;
52
+ importantForAccessibility?: ("auto" | "yes" | "no" | "no-hide-descendants") | undefined;
53
+ 'aria-hidden'?: boolean | undefined;
54
+ 'aria-modal'?: boolean | undefined;
55
+ role?: import("react-native").Role | undefined;
56
+ accessibilityLabelledBy?: string | string[] | undefined;
57
+ 'aria-labelledby'?: string | undefined;
58
+ accessibilityLiveRegion?: "none" | "polite" | "assertive" | undefined;
59
+ 'aria-live'?: ("polite" | "assertive" | "off") | undefined;
60
+ screenReaderFocusable?: boolean | undefined;
61
+ accessibilityElementsHidden?: boolean | undefined;
62
+ accessibilityViewIsModal?: boolean | undefined;
63
+ onAccessibilityEscape?: (() => void) | undefined;
64
+ onAccessibilityTap?: (() => void) | undefined;
65
+ onMagicTap?: (() => void) | undefined;
66
+ accessibilityIgnoresInvertColors?: boolean | undefined;
67
+ accessibilityLanguage?: string | undefined;
68
+ accessibilityShowsLargeContentViewer?: boolean | undefined;
69
+ accessibilityLargeContentTitle?: string | undefined;
70
+ accessibilityRespondsToUserInteraction?: boolean | undefined;
71
+ id?: string | undefined;
72
+ onLayout?: ((event: import("react-native").LayoutChangeEvent) => void) | undefined | undefined;
73
+ testID?: string | undefined | undefined;
74
+ nativeID?: string | undefined | undefined;
75
+ needsOffscreenAlphaCompositing?: boolean | undefined | undefined;
76
+ pointerEvents?: "box-none" | "none" | "box-only" | "auto" | undefined | undefined;
77
+ removeClippedSubviews?: boolean | undefined | undefined;
78
+ collapsable?: boolean | undefined | undefined;
79
+ collapsableChildren?: boolean | undefined | undefined;
80
+ renderToHardwareTextureAndroid?: boolean | undefined | undefined;
81
+ focusable?: boolean | undefined | undefined;
82
+ tabIndex?: 0 | -1 | undefined | undefined;
83
+ shouldRasterizeIOS?: boolean | undefined | undefined;
84
+ isTVSelectable?: boolean | undefined | undefined;
85
+ hasTVPreferredFocus?: boolean | undefined | undefined;
86
+ tvParallaxShiftDistanceX?: number | undefined | undefined;
87
+ tvParallaxShiftDistanceY?: number | undefined | undefined;
88
+ tvParallaxTiltAngle?: number | undefined | undefined;
89
+ tvParallaxMagnification?: number | undefined | undefined;
90
+ onStartShouldSetResponder?: ((event: import("react-native").GestureResponderEvent) => boolean) | undefined | undefined;
91
+ onMoveShouldSetResponder?: ((event: import("react-native").GestureResponderEvent) => boolean) | undefined | undefined;
92
+ onResponderEnd?: ((event: import("react-native").GestureResponderEvent) => void) | undefined | undefined;
93
+ onResponderGrant?: ((event: import("react-native").GestureResponderEvent) => void) | undefined | undefined;
94
+ onResponderReject?: ((event: import("react-native").GestureResponderEvent) => void) | undefined | undefined;
95
+ onResponderMove?: ((event: import("react-native").GestureResponderEvent) => void) | undefined | undefined;
96
+ onResponderRelease?: ((event: import("react-native").GestureResponderEvent) => void) | undefined | undefined;
97
+ onResponderStart?: ((event: import("react-native").GestureResponderEvent) => void) | undefined | undefined;
98
+ onResponderTerminationRequest?: ((event: import("react-native").GestureResponderEvent) => boolean) | undefined | undefined;
99
+ onResponderTerminate?: ((event: import("react-native").GestureResponderEvent) => void) | undefined | undefined;
100
+ onStartShouldSetResponderCapture?: ((event: import("react-native").GestureResponderEvent) => boolean) | undefined | undefined;
101
+ onMoveShouldSetResponderCapture?: ((event: import("react-native").GestureResponderEvent) => boolean) | undefined | undefined;
102
+ onTouchStart?: ((event: import("react-native").GestureResponderEvent) => void) | undefined | undefined;
103
+ onTouchMove?: ((event: import("react-native").GestureResponderEvent) => void) | undefined | undefined;
104
+ onTouchEnd?: ((event: import("react-native").GestureResponderEvent) => void) | undefined | undefined;
105
+ onTouchCancel?: ((event: import("react-native").GestureResponderEvent) => void) | undefined | undefined;
106
+ onTouchEndCapture?: ((event: import("react-native").GestureResponderEvent) => void) | undefined | undefined;
107
+ onPointerEnter?: ((event: import("react-native").PointerEvent) => void) | undefined | undefined;
108
+ onPointerEnterCapture?: ((event: import("react-native").PointerEvent) => void) | undefined | undefined;
109
+ onPointerLeave?: ((event: import("react-native").PointerEvent) => void) | undefined | undefined;
110
+ onPointerLeaveCapture?: ((event: import("react-native").PointerEvent) => void) | undefined | undefined;
111
+ onPointerMove?: ((event: import("react-native").PointerEvent) => void) | undefined | undefined;
112
+ onPointerMoveCapture?: ((event: import("react-native").PointerEvent) => void) | undefined | undefined;
113
+ onPointerCancel?: ((event: import("react-native").PointerEvent) => void) | undefined | undefined;
114
+ onPointerCancelCapture?: ((event: import("react-native").PointerEvent) => void) | undefined | undefined;
115
+ onPointerDown?: ((event: import("react-native").PointerEvent) => void) | undefined | undefined;
116
+ onPointerDownCapture?: ((event: import("react-native").PointerEvent) => void) | undefined | undefined;
117
+ onPointerUp?: ((event: import("react-native").PointerEvent) => void) | undefined | undefined;
118
+ onPointerUpCapture?: ((event: import("react-native").PointerEvent) => void) | undefined | undefined;
119
+ hasFeedbackText?: boolean | undefined;
120
+ hasHelpText?: boolean | undefined;
121
+ setHasFeedbackText?: import("react").Dispatch<import("react").SetStateAction<boolean>> | undefined;
122
+ setHasHelpText?: import("react").Dispatch<import("react").SetStateAction<boolean>> | undefined;
123
+ name?: string | undefined;
124
+ labelId?: string | undefined;
125
+ feedbackId?: string | undefined;
126
+ helpTextId?: string | undefined;
127
+ htmlProps?: {
128
+ [x: string]: unknown;
129
+ } | undefined;
130
+ inputRef?: React.RefObject<import("react-native").TextInput | null> | undefined;
131
+ focusInput?: (() => void) | undefined;
132
+ isRequired?: boolean | undefined;
133
+ };
134
+ isInvalid: boolean;
135
+ isReadOnly: boolean;
136
+ inputProps: any;
137
+ labelProps: Record<string, unknown>;
138
+ isChecked: any;
139
+ isDisabled: any;
140
+ isHovered: boolean;
141
+ hoverProps: {
142
+ onHoverIn: () => void;
143
+ onHoverOut: () => void;
144
+ };
145
+ mergedRef: import("react").RefCallback<unknown>;
146
+ inputRef: import("react").RefObject<HTMLInputElement | null>;
147
+ };
148
+ export {};
149
+ //# sourceMappingURL=useRadioRoot.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRadioRoot.d.ts","sourceRoot":"","sources":["../../../src/radio/useRadioRoot.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,UAAU,mBAAmB;IAC3B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED,wBAAgB,YAAY,CAC1B,KAAK,EAAE,WAAW,EAClB,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,EACxB,EAAE,kBAA0B,EAAE,GAAE,mBAAwB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAsDzD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdx-ui/primitives",
3
- "version": "0.0.1-beta.1",
3
+ "version": "0.0.1-beta.11",
4
4
  "main": "lib/commonjs/index.js",
5
5
  "module": "lib/module/index.js",
6
6
  "react-native": "src/index.ts",
@@ -51,13 +51,16 @@
51
51
  }
52
52
  },
53
53
  "dependencies": {
54
+ "@react-aria/utils": "^3.33.0",
54
55
  "@react-aria/visually-hidden": "3.8.30",
55
56
  "@react-native-aria/checkbox": "0.2.10",
56
57
  "@react-native-aria/focus": "^0.2.9",
57
58
  "@react-native-aria/interactions": "^0.2.16",
59
+ "@react-native-aria/radio": "0.2.13",
58
60
  "@react-stately/checkbox": "3.7.4",
61
+ "@react-stately/radio": "3.12.0",
59
62
  "@react-stately/toggle": "3.9.4",
60
- "@cdx-ui/utils": "0.0.1-beta.1"
63
+ "@cdx-ui/utils": "0.0.1-beta.11"
61
64
  },
62
65
  "devDependencies": {
63
66
  "@types/react": "*",
package/src/index.ts CHANGED
@@ -7,9 +7,11 @@ export * from './form';
7
7
  export * from './input';
8
8
  export * from './otp-input';
9
9
  export * from './link';
10
+ export * from './list-item';
10
11
  export { type EdgeInsets, OverlayInsetsProvider } from './overlay';
11
12
  export * from './select';
12
13
  export * from './switch';
13
14
  export * from './progress';
15
+ export * from './radio';
14
16
  export type { InteractionState } from './types';
15
17
  export { dataAttributes } from './utils/dataAttributes';
@@ -0,0 +1,5 @@
1
+ import { createContext } from '@cdx-ui/utils';
2
+ import type { IListItemContextValue } from './types';
3
+
4
+ export const [ListItemProvider, useListItemContext] =
5
+ createContext<IListItemContextValue>('ListItemContext');
@@ -0,0 +1,23 @@
1
+ import React, { forwardRef } from 'react';
2
+ import { dataAttributes } from '../utils/dataAttributes';
3
+ import type { IListItemContentProps } from './types';
4
+
5
+ const contentStyle = {
6
+ flex: 1,
7
+ flexDirection: 'column' as const,
8
+ minWidth: 0,
9
+ };
10
+
11
+ export const createListItemContent = <T,>(Base: React.ComponentType<T>) =>
12
+ forwardRef(({ children, style, ...props }: IListItemContentProps, ref: React.Ref<unknown>) => (
13
+ <Base
14
+ {...(props as T)}
15
+ {...dataAttributes({
16
+ slot: 'list-item-content',
17
+ })}
18
+ ref={ref as React.Ref<T>}
19
+ style={[contentStyle, style]}
20
+ >
21
+ {children}
22
+ </Base>
23
+ ));
@@ -0,0 +1,19 @@
1
+ import React, { forwardRef } from 'react';
2
+ import { dataAttributes } from '../utils/dataAttributes';
3
+ import type { IListItemDescriptionProps } from './types';
4
+
5
+ export const createListItemDescription = <T,>(Base: React.ComponentType<T>) =>
6
+ forwardRef(
7
+ ({ children, style, ...props }: IListItemDescriptionProps, ref: React.Ref<unknown>) => (
8
+ <Base
9
+ {...(props as T)}
10
+ {...dataAttributes({
11
+ slot: 'list-item-description',
12
+ })}
13
+ ref={ref as React.Ref<T>}
14
+ style={style}
15
+ >
16
+ {children}
17
+ </Base>
18
+ ),
19
+ );
@@ -0,0 +1,30 @@
1
+ import React, { forwardRef } from 'react';
2
+ import { dataAttributes } from '../utils/dataAttributes';
3
+ import type { IListItemLeadingSlotProps } from './types';
4
+
5
+ const shrinkZero = { flexShrink: 0 as const };
6
+
7
+ export const createListItemLeadingSlot = <T,>(Base: React.ComponentType<T>) =>
8
+ forwardRef(
9
+ (
10
+ { 'aria-hidden': ariaHidden, style, children, ...props }: IListItemLeadingSlotProps,
11
+ ref: React.Ref<unknown>,
12
+ ) => {
13
+ const accessibilityElementsHidden = ariaHidden !== false;
14
+
15
+ return (
16
+ <Base
17
+ {...(props as T)}
18
+ {...dataAttributes({
19
+ slot: 'list-item-leading',
20
+ })}
21
+ accessibilityElementsHidden={accessibilityElementsHidden}
22
+ aria-hidden={ariaHidden}
23
+ ref={ref as React.Ref<T>}
24
+ style={[shrinkZero, style]}
25
+ >
26
+ {children}
27
+ </Base>
28
+ );
29
+ },
30
+ );
@@ -0,0 +1,17 @@
1
+ import React, { forwardRef } from 'react';
2
+ import { dataAttributes } from '../utils/dataAttributes';
3
+ import type { IListItemMetaProps } from './types';
4
+
5
+ export const createListItemMeta = <T,>(Base: React.ComponentType<T>) =>
6
+ forwardRef(({ children, style, ...props }: IListItemMetaProps, ref: React.Ref<unknown>) => (
7
+ <Base
8
+ {...(props as T)}
9
+ {...dataAttributes({
10
+ slot: 'list-item-meta',
11
+ })}
12
+ ref={ref as React.Ref<T>}
13
+ style={style}
14
+ >
15
+ {children}
16
+ </Base>
17
+ ));
@@ -0,0 +1,163 @@
1
+ import React, { forwardRef, useMemo } from 'react';
2
+ import type { PressableProps } from 'react-native';
3
+ import { composeEventHandlers, mergeRefs } from '@cdx-ui/utils';
4
+ import { useHover, usePress } from '@react-native-aria/interactions';
5
+ import { dataAttributes } from '../utils/dataAttributes';
6
+ import { ListItemProvider } from './context';
7
+ import type { IListItemProps, IListItemPressablePassthrough } from './types';
8
+
9
+ function listItemRootDataAttrs(
10
+ size: IListItemProps['size'],
11
+ surface: IListItemProps['surface'],
12
+ showSeparator: boolean | undefined,
13
+ crossAlign: IListItemProps['crossAlign'],
14
+ ) {
15
+ return dataAttributes({
16
+ slot: 'list-item',
17
+ size: size ?? 'default',
18
+ surface: surface ?? 'default',
19
+ separator: showSeparator ?? true,
20
+ crossAlign: crossAlign ?? 'center',
21
+ });
22
+ }
23
+
24
+ function rowStyleForCrossAlign(crossAlign: IListItemProps['crossAlign']) {
25
+ return {
26
+ flexDirection: 'row' as const,
27
+ alignSelf: 'stretch' as const,
28
+ alignItems: crossAlign === 'start' ? ('flex-start' as const) : ('center' as const),
29
+ };
30
+ }
31
+
32
+ export const createListItemRoot = <V, P>(
33
+ BaseView: React.ComponentType<V>,
34
+ BasePressable: React.ComponentType<P>,
35
+ ) =>
36
+ forwardRef(
37
+ (
38
+ {
39
+ asChild = false,
40
+ children,
41
+ onPress,
42
+ size = 'default',
43
+ surface = 'default',
44
+ showSeparator = true,
45
+ crossAlign = 'center',
46
+ disabled = false,
47
+ style,
48
+ ...restProps
49
+ }: IListItemProps,
50
+ ref: React.Ref<unknown>,
51
+ ) => {
52
+ const asChildInteractive = asChild && !!onPress && React.isValidElement(children);
53
+ const isPressableRoot = !!onPress && !asChildInteractive;
54
+
55
+ const pressState = usePress({
56
+ isDisabled: !isPressableRoot || disabled,
57
+ });
58
+ const isPressed = pressState.isPressed;
59
+ const pressProps = pressState.pressProps as Pick<PressableProps, 'onPressIn' | 'onPressOut'>;
60
+ const { hoverProps, isHovered } = useHover();
61
+
62
+ const slotAttrs = listItemRootDataAttrs(size, surface, showSeparator, crossAlign);
63
+
64
+ const contextValue = useMemo(
65
+ () => ({
66
+ isPressed: isPressableRoot ? isPressed : false,
67
+ isHovered,
68
+ isDisabled: disabled,
69
+ crossAlign: crossAlign ?? 'center',
70
+ }),
71
+ [isPressableRoot, isPressed, isHovered, disabled, crossAlign],
72
+ );
73
+
74
+ if (asChildInteractive) {
75
+ const child = children as React.ReactElement<Record<string, unknown>>;
76
+
77
+ const mergedOnPress = composeEventHandlers(
78
+ child.props.onPress as IListItemProps['onPress'],
79
+ onPress,
80
+ );
81
+
82
+ const childDisabled = !!(child.props as { disabled?: boolean }).disabled;
83
+
84
+ const resolvedDisabled = disabled || childDisabled;
85
+
86
+ return (
87
+ <ListItemProvider
88
+ value={{
89
+ isPressed: false,
90
+ isHovered: false,
91
+ isDisabled: resolvedDisabled,
92
+ crossAlign: crossAlign ?? 'center',
93
+ }}
94
+ >
95
+ {React.cloneElement(child, {
96
+ ...restProps,
97
+ ...slotAttrs,
98
+ ...dataAttributes({
99
+ active: false,
100
+ hovered: false,
101
+ disabled: resolvedDisabled,
102
+ }),
103
+ ...(resolvedDisabled && { accessibilityState: { disabled: true } }),
104
+ disabled: resolvedDisabled,
105
+ onPress: resolvedDisabled ? undefined : mergedOnPress,
106
+ ref: mergeRefs(ref, child.props.ref as React.Ref<unknown>),
107
+ style: [rowStyleForCrossAlign(crossAlign), style, child.props.style],
108
+ })}
109
+ </ListItemProvider>
110
+ );
111
+ }
112
+
113
+ if (isPressableRoot) {
114
+ const interactionAttrs = dataAttributes({
115
+ active: isPressed,
116
+ hovered: isHovered,
117
+ disabled,
118
+ });
119
+
120
+ const {
121
+ onPressIn: onPressInProp,
122
+ onPressOut: onPressOutProp,
123
+ onHoverIn: onHoverInProp,
124
+ onHoverOut: onHoverOutProp,
125
+ } = restProps as IListItemPressablePassthrough;
126
+
127
+ return (
128
+ <ListItemProvider value={contextValue}>
129
+ <BasePressable
130
+ {...(restProps as P)}
131
+ {...slotAttrs}
132
+ {...interactionAttrs}
133
+ {...(disabled && { accessibilityState: { disabled: true } })}
134
+ disabled={disabled}
135
+ ref={ref as React.Ref<P>}
136
+ style={[rowStyleForCrossAlign(crossAlign), style]}
137
+ onPress={disabled ? undefined : onPress}
138
+ onPressIn={composeEventHandlers(onPressInProp, pressProps.onPressIn)}
139
+ onPressOut={composeEventHandlers(onPressOutProp, pressProps.onPressOut)}
140
+ onHoverIn={composeEventHandlers(onHoverInProp, hoverProps.onHoverIn)}
141
+ onHoverOut={composeEventHandlers(onHoverOutProp, hoverProps.onHoverOut)}
142
+ >
143
+ {children}
144
+ </BasePressable>
145
+ </ListItemProvider>
146
+ );
147
+ }
148
+
149
+ return (
150
+ <ListItemProvider value={contextValue}>
151
+ <BaseView
152
+ {...(restProps as V)}
153
+ {...slotAttrs}
154
+ {...(disabled ? dataAttributes({ disabled: true }) : undefined)}
155
+ ref={ref as React.Ref<V>}
156
+ style={[rowStyleForCrossAlign(crossAlign), style]}
157
+ >
158
+ {children}
159
+ </BaseView>
160
+ </ListItemProvider>
161
+ );
162
+ },
163
+ );
@@ -0,0 +1,53 @@
1
+ import React, { forwardRef } from 'react';
2
+ import { View } from 'react-native';
3
+ import { dataAttributes } from '../utils/dataAttributes';
4
+ import type { IListItemSectionHeaderProps } from './types';
5
+
6
+ const row = {
7
+ flexDirection: 'row' as const,
8
+ alignItems: 'center' as const,
9
+ justifyContent: 'space-between' as const,
10
+ gap: 8,
11
+ };
12
+
13
+ const labelCell = {
14
+ flex: 1,
15
+ minWidth: 0,
16
+ /** Keeps the label column from stretching to a taller trailing sibling (e.g. Chip). */
17
+ alignSelf: 'center' as const,
18
+ };
19
+
20
+ const trailingCell = {
21
+ flexShrink: 0,
22
+ /** Prevents the trailing slot from stretching vertically and “filling” the row. */
23
+ alignSelf: 'center' as const,
24
+ };
25
+
26
+ export const createListItemSectionHeader = <T,>(Base: React.ComponentType<T>) =>
27
+ forwardRef(
28
+ (
29
+ {
30
+ children,
31
+ trailing,
32
+ showDivider = true,
33
+ style,
34
+ accessibilityRole = 'header',
35
+ ...props
36
+ }: IListItemSectionHeaderProps,
37
+ ref: React.Ref<unknown>,
38
+ ) => (
39
+ <Base
40
+ {...(props as T)}
41
+ {...dataAttributes({
42
+ slot: 'list-section-header',
43
+ divider: showDivider,
44
+ })}
45
+ accessibilityRole={accessibilityRole}
46
+ ref={ref as React.Ref<T>}
47
+ style={[row, style]}
48
+ >
49
+ <View style={labelCell}>{children}</View>
50
+ {trailing ? <View style={trailingCell}>{trailing}</View> : null}
51
+ </Base>
52
+ ),
53
+ );
@@ -0,0 +1,17 @@
1
+ import React, { forwardRef } from 'react';
2
+ import { dataAttributes } from '../utils/dataAttributes';
3
+ import type { IListItemTitleProps } from './types';
4
+
5
+ export const createListItemTitle = <T,>(Base: React.ComponentType<T>) =>
6
+ forwardRef(({ children, style, ...props }: IListItemTitleProps, ref: React.Ref<unknown>) => (
7
+ <Base
8
+ {...(props as T)}
9
+ {...dataAttributes({
10
+ slot: 'list-item-title',
11
+ })}
12
+ ref={ref as React.Ref<T>}
13
+ style={style}
14
+ >
15
+ {children}
16
+ </Base>
17
+ ));
@@ -0,0 +1,21 @@
1
+ import React, { forwardRef } from 'react';
2
+ import { dataAttributes } from '../utils/dataAttributes';
3
+ import type { IListItemTrailingSlotProps } from './types';
4
+
5
+ const shrinkZero = { flexShrink: 0 as const };
6
+
7
+ export const createListItemTrailingSlot = <T,>(Base: React.ComponentType<T>) =>
8
+ forwardRef(
9
+ ({ children, style, ...props }: IListItemTrailingSlotProps, ref: React.Ref<unknown>) => (
10
+ <Base
11
+ {...(props as T)}
12
+ {...dataAttributes({
13
+ slot: 'list-item-trailing',
14
+ })}
15
+ ref={ref as React.Ref<T>}
16
+ style={[shrinkZero, style]}
17
+ >
18
+ {children}
19
+ </Base>
20
+ ),
21
+ );
@@ -0,0 +1,88 @@
1
+ import type React from 'react';
2
+ import { createListItemContent } from './createListItemContent';
3
+ import { createListItemDescription } from './createListItemDescription';
4
+ import { createListItemLeadingSlot } from './createListItemLeadingSlot';
5
+ import { createListItemMeta } from './createListItemMeta';
6
+ import { createListItemRoot } from './createListItemRoot';
7
+ import { createListItemSectionHeader } from './createListItemSectionHeader';
8
+ import { createListItemTitle } from './createListItemTitle';
9
+ import { createListItemTrailingSlot } from './createListItemTrailingSlot';
10
+ import type { IListItemComponentType } from './types';
11
+
12
+ export type {
13
+ IListItemComponentType,
14
+ IListItemContentProps,
15
+ IListItemContextValue,
16
+ IListItemDescriptionProps,
17
+ IListItemLeadingSlotProps,
18
+ IListItemMetaProps,
19
+ IListItemPressablePassthrough,
20
+ IListItemProps,
21
+ IListItemSectionHeaderProps,
22
+ IListItemTitleProps,
23
+ IListItemTrailingSlotProps,
24
+ ListItemCrossAlign,
25
+ ListItemSize,
26
+ ListItemSurface,
27
+ } from './types';
28
+
29
+ export { ListItemProvider, useListItemContext } from './context';
30
+
31
+ export function createListItem<
32
+ ViewComponent,
33
+ PressableComponent,
34
+ LeadingSlot,
35
+ Content,
36
+ Title,
37
+ Description,
38
+ Meta,
39
+ TrailingSlot,
40
+ SectionHeader,
41
+ >(BaseComponents: {
42
+ View: React.ComponentType<ViewComponent>;
43
+ Pressable: React.ComponentType<PressableComponent>;
44
+ LeadingSlot: React.ComponentType<LeadingSlot>;
45
+ Content: React.ComponentType<Content>;
46
+ Title: React.ComponentType<Title>;
47
+ Description: React.ComponentType<Description>;
48
+ Meta: React.ComponentType<Meta>;
49
+ TrailingSlot: React.ComponentType<TrailingSlot>;
50
+ SectionHeader: React.ComponentType<SectionHeader>;
51
+ }) {
52
+ const ListItem = createListItemRoot(BaseComponents.View, BaseComponents.Pressable);
53
+ const LeadingSlot = createListItemLeadingSlot(BaseComponents.LeadingSlot);
54
+ const Content = createListItemContent(BaseComponents.Content);
55
+ const Title = createListItemTitle(BaseComponents.Title);
56
+ const Description = createListItemDescription(BaseComponents.Description);
57
+ const Meta = createListItemMeta(BaseComponents.Meta);
58
+ const TrailingSlot = createListItemTrailingSlot(BaseComponents.TrailingSlot);
59
+ const SectionHeader = createListItemSectionHeader(BaseComponents.SectionHeader);
60
+
61
+ ListItem.displayName = 'ListItemPrimitive';
62
+ LeadingSlot.displayName = 'ListItemPrimitive.LeadingSlot';
63
+ Content.displayName = 'ListItemPrimitive.Content';
64
+ Title.displayName = 'ListItemPrimitive.Title';
65
+ Description.displayName = 'ListItemPrimitive.Description';
66
+ Meta.displayName = 'ListItemPrimitive.Meta';
67
+ TrailingSlot.displayName = 'ListItemPrimitive.TrailingSlot';
68
+ SectionHeader.displayName = 'ListItemPrimitive.SectionHeader';
69
+
70
+ return Object.assign(ListItem, {
71
+ LeadingSlot,
72
+ Content,
73
+ Title,
74
+ Description,
75
+ Meta,
76
+ TrailingSlot,
77
+ SectionHeader,
78
+ }) as IListItemComponentType<
79
+ ViewComponent | PressableComponent,
80
+ LeadingSlot,
81
+ Content,
82
+ Title,
83
+ Description,
84
+ Meta,
85
+ TrailingSlot,
86
+ SectionHeader
87
+ >;
88
+ }