@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.
- package/README.md +34 -0
- package/dist/es/components/ActionSheet/ActionSheet.js +53 -19
- package/dist/es/components/Alert/Alert.js +163 -0
- package/dist/es/components/Avatar/Avatar.js +20 -8
- package/dist/es/components/BottomActions/BottomActions.js +34 -0
- package/dist/es/components/BottomSheet/BottomSheet.js +85 -17
- package/dist/es/components/Button/Button.js +108 -28
- package/dist/es/components/Card/Card.js +16 -8
- package/dist/es/components/Checkbox/Checkbox.js +67 -99
- package/dist/es/components/Chip/Chip.js +16 -7
- package/dist/es/components/Dialog/Dialog.js +38 -24
- package/dist/es/components/Field/Field.js +91 -0
- package/dist/es/components/FloatingLabelInput/FloatingLabelInput.js +59 -0
- package/dist/es/components/Icon/createIcon.js +13 -2
- package/dist/es/components/Indicator/CircularProgress.js +80 -0
- package/dist/es/components/Indicator/LoadingDots.js +46 -0
- package/dist/es/components/Indicator/LoadingIndicator.js +101 -0
- package/dist/es/components/Indicator/index.js +3 -0
- package/dist/es/components/Input/Input.js +69 -60
- package/dist/es/components/InputGroup/InputGroup.js +130 -0
- package/dist/es/components/List/List.js +175 -59
- package/dist/es/components/Menu/Menu.js +69 -40
- package/dist/es/components/NavigationButton/NavigationButton.js +20 -4
- package/dist/es/components/OTPInput/OTPInput.js +9 -3
- package/dist/es/components/PageControl/PageControl.js +13 -7
- package/dist/es/components/Popover/Popover.js +128 -0
- package/dist/es/components/Progress/Progress.js +142 -0
- package/dist/es/components/ProgressSteps/ProgressSteps.js +207 -0
- package/dist/es/components/RollingNumber/RollingNumber.js +125 -0
- package/dist/es/components/Select/Select.js +97 -34
- package/dist/es/components/Separator/Separator.js +31 -0
- package/dist/es/components/ShimmerText/ShimmerText.js +98 -0
- package/dist/es/components/Stepper/Stepper.js +219 -0
- package/dist/es/components/Switch/Switch.js +26 -12
- package/dist/es/components/TagInput/TagInput.js +121 -0
- package/dist/es/components/Text/Text.js +7 -4
- package/dist/es/components/TextLink/TextLink.js +42 -0
- package/dist/es/components/Textarea/Textarea.js +12 -0
- package/dist/es/components/Tip/Tip.js +193 -0
- package/dist/es/components/Toolbar/Toolbar.js +6 -2
- package/dist/es/components/Tooltip/Tooltip.js +272 -0
- package/dist/es/index.js +20 -2
- package/dist/es/internal/FloatingPanel.js +111 -0
- package/dist/es/internal/fieldStack.js +73 -0
- package/dist/es/internal/floating.js +97 -0
- package/dist/es/internal/ripple.js +119 -0
- package/dist/es/internal/row.js +2 -1
- package/dist/es/internal/transition.js +113 -0
- package/dist/es/theme/ThemeProvider.js +41 -9
- package/dist/es/theme/material.js +37 -7
- package/dist/types/components/ActionSheet/ActionSheet.d.ts +15 -7
- package/dist/types/components/Alert/Alert.d.ts +51 -0
- package/dist/types/components/Avatar/Avatar.d.ts +4 -2
- package/dist/types/components/BottomActions/BottomActions.d.ts +18 -0
- package/dist/types/components/BottomSheet/BottomSheet.d.ts +4 -2
- package/dist/types/components/Button/Button.d.ts +20 -5
- package/dist/types/components/Card/Card.d.ts +14 -1
- package/dist/types/components/Checkbox/Checkbox.d.ts +4 -3
- package/dist/types/components/Chip/Chip.d.ts +12 -1
- package/dist/types/components/Dialog/Dialog.d.ts +9 -5
- package/dist/types/components/Field/Field.d.ts +64 -0
- package/dist/types/components/FloatingLabelInput/FloatingLabelInput.d.ts +42 -0
- package/dist/types/components/Indicator/CircularProgress.d.ts +34 -0
- package/dist/types/components/Indicator/LoadingDots.d.ts +17 -0
- package/dist/types/components/Indicator/LoadingIndicator.d.ts +46 -0
- package/dist/types/components/Indicator/index.d.ts +3 -0
- package/dist/types/components/Input/Input.d.ts +13 -3
- package/dist/types/components/InputGroup/InputGroup.d.ts +71 -0
- package/dist/types/components/List/List.d.ts +57 -14
- package/dist/types/components/Menu/Menu.d.ts +4 -0
- package/dist/types/components/NavigationButton/NavigationButton.d.ts +11 -3
- package/dist/types/components/OTPInput/OTPInput.d.ts +10 -1
- package/dist/types/components/PageControl/PageControl.d.ts +11 -1
- package/dist/types/components/Popover/Popover.d.ts +86 -0
- package/dist/types/components/Progress/Progress.d.ts +56 -0
- package/dist/types/components/ProgressSteps/ProgressSteps.d.ts +61 -0
- package/dist/types/components/RollingNumber/RollingNumber.d.ts +36 -0
- package/dist/types/components/Select/Select.d.ts +36 -8
- package/dist/types/components/Separator/Separator.d.ts +19 -0
- package/dist/types/components/ShimmerText/ShimmerText.d.ts +28 -0
- package/dist/types/components/Stepper/Stepper.d.ts +61 -0
- package/dist/types/components/Switch/Switch.d.ts +5 -5
- package/dist/types/components/TagInput/TagInput.d.ts +44 -0
- package/dist/types/components/TextLink/TextLink.d.ts +30 -0
- package/dist/types/components/Textarea/Textarea.d.ts +19 -0
- package/dist/types/components/Tip/Tip.d.ts +71 -0
- package/dist/types/components/Toolbar/Toolbar.d.ts +9 -1
- package/dist/types/components/Tooltip/Tooltip.d.ts +84 -0
- package/dist/types/index.d.ts +20 -2
- package/dist/types/internal/FloatingPanel.d.ts +70 -0
- package/dist/types/internal/fieldStack.d.ts +48 -0
- package/dist/types/internal/floating.d.ts +71 -0
- package/dist/types/internal/ripple.d.ts +17 -0
- package/dist/types/internal/row.d.ts +15 -3
- package/dist/types/internal/transition.d.ts +37 -0
- package/dist/types/theme/ThemeProvider.d.ts +28 -4
- package/dist/types/theme/material.d.ts +20 -6
- package/dist/types/theme/types.d.ts +8 -0
- package/package.json +2 -2
- package/src/components/ActionSheet/ActionSheet.tsx +107 -38
- package/src/components/Alert/Alert.tsx +279 -0
- package/src/components/Avatar/Avatar.tsx +21 -9
- package/src/components/BottomActions/BottomActions.tsx +54 -0
- package/src/components/BottomSheet/BottomSheet.tsx +111 -25
- package/src/components/Button/Button.tsx +170 -35
- package/src/components/Card/Card.tsx +33 -9
- package/src/components/Checkbox/Checkbox.tsx +89 -124
- package/src/components/Chip/Chip.tsx +49 -6
- package/src/components/Dialog/Dialog.tsx +68 -37
- package/src/components/Field/Field.tsx +227 -0
- package/src/components/FloatingLabelInput/FloatingLabelInput.tsx +144 -0
- package/src/components/Icon/createIcon.tsx +16 -6
- package/src/components/Indicator/CircularProgress.tsx +141 -0
- package/src/components/Indicator/LoadingDots.tsx +79 -0
- package/src/components/Indicator/LoadingIndicator.tsx +166 -0
- package/src/components/Indicator/index.ts +3 -0
- package/src/components/Input/Input.tsx +126 -97
- package/src/components/InputGroup/InputGroup.tsx +261 -0
- package/src/components/List/List.tsx +345 -88
- package/src/components/Menu/Menu.tsx +83 -41
- package/src/components/NavigationButton/NavigationButton.tsx +35 -5
- package/src/components/OTPInput/OTPInput.tsx +21 -2
- package/src/components/PageControl/PageControl.tsx +36 -8
- package/src/components/Popover/Popover.tsx +261 -0
- package/src/components/Progress/Progress.tsx +255 -0
- package/src/components/ProgressSteps/ProgressSteps.tsx +415 -0
- package/src/components/RollingNumber/RollingNumber.tsx +189 -0
- package/src/components/Select/Select.tsx +175 -71
- package/src/components/Separator/Separator.tsx +51 -0
- package/src/components/ShimmerText/ShimmerText.tsx +144 -0
- package/src/components/Stepper/Stepper.tsx +386 -0
- package/src/components/Switch/Switch.tsx +26 -12
- package/src/components/TagInput/TagInput.tsx +227 -0
- package/src/components/Text/Text.tsx +8 -4
- package/src/components/TextLink/TextLink.tsx +77 -0
- package/src/components/Textarea/Textarea.tsx +23 -0
- package/src/components/Tip/Tip.tsx +410 -0
- package/src/components/Toolbar/Toolbar.tsx +27 -2
- package/src/components/Tooltip/Tooltip.tsx +478 -0
- package/src/index.ts +36 -2
- package/src/internal/FloatingPanel.tsx +199 -0
- package/src/internal/fieldStack.tsx +179 -0
- package/src/internal/floating.ts +131 -0
- package/src/internal/ripple.tsx +132 -0
- package/src/internal/row.ts +16 -3
- package/src/internal/transition.ts +124 -0
- package/src/theme/ThemeProvider.tsx +65 -15
- package/src/theme/material.ts +39 -7
- package/src/theme/types.ts +8 -0
|
@@ -0,0 +1,478 @@
|
|
|
1
|
+
import { cloneElement, createContext, isValidElement, useContext, useEffect, useState, type ReactElement, type ReactNode } from "react"
|
|
2
|
+
import { NativeModules, Platform, Text as RNText, StyleSheet, View, type GestureResponderEvent, type StyleProp, type ViewStyle } from "react-native"
|
|
3
|
+
import CheckMd from "../../icons/plex/CheckMd"
|
|
4
|
+
import Copy from "../../icons/plex/Copy"
|
|
5
|
+
import { useDescription } from "../../internal/a11y"
|
|
6
|
+
import { FloatingPanel } from "../../internal/FloatingPanel"
|
|
7
|
+
import { anchorProps, type FloatingAlign, type FloatingSide } from "../../internal/floating"
|
|
8
|
+
import { elevationShadow } from "../../theme/material"
|
|
9
|
+
import { useTheme } from "../../theme/ThemeProvider"
|
|
10
|
+
import type { Theme } from "../../theme/types"
|
|
11
|
+
import { IconDefaultsProvider } from "../Icon/createIcon"
|
|
12
|
+
import { useMenuAnchor } from "../Menu/Menu"
|
|
13
|
+
import { Text, type TextProps } from "../Text/Text"
|
|
14
|
+
|
|
15
|
+
export type TooltipGutterSize = "sm" | "md" | "lg"
|
|
16
|
+
|
|
17
|
+
type TooltipPlacementProps = {
|
|
18
|
+
/** The preferred side of the trigger; it turns when there is no room. @default "top" */
|
|
19
|
+
side?: FloatingSide
|
|
20
|
+
/** The preferred alignment against the trigger. @default "center" */
|
|
21
|
+
align?: FloatingAlign
|
|
22
|
+
/** An offset from the `start` or `end` alignment. @default 0 */
|
|
23
|
+
alignOffset?: number
|
|
24
|
+
/** The distance from the trigger. @default 5 */
|
|
25
|
+
sideOffset?: number
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export type TooltipProps = TooltipPlacementProps & {
|
|
29
|
+
/** The trigger: a single element. Wrap plain text in `Tooltip.TriggerDecorator`. */
|
|
30
|
+
children: ReactNode
|
|
31
|
+
/** The tooltip's content; `null` shows no tooltip. */
|
|
32
|
+
content: ReactNode
|
|
33
|
+
/** The tooltip's max width; `"none"` keeps it on one line at its natural width. @default 300 */
|
|
34
|
+
maxWidth?: number | "none"
|
|
35
|
+
/** Keeps the tooltip open (`true`) or closed (`false`). */
|
|
36
|
+
forceOpen?: boolean
|
|
37
|
+
/** Short tooltips of one to three words, in inverted colors. @default false */
|
|
38
|
+
compact?: boolean
|
|
39
|
+
/** The padding inside the tooltip. @default "md" */
|
|
40
|
+
gutterSize?: TooltipGutterSize
|
|
41
|
+
/** The style of the tooltip's panel. */
|
|
42
|
+
contentStyle?: StyleProp<ViewStyle>
|
|
43
|
+
testID?: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
type TooltipContextValue = { open: boolean; show: () => void }
|
|
47
|
+
const TooltipContext = createContext<TooltipContextValue | null>(null)
|
|
48
|
+
|
|
49
|
+
/** How long a tooltip opened by a long press stays: Material's 1500ms. */
|
|
50
|
+
const SHOW_FOR = 1500
|
|
51
|
+
|
|
52
|
+
const GUTTERS: Record<TooltipGutterSize, { vertical: number; horizontal: number }> = {
|
|
53
|
+
sm: { vertical: 8, horizontal: 12 },
|
|
54
|
+
md: { vertical: 12, horizontal: 16 },
|
|
55
|
+
lg: { vertical: 14, horizontal: 18 },
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Brief text that explains a control, as @plexui/ui's Tooltip. A phone has no hover: a long press on the trigger
|
|
60
|
+
* shows it for 1.5 seconds, as Android shows a tooltip, and a tap anywhere hides it; `forceOpen` keeps it shown. A
|
|
61
|
+
* screen reader reads the content as the trigger's description. On iOS (which has no tooltips) and the web it is the
|
|
62
|
+
* web's tooltip (the elevated surface with its shadow, `--radius-md`, 14/20 text; `compact` inverted, 2 by 8); on
|
|
63
|
+
* Android Material 3's tooltips: `compact` the plain tooltip (inverse surface, Body S, 4dp corners), otherwise the
|
|
64
|
+
* rich tooltip's surface (12dp corners, Body M, level 2 shadow). A disabled trigger shows its tooltip too.
|
|
65
|
+
*/
|
|
66
|
+
export function Tooltip({
|
|
67
|
+
children,
|
|
68
|
+
content,
|
|
69
|
+
maxWidth = 300,
|
|
70
|
+
forceOpen,
|
|
71
|
+
compact = false,
|
|
72
|
+
side = "top",
|
|
73
|
+
align = "center",
|
|
74
|
+
alignOffset = 0,
|
|
75
|
+
sideOffset = 5,
|
|
76
|
+
gutterSize = "md",
|
|
77
|
+
contentStyle,
|
|
78
|
+
testID,
|
|
79
|
+
}: TooltipProps) {
|
|
80
|
+
const enabled = content !== null
|
|
81
|
+
const [visible, setVisible] = useState(false)
|
|
82
|
+
const open = enabled && (forceOpen ?? visible)
|
|
83
|
+
const { anchor, place, setTrigger } = useMenuAnchor(open)
|
|
84
|
+
const show = () => {
|
|
85
|
+
if (!enabled || forceOpen !== undefined) return
|
|
86
|
+
place(() => setVisible(true))
|
|
87
|
+
}
|
|
88
|
+
// A long press shows it for a while; a tap anywhere hides it sooner
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
if (!visible || forceOpen !== undefined) return
|
|
91
|
+
const timer = setTimeout(() => setVisible(false), SHOW_FOR)
|
|
92
|
+
return () => clearTimeout(timer)
|
|
93
|
+
}, [visible, forceOpen])
|
|
94
|
+
const description = useDescription(enabled ? content : null)
|
|
95
|
+
const [touch] = useState(() => new LongTouch())
|
|
96
|
+
useEffect(() => () => touch.cancel(), [touch])
|
|
97
|
+
const first = Array.isArray(children) ? children[0] : children
|
|
98
|
+
// Plain text is a decorated trigger
|
|
99
|
+
const child: ReactNode = typeof first === "string" || typeof first === "number" ? <TriggerDecorator>{first}</TriggerDecorator> : first
|
|
100
|
+
const trigger = isValidElement(child)
|
|
101
|
+
? cloneElement(child as ReactElement<TriggerChildProps>, triggerProps(child as ReactElement<TriggerChildProps>, show, touch, description.props, anchorProps((child as ReactElement<TriggerChildProps>).props, setTrigger as never, open ? () => place() : undefined)))
|
|
102
|
+
: child
|
|
103
|
+
return (
|
|
104
|
+
<TooltipContext.Provider value={{ open, show }}>
|
|
105
|
+
{trigger}
|
|
106
|
+
{enabled && Platform.OS === "web" && description.id ? (
|
|
107
|
+
// The web's description: the trigger points at it with aria-describedby
|
|
108
|
+
<RNText nativeID={description.id} style={styles.hidden}>
|
|
109
|
+
{textContent(content)}
|
|
110
|
+
</RNText>
|
|
111
|
+
) : null}
|
|
112
|
+
{enabled ? (
|
|
113
|
+
<TooltipPanel
|
|
114
|
+
open={open}
|
|
115
|
+
onDismiss={() => setVisible(false)}
|
|
116
|
+
anchor={anchor}
|
|
117
|
+
side={side}
|
|
118
|
+
align={align}
|
|
119
|
+
alignOffset={alignOffset}
|
|
120
|
+
sideOffset={sideOffset}
|
|
121
|
+
compact={compact}
|
|
122
|
+
maxWidth={maxWidth}
|
|
123
|
+
gutterSize={gutterSize}
|
|
124
|
+
style={contentStyle}
|
|
125
|
+
testID={testID}
|
|
126
|
+
>
|
|
127
|
+
{content}
|
|
128
|
+
</TooltipPanel>
|
|
129
|
+
) : null}
|
|
130
|
+
</TooltipContext.Provider>
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
Tooltip.displayName = "Tooltip"
|
|
134
|
+
|
|
135
|
+
type TriggerChildProps = {
|
|
136
|
+
onLongPress?: (event: GestureResponderEvent) => void
|
|
137
|
+
onTouchStart?: (event: GestureResponderEvent) => void
|
|
138
|
+
onTouchEnd?: (event: GestureResponderEvent) => void
|
|
139
|
+
onTouchCancel?: (event: GestureResponderEvent) => void
|
|
140
|
+
onTouchMove?: (event: GestureResponderEvent) => void
|
|
141
|
+
disabled?: boolean | null
|
|
142
|
+
ref?: unknown
|
|
143
|
+
onLayout?: (event: never) => void
|
|
144
|
+
}
|
|
145
|
+
type DescribedProps = { accessibilityHint?: string; "aria-describedby"?: string }
|
|
146
|
+
|
|
147
|
+
/** A press held for 500ms, as React Native's long press: a disabled control's own touches, which it does not take. */
|
|
148
|
+
class LongTouch {
|
|
149
|
+
private timer: ReturnType<typeof setTimeout> | undefined
|
|
150
|
+
start(run: () => void) {
|
|
151
|
+
clearTimeout(this.timer)
|
|
152
|
+
this.timer = setTimeout(run, LONG_PRESS)
|
|
153
|
+
}
|
|
154
|
+
cancel() {
|
|
155
|
+
clearTimeout(this.timer)
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
const LONG_PRESS = 500
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* The trigger's props: the tooltip as its description, the long press that shows it after its own, and its node and
|
|
163
|
+
* layout as the tooltip's anchor. A disabled control takes no press, so its touches show the tooltip.
|
|
164
|
+
*/
|
|
165
|
+
function triggerProps(child: ReactElement<TriggerChildProps>, show: () => void, touch: LongTouch, described: DescribedProps, anchor: object): Partial<TriggerChildProps> {
|
|
166
|
+
const own = child.props
|
|
167
|
+
const disabled = own.disabled === true
|
|
168
|
+
return {
|
|
169
|
+
...described,
|
|
170
|
+
...anchor,
|
|
171
|
+
onLongPress: (event: GestureResponderEvent) => {
|
|
172
|
+
own.onLongPress?.(event)
|
|
173
|
+
show()
|
|
174
|
+
},
|
|
175
|
+
...(disabled
|
|
176
|
+
? {
|
|
177
|
+
onTouchStart: (event: GestureResponderEvent) => {
|
|
178
|
+
own.onTouchStart?.(event)
|
|
179
|
+
touch.start(show)
|
|
180
|
+
},
|
|
181
|
+
onTouchEnd: (event: GestureResponderEvent) => {
|
|
182
|
+
own.onTouchEnd?.(event)
|
|
183
|
+
touch.cancel()
|
|
184
|
+
},
|
|
185
|
+
onTouchCancel: (event: GestureResponderEvent) => {
|
|
186
|
+
own.onTouchCancel?.(event)
|
|
187
|
+
touch.cancel()
|
|
188
|
+
},
|
|
189
|
+
onTouchMove: (event: GestureResponderEvent) => {
|
|
190
|
+
own.onTouchMove?.(event)
|
|
191
|
+
touch.cancel()
|
|
192
|
+
},
|
|
193
|
+
}
|
|
194
|
+
: null),
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const textContent = (node: ReactNode): string =>
|
|
199
|
+
node == null || typeof node === "boolean" ? "" : typeof node === "string" || typeof node === "number" ? String(node) : Array.isArray(node) ? node.map(textContent).join("") : isValidElement<{ children?: ReactNode }>(node) ? textContent(node.props.children) : ""
|
|
200
|
+
|
|
201
|
+
type TooltipPanelProps = Required<TooltipPlacementProps> & {
|
|
202
|
+
open: boolean
|
|
203
|
+
onDismiss: () => void
|
|
204
|
+
anchor: Parameters<typeof FloatingPanel>[0]["anchor"]
|
|
205
|
+
compact: boolean
|
|
206
|
+
maxWidth: number | "none"
|
|
207
|
+
gutterSize: TooltipGutterSize
|
|
208
|
+
style?: StyleProp<ViewStyle>
|
|
209
|
+
testID?: string
|
|
210
|
+
children: ReactNode
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
/** The colors and shape of a tooltip on each platform. */
|
|
214
|
+
function tooltipLook(theme: Theme, compact: boolean, gutterSize: TooltipGutterSize) {
|
|
215
|
+
const m = theme.material
|
|
216
|
+
if (theme.isAndroid) {
|
|
217
|
+
return compact
|
|
218
|
+
? // Material 3's plain tooltip
|
|
219
|
+
{ background: m.inverseSurface, text: m.inverseOnSurface, radius: 4, padding: { vertical: 4, horizontal: 8 }, minHeight: 24, shadow: undefined, maxWidth: 200, variant: "caption1" as const, weight: "regular" as const }
|
|
220
|
+
: // Material 3's rich tooltip: its supporting text on its container
|
|
221
|
+
{ background: m.surfaceContainer, text: m.onSurfaceVariant, radius: 12, padding: { vertical: 12, horizontal: 16 }, minHeight: 0, shadow: elevationShadow.level2, maxWidth: 320, variant: "subheadline" as const, weight: undefined }
|
|
222
|
+
}
|
|
223
|
+
const shadow = [theme.token("--shadow"), theme.token("--shadow-hairline")].filter((part) => typeof part === "string").join(", ")
|
|
224
|
+
return compact
|
|
225
|
+
? { background: theme.color("--gray-700"), text: theme.color("--gray-0"), radius: theme.length("--radius-md", 8), padding: { vertical: 2, horizontal: 8 }, minHeight: 0, shadow, maxWidth: undefined, variant: undefined, weight: undefined }
|
|
226
|
+
: { background: theme.color("--color-surface-elevated", theme.colors.surfaceElevated), text: theme.colors.text, radius: theme.length("--radius-md", 8), padding: GUTTERS[gutterSize], minHeight: 0, shadow, maxWidth: undefined, variant: undefined, weight: undefined }
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function TooltipPanel({ open, onDismiss, anchor, side, align, alignOffset, sideOffset, compact, maxWidth, gutterSize, style, testID, children }: TooltipPanelProps) {
|
|
230
|
+
const theme = useTheme()
|
|
231
|
+
const look = tooltipLook(theme, compact, gutterSize)
|
|
232
|
+
// Material's tooltips stand 4dp from their anchor
|
|
233
|
+
const offset = theme.isAndroid ? Math.min(sideOffset, 4) : sideOffset
|
|
234
|
+
const width: ViewStyle = maxWidth === "none" ? {} : { maxWidth: look.maxWidth != null ? Math.min(maxWidth, look.maxWidth) : maxWidth }
|
|
235
|
+
return (
|
|
236
|
+
<FloatingPanel
|
|
237
|
+
open={open}
|
|
238
|
+
onDismiss={onDismiss}
|
|
239
|
+
anchor={anchor}
|
|
240
|
+
side={side}
|
|
241
|
+
align={align}
|
|
242
|
+
alignOffset={alignOffset}
|
|
243
|
+
sideOffset={offset}
|
|
244
|
+
collisionPadding={15}
|
|
245
|
+
motion="tooltip"
|
|
246
|
+
passThrough
|
|
247
|
+
autoFocus={false}
|
|
248
|
+
role="tooltip"
|
|
249
|
+
testID={testID}
|
|
250
|
+
style={width}
|
|
251
|
+
>
|
|
252
|
+
{() => (
|
|
253
|
+
<View
|
|
254
|
+
style={[
|
|
255
|
+
styles.panel,
|
|
256
|
+
{
|
|
257
|
+
backgroundColor: look.background,
|
|
258
|
+
borderRadius: look.radius,
|
|
259
|
+
paddingVertical: look.padding.vertical,
|
|
260
|
+
paddingHorizontal: look.padding.horizontal,
|
|
261
|
+
minHeight: look.minHeight,
|
|
262
|
+
boxShadow: look.shadow,
|
|
263
|
+
},
|
|
264
|
+
style,
|
|
265
|
+
]}
|
|
266
|
+
>
|
|
267
|
+
<IconDefaultsProvider size={theme.isAndroid ? 16 : 18} color={look.text}>
|
|
268
|
+
{typeof children === "string" || typeof children === "number" ? (
|
|
269
|
+
<Text variant={look.variant} size={look.variant ? undefined : "sm"} weight={look.weight} color={look.text} numberOfLines={maxWidth === "none" ? 1 : undefined}>
|
|
270
|
+
{children}
|
|
271
|
+
</Text>
|
|
272
|
+
) : (
|
|
273
|
+
children
|
|
274
|
+
)}
|
|
275
|
+
</IconDefaultsProvider>
|
|
276
|
+
</View>
|
|
277
|
+
)}
|
|
278
|
+
</FloatingPanel>
|
|
279
|
+
)
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export type TriggerDecoratorProps = Pick<TextProps, "variant" | "size" | "weight" | "color" | "style"> & {
|
|
283
|
+
/** Text that the tooltip explains. */
|
|
284
|
+
children: ReactNode
|
|
285
|
+
/** Makes the text a stop of the keyboard (the web). @default true */
|
|
286
|
+
focusable?: boolean
|
|
287
|
+
testID?: string
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Makes text a tooltip's trigger, as @plexui/ui's Tooltip.TriggerDecorator: a tap or a long press shows the tooltip,
|
|
292
|
+
* and the text gets the dotted underline of an open tooltip (the tertiary text color; Android draws it solid).
|
|
293
|
+
*/
|
|
294
|
+
export function TriggerDecorator({ children, focusable = true, testID, variant, size, weight, color, style, ...described }: TriggerDecoratorProps & DescribedProps) {
|
|
295
|
+
const theme = useTheme()
|
|
296
|
+
const tooltip = useContext(TooltipContext)
|
|
297
|
+
const open = tooltip?.open ?? false
|
|
298
|
+
return (
|
|
299
|
+
<Text
|
|
300
|
+
{...described}
|
|
301
|
+
// A text of its own: it takes the type the web's decorator inherits from the text around it
|
|
302
|
+
variant={variant}
|
|
303
|
+
size={size}
|
|
304
|
+
weight={weight}
|
|
305
|
+
color={color}
|
|
306
|
+
accessibilityRole="text"
|
|
307
|
+
onPress={tooltip?.show}
|
|
308
|
+
onLongPress={tooltip?.show}
|
|
309
|
+
suppressHighlighting
|
|
310
|
+
// A stop of the web's keyboard, as the web's decorator (tabindex 0)
|
|
311
|
+
{...((Platform.OS === "web" && focusable ? { tabIndex: 0 } : null) as object)}
|
|
312
|
+
testID={testID}
|
|
313
|
+
// The web's underline is there in a transparent color until the tooltip opens; Android draws no colored or
|
|
314
|
+
// dotted line, so the line itself comes and goes
|
|
315
|
+
style={[style, open ? [styles.decorator, { textDecorationColor: theme.color("--color-text-tertiary") }] : null]}
|
|
316
|
+
>
|
|
317
|
+
{children}
|
|
318
|
+
</Text>
|
|
319
|
+
)
|
|
320
|
+
}
|
|
321
|
+
TriggerDecorator.displayName = "Tooltip.TriggerDecorator"
|
|
322
|
+
|
|
323
|
+
Tooltip.TriggerDecorator = TriggerDecorator
|
|
324
|
+
|
|
325
|
+
export type CopyTooltipProps = TooltipPlacementProps & {
|
|
326
|
+
/** The trigger element (a Button, or text in `Tooltip.TriggerDecorator`). */
|
|
327
|
+
children: ReactNode
|
|
328
|
+
/** The text copied to the clipboard. */
|
|
329
|
+
copyValue: string
|
|
330
|
+
/** Called once the clipboard write settles, with whether it succeeded; Copied! shows only after a successful write. */
|
|
331
|
+
onCopy?: (copied: boolean) => void
|
|
332
|
+
/**
|
|
333
|
+
* Writes the text to the clipboard, in place of the default: the web's Clipboard API, React Native's clipboard
|
|
334
|
+
* module elsewhere. Pass one that uses your app's clipboard library (`expo-clipboard`'s `setStringAsync`).
|
|
335
|
+
*/
|
|
336
|
+
copy?: (value: string) => Promise<boolean | void> | boolean | void
|
|
337
|
+
testID?: string
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
/**
|
|
341
|
+
* The pending feedback of a CopyTooltip: its timer, and the copy it belongs to. A newer copy, a long press or a close
|
|
342
|
+
* drops an older one's.
|
|
343
|
+
*/
|
|
344
|
+
class Feedback {
|
|
345
|
+
mounted = true
|
|
346
|
+
private generation = 0
|
|
347
|
+
private timer: ReturnType<typeof setTimeout> | undefined
|
|
348
|
+
/** Starts a new attempt and cancels the pending one. */
|
|
349
|
+
next() {
|
|
350
|
+
this.generation += 1
|
|
351
|
+
clearTimeout(this.timer)
|
|
352
|
+
return this.generation
|
|
353
|
+
}
|
|
354
|
+
current(generation: number) {
|
|
355
|
+
return generation === this.generation
|
|
356
|
+
}
|
|
357
|
+
after(ms: number, run: () => void) {
|
|
358
|
+
clearTimeout(this.timer)
|
|
359
|
+
this.timer = setTimeout(run, ms)
|
|
360
|
+
}
|
|
361
|
+
mount() {
|
|
362
|
+
this.mounted = true
|
|
363
|
+
return () => {
|
|
364
|
+
this.mounted = false
|
|
365
|
+
clearTimeout(this.timer)
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
/** Copied! stays for a second, as on the web. */
|
|
371
|
+
const COPIED_FOR = 1000
|
|
372
|
+
|
|
373
|
+
/**
|
|
374
|
+
* A trigger that copies a value, as @plexui/ui's CopyTooltip on a phone: a tap copies it and says Copied! with a check
|
|
375
|
+
* in a compact tooltip for a second; a long press shows Copy.
|
|
376
|
+
*/
|
|
377
|
+
export function CopyTooltip({ children, copyValue, onCopy, copy = writeClipboard, side = "top", align = "center", alignOffset = 0, sideOffset = 5, testID }: CopyTooltipProps) {
|
|
378
|
+
const [open, setOpen] = useState(false)
|
|
379
|
+
const [copied, setCopied] = useState(false)
|
|
380
|
+
const { anchor, place, setTrigger } = useMenuAnchor(open)
|
|
381
|
+
const [feedback] = useState(() => new Feedback())
|
|
382
|
+
useEffect(() => feedback.mount(), [feedback])
|
|
383
|
+
const hide = () => {
|
|
384
|
+
feedback.next()
|
|
385
|
+
setOpen(false)
|
|
386
|
+
}
|
|
387
|
+
const run = async () => {
|
|
388
|
+
const own = feedback.next()
|
|
389
|
+
setCopied(false)
|
|
390
|
+
let succeeded = false
|
|
391
|
+
try {
|
|
392
|
+
succeeded = (await copy(copyValue)) !== false
|
|
393
|
+
} catch {
|
|
394
|
+
succeeded = false
|
|
395
|
+
}
|
|
396
|
+
if (!feedback.mounted) return
|
|
397
|
+
onCopy?.(succeeded)
|
|
398
|
+
if (!feedback.current(own) || !succeeded) return
|
|
399
|
+
setCopied(true)
|
|
400
|
+
place(() => setOpen(true))
|
|
401
|
+
feedback.after(COPIED_FOR, () => setOpen(false))
|
|
402
|
+
}
|
|
403
|
+
const ask = () => {
|
|
404
|
+
feedback.next()
|
|
405
|
+
setCopied(false)
|
|
406
|
+
place(() => setOpen(true))
|
|
407
|
+
feedback.after(SHOW_FOR, () => setOpen(false))
|
|
408
|
+
}
|
|
409
|
+
const first = Array.isArray(children) ? children[0] : children
|
|
410
|
+
const child: ReactNode = typeof first === "string" || typeof first === "number" ? <TriggerDecorator>{first}</TriggerDecorator> : first
|
|
411
|
+
const own = isValidElement(child) ? (child.props as TriggerChildProps & { onPress?: (event: GestureResponderEvent) => void }) : null
|
|
412
|
+
const trigger =
|
|
413
|
+
isValidElement(child) && own
|
|
414
|
+
? cloneElement(child as ReactElement<TriggerChildProps>, {
|
|
415
|
+
...anchorProps(own, setTrigger as never, open ? () => place() : undefined),
|
|
416
|
+
onPress: (event: GestureResponderEvent) => {
|
|
417
|
+
own.onPress?.(event)
|
|
418
|
+
void run()
|
|
419
|
+
},
|
|
420
|
+
onLongPress: ask,
|
|
421
|
+
} as Partial<TriggerChildProps>)
|
|
422
|
+
: child
|
|
423
|
+
return (
|
|
424
|
+
<TooltipContext.Provider value={{ open, show: () => void run() }}>
|
|
425
|
+
{trigger}
|
|
426
|
+
<TooltipPanel
|
|
427
|
+
open={open}
|
|
428
|
+
onDismiss={hide}
|
|
429
|
+
anchor={anchor}
|
|
430
|
+
side={side}
|
|
431
|
+
align={align}
|
|
432
|
+
alignOffset={alignOffset}
|
|
433
|
+
sideOffset={sideOffset}
|
|
434
|
+
compact
|
|
435
|
+
maxWidth="none"
|
|
436
|
+
gutterSize="md"
|
|
437
|
+
testID={testID}
|
|
438
|
+
>
|
|
439
|
+
<CopyLabel copied={copied} />
|
|
440
|
+
</TooltipPanel>
|
|
441
|
+
</TooltipContext.Provider>
|
|
442
|
+
)
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/** Copy with its icon, or Copied! with a check: the check's own room makes the gap smaller, as on the web. */
|
|
446
|
+
function CopyLabel({ copied }: { copied: boolean }) {
|
|
447
|
+
const theme = useTheme()
|
|
448
|
+
const look = tooltipLook(theme, true, "md")
|
|
449
|
+
return (
|
|
450
|
+
<View style={[styles.copyLabel, { gap: copied ? 2 : 4 }]}>
|
|
451
|
+
{copied ? <CheckMd /> : <Copy />}
|
|
452
|
+
<Text variant={look.variant} size={look.variant ? undefined : "sm"} weight={look.weight} color={look.text}>
|
|
453
|
+
{copied ? "Copied!" : "Copy"}
|
|
454
|
+
</Text>
|
|
455
|
+
</View>
|
|
456
|
+
)
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
/** The web's Clipboard API; React Native's own clipboard module on a phone (its `setString`). */
|
|
460
|
+
async function writeClipboard(value: string): Promise<boolean> {
|
|
461
|
+
if (Platform.OS === "web") {
|
|
462
|
+
const clipboard = (globalThis as { navigator?: { clipboard?: { writeText?: (text: string) => Promise<void> } } }).navigator?.clipboard
|
|
463
|
+
if (!clipboard?.writeText) return false
|
|
464
|
+
await clipboard.writeText(value)
|
|
465
|
+
return true
|
|
466
|
+
}
|
|
467
|
+
const module = (NativeModules as { Clipboard?: { setString?: (text: string) => void } }).Clipboard
|
|
468
|
+
if (!module?.setString) return false
|
|
469
|
+
module.setString(value)
|
|
470
|
+
return true
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const styles = StyleSheet.create({
|
|
474
|
+
panel: { justifyContent: "center", borderCurve: "continuous" },
|
|
475
|
+
hidden: { display: "none" },
|
|
476
|
+
decorator: { textDecorationLine: "underline", textDecorationStyle: "dotted" },
|
|
477
|
+
copyLabel: { flexDirection: "row", alignItems: "center" },
|
|
478
|
+
})
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @plexui/react-native: the components of Plex UI for React Native, drawn as iOS 26 or Material 3 from one set of
|
|
2
2
|
// tokens (@plexui/styles).
|
|
3
|
-
export { ThemeProvider, createTheme, defaultPlatform, interFonts, useTheme, type ThemeProviderProps } from "./theme/ThemeProvider"
|
|
3
|
+
export { ThemeProvider, createTheme, defaultPlatform, interFonts, robotoFonts, useTheme, type PlatformFonts, type ThemeProviderProps } from "./theme/ThemeProvider"
|
|
4
4
|
export type {
|
|
5
5
|
BrandTheme,
|
|
6
6
|
ColorScheme,
|
|
@@ -63,6 +63,20 @@ export { Switch, type SwitchProps } from "./components/Switch/Switch"
|
|
|
63
63
|
export { Checkbox, type CheckboxProps } from "./components/Checkbox/Checkbox"
|
|
64
64
|
export { RadioGroup, type RadioGroupItemProps, type RadioGroupProps } from "./components/RadioGroup/RadioGroup"
|
|
65
65
|
export { Input, InputAdornmentButton, TextField, type InputAdornmentButtonProps, type InputProps, type InputVariant, type TextFieldProps } from "./components/Input/Input"
|
|
66
|
+
export { Field, FieldError, type FieldControlProps, type FieldErrorProps, type FieldProps } from "./components/Field/Field"
|
|
67
|
+
export { Textarea, type TextareaProps } from "./components/Textarea/Textarea"
|
|
68
|
+
export { FloatingLabelInput, type FloatingLabelInputProps } from "./components/FloatingLabelInput/FloatingLabelInput"
|
|
69
|
+
export {
|
|
70
|
+
InputGroup,
|
|
71
|
+
type InputGroupAddonAlign,
|
|
72
|
+
type InputGroupAddonProps,
|
|
73
|
+
type InputGroupButtonProps,
|
|
74
|
+
type InputGroupInputProps,
|
|
75
|
+
type InputGroupProps,
|
|
76
|
+
type InputGroupTextareaProps,
|
|
77
|
+
type InputGroupTextProps,
|
|
78
|
+
} from "./components/InputGroup/InputGroup"
|
|
79
|
+
export { TagInput, type Tag, type TagInputProps } from "./components/TagInput/TagInput"
|
|
66
80
|
export { OTPInput, type OTPInputProps } from "./components/OTPInput/OTPInput"
|
|
67
81
|
export { Select, type SelectOption, type SelectProps } from "./components/Select/Select"
|
|
68
82
|
export { Menu, type MenuContentProps, type MenuItemProps, type MenuProps } from "./components/Menu/Menu"
|
|
@@ -73,10 +87,30 @@ export { Toaster, toast, type ToasterProps, type ToastId, type ToastOptions, typ
|
|
|
73
87
|
|
|
74
88
|
export { Avatar, AvatarGroup, type AvatarColor, type AvatarGroupProps, type AvatarProps, type AvatarVariant } from "./components/Avatar/Avatar"
|
|
75
89
|
export { Badge, type BadgeColor, type BadgeProps, type BadgeSize, type BadgeVariant } from "./components/Badge/Badge"
|
|
76
|
-
export {
|
|
90
|
+
export { BottomActions, type BottomActionsProps } from "./components/BottomActions/BottomActions"
|
|
91
|
+
export { Card, cardColors, type CardColor, type CardMediaProps, type CardProps, type CardSize, type CardVariant } from "./components/Card/Card"
|
|
77
92
|
export { List, ListItem, type ListItemProps, type ListProps } from "./components/List/List"
|
|
78
93
|
export { Chip, type ChipProps } from "./components/Chip/Chip"
|
|
79
94
|
export { Skeleton, type SkeletonProps } from "./components/Skeleton/Skeleton"
|
|
95
|
+
export { Progress, progressSegments, type ProgressColor, type ProgressProps, type ProgressSegment, type ProgressSize } from "./components/Progress/Progress"
|
|
96
|
+
export { ProgressSteps, type ProgressStepsProps, type ProgressStepsSize, type StepDescriptionProps, type StepProps, type StepTitleProps } from "./components/ProgressSteps/ProgressSteps"
|
|
97
|
+
export { Stepper, stepValue, type StepperProps } from "./components/Stepper/Stepper"
|
|
98
|
+
export { CircularProgress, getSimulatedProgress, LoadingDots, LoadingIndicator, type CircularProgressProps, type LoadingDotsProps, type LoadingIndicatorProps } from "./components/Indicator"
|
|
99
|
+
export { ShimmerableText, ShimmerText, type ShimmerableTextProps, type ShimmerTextProps } from "./components/ShimmerText/ShimmerText"
|
|
100
|
+
export { RollingNumber, rollingNumberParts, type RollingNumberProps } from "./components/RollingNumber/RollingNumber"
|
|
80
101
|
export { EmptyMessage, EmptyState, type EmptyMessageProps } from "./components/EmptyMessage/EmptyMessage"
|
|
81
102
|
export { Slider, type SliderMark, type SliderProps } from "./components/Slider/Slider"
|
|
82
103
|
export { PageControl, pageControlDots, type PageControlChangeDetails, type PageControlDotSize, type PageControlProps } from "./components/PageControl/PageControl"
|
|
104
|
+
export { Alert, type AlertColor, type AlertMobileActions, type AlertProps, type AlertVariant } from "./components/Alert/Alert"
|
|
105
|
+
export { Tip, type TipArrowEdge, type TipMobileActions, type TipPopoverProps, type TipProps } from "./components/Tip/Tip"
|
|
106
|
+
export { CopyTooltip, Tooltip, type CopyTooltipProps, type TooltipGutterSize, type TooltipProps, type TriggerDecoratorProps } from "./components/Tooltip/Tooltip"
|
|
107
|
+
export {
|
|
108
|
+
Popover,
|
|
109
|
+
usePopoverController,
|
|
110
|
+
type PopoverContentProps,
|
|
111
|
+
type PopoverController,
|
|
112
|
+
type PopoverProps,
|
|
113
|
+
type PopoverTriggerProps,
|
|
114
|
+
} from "./components/Popover/Popover"
|
|
115
|
+
export { Separator, type SeparatorProps } from "./components/Separator/Separator"
|
|
116
|
+
export { TextLink, type TextLinkProps } from "./components/TextLink/TextLink"
|