@tastic/profile 0.14.0 → 0.15.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tastic/profile",
3
- "version": "0.14.0",
3
+ "version": "0.15.0",
4
4
  "description": "Player profile identity for local-multiplayer React Native games: a saved name/color/tag a player selects per seat, with a picker, an inline-editable roster screen, and a reusable identity badge, deliberately blind to any app-specific fields (control scheme, stats) an app layers on top",
5
5
  "keywords": [
6
6
  "react-native",
@@ -63,15 +63,15 @@
63
63
  "prettier": "@infinitetoken/eslint-config/prettier",
64
64
  "devDependencies": {
65
65
  "@infinitetoken/eslint-config": "0.2.0",
66
- "@infinitetoken/jest-config": "^0.4.0",
67
- "@infinitetoken/tsconfig": "^0.5.0",
68
- "@rific/auto-paper": "^0.13.2",
66
+ "@infinitetoken/jest-config": "^0.5.2",
67
+ "@infinitetoken/tsconfig": "^0.6.0",
68
+ "@rific/auto-paper": "^0.13.3",
69
69
  "@rific/core": "^0.3.1",
70
70
  "@rific/feedback-press": "^0.13.0",
71
71
  "@rific/focus-chain": "^0.4.8",
72
- "@rific/toaster": "^0.8.0",
72
+ "@rific/toaster": "^0.8.1",
73
73
  "@tastic/core": "^0.14.0",
74
- "@tastic/hud": "^0.19.0",
74
+ "@tastic/hud": "^0.20.0",
75
75
  "@testing-library/dom": "^10.4.1",
76
76
  "@testing-library/react": "^16.3.2",
77
77
  "@types/jest": "^30.0.0",
@@ -79,13 +79,13 @@
79
79
  "eslint": "^9.39.4",
80
80
  "eslint-plugin-react-hooks": "^7.1.1",
81
81
  "eslint-plugin-react-native": "^5.0.0",
82
- "expo-modules-core": "^57.0.14",
82
+ "expo-modules-core": "^58.0.21",
83
83
  "jest": "^30.4.2",
84
84
  "jest-environment-jsdom": "^30.4.1",
85
85
  "prettier": "^3.8.3",
86
86
  "react": "^19.0.0",
87
87
  "react-dom": "^19.0.0",
88
- "react-native": "^0.86.3",
88
+ "react-native": "^0.88.0",
89
89
  "react-native-paper": "^5.15.2",
90
90
  "react-native-safe-area-context": "^5.0.0",
91
91
  "tsup": "^8.0.0",
@@ -0,0 +1,64 @@
1
+ import { PopoverHost, PopoverRotation } from '@tastic/hud'
2
+ import { type StyleProp, type ViewStyle } from 'react-native'
3
+
4
+ import { IconRow, pickerContentSize, PickerMenu, type ProfilePickerAlignResult, type ProfilePickerColorSection, type ProfilePickerContentSize } from './PickerMenu'
5
+
6
+ export interface OptionPickerOption<T extends string> {
7
+ value: T
8
+ label: string
9
+ icon?: string
10
+ }
11
+
12
+ // The popover's content footprint: one row per option, plus (with a `colorSection`) the Color row,
13
+ // or the color page if that's taller - the same formula as getProfilePickerContentSize, for a host
14
+ // that places this picker itself through `alignOverride` (a @tastic/split-screen zone's
15
+ // useZoneClampedAlign, for one).
16
+ export function getOptionPickerContentSize(optionCount: number, colorSection?: Pick<ProfilePickerColorSection, 'swatches' | 'caption'>): ProfilePickerContentSize {
17
+ return pickerContentSize(optionCount, colorSection)
18
+ }
19
+
20
+ interface OptionPickerProps<T extends string> {
21
+ // The popover id this trigger toggles on `host`.
22
+ id: string
23
+ host: PopoverHost
24
+ options: OptionPickerOption<T>[]
25
+ value: T
26
+ onChange: (value: T) => void
27
+ // The seat's live color: the chip, the menu's border and caret, and the selected row's fill.
28
+ color: string
29
+ dark: boolean
30
+ // The chip's glyph (e.g. a robot for a CPU seat).
31
+ icon: string
32
+ // An option without its own icon falls back to this one in its row. Defaults to `icon`.
33
+ rowIcon?: string
34
+ // The same Color row and page as ProfilePicker's `colorSection`.
35
+ colorSection?: ProfilePickerColorSection
36
+ // See ProfilePicker's own props of the same names.
37
+ align?: 'left' | 'right' | 'center'
38
+ alignOverride?: ProfilePickerAlignResult
39
+ rotation?: PopoverRotation
40
+ triggerStyle?: StyleProp<ViewStyle>
41
+ }
42
+
43
+ // ProfilePicker's chip button and dropdown for a seat with no profile: a list of options (a CPU
44
+ // seat's difficulties) under the same Color row, so a CPU seat is the same one control as a
45
+ // player's. The button leads with a chip in `color` with `icon`, then the selected option's label
46
+ // and a chevron. Picking an option closes the dropdown; the Color row works exactly as it does in
47
+ // ProfilePicker (picking a swatch stays on the color page).
48
+ export function OptionPicker<T extends string>({ id, host, options, value, onChange, color, dark, icon, rowIcon = icon, colorSection, align, alignOverride, rotation = 0, triggerStyle }: OptionPickerProps<T>) {
49
+ const fg = dark ? '#FFFFFF' : '#000000'
50
+ const selected = options.find((option) => option.value === value)
51
+
52
+ const handleSelect = (option: OptionPickerOption<T>) => {
53
+ onChange(option.value)
54
+ host.close()
55
+ }
56
+
57
+ return (
58
+ <PickerMenu id={id} host={host} color={color} dark={dark} label={selected?.label ?? ''} chip={{ icon }} colorSection={colorSection} contentSize={getOptionPickerContentSize(options.length, colorSection)} align={align} alignOverride={alignOverride} rotation={rotation} triggerStyle={triggerStyle}>
59
+ {options.map((option) => (
60
+ <IconRow key={option.value} icon={option.icon ?? rowIcon} label={option.label} selected={option.value === value} color={color} fg={fg} onPress={() => handleSelect(option)} />
61
+ ))}
62
+ </PickerMenu>
63
+ )
64
+ }
@@ -0,0 +1,481 @@
1
+ import { defaultColors, FadingScrollView, getContrastColor, type SeedColor } from '@rific/auto-paper'
2
+ import { TouchableRipple } from '@rific/feedback-press'
3
+ import { PopoverBody, PopoverHost, PopoverRotation, useAutoAlign } from '@tastic/hud'
4
+ import { ReactNode, RefObject, useState } from 'react'
5
+ import { type LayoutChangeEvent, type StyleProp, StyleSheet, View, type ViewStyle } from 'react-native'
6
+ import { Icon, Text } from 'react-native-paper'
7
+
8
+ import { IdentityChip } from './IdentityChip'
9
+
10
+ // The trigger and popover ProfilePicker and OptionPicker share: a name trigger (or the chip pill),
11
+ // a bordered menu of rows, and with a `colorSection` a Color row that swaps the menu for a page of
12
+ // swatches. Not exported from index.ts: each picker owns its own rows.
13
+
14
+ const TRIGGER_HEIGHT = 28
15
+ const POPOVER_WIDTH = 220
16
+ const ROW_HEIGHT = 36
17
+ const LIST_PADDING = 8
18
+ const MENU_BORDER_WIDTH = 2
19
+ // A row's own inset from the list's padded edge (`rowInner`'s paddingHorizontal); the color page
20
+ // lines its swatches up with it.
21
+ const ROW_INSET = 12
22
+ // The chip trigger (see `colorSection`): a CHIP_SIZE circle inside a pill padded by CHIP_TRIGGER_PADDING.
23
+ const CHIP_SIZE = 32
24
+ const CHIP_TRIGGER_PADDING = 6
25
+
26
+ // The color row and page (see `colorSection`). Every height here is fixed (explicit line heights),
27
+ // so pickerContentSize can size them exactly. Swatches are the same 28pt circles as
28
+ // @tastic/hud's InlineColorPicker, spread to span exactly the rows' content width (5 across, so
29
+ // 20 colors fill 4 full rows), with the same spacing between rows.
30
+ const SWATCH_SIZE = 28
31
+ const SWATCH_MIN_GAP = 6
32
+ // The Color row: a plain row's height, or taller with a caption line under the label.
33
+ const COLOR_ROW_CAPTIONED_HEIGHT = 48
34
+ const COLOR_LABEL_LINE = 18
35
+ const COLOR_CAPTION_LINE = 16
36
+ // The divider under the Color row: 1pt plus 4pt above and below, the same as the Manage divider.
37
+ const COLOR_ROW_DIVIDER = 9
38
+ // The color page: a back row, then the grid with this much space above and below it.
39
+ const GRID_TOP = 4
40
+ const GRID_BOTTOM = 8
41
+ const GRID_WIDTH = POPOVER_WIDTH - 2 * MENU_BORDER_WIDTH - 2 * LIST_PADDING - 2 * ROW_INSET
42
+ const GRID_COLUMNS = Math.floor((GRID_WIDTH + SWATCH_MIN_GAP) / (SWATCH_SIZE + SWATCH_MIN_GAP))
43
+ const GRID_GAP = (GRID_WIDTH - GRID_COLUMNS * SWATCH_SIZE) / (GRID_COLUMNS - 1)
44
+
45
+ // A color choice behind a row at the top of the popover (see ProfilePicker's `colorSection`).
46
+ export interface ProfilePickerColorSection {
47
+ // The raw seed color in effect - matched against each swatch's own value for the checkmark.
48
+ value: string
49
+ onChange: (hex: string) => void
50
+ // Transforms only what's drawn (each swatch's fill), leaving `value` and what `onChange` commits
51
+ // untouched - the same contract as @tastic/hud's InlineColorPicker `previewValue`, for a host
52
+ // that mutes or tints the seed before using it.
53
+ previewValue?: (hex: string) => string
54
+ swatches?: SeedColor[]
55
+ // The row's label, and the color page's heading. Defaults to 'Color'.
56
+ label?: string
57
+ // One short line under the row's label, e.g. where the color applies.
58
+ caption?: string
59
+ // Another seat's color, if any: its swatch stays in the grid but is disabled and marked with an
60
+ // X, the same as @tastic/hud's InlineColorPicker `takenValue`. Unless `allowSwapTaken` is set.
61
+ takenValue?: string
62
+ // Lets a press on the taken swatch pick it anyway (marked with a swap icon instead), for a host
63
+ // that swaps the two colors - when the other seat is the CPU, not a second person. Same as
64
+ // InlineColorPicker's `allowSwapTaken`.
65
+ allowSwapTaken?: boolean
66
+ }
67
+
68
+ // A complete placement decision for the popover: which way it opens, how tall it may grow, whether
69
+ // this open's measurement has landed yet, and the ref attached to the measured trigger.
70
+ // Structurally identical to @tastic/hud's own `AlignResult` (exported from hud >= 0.12.0, and the
71
+ // same shape `useAutoAlign` itself returns) - declared here rather than imported so this package's
72
+ // public types don't start requiring a newer @tastic/hud than its peer range already admits. A
73
+ // hud `AlignResult` (e.g. from `useZoneClampedAlign`) is assignable to this as-is.
74
+ export interface ProfilePickerAlignResult {
75
+ align: 'left' | 'right' | 'center'
76
+ verticalAlign: 'below' | 'above'
77
+ maxHeight: number
78
+ measured: boolean
79
+ triggerRef: RefObject<View | null>
80
+ }
81
+
82
+ export interface ProfilePickerContentSize {
83
+ width: number
84
+ height: number
85
+ }
86
+
87
+ function colorRowHeight(caption: string | undefined) {
88
+ return caption ? COLOR_ROW_CAPTIONED_HEIGHT : ROW_HEIGHT
89
+ }
90
+
91
+ // The color page's content: the back row and the grid.
92
+ function colorPageHeight(swatches: SeedColor[]) {
93
+ const rows = Math.ceil(swatches.length / GRID_COLUMNS)
94
+ return ROW_HEIGHT + GRID_TOP + rows * SWATCH_SIZE + (rows - 1) * GRID_GAP + GRID_BOTTOM
95
+ }
96
+
97
+ // The popover's content footprint for `rowCount` rows: always POPOVER_WIDTH wide, tall enough for
98
+ // the rows plus the list's own padding. With a `colorSection`, it's the taller of the popover's two
99
+ // pages, exactly: the list with the Color row and its divider on top, or the color page (a back row
100
+ // and the swatches), so one placement fits whichever page is showing. It leaves out the menu's 2pt
101
+ // border and the Manage divider, ~13pt in all, so treat it as a placement estimate, not a
102
+ // pixel-exact measurement. getProfilePickerContentSize and getOptionPickerContentSize count the
103
+ // rows for their own picker.
104
+ export function pickerContentSize(rowCount: number, colorSection?: Pick<ProfilePickerColorSection, 'swatches' | 'caption'>): ProfilePickerContentSize {
105
+ const list = rowCount * ROW_HEIGHT + (colorSection ? colorRowHeight(colorSection.caption) + COLOR_ROW_DIVIDER : 0)
106
+ const content = colorSection ? Math.max(list, colorPageHeight(colorSection.swatches ?? defaultColors)) : list
107
+ return { width: POPOVER_WIDTH, height: LIST_PADDING * 2 + content }
108
+ }
109
+
110
+ interface PickerMenuProps {
111
+ // The popover id this trigger toggles on `host`.
112
+ id: string
113
+ host: PopoverHost
114
+ // The seat/context's live color: the menu's border and caret, the plain trigger's label, the chip.
115
+ color: string
116
+ dark: boolean
117
+ // The trigger's text, uppercased here.
118
+ label: string
119
+ // Turns the trigger into the chip pill: a circle in `color` with `tag` (or `icon`), then the label
120
+ // and the chevron. Omit for the plain name trigger.
121
+ chip?: { tag?: string; icon: string }
122
+ colorSection?: ProfilePickerColorSection
123
+ // The color whose swatch carries a dot on the color page (see ColorPage).
124
+ homeColor?: string
125
+ // The list page's size, from pickerContentSize, for the automatic placement.
126
+ contentSize: ProfilePickerContentSize
127
+ align?: 'left' | 'right' | 'center'
128
+ alignOverride?: ProfilePickerAlignResult
129
+ rotation: PopoverRotation
130
+ triggerStyle?: StyleProp<ViewStyle>
131
+ // Pinned under the list page's rows, behind a divider (ProfilePicker's Manage row).
132
+ footer?: ReactNode
133
+ // The list page's rows.
134
+ children: ReactNode
135
+ }
136
+
137
+ export function PickerMenu({ id, host, color, dark, label, chip, colorSection, homeColor, contentSize, align: forcedAlign, alignOverride, rotation, triggerStyle, footer, children }: PickerMenuProps) {
138
+ const menuBg = dark ? '#000000' : '#FFFFFF'
139
+ const fg = dark ? '#FFFFFF' : '#000000'
140
+
141
+ const open = host.openId === id
142
+ // Always called, even when `alignOverride` is supplied and this result goes unused - hooks can't
143
+ // be conditional (see @tastic/hud's InlineColorPicker for the identical pattern). With an
144
+ // override its triggerRef is never attached, so this hook's own measurement is a no-op.
145
+ const auto = useAutoAlign(open, contentSize.width, contentSize.height, rotation)
146
+ const placement = alignOverride ?? auto
147
+ const { maxHeight, measured, triggerRef, verticalAlign } = placement
148
+ const align = forcedAlign ?? placement.align
149
+
150
+ // The chip trigger is a whole pill, so the caret points at its middle: PopoverBody places the
151
+ // caret half a `triggerSize` in from the side the popover is aligned to, so the pill's own width
152
+ // centers it whichever way the popover opens. The plain trigger keeps TRIGGER_HEIGHT, as before.
153
+ const chipTrigger = !!chip
154
+ const [triggerWidth, setTriggerWidth] = useState(0)
155
+ const handleAnchorLayout = chipTrigger ? (e: LayoutChangeEvent) => setTriggerWidth(e.nativeEvent.layout.width) : undefined
156
+ // Which page the popover shows. Reset on every press of the trigger, so an open always starts on
157
+ // the list (a press away closes the popover without coming back through here).
158
+ const [colorPage, setColorPage] = useState(false)
159
+ const showColorPage = !!colorSection && colorPage
160
+ const handleTriggerPress = () => {
161
+ setColorPage(false)
162
+ host.toggle(id)
163
+ }
164
+ const triggerLabel = label.toUpperCase()
165
+ // Shown on the list page only (see the footer below).
166
+ const showFooter = !!footer && !showColorPage
167
+
168
+ return (
169
+ <View style={[styles.anchor, open && styles.anchorOpen]} onLayout={handleAnchorLayout}>
170
+ <TouchableRipple onPress={handleTriggerPress} borderless={chipTrigger} style={[styles.trigger, chipTrigger && styles.chipTrigger, triggerStyle]} accessibilityRole='button' accessibilityLabel={triggerLabel}>
171
+ <View ref={triggerRef} collapsable={false} style={chipTrigger ? styles.chipTriggerInner : styles.triggerInner}>
172
+ {chip && <IdentityChip color={color} tag={chip.tag} icon={chip.icon} size={CHIP_SIZE} />}
173
+ {/* The chip trigger's name and chevron are plain fg: the chip carries the color, and a muted
174
+ color on the host's pill read dim. The plain trigger keeps the color, which is what tells a
175
+ multi-seat game's seats apart. */}
176
+ <Text style={[styles.triggerLabel, { color: chipTrigger ? fg : color }]} numberOfLines={1}>
177
+ {triggerLabel}
178
+ </Text>
179
+ <Icon source='menu-down' size={16} color={chipTrigger ? fg : color} />
180
+ </View>
181
+ </TouchableRipple>
182
+
183
+ {/* Gated on `measured`, not just `open` - see InlineColorPicker's identical fix. */}
184
+ <PopoverBody visible={open && measured} align={align} verticalAlign={verticalAlign} caretColor={menuBg} caretBorderColor={color} caretBorderWidth={MENU_BORDER_WIDTH} triggerSize={chipTrigger ? triggerWidth : TRIGGER_HEIGHT}>
185
+ {/* The box (background, border, max height) is a plain View around the scroller, so
186
+ FadingScrollView's edge fade - the same cue as a dialog's scrolling rows - masks only the
187
+ rows, never the menu's own border or background. */}
188
+ <View
189
+ style={[
190
+ styles.menu,
191
+ {
192
+ backgroundColor: menuBg,
193
+ borderColor: color,
194
+ width: POPOVER_WIDTH,
195
+ maxHeight
196
+ }
197
+ ]}
198
+ >
199
+ {/* Keyed by page, so swapping pages starts the new one scrolled to its top. */}
200
+ <FadingScrollView key={showColorPage ? 'color' : 'list'} contentContainerStyle={[styles.menuContent, showFooter && styles.menuContentAboveFooter]} showsVerticalScrollIndicator={false}>
201
+ {colorSection && colorPage ? (
202
+ <ColorPage section={colorSection} homeColor={homeColor} fg={fg} onBack={() => setColorPage(false)} />
203
+ ) : (
204
+ <>
205
+ {colorSection && <ColorRow section={colorSection} fg={fg} dividerColor={color} onPress={() => setColorPage(true)} />}
206
+ {children}
207
+ </>
208
+ )}
209
+ </FadingScrollView>
210
+ {/* The footer is pinned below the scrolling rows, the way a dialog's Done sits below its
211
+ rows: always reachable, with the rows fading out above its divider while there are more
212
+ below. Not on the color page, which only has the back row and the swatches. */}
213
+ {showFooter && (
214
+ <View style={styles.menuFooter}>
215
+ <View style={[styles.divider, { backgroundColor: color }]} />
216
+ {footer}
217
+ </View>
218
+ )}
219
+ </View>
220
+ </PopoverBody>
221
+ </View>
222
+ )
223
+ }
224
+
225
+ interface IconRowProps {
226
+ icon: string
227
+ label: string
228
+ // Fills the row with `color` (its icon and label then contrast against it).
229
+ selected: boolean
230
+ color: string
231
+ fg: string
232
+ disabled?: boolean
233
+ onPress: () => void
234
+ }
235
+
236
+ // A selectable row led by an icon: ProfilePicker's null/"guest" row, and every OptionPicker row.
237
+ // A selected row's own background fills entirely with its identity color - matching how a selected
238
+ // row reads elsewhere (see @tastic/hud's SectionedDropdown) rather than a checkmark bolted onto an
239
+ // otherwise-plain row.
240
+ export function IconRow({ icon, label, selected, color, fg, disabled = false, onPress }: IconRowProps) {
241
+ const textColor = selected ? getContrastColor(color) : fg
242
+ return (
243
+ <TouchableRipple disabled={disabled} onPress={onPress} style={[pickerMenuStyles.row, selected && { backgroundColor: color }]}>
244
+ <View style={[pickerMenuStyles.rowInner, disabled && pickerMenuStyles.rowDisabled]}>
245
+ {/* Unfilled, matching a selected profile row's own ProfileChip treatment - no background
246
+ circle, but still the same fixed-size slot every row's icon/chip sits in (see ProfileChip's
247
+ own doc), so this row's icon stays lined up with every other row regardless of selection. */}
248
+ <View style={styles.iconSlot}>
249
+ <Icon source={icon} size={13} color={textColor} />
250
+ </View>
251
+ <Text style={[pickerMenuStyles.rowLabel, { color: textColor }]} numberOfLines={1}>
252
+ {label}
253
+ </Text>
254
+ </View>
255
+ </TouchableRipple>
256
+ )
257
+ }
258
+
259
+ // The list page's top row: a swatch of the color in effect, the label (and caption), and a chevron
260
+ // to the color page. A divider sets it apart from the selectable rows under it.
261
+ function ColorRow({ section, fg, dividerColor, onPress }: { section: ProfilePickerColorSection; fg: string; dividerColor: string; onPress: () => void }) {
262
+ const { value, previewValue, label = 'Color', caption } = section
263
+ const drawn = previewValue ? previewValue(value) : value
264
+ return (
265
+ <>
266
+ <TouchableRipple onPress={onPress} style={[pickerMenuStyles.row, { height: colorRowHeight(caption) }]} accessibilityRole='button' accessibilityLabel={caption ? `${label}, ${caption}` : label}>
267
+ <View style={pickerMenuStyles.rowInner}>
268
+ <View style={[styles.colorRowSwatch, { backgroundColor: drawn }]} />
269
+ <View style={styles.colorRowText}>
270
+ <Text style={[styles.colorRowLabel, { color: fg }]} numberOfLines={1}>
271
+ {label}
272
+ </Text>
273
+ {caption ? (
274
+ <Text style={[styles.colorRowCaption, { color: fg }]} numberOfLines={1}>
275
+ {caption}
276
+ </Text>
277
+ ) : null}
278
+ </View>
279
+ <Icon source='chevron-right' size={18} color={fg} />
280
+ </View>
281
+ </TouchableRipple>
282
+ <View style={[styles.divider, { backgroundColor: dividerColor }]} />
283
+ </>
284
+ )
285
+ }
286
+
287
+ // The color page: a back row to the list, then the swatches. `homeColor` is the selected profile's
288
+ // own color: its swatch carries a dot, so a player who has picked something else can find their way
289
+ // back to it (the profile's row shows that color, but matching it to one of two similar swatches by
290
+ // eye is guesswork). The check takes the dot's place on the swatch in effect, so the dot only shows
291
+ // while the color in effect is another one. Another seat's color (`takenValue`) is marked with an X
292
+ // and disabled, or a swap icon when `allowSwapTaken` lets it be picked.
293
+ function ColorPage({ section, homeColor, fg, onBack }: { section: ProfilePickerColorSection; homeColor?: string; fg: string; onBack: () => void }) {
294
+ const { value, onChange, previewValue, swatches = defaultColors, label = 'Color', takenValue, allowSwapTaken } = section
295
+ const displayFor = previewValue ?? ((hex: string) => hex)
296
+ return (
297
+ <>
298
+ <TouchableRipple onPress={onBack} style={pickerMenuStyles.row} accessibilityRole='button' accessibilityLabel='Back'>
299
+ <View style={pickerMenuStyles.rowInner}>
300
+ <View style={styles.iconSlot}>
301
+ <Icon source='chevron-left' size={20} color={fg} />
302
+ </View>
303
+ <Text style={[styles.colorRowLabel, { color: fg }]} numberOfLines={1}>
304
+ {label}
305
+ </Text>
306
+ </View>
307
+ </TouchableRipple>
308
+ <View style={styles.swatches}>
309
+ {swatches.map((swatch) => {
310
+ const selected = swatch.value.toLowerCase() === value.toLowerCase()
311
+ const isHomeColor = !!homeColor && swatch.value.toLowerCase() === homeColor.toLowerCase()
312
+ const taken = !selected && !!takenValue && swatch.value.toLowerCase() === takenValue.toLowerCase()
313
+ const swappable = taken && !!allowSwapTaken
314
+ const swatchDisplay = displayFor(swatch.value)
315
+ const contrast = getContrastColor(swatchDisplay)
316
+ const accessibilityLabel = swappable ? `${swatch.label}, swap` : taken ? `${swatch.label}, taken` : isHomeColor ? `${swatch.label}, profile color` : swatch.label
317
+ // The same swatch as @tastic/hud's InlineColorPicker: a filled circle, the selected one
318
+ // ringed and checked, a taken one faded with an X.
319
+ return (
320
+ <TouchableRipple key={swatch.value} disabled={taken && !swappable} onPress={() => onChange(swatch.value)} borderless style={[styles.swatch, { backgroundColor: swatchDisplay }, selected && styles.swatchSelected, taken && !swappable && styles.swatchTaken]} accessibilityRole='button' accessibilityLabel={accessibilityLabel} accessibilityState={{ selected, disabled: taken && !swappable }}>
321
+ {selected ? <Icon source='check' size={16} color={contrast} /> : swappable ? <Icon source='swap-horizontal' size={16} color={contrast} /> : taken ? <Icon source='close' size={16} color={contrast} /> : isHomeColor ? <View style={[styles.homeDot, { backgroundColor: contrast }]} /> : <View />}
322
+ </TouchableRipple>
323
+ )
324
+ })}
325
+ </View>
326
+ </>
327
+ )
328
+ }
329
+
330
+ // The rows' own styles, shared with ProfilePicker's profile rows.
331
+ export const pickerMenuStyles = StyleSheet.create({
332
+ row: {
333
+ borderRadius: 8,
334
+ height: ROW_HEIGHT
335
+ },
336
+ rowDisabled: {
337
+ opacity: 0.35
338
+ },
339
+ rowInner: {
340
+ alignItems: 'center',
341
+ flexDirection: 'row',
342
+ flex: 1,
343
+ gap: 8,
344
+ paddingHorizontal: ROW_INSET
345
+ },
346
+ rowLabel: {
347
+ flex: 1,
348
+ fontSize: 14
349
+ }
350
+ })
351
+
352
+ const styles = StyleSheet.create({
353
+ anchor: {
354
+ position: 'relative'
355
+ },
356
+ // See InlineColorPicker's identical comment - React Native Web gives every position:'relative'
357
+ // view its own stacking context, so the elevation has to live on the anchor itself.
358
+ anchorOpen: {
359
+ zIndex: 100
360
+ },
361
+ // The pill, rounded at both ends. The host adds its own background through `triggerStyle`.
362
+ chipTrigger: {
363
+ borderRadius: (CHIP_SIZE + 2 * CHIP_TRIGGER_PADDING) / 2
364
+ },
365
+ // The padding lives on the measured view, not the pressable around it, so the placement measures
366
+ // the pill's real edge: measured from inside the padding, a popover opening toward a screen edge
367
+ // was sized as if the pill were 6pt further from it, and ran 2pt past that edge.
368
+ chipTriggerInner: {
369
+ alignItems: 'center',
370
+ flexDirection: 'row',
371
+ gap: 8,
372
+ height: CHIP_SIZE + 2 * CHIP_TRIGGER_PADDING,
373
+ paddingLeft: CHIP_TRIGGER_PADDING,
374
+ paddingRight: CHIP_TRIGGER_PADDING + 8
375
+ },
376
+ colorRowCaption: {
377
+ fontSize: 12,
378
+ lineHeight: COLOR_CAPTION_LINE,
379
+ opacity: 0.6
380
+ },
381
+ // A row's label, with a line height so the captioned Color row's height is exact.
382
+ colorRowLabel: {
383
+ fontSize: 14,
384
+ lineHeight: COLOR_LABEL_LINE
385
+ },
386
+ // The color in effect, in the same 22pt slot as every row's chip.
387
+ colorRowSwatch: {
388
+ borderRadius: 11,
389
+ height: 22,
390
+ width: 22
391
+ },
392
+ colorRowText: {
393
+ flex: 1
394
+ },
395
+ // Separates the footer (a navigation action) and the Color row from the selectable rows - a
396
+ // different kind of action, not just another row in the same list. Tinted with the seat's own color
397
+ // (passed in as backgroundColor) rather than a flat gray, matching the border/caret's own
398
+ // accent-tinted look.
399
+ divider: {
400
+ height: 1,
401
+ marginVertical: 4,
402
+ opacity: 0.25
403
+ },
404
+ // The selected profile's own color (see ColorPage).
405
+ homeDot: {
406
+ borderRadius: 4,
407
+ height: 8,
408
+ width: 8
409
+ },
410
+ // Matches ProfileChip's own default size/shape exactly (see IconRow's own render-site comment) -
411
+ // no backgroundColor, unlike ProfileChip's own default: an icon row has no identity color of its
412
+ // own to fill it with, and the render site colors the icon directly instead.
413
+ iconSlot: {
414
+ alignItems: 'center',
415
+ borderRadius: 11,
416
+ height: 22,
417
+ justifyContent: 'center',
418
+ width: 22
419
+ },
420
+ menu: {
421
+ borderRadius: 12,
422
+ borderWidth: MENU_BORDER_WIDTH,
423
+ elevation: 8,
424
+ shadowColor: '#000000',
425
+ shadowOffset: { height: 2, width: 0 },
426
+ shadowOpacity: 0.3,
427
+ shadowRadius: 8
428
+ },
429
+ // Padded on every side (not just top/bottom) - a selected row's own full-color background (see
430
+ // `row`'s borderRadius) needs real margin from the menu's own straight edges to read as a rounded
431
+ // pill instead of looking clipped against them.
432
+ menuContent: {
433
+ padding: LIST_PADDING
434
+ },
435
+ // With a footer pinned below, its own padding takes the bottom edge (same total height as before).
436
+ menuContentAboveFooter: {
437
+ paddingBottom: 0
438
+ },
439
+ menuFooter: {
440
+ paddingBottom: LIST_PADDING,
441
+ paddingHorizontal: LIST_PADDING
442
+ },
443
+ swatch: {
444
+ alignItems: 'center',
445
+ borderRadius: SWATCH_SIZE / 2,
446
+ height: SWATCH_SIZE,
447
+ justifyContent: 'center',
448
+ width: SWATCH_SIZE
449
+ },
450
+ swatchSelected: {
451
+ borderColor: '#ffffff',
452
+ borderWidth: 2
453
+ },
454
+ swatchTaken: {
455
+ opacity: 0.35
456
+ },
457
+ swatches: {
458
+ columnGap: GRID_GAP,
459
+ flexDirection: 'row',
460
+ flexWrap: 'wrap',
461
+ marginBottom: GRID_BOTTOM,
462
+ marginHorizontal: ROW_INSET,
463
+ marginTop: GRID_TOP,
464
+ rowGap: GRID_GAP,
465
+ width: GRID_WIDTH
466
+ },
467
+ trigger: {
468
+ alignSelf: 'flex-start'
469
+ },
470
+ triggerInner: {
471
+ alignItems: 'center',
472
+ flexDirection: 'row',
473
+ gap: 2,
474
+ height: TRIGGER_HEIGHT
475
+ },
476
+ triggerLabel: {
477
+ fontSize: 13,
478
+ fontWeight: '700',
479
+ letterSpacing: 1
480
+ }
481
+ })