panelui-native 0.103.2 → 0.105.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 +2 -0
- package/lib/module/components/countdown/countdown-time.js +96 -0
- package/lib/module/components/countdown/countdown-time.js.map +1 -0
- package/lib/module/components/countdown/index.js +345 -0
- package/lib/module/components/countdown/index.js.map +1 -0
- package/lib/module/components/flow/index.js +64 -55
- package/lib/module/components/flow/index.js.map +1 -1
- package/lib/module/components/leaderboard/index.js +442 -0
- package/lib/module/components/leaderboard/index.js.map +1 -0
- package/lib/module/components/leaderboard/leaderboard-rank.js +65 -0
- package/lib/module/components/leaderboard/leaderboard-rank.js.map +1 -0
- package/lib/module/components/map/index.js +114 -50
- package/lib/module/components/map/index.js.map +1 -1
- package/lib/module/index.js +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/components/countdown/countdown-time.d.ts +53 -0
- package/lib/typescript/src/components/countdown/countdown-time.d.ts.map +1 -0
- package/lib/typescript/src/components/countdown/index.d.ts +170 -0
- package/lib/typescript/src/components/countdown/index.d.ts.map +1 -0
- package/lib/typescript/src/components/flow/index.d.ts.map +1 -1
- package/lib/typescript/src/components/leaderboard/index.d.ts +63 -0
- package/lib/typescript/src/components/leaderboard/index.d.ts.map +1 -0
- package/lib/typescript/src/components/leaderboard/leaderboard-rank.d.ts +41 -0
- package/lib/typescript/src/components/leaderboard/leaderboard-rank.d.ts.map +1 -0
- package/lib/typescript/src/components/map/index.d.ts +30 -5
- package/lib/typescript/src/components/map/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/package.json +1 -1
- package/src/components/countdown/countdown-time.ts +105 -0
- package/src/components/countdown/index.tsx +335 -0
- package/src/components/flow/index.tsx +65 -51
- package/src/components/leaderboard/index.tsx +535 -0
- package/src/components/leaderboard/leaderboard-rank.ts +84 -0
- package/src/components/map/index.tsx +130 -44
- package/src/index.ts +15 -0
|
@@ -0,0 +1,442 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Leaderboard — entries ranked by a value, with the top three on a podium.
|
|
5
|
+
*
|
|
6
|
+
* ```tsx
|
|
7
|
+
* <Leaderboard
|
|
8
|
+
* data={[
|
|
9
|
+
* { id: 'maya', name: 'Maya Chen', value: 12480, change: 2 },
|
|
10
|
+
* { id: 'omar', name: 'Omar Haddad', value: 11930 },
|
|
11
|
+
* { id: 'lena', name: 'Lena Brandt', value: 10215, change: -1 },
|
|
12
|
+
* { id: 'sam', name: 'Sam Okafor', value: 9870 },
|
|
13
|
+
* ]}
|
|
14
|
+
* unit="steps"
|
|
15
|
+
* highlightId="sam"
|
|
16
|
+
* />
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* Data in, ranks out. The caller passes values and the component sorts and
|
|
20
|
+
* places them, so ties are numbered the same way everywhere and a row can
|
|
21
|
+
* never show a place its value does not earn. See `leaderboard-rank.ts`.
|
|
22
|
+
*
|
|
23
|
+
* The podium is laid out 2-1-3, first in the middle and highest, because that
|
|
24
|
+
* is the arrangement people already read a top three in. Its bars are drawn
|
|
25
|
+
* to scale against the leader by default: a close race looks close and a
|
|
26
|
+
* runaway looks like one, which a fixed staircase of heights cannot show.
|
|
27
|
+
*
|
|
28
|
+
* Every podium column and every row is one accessible element. A screen
|
|
29
|
+
* reader hears "Rank 2, Omar Haddad, 11,930 steps" once, rather than the
|
|
30
|
+
* rank, the name and the value as three stops in a grid it cannot see.
|
|
31
|
+
*/
|
|
32
|
+
import { forwardRef, useEffect, useMemo } from 'react';
|
|
33
|
+
import { Pressable, View } from 'react-native';
|
|
34
|
+
import Animated, { useAnimatedStyle, useReducedMotion, useSharedValue, withDelay, withTiming, Easing } from 'react-native-reanimated';
|
|
35
|
+
import { tv } from 'tailwind-variants';
|
|
36
|
+
import { useCSSVariable } from 'uniwind';
|
|
37
|
+
import { ArrowDownIcon, ArrowUpIcon } from "../../icons/index.js";
|
|
38
|
+
import { Text } from "../../primitives/text.js";
|
|
39
|
+
import { cn } from "../../utils/cn.js";
|
|
40
|
+
import { Avatar } from "../avatar/index.js";
|
|
41
|
+
import { podiumHeights, rankEntries } from "./leaderboard-rank.js";
|
|
42
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
43
|
+
export { rankEntries } from "./leaderboard-rank.js";
|
|
44
|
+
/** Milliseconds for a podium bar to grow. */
|
|
45
|
+
const GROW_DURATION = 620;
|
|
46
|
+
/** Delay between bars. Third rises first and first last, so the leader lands on the beat. */
|
|
47
|
+
const GROW_STAGGER = 110;
|
|
48
|
+
const leaderboardVariants = tv({
|
|
49
|
+
slots: {
|
|
50
|
+
root: 'w-full gap-4',
|
|
51
|
+
podium: 'flex-row items-end gap-2 px-1',
|
|
52
|
+
column: 'flex-1 items-center',
|
|
53
|
+
person: 'items-center gap-1 pb-2',
|
|
54
|
+
rankBadge: 'absolute -bottom-1.5 h-5 min-w-5 items-center justify-center self-center rounded-full border-2 border-background px-1',
|
|
55
|
+
bar: 'w-full items-center overflow-hidden rounded-t-2xl pt-2.5',
|
|
56
|
+
card: 'flex-1 items-center gap-1.5 rounded-2xl border border-border bg-card px-2 pb-3 pt-4',
|
|
57
|
+
list: 'overflow-hidden rounded-2xl border border-border bg-card',
|
|
58
|
+
row: 'min-h-14 flex-row items-center gap-3 px-3 py-2.5',
|
|
59
|
+
rowDivider: 'ml-14 h-px bg-border',
|
|
60
|
+
rank: 'w-7 text-center text-sm font-semibold tabular-nums text-muted-foreground',
|
|
61
|
+
rowText: 'flex-1 gap-0.5',
|
|
62
|
+
value: 'text-sm font-semibold tabular-nums text-foreground',
|
|
63
|
+
change: 'min-w-10 flex-row items-center justify-end gap-0.5',
|
|
64
|
+
gap: 'flex-row items-center justify-center gap-1 py-1.5',
|
|
65
|
+
gapDot: 'h-1 w-1 rounded-full bg-muted-foreground/40',
|
|
66
|
+
empty: 'items-center rounded-2xl border border-dashed border-border px-4 py-8'
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Colour by podium place. A lookup rather than a `tv()` variant: place is
|
|
72
|
+
* derived from the data, not something a caller passes, and a variant here
|
|
73
|
+
* would be documented as a prop on `Leaderboard`.
|
|
74
|
+
*
|
|
75
|
+
* One hue stepped down in strength, so the podium reads as a single series
|
|
76
|
+
* and follows the theme's primary rather than borrowing medal colours that
|
|
77
|
+
* would clash with half the themes.
|
|
78
|
+
*/
|
|
79
|
+
const PLACE = {
|
|
80
|
+
1: {
|
|
81
|
+
bar: 'bg-primary',
|
|
82
|
+
badge: 'bg-primary'
|
|
83
|
+
},
|
|
84
|
+
2: {
|
|
85
|
+
bar: 'bg-primary/40',
|
|
86
|
+
badge: 'bg-foreground'
|
|
87
|
+
},
|
|
88
|
+
3: {
|
|
89
|
+
bar: 'bg-primary/16',
|
|
90
|
+
badge: 'bg-foreground'
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
function initials(name) {
|
|
94
|
+
const parts = name.trim().split(/\s+/).filter(Boolean);
|
|
95
|
+
const first = parts[0]?.[0] ?? '';
|
|
96
|
+
const last = parts.length > 1 ? parts[parts.length - 1]?.[0] ?? '' : '';
|
|
97
|
+
return (first + last).toUpperCase() || '?';
|
|
98
|
+
}
|
|
99
|
+
function toSource(avatar) {
|
|
100
|
+
return typeof avatar === 'string' ? {
|
|
101
|
+
uri: avatar
|
|
102
|
+
} : avatar;
|
|
103
|
+
}
|
|
104
|
+
const defaultFormat = value => value.toLocaleString('en-US');
|
|
105
|
+
function describe({
|
|
106
|
+
entry,
|
|
107
|
+
rank,
|
|
108
|
+
tied
|
|
109
|
+
}, label, unit) {
|
|
110
|
+
const place = tied ? `Rank ${rank}, tied` : `Rank ${rank}`;
|
|
111
|
+
const parts = [place, entry.name, unit ? `${label} ${unit}` : label];
|
|
112
|
+
if (entry.subtitle) parts.splice(2, 0, entry.subtitle);
|
|
113
|
+
if (entry.change) {
|
|
114
|
+
const n = Math.abs(entry.change);
|
|
115
|
+
parts.push(`${entry.change > 0 ? 'up' : 'down'} ${n} ${n === 1 ? 'place' : 'places'}`);
|
|
116
|
+
} else if (entry.change === 0) {
|
|
117
|
+
parts.push('no change');
|
|
118
|
+
}
|
|
119
|
+
return parts.join(', ');
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** A pressable when the board is, a plain view when it is not. */
|
|
123
|
+
function Slot({
|
|
124
|
+
onPress,
|
|
125
|
+
label,
|
|
126
|
+
className,
|
|
127
|
+
children
|
|
128
|
+
}) {
|
|
129
|
+
if (onPress) {
|
|
130
|
+
return /*#__PURE__*/_jsx(Pressable, {
|
|
131
|
+
accessible: true,
|
|
132
|
+
accessibilityRole: "button",
|
|
133
|
+
accessibilityLabel: label,
|
|
134
|
+
onPress: onPress,
|
|
135
|
+
className: cn(className, 'active:opacity-70'),
|
|
136
|
+
children: children
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return /*#__PURE__*/_jsx(View, {
|
|
140
|
+
accessible: true,
|
|
141
|
+
accessibilityLabel: label,
|
|
142
|
+
className: className,
|
|
143
|
+
children: children
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
function PodiumBar({
|
|
147
|
+
place,
|
|
148
|
+
height,
|
|
149
|
+
delay,
|
|
150
|
+
rank
|
|
151
|
+
}) {
|
|
152
|
+
const slots = leaderboardVariants();
|
|
153
|
+
const reduced = useReducedMotion();
|
|
154
|
+
const grown = useSharedValue(reduced ? height : 0);
|
|
155
|
+
useEffect(() => {
|
|
156
|
+
grown.value = reduced ? height : withDelay(delay, withTiming(height, {
|
|
157
|
+
duration: GROW_DURATION,
|
|
158
|
+
easing: Easing.out(Easing.cubic)
|
|
159
|
+
}));
|
|
160
|
+
}, [grown, height, delay, reduced]);
|
|
161
|
+
const style = useAnimatedStyle(() => ({
|
|
162
|
+
height: grown.value
|
|
163
|
+
}));
|
|
164
|
+
// The numeral fades in once the bar is tall enough to hold it, so it never
|
|
165
|
+
// overflows a bar that is still a few points high.
|
|
166
|
+
const numeral = useAnimatedStyle(() => ({
|
|
167
|
+
opacity: Math.min(1, Math.max(0, (grown.value - 28) / 24))
|
|
168
|
+
}));
|
|
169
|
+
return /*#__PURE__*/_jsx(Animated.View, {
|
|
170
|
+
className: cn(slots.bar(), PLACE[place].bar),
|
|
171
|
+
style: style,
|
|
172
|
+
children: /*#__PURE__*/_jsx(Animated.View, {
|
|
173
|
+
style: numeral,
|
|
174
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
175
|
+
size: place === 1 ? '3xl' : '2xl',
|
|
176
|
+
weight: "bold",
|
|
177
|
+
className: cn('tabular-nums', place === 1 ? 'text-primary-foreground' : 'text-foreground/70'),
|
|
178
|
+
children: rank
|
|
179
|
+
})
|
|
180
|
+
})
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
function RankBadge({
|
|
184
|
+
place,
|
|
185
|
+
rank
|
|
186
|
+
}) {
|
|
187
|
+
const slots = leaderboardVariants();
|
|
188
|
+
return /*#__PURE__*/_jsx(View, {
|
|
189
|
+
className: cn(slots.rankBadge(), PLACE[place].badge),
|
|
190
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
191
|
+
className: cn('text-[10px] font-bold tabular-nums', place === 1 ? 'text-primary-foreground' : 'text-background'),
|
|
192
|
+
children: rank
|
|
193
|
+
})
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
function ChangeLabel({
|
|
197
|
+
change
|
|
198
|
+
}) {
|
|
199
|
+
const slots = leaderboardVariants();
|
|
200
|
+
const success = useCSSVariable('--color-success');
|
|
201
|
+
const destructive = useCSSVariable('--color-destructive');
|
|
202
|
+
if (change === undefined) return null;
|
|
203
|
+
if (change === 0) {
|
|
204
|
+
return /*#__PURE__*/_jsx(View, {
|
|
205
|
+
className: slots.change(),
|
|
206
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
207
|
+
size: "xs",
|
|
208
|
+
muted: true,
|
|
209
|
+
className: "tabular-nums",
|
|
210
|
+
children: "\u2013"
|
|
211
|
+
})
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
const up = change > 0;
|
|
215
|
+
const tint = up ? success : destructive;
|
|
216
|
+
const color = typeof tint === 'string' ? tint : undefined;
|
|
217
|
+
const Arrow = up ? ArrowUpIcon : ArrowDownIcon;
|
|
218
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
219
|
+
className: slots.change(),
|
|
220
|
+
children: [/*#__PURE__*/_jsx(Arrow, {
|
|
221
|
+
size: 11,
|
|
222
|
+
strokeWidth: 2.5,
|
|
223
|
+
color: color
|
|
224
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
225
|
+
size: "xs",
|
|
226
|
+
weight: "medium",
|
|
227
|
+
className: cn('tabular-nums', up ? 'text-success' : 'text-destructive'),
|
|
228
|
+
children: Math.abs(change)
|
|
229
|
+
})]
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Ranked entries with a podium for the top three and a list for the rest.
|
|
235
|
+
*
|
|
236
|
+
* Renders every row it is given rather than virtualising them: a board is
|
|
237
|
+
* read from the top, and past a few dozen rows nobody is reading it. Use
|
|
238
|
+
* `limit` for a long board, and `highlightId` to keep the viewer's own row in
|
|
239
|
+
* sight when the limit cuts them off.
|
|
240
|
+
*/
|
|
241
|
+
const LeaderboardRoot = /*#__PURE__*/forwardRef(function Leaderboard({
|
|
242
|
+
className,
|
|
243
|
+
data,
|
|
244
|
+
podium = 'bars',
|
|
245
|
+
order = 'desc',
|
|
246
|
+
podiumScale = 'value',
|
|
247
|
+
podiumHeight = 132,
|
|
248
|
+
limit,
|
|
249
|
+
highlightId,
|
|
250
|
+
formatValue = defaultFormat,
|
|
251
|
+
unit,
|
|
252
|
+
onPressEntry,
|
|
253
|
+
emptyText = 'No entries yet',
|
|
254
|
+
...props
|
|
255
|
+
}, ref) {
|
|
256
|
+
const slots = leaderboardVariants();
|
|
257
|
+
const ranked = useMemo(() => rankEntries(data, order), [data, order]);
|
|
258
|
+
const shown = limit != null ? ranked.slice(0, Math.max(0, limit)) : ranked;
|
|
259
|
+
|
|
260
|
+
// The viewer's own row, when the limit has cut it off.
|
|
261
|
+
const pinned = highlightId != null && !shown.some(r => r.entry.id === highlightId) ? ranked.find(r => r.entry.id === highlightId) : undefined;
|
|
262
|
+
const top = podium === 'none' ? [] : shown.slice(0, 3);
|
|
263
|
+
const rest = podium === 'none' ? shown : shown.slice(3);
|
|
264
|
+
const press = item => onPressEntry ? () => onPressEntry(item.entry, item.rank) : undefined;
|
|
265
|
+
if (ranked.length === 0) {
|
|
266
|
+
return /*#__PURE__*/_jsx(View, {
|
|
267
|
+
ref: ref,
|
|
268
|
+
className: slots.root({
|
|
269
|
+
className
|
|
270
|
+
}),
|
|
271
|
+
...props,
|
|
272
|
+
children: /*#__PURE__*/_jsx(View, {
|
|
273
|
+
className: slots.empty(),
|
|
274
|
+
children: /*#__PURE__*/_jsx(Text, {
|
|
275
|
+
size: "sm",
|
|
276
|
+
muted: true,
|
|
277
|
+
children: emptyText
|
|
278
|
+
})
|
|
279
|
+
})
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Second, first, third. With fewer than three the missing seats are left
|
|
284
|
+
// out rather than drawn empty.
|
|
285
|
+
const seats = [top[1], top[0], top[2]].map((item, slot) => item ? {
|
|
286
|
+
item,
|
|
287
|
+
place: [2, 1, 3][slot]
|
|
288
|
+
} : null).filter(seat => !!seat);
|
|
289
|
+
const heights = podiumHeights(seats.map(s => s.item.entry.value), seats.map(s => s.item.rank), order === 'asc' ? 'rank' : podiumScale);
|
|
290
|
+
const renderRow = (item, index) => {
|
|
291
|
+
const label = formatValue(item.entry.value);
|
|
292
|
+
const highlighted = item.entry.id === highlightId;
|
|
293
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
294
|
+
children: [index > 0 ? /*#__PURE__*/_jsx(View, {
|
|
295
|
+
className: slots.rowDivider()
|
|
296
|
+
}) : null, /*#__PURE__*/_jsxs(Slot, {
|
|
297
|
+
onPress: press(item),
|
|
298
|
+
label: describe(item, label, unit),
|
|
299
|
+
className: cn(slots.row(), highlighted && 'bg-primary/10'),
|
|
300
|
+
children: [/*#__PURE__*/_jsx(Text, {
|
|
301
|
+
className: cn(slots.rank(), highlighted && 'text-primary'),
|
|
302
|
+
children: item.rank
|
|
303
|
+
}), /*#__PURE__*/_jsx(Avatar, {
|
|
304
|
+
size: "sm",
|
|
305
|
+
source: toSource(item.entry.avatar),
|
|
306
|
+
fallback: initials(item.entry.name)
|
|
307
|
+
}), /*#__PURE__*/_jsxs(View, {
|
|
308
|
+
className: slots.rowText(),
|
|
309
|
+
children: [/*#__PURE__*/_jsx(Text, {
|
|
310
|
+
size: "sm",
|
|
311
|
+
weight: "medium",
|
|
312
|
+
numberOfLines: 1,
|
|
313
|
+
children: item.entry.name
|
|
314
|
+
}), item.entry.subtitle ? /*#__PURE__*/_jsx(Text, {
|
|
315
|
+
size: "xs",
|
|
316
|
+
muted: true,
|
|
317
|
+
numberOfLines: 1,
|
|
318
|
+
children: item.entry.subtitle
|
|
319
|
+
}) : null]
|
|
320
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
321
|
+
className: slots.value(),
|
|
322
|
+
children: label
|
|
323
|
+
}), /*#__PURE__*/_jsx(ChangeLabel, {
|
|
324
|
+
change: item.entry.change
|
|
325
|
+
})]
|
|
326
|
+
})]
|
|
327
|
+
}, item.entry.id);
|
|
328
|
+
};
|
|
329
|
+
return /*#__PURE__*/_jsxs(View, {
|
|
330
|
+
ref: ref,
|
|
331
|
+
className: slots.root({
|
|
332
|
+
className
|
|
333
|
+
}),
|
|
334
|
+
...props,
|
|
335
|
+
children: [podium === 'bars' && seats.length > 0 ? /*#__PURE__*/_jsx(View, {
|
|
336
|
+
className: slots.podium(),
|
|
337
|
+
children: seats.map(({
|
|
338
|
+
item,
|
|
339
|
+
place
|
|
340
|
+
}, i) => {
|
|
341
|
+
const label = formatValue(item.entry.value);
|
|
342
|
+
return /*#__PURE__*/_jsxs(Slot, {
|
|
343
|
+
onPress: press(item),
|
|
344
|
+
label: describe(item, label, unit),
|
|
345
|
+
className: slots.column(),
|
|
346
|
+
children: [/*#__PURE__*/_jsxs(View, {
|
|
347
|
+
className: slots.person(),
|
|
348
|
+
children: [/*#__PURE__*/_jsxs(View, {
|
|
349
|
+
className: "mb-1.5",
|
|
350
|
+
children: [/*#__PURE__*/_jsx(Avatar, {
|
|
351
|
+
size: place === 1 ? 'lg' : 'md',
|
|
352
|
+
source: toSource(item.entry.avatar),
|
|
353
|
+
fallback: initials(item.entry.name),
|
|
354
|
+
className: cn(place === 1 && 'border-2 border-primary', item.entry.id === highlightId && place !== 1 && 'border-2 border-primary/60')
|
|
355
|
+
}), /*#__PURE__*/_jsx(RankBadge, {
|
|
356
|
+
place: place,
|
|
357
|
+
rank: item.rank
|
|
358
|
+
})]
|
|
359
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
360
|
+
size: "sm",
|
|
361
|
+
weight: "semibold",
|
|
362
|
+
numberOfLines: 1,
|
|
363
|
+
className: "text-center",
|
|
364
|
+
children: item.entry.name
|
|
365
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
366
|
+
size: "xs",
|
|
367
|
+
muted: true,
|
|
368
|
+
numberOfLines: 1,
|
|
369
|
+
className: "tabular-nums",
|
|
370
|
+
children: label
|
|
371
|
+
})]
|
|
372
|
+
}), /*#__PURE__*/_jsx(PodiumBar, {
|
|
373
|
+
place: place,
|
|
374
|
+
rank: item.rank,
|
|
375
|
+
height: Math.round(podiumHeight * heights[i]),
|
|
376
|
+
delay: (3 - place) * GROW_STAGGER
|
|
377
|
+
})]
|
|
378
|
+
}, item.entry.id);
|
|
379
|
+
})
|
|
380
|
+
}) : null, podium === 'cards' && seats.length > 0 ? /*#__PURE__*/_jsx(View, {
|
|
381
|
+
className: "flex-row items-end gap-2",
|
|
382
|
+
children: seats.map(({
|
|
383
|
+
item,
|
|
384
|
+
place
|
|
385
|
+
}) => {
|
|
386
|
+
const label = formatValue(item.entry.value);
|
|
387
|
+
return /*#__PURE__*/_jsxs(Slot, {
|
|
388
|
+
onPress: press(item),
|
|
389
|
+
label: describe(item, label, unit),
|
|
390
|
+
className: cn(slots.card(), place === 1 && 'border-primary pb-5 pt-5 shadow-sm', item.entry.id === highlightId && place !== 1 && 'border-primary/40'),
|
|
391
|
+
children: [/*#__PURE__*/_jsxs(View, {
|
|
392
|
+
className: "mb-1.5",
|
|
393
|
+
children: [/*#__PURE__*/_jsx(Avatar, {
|
|
394
|
+
size: place === 1 ? 'lg' : 'md',
|
|
395
|
+
source: toSource(item.entry.avatar),
|
|
396
|
+
fallback: initials(item.entry.name),
|
|
397
|
+
className: cn(place === 1 && 'border-2 border-primary')
|
|
398
|
+
}), /*#__PURE__*/_jsx(RankBadge, {
|
|
399
|
+
place: place,
|
|
400
|
+
rank: item.rank
|
|
401
|
+
})]
|
|
402
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
403
|
+
size: "sm",
|
|
404
|
+
weight: "semibold",
|
|
405
|
+
numberOfLines: 1,
|
|
406
|
+
className: "text-center",
|
|
407
|
+
children: item.entry.name
|
|
408
|
+
}), /*#__PURE__*/_jsx(Text, {
|
|
409
|
+
size: place === 1 ? 'base' : 'sm',
|
|
410
|
+
weight: "bold",
|
|
411
|
+
numberOfLines: 1,
|
|
412
|
+
className: cn('tabular-nums', place === 1 && 'text-primary'),
|
|
413
|
+
children: label
|
|
414
|
+
}), item.entry.subtitle ? /*#__PURE__*/_jsx(Text, {
|
|
415
|
+
size: "xs",
|
|
416
|
+
muted: true,
|
|
417
|
+
numberOfLines: 1,
|
|
418
|
+
children: item.entry.subtitle
|
|
419
|
+
}) : null]
|
|
420
|
+
}, item.entry.id);
|
|
421
|
+
})
|
|
422
|
+
}) : null, rest.length > 0 || pinned ? /*#__PURE__*/_jsxs(View, {
|
|
423
|
+
className: slots.list(),
|
|
424
|
+
accessibilityRole: "list",
|
|
425
|
+
children: [rest.map(renderRow), pinned ? /*#__PURE__*/_jsxs(_Fragment, {
|
|
426
|
+
children: [rest.length > 0 ? /*#__PURE__*/_jsxs(View, {
|
|
427
|
+
className: slots.gap(),
|
|
428
|
+
importantForAccessibility: "no-hide-descendants",
|
|
429
|
+
children: [/*#__PURE__*/_jsx(View, {
|
|
430
|
+
className: slots.gapDot()
|
|
431
|
+
}), /*#__PURE__*/_jsx(View, {
|
|
432
|
+
className: slots.gapDot()
|
|
433
|
+
}), /*#__PURE__*/_jsx(View, {
|
|
434
|
+
className: slots.gapDot()
|
|
435
|
+
})]
|
|
436
|
+
}) : null, renderRow(pinned, 0)]
|
|
437
|
+
}) : null]
|
|
438
|
+
}) : null]
|
|
439
|
+
});
|
|
440
|
+
});
|
|
441
|
+
export const Leaderboard = LeaderboardRoot;
|
|
442
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["forwardRef","useEffect","useMemo","Pressable","View","Animated","useAnimatedStyle","useReducedMotion","useSharedValue","withDelay","withTiming","Easing","tv","useCSSVariable","ArrowDownIcon","ArrowUpIcon","Text","cn","Avatar","podiumHeights","rankEntries","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","GROW_DURATION","GROW_STAGGER","leaderboardVariants","slots","root","podium","column","person","rankBadge","bar","card","list","row","rowDivider","rank","rowText","value","change","gap","gapDot","empty","PLACE","badge","initials","name","parts","trim","split","filter","Boolean","first","last","length","toUpperCase","toSource","avatar","uri","defaultFormat","toLocaleString","describe","entry","tied","label","unit","place","subtitle","splice","n","Math","abs","push","join","Slot","onPress","className","children","accessible","accessibilityRole","accessibilityLabel","PodiumBar","height","delay","reduced","grown","duration","easing","out","cubic","style","numeral","opacity","min","max","size","weight","RankBadge","ChangeLabel","success","destructive","undefined","muted","up","tint","color","Arrow","strokeWidth","LeaderboardRoot","Leaderboard","data","order","podiumScale","podiumHeight","limit","highlightId","formatValue","onPressEntry","emptyText","props","ref","ranked","shown","slice","pinned","some","r","id","find","top","rest","press","item","seats","map","slot","seat","heights","s","renderRow","index","highlighted","source","fallback","numberOfLines","i","round","importantForAccessibility"],"sourceRoot":"../../../../src","sources":["components/leaderboard/index.tsx"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,UAAU,EAAEC,SAAS,EAAEC,OAAO,QAAQ,OAAO;AACtD,SACEC,SAAS,EACTC,IAAI,QAGC,cAAc;AACrB,OAAOC,QAAQ,IACbC,gBAAgB,EAChBC,gBAAgB,EAChBC,cAAc,EACdC,SAAS,EACTC,UAAU,EACVC,MAAM,QACD,yBAAyB;AAChC,SAASC,EAAE,QAAQ,mBAAmB;AACtC,SAASC,cAAc,QAAQ,SAAS;AACxC,SAASC,aAAa,EAAEC,WAAW,QAAQ,sBAAa;AACxD,SAASC,IAAI,QAAQ,0BAAuB;AAC5C,SAASC,EAAE,QAAQ,mBAAgB;AACnC,SAASC,MAAM,QAAQ,oBAAW;AAClC,SAASC,aAAa,EAAEC,WAAW,QAAqB,uBAAoB;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA,EAAAC,QAAA,IAAAC,SAAA;AAE7E,SAASN,WAAW,QAAQ,uBAAoB;AAGhD;AACA,MAAMO,aAAa,GAAG,GAAG;AACzB;AACA,MAAMC,YAAY,GAAG,GAAG;AAExB,MAAMC,mBAAmB,GAAGjB,EAAE,CAAC;EAC7BkB,KAAK,EAAE;IACLC,IAAI,EAAE,cAAc;IACpBC,MAAM,EAAE,+BAA+B;IACvCC,MAAM,EAAE,qBAAqB;IAC7BC,MAAM,EAAE,yBAAyB;IACjCC,SAAS,EACP,uHAAuH;IACzHC,GAAG,EAA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I;UAAC6E,SAAS,EAAEnD,KAAK,CAACe,GAAG,CAAC,CAAE;UAAC2G,yBAAyB,EAAC,qBAAqB;UAAAtE,QAAA,gBAC3E5D,IAAA,CAAClB,IAAI;YAAC6E,SAAS,EAAEnD,KAAK,CAACgB,MAAM,CAAC;UAAE,CAAE,CAAC,eACnCxB,IAAA,CAAClB,IAAI;YAAC6E,SAAS,EAAEnD,KAAK,CAACgB,MAAM,CAAC;UAAE,CAAE,CAAC,eACnCxB,IAAA,CAAClB,IAAI;YAAC6E,SAAS,EAAEnD,KAAK,CAACgB,MAAM,CAAC;UAAE,CAAE,CAAC;QAAA,CAC/B,CAAC,GACL,IAAI,EACPkG,SAAS,CAACf,MAAM,EAAE,CAAC,CAAC;MAAA,CACrB,CAAC,GACD,IAAI;IAAA,CACJ,CAAC,GACL,IAAI;EAAA,CACJ,CAAC;AAEX,CAAC,CAAC;AAEF,OAAO,MAAMf,WAAW,GAAGD,eAAe","ignoreList":[]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Ranking for `Leaderboard`, kept apart from the views so it can be tested
|
|
5
|
+
* without mounting anything.
|
|
6
|
+
*
|
|
7
|
+
* Ties share a place and the next place is skipped — 1, 2, 2, 4. That is how
|
|
8
|
+
* a scoreboard is read: two people on the same score are both second, and the
|
|
9
|
+
* one below them is fourth, because three people beat them. Numbering the
|
|
10
|
+
* next one third would claim a place nobody below a tie can hold.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Sorts by value and assigns competition ranks.
|
|
15
|
+
*
|
|
16
|
+
* `desc` puts the highest value first — points, revenue, steps. `asc` puts
|
|
17
|
+
* the lowest first, for a race time or a golf score. Entries whose value is
|
|
18
|
+
* not a finite number are dropped rather than sorted to an arbitrary end,
|
|
19
|
+
* since a row with no score has no place to be ranked at. The sort is stable,
|
|
20
|
+
* so equal values keep the order they were passed in.
|
|
21
|
+
*/
|
|
22
|
+
export function rankEntries(data, order = 'desc') {
|
|
23
|
+
const sign = order === 'asc' ? 1 : -1;
|
|
24
|
+
const sorted = data.filter(entry => Number.isFinite(entry.value)).map((entry, index) => ({
|
|
25
|
+
entry,
|
|
26
|
+
index
|
|
27
|
+
})).sort((a, b) => sign * (a.entry.value - b.entry.value) || a.index - b.index).map(({
|
|
28
|
+
entry
|
|
29
|
+
}) => entry);
|
|
30
|
+
const ranked = [];
|
|
31
|
+
sorted.forEach((entry, index) => {
|
|
32
|
+
const previous = ranked[index - 1];
|
|
33
|
+
const rank = previous && previous.entry.value === entry.value ? previous.rank : index + 1;
|
|
34
|
+
ranked.push({
|
|
35
|
+
entry,
|
|
36
|
+
rank,
|
|
37
|
+
tied: false
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
for (let i = 0; i < ranked.length; i += 1) {
|
|
41
|
+
const current = ranked[i];
|
|
42
|
+
current.tied = ranked[i - 1]?.rank === current.rank || ranked[i + 1]?.rank === current.rank;
|
|
43
|
+
}
|
|
44
|
+
return ranked;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Bar heights for the podium, as fractions of the tallest bar.
|
|
49
|
+
*
|
|
50
|
+
* `value` scales each bar by its value against the leader's, so a close race
|
|
51
|
+
* looks close. A floor keeps third place a bar rather than a sliver when the
|
|
52
|
+
* leader is far ahead. `rank` steps the heights by place and ignores the
|
|
53
|
+
* values — the only honest choice for `asc`, where the best value is the
|
|
54
|
+
* smallest and a bar proportional to it would be shortest.
|
|
55
|
+
*/
|
|
56
|
+
export function podiumHeights(values, ranks, scale, floor = 0.4) {
|
|
57
|
+
if (scale === 'rank') {
|
|
58
|
+
const steps = [1, 0.74, 0.56];
|
|
59
|
+
return ranks.map(rank => steps[Math.min(rank, 3) - 1] ?? steps[2]);
|
|
60
|
+
}
|
|
61
|
+
const peak = Math.max(...values.map(value => Math.abs(value)), 0);
|
|
62
|
+
if (peak === 0) return values.map(() => 1);
|
|
63
|
+
return values.map(value => floor + (1 - floor) * (Math.abs(value) / peak));
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=leaderboard-rank.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["rankEntries","data","order","sign","sorted","filter","entry","Number","isFinite","value","map","index","sort","a","b","ranked","forEach","previous","rank","push","tied","i","length","current","podiumHeights","values","ranks","scale","floor","steps","Math","min","peak","max","abs"],"sourceRoot":"../../../../src","sources":["components/leaderboard/leaderboard-rank.ts"],"mappings":";;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAeA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,WAAWA,CACzBC,IAAkB,EAClBC,KAAqB,GAAG,MAAM,EACjB;EACb,MAAMC,IAAI,GAAGD,KAAK,KAAK,KAAK,GAAG,CAAC,GAAG,CAAC,CAAC;EACrC,MAAME,MAAM,GAAGH,IAAI,CAChBI,MAAM,CAAEC,KAAK,IAAKC,MAAM,CAACC,QAAQ,CAACF,KAAK,CAACG,KAAK,CAAC,CAAC,CAC/CC,GAAG,CAAC,CAACJ,KAAK,EAAEK,KAAK,MAAM;IAAEL,KAAK;IAAEK;EAAM,CAAC,CAAC,CAAC,CACzCC,IAAI,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAKX,IAAI,IAAIU,CAAC,CAACP,KAAK,CAACG,KAAK,GAAGK,CAAC,CAACR,KAAK,CAACG,KAAK,CAAC,IAAII,CAAC,CAACF,KAAK,GAAGG,CAAC,CAACH,KAAK,CAAC,CAC3ED,GAAG,CAAC,CAAC;IAAEJ;EAAM,CAAC,KAAKA,KAAK,CAAC;EAE5B,MAAMS,MAAmB,GAAG,EAAE;EAC9BX,MAAM,CAACY,OAAO,CAAC,CAACV,KAAK,EAAEK,KAAK,KAAK;IAC/B,MAAMM,QAAQ,GAAGF,MAAM,CAACJ,KAAK,GAAG,CAAC,CAAC;IAClC,MAAMO,I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