@cdx-ui/primitives 0.0.1-beta.4 → 0.0.1-beta.6

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 (86) hide show
  1. package/README.md +1 -0
  2. package/lib/commonjs/index.js +12 -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/module/index.js +1 -0
  27. package/lib/module/index.js.map +1 -1
  28. package/lib/module/list-item/context.js +5 -0
  29. package/lib/module/list-item/context.js.map +1 -0
  30. package/lib/module/list-item/createListItemContent.js +24 -0
  31. package/lib/module/list-item/createListItemContent.js.map +1 -0
  32. package/lib/module/list-item/createListItemDescription.js +19 -0
  33. package/lib/module/list-item/createListItemDescription.js.map +1 -0
  34. package/lib/module/list-item/createListItemLeadingSlot.js +28 -0
  35. package/lib/module/list-item/createListItemLeadingSlot.js.map +1 -0
  36. package/lib/module/list-item/createListItemMeta.js +19 -0
  37. package/lib/module/list-item/createListItemMeta.js.map +1 -0
  38. package/lib/module/list-item/createListItemRoot.js +136 -0
  39. package/lib/module/list-item/createListItemRoot.js.map +1 -0
  40. package/lib/module/list-item/createListItemSectionHeader.js +48 -0
  41. package/lib/module/list-item/createListItemSectionHeader.js.map +1 -0
  42. package/lib/module/list-item/createListItemTitle.js +19 -0
  43. package/lib/module/list-item/createListItemTitle.js.map +1 -0
  44. package/lib/module/list-item/createListItemTrailingSlot.js +22 -0
  45. package/lib/module/list-item/createListItemTrailingSlot.js.map +1 -0
  46. package/lib/module/list-item/index.js +39 -0
  47. package/lib/module/list-item/index.js.map +1 -0
  48. package/lib/module/list-item/types.js +4 -0
  49. package/lib/module/list-item/types.js.map +1 -0
  50. package/lib/typescript/index.d.ts +1 -0
  51. package/lib/typescript/index.d.ts.map +1 -1
  52. package/lib/typescript/list-item/context.d.ts +6 -0
  53. package/lib/typescript/list-item/context.d.ts.map +1 -0
  54. package/lib/typescript/list-item/createListItemContent.d.ts +3 -0
  55. package/lib/typescript/list-item/createListItemContent.d.ts.map +1 -0
  56. package/lib/typescript/list-item/createListItemDescription.d.ts +3 -0
  57. package/lib/typescript/list-item/createListItemDescription.d.ts.map +1 -0
  58. package/lib/typescript/list-item/createListItemLeadingSlot.d.ts +4 -0
  59. package/lib/typescript/list-item/createListItemLeadingSlot.d.ts.map +1 -0
  60. package/lib/typescript/list-item/createListItemMeta.d.ts +3 -0
  61. package/lib/typescript/list-item/createListItemMeta.d.ts.map +1 -0
  62. package/lib/typescript/list-item/createListItemRoot.d.ts +4 -0
  63. package/lib/typescript/list-item/createListItemRoot.d.ts.map +1 -0
  64. package/lib/typescript/list-item/createListItemSectionHeader.d.ts +4 -0
  65. package/lib/typescript/list-item/createListItemSectionHeader.d.ts.map +1 -0
  66. package/lib/typescript/list-item/createListItemTitle.d.ts +3 -0
  67. package/lib/typescript/list-item/createListItemTitle.d.ts.map +1 -0
  68. package/lib/typescript/list-item/createListItemTrailingSlot.d.ts +3 -0
  69. package/lib/typescript/list-item/createListItemTrailingSlot.d.ts.map +1 -0
  70. package/lib/typescript/list-item/index.d.ts +16 -0
  71. package/lib/typescript/list-item/index.d.ts.map +1 -0
  72. package/lib/typescript/list-item/types.d.ts +86 -0
  73. package/lib/typescript/list-item/types.d.ts.map +1 -0
  74. package/package.json +2 -2
  75. package/src/index.ts +1 -0
  76. package/src/list-item/context.tsx +5 -0
  77. package/src/list-item/createListItemContent.tsx +23 -0
  78. package/src/list-item/createListItemDescription.tsx +19 -0
  79. package/src/list-item/createListItemLeadingSlot.tsx +30 -0
  80. package/src/list-item/createListItemMeta.tsx +17 -0
  81. package/src/list-item/createListItemRoot.tsx +163 -0
  82. package/src/list-item/createListItemSectionHeader.tsx +53 -0
  83. package/src/list-item/createListItemTitle.tsx +17 -0
  84. package/src/list-item/createListItemTrailingSlot.tsx +21 -0
  85. package/src/list-item/index.ts +88 -0
  86. package/src/list-item/types.ts +122 -0
