@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,227 @@
1
+ import { useContext, useRef, useState, type ComponentRef } from "react"
2
+ import { Pressable, StyleSheet, TextInput, View, type StyleProp, type TextInputKeyPressEvent, type ViewStyle } from "react-native"
3
+ import X from "../../icons/plex/X"
4
+ import { RowEndContext } from "../../internal/row"
5
+ import { dangerText, withAlpha } from "../../theme/material"
6
+ import { useTheme } from "../../theme/ThemeProvider"
7
+ import { Text } from "../Text/Text"
8
+
9
+ export type Tag = {
10
+ value: string
11
+ /** What the `validator` said when the tag was made. */
12
+ valid: boolean
13
+ }
14
+
15
+ export type TagInputProps = {
16
+ /** The tags it starts with, when it holds its own. */
17
+ defaultValue?: Tag[]
18
+ /** The tags, when the caller holds them (with `onChange`). */
19
+ value?: Tag[]
20
+ /** @default "xl" */
21
+ size?: "sm" | "md" | "lg" | "xl" | "2xl" | "3xl"
22
+ /** `ghost` has no frame (the value of a List row). @default "outline" */
23
+ variant?: "outline" | "ghost"
24
+ onChange?: (tags: Tag[]) => void
25
+ placeholder?: string
26
+ /** Judges each new tag: an invalid one stands in the danger color. Read only when a tag is made. */
27
+ validator?: (value: string) => boolean
28
+ /** The most tags it takes; the field goes at that count. */
29
+ maxTags?: number
30
+ /** @default false */
31
+ autoFocus?: boolean
32
+ /** The least height, in lines of tags. @default 1 */
33
+ rows?: number
34
+ /** The characters that end a tag as they are typed (and split a paste). @default [",", " "] */
35
+ delimiters?: string[]
36
+ disabled?: boolean
37
+ /** A capsule frame. @default false */
38
+ pill?: boolean
39
+ /** The field's name. */
40
+ accessibilityLabel?: string
41
+ style?: StyleProp<ViewStyle>
42
+ testID?: string
43
+ }
44
+
45
+ /** The tag sizes of the web's control table: the field's height, which a tag's line keeps. */
46
+ const HEIGHT: Record<NonNullable<TagInputProps["size"]>, number> = { sm: 28, md: 32, lg: 36, xl: 40, "2xl": 44, "3xl": 48 }
47
+
48
+ /**
49
+ * A field that turns what is typed into tags: Plex UI's TagInput. A delimiter (a comma, a space) or Return makes the
50
+ * text a tag; Backspace in an empty field takes the last one; each tag's × removes it. iOS: the web's phone tags, a
51
+ * 44pt line for each with a 32pt gray pill (`--color-background-secondary-soft-alpha`), its 17pt words 8 in and the ×
52
+ * in a 44pt target after them, 8 apart; an invalid tag in the danger color. Android: 32dp chips, 16 round, filled with
53
+ * the text color at 5%, their words 14sp, the × in a 32dp target, 8 apart. In a List row (`Field row`, vertical) it is
54
+ * the row's bare value; elsewhere it has the frame of an outlined field.
55
+ */
56
+ export function TagInput({
57
+ defaultValue,
58
+ value,
59
+ size = "xl",
60
+ variant = "outline",
61
+ onChange,
62
+ placeholder,
63
+ validator,
64
+ maxTags,
65
+ autoFocus = false,
66
+ rows = 1,
67
+ delimiters = [",", " "],
68
+ disabled = false,
69
+ pill = false,
70
+ accessibilityLabel,
71
+ style,
72
+ testID,
73
+ }: TagInputProps) {
74
+ const theme = useTheme()
75
+ const android = theme.isAndroid
76
+ const rowEnd = useContext(RowEndContext)
77
+ const bare = rowEnd != null || variant === "ghost"
78
+ const [own, setOwn] = useState<Tag[]>(defaultValue ?? [])
79
+ const tags = value ?? own
80
+ const [text, setText] = useState("")
81
+ const input = useRef<ComponentRef<typeof TextInput> | null>(null)
82
+ const set = (next: Tag[]) => {
83
+ if (value === undefined) setOwn(next)
84
+ onChange?.(next)
85
+ }
86
+ // New tags from words: trimmed, no repeats, up to `maxTags`, judged as they are made
87
+ const add = (words: string[]) => {
88
+ const next = [...tags]
89
+ for (const word of words) {
90
+ const trimmed = word.trim()
91
+ if (!trimmed || next.some((tag) => tag.value === trimmed)) continue
92
+ if (maxTags && next.length >= maxTags) break
93
+ next.push({ value: trimmed, valid: validator?.(trimmed) ?? true })
94
+ }
95
+ if (next.length !== tags.length) set(next)
96
+ }
97
+ const remove = (index: number) => set(tags.filter((_, at) => at !== index))
98
+ const onChangeText = (next: string) => {
99
+ if (disabled) return
100
+ // A delimiter typed or pasted ends the words before it
101
+ const pattern = new RegExp(`[${delimiters.map((d) => d.replace(/[-\\\]^]/g, "\\$&")).join("")}\n]`)
102
+ if (delimiters.length > 0 && pattern.test(next)) {
103
+ const parts = next.split(pattern)
104
+ add(parts.slice(0, -1))
105
+ setText(parts[parts.length - 1] ?? "")
106
+ return
107
+ }
108
+ setText(next)
109
+ }
110
+ const onKeyPress = (event: TextInputKeyPressEvent) => {
111
+ if (event.nativeEvent.key === "Backspace" && text === "" && tags.length > 0) remove(tags.length - 1)
112
+ }
113
+ const full = maxTags != null && tags.length >= maxTags
114
+ // iOS's tag: a 44pt line, the pill 6 inside it; Android's chip 32dp
115
+ const line = android ? 32 : bare ? theme.length("--control-size-lg", 44) : HEIGHT[size]
116
+ const inset = android ? 0 : bare ? 6 : 4
117
+ const type = android
118
+ ? { fontSize: 14, lineHeight: 18 }
119
+ : { fontSize: theme.length("--field-row-label-font-size", 17), lineHeight: theme.length("--field-row-label-line-height", 22) }
120
+ const fieldType = android ? { fontSize: 17, lineHeight: 20 } : type
121
+ const ink = theme.colors.text
122
+ const fill = android ? withAlpha(theme.colors.text, 0.05) : theme.color("--color-background-secondary-soft-alpha")
123
+ const badFill = android ? withAlpha(dangerText(theme), 0.1) : theme.color("--color-background-danger-soft-alpha", fill)
124
+ const badInk = android ? dangerText(theme) : theme.color("--color-text-danger")
125
+ const gap = 8
126
+ // Lines of tags 8 apart in a row, as the web's phone rows (2 in a frame)
127
+ const rowGap = android || bare ? gap : 2
128
+ // The field is as tall as its text: after the last tag it stands in the middle of the tag's line, under the tags a
129
+ // line of its own (28, the web's phone row)
130
+ const fieldLine = android ? 20 : bare ? 28 : line
131
+ // As wide as its text (or its hint) and a cursor gutter of 10, as the web's: it takes the rest of the last tag's
132
+ // line when that fits, else a line of its own under the tags
133
+ const [textWidth, setTextWidth] = useState(0)
134
+ const minHeight = rows > 1 ? rows * line + (rows - 1) * rowGap : undefined
135
+ const frame: ViewStyle | null = bare
136
+ ? null
137
+ : {
138
+ borderWidth: StyleSheet.hairlineWidth * 2,
139
+ borderColor: theme.colors.border,
140
+ borderRadius: pill ? 9999 : android ? 8 : theme.length("--control-radius-lg", 10),
141
+ paddingHorizontal: android ? 12 : 8,
142
+ paddingVertical: 4,
143
+ }
144
+ return (
145
+ <Pressable
146
+ testID={testID}
147
+ accessible={false}
148
+ disabled={disabled}
149
+ onPress={() => input.current?.focus()}
150
+ style={[
151
+ styles.box,
152
+ { columnGap: gap, rowGap, minHeight, opacity: disabled ? 0.5 : 1 },
153
+ // Tags are solid, so they stand 2 further from a label than a line of text (the web's ghost TagInput)
154
+ bare && !android && tags.length > 0 ? { marginVertical: 2 } : null,
155
+ frame,
156
+ style,
157
+ ]}
158
+ >
159
+ {full ? null : (
160
+ // A hidden copy of the text or the hint across the whole box, which sizes the field
161
+ <Text
162
+ accessible={false}
163
+ importantForAccessibility="no-hide-descendants"
164
+ numberOfLines={1}
165
+ onLayout={(event) => setTextWidth(Math.ceil(event.nativeEvent.layout.width))}
166
+ style={[fieldType, theme.font("regular"), styles.measure]}
167
+ >
168
+ {text || placeholder || ""}
169
+ </Text>
170
+ )}
171
+ {tags.map((tag, index) => {
172
+ const color = tag.valid ? ink : badInk
173
+ return (
174
+ <View key={tag.value} style={[styles.tag, { height: line, paddingStart: android ? 12 : 8 }]}>
175
+ <View pointerEvents="none" style={[StyleSheet.absoluteFill, { top: inset, bottom: inset, borderRadius: 9999, backgroundColor: tag.valid ? fill : badFill }]} />
176
+ <Text numberOfLines={1} color={color} style={[type, styles.shrink]}>
177
+ {tag.value}
178
+ </Text>
179
+ <Pressable
180
+ accessibilityRole="button"
181
+ accessibilityLabel={`Remove ${tag.value}`}
182
+ disabled={disabled}
183
+ hitSlop={android ? 8 : 0}
184
+ onPress={() => remove(index)}
185
+ style={({ pressed }) => [styles.remove, { width: android ? 32 : line, height: line, opacity: pressed ? 0.3 : 0.5, marginStart: android ? 0 : -4 }]}
186
+ >
187
+ <X size={android ? 18 : theme.length("--control-icon-size-sm", 16)} color={color} />
188
+ </Pressable>
189
+ </View>
190
+ )
191
+ })}
192
+ {full ? null : (
193
+ <View style={[styles.field, { height: fieldLine, minWidth: Math.max(20, textWidth) + 10 }]}>
194
+ <TextInput
195
+ ref={input}
196
+ value={text}
197
+ onChangeText={onChangeText}
198
+ onKeyPress={onKeyPress}
199
+ onSubmitEditing={() => {
200
+ add([text])
201
+ setText("")
202
+ }}
203
+ submitBehavior="submit"
204
+ autoFocus={autoFocus}
205
+ editable={!disabled}
206
+ placeholder={placeholder}
207
+ placeholderTextColor={theme.isAndroid ? theme.colors.textTertiary : theme.colors.labelTertiary}
208
+ accessibilityLabel={accessibilityLabel ?? placeholder}
209
+ autoCapitalize="none"
210
+ autoCorrect={false}
211
+ style={[styles.input, fieldType, theme.font("regular"), { color: ink, height: fieldLine }]}
212
+ />
213
+ </View>
214
+ )}
215
+ </Pressable>
216
+ )
217
+ }
218
+
219
+ const styles = StyleSheet.create({
220
+ box: { alignSelf: "stretch", flexDirection: "row", flexWrap: "wrap", alignItems: "center" },
221
+ tag: { flexDirection: "row", alignItems: "center", maxWidth: "100%", gap: 4 },
222
+ shrink: { flexShrink: 1 },
223
+ remove: { alignItems: "center", justifyContent: "center" },
224
+ field: { flexGrow: 1, flexBasis: 0, maxWidth: "100%", justifyContent: "center" },
225
+ measure: { position: "absolute", start: 0, top: 0, opacity: 0, alignSelf: "flex-start", pointerEvents: "none" },
226
+ input: { padding: 0, margin: 0, borderWidth: 0, outlineStyle: "none" } as never,
227
+ })
@@ -91,6 +91,7 @@ export function textStyle(
91
91
  base = style.weight
92
92
  }
