@tamagui/list-item 1.0.1-beta.56 → 1.0.1-beta.60

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tamagui/list-item",
3
- "version": "1.0.1-beta.56",
3
+ "version": "1.0.1-beta.60",
4
4
  "sideEffects": false,
5
5
  "source": "src/index.ts",
6
6
  "types": "./types/index.d.ts",
@@ -8,6 +8,7 @@
8
8
  "module": "dist/esm",
9
9
  "module:jsx": "dist/jsx",
10
10
  "files": [
11
+ "src",
11
12
  "types",
12
13
  "dist"
13
14
  ],
@@ -16,16 +17,16 @@
16
17
  "watch": "tamagui-build --watch"
17
18
  },
18
19
  "dependencies": {
19
- "@tamagui/core": "^1.0.1-beta.56",
20
- "@tamagui/font-size": "^1.0.1-beta.56",
21
- "@tamagui/helpers-tamagui": "^1.0.1-beta.56"
20
+ "@tamagui/core": "^1.0.1-beta.60",
21
+ "@tamagui/font-size": "^1.0.1-beta.60",
22
+ "@tamagui/helpers-tamagui": "^1.0.1-beta.60"
22
23
  },
23
24
  "peerDependencies": {
24
25
  "react": "*",
25
26
  "react-dom": "*"
26
27
  },
27
28
  "devDependencies": {
28
- "@tamagui/build": "^1.0.1-beta.56",
29
+ "@tamagui/build": "^1.0.1-beta.60",
29
30
  "react": "*",
30
31
  "react-dom": "*"
31
32
  },
