@plexui/react-native 0.1.1 → 0.2.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.
Files changed (149) hide show
  1. package/README.md +34 -0
  2. package/dist/es/components/ActionSheet/ActionSheet.js +53 -19
  3. package/dist/es/components/Alert/Alert.js +163 -0
  4. package/dist/es/components/Avatar/Avatar.js +20 -8
  5. package/dist/es/components/BottomActions/BottomActions.js +34 -0
  6. package/dist/es/components/BottomSheet/BottomSheet.js +85 -17
  7. package/dist/es/components/Button/Button.js +108 -28
  8. package/dist/es/components/Card/Card.js +16 -8
  9. package/dist/es/components/Checkbox/Checkbox.js +67 -99
  10. package/dist/es/components/Chip/Chip.js +16 -7
  11. package/dist/es/components/Dialog/Dialog.js +38 -24
  12. package/dist/es/components/Field/Field.js +91 -0
  13. package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js +59 -0
  14. package/dist/es/components/Icon/createIcon.js +13 -2
  15. package/dist/es/components/Indicator/CircularProgress.js +80 -0
  16. package/dist/es/components/Indicator/LoadingDots.js +46 -0
  17. package/dist/es/components/Indicator/LoadingIndicator.js +101 -0
  18. package/dist/es/components/Indicator/index.js +3 -0
  19. package/dist/es/components/Input/Input.js +69 -60
  20. package/dist/es/components/InputGroup/InputGroup.js +130 -0
  21. package/dist/es/components/List/List.js +175 -59
  22. package/dist/es/components/Menu/Menu.js +69 -40
  23. package/dist/es/components/NavigationButton/NavigationButton.js +20 -4
  24. package/dist/es/components/OTPInput/OTPInput.js +9 -3
  25. package/dist/es/components/PageControl/PageControl.js +13 -7
  26. package/dist/es/components/Popover/Popover.js +128 -0
  27. package/dist/es/components/Progress/Progress.js +142 -0
  28. package/dist/es/components/ProgressSteps/ProgressSteps.js +207 -0
  29. package/dist/es/components/RollingNumber/RollingNumber.js +125 -0
  30. package/dist/es/components/Select/Select.js +97 -34
  31. package/dist/es/components/Separator/Separator.js +31 -0
  32. package/dist/es/components/ShimmerText/ShimmerText.js +98 -0
  33. package/dist/es/components/Stepper/Stepper.js +219 -0
  34. package/dist/es/components/Switch/Switch.js +26 -12
  35. package/dist/es/components/TagInput/TagInput.js +121 -0
  36. package/dist/es/components/Text/Text.js +7 -4
  37. package/dist/es/components/TextLink/TextLink.js +42 -0
  38. package/dist/es/components/Textarea/Textarea.js +12 -0
  39. package/dist/es/components/Tip/Tip.js +193 -0
  40. package/dist/es/components/Toolbar/Toolbar.js +6 -2
  41. package/dist/es/components/Tooltip/Tooltip.js +272 -0
  42. package/dist/es/index.js +20 -2
  43. package/dist/es/internal/FloatingPanel.js +111 -0
  44. package/dist/es/internal/fieldStack.js +73 -0
  45. package/dist/es/internal/floating.js +97 -0
  46. package/dist/es/internal/ripple.js +119 -0
  47. package/dist/es/internal/row.js +2 -1
  48. package/dist/es/internal/transition.js +113 -0
  49. package/dist/es/theme/ThemeProvider.js +41 -9
  50. package/dist/es/theme/material.js +37 -7
  51. package/dist/types/components/ActionSheet/ActionSheet.d.ts +15 -7
  52. package/dist/types/components/Alert/Alert.d.ts +51 -0
  53. package/dist/types/components/Avatar/Avatar.d.ts +4 -2
  54. package/dist/types/components/BottomActions/BottomActions.d.ts +18 -0
  55. package/dist/types/components/BottomSheet/BottomSheet.d.ts +4 -2
  56. package/dist/types/components/Button/Button.d.ts +20 -5
  57. package/dist/types/components/Card/Card.d.ts +14 -1
  58. package/dist/types/components/Checkbox/Checkbox.d.ts +4 -3
  59. package/dist/types/components/Chip/Chip.d.ts +12 -1
  60. package/dist/types/components/Dialog/Dialog.d.ts +9 -5
  61. package/dist/types/components/Field/Field.d.ts +64 -0
  62. package/dist/types/components/FloatingLabelInput/FloatingLabelInput.d.ts +42 -0
  63. package/dist/types/components/Indicator/CircularProgress.d.ts +34 -0
  64. package/dist/types/components/Indicator/LoadingDots.d.ts +17 -0
  65. package/dist/types/components/Indicator/LoadingIndicator.d.ts +46 -0
  66. package/dist/types/components/Indicator/index.d.ts +3 -0
  67. package/dist/types/components/Input/Input.d.ts +13 -3
  68. package/dist/types/components/InputGroup/InputGroup.d.ts +71 -0
  69. package/dist/types/components/List/List.d.ts +57 -14
  70. package/dist/types/components/Menu/Menu.d.ts +4 -0
  71. package/dist/types/components/NavigationButton/NavigationButton.d.ts +11 -3
  72. package/dist/types/components/OTPInput/OTPInput.d.ts +10 -1
  73. package/dist/types/components/PageControl/PageControl.d.ts +11 -1
  74. package/dist/types/components/Popover/Popover.d.ts +86 -0
  75. package/dist/types/components/Progress/Progress.d.ts +56 -0
  76. package/dist/types/components/ProgressSteps/ProgressSteps.d.ts +61 -0
  77. package/dist/types/components/RollingNumber/RollingNumber.d.ts +36 -0
  78. package/dist/types/components/Select/Select.d.ts +36 -8
  79. package/dist/types/components/Separator/Separator.d.ts +19 -0
  80. package/dist/types/components/ShimmerText/ShimmerText.d.ts +28 -0
  81. package/dist/types/components/Stepper/Stepper.d.ts +61 -0
  82. package/dist/types/components/Switch/Switch.d.ts +5 -5
  83. package/dist/types/components/TagInput/TagInput.d.ts +44 -0
  84. package/dist/types/components/TextLink/TextLink.d.ts +30 -0
  85. package/dist/types/components/Textarea/Textarea.d.ts +19 -0
  86. package/dist/types/components/Tip/Tip.d.ts +71 -0
  87. package/dist/types/components/Toolbar/Toolbar.d.ts +9 -1
  88. package/dist/types/components/Tooltip/Tooltip.d.ts +84 -0
  89. package/dist/types/index.d.ts +20 -2
  90. package/dist/types/internal/FloatingPanel.d.ts +70 -0
  91. package/dist/types/internal/fieldStack.d.ts +48 -0
  92. package/dist/types/internal/floating.d.ts +71 -0
  93. package/dist/types/internal/ripple.d.ts +17 -0
  94. package/dist/types/internal/row.d.ts +15 -3
  95. package/dist/types/internal/transition.d.ts +37 -0
  96. package/dist/types/theme/ThemeProvider.d.ts +28 -4
  97. package/dist/types/theme/material.d.ts +20 -6
  98. package/dist/types/theme/types.d.ts +8 -0
  99. package/package.json +2 -2
  100. package/src/components/ActionSheet/ActionSheet.tsx +107 -38
  101. package/src/components/Alert/Alert.tsx +279 -0
  102. package/src/components/Avatar/Avatar.tsx +21 -9
  103. package/src/components/BottomActions/BottomActions.tsx +54 -0
  104. package/src/components/BottomSheet/BottomSheet.tsx +111 -25
  105. package/src/components/Button/Button.tsx +170 -35
  106. package/src/components/Card/Card.tsx +33 -9
  107. package/src/components/Checkbox/Checkbox.tsx +89 -124
  108. package/src/components/Chip/Chip.tsx +49 -6
  109. package/src/components/Dialog/Dialog.tsx +68 -37
  110. package/src/components/Field/Field.tsx +227 -0
  111. package/src/components/FloatingLabelInput/FloatingLabelInput.tsx +144 -0
  112. package/src/components/Icon/createIcon.tsx +16 -6
  113. package/src/components/Indicator/CircularProgress.tsx +141 -0
  114. package/src/components/Indicator/LoadingDots.tsx +79 -0
  115. package/src/components/Indicator/LoadingIndicator.tsx +166 -0
  116. package/src/components/Indicator/index.ts +3 -0
  117. package/src/components/Input/Input.tsx +126 -97
  118. package/src/components/InputGroup/InputGroup.tsx +261 -0
  119. package/src/components/List/List.tsx +345 -88
  120. package/src/components/Menu/Menu.tsx +83 -41
  121. package/src/components/NavigationButton/NavigationButton.tsx +35 -5
  122. package/src/components/OTPInput/OTPInput.tsx +21 -2
  123. package/src/components/PageControl/PageControl.tsx +36 -8
  124. package/src/components/Popover/Popover.tsx +261 -0
  125. package/src/components/Progress/Progress.tsx +255 -0
  126. package/src/components/ProgressSteps/ProgressSteps.tsx +415 -0
  127. package/src/components/RollingNumber/RollingNumber.tsx +189 -0
  128. package/src/components/Select/Select.tsx +175 -71
  129. package/src/components/Separator/Separator.tsx +51 -0
  130. package/src/components/ShimmerText/ShimmerText.tsx +144 -0
  131. package/src/components/Stepper/Stepper.tsx +386 -0
  132. package/src/components/Switch/Switch.tsx +26 -12
  133. package/src/components/TagInput/TagInput.tsx +227 -0
  134. package/src/components/Text/Text.tsx +8 -4
  135. package/src/components/TextLink/TextLink.tsx +77 -0
  136. package/src/components/Textarea/Textarea.tsx +23 -0
  137. package/src/components/Tip/Tip.tsx +410 -0
  138. package/src/components/Toolbar/Toolbar.tsx +27 -2
  139. package/src/components/Tooltip/Tooltip.tsx +478 -0
  140. package/src/index.ts +36 -2
  141. package/src/internal/FloatingPanel.tsx +199 -0
  142. package/src/internal/fieldStack.tsx +179 -0
  143. package/src/internal/floating.ts +131 -0
  144. package/src/internal/ripple.tsx +132 -0
  145. package/src/internal/row.ts +16 -3
  146. package/src/internal/transition.ts +124 -0
  147. package/src/theme/ThemeProvider.tsx +65 -15
  148. package/src/theme/material.ts +39 -7
  149. package/src/theme/types.ts +8 -0
