panelui-native 0.83.0 → 0.85.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 +17 -8
- package/lib/module/components/bottom-sheet/index.js +3 -2
- package/lib/module/components/bottom-sheet/index.js.map +1 -1
- package/lib/module/components/button/index.js +37 -16
- package/lib/module/components/button/index.js.map +1 -1
- package/lib/module/components/circular-text/circular-text-geometry.js +63 -0
- package/lib/module/components/circular-text/circular-text-geometry.js.map +1 -0
- package/lib/module/components/circular-text/index.js +146 -0
- package/lib/module/components/circular-text/index.js.map +1 -0
- package/lib/module/components/flip-card/index.js +338 -0
- package/lib/module/components/flip-card/index.js.map +1 -0
- package/lib/module/components/marquee/index.js +12 -5
- package/lib/module/components/marquee/index.js.map +1 -1
- package/lib/module/components/panelside/index.js +15 -417
- package/lib/module/components/panelside/index.js.map +1 -1
- package/lib/module/components/popover/index.js +120 -7
- package/lib/module/components/popover/index.js.map +1 -1
- package/lib/module/components/select/index.js +3 -2
- package/lib/module/components/select/index.js.map +1 -1
- package/lib/module/components/slider/index.js +16 -5
- package/lib/module/components/slider/index.js.map +1 -1
- package/lib/module/components/switch/index.js +28 -7
- package/lib/module/components/switch/index.js.map +1 -1
- package/lib/module/icons/index.js +24 -4
- package/lib/module/icons/index.js.map +1 -1
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/native/index.js +35 -0
- package/lib/module/native/index.js.map +1 -1
- package/lib/module/native/native-host.js +62 -0
- package/lib/module/native/native-host.js.map +1 -0
- package/lib/module/primitives/glass.js +14 -0
- package/lib/module/primitives/glass.js.map +1 -1
- package/lib/typescript/src/components/bottom-sheet/index.d.ts.map +1 -1
- package/lib/typescript/src/components/button/index.d.ts.map +1 -1
- package/lib/typescript/src/components/circular-text/circular-text-geometry.d.ts +39 -0
- package/lib/typescript/src/components/circular-text/circular-text-geometry.d.ts.map +1 -0
- package/lib/typescript/src/components/circular-text/index.d.ts +69 -0
- package/lib/typescript/src/components/circular-text/index.d.ts.map +1 -0
- package/lib/typescript/src/components/flip-card/index.d.ts +116 -0
- package/lib/typescript/src/components/flip-card/index.d.ts.map +1 -0
- package/lib/typescript/src/components/marquee/index.d.ts.map +1 -1
- package/lib/typescript/src/components/panelside/index.d.ts +10 -202
- package/lib/typescript/src/components/panelside/index.d.ts.map +1 -1
- package/lib/typescript/src/components/popover/index.d.ts +25 -1
- package/lib/typescript/src/components/popover/index.d.ts.map +1 -1
- package/lib/typescript/src/components/slider/index.d.ts.map +1 -1
- package/lib/typescript/src/components/switch/index.d.ts +0 -4
- package/lib/typescript/src/components/switch/index.d.ts.map +1 -1
- package/lib/typescript/src/icons/index.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +3 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/native/index.d.ts +67 -10
- package/lib/typescript/src/native/index.d.ts.map +1 -1
- package/lib/typescript/src/native/native-host.d.ts +71 -0
- package/lib/typescript/src/native/native-host.d.ts.map +1 -0
- package/lib/typescript/src/primitives/glass.d.ts.map +1 -1
- package/package.json +11 -1
- package/src/components/bottom-sheet/index.tsx +8 -3
- package/src/components/button/index.tsx +36 -15
- package/src/components/circular-text/circular-text-geometry.ts +80 -0
- package/src/components/circular-text/index.tsx +217 -0
- package/src/components/flip-card/index.tsx +419 -0
- package/src/components/marquee/index.tsx +12 -5
- package/src/components/panelside/index.tsx +16 -604
- package/src/components/popover/index.tsx +146 -4
- package/src/components/select/index.tsx +3 -3
- package/src/components/slider/index.tsx +28 -6
- package/src/components/switch/index.tsx +28 -7
- package/src/icons/index.tsx +23 -2
- package/src/index.ts +10 -6
- package/src/native/index.ts +89 -9
- package/src/native/native-host.tsx +75 -0
- package/src/primitives/glass.tsx +12 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Where each character sits on the ring, kept out of the component so it can
|
|
3
|
+
* be tested without rendering one.
|
|
4
|
+
*
|
|
5
|
+
* Every number here reaches a transform, and a transform treats `NaN` and
|
|
6
|
+
* `Infinity` as a frame that never resolves rather than as an error — a ring
|
|
7
|
+
* handed a bad radius should draw nothing, not wedge. So the guards live at
|
|
8
|
+
* the boundary, once, instead of at each use.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
/** Points from the centre to the baseline the characters sit on. */
|
|
12
|
+
export const DEFAULT_CIRCULAR_TEXT_RADIUS = 90;
|
|
13
|
+
|
|
14
|
+
/** Milliseconds for one full turn. Slow: it is decoration, not a spinner. */
|
|
15
|
+
export const DEFAULT_CIRCULAR_TEXT_DURATION = 20000;
|
|
16
|
+
|
|
17
|
+
/** Degrees of the circle the text is spread across. The whole way round. */
|
|
18
|
+
export const DEFAULT_CIRCULAR_TEXT_SPREAD = 360;
|
|
19
|
+
|
|
20
|
+
export function normalizeRadius(value: number): number {
|
|
21
|
+
if (!Number.isFinite(value)) return DEFAULT_CIRCULAR_TEXT_RADIUS;
|
|
22
|
+
return Math.max(value, 0);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function normalizeDuration(value: number): number {
|
|
26
|
+
if (!Number.isFinite(value)) return DEFAULT_CIRCULAR_TEXT_DURATION;
|
|
27
|
+
return Math.max(value, 0);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function normalizeSpread(value: number): number {
|
|
31
|
+
if (!Number.isFinite(value)) return DEFAULT_CIRCULAR_TEXT_SPREAD;
|
|
32
|
+
// Clamped rather than wrapped: past a full turn the characters would overlap
|
|
33
|
+
// the ones already there, and a spread of -40 is a spread of 40 the other
|
|
34
|
+
// way round, which `reverse` is the prop for.
|
|
35
|
+
return Math.min(Math.abs(value), 360);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface CircularTextGlyph {
|
|
39
|
+
/** The character itself. */
|
|
40
|
+
character: string;
|
|
41
|
+
/** Its place in the string, which is what makes a stable key. */
|
|
42
|
+
index: number;
|
|
43
|
+
/** Degrees clockwise from the top, before any rotation of the ring. */
|
|
44
|
+
angle: number;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* One entry per character, evenly spaced around the arc.
|
|
49
|
+
*
|
|
50
|
+
* The step is measured between characters rather than across them, and which
|
|
51
|
+
* of the two you divide by is the whole difference between a closed ring and
|
|
52
|
+
* one with a visible seam. A full turn has no last gap — the end of the string
|
|
53
|
+
* is adjacent to its start — so `n` characters make `n` gaps and the step is
|
|
54
|
+
* `spread / n`. Anything less than a full turn has one gap fewer than it has
|
|
55
|
+
* characters, so the step is `spread / (n - 1)` and the text reaches both ends
|
|
56
|
+
* of the arc it was given instead of stopping short of the second one.
|
|
57
|
+
*/
|
|
58
|
+
export function circularTextGlyphs(
|
|
59
|
+
text: string,
|
|
60
|
+
spread: number,
|
|
61
|
+
startAngle: number
|
|
62
|
+
): CircularTextGlyph[] {
|
|
63
|
+
const characters = Array.from(text);
|
|
64
|
+
if (characters.length === 0) return [];
|
|
65
|
+
|
|
66
|
+
const arc = normalizeSpread(spread);
|
|
67
|
+
const from = Number.isFinite(startAngle) ? startAngle : 0;
|
|
68
|
+
const closed = arc >= 360;
|
|
69
|
+
|
|
70
|
+
// One character cannot be spread across anything, and dividing by the zero
|
|
71
|
+
// gaps it has would put it nowhere.
|
|
72
|
+
const step =
|
|
73
|
+
characters.length === 1 ? 0 : arc / (closed ? characters.length : characters.length - 1);
|
|
74
|
+
|
|
75
|
+
return characters.map((character, index) => ({
|
|
76
|
+
character,
|
|
77
|
+
index,
|
|
78
|
+
angle: from + step * index,
|
|
79
|
+
}));
|
|
80
|
+
}
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import { useEffect, useMemo } from 'react';
|
|
2
|
+
import { View, type ViewProps } from 'react-native';
|
|
3
|
+
import Animated, {
|
|
4
|
+
Easing,
|
|
5
|
+
cancelAnimation,
|
|
6
|
+
useAnimatedStyle,
|
|
7
|
+
useReducedMotion,
|
|
8
|
+
useSharedValue,
|
|
9
|
+
withRepeat,
|
|
10
|
+
withTiming,
|
|
11
|
+
} from 'react-native-reanimated';
|
|
12
|
+
import { tv } from 'tailwind-variants';
|
|
13
|
+
import { Text } from '../../primitives/text';
|
|
14
|
+
import { cn } from '../../utils/cn';
|
|
15
|
+
import {
|
|
16
|
+
DEFAULT_CIRCULAR_TEXT_DURATION,
|
|
17
|
+
DEFAULT_CIRCULAR_TEXT_RADIUS,
|
|
18
|
+
DEFAULT_CIRCULAR_TEXT_SPREAD,
|
|
19
|
+
circularTextGlyphs,
|
|
20
|
+
normalizeDuration,
|
|
21
|
+
normalizeRadius,
|
|
22
|
+
normalizeSpread,
|
|
23
|
+
} from './circular-text-geometry';
|
|
24
|
+
|
|
25
|
+
const circularTextVariants = tv({
|
|
26
|
+
base: 'items-center justify-center',
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
const glyphVariants = tv({
|
|
30
|
+
/*
|
|
31
|
+
* Every character gets a box the size of the ring, laid over the same point,
|
|
32
|
+
* with the character at the top edge of it. Rotating the box about its own
|
|
33
|
+
* centre — which is the ring's centre — is what swings the character round
|
|
34
|
+
* the circle, and it means no per-character arithmetic reaches the transform
|
|
35
|
+
* beyond the one angle.
|
|
36
|
+
*
|
|
37
|
+
* The box's size is set inline rather than by a utility, and that is not
|
|
38
|
+
* decoration: a box that states its own width and height cannot end up with
|
|
39
|
+
* a different one, and one glyph sitting at twice the radius of the rest is
|
|
40
|
+
* exactly what a box of the wrong size looks like.
|
|
41
|
+
*/
|
|
42
|
+
base: 'items-center justify-start',
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* The glyph size the ring is drawn at unless the caller says otherwise.
|
|
47
|
+
*
|
|
48
|
+
* A step up from the body default. Text bent round a circle is read a letter
|
|
49
|
+
* at a time rather than as a word, and at body size the letters are small
|
|
50
|
+
* enough that the ring reads as a texture instead of as a phrase.
|
|
51
|
+
*/
|
|
52
|
+
const GLYPH_TEXT = 'text-lg';
|
|
53
|
+
|
|
54
|
+
export interface CircularTextProps extends Omit<ViewProps, 'children'> {
|
|
55
|
+
/**
|
|
56
|
+
* The text to set around the circle. A string, not elements: each character
|
|
57
|
+
* is placed and turned on its own, so there is nothing for markup inside it
|
|
58
|
+
* to apply to.
|
|
59
|
+
*/
|
|
60
|
+
children: string;
|
|
61
|
+
/**
|
|
62
|
+
* Points from the centre of the ring to the outside of the text.
|
|
63
|
+
*
|
|
64
|
+
* It is also half the component's width and height — the ring is a square
|
|
65
|
+
* that measures `radius * 2` on both axes, and the characters hang inside
|
|
66
|
+
* its edge. Nothing is laid out around it, so give the space it needs.
|
|
67
|
+
*/
|
|
68
|
+
radius?: number;
|
|
69
|
+
/**
|
|
70
|
+
* Milliseconds for one full turn. Slow by default: it is decoration, and a
|
|
71
|
+
* ring that turns at the speed of a spinner reads as something loading.
|
|
72
|
+
*/
|
|
73
|
+
spinDuration?: number;
|
|
74
|
+
/** Turn anticlockwise. */
|
|
75
|
+
reverse?: boolean;
|
|
76
|
+
/**
|
|
77
|
+
* Hold the ring where it is.
|
|
78
|
+
*
|
|
79
|
+
* It stops in place rather than returning to the top, and resumes from
|
|
80
|
+
* there, so a ring paused mid-word is still on that word when it starts
|
|
81
|
+
* again.
|
|
82
|
+
*/
|
|
83
|
+
paused?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Degrees of the circle the text is spread across. The whole way round by
|
|
86
|
+
* default.
|
|
87
|
+
*
|
|
88
|
+
* A full turn has no last gap, since the end of the string is adjacent to
|
|
89
|
+
* its start. Anything less is an arc with two ends, and the text reaches
|
|
90
|
+
* both of them.
|
|
91
|
+
*/
|
|
92
|
+
spread?: number;
|
|
93
|
+
/** Degrees clockwise from the top that the first character sits at. */
|
|
94
|
+
startAngle?: number;
|
|
95
|
+
/** Classes for the ring's own box. */
|
|
96
|
+
className?: string;
|
|
97
|
+
/** Classes for the characters — size, weight, colour, tracking. */
|
|
98
|
+
textClassName?: string;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Text set around a circle, turning.
|
|
103
|
+
*
|
|
104
|
+
* For a badge, a seal, a mark around a logo: decoration whose job is to be a
|
|
105
|
+
* shape first and a sentence second. The characters are placed one at a time
|
|
106
|
+
* and each is turned to sit square on the curve, so the ring closes and the
|
|
107
|
+
* text at the bottom is upside down — which is what makes it read as a
|
|
108
|
+
* circle rather than as a sentence bent into one.
|
|
109
|
+
*
|
|
110
|
+
* The centre is left empty and nothing is laid out inside it. Put a logo
|
|
111
|
+
* there by stacking the two, rather than by passing it as a child.
|
|
112
|
+
*
|
|
113
|
+
* The turn runs entirely on the UI thread, and under the platform's
|
|
114
|
+
* reduce-motion setting the ring is drawn once and held still. Not a slower
|
|
115
|
+
* turn — none. The shape carries the whole meaning; the rotation is the part
|
|
116
|
+
* that setting exists to remove.
|
|
117
|
+
*/
|
|
118
|
+
export function CircularText({
|
|
119
|
+
children,
|
|
120
|
+
radius = DEFAULT_CIRCULAR_TEXT_RADIUS,
|
|
121
|
+
spinDuration = DEFAULT_CIRCULAR_TEXT_DURATION,
|
|
122
|
+
reverse = false,
|
|
123
|
+
paused = false,
|
|
124
|
+
spread = DEFAULT_CIRCULAR_TEXT_SPREAD,
|
|
125
|
+
startAngle = 0,
|
|
126
|
+
className,
|
|
127
|
+
textClassName,
|
|
128
|
+
style,
|
|
129
|
+
...props
|
|
130
|
+
}: CircularTextProps) {
|
|
131
|
+
const reducedMotion = useReducedMotion();
|
|
132
|
+
const rotation = useSharedValue(0);
|
|
133
|
+
|
|
134
|
+
const size = normalizeRadius(radius) * 2;
|
|
135
|
+
const duration = normalizeDuration(spinDuration);
|
|
136
|
+
const arc = normalizeSpread(spread);
|
|
137
|
+
|
|
138
|
+
const glyphs = useMemo(
|
|
139
|
+
() => circularTextGlyphs(children, arc, startAngle),
|
|
140
|
+
[children, arc, startAngle]
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
// A duration of zero is a timing that never advances, so it is a held ring
|
|
144
|
+
// rather than an infinitely fast one.
|
|
145
|
+
const turning = !paused && !reducedMotion && duration > 0 && glyphs.length > 0;
|
|
146
|
+
|
|
147
|
+
useEffect(() => {
|
|
148
|
+
if (!turning) {
|
|
149
|
+
// Leaves the value where it reached. Zeroing here would send a ring
|
|
150
|
+
// paused mid-word back to the top, and the pause would read as a reset.
|
|
151
|
+
cancelAnimation(rotation);
|
|
152
|
+
return undefined;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/*
|
|
156
|
+
* From wherever it already is, one turn, forever.
|
|
157
|
+
*
|
|
158
|
+
* The repeat restarts each cycle at the value it began on, and the state
|
|
159
|
+
* at `from + 360` is the state at `from`, so the seam between cycles is
|
|
160
|
+
* arithmetic rather than something to see. Taking the remainder first
|
|
161
|
+
* keeps the number from growing without bound over a long session.
|
|
162
|
+
*/
|
|
163
|
+
const from = rotation.value % 360;
|
|
164
|
+
const to = reverse ? from - 360 : from + 360;
|
|
165
|
+
rotation.value = from;
|
|
166
|
+
rotation.value = withRepeat(
|
|
167
|
+
withTiming(to, { duration, easing: Easing.linear }),
|
|
168
|
+
-1,
|
|
169
|
+
false
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
return () => cancelAnimation(rotation);
|
|
173
|
+
}, [rotation, turning, duration, reverse]);
|
|
174
|
+
|
|
175
|
+
const ringStyle = useAnimatedStyle(() => ({
|
|
176
|
+
transform: [{ rotate: `${rotation.value}deg` }],
|
|
177
|
+
}));
|
|
178
|
+
|
|
179
|
+
return (
|
|
180
|
+
<View
|
|
181
|
+
accessible
|
|
182
|
+
accessibilityRole="text"
|
|
183
|
+
accessibilityLabel={children}
|
|
184
|
+
className={cn(circularTextVariants(), className)}
|
|
185
|
+
style={[{ width: size, height: size }, style]}
|
|
186
|
+
{...props}
|
|
187
|
+
>
|
|
188
|
+
{/* Hidden from assistive technology as a group: the label above already
|
|
189
|
+
says what it reads, and a ring announced character by character is a
|
|
190
|
+
string spelled out one letter at a time. */}
|
|
191
|
+
<Animated.View
|
|
192
|
+
accessibilityElementsHidden
|
|
193
|
+
importantForAccessibility="no-hide-descendants"
|
|
194
|
+
style={[{ width: size, height: size }, ringStyle]}
|
|
195
|
+
>
|
|
196
|
+
{glyphs.map((glyph) => (
|
|
197
|
+
<View
|
|
198
|
+
key={`${glyph.character}-${glyph.index}`}
|
|
199
|
+
className={glyphVariants()}
|
|
200
|
+
style={{
|
|
201
|
+
position: 'absolute',
|
|
202
|
+
left: 0,
|
|
203
|
+
top: 0,
|
|
204
|
+
width: size,
|
|
205
|
+
height: size,
|
|
206
|
+
transform: [{ rotate: `${glyph.angle}deg` }],
|
|
207
|
+
}}
|
|
208
|
+
>
|
|
209
|
+
<Text className={cn(GLYPH_TEXT, textClassName)}>{glyph.character}</Text>
|
|
210
|
+
</View>
|
|
211
|
+
))}
|
|
212
|
+
</Animated.View>
|
|
213
|
+
</View>
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
CircularText.displayName = 'CircularText';
|