93
93
  return {
94
+ ...WEB_SMOOTHING,
94
95
  fontSize,
95
96
  lineHeight,
96
97
  ...(mono ? { ...theme.monoFont, fontWeight: weight ? weightNumber(weight) : undefined } : theme.font(weight ?? base)),
@@ -108,11 +109,14 @@ function trackingFor(theme: Theme, style: StyleProp<TextStyle>, mono: boolean |
108
109
  return typeof flat?.fontSize === "number" && flat.letterSpacing === undefined ? { letterSpacing: theme.tracking(flat.fontSize) } : null
109
110
  }
110
111
 
111
- // On the web (react-native-web) the type is Inter's variable font, which the Plex UI tokens set at SF's own Medium and
112
- // Semibold strokes, 510 and 590 (touch.css); a device's system font takes the named weights
112
+ // On the web, Chromium and Firefox on a Mac draw text with subpixel smoothing, 11–20% heavier than an iPhone draws the
113
+ // same words; grayscale smoothing draws them within 1–2% of it
114
+ const WEB_SMOOTHING = (Platform.OS === "web" ? { WebkitFontSmoothing: "antialiased", MozOsxFontSmoothing: "grayscale" } : {}) as TextStyle
115
+
116
+ // A mono face's weights: the web's 501–549 of a system face draw as a synthesized bold in Chromium, so Medium is 500
113
117
  const weightNumber = (weight: FontWeightName) =>
114
118
  (Platform.OS === "web"
115
- ? { regular: "400", medium: "510", semibold: "590", bold: "700" } as Record<FontWeightName, string>
119
+ ? { regular: "400", medium: "500", semibold: "590", bold: "700" } as Record<FontWeightName, string>
116
120
  : { regular: "400", medium: "500", semibold: "600", bold: "700" })[weight] as TextStyle["fontWeight"]
117
121
 
118
122
  /**
@@ -154,7 +158,7 @@ export function Heading({ size = "md", weight = "semibold", color, align, mono,
154
158
  accessibilityRole="header"
155
159
  {...rest}
156
160
  style={[
157
- { fontSize, lineHeight },
161
+ { ...WEB_SMOOTHING, fontSize, lineHeight },
158
162
  mono ? { ...theme.monoFont, fontWeight: weightNumber(weight), letterSpacing: 0 } : { letterSpacing: theme.tracking(fontSize), ...theme.font(weight) },
159
163
  tabularNums ? { fontVariant: ["tabular-nums"] } : null,
160
164
  { color: textColor(theme, color ?? "primary") },
@@ -0,0 +1,77 @@
1
+ import { useState, type ReactNode } from "react"
2
+ import { Linking, Platform, Text as RNText, type GestureResponderEvent, type StyleProp, type TextStyle } from "react-native"
3
+ import { controlHighlight } from "../../theme/material"
4
+ import { useTheme } from "../../theme/ThemeProvider"
5
+ import type { FontWeightName } from "../../theme/types"
6
+
7
+ export type TextLinkProps = {
8
+ /** The link's text; an icon after it (an external link's arrow) stands on the text's line. */
9
+ children: ReactNode
10
+ /** Where the link goes: opened with `Linking`, a link of the page on the web. An http:// or https:// URL is external. */
11
+ href?: string
12
+ /** The primary link color in place of the text's own, with no underline unless `underline` asks for one. @default false */
13
+ primary?: boolean
14
+ /** Underlines the link. @default true, false for a `primary` link */
15
+ underline?: boolean
16
+ /** External link behavior (a new tab on the web) whatever the URL. Detected from the URL by default. */
17
+ forceExternal?: boolean
18
+ /** Called when the link is pressed, before it opens `href`; `event.preventDefault()` keeps it from opening. */
19
+ onPress?: (event: GestureResponderEvent) => void
20
+ /** The weight of the link's text; it takes the text's own around it by default (`--link-font-weight: inherit`). */
21
+ weight?: FontWeightName
22
+ accessibilityLabel?: string
23
+ testID?: string
24
+ style?: StyleProp<TextStyle>
25
+ }
26
+
27
+ const EXTERNAL = /^https?:\/\//
28
+
29
+ /**
30
+ * A link in running text, as @plexui/ui's TextLink: put it inside a `Text`, whose face, size and color it takes
31
+ * (the web's `currentcolor`), underlined; `primary` colors it with `--link-primary-text-color` and drops the underline.
32
+ * iOS highlights a pressed link as its text views do (a gray behind the text); Android and the web draw the press of a
33
+ * row in the Plex Android look (the text's ink at 11%, white at 5% at night). With `href` it is a `link` and opens the
34
+ * URL (an `<a>` on the web, a new tab for an external one); with only `onPress` it is a `button`.
35
+ */
36
+ export function TextLink({ children, href, primary = false, underline = !primary, forceExternal, onPress, weight, accessibilityLabel, testID, style }: TextLinkProps) {
37
+ const theme = useTheme()
38
+ const [pressed, setPressed] = useState(false)
39
+ const external = forceExternal ?? EXTERNAL.test(href ?? "")
40
+ const web = Platform.OS === "web"
41
+ const press = (event: GestureResponderEvent) => {
42
+ onPress?.(event)
43
+ if (!href || web || prevented(event)) return
44
+ void Linking.openURL(href).catch(() => {})
45
+ }
46
+ const actionable = href != null || onPress != null
47
+ // react-native-web draws a Text with `href` as an anchor: the browser opens it, a new tab for an external one
48
+ const anchor = web && href ? { href, hrefAttrs: external ? { target: "_blank", rel: "noopener noreferrer" } : undefined } : null
49
+ // iOS's own Text highlights a press (as UITextView's links); elsewhere the press layer of a row
50
+ const highlight = theme.isIOS && !web ? null : pressed ? { backgroundColor: controlHighlight(theme.scheme) } : null
51
+ return (
52
+ <RNText
53
+ {...anchor}
54
+ accessibilityRole={href ? "link" : onPress ? "button" : undefined}
55
+ accessibilityLabel={accessibilityLabel}
56
+ testID={testID}
57
+ onPress={actionable ? press : undefined}
58
+ onPressIn={actionable ? () => setPressed(true) : undefined}
59
+ onPressOut={actionable ? () => setPressed(false) : undefined}
60
+ style={[
61
+ primary ? { color: theme.color("--link-primary-text-color", theme.colors.textAccent) } : null,
62
+ underline ? { textDecorationLine: "underline" } : null,
63
+ weight ? theme.font(weight) : null,
64
+ highlight,
65
+ style,
66
+ ]}
67
+ >
68
+ {children}
69
+ </RNText>
70
+ )
71
+ }
72
+
73
+ /** A press the handler kept from going on (`event.preventDefault()`). */
74
+ function prevented(event: GestureResponderEvent) {
75
+ const synthetic = event as GestureResponderEvent & { isDefaultPrevented?: () => boolean; defaultPrevented?: boolean }
76
+ return synthetic.defaultPrevented === true || synthetic.isDefaultPrevented?.() === true
77
+ }
@@ -0,0 +1,23 @@
1
+ import { InputField, type InputProps } from "../Input/Input"
2
+
3
+ export type TextareaProps = Omit<InputProps, "multiline" | "onClear" | "startAdornment" | "endAdornment" | "pill" | "selectTextOnFocus"> & {
4
+ /** The lines it shows. @default 3 */
5
+ rows?: number
6
+ /** It grows with what is typed, from `rows` lines up to `maxRows`. @default false */
7
+ autoResize?: boolean
8
+ /** The most lines it grows to with `autoResize`, then it scrolls. @default Math.max(rows, 10) */
9
+ maxRows?: number
10
+ /** Selects all its text when it takes focus (TextInput's `selectTextOnFocus`). @default false */
11
+ autoSelect?: boolean
12
+ }
13
+
14
+ /**
15
+ * A text field of several lines: Plex UI's Textarea. It is the Input's field with `multiline` (the same variants, sizes
16
+ * and states, the same frames on both platforms), `rows` lines tall, its text from the top. In a List row (a `Field
17
+ * row`) it is the row's bare value: under its label, or alone, from the row's text start, as the web's on a phone.
18
+ * iOS: the field's 17/22 lines, 11 above and below them in a frame; Android: the outlined field's 17/20 lines, a
19
+ * label floating in its frame inside a Field.
20
+ */
21
+ export function Textarea({ rows = 3, autoResize = false, maxRows, autoSelect = false, ...rest }: TextareaProps) {
22
+ return <InputField {...rest} multiline rows={rows} autoResize={autoResize} maxRows={maxRows} selectTextOnFocus={autoSelect} />
23
+ }