jfs-components 0.1.2 → 0.1.8
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/CHANGELOG.md +29 -0
- package/lib/commonjs/components/AmountInput/AmountInput.js +8 -5
- package/lib/commonjs/components/BenefitCard/BenefitCard.js +231 -0
- package/lib/commonjs/components/CcCard/CcCard.js +470 -0
- package/lib/commonjs/components/Checkbox/Checkbox.js +4 -3
- package/lib/commonjs/components/CheckboxItem/CheckboxItem.js +4 -3
- package/lib/commonjs/components/CompareTable/CompareTable.js +372 -0
- package/lib/commonjs/components/ComparisonBar/ComparisonBar.js +266 -0
- package/lib/commonjs/components/DropdownInput/DropdownInput.js +35 -3
- package/lib/commonjs/components/FormField/FormField.js +4 -3
- package/lib/commonjs/components/InputSearch/InputSearch.js +6 -4
- package/lib/commonjs/components/NoteInput/NoteInput.js +6 -5
- package/lib/commonjs/components/PdpCcCard/PdpCcCard.js +273 -0
- package/lib/commonjs/components/ProductMerchandisingCard/GlassFill.js +263 -0
- package/lib/commonjs/components/ProductMerchandisingCard/GlassFill.web.js +116 -0
- package/lib/commonjs/components/ProductMerchandisingCard/ProductMerchandisingCard.js +353 -0
- package/lib/commonjs/components/ProjectionMarker/ProjectionMarker.js +161 -0
- package/lib/commonjs/components/Radio/Radio.js +5 -5
- package/lib/commonjs/components/Slider/Slider.js +473 -0
- package/lib/commonjs/components/TextInput/TextInput.js +13 -8
- package/lib/commonjs/components/TextSegment/TextSegment.js +118 -0
- package/lib/commonjs/components/index.js +63 -0
- package/lib/commonjs/design-tokens/Coin Variables-variables-full.json +1 -1
- package/lib/commonjs/design-tokens/figma-modes.generated.js +38 -9
- package/lib/commonjs/icons/registry.js +1 -1
- package/lib/commonjs/utils/react-utils.js +22 -0
- package/lib/module/components/AmountInput/AmountInput.js +6 -4
- package/lib/module/components/BenefitCard/BenefitCard.js +225 -0
- package/lib/module/components/CcCard/CcCard.js +464 -0
- package/lib/module/components/Checkbox/Checkbox.js +5 -4
- package/lib/module/components/CheckboxItem/CheckboxItem.js +5 -4
- package/lib/module/components/CompareTable/CompareTable.js +367 -0
- package/lib/module/components/ComparisonBar/ComparisonBar.js +260 -0
- package/lib/module/components/DropdownInput/DropdownInput.js +36 -4
- package/lib/module/components/FormField/FormField.js +5 -4
- package/lib/module/components/InputSearch/InputSearch.js +6 -4
- package/lib/module/components/NoteInput/NoteInput.js +7 -6
- package/lib/module/components/PdpCcCard/PdpCcCard.js +267 -0
- package/lib/module/components/ProductMerchandisingCard/GlassFill.js +257 -0
- package/lib/module/components/ProductMerchandisingCard/GlassFill.web.js +111 -0
- package/lib/module/components/ProductMerchandisingCard/ProductMerchandisingCard.js +347 -0
- package/lib/module/components/ProjectionMarker/ProjectionMarker.js +156 -0
- package/lib/module/components/Radio/Radio.js +5 -4
- package/lib/module/components/Slider/Slider.js +468 -0
- package/lib/module/components/TextInput/TextInput.js +15 -10
- package/lib/module/components/TextSegment/TextSegment.js +113 -0
- package/lib/module/components/index.js +9 -0
- package/lib/module/design-tokens/Coin Variables-variables-full.json +1 -1
- package/lib/module/design-tokens/figma-modes.generated.js +38 -9
- package/lib/module/icons/registry.js +1 -1
- package/lib/module/utils/react-utils.js +21 -0
- package/lib/typescript/src/components/AmountInput/AmountInput.d.ts +3 -2
- package/lib/typescript/src/components/BenefitCard/BenefitCard.d.ts +93 -0
- package/lib/typescript/src/components/CcCard/CcCard.d.ts +137 -0
- package/lib/typescript/src/components/Checkbox/Checkbox.d.ts +3 -2
- package/lib/typescript/src/components/CheckboxItem/CheckboxItem.d.ts +2 -2
- package/lib/typescript/src/components/CompareTable/CompareTable.d.ts +88 -0
- package/lib/typescript/src/components/ComparisonBar/ComparisonBar.d.ts +118 -0
- package/lib/typescript/src/components/DropdownInput/DropdownInput.d.ts +20 -1
- package/lib/typescript/src/components/FormField/FormField.d.ts +2 -2
- package/lib/typescript/src/components/InputSearch/InputSearch.d.ts +23 -2
- package/lib/typescript/src/components/NoteInput/NoteInput.d.ts +19 -2
- package/lib/typescript/src/components/PdpCcCard/PdpCcCard.d.ts +84 -0
- package/lib/typescript/src/components/ProductMerchandisingCard/GlassFill.d.ts +56 -0
- package/lib/typescript/src/components/ProductMerchandisingCard/GlassFill.web.d.ts +27 -0
- package/lib/typescript/src/components/ProductMerchandisingCard/ProductMerchandisingCard.d.ts +81 -0
- package/lib/typescript/src/components/ProjectionMarker/ProjectionMarker.d.ts +82 -0
- package/lib/typescript/src/components/Radio/Radio.d.ts +3 -2
- package/lib/typescript/src/components/RadioButton/RadioButton.d.ts +2 -2
- package/lib/typescript/src/components/Slider/Slider.d.ts +99 -0
- package/lib/typescript/src/components/TextInput/TextInput.d.ts +9 -29
- package/lib/typescript/src/components/TextSegment/TextSegment.d.ts +100 -0
- package/lib/typescript/src/components/index.d.ts +10 -1
- package/lib/typescript/src/design-tokens/figma-modes.generated.d.ts +22 -2
- package/lib/typescript/src/icons/registry.d.ts +1 -1
- package/lib/typescript/src/utils/react-utils.d.ts +10 -0
- package/package.json +2 -1
- package/src/components/AmountInput/AmountInput.tsx +7 -5
- package/src/components/BenefitCard/BenefitCard.tsx +309 -0
- package/src/components/CcCard/CcCard.tsx +598 -0
- package/src/components/Checkbox/Checkbox.tsx +5 -4
- package/src/components/CheckboxItem/CheckboxItem.tsx +5 -4
- package/src/components/CompareTable/CompareTable.tsx +477 -0
- package/src/components/ComparisonBar/ComparisonBar.tsx +356 -0
- package/src/components/DropdownInput/DropdownInput.tsx +55 -3
- package/src/components/FormField/FormField.tsx +5 -4
- package/src/components/InputSearch/InputSearch.tsx +8 -5
- package/src/components/NoteInput/NoteInput.tsx +8 -6
- package/src/components/PdpCcCard/PdpCcCard.tsx +356 -0
- package/src/components/ProductMerchandisingCard/GlassFill.tsx +276 -0
- package/src/components/ProductMerchandisingCard/GlassFill.web.tsx +127 -0
- package/src/components/ProductMerchandisingCard/ProductMerchandisingCard.tsx +423 -0
- package/src/components/ProjectionMarker/ProjectionMarker.tsx +277 -0
- package/src/components/Radio/Radio.tsx +5 -4
- package/src/components/Slider/Slider.tsx +628 -0
- package/src/components/TextInput/TextInput.tsx +15 -11
- package/src/components/TextSegment/TextSegment.tsx +166 -0
- package/src/components/index.ts +10 -1
- package/src/design-tokens/Coin Variables-variables-full.json +1 -1
- package/src/design-tokens/figma-modes.generated.ts +38 -9
- package/src/icons/registry.ts +1 -1
- package/src/utils/react-utils.ts +23 -0
- package/lib/typescript/scripts/extract-component-tokens.d.ts +0 -9
- package/lib/typescript/scripts/generate-component-docs.d.ts +0 -9
- package/lib/typescript/scripts/generate-icon-registry.d.ts +0 -3
- package/lib/typescript/scripts/generate-mode-types.d.ts +0 -2
- package/lib/typescript/scripts/retype-modes.d.cts +0 -2
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import React, { useMemo } from 'react'
|
|
2
|
+
import {
|
|
3
|
+
Pressable,
|
|
4
|
+
View,
|
|
5
|
+
type ImageSourcePropType,
|
|
6
|
+
type StyleProp,
|
|
7
|
+
type ViewStyle,
|
|
8
|
+
} from 'react-native'
|
|
9
|
+
import { getVariableByName } from '../../design-tokens/figma-variables-resolver'
|
|
10
|
+
import { useTokens } from '../../design-tokens/JFSThemeProvider'
|
|
11
|
+
import { EMPTY_MODES } from '../../utils/react-utils'
|
|
12
|
+
import { usePressableWebSupport } from '../../utils/web-platform-utils'
|
|
13
|
+
import Button from '../Button/Button'
|
|
14
|
+
import Image from '../Image/Image'
|
|
15
|
+
import IconCapsule from '../IconCapsule/IconCapsule'
|
|
16
|
+
import type { Modes } from '../../design-tokens'
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A single slot in the {@link ComparisonBar}. Each item is either empty (the
|
|
20
|
+
* "Add" state — a tappable `+` capsule) or filled with an image (the
|
|
21
|
+
* "Image Added" state — the image plus a dismiss capsule in the corner).
|
|
22
|
+
*
|
|
23
|
+
* The presence of {@link ComparisonBarItem.imageSource} is what toggles the
|
|
24
|
+
* state: provide a source to show the image, leave it `undefined`/`null` to
|
|
25
|
+
* show the empty add slot. This keeps the component fully controlled — the
|
|
26
|
+
* `ComparisonBar` never owns the image state itself, so the consumer decides
|
|
27
|
+
* (e.g. after opening a file/asset picker) when and how an item flips between
|
|
28
|
+
* the two states.
|
|
29
|
+
*/
|
|
30
|
+
export type ComparisonBarItem = {
|
|
31
|
+
/**
|
|
32
|
+
* Stable identifier for this slot. Returned to callbacks so the consumer
|
|
33
|
+
* can target the exact item that was interacted with. Falls back to the
|
|
34
|
+
* array index when omitted.
|
|
35
|
+
*/
|
|
36
|
+
id?: string | number
|
|
37
|
+
/**
|
|
38
|
+
* Image to render in the slot. When provided the slot renders in the
|
|
39
|
+
* "Image Added" state; when omitted/`null` it renders the empty "Add" state.
|
|
40
|
+
* Accepts the same shapes as the library `Image` component (remote URL
|
|
41
|
+
* string, `{ uri }`, or a `require()`d asset).
|
|
42
|
+
*/
|
|
43
|
+
imageSource?: ImageSourcePropType | string | null
|
|
44
|
+
/** Accessibility label for the slot. Defaults to a generic add/remove label. */
|
|
45
|
+
accessibilityLabel?: string
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export type ComparisonBarProps = {
|
|
49
|
+
/**
|
|
50
|
+
* The slots rendered before the Compare button. Each entry controls its own
|
|
51
|
+
* add/image state via {@link ComparisonBarItem.imageSource}.
|
|
52
|
+
*/
|
|
53
|
+
items: ComparisonBarItem[]
|
|
54
|
+
/**
|
|
55
|
+
* Fired when an empty (Add) slot is tapped. The consumer is expected to react
|
|
56
|
+
* by opening whatever picker is appropriate and then updating that item's
|
|
57
|
+
* `imageSource` to flip it into the "Image Added" state — the component does
|
|
58
|
+
* not know how images are sourced. Receives the item's `id` (or index when no
|
|
59
|
+
* id was supplied) and the slot index.
|
|
60
|
+
*/
|
|
61
|
+
onItemPress?: (id: ComparisonBarItem['id'], index: number) => void
|
|
62
|
+
/**
|
|
63
|
+
* Fired when a filled slot is tapped. For better mobile ergonomics the
|
|
64
|
+
* *entire* filled slot is the remove target (the dismiss capsule is just a
|
|
65
|
+
* visual affordance), so a fingertip anywhere on the item triggers this. The
|
|
66
|
+
* consumer is expected to clear that item's `imageSource` to return it to the
|
|
67
|
+
* "Add" state. Receives the item's `id` (or index) and the slot index.
|
|
68
|
+
*/
|
|
69
|
+
onItemRemove?: (id: ComparisonBarItem['id'], index: number) => void
|
|
70
|
+
/** Fired when the Compare button is pressed. */
|
|
71
|
+
onCompare?: () => void
|
|
72
|
+
/** Label for the trailing action button. Defaults to `"Compare"`. */
|
|
73
|
+
compareLabel?: string
|
|
74
|
+
/**
|
|
75
|
+
* Explicitly controls the Compare button's *functional* disabled state — a
|
|
76
|
+
* truly disabled button is non-interactive (its `onPress` never fires), not
|
|
77
|
+
* just dimmed. Note that `modes` only affects appearance, so dimming the
|
|
78
|
+
* button via tokens does NOT stop taps; that is what this prop is for.
|
|
79
|
+
*
|
|
80
|
+
* When provided (a boolean), it always wins over
|
|
81
|
+
* {@link ComparisonBarProps.disableCompareWhenEmpty}. Leave it `undefined`
|
|
82
|
+
* to fall back to the auto behavior.
|
|
83
|
+
*/
|
|
84
|
+
compareDisabled?: boolean
|
|
85
|
+
/**
|
|
86
|
+
* When `true` (default) the Compare button is automatically (and truly)
|
|
87
|
+
* disabled while no slot has an image — there is nothing to compare yet. Set
|
|
88
|
+
* to `false` to keep it tappable even when empty. Ignored when
|
|
89
|
+
* {@link ComparisonBarProps.compareDisabled} is set explicitly.
|
|
90
|
+
*/
|
|
91
|
+
disableCompareWhenEmpty?: boolean
|
|
92
|
+
/** Mode configuration passed to the token resolver. */
|
|
93
|
+
modes?: Modes
|
|
94
|
+
/** Style overrides for the outer floating card. */
|
|
95
|
+
style?: StyleProp<ViewStyle>
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const ITEM_WIDTH = 45
|
|
99
|
+
const ITEM_HEIGHT = 44
|
|
100
|
+
|
|
101
|
+
interface ComparisonBarTokens {
|
|
102
|
+
card: ViewStyle
|
|
103
|
+
item: ViewStyle
|
|
104
|
+
itemImageState: ViewStyle
|
|
105
|
+
imageRadius: number
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function resolveTokens(modes: Modes): ComparisonBarTokens {
|
|
109
|
+
const cardGap = (getVariableByName('compareFloatCard/gap', modes) ?? 12) as number
|
|
110
|
+
const cardPadH = (getVariableByName('compareFloatCard/padding/horizontal', modes) ?? 12) as number
|
|
111
|
+
const cardPadV = (getVariableByName('compareFloatCard/padding/vertical', modes) ?? 10) as number
|
|
112
|
+
const cardRadius = (getVariableByName('compareFloatCard/radius', modes) ?? 12) as number
|
|
113
|
+
const cardBackground = (getVariableByName('compareFloatCard/background', modes) ?? '#ffffff') as string
|
|
114
|
+
const cardBorderColor = (getVariableByName('compareFloatCard/border/color', modes) ?? '#f5f5f5') as string
|
|
115
|
+
|
|
116
|
+
const itemPadH = (getVariableByName('compareCardItem/padding/horizontal', modes) ?? 6) as number
|
|
117
|
+
const itemPadV = (getVariableByName('compareCardItem/padding/vertical', modes) ?? 8) as number
|
|
118
|
+
const itemRadius = (getVariableByName('compareCardItem/radius', modes) ?? 8) as number
|
|
119
|
+
const itemBackground = (getVariableByName('compareCardItem/background', modes) ?? '#ebebed') as string
|
|
120
|
+
|
|
121
|
+
const imageRadius = (getVariableByName('image/radius', modes) ?? 8) as number
|
|
122
|
+
|
|
123
|
+
return {
|
|
124
|
+
card: {
|
|
125
|
+
flexDirection: 'row',
|
|
126
|
+
alignItems: 'center',
|
|
127
|
+
gap: cardGap,
|
|
128
|
+
paddingHorizontal: cardPadH,
|
|
129
|
+
paddingVertical: cardPadV,
|
|
130
|
+
borderRadius: cardRadius,
|
|
131
|
+
borderWidth: 1,
|
|
132
|
+
borderColor: cardBorderColor,
|
|
133
|
+
backgroundColor: cardBackground,
|
|
134
|
+
alignSelf: 'flex-start',
|
|
135
|
+
},
|
|
136
|
+
item: {
|
|
137
|
+
width: ITEM_WIDTH,
|
|
138
|
+
height: ITEM_HEIGHT,
|
|
139
|
+
borderRadius: itemRadius,
|
|
140
|
+
backgroundColor: itemBackground,
|
|
141
|
+
paddingHorizontal: itemPadH,
|
|
142
|
+
paddingVertical: itemPadV,
|
|
143
|
+
alignItems: 'center',
|
|
144
|
+
justifyContent: 'center',
|
|
145
|
+
},
|
|
146
|
+
itemImageState: {
|
|
147
|
+
paddingHorizontal: itemPadH,
|
|
148
|
+
paddingVertical: itemPadV,
|
|
149
|
+
},
|
|
150
|
+
imageRadius,
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
type AdditemProps = {
|
|
155
|
+
item: ComparisonBarItem
|
|
156
|
+
index: number
|
|
157
|
+
tokens: ComparisonBarTokens
|
|
158
|
+
addCapsuleModes: Modes
|
|
159
|
+
closeCapsuleModes: Modes
|
|
160
|
+
onPress?: ComparisonBarProps['onItemPress']
|
|
161
|
+
onRemove?: ComparisonBarProps['onItemRemove']
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Internal slot renderer for {@link ComparisonBar}. Intentionally NOT exported
|
|
166
|
+
* — it is meaningless outside of a `ComparisonBar` (its layout, sizing and
|
|
167
|
+
* remove affordance all assume the surrounding card) and is kept private so
|
|
168
|
+
* the public surface stays a single, cohesive component.
|
|
169
|
+
*/
|
|
170
|
+
function Additem({ item, index, tokens, addCapsuleModes, closeCapsuleModes, onPress, onRemove }: AdditemProps) {
|
|
171
|
+
const hasImage = item.imageSource != null && item.imageSource !== ''
|
|
172
|
+
const id = item.id ?? index
|
|
173
|
+
|
|
174
|
+
const addWebProps = usePressableWebSupport({
|
|
175
|
+
restProps: {},
|
|
176
|
+
onPress: () => onPress?.(id, index),
|
|
177
|
+
disabled: false,
|
|
178
|
+
accessibilityLabel: item.accessibilityLabel ?? 'Add item to comparison',
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
const removeWebProps = usePressableWebSupport({
|
|
182
|
+
restProps: {},
|
|
183
|
+
onPress: () => onRemove?.(id, index),
|
|
184
|
+
disabled: false,
|
|
185
|
+
accessibilityLabel: item.accessibilityLabel ?? 'Remove item from comparison',
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
if (!hasImage) {
|
|
189
|
+
return (
|
|
190
|
+
<Pressable
|
|
191
|
+
style={tokens.item}
|
|
192
|
+
accessibilityRole="button"
|
|
193
|
+
accessibilityLabel={item.accessibilityLabel ?? 'Add item to comparison'}
|
|
194
|
+
onPress={() => onPress?.(id, index)}
|
|
195
|
+
{...addWebProps}
|
|
196
|
+
>
|
|
197
|
+
<IconCapsule iconName="ic_add" modes={addCapsuleModes} style={ADD_CAPSULE_STYLE} />
|
|
198
|
+
</Pressable>
|
|
199
|
+
)
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Mobile-first: the entire filled slot is the remove target, not just the
|
|
203
|
+
// tiny close capsule (which a fingertip struggles to hit). The capsule stays
|
|
204
|
+
// purely as a visual affordance and is marked non-interactive so it never
|
|
205
|
+
// intercepts the press from the surrounding Pressable.
|
|
206
|
+
return (
|
|
207
|
+
<Pressable
|
|
208
|
+
style={[tokens.item, tokens.itemImageState]}
|
|
209
|
+
accessibilityRole="button"
|
|
210
|
+
accessibilityLabel={item.accessibilityLabel ?? 'Remove item from comparison'}
|
|
211
|
+
onPress={() => onRemove?.(id, index)}
|
|
212
|
+
{...removeWebProps}
|
|
213
|
+
>
|
|
214
|
+
<Image
|
|
215
|
+
imageSource={item.imageSource as any}
|
|
216
|
+
width="100%"
|
|
217
|
+
height="100%"
|
|
218
|
+
borderRadius={tokens.imageRadius}
|
|
219
|
+
resizeMode="cover"
|
|
220
|
+
accessibilityLabel={item.accessibilityLabel ?? 'Comparison item image'}
|
|
221
|
+
/>
|
|
222
|
+
<View style={CLOSE_CAPSULE_WRAPPER_STYLE} pointerEvents="none">
|
|
223
|
+
<IconCapsule iconName="ic_close" modes={closeCapsuleModes} />
|
|
224
|
+
</View>
|
|
225
|
+
</Pressable>
|
|
226
|
+
)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// The Add capsule is the transparent IconCapsule variant from Figma (the gray
|
|
230
|
+
// item box is the visible surface); its size/icon come from the resolved
|
|
231
|
+
// `Icon Capsule Size: S` tokens, we only flatten the background/border here.
|
|
232
|
+
const ADD_CAPSULE_STYLE: ViewStyle = {
|
|
233
|
+
backgroundColor: 'transparent',
|
|
234
|
+
borderColor: 'transparent',
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
// Positions the dismiss IconCapsule in the slot's top-right corner. The capsule
|
|
238
|
+
// itself (size/background/icon) is fully token-driven via `closeCapsuleModes`.
|
|
239
|
+
const CLOSE_CAPSULE_WRAPPER_STYLE: ViewStyle = {
|
|
240
|
+
position: 'absolute',
|
|
241
|
+
top: 1,
|
|
242
|
+
right: 1,
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Mode overrides applied on top of the consumer's `modes` for each capsule.
|
|
246
|
+
// These mirror the Figma component's IconCapsule variant selections so the
|
|
247
|
+
// sizing and colours come from design tokens instead of magic numbers.
|
|
248
|
+
const ADD_CAPSULE_MODE_OVERRIDES: Modes = { 'Icon Capsule Size': 'XS' }
|
|
249
|
+
const CLOSE_CAPSULE_MODE_OVERRIDES: Modes = {
|
|
250
|
+
AppearanceBrand: 'Neutral',
|
|
251
|
+
Emphasis: 'Medium',
|
|
252
|
+
'Icon Capsule Size': 'XS',
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* ComparisonBar — a floating card that lets a user assemble a set of items to
|
|
257
|
+
* compare, then trigger the comparison.
|
|
258
|
+
*
|
|
259
|
+
* Each slot is fully controlled via its `imageSource`: an empty slot shows a
|
|
260
|
+
* tappable `+` (the "Add" state) and a filled slot shows the image with a
|
|
261
|
+
* dismiss capsule (the "Image Added" state). The component never sources or
|
|
262
|
+
* stores images itself — when an empty slot is pressed it fires `onItemPress`
|
|
263
|
+
* with the item's id/index so the consumer can open whatever picker is
|
|
264
|
+
* appropriate and then update that item's `imageSource` to flip its state.
|
|
265
|
+
* Tapping a filled slot (anywhere on it — a mobile-friendly hit target, with
|
|
266
|
+
* the dismiss capsule as a visual affordance) fires `onItemRemove` so the
|
|
267
|
+
* consumer can clear the source again.
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```tsx
|
|
271
|
+
* const [items, setItems] = useState<ComparisonBarItem[]>([
|
|
272
|
+
* { id: 'a' }, { id: 'b' }, { id: 'c' }, { id: 'd' },
|
|
273
|
+
* ])
|
|
274
|
+
*
|
|
275
|
+
* <ComparisonBar
|
|
276
|
+
* items={items}
|
|
277
|
+
* onItemPress={async (id) => {
|
|
278
|
+
* const uri = await openImagePicker()
|
|
279
|
+
* setItems(prev => prev.map(it => it.id === id ? { ...it, imageSource: uri } : it))
|
|
280
|
+
* }}
|
|
281
|
+
* onItemRemove={(id) =>
|
|
282
|
+
* setItems(prev => prev.map(it => it.id === id ? { ...it, imageSource: null } : it))
|
|
283
|
+
* }
|
|
284
|
+
* onCompare={runComparison}
|
|
285
|
+
* />
|
|
286
|
+
* ```
|
|
287
|
+
*/
|
|
288
|
+
function ComparisonBar({
|
|
289
|
+
items,
|
|
290
|
+
onItemPress,
|
|
291
|
+
onItemRemove,
|
|
292
|
+
onCompare,
|
|
293
|
+
compareLabel = 'Compare',
|
|
294
|
+
compareDisabled,
|
|
295
|
+
disableCompareWhenEmpty = true,
|
|
296
|
+
modes: propModes = EMPTY_MODES,
|
|
297
|
+
style,
|
|
298
|
+
}: ComparisonBarProps) {
|
|
299
|
+
const { modes: globalModes } = useTokens()
|
|
300
|
+
const modes = useMemo(
|
|
301
|
+
() =>
|
|
302
|
+
globalModes === EMPTY_MODES && propModes === EMPTY_MODES
|
|
303
|
+
? EMPTY_MODES
|
|
304
|
+
: { ...globalModes, ...propModes },
|
|
305
|
+
[globalModes, propModes]
|
|
306
|
+
)
|
|
307
|
+
|
|
308
|
+
const tokens = useMemo(() => resolveTokens(modes), [modes])
|
|
309
|
+
|
|
310
|
+
// Capsule modes = consumer modes + this component's fixed IconCapsule variant
|
|
311
|
+
// selections. Memoized so each `Additem`'s `IconCapsule` keeps a stable
|
|
312
|
+
// `modes` identity and hits the resolver cache.
|
|
313
|
+
const addCapsuleModes = useMemo(
|
|
314
|
+
() => ({ ...modes, ...ADD_CAPSULE_MODE_OVERRIDES }),
|
|
315
|
+
[modes]
|
|
316
|
+
)
|
|
317
|
+
const closeCapsuleModes = useMemo(
|
|
318
|
+
() => ({ ...modes, ...CLOSE_CAPSULE_MODE_OVERRIDES }),
|
|
319
|
+
[modes]
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
// An explicit `compareDisabled` always wins (functional disable — the tap is
|
|
323
|
+
// truly blocked, not merely dimmed). Otherwise auto-disable while no slot has
|
|
324
|
+
// an image, since there is nothing to compare yet.
|
|
325
|
+
const hasAnyImage = useMemo(
|
|
326
|
+
() => items.some((it) => it.imageSource != null && it.imageSource !== ''),
|
|
327
|
+
[items]
|
|
328
|
+
)
|
|
329
|
+
const isCompareDisabled =
|
|
330
|
+
compareDisabled ?? (disableCompareWhenEmpty && !hasAnyImage)
|
|
331
|
+
|
|
332
|
+
return (
|
|
333
|
+
<View style={[tokens.card, style]}>
|
|
334
|
+
{items.map((item, index) => (
|
|
335
|
+
<Additem
|
|
336
|
+
key={item.id ?? index}
|
|
337
|
+
item={item}
|
|
338
|
+
index={index}
|
|
339
|
+
tokens={tokens}
|
|
340
|
+
addCapsuleModes={addCapsuleModes}
|
|
341
|
+
closeCapsuleModes={closeCapsuleModes}
|
|
342
|
+
onPress={onItemPress}
|
|
343
|
+
onRemove={onItemRemove}
|
|
344
|
+
/>
|
|
345
|
+
))}
|
|
346
|
+
<Button
|
|
347
|
+
label={compareLabel}
|
|
348
|
+
modes={modes}
|
|
349
|
+
disabled={isCompareDisabled}
|
|
350
|
+
{...(onCompare !== undefined ? { onPress: onCompare } : {})}
|
|
351
|
+
/>
|
|
352
|
+
</View>
|
|
353
|
+
)
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export default React.memo(ComparisonBar)
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React, {
|
|
2
|
+
forwardRef,
|
|
2
3
|
useCallback,
|
|
3
4
|
useEffect,
|
|
5
|
+
useImperativeHandle,
|
|
4
6
|
useMemo,
|
|
5
7
|
useRef,
|
|
6
8
|
useState,
|
|
@@ -52,6 +54,28 @@ export type DropdownInputOption = {
|
|
|
52
54
|
|
|
53
55
|
type Rect = { x: number; y: number; width: number; height: number }
|
|
54
56
|
|
|
57
|
+
/**
|
|
58
|
+
* Imperative handle exposed via `ref`. Lets the consumer drive the dropdown
|
|
59
|
+
* from outside — e.g. close it when an Android hardware/system button is
|
|
60
|
+
* pressed, or open it programmatically from a sibling control.
|
|
61
|
+
*/
|
|
62
|
+
export type DropdownInputHandle = {
|
|
63
|
+
/** Opens the options menu (no-op when disabled / read-only). */
|
|
64
|
+
open: () => void
|
|
65
|
+
/** Closes the options menu. */
|
|
66
|
+
close: () => void
|
|
67
|
+
/** Toggles the options menu open/closed. */
|
|
68
|
+
toggle: () => void
|
|
69
|
+
/** Moves focus to the trigger (web). */
|
|
70
|
+
focus: () => void
|
|
71
|
+
/** Removes focus from the trigger (web). */
|
|
72
|
+
blur: () => void
|
|
73
|
+
/** Measures the trigger in window coordinates. */
|
|
74
|
+
measureInWindow: (
|
|
75
|
+
callback: (x: number, y: number, width: number, height: number) => void
|
|
76
|
+
) => void
|
|
77
|
+
}
|
|
78
|
+
|
|
55
79
|
export type DropdownInputProps = {
|
|
56
80
|
/** Label rendered above the input. */
|
|
57
81
|
label?: string
|
|
@@ -307,7 +331,7 @@ function collectOptionsFromChildren(
|
|
|
307
331
|
// Component
|
|
308
332
|
// ---------------------------------------------------------------------------
|
|
309
333
|
|
|
310
|
-
function DropdownInput({
|
|
334
|
+
const DropdownInput = forwardRef<DropdownInputHandle, DropdownInputProps>(function DropdownInput({
|
|
311
335
|
label,
|
|
312
336
|
placeholder = 'Select an option',
|
|
313
337
|
items,
|
|
@@ -338,7 +362,7 @@ function DropdownInput({
|
|
|
338
362
|
accessibilityHint,
|
|
339
363
|
onFocus,
|
|
340
364
|
onBlur,
|
|
341
|
-
}: DropdownInputProps) {
|
|
365
|
+
}: DropdownInputProps, ref: React.Ref<DropdownInputHandle>) {
|
|
342
366
|
// ---------------- Modes ----------------
|
|
343
367
|
const { modes: globalModes } = useTokens()
|
|
344
368
|
const baseModes = useMemo(
|
|
@@ -497,6 +521,34 @@ function DropdownInput({
|
|
|
497
521
|
[measure]
|
|
498
522
|
)
|
|
499
523
|
|
|
524
|
+
// ---------------- Imperative handle ----------------
|
|
525
|
+
useImperativeHandle(
|
|
526
|
+
ref,
|
|
527
|
+
() => ({
|
|
528
|
+
open: () => {
|
|
529
|
+
if (isDisabled || isReadOnly) return
|
|
530
|
+
measure()
|
|
531
|
+
setOpenState(true)
|
|
532
|
+
},
|
|
533
|
+
close: closeMenu,
|
|
534
|
+
toggle: () => {
|
|
535
|
+
if (isDisabled || isReadOnly) return
|
|
536
|
+
measure()
|
|
537
|
+
toggleMenu()
|
|
538
|
+
},
|
|
539
|
+
focus: () => {
|
|
540
|
+
;(triggerRef.current as unknown as { focus?: () => void })?.focus?.()
|
|
541
|
+
},
|
|
542
|
+
blur: () => {
|
|
543
|
+
;(triggerRef.current as unknown as { blur?: () => void })?.blur?.()
|
|
544
|
+
},
|
|
545
|
+
measureInWindow: (callback) => {
|
|
546
|
+
triggerRef.current?.measureInWindow(callback)
|
|
547
|
+
},
|
|
548
|
+
}),
|
|
549
|
+
[isDisabled, isReadOnly, measure, setOpenState, closeMenu, toggleMenu]
|
|
550
|
+
)
|
|
551
|
+
|
|
500
552
|
// ---------------- Popup positioning ----------------
|
|
501
553
|
const [menuSize, setMenuSize] = useState<{
|
|
502
554
|
width: number
|
|
@@ -863,7 +915,7 @@ function DropdownInput({
|
|
|
863
915
|
</Modal>
|
|
864
916
|
</View>
|
|
865
917
|
)
|
|
866
|
-
}
|
|
918
|
+
})
|
|
867
919
|
|
|
868
920
|
const webNoOutline: any = {
|
|
869
921
|
outlineStyle: 'none',
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useCallback, useMemo, useState } from 'react'
|
|
1
|
+
import React, { forwardRef, useCallback, useMemo, useState } from 'react'
|
|
2
2
|
import {
|
|
3
3
|
View,
|
|
4
4
|
Text,
|
|
@@ -301,7 +301,7 @@ function firstError(error: string | string[] | undefined): string | undefined {
|
|
|
301
301
|
// Component
|
|
302
302
|
// ---------------------------------------------------------------------------
|
|
303
303
|
|
|
304
|
-
function FormField({
|
|
304
|
+
const FormField = forwardRef<RNTextInput, FormFieldProps>(function FormField({
|
|
305
305
|
label,
|
|
306
306
|
placeholder,
|
|
307
307
|
value,
|
|
@@ -329,7 +329,7 @@ function FormField({
|
|
|
329
329
|
accessibilityLabel,
|
|
330
330
|
accessibilityHint,
|
|
331
331
|
testID,
|
|
332
|
-
}: FormFieldProps) {
|
|
332
|
+
}: FormFieldProps, ref: React.Ref<RNTextInput>) {
|
|
333
333
|
// -- Form context integration -------------------------------------------
|
|
334
334
|
const formCtx = useFormContext()
|
|
335
335
|
const formError =
|
|
@@ -552,6 +552,7 @@ function FormField({
|
|
|
552
552
|
</View>
|
|
553
553
|
)}
|
|
554
554
|
<RNTextInput
|
|
555
|
+
ref={ref}
|
|
555
556
|
style={[inputTextStyles, inputTextStyle]}
|
|
556
557
|
value={value ?? ''}
|
|
557
558
|
onChangeText={handleChangeText}
|
|
@@ -590,6 +591,6 @@ function FormField({
|
|
|
590
591
|
)}
|
|
591
592
|
</View>
|
|
592
593
|
)
|
|
593
|
-
}
|
|
594
|
+
})
|
|
594
595
|
|
|
595
596
|
export default FormField
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import React, { useState } from 'react'
|
|
2
|
-
import { View, Text, Pressable, type StyleProp, type ViewStyle, type TextStyle, type TextInputProps as RNTextInputProps } from 'react-native'
|
|
1
|
+
import React, { forwardRef, useState } from 'react'
|
|
2
|
+
import { View, Text, Pressable, TextInput as RNTextInput, type StyleProp, type ViewStyle, type TextStyle, type TextInputProps as RNTextInputProps } from 'react-native'
|
|
3
3
|
import { getVariableByName } from '../../design-tokens/figma-variables-resolver'
|
|
4
4
|
import { EMPTY_MODES } from '../../utils/react-utils'
|
|
5
5
|
import Icon from '../../icons/Icon'
|
|
@@ -81,7 +81,7 @@ export type InputSearchProps = {
|
|
|
81
81
|
accessibilityHint?: string;
|
|
82
82
|
} & Omit<RNTextInputProps, 'style' | 'onChangeText' | 'onFocus' | 'onBlur' | 'placeholder' | 'value'>;
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
const InputSearch = forwardRef<RNTextInput, InputSearchProps>(function InputSearch({
|
|
85
85
|
supportText = true,
|
|
86
86
|
supportTextLabel = "Support Text",
|
|
87
87
|
supportTextIcon = "ic_info",
|
|
@@ -96,7 +96,7 @@ export default function InputSearch({
|
|
|
96
96
|
trailing,
|
|
97
97
|
inputStyle,
|
|
98
98
|
...rest
|
|
99
|
-
}: InputSearchProps) {
|
|
99
|
+
}: InputSearchProps, ref: React.Ref<RNTextInput>) {
|
|
100
100
|
const [isFocused, setIsFocused] = useState(false)
|
|
101
101
|
|
|
102
102
|
// Hardcode InputState based on the state prop, ignoring any external InputState passed in modes
|
|
@@ -156,6 +156,7 @@ export default function InputSearch({
|
|
|
156
156
|
gap: formFieldGap,
|
|
157
157
|
}, containerStyle]}>
|
|
158
158
|
<TextInput
|
|
159
|
+
ref={ref}
|
|
159
160
|
placeholder={placeholder}
|
|
160
161
|
value={value || ''}
|
|
161
162
|
onChangeText={onChangeText || (() => { })}
|
|
@@ -178,4 +179,6 @@ export default function InputSearch({
|
|
|
178
179
|
)}
|
|
179
180
|
</View>
|
|
180
181
|
)
|
|
181
|
-
}
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
export default InputSearch
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, useRef
|
|
1
|
+
import React, { forwardRef, useState, useRef } from 'react'
|
|
2
2
|
import {
|
|
3
3
|
View,
|
|
4
4
|
TextInput as RNTextInput,
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
type TextInputProps,
|
|
12
12
|
} from 'react-native'
|
|
13
13
|
import { getVariableByName } from '../../design-tokens/figma-variables-resolver'
|
|
14
|
-
import { EMPTY_MODES } from '../../utils/react-utils'
|
|
14
|
+
import { EMPTY_MODES, mergeRefs } from '../../utils/react-utils'
|
|
15
15
|
import type { Modes } from '../../design-tokens'
|
|
16
16
|
|
|
17
17
|
export type NoteInputProps = {
|
|
@@ -35,7 +35,7 @@ export type NoteInputProps = {
|
|
|
35
35
|
* NoteInput component representing an interactive "Add note" badge style field.
|
|
36
36
|
* Allows the user to click, clears the placeholder text, and shows a blinking cursor when focused.
|
|
37
37
|
*/
|
|
38
|
-
|
|
38
|
+
const NoteInput = forwardRef<RNTextInput, NoteInputProps>(function NoteInput({
|
|
39
39
|
value = '',
|
|
40
40
|
placeholder = 'Add note',
|
|
41
41
|
onChangeText,
|
|
@@ -46,7 +46,7 @@ export default function NoteInput({
|
|
|
46
46
|
onFocus,
|
|
47
47
|
onBlur,
|
|
48
48
|
...rest
|
|
49
|
-
}: NoteInputProps) {
|
|
49
|
+
}: NoteInputProps, ref: React.Ref<RNTextInput>) {
|
|
50
50
|
const [internalFocused, setInternalFocused] = useState(false)
|
|
51
51
|
const inputRef = useRef<RNTextInput>(null)
|
|
52
52
|
|
|
@@ -120,7 +120,7 @@ export default function NoteInput({
|
|
|
120
120
|
{internalFocused ? (value || ' ') : (value || placeholder)}
|
|
121
121
|
</Text>
|
|
122
122
|
<RNTextInput
|
|
123
|
-
ref={inputRef}
|
|
123
|
+
ref={mergeRefs(inputRef, ref)}
|
|
124
124
|
value={value}
|
|
125
125
|
onChangeText={onChangeText}
|
|
126
126
|
placeholder={internalFocused ? '' : placeholder}
|
|
@@ -145,4 +145,6 @@ export default function NoteInput({
|
|
|
145
145
|
</View>
|
|
146
146
|
</Pressable>
|
|
147
147
|
)
|
|
148
|
-
}
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
export default NoteInput
|