@@ -0,0 +1,201 @@
1
+ import {
2
+ FontSizeTokens,
3
+ GetProps,
4
+ ReactComponentWithRef,
5
+ Spacer,
6
+ ThemeableProps,
7
+ getSize,
8
+ getVariableValue,
9
+ styled,
10
+ themeable,
11
+ withStaticProperties,
12
+ } from '@tamagui/core'
13
+ import { getFontSize } from '@tamagui/font-size'
14
+ import {
15
+ TextParentStyles,
16
+ useGetThemedIcon,
17
+ wrapStringChildrenInText,
18
+ } from '@tamagui/helpers-tamagui'
19
+ import { ThemeableStack, YStack } from '@tamagui/stacks'
20
+ import { SizableText } from '@tamagui/text'
21
+ import React, { FunctionComponent, forwardRef } from 'react'
22
+ import { View } from 'react-native'
23
+
24
+ // bugfix esbuild strips react jsx: 'preserve'
25
+ React['createElement']
26
+
27
+ type ListItemIconProps = { color?: string; size?: number }
28
+ type IconProp = JSX.Element | FunctionComponent<ListItemIconProps> | null
29
+
30
+ export type ListItemProps = Omit<TextParentStyles, 'TextComponent'> &
31
+ GetProps<typeof ListItemFrame> &
32
+ ThemeableProps & {
33
+ // add icon before, passes color and size automatically if Component
34
+ icon?: IconProp
35
+ // add icon after, passes color and size automatically if Component
36
+ iconAfter?: IconProp
37
+ // adjust icon relative to size
38
+ // default: -1
39
+ scaleIcon?: number
40
+ // make the spacing elements flex
41
+ spaceFlex?: number | boolean
42
+ // adjust internal space relative to icon size
43
+ scaleSpace?: number
44
+ // title
45
+ title?: React.ReactNode
46
+ // subtitle
47
+ subTitle?: React.ReactNode
48
+ }
49
+
50
+ const ListItemFrame = styled(ThemeableStack, {
51
+ name: 'ListItem',
52
+ tag: 'li',
53
+ alignItems: 'center',
54
+ flexWrap: 'nowrap',
55
+ width: '100%',
56
+ borderColor: '$borderColor',
57
+ maxWidth: '100%',
58
+ overflow: 'hidden',
59
+ flexDirection: 'row',
60
+
61
+ variants: {
62
+ size: {
63
+ '...size': (val, { tokens }) => {
64
+ return {
65
+ minHeight: tokens.size[val],
66
+ paddingHorizontal: tokens.space[val],
67
+ }
68
+ },
69
+ },
70
+
71
+ active: {
72
+ true: {
73
+ hoverStyle: {
74
+ backgroundColor: '$background',
75
+ },
76
+ },
77
+ false: {},
78
+ },
79
+
80
+ disabled: {
81
+ true: {
82
+ opacity: 0.5,
83
+ // TODO breaking types
84
+ pointerEvents: 'none' as any,
85
+ },
86
+ false: {},
87
+ },
88
+ },
89
+
90
+ defaultVariants: {
91
+ size: '$4',
92
+ },
93
+ })
94
+
95
+ export const ListItemText = styled(SizableText, {
96
+ color: '$color',
97
+ selectable: false,
98
+ flexGrow: 1,
99
+ flexShrink: 1,
100
+ ellipse: true,
101
+ })
102
+
103
+ export const ListItemSubtitle = styled(ListItemText, {
104
+ color: '$colorPress',
105
+ size: '$3',
106
+ })
107
+
108
+ const ListItemComponent = forwardRef((props: ListItemProps, ref) => {
109
+ // careful not to desctructure and re-order props, order is important
110
+ const {
111
+ children,
112
+ icon,
113
+ iconAfter,
114
+ noTextWrap,
115
+ theme: themeName,
116
+ space,
117
+ spaceFlex,
118
+ scaleIcon = 1,
119
+ scaleSpace = 1,
120
+ subTitle,
121
+
122
+ // text props
123
+ color,
124
+ fontWeight,
125
+ letterSpacing,
126
+ fontSize,
127
+ fontFamily,
128
+ textAlign,
129
+ textProps,
130
+ title,
131
+ ...rest
132
+ } = props as ListItemProps
133
+
134
+ const size = props.size || '$4'
135
+ const subtitleSizeToken = getSize(size, -3)
136
+ const subtitleSize = `$${subtitleSizeToken.key}` as FontSizeTokens
137
+ const iconSize = getFontSize(size) * scaleIcon
138
+ const getThemedIcon = useGetThemedIcon({ size: iconSize, color })
139
+ const [themedIcon, themedIconAfter] = [icon, iconAfter].map(getThemedIcon)
140
+ const spaceSize = getVariableValue(iconSize) * scaleSpace
141
+ const contents = wrapStringChildrenInText(ListItemText, props)
142
+
143
+ return (
144
+ <ListItemFrame fontFamily={fontFamily} ref={ref as any} {...rest}>
145
+ {themedIcon || themedIconAfter ? (
146
+ <>
147
+ {themedIcon ? (
148
+ <>
149
+ {themedIcon}
150
+ <Spacer size={spaceSize} />
151
+ </>
152
+ ) : null}
153
+ {/* helper for common title/subtitle pttern */}
154
+ {!!(title || subTitle) && (
155
+ <YStack flex={1}>
156
+ <ListItemText>{title}</ListItemText>
157
+ {subTitle ? (
158
+ typeof subTitle === 'string' ? (
159
+ // TODO can use theme but we need to standardize to alt themes
160
+ // or standardize on subtle colors in themes
161
+ <ListItemSubtitle marginTop="$-2" opacity={0.65} size={subtitleSize}>
162
+ {subTitle}
163
+ </ListItemSubtitle>
164
+ ) : (
165
+ subTitle
166
+ )
167
+ ) : null}
168
+ </YStack>
169
+ )}
170
+ {contents}
171
+ {themedIconAfter ? (
172
+ <>
173
+ <Spacer flex size={spaceSize} />
174
+ {themedIconAfter}
175
+ </>
176
+ ) : null}
177
+ </>
178
+ ) : (
179
+ contents
180
+ )}
181
+ </ListItemFrame>
182
+ )
183
+ })
184
+
185
+ const ListItemInner: ReactComponentWithRef<ListItemProps, HTMLLIElement | View> =
186
+ ListItemFrame.extractable(themeable(ListItemComponent as any) as any, {
187
+ inlineProps: new Set([
188
+ // text props go here (can't really optimize them, but we never fully extract listItem anyway)
189
+ 'color',
190
+ 'fontWeight',
191
+ 'fontSize',
192
+ 'fontFamily',
193
+ 'letterSpacing',
194
+ 'textAlign',
195
+ ]),
196
+ })
197
+
198
+ export const ListItem = withStaticProperties(ListItemInner, {
199
+ Text: ListItemText,
200
+ Subtitle: ListItemSubtitle,
201
+ })
package/src/index.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './ListItem'