@@ -0,0 +1,261 @@
1
+ import { createContext, isValidElement, useContext, type ReactElement, type ReactNode } from "react"
2
+ import { Pressable, StyleSheet, View, type StyleProp, type ViewStyle } from "react-native"
3
+ import { flattenChildren } from "../../internal/children"
4
+ import { RowEndContext } from "../../internal/row"
5
+ import { useTheme } from "../../theme/ThemeProvider"
6
+ import { Button, buttonColors, type ButtonProps, type ControlSize } from "../Button/Button"
7
+ import { IconDefaultsProvider } from "../Icon/createIcon"
8
+ import { InputAdornmentButton, InputField, type InputProps } from "../Input/Input"
9
+ import { Text, type TextProps } from "../Text/Text"
10
+
11
+ type GroupState = { size: ControlSize; pill: boolean; disabled: boolean; invalid: boolean; row: boolean }
12
+
13
+ const GroupContext = createContext<GroupState | null>(null)
14
+
15
+ /** The size of a button in a group, a step under the field's (InputGroup.tsx). */
16
+ const BUTTON_SIZE: Record<ControlSize, ControlSize> = { "3xs": "3xs", "2xs": "3xs", xs: "3xs", sm: "3xs", md: "2xs", lg: "sm", xl: "md", "2xl": "lg", "3xl": "xl" }
17
+
18
+ export type InputGroupProps = {
19
+ /** @default "outline" */
20
+ variant?: "outline" | "soft"
21
+ /** @default "md" */
22
+ size?: ControlSize
23
+ /** A capsule. @default false */
24
+ pill?: boolean
25
+ /** @default false */
26
+ disabled?: boolean
27
+ /** @default false */
28
+ invalid?: boolean
29
+ /** One `InputGroup.Input` or `InputGroup.Textarea`, and `InputGroup.Addon`s around it. */
30
+ children: ReactNode
31
+ style?: StyleProp<ViewStyle>
32
+ testID?: string
33
+ }
34
+
35
+ export type InputGroupInputProps = Omit<InputProps, "variant" | "size" | "pill" | "startAdornment" | "endAdornment" | "multiline">
36
+ export type InputGroupTextareaProps = InputGroupInputProps & {
37
+ /** @default 3 */
38
+ rows?: number
39
+ autoResize?: boolean
40
+ maxRows?: number
41
+ }
42
+
43
+ export type InputGroupAddonAlign = "inline-start" | "inline-end" | "block-start" | "block-end"
44
+ export type InputGroupAddonProps = {
45
+ /**
46
+ * Where the addon sits: before or after the control on its line, or as a row above or below it (a Textarea's heading
47
+ * or counter). @default "inline-start"
48
+ */
49
+ align?: InputGroupAddonAlign
50
+ children: ReactNode
51
+ style?: StyleProp<ViewStyle>
52
+ }
53
+
54
+ export type InputGroupButtonProps = Omit<ButtonProps, "size"> & {
55
+ /** @default "secondary" */
56
+ color?: ButtonProps["color"]
57
+ }
58
+
59
+ export type InputGroupTextProps = TextProps
60
+
61
+ /** The control of a group: its props, read by the group (it is drawn by the group's field). */
62
+ function InputGroupInput(_props: InputGroupInputProps): ReactElement | null {
63
+ return null
64
+ }
65
+
66
+ function InputGroupTextarea(_props: InputGroupTextareaProps): ReactElement | null {
67
+ return null
68
+ }
69
+
70
+ /** Content beside, above or below the control: icons, text, buttons. */
71
+ function InputGroupAddon({ children, style }: InputGroupAddonProps) {
72
+ return <View style={[styles.addon, style]}>{children}</View>
73
+ }
74
+
75
+ /**
76
+ * A ghost Button sized from the group, a step under the field. An icon alone (`uniform`) is the field's adornment
77
+ * button: its 44pt (48dp) target around a 20pt (24dp) glyph in the field's icon gray.
78
+ */
79
+ function InputGroupButton({ color = "secondary", variant = "ghost", uniform = false, disabled, children, accessibilityLabel, onPress, style, ...rest }: InputGroupButtonProps) {
80
+ const group = useContext(GroupContext)
81
+ const theme = useTheme()
82
+ if (uniform && variant === "ghost" && group?.row && !theme.isAndroid) {
83
+ // In a row on iOS, as the web's on a phone: a 36pt square (the 44pt row control less 4 above and below) that ends
84
+ // at the row's inset, an 18pt symbol in the ghost button's color
85
+ const size = theme.length("--control-size-lg", 44) - 8
86
+ const off = disabled ?? group.disabled
87
+ return (
88
+ <Pressable
89
+ accessibilityRole="button"
90
+ accessibilityLabel={accessibilityLabel}
91
+ accessibilityState={{ disabled: off }}
92
+ disabled={off}
93
+ onPress={onPress ?? undefined}
94
+ style={({ pressed }) => [
95
+ styles.rowButton,
96
+ // It overhangs the row's line, as the web's, so the row keeps its 52
97
+ { width: size, height: size, marginVertical: (theme.length("--field-row-label-line-height", 22) - size) / 2, opacity: off || pressed ? 0.5 : 1 },
98
+ style,
99
+ ]}
100
+ >
101
+ <IconDefaultsProvider size={theme.length("--control-icon-size-md", 18)} color={buttonColors(theme, color, "ghost", false, false).text}>
102
+ {children}
103
+ </IconDefaultsProvider>
104
+ </Pressable>
105
+ )
106
+ }
107
+ if (uniform && variant === "ghost") {
108
+ return (
109
+ <InputAdornmentButton accessibilityLabel={accessibilityLabel ?? ""} disabled={disabled ?? group?.disabled} onPress={onPress ?? undefined} style={style}>
110
+ {children}
111
+ </InputAdornmentButton>
112
+ )
113
+ }
114
+ return (
115
+ <Button
116
+ {...rest}
117
+ color={color}
118
+ variant={variant}
119
+ uniform={uniform}
120
+ size={BUTTON_SIZE[group?.size ?? "md"]}
121
+ disabled={disabled ?? group?.disabled}
122
+ accessibilityLabel={accessibilityLabel}
123
+ onPress={onPress}
124
+ style={style}
125
+ >
126
+ {children}
127
+ </Button>
128
+ )
129
+ }
130
+
131
+ /** Plain text in an addon (a prefix, a unit, a counter): the field's type in the secondary label. */
132
+ function InputGroupText({ style, children, ...rest }: InputGroupTextProps) {
133
+ const theme = useTheme()
134
+ const group = useContext(GroupContext)
135
+ const type = theme.isAndroid
136
+ ? group?.row
137
+ ? styles.androidRowText
138
+ : styles.androidText
139
+ : { fontSize: theme.length("--field-row-label-font-size", 17), lineHeight: theme.length("--field-row-label-line-height", 22) }
140
+ return (
141
+ <Text {...rest} color={theme.colors.labelSecondary} numberOfLines={1} style={[type, { opacity: group?.disabled ? 0.5 : 1 }, style]}>
142
+ {children}
143
+ </Text>
144
+ )
145
+ }
146
+
147
+ type AddonElement = ReactElement<InputGroupAddonProps>
148
+
149
+ /**
150
+ * A field with addons around its control: Plex UI's InputGroup. The addons on its line are the field's adornments
151
+ * (an icon, a prefix, a unit, a button), in the frame of an Input of the same `variant`, `size` and `pill`; block
152
+ * addons stand as rows above and below the control inside one frame. In a List row (a `Field row`) the row is the
153
+ * frame, as the web's on a phone: a prefix sits right before the value in the secondary label, a unit right after it
154
+ * ("72 kg"), a button at the row's end.
155
+ */
156
+ export function InputGroup({ variant = "outline", size = "md", pill = false, disabled = false, invalid = false, children, style, testID }: InputGroupProps) {
157
+ const theme = useTheme()
158
+ const rowEnd = useContext(RowEndContext)
159
+ const row = rowEnd != null
160
+ const parts = flattenChildren(children).filter(isValidElement)
161
+ const control = parts.find((part) => part.type === InputGroupInput || part.type === InputGroupTextarea) as
162
+ | ReactElement<InputGroupTextareaProps>
163
+ | undefined
164
+ const addons = parts.filter((part) => part.type === InputGroupAddon) as AddonElement[]
165
+ const at = (align: InputGroupAddonAlign) => addons.filter((addon) => (addon.props.align ?? "inline-start") === align)
166
+ const inline = (align: "inline-start" | "inline-end") => {
167
+ const found = at(align)
168
+ return found.length === 0 ? undefined : <View style={styles.addons}>{found}</View>
169
+ }
170
+ const multiline = control?.type === InputGroupTextarea
171
+ const own = control?.props ?? {}
172
+ const state: GroupState = { size, pill, disabled, invalid, row }
173
+ const field = (props: Partial<InputProps> & { rows?: number; autoResize?: boolean; maxRows?: number; valueAtEnd?: boolean }) => (
174
+ <InputField
175
+ {...own}
176
+ disabled={own.disabled ?? disabled}
177
+ invalid={own.invalid ?? invalid}
178
+ size={size}
179
+ pill={pill}
180
+ multiline={multiline}
181
+ rows={multiline ? (own.rows ?? 3) : undefined}
182
+ {...props}
183
+ />
184
+ )
185
+ if (row) {
186
+ // The row is the frame: the prefix right before the value, the unit 8 after it (as the web's "5 km"), a button at
187
+ // the end
188
+ const start = inline("inline-start")
189
+ const end = inline("inline-end")
190
+ // A text prefix is part of the value ("$0.00", as iOS writes it); an icon keeps a gap before the value
191
+ const textPrefix = at("inline-start").every((addon) =>
192
+ flattenChildren(addon.props.children).every((child) => typeof child === "string" || (isValidElement(child) && child.type === InputGroupText)),
193
+ )
194
+ return (
195
+ <GroupContext.Provider value={state}>
196
+ <View testID={testID} style={[styles.inRow, style]}>
197
+ {start != null ? <View style={{ marginEnd: textPrefix ? 0 : theme.isAndroid ? 4 : 8 }}>{start}</View> : null}
198
+ {/* On Android a value before its unit stands at the row's end, as a value row's ("72 kg") */}
199
+ <View style={styles.grow}>{field({ variant: "ghost", style: theme.isAndroid ? styles.flush : undefined, valueAtEnd: theme.isAndroid && rowEnd.align !== "start" })}</View>
200
+ {end != null ? <View style={{ marginStart: theme.isAndroid ? 4 : 8 }}>{end}</View> : null}
201
+ </View>
202
+ </GroupContext.Provider>
203
+ )
204
+ }
205
+ const above = at("block-start")
206
+ const below = at("block-end")
207
+ if (above.length === 0 && below.length === 0) {
208
+ return (
209
+ <GroupContext.Provider value={state}>
210
+ {field({ variant, startAdornment: inline("inline-start"), endAdornment: inline("inline-end"), style, testID })}
211
+ </GroupContext.Provider>
212
+ )
213
+ }
214
+ // Block addons: rows above and below the control in one frame, the control bare between them
215
+ const radius = theme.isAndroid ? 8 : theme.length("--control-radius-lg", 10)
216
+ return (
217
+ <GroupContext.Provider value={state}>
218
+ <View
219
+ testID={testID}
220
+ style={[
221
+ styles.block,
222
+ {
223
+ borderRadius: pill ? 9999 : radius,
224
+ borderWidth: variant === "outline" ? StyleSheet.hairlineWidth * 2 : 0,
225
+ borderColor: invalid ? theme.color("--color-border-danger-outline", theme.colors.border) : theme.colors.border,
226
+ backgroundColor: variant === "soft" ? theme.color("--input-soft-background-color", theme.colors.surfaceSecondary) : undefined,
227
+ opacity: disabled ? 0.5 : 1,
228
+ },
229
+ style,
230
+ ]}
231
+ >
232
+ {above.length > 0 ? <View style={[styles.blockRow, styles.blockTop]}>{above}</View> : null}
233
+ {field({ variant: "ghost", startAdornment: inline("inline-start"), endAdornment: inline("inline-end") })}
234
+ {below.length > 0 ? <View style={[styles.blockRow, styles.blockBottom]}>{below}</View> : null}
235
+ </View>
236
+ </GroupContext.Provider>
237
+ )
238
+ }
239
+
240
+ InputGroup.Input = InputGroupInput
241
+ InputGroup.Textarea = InputGroupTextarea
242
+ InputGroup.Addon = InputGroupAddon
243
+ InputGroup.Button = InputGroupButton
244
+ InputGroup.Text = InputGroupText
245
+
246
+ export { InputGroupAddon, InputGroupButton, InputGroupInput, InputGroupText, InputGroupTextarea }
247
+
248
+ const styles = StyleSheet.create({
249
+ addon: { flexDirection: "row", alignItems: "center", gap: 8 },
250
+ addons: { flexDirection: "row", alignItems: "center", gap: 8 },
251
+ inRow: { flex: 1, minWidth: 0, flexDirection: "row", alignItems: "center" },
252
+ grow: { flex: 1, minWidth: 0 },
253
+ rowButton: { alignItems: "center", justifyContent: "center" },
254
+ flush: { paddingStart: 0, paddingEnd: 0 },
255
+ androidText: { fontSize: 16, lineHeight: 20 },
256
+ androidRowText: { fontSize: 16, lineHeight: 20 },
257
+ block: { alignSelf: "stretch", overflow: "hidden" },
258
+ blockRow: { paddingHorizontal: 12, flexDirection: "row", alignItems: "center", gap: 8 },
259
+ blockTop: { paddingTop: 10 },
260
+ blockBottom: { paddingBottom: 10 },
261
+ })