@bacon-pos/ui 0.5.1 → 0.7.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/lib/commonjs/components/Dropdown/Dropdown.js +282 -0
- package/lib/commonjs/components/Dropdown/Dropdown.js.map +1 -0
- package/lib/commonjs/components/Dropdown/Dropdown.stories.js +519 -0
- package/lib/commonjs/components/Dropdown/Dropdown.stories.js.map +1 -0
- package/lib/commonjs/components/Dropdown/Dropdown.test.js +113 -0
- package/lib/commonjs/components/Dropdown/Dropdown.test.js.map +1 -0
- package/lib/commonjs/components/Dropdown/index.js +19 -0
- package/lib/commonjs/components/Dropdown/index.js.map +1 -0
- package/lib/commonjs/components/Menu/Menu.js +214 -0
- package/lib/commonjs/components/Menu/Menu.js.map +1 -0
- package/lib/commonjs/components/Menu/Menu.test.js +71 -0
- package/lib/commonjs/components/Menu/Menu.test.js.map +1 -0
- package/lib/commonjs/components/Menu/MenuButton.js +73 -0
- package/lib/commonjs/components/Menu/MenuButton.js.map +1 -0
- package/lib/commonjs/components/Menu/MenuButton.stories.js +166 -0
- package/lib/commonjs/components/Menu/MenuButton.stories.js.map +1 -0
- package/lib/commonjs/components/Menu/SelectButton.js +143 -0
- package/lib/commonjs/components/Menu/SelectButton.js.map +1 -0
- package/lib/commonjs/components/Menu/SelectButton.stories.js +116 -0
- package/lib/commonjs/components/Menu/SelectButton.stories.js.map +1 -0
- package/lib/commonjs/components/Menu/SelectButton.test.js +80 -0
- package/lib/commonjs/components/Menu/SelectButton.test.js.map +1 -0
- package/lib/commonjs/components/Menu/UserMenu.js +73 -0
- package/lib/commonjs/components/Menu/UserMenu.js.map +1 -0
- package/lib/commonjs/components/Menu/UserMenu.stories.js +85 -0
- package/lib/commonjs/components/Menu/UserMenu.stories.js.map +1 -0
- package/lib/commonjs/components/Menu/UserMenu.test.js +52 -0
- package/lib/commonjs/components/Menu/UserMenu.test.js.map +1 -0
- package/lib/commonjs/components/Menu/index.js +34 -0
- package/lib/commonjs/components/Menu/index.js.map +1 -0
- package/lib/commonjs/components/Select/Select.js +246 -0
- package/lib/commonjs/components/Select/Select.js.map +1 -0
- package/lib/commonjs/components/Select/Select.stories.js +221 -0
- package/lib/commonjs/components/Select/Select.stories.js.map +1 -0
- package/lib/commonjs/components/Select/Select.test.js +165 -0
- package/lib/commonjs/components/Select/Select.test.js.map +1 -0
- package/lib/commonjs/components/Select/index.js +13 -0
- package/lib/commonjs/components/Select/index.js.map +1 -0
- package/lib/commonjs/components/UserChip/UserChip.js +121 -0
- package/lib/commonjs/components/UserChip/UserChip.js.map +1 -0
- package/lib/commonjs/components/UserChip/UserChip.stories.js +153 -0
- package/lib/commonjs/components/UserChip/UserChip.stories.js.map +1 -0
- package/lib/commonjs/components/UserChip/UserChip.test.js +59 -0
- package/lib/commonjs/components/UserChip/UserChip.test.js.map +1 -0
- package/lib/commonjs/components/UserChip/index.js +13 -0
- package/lib/commonjs/components/UserChip/index.js.map +1 -0
- package/lib/commonjs/components/index.js +57 -13
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/module/components/Dropdown/Dropdown.js +277 -0
- package/lib/module/components/Dropdown/Dropdown.js.map +1 -0
- package/lib/module/components/Dropdown/Dropdown.stories.js +515 -0
- package/lib/module/components/Dropdown/Dropdown.stories.js.map +1 -0
- package/lib/module/components/Dropdown/Dropdown.test.js +113 -0
- package/lib/module/components/Dropdown/Dropdown.test.js.map +1 -0
- package/lib/module/components/Dropdown/index.js +4 -0
- package/lib/module/components/Dropdown/index.js.map +1 -0
- package/lib/module/components/Menu/Menu.js +210 -0
- package/lib/module/components/Menu/Menu.js.map +1 -0
- package/lib/module/components/Menu/Menu.test.js +71 -0
- package/lib/module/components/Menu/Menu.test.js.map +1 -0
- package/lib/module/components/Menu/MenuButton.js +69 -0
- package/lib/module/components/Menu/MenuButton.js.map +1 -0
- package/lib/module/components/Menu/MenuButton.stories.js +162 -0
- package/lib/module/components/Menu/MenuButton.stories.js.map +1 -0
- package/lib/module/components/Menu/SelectButton.js +139 -0
- package/lib/module/components/Menu/SelectButton.js.map +1 -0
- package/lib/module/components/Menu/SelectButton.stories.js +112 -0
- package/lib/module/components/Menu/SelectButton.stories.js.map +1 -0
- package/lib/module/components/Menu/SelectButton.test.js +80 -0
- package/lib/module/components/Menu/SelectButton.test.js.map +1 -0
- package/lib/module/components/Menu/UserMenu.js +69 -0
- package/lib/module/components/Menu/UserMenu.js.map +1 -0
- package/lib/module/components/Menu/UserMenu.stories.js +81 -0
- package/lib/module/components/Menu/UserMenu.stories.js.map +1 -0
- package/lib/module/components/Menu/UserMenu.test.js +52 -0
- package/lib/module/components/Menu/UserMenu.test.js.map +1 -0
- package/lib/module/components/Menu/index.js +7 -0
- package/lib/module/components/Menu/index.js.map +1 -0
- package/lib/module/components/Select/Select.js +244 -0
- package/lib/module/components/Select/Select.js.map +1 -0
- package/lib/module/components/Select/Select.stories.js +217 -0
- package/lib/module/components/Select/Select.stories.js.map +1 -0
- package/lib/module/components/Select/Select.test.js +165 -0
- package/lib/module/components/Select/Select.test.js.map +1 -0
- package/lib/module/components/Select/index.js +4 -0
- package/lib/module/components/Select/index.js.map +1 -0
- package/lib/module/components/UserChip/UserChip.js +117 -0
- package/lib/module/components/UserChip/UserChip.js.map +1 -0
- package/lib/module/components/UserChip/UserChip.stories.js +149 -0
- package/lib/module/components/UserChip/UserChip.stories.js.map +1 -0
- package/lib/module/components/UserChip/UserChip.test.js +59 -0
- package/lib/module/components/UserChip/UserChip.test.js.map +1 -0
- package/lib/module/components/UserChip/index.js +4 -0
- package/lib/module/components/UserChip/index.js.map +1 -0
- package/lib/module/components/index.js +4 -0
- package/lib/module/components/index.js.map +1 -1
- package/lib/typescript/commonjs/components/Dropdown/Dropdown.d.ts +105 -0
- package/lib/typescript/commonjs/components/Dropdown/Dropdown.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/Dropdown/index.d.ts +3 -0
- package/lib/typescript/commonjs/components/Dropdown/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/Menu/Menu.d.ts +66 -0
- package/lib/typescript/commonjs/components/Menu/Menu.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/Menu/MenuButton.d.ts +46 -0
- package/lib/typescript/commonjs/components/Menu/MenuButton.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/Menu/SelectButton.d.ts +60 -0
- package/lib/typescript/commonjs/components/Menu/SelectButton.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/Menu/UserMenu.d.ts +46 -0
- package/lib/typescript/commonjs/components/Menu/UserMenu.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/Menu/index.d.ts +9 -0
- package/lib/typescript/commonjs/components/Menu/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/Select/Select.d.ts +73 -0
- package/lib/typescript/commonjs/components/Select/Select.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/Select/index.d.ts +3 -0
- package/lib/typescript/commonjs/components/Select/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/UserChip/UserChip.d.ts +33 -0
- package/lib/typescript/commonjs/components/UserChip/UserChip.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/UserChip/index.d.ts +3 -0
- package/lib/typescript/commonjs/components/UserChip/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/components/index.d.ts +4 -0
- package/lib/typescript/commonjs/components/index.d.ts.map +1 -1
- package/lib/typescript/module/components/Dropdown/Dropdown.d.ts +105 -0
- package/lib/typescript/module/components/Dropdown/Dropdown.d.ts.map +1 -0
- package/lib/typescript/module/components/Dropdown/index.d.ts +3 -0
- package/lib/typescript/module/components/Dropdown/index.d.ts.map +1 -0
- package/lib/typescript/module/components/Menu/Menu.d.ts +66 -0
- package/lib/typescript/module/components/Menu/Menu.d.ts.map +1 -0
- package/lib/typescript/module/components/Menu/MenuButton.d.ts +46 -0
- package/lib/typescript/module/components/Menu/MenuButton.d.ts.map +1 -0
- package/lib/typescript/module/components/Menu/SelectButton.d.ts +60 -0
- package/lib/typescript/module/components/Menu/SelectButton.d.ts.map +1 -0
- package/lib/typescript/module/components/Menu/UserMenu.d.ts +46 -0
- package/lib/typescript/module/components/Menu/UserMenu.d.ts.map +1 -0
- package/lib/typescript/module/components/Menu/index.d.ts +9 -0
- package/lib/typescript/module/components/Menu/index.d.ts.map +1 -0
- package/lib/typescript/module/components/Select/Select.d.ts +73 -0
- package/lib/typescript/module/components/Select/Select.d.ts.map +1 -0
- package/lib/typescript/module/components/Select/index.d.ts +3 -0
- package/lib/typescript/module/components/Select/index.d.ts.map +1 -0
- package/lib/typescript/module/components/UserChip/UserChip.d.ts +33 -0
- package/lib/typescript/module/components/UserChip/UserChip.d.ts.map +1 -0
- package/lib/typescript/module/components/UserChip/index.d.ts +3 -0
- package/lib/typescript/module/components/UserChip/index.d.ts.map +1 -0
- package/lib/typescript/module/components/index.d.ts +4 -0
- package/lib/typescript/module/components/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/Dropdown/Dropdown.tsx +319 -0
- package/src/components/Dropdown/index.ts +2 -0
- package/src/components/Menu/Menu.tsx +249 -0
- package/src/components/Menu/MenuButton.tsx +98 -0
- package/src/components/Menu/SelectButton.tsx +171 -0
- package/src/components/Menu/UserMenu.tsx +100 -0
- package/src/components/Menu/index.ts +14 -0
- package/src/components/Select/Select.tsx +323 -0
- package/src/components/Select/index.ts +2 -0
- package/src/components/UserChip/UserChip.tsx +138 -0
- package/src/components/UserChip/index.ts +2 -0
- package/src/components/index.ts +4 -0
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Select = Select;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _index = require("../../theme/index.js");
|
|
10
|
+
var _Dropdown = require("../Dropdown/Dropdown.js");
|
|
11
|
+
var _Icon = require("../Icon/Icon.js");
|
|
12
|
+
var _Menu = require("../Menu/Menu.js");
|
|
13
|
+
var _Text = require("../Text/Text.js");
|
|
14
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
15
|
+
/** Width of the focus ring, in px (Figma "Focus" effect: spread 6). */const FOCUS_RING_SPREAD = 6;
|
|
16
|
+
const FOCUS_RING_ALPHA = 0.15;
|
|
17
|
+
|
|
18
|
+
/** Convert a `#RRGGBB` (or `#RGB`) token to an `rgba()` string at the given alpha. */
|
|
19
|
+
function hexToRgba(hex, alpha) {
|
|
20
|
+
const h = hex.replace('#', '');
|
|
21
|
+
const full = h.length === 3 ? h.replace(/./g, c => c + c) : h;
|
|
22
|
+
const r = parseInt(full.slice(0, 2), 16);
|
|
23
|
+
const g = parseInt(full.slice(2, 4), 16);
|
|
24
|
+
const b = parseInt(full.slice(4, 6), 16);
|
|
25
|
+
return `rgba(${r}, ${g}, ${b}, ${alpha})`;
|
|
26
|
+
}
|
|
27
|
+
const SIZES = {
|
|
28
|
+
md: {
|
|
29
|
+
height: 48,
|
|
30
|
+
gap: 8,
|
|
31
|
+
iconSize: 20,
|
|
32
|
+
textVariant: 'bodyMedium'
|
|
33
|
+
},
|
|
34
|
+
lg: {
|
|
35
|
+
height: 58,
|
|
36
|
+
gap: 10,
|
|
37
|
+
iconSize: 24,
|
|
38
|
+
textVariant: 'bodyLarge'
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
/** An option in a `Select`. */
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Select — a form field that opens a `Dropdown` of options. The field mirrors
|
|
46
|
+
* `Input` (pill, label, helper/error, lime focus ring, red error ring); it is
|
|
47
|
+
* not editable — pressing it opens the menu, which matches the field width. The
|
|
48
|
+
* current option is marked with a check. With `multiple`, rows become checkboxes,
|
|
49
|
+
* the value is an array, and the menu stays open while picking.
|
|
50
|
+
*/
|
|
51
|
+
function Select({
|
|
52
|
+
options,
|
|
53
|
+
multiple = false,
|
|
54
|
+
value,
|
|
55
|
+
defaultValue,
|
|
56
|
+
onChange,
|
|
57
|
+
label,
|
|
58
|
+
helperText,
|
|
59
|
+
error,
|
|
60
|
+
placeholder = 'Select option',
|
|
61
|
+
leftIcon,
|
|
62
|
+
size = 'lg',
|
|
63
|
+
width,
|
|
64
|
+
fullWidth = true,
|
|
65
|
+
disabled = false,
|
|
66
|
+
renderValue,
|
|
67
|
+
matchTriggerWidth = true,
|
|
68
|
+
menuWidth,
|
|
69
|
+
maxHeight,
|
|
70
|
+
anchorOrigin = {
|
|
71
|
+
vertical: 'bottom',
|
|
72
|
+
horizontal: 'left'
|
|
73
|
+
},
|
|
74
|
+
menuOrigin = {
|
|
75
|
+
vertical: 'top',
|
|
76
|
+
horizontal: 'left'
|
|
77
|
+
},
|
|
78
|
+
offset = 8,
|
|
79
|
+
autoFit = true,
|
|
80
|
+
insets,
|
|
81
|
+
closeOnSelect,
|
|
82
|
+
style
|
|
83
|
+
}) {
|
|
84
|
+
const theme = (0, _index.useTheme)();
|
|
85
|
+
const sizeConfig = SIZES[size];
|
|
86
|
+
const isControlled = value !== undefined;
|
|
87
|
+
const [internal, setInternal] = (0, _react.useState)(defaultValue ?? (multiple ? [] : undefined));
|
|
88
|
+
const current = isControlled ? value : internal;
|
|
89
|
+
const selectedKeys = multiple ? current ?? [] : current != null ? [current] : [];
|
|
90
|
+
const commit = next => {
|
|
91
|
+
if (!isControlled) setInternal(next);
|
|
92
|
+
onChange?.(next);
|
|
93
|
+
};
|
|
94
|
+
const selectSingle = key => commit(key);
|
|
95
|
+
const toggleMulti = key => {
|
|
96
|
+
const set = new Set(selectedKeys);
|
|
97
|
+
if (set.has(key)) set.delete(key);else set.add(key);
|
|
98
|
+
commit([...set]);
|
|
99
|
+
};
|
|
100
|
+
const selectedOptions = options.filter(o => selectedKeys.includes(o.key));
|
|
101
|
+
const isEmpty = selectedOptions.length === 0;
|
|
102
|
+
const displayText = renderValue ? renderValue(selectedOptions) : isEmpty ? placeholder : selectedOptions.map(o => o.label).join(', ');
|
|
103
|
+
const hasError = Boolean(error);
|
|
104
|
+
const message = typeof error === 'string' ? error : helperText;
|
|
105
|
+
const rows = options.map(o => ({
|
|
106
|
+
key: o.key,
|
|
107
|
+
label: o.label,
|
|
108
|
+
disabled: o.disabled,
|
|
109
|
+
leading: o.icon ? {
|
|
110
|
+
kind: 'icon',
|
|
111
|
+
name: o.icon
|
|
112
|
+
} : undefined,
|
|
113
|
+
trailing: multiple ? {
|
|
114
|
+
kind: 'checkbox',
|
|
115
|
+
checked: selectedKeys.includes(o.key),
|
|
116
|
+
onChange: () => toggleMulti(o.key)
|
|
117
|
+
} : selectedKeys.includes(o.key) ? {
|
|
118
|
+
kind: 'icon',
|
|
119
|
+
name: 'check',
|
|
120
|
+
color: theme.colors.feedback.success
|
|
121
|
+
} : undefined
|
|
122
|
+
}));
|
|
123
|
+
const shouldClose = closeOnSelect ?? !multiple;
|
|
124
|
+
const iconBox = {
|
|
125
|
+
width: sizeConfig.iconSize,
|
|
126
|
+
height: sizeConfig.iconSize,
|
|
127
|
+
alignItems: 'center',
|
|
128
|
+
justifyContent: 'center'
|
|
129
|
+
};
|
|
130
|
+
const containerWidth = width != null ? {
|
|
131
|
+
width,
|
|
132
|
+
alignSelf: 'flex-start'
|
|
133
|
+
} : fullWidth ? {
|
|
134
|
+
alignSelf: 'stretch'
|
|
135
|
+
} : {
|
|
136
|
+
alignSelf: 'flex-start'
|
|
137
|
+
};
|
|
138
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
139
|
+
style: [containerWidth, style],
|
|
140
|
+
children: [label ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.Text, {
|
|
141
|
+
variant: "bodySmall",
|
|
142
|
+
color: "secondary",
|
|
143
|
+
style: {
|
|
144
|
+
marginBottom: 4,
|
|
145
|
+
marginLeft: 8
|
|
146
|
+
},
|
|
147
|
+
children: label
|
|
148
|
+
}) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)(_Menu.Menu, {
|
|
149
|
+
anchorOrigin: anchorOrigin,
|
|
150
|
+
menuOrigin: menuOrigin,
|
|
151
|
+
offset: offset,
|
|
152
|
+
autoFit: autoFit,
|
|
153
|
+
insets: insets,
|
|
154
|
+
triggerStyle: {
|
|
155
|
+
alignSelf: 'stretch'
|
|
156
|
+
},
|
|
157
|
+
renderTrigger: ({
|
|
158
|
+
open,
|
|
159
|
+
toggle
|
|
160
|
+
}) => {
|
|
161
|
+
const showRing = open && !disabled;
|
|
162
|
+
const borderColor = disabled ? theme.colors.disabled.border : hasError ? theme.colors.feedback.error : open ? theme.colors.border.focus : theme.colors.border.default;
|
|
163
|
+
const ringColor = hasError ? theme.colors.feedback.error : theme.colors.border.focus;
|
|
164
|
+
const boxShadow = showRing ? [{
|
|
165
|
+
offsetX: 0,
|
|
166
|
+
offsetY: 0,
|
|
167
|
+
blurRadius: 0,
|
|
168
|
+
spreadDistance: FOCUS_RING_SPREAD,
|
|
169
|
+
color: hexToRgba(ringColor, FOCUS_RING_ALPHA)
|
|
170
|
+
}] : undefined;
|
|
171
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.Pressable, {
|
|
172
|
+
onPress: toggle,
|
|
173
|
+
disabled: disabled,
|
|
174
|
+
accessibilityRole: "button",
|
|
175
|
+
accessibilityState: {
|
|
176
|
+
expanded: open,
|
|
177
|
+
disabled
|
|
178
|
+
},
|
|
179
|
+
accessibilityLabel: label ?? placeholder,
|
|
180
|
+
style: {
|
|
181
|
+
flexDirection: 'row',
|
|
182
|
+
alignItems: 'center',
|
|
183
|
+
gap: sizeConfig.gap,
|
|
184
|
+
height: sizeConfig.height,
|
|
185
|
+
paddingHorizontal: 16,
|
|
186
|
+
borderWidth: 1,
|
|
187
|
+
borderColor,
|
|
188
|
+
borderRadius: theme.radii.pill,
|
|
189
|
+
backgroundColor: disabled ? theme.colors.disabled.background : theme.colors.background.default,
|
|
190
|
+
boxShadow
|
|
191
|
+
},
|
|
192
|
+
children: [leftIcon ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
193
|
+
style: iconBox,
|
|
194
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.Icon, {
|
|
195
|
+
name: leftIcon,
|
|
196
|
+
size: sizeConfig.iconSize,
|
|
197
|
+
color: disabled ? theme.colors.disabled.foreground : 'secondary'
|
|
198
|
+
})
|
|
199
|
+
}) : null, /*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.Text, {
|
|
200
|
+
variant: sizeConfig.textVariant,
|
|
201
|
+
color: disabled ? 'tertiary' : isEmpty ? 'tertiary' : 'primary',
|
|
202
|
+
numberOfLines: 1,
|
|
203
|
+
style: {
|
|
204
|
+
flex: 1,
|
|
205
|
+
minWidth: 0
|
|
206
|
+
},
|
|
207
|
+
children: displayText
|
|
208
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
209
|
+
style: [iconBox, {
|
|
210
|
+
transform: [{
|
|
211
|
+
rotate: open ? '180deg' : '0deg'
|
|
212
|
+
}]
|
|
213
|
+
}],
|
|
214
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.Icon, {
|
|
215
|
+
name: "chevron-down",
|
|
216
|
+
size: sizeConfig.iconSize,
|
|
217
|
+
color: disabled ? theme.colors.disabled.foreground : 'secondary'
|
|
218
|
+
})
|
|
219
|
+
})]
|
|
220
|
+
});
|
|
221
|
+
},
|
|
222
|
+
children: ({
|
|
223
|
+
close,
|
|
224
|
+
triggerWidth,
|
|
225
|
+
maxHeight: autoMaxHeight
|
|
226
|
+
}) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_Dropdown.Dropdown, {
|
|
227
|
+
options: rows,
|
|
228
|
+
width: matchTriggerWidth ? triggerWidth : menuWidth,
|
|
229
|
+
maxHeight: maxHeight ?? autoMaxHeight,
|
|
230
|
+
onSelect: multiple ? undefined : key => {
|
|
231
|
+
selectSingle(key);
|
|
232
|
+
if (shouldClose) close();
|
|
233
|
+
}
|
|
234
|
+
})
|
|
235
|
+
}), message ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.Text, {
|
|
236
|
+
variant: "bodySmall",
|
|
237
|
+
color: hasError ? theme.colors.feedback.error : 'tertiary',
|
|
238
|
+
style: {
|
|
239
|
+
marginTop: 8,
|
|
240
|
+
marginLeft: 8
|
|
241
|
+
},
|
|
242
|
+
children: message
|
|
243
|
+
}) : null]
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
//# sourceMappingURL=Select.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNative","_index","_Dropdown","_Icon","_Menu","_Text","_jsxRuntime","FOCUS_RING_SPREAD","FOCUS_RING_ALPHA","hexToRgba","hex","alpha","h","replace","full","length","c","r","parseInt","slice","g","b","SIZES","md","height","gap","iconSize","textVariant","lg","Select","options","multiple","value","defaultValue","onChange","label","helperText","error","placeholder","leftIcon","size","width","fullWidth","disabled","renderValue","matchTriggerWidth","menuWidth","maxHeight","anchorOrigin","vertical","horizontal","menuOrigin","offset","autoFit","insets","closeOnSelect","style","theme","useTheme","sizeConfig","isControlled","undefined","internal","setInternal","useState","current","selectedKeys","commit","next","selectSingle","key","toggleMulti","set","Set","has","delete","add","selectedOptions","filter","o","includes","isEmpty","displayText","map","join","hasError","Boolean","message","rows","leading","icon","kind","name","trailing","checked","color","colors","feedback","success","shouldClose","iconBox","alignItems","justifyContent","containerWidth","alignSelf","jsxs","View","children","jsx","Text","variant","marginBottom","marginLeft","Menu","triggerStyle","renderTrigger","open","toggle","showRing","borderColor","border","focus","default","ringColor","boxShadow","offsetX","offsetY","blurRadius","spreadDistance","Pressable","onPress","accessibilityRole","accessibilityState","expanded","accessibilityLabel","flexDirection","paddingHorizontal","borderWidth","borderRadius","radii","pill","backgroundColor","background","Icon","foreground","numberOfLines","flex","minWidth","transform","rotate","close","triggerWidth","autoMaxHeight","Dropdown","onSelect","marginTop"],"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,QAAQ,CAAC5D,KAAK,GAAG,UAAW;MAC3DmB,KAAK,EAAE;QAAEmG,SAAS,EAAE,CAAC;QAAE3C,UAAU,EAAE;MAAE,CAAE;MAAAL,QAAA,EAEtCpB;IAAO,CACJ,CAAC,GACL,IAAI;EAAA,CACJ,CAAC;AAEX","ignoreList":[]}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = exports.SingleSelect = exports.Scrollable = exports.MultiSelect = exports.InsideDialog = exports.FixedMenuWidth = exports.Error = exports.Disabled = exports.Default = exports.CustomWidth = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _Select = require("./Select.js");
|
|
10
|
+
var _Button = require("../Button/Button.js");
|
|
11
|
+
var _Dialog = require("../Dialog/Dialog.js");
|
|
12
|
+
var _Text = require("../Text/Text.js");
|
|
13
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
14
|
+
const meta = {
|
|
15
|
+
title: 'Components/Select',
|
|
16
|
+
component: _Select.Select
|
|
17
|
+
};
|
|
18
|
+
var _default = exports.default = meta;
|
|
19
|
+
const OPTIONS = [{
|
|
20
|
+
key: 'dine-in',
|
|
21
|
+
label: 'Dine in',
|
|
22
|
+
icon: 'dish'
|
|
23
|
+
}, {
|
|
24
|
+
key: 'take-out',
|
|
25
|
+
label: 'Take out',
|
|
26
|
+
icon: 'shopping-bag'
|
|
27
|
+
}, {
|
|
28
|
+
key: 'delivery',
|
|
29
|
+
label: 'Delivery',
|
|
30
|
+
icon: 'truck-delivery'
|
|
31
|
+
}, {
|
|
32
|
+
key: 'pickup',
|
|
33
|
+
label: 'Pickup',
|
|
34
|
+
icon: 'shopping-bag'
|
|
35
|
+
}];
|
|
36
|
+
function Frame({
|
|
37
|
+
children
|
|
38
|
+
}) {
|
|
39
|
+
// Height gives the open menu room in the Storybook canvas.
|
|
40
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
41
|
+
style: {
|
|
42
|
+
padding: 24,
|
|
43
|
+
width: 360,
|
|
44
|
+
height: 420
|
|
45
|
+
},
|
|
46
|
+
children: children
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** Default field (matches Figma "Default"). */
|
|
51
|
+
const Default = exports.Default = {
|
|
52
|
+
render: () => /*#__PURE__*/(0, _jsxRuntime.jsx)(Frame, {
|
|
53
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.Select, {
|
|
54
|
+
options: OPTIONS,
|
|
55
|
+
label: "Label",
|
|
56
|
+
helperText: "Helper text",
|
|
57
|
+
leftIcon: "shopping-bag",
|
|
58
|
+
onChange: () => {}
|
|
59
|
+
})
|
|
60
|
+
})
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** Single select — the current option is marked with a check. */
|
|
64
|
+
const SingleSelect = exports.SingleSelect = {
|
|
65
|
+
render: () => {
|
|
66
|
+
const [value, setValue] = (0, _react.useState)('dine-in');
|
|
67
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Frame, {
|
|
68
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.Select, {
|
|
69
|
+
options: OPTIONS,
|
|
70
|
+
label: "Order type",
|
|
71
|
+
helperText: "Helper text",
|
|
72
|
+
leftIcon: "shopping-bag",
|
|
73
|
+
value: value,
|
|
74
|
+
onChange: setValue
|
|
75
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Text.Text, {
|
|
76
|
+
variant: "caption",
|
|
77
|
+
color: "secondary",
|
|
78
|
+
style: {
|
|
79
|
+
marginTop: 12
|
|
80
|
+
},
|
|
81
|
+
children: ["value: ", String(value)]
|
|
82
|
+
})]
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
/** Multi select — rows become checkboxes; the menu stays open while picking. */
|
|
88
|
+
const MultiSelect = exports.MultiSelect = {
|
|
89
|
+
render: () => {
|
|
90
|
+
const [value, setValue] = (0, _react.useState)(['dine-in', 'delivery']);
|
|
91
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(Frame, {
|
|
92
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.Select, {
|
|
93
|
+
options: OPTIONS,
|
|
94
|
+
multiple: true,
|
|
95
|
+
label: "Order types",
|
|
96
|
+
helperText: "Choose one or more",
|
|
97
|
+
value: value,
|
|
98
|
+
onChange: setValue
|
|
99
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Text.Text, {
|
|
100
|
+
variant: "caption",
|
|
101
|
+
color: "secondary",
|
|
102
|
+
style: {
|
|
103
|
+
marginTop: 12
|
|
104
|
+
},
|
|
105
|
+
children: ["value: ", Array.isArray(value) ? value.join(', ') : value]
|
|
106
|
+
})]
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
/** Error state — red border, red ring on open, red helper text. */
|
|
112
|
+
const Error = exports.Error = {
|
|
113
|
+
render: () => /*#__PURE__*/(0, _jsxRuntime.jsx)(Frame, {
|
|
114
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.Select, {
|
|
115
|
+
options: OPTIONS,
|
|
116
|
+
label: "Order type",
|
|
117
|
+
error: "Please choose an option",
|
|
118
|
+
leftIcon: "shopping-bag",
|
|
119
|
+
onChange: () => {}
|
|
120
|
+
})
|
|
121
|
+
})
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/** Disabled. */
|
|
125
|
+
const Disabled = exports.Disabled = {
|
|
126
|
+
render: () => /*#__PURE__*/(0, _jsxRuntime.jsx)(Frame, {
|
|
127
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.Select, {
|
|
128
|
+
options: OPTIONS,
|
|
129
|
+
label: "Label",
|
|
130
|
+
helperText: "Helper text",
|
|
131
|
+
leftIcon: "shopping-bag",
|
|
132
|
+
disabled: true,
|
|
133
|
+
defaultValue: "dine-in"
|
|
134
|
+
})
|
|
135
|
+
})
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/** Long list — the menu scrolls past maxHeight. */
|
|
139
|
+
const Scrollable = exports.Scrollable = {
|
|
140
|
+
render: () => {
|
|
141
|
+
const many = Array.from({
|
|
142
|
+
length: 20
|
|
143
|
+
}).map((_, i) => ({
|
|
144
|
+
key: String(i),
|
|
145
|
+
label: `Option ${i + 1}`
|
|
146
|
+
}));
|
|
147
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(Frame, {
|
|
148
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.Select, {
|
|
149
|
+
options: many,
|
|
150
|
+
label: "Pick one",
|
|
151
|
+
maxHeight: 260,
|
|
152
|
+
onChange: () => {}
|
|
153
|
+
})
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
/** Fixed menu width instead of matching the field. */
|
|
159
|
+
const FixedMenuWidth = exports.FixedMenuWidth = {
|
|
160
|
+
render: () => /*#__PURE__*/(0, _jsxRuntime.jsx)(Frame, {
|
|
161
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.Select, {
|
|
162
|
+
options: OPTIONS,
|
|
163
|
+
label: "Order type",
|
|
164
|
+
matchTriggerWidth: false,
|
|
165
|
+
menuWidth: 300,
|
|
166
|
+
onChange: () => {}
|
|
167
|
+
})
|
|
168
|
+
})
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/** Fixed field width (default is full width, the Figma behavior). */
|
|
172
|
+
const CustomWidth = exports.CustomWidth = {
|
|
173
|
+
render: () => /*#__PURE__*/(0, _jsxRuntime.jsx)(Frame, {
|
|
174
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.Select, {
|
|
175
|
+
options: OPTIONS,
|
|
176
|
+
label: "Order type",
|
|
177
|
+
width: 260,
|
|
178
|
+
leftIcon: "shopping-bag",
|
|
179
|
+
onChange: () => {}
|
|
180
|
+
})
|
|
181
|
+
})
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Inside a Dialog — the two modals coexist: the menu positions over the dialog,
|
|
186
|
+
* tapping outside the menu closes only the menu (not the dialog), and back closes
|
|
187
|
+
* the menu first.
|
|
188
|
+
*/
|
|
189
|
+
const InsideDialog = exports.InsideDialog = {
|
|
190
|
+
render: () => {
|
|
191
|
+
const [open, setOpen] = (0, _react.useState)(false);
|
|
192
|
+
const [value, setValue] = (0, _react.useState)('dine-in');
|
|
193
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
194
|
+
style: {
|
|
195
|
+
padding: 24
|
|
196
|
+
},
|
|
197
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Button.Button, {
|
|
198
|
+
label: "Open dialog",
|
|
199
|
+
onPress: () => setOpen(true)
|
|
200
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_Dialog.Dialog, {
|
|
201
|
+
visible: open,
|
|
202
|
+
onClose: () => setOpen(false),
|
|
203
|
+
title: "Order details",
|
|
204
|
+
subtitle: "Pick the order type",
|
|
205
|
+
cancel: {},
|
|
206
|
+
actions: [{
|
|
207
|
+
label: 'Save',
|
|
208
|
+
onPress: () => setOpen(false)
|
|
209
|
+
}],
|
|
210
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.Select, {
|
|
211
|
+
options: OPTIONS,
|
|
212
|
+
label: "Order type",
|
|
213
|
+
leftIcon: "shopping-bag",
|
|
214
|
+
value: value,
|
|
215
|
+
onChange: setValue
|
|
216
|
+
})
|
|
217
|
+
})]
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
//# sourceMappingURL=Select.stories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","require","_reactNative","_Select","_Button","_Dialog","_Text","_jsxRuntime","meta","title","component","Select","_default","exports","default","OPTIONS","key","label","icon","Frame","children","jsx","View","style","padding","width","height","Default","render","options","helperText","leftIcon","onChange","SingleSelect","value","setValue","useState","jsxs","Text","variant","color","marginTop","String","MultiSelect","multiple","Array","isArray","join","Error","error","Disabled","disabled","defaultValue","Scrollable","many","from","length","map","_","i","maxHeight","FixedMenuWidth","matchTriggerWidth","menuWidth","CustomWidth","InsideDialog","open","setOpen","Button","onPress","Dialog","visible","onClose","subtitle","cancel","actions"],"sourceRoot":"..\\..\\..\\..\\src","sources":["components/Select/Select.stories.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,KAAA,GAAAL,OAAA;AAAoC,IAAAM,WAAA,GAAAN,OAAA;AAEpC,MAAMO,IAAI,GAAG;EACXC,KAAK,EAAE,mBAAmB;EAC1BC,SAAS,EAAEC;AACb,CAA+B;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEjBN,IAAI;AAGnB,MAAMO,OAAuB,GAAG,CAC9B;EAAEC,GAAG,EAAE,SAAS;EAAEC,KAAK,EAAE,SAAS;EAAEC,IAAI,EAAE;AAAO,CAAC,EAClD;EAAEF,GAAG,EAAE,UAAU;EAAEC,KAAK,EAAE,UAAU;EAAEC,IAAI,EAAE;AAAe,CAAC,EAC5D;EAAEF,GAAG,EAAE,UAAU;EAAEC,KAAK,EAAE,UAAU;EAAEC,IAAI,EAAE;AAAiB,CAAC,EAC9D;EAAEF,GAAG,EAAE,QAAQ;EAAEC,KAAK,EAAE,QAAQ;EAAEC,IAAI,EAAE;AAAe,CAAC,CACzD;AAED,SAASC,KAAKA,CAAC;EA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AO,CAAC,IAAI;MAAE,CAAE,CAAC,eAC5D,IAAA5D,WAAA,CAAAc,GAAA,EAAChB,OAAA,CAAAiE,MAAM;QACLC,OAAO,EAAEL,IAAK;QACdM,OAAO,EAAEA,CAAA,KAAML,OAAO,CAAC,KAAK,CAAE;QAC9B1D,KAAK,EAAC,eAAe;QACrBgE,QAAQ,EAAC,qBAAqB;QAC9BC,MAAM,EAAE,CAAC,CAAE;QACXC,OAAO,EAAE,CAAC;UAAE1D,KAAK,EAAE,MAAM;UAAEoD,OAAO,EAAEA,CAAA,KAAMF,OAAO,CAAC,KAAK;QAAE,CAAC,CAAE;QAAA/C,QAAA,eAE5D,IAAAb,WAAA,CAAAc,GAAA,EAAClB,OAAA,CAAAQ,MAAM;UACLkB,OAAO,EAAEd,OAAQ;UACjBE,KAAK,EAAC,YAAY;UAClBc,QAAQ,EAAC,cAAc;UACvBG,KAAK,EAAEA,KAAM;UACbF,QAAQ,EAAEG;QAAS,CACpB;MAAC,CACI,CAAC;IAAA,CACL,CAAC;EAEX;AACF,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _react = require("react");
|
|
4
|
+
var _reactNative = require("@testing-library/react-native");
|
|
5
|
+
var _index = require("../../theme/index.js");
|
|
6
|
+
var _Select = require("./Select.js");
|
|
7
|
+
var _Dialog = require("../Dialog/Dialog.js");
|
|
8
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
9
|
+
function wrap(ui) {
|
|
10
|
+
return (0, _reactNative.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index.ThemeProvider, {
|
|
11
|
+
children: ui
|
|
12
|
+
}));
|
|
13
|
+
}
|
|
14
|
+
const OPTIONS = [{
|
|
15
|
+
key: 'dine-in',
|
|
16
|
+
label: 'Dine in'
|
|
17
|
+
}, {
|
|
18
|
+
key: 'take-out',
|
|
19
|
+
label: 'Take out'
|
|
20
|
+
}, {
|
|
21
|
+
key: 'delivery',
|
|
22
|
+
label: 'Delivery'
|
|
23
|
+
}];
|
|
24
|
+
describe('Select (single)', () => {
|
|
25
|
+
it('shows the placeholder when empty', () => {
|
|
26
|
+
wrap(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.Select, {
|
|
27
|
+
options: OPTIONS,
|
|
28
|
+
placeholder: "Select option"
|
|
29
|
+
}));
|
|
30
|
+
expect(_reactNative.screen.getByText('Select option')).toBeTruthy();
|
|
31
|
+
});
|
|
32
|
+
it('shows the selected label', () => {
|
|
33
|
+
wrap(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.Select, {
|
|
34
|
+
options: OPTIONS,
|
|
35
|
+
value: "take-out"
|
|
36
|
+
}));
|
|
37
|
+
expect(_reactNative.screen.getByText('Take out')).toBeTruthy();
|
|
38
|
+
});
|
|
39
|
+
it('opens, selects an option, calls onChange and closes', () => {
|
|
40
|
+
const onChange = jest.fn();
|
|
41
|
+
wrap(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.Select, {
|
|
42
|
+
options: OPTIONS,
|
|
43
|
+
placeholder: "Select option",
|
|
44
|
+
onChange: onChange
|
|
45
|
+
}));
|
|
46
|
+
_reactNative.fireEvent.press(_reactNative.screen.getByText('Select option'));
|
|
47
|
+
_reactNative.fireEvent.press(_reactNative.screen.getByText('Delivery'));
|
|
48
|
+
expect(onChange).toHaveBeenCalledWith('delivery');
|
|
49
|
+
// Menu closed → the other option is gone.
|
|
50
|
+
expect(_reactNative.screen.queryByText('Take out')).toBeNull();
|
|
51
|
+
});
|
|
52
|
+
it('renders the error message', () => {
|
|
53
|
+
wrap(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.Select, {
|
|
54
|
+
options: OPTIONS,
|
|
55
|
+
error: "Required"
|
|
56
|
+
}));
|
|
57
|
+
expect(_reactNative.screen.getByText('Required')).toBeTruthy();
|
|
58
|
+
});
|
|
59
|
+
it('does not open when disabled', () => {
|
|
60
|
+
wrap(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.Select, {
|
|
61
|
+
options: OPTIONS,
|
|
62
|
+
placeholder: "Select option",
|
|
63
|
+
disabled: true
|
|
64
|
+
}));
|
|
65
|
+
_reactNative.fireEvent.press(_reactNative.screen.getByText('Select option'));
|
|
66
|
+
expect(_reactNative.screen.queryByText('Delivery')).toBeNull();
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
describe('Select (multiple)', () => {
|
|
70
|
+
function MultiControlled() {
|
|
71
|
+
const [value, setValue] = (0, _react.useState)([]);
|
|
72
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.Select, {
|
|
73
|
+
options: OPTIONS,
|
|
74
|
+
multiple: true,
|
|
75
|
+
value: value,
|
|
76
|
+
onChange: setValue,
|
|
77
|
+
placeholder: "Pick"
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
it('adds keys to the array and stays open', () => {
|
|
81
|
+
const onChange = jest.fn();
|
|
82
|
+
wrap(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.Select, {
|
|
83
|
+
options: OPTIONS,
|
|
84
|
+
multiple: true,
|
|
85
|
+
value: [],
|
|
86
|
+
onChange: onChange,
|
|
87
|
+
placeholder: "Pick"
|
|
88
|
+
}));
|
|
89
|
+
_reactNative.fireEvent.press(_reactNative.screen.getByText('Pick'));
|
|
90
|
+
_reactNative.fireEvent.press(_reactNative.screen.getByText('Dine in'));
|
|
91
|
+
expect(onChange).toHaveBeenCalledWith(['dine-in']);
|
|
92
|
+
// Still open — other rows remain visible.
|
|
93
|
+
expect(_reactNative.screen.getByText('Delivery')).toBeTruthy();
|
|
94
|
+
});
|
|
95
|
+
it('toggles selected keys off', () => {
|
|
96
|
+
const onChange = jest.fn();
|
|
97
|
+
wrap(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.Select, {
|
|
98
|
+
options: OPTIONS,
|
|
99
|
+
multiple: true,
|
|
100
|
+
value: ['dine-in'],
|
|
101
|
+
onChange: onChange,
|
|
102
|
+
placeholder: "Pick"
|
|
103
|
+
}));
|
|
104
|
+
// Before opening, only the trigger shows "Dine in".
|
|
105
|
+
_reactNative.fireEvent.press(_reactNative.screen.getByText('Dine in')); // opens the menu
|
|
106
|
+
// Now there are two: trigger + row. Press the row (last).
|
|
107
|
+
const matches = _reactNative.screen.getAllByText('Dine in');
|
|
108
|
+
_reactNative.fireEvent.press(matches[matches.length - 1]);
|
|
109
|
+
expect(onChange).toHaveBeenCalledWith([]);
|
|
110
|
+
});
|
|
111
|
+
it('joins multiple labels in the trigger', () => {
|
|
112
|
+
wrap(/*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.Select, {
|
|
113
|
+
options: OPTIONS,
|
|
114
|
+
multiple: true,
|
|
115
|
+
value: ['dine-in', 'delivery']
|
|
116
|
+
}));
|
|
117
|
+
expect(_reactNative.screen.getByText('Dine in, Delivery')).toBeTruthy();
|
|
118
|
+
});
|
|
119
|
+
it('reflects new picks (controlled loop)', () => {
|
|
120
|
+
wrap(/*#__PURE__*/(0, _jsxRuntime.jsx)(MultiControlled, {}));
|
|
121
|
+
_reactNative.fireEvent.press(_reactNative.screen.getByText('Pick'));
|
|
122
|
+
_reactNative.fireEvent.press(_reactNative.screen.getByText('Take out'));
|
|
123
|
+
// Menu stays open, so the label now appears on both the trigger and the row.
|
|
124
|
+
expect(_reactNative.screen.getAllByText('Take out').length).toBe(2);
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
describe('Select inside Dialog', () => {
|
|
128
|
+
function DialogWithSelect() {
|
|
129
|
+
const [value, setValue] = (0, _react.useState)('dine-in');
|
|
130
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_Dialog.Dialog, {
|
|
131
|
+
visible: true,
|
|
132
|
+
onClose: () => {},
|
|
133
|
+
title: "Order",
|
|
134
|
+
actions: [{
|
|
135
|
+
label: 'Save'
|
|
136
|
+
}],
|
|
137
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_Select.Select, {
|
|
138
|
+
options: OPTIONS,
|
|
139
|
+
label: "Order type",
|
|
140
|
+
value: value,
|
|
141
|
+
onChange: setValue
|
|
142
|
+
})
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
it('opens the select menu over the dialog without closing it', () => {
|
|
146
|
+
wrap(/*#__PURE__*/(0, _jsxRuntime.jsx)(DialogWithSelect, {}));
|
|
147
|
+
// Dialog is visible.
|
|
148
|
+
expect(_reactNative.screen.getByText('Order')).toBeTruthy();
|
|
149
|
+
// Open the select (trigger shows "Dine in").
|
|
150
|
+
_reactNative.fireEvent.press(_reactNative.screen.getByText('Dine in'));
|
|
151
|
+
// Menu rows appear...
|
|
152
|
+
expect(_reactNative.screen.getByText('Delivery')).toBeTruthy();
|
|
153
|
+
// ...and the dialog is still there.
|
|
154
|
+
expect(_reactNative.screen.getByText('Order')).toBeTruthy();
|
|
155
|
+
});
|
|
156
|
+
it('selecting in the menu updates the field and keeps the dialog open', () => {
|
|
157
|
+
wrap(/*#__PURE__*/(0, _jsxRuntime.jsx)(DialogWithSelect, {}));
|
|
158
|
+
_reactNative.fireEvent.press(_reactNative.screen.getByText('Dine in'));
|
|
159
|
+
_reactNative.fireEvent.press(_reactNative.screen.getByText('Delivery'));
|
|
160
|
+
// Field now shows Delivery; dialog title still present.
|
|
161
|
+
expect(_reactNative.screen.getByText('Delivery')).toBeTruthy();
|
|
162
|
+
expect(_reactNative.screen.getByText('Order')).toBeTruthy();
|
|
163
|
+
});
|
|
164
|
+
});
|
|
165
|
+
//# sourceMappingURL=Select.test.js.map
|