@@ -0,0 +1,86 @@
1
+ import type { ForwardRefExoticComponent, PropsWithoutRef, ReactNode, RefAttributes } from 'react';
2
+ import type { PressableProps, TextProps, ViewProps } from 'react-native';
3
+ export type ListItemSize = 'default' | 'compact';
4
+ export type ListItemSurface = 'default' | 'negative';
5
+ /**
6
+ * Cross-axis alignment for the row (`flex-direction: row`).
7
+ * - **center**: Leading, content, and trailing are vertically centered (typical transactions).
8
+ * - **start**: Top-aligned — use when trailing text should align with the title row (e.g. branch distance “2.04 mi”) or status chips sit above a tall content stack.
9
+ */
10
+ export type ListItemCrossAlign = 'center' | 'start';
11
+ export type IListItemPressablePassthrough = Partial<Pick<PressableProps, 'onPressIn' | 'onPressOut' | 'onHoverIn' | 'onHoverOut'>>;
12
+ export interface IListItemProps extends ViewProps, IListItemPressablePassthrough {
13
+ /**
14
+ * Disables press handling when the root is pressable (maps to Pressable `disabled`).
15
+ */
16
+ disabled?: boolean;
17
+ /**
18
+ * When set (and `asChild` is not used), root renders as pressable with interaction props.
19
+ */
20
+ onPress?: PressableProps['onPress'];
21
+ /**
22
+ * Vertical density; mapped at styled layer via `data-size`.
23
+ * @default 'default'
24
+ */
25
+ size?: ListItemSize;
26
+ /**
27
+ * Semantic row surface (e.g. canceled transaction); mapped via `data-surface`.
28
+ * @default 'default'
29
+ */
30
+ surface?: ListItemSurface;
31
+ /**
32
+ * Whether the row shows a bottom separator; mapped via `data-separator`.
33
+ * @default true
34
+ */
35
+ showSeparator?: boolean;
36
+ /**
37
+ * Vertical alignment of leading / content / trailing along the row cross axis.
38
+ * @default 'center'
39
+ */
40
+ crossAlign?: ListItemCrossAlign;
41
+ /**
42
+ * Merge interaction props onto a single child instead of rendering the default pressable root.
43
+ * Intended for use with `onPress`.
44
+ */
45
+ asChild?: boolean;
46
+ }
47
+ export interface IListItemContextValue {
48
+ isPressed: boolean;
49
+ isHovered: boolean;
50
+ isDisabled: boolean;
51
+ crossAlign: ListItemCrossAlign;
52
+ }
53
+ export interface IListItemLeadingSlotProps extends ViewProps {
54
+ /**
55
+ * Decorative leading content defaults to hidden from the accessibility tree.
56
+ * Set to `false` when the leading region contains meaningful controls.
57
+ * @default true
58
+ */
59
+ 'aria-hidden'?: boolean;
60
+ }
61
+ export type IListItemContentProps = ViewProps;
62
+ export type IListItemTitleProps = TextProps;
63
+ export type IListItemDescriptionProps = TextProps;
64
+ export type IListItemMetaProps = TextProps;
65
+ export type IListItemTrailingSlotProps = ViewProps;
66
+ export interface IListItemSectionHeaderProps extends ViewProps {
67
+ /** Primary section label (e.g. date heading). */
68
+ children: ReactNode;
69
+ /** Optional right-aligned adornment (e.g. section Chip). */
70
+ trailing?: ReactNode;
71
+ /**
72
+ * Whether to expose the top divider marker for styling (`data-divider`).
73
+ * @default true
74
+ */
75
+ showDivider?: boolean;
76
+ }
77
+ export type IListItemComponentType<RootRef, LeadingSlot, Content, Title, Description, Meta, TrailingSlot, SectionHeader> = ForwardRefExoticComponent<RefAttributes<RootRef> & IListItemProps> & {
78
+ LeadingSlot: ForwardRefExoticComponent<RefAttributes<LeadingSlot> & PropsWithoutRef<LeadingSlot> & IListItemLeadingSlotProps>;
79
+ Content: ForwardRefExoticComponent<RefAttributes<Content> & PropsWithoutRef<Content> & IListItemContentProps>;
80
+ Title: ForwardRefExoticComponent<RefAttributes<Title> & PropsWithoutRef<Title> & IListItemTitleProps>;
81
+ Description: ForwardRefExoticComponent<RefAttributes<Description> & PropsWithoutRef<Description> & IListItemDescriptionProps>;
82
+ Meta: ForwardRefExoticComponent<RefAttributes<Meta> & PropsWithoutRef<Meta> & IListItemMetaProps>;
83
+ TrailingSlot: ForwardRefExoticComponent<RefAttributes<TrailingSlot> & PropsWithoutRef<TrailingSlot> & IListItemTrailingSlotProps>;
84
+ SectionHeader: ForwardRefExoticComponent<RefAttributes<SectionHeader> & PropsWithoutRef<SectionHeader> & IListItemSectionHeaderProps>;
85
+ };
86
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/list-item/types.ts"],"names":[],"mappings":"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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cdx-ui/primitives",
3
- "version": "0.0.1-beta.4",
3
+ "version": "0.0.1-beta.6",
4
4
  "main": "lib/commonjs/index.js",
5
5
  "module": "lib/module/index.js",
6
6
  "react-native": "src/index.ts",
@@ -57,7 +57,7 @@
57
57
  "@react-native-aria/interactions": "^0.2.16",
58
58
  "@react-stately/checkbox": "3.7.4",
59
59
  "@react-stately/toggle": "3.9.4",
60
- "@cdx-ui/utils": "0.0.1-beta.4"
60
+ "@cdx-ui/utils": "0.0.1-beta.6"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/react": "*",
package/src/index.ts CHANGED
@@ -7,6 +7,7 @@ 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';
@@ -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
+ }