@bacon-pos/ui 0.15.1 → 0.16.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.
Files changed (36) hide show
  1. package/lib/commonjs/components/SegmentedButton/SegmentedButton.js +217 -0
  2. package/lib/commonjs/components/SegmentedButton/SegmentedButton.js.map +1 -0
  3. package/lib/commonjs/components/SegmentedButton/SegmentedButton.stories.js +215 -0
  4. package/lib/commonjs/components/SegmentedButton/SegmentedButton.stories.js.map +1 -0
  5. package/lib/commonjs/components/SegmentedButton/SegmentedButton.test.js +97 -0
  6. package/lib/commonjs/components/SegmentedButton/SegmentedButton.test.js.map +1 -0
  7. package/lib/commonjs/components/SegmentedButton/index.js +13 -0
  8. package/lib/commonjs/components/SegmentedButton/index.js.map +1 -0
  9. package/lib/commonjs/components/index.js +21 -10
  10. package/lib/commonjs/components/index.js.map +1 -1
  11. package/lib/module/components/SegmentedButton/SegmentedButton.js +213 -0
  12. package/lib/module/components/SegmentedButton/SegmentedButton.js.map +1 -0
  13. package/lib/module/components/SegmentedButton/SegmentedButton.stories.js +211 -0
  14. package/lib/module/components/SegmentedButton/SegmentedButton.stories.js.map +1 -0
  15. package/lib/module/components/SegmentedButton/SegmentedButton.test.js +96 -0
  16. package/lib/module/components/SegmentedButton/SegmentedButton.test.js.map +1 -0
  17. package/lib/module/components/SegmentedButton/index.js +4 -0
  18. package/lib/module/components/SegmentedButton/index.js.map +1 -0
  19. package/lib/module/components/index.js +1 -0
  20. package/lib/module/components/index.js.map +1 -1
  21. package/lib/typescript/commonjs/components/SegmentedButton/SegmentedButton.d.ts +68 -0
  22. package/lib/typescript/commonjs/components/SegmentedButton/SegmentedButton.d.ts.map +1 -0
  23. package/lib/typescript/commonjs/components/SegmentedButton/index.d.ts +2 -0
  24. package/lib/typescript/commonjs/components/SegmentedButton/index.d.ts.map +1 -0
  25. package/lib/typescript/commonjs/components/index.d.ts +1 -0
  26. package/lib/typescript/commonjs/components/index.d.ts.map +1 -1
  27. package/lib/typescript/module/components/SegmentedButton/SegmentedButton.d.ts +68 -0
  28. package/lib/typescript/module/components/SegmentedButton/SegmentedButton.d.ts.map +1 -0
  29. package/lib/typescript/module/components/SegmentedButton/index.d.ts +2 -0
  30. package/lib/typescript/module/components/SegmentedButton/index.d.ts.map +1 -0
  31. package/lib/typescript/module/components/index.d.ts +1 -0
  32. package/lib/typescript/module/components/index.d.ts.map +1 -1
  33. package/package.json +1 -1
  34. package/src/components/SegmentedButton/SegmentedButton.tsx +269 -0
  35. package/src/components/SegmentedButton/index.ts +7 -0
  36. package/src/components/index.ts +1 -0
@@ -0,0 +1,217 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.SegmentedButton = SegmentedButton;
7
+ var _react = require("react");
8
+ var _reactNative = require("react-native");
9
+ var _index = require("../../theme/index.js");
10
+ var _Icon = require("../Icon/Icon.js");
11
+ var _Text = require("../Text/Text.js");
12
+ var _jsxRuntime = require("react/jsx-runtime");
13
+ /** `default` = soft-rounded rectangle; `round` = fully rounded (pill). */
14
+
15
+ const SIZES = {
16
+ sm: {
17
+ paddingH: 12,
18
+ paddingV: 10,
19
+ gap: 6,
20
+ trackPadding: 4,
21
+ text: 'bodyMedium',
22
+ icon: 18,
23
+ radius: 'md'
24
+ },
25
+ md: {
26
+ paddingH: 16,
27
+ paddingV: 12,
28
+ gap: 8,
29
+ trackPadding: 5,
30
+ text: 'bodyLarge',
31
+ icon: 20,
32
+ radius: 'lg'
33
+ }
34
+ };
35
+
36
+ /**
37
+ * SegmentedButton — faithful to the Bacon POS Figma "Segmented button". A single
38
+ * connected control of 2+ options where exactly one is selected: the active
39
+ * segment fills dark with inverse text; the rest are transparent with secondary
40
+ * text, all inside a rounded track. Supports `sm`/`md` sizes, `default`/`round`
41
+ * shapes (or a custom `radius`), hug / `fullWidth` / fixed `width` layouts, icons,
42
+ * per-segment disabling, and color overrides. Controlled or uncontrolled.
43
+ */
44
+ function SegmentedButton({
45
+ options,
46
+ value,
47
+ defaultValue,
48
+ onChange,
49
+ size = 'md',
50
+ shape = 'default',
51
+ radius,
52
+ fullWidth = false,
53
+ width,
54
+ disabled = false,
55
+ bordered = true,
56
+ trackColor,
57
+ selectedColor,
58
+ selectedTextColor,
59
+ textColor,
60
+ iconSize,
61
+ animated = true,
62
+ style,
63
+ accessibilityLabel,
64
+ testID
65
+ }) {
66
+ const theme = (0, _index.useTheme)();
67
+ const cfg = SIZES[size];
68
+ const isControlled = value !== undefined;
69
+ const [uncontrolled, setUncontrolled] = (0, _react.useState)(defaultValue ?? options[0]?.value ?? '');
70
+ const selected = isControlled ? value : uncontrolled;
71
+ const select = next => {
72
+ if (!isControlled) setUncontrolled(next);
73
+ onChange?.(next);
74
+ };
75
+
76
+ // Sliding highlight (thumb): we measure each segment's position/size and glide
77
+ // an absolutely-positioned fill to the selected one.
78
+ const layouts = (0, _react.useRef)({});
79
+ const thumbX = (0, _react.useRef)(new _reactNative.Animated.Value(0)).current;
80
+ const thumbW = (0, _react.useRef)(new _reactNative.Animated.Value(0)).current;
81
+ const placed = (0, _react.useRef)(false);
82
+ const [measured, setMeasured] = (0, _react.useState)(false);
83
+ const placeThumb = (x, width, withAnim) => {
84
+ if (withAnim && animated) {
85
+ _reactNative.Animated.parallel([_reactNative.Animated.timing(thumbX, {
86
+ toValue: x,
87
+ duration: 200,
88
+ easing: _reactNative.Easing.out(_reactNative.Easing.cubic),
89
+ useNativeDriver: false
90
+ }), _reactNative.Animated.timing(thumbW, {
91
+ toValue: width,
92
+ duration: 200,
93
+ easing: _reactNative.Easing.out(_reactNative.Easing.cubic),
94
+ useNativeDriver: false
95
+ })]).start();
96
+ } else {
97
+ thumbX.setValue(x);
98
+ thumbW.setValue(width);
99
+ }
100
+ };
101
+
102
+ // Animate to the selected segment when it changes (once layouts are known).
103
+ (0, _react.useEffect)(() => {
104
+ const l = layouts.current[selected];
105
+ if (!l) return;
106
+ placeThumb(l.x, l.width, placed.current);
107
+ if (!placed.current) {
108
+ placed.current = true;
109
+ setMeasured(true);
110
+ }
111
+ // eslint-disable-next-line react-hooks/exhaustive-deps
112
+ }, [selected, animated]);
113
+ const onSegmentLayout = value => e => {
114
+ const {
115
+ x,
116
+ width
117
+ } = e.nativeEvent.layout;
118
+ layouts.current[value] = {
119
+ x,
120
+ width
121
+ };
122
+ // Place/keep the thumb aligned with the selected segment (initial mount and
123
+ // on relayout/resize) without animating.
124
+ if (value === selected) {
125
+ placeThumb(x, width, false);
126
+ if (!placed.current) {
127
+ placed.current = true;
128
+ setMeasured(true);
129
+ }
130
+ }
131
+ };
132
+ const trackRadius = radius ?? (shape === 'round' ? theme.radii.pill : theme.radii.xl);
133
+ const segmentRadius = shape === 'round' ? theme.radii.pill : radius != null ? Math.max(radius - cfg.trackPadding, 0) : theme.radii[cfg.radius];
134
+ const selectedBg = selectedColor ?? theme.colors.action.inverse;
135
+ const selectedFg = selectedTextColor ?? theme.colors.action.inverseForeground;
136
+ const restFg = textColor ?? theme.colors.text.secondary;
137
+ const resolvedIconSize = iconSize ?? cfg.icon;
138
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
139
+ testID: testID,
140
+ accessibilityRole: "radiogroup",
141
+ accessibilityLabel: accessibilityLabel,
142
+ style: [{
143
+ padding: cfg.trackPadding,
144
+ borderRadius: trackRadius,
145
+ borderWidth: bordered ? 1 : 0,
146
+ borderColor: theme.colors.border.default,
147
+ backgroundColor: trackColor ?? theme.colors.background.muted,
148
+ alignSelf: fullWidth && width == null ? 'stretch' : 'flex-start',
149
+ width: width ?? (fullWidth ? '100%' : undefined),
150
+ opacity: disabled ? 0.5 : 1
151
+ }, style],
152
+ children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
153
+ style: {
154
+ flexDirection: 'row',
155
+ alignItems: 'stretch',
156
+ gap: cfg.gap,
157
+ position: 'relative'
158
+ },
159
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Animated.View, {
160
+ pointerEvents: "none",
161
+ style: {
162
+ position: 'absolute',
163
+ top: 0,
164
+ bottom: 0,
165
+ left: thumbX,
166
+ width: thumbW,
167
+ borderRadius: segmentRadius,
168
+ backgroundColor: selectedBg,
169
+ opacity: measured ? 1 : 0
170
+ }
171
+ }), options.map(opt => {
172
+ const isSelected = opt.value === selected;
173
+ const isDisabled = disabled || opt.disabled;
174
+ const fg = isSelected ? selectedFg : restFg;
175
+ const iconNode = opt.icon ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_Icon.Icon, {
176
+ name: opt.icon,
177
+ size: resolvedIconSize,
178
+ color: fg
179
+ }) : null;
180
+ const iconRight = opt.iconPosition === 'right';
181
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.Pressable, {
182
+ onLayout: onSegmentLayout(opt.value),
183
+ onPress: isDisabled ? undefined : () => select(opt.value),
184
+ disabled: isDisabled,
185
+ accessibilityRole: "button",
186
+ accessibilityState: {
187
+ selected: isSelected,
188
+ disabled: isDisabled
189
+ },
190
+ accessibilityLabel: opt.label,
191
+ testID: `segment-${opt.value}`,
192
+ style: ({
193
+ pressed
194
+ }) => ({
195
+ flex: fullWidth || width != null ? 1 : undefined,
196
+ flexDirection: 'row',
197
+ alignItems: 'center',
198
+ justifyContent: 'center',
199
+ gap: cfg.gap,
200
+ paddingHorizontal: cfg.paddingH,
201
+ paddingVertical: cfg.paddingV,
202
+ borderRadius: segmentRadius,
203
+ opacity: opt.disabled ? 0.5 : pressed && !isSelected ? 0.6 : 1
204
+ }),
205
+ children: [iconNode && !iconRight ? iconNode : null, /*#__PURE__*/(0, _jsxRuntime.jsx)(_Text.Text, {
206
+ variant: cfg.text,
207
+ weight: "medium",
208
+ color: fg,
209
+ numberOfLines: 1,
210
+ children: opt.label
211
+ }), iconNode && iconRight ? iconNode : null]
212
+ }, opt.value);
213
+ })]
214
+ })
215
+ });
216
+ }
217
+ //# sourceMappingURL=SegmentedButton.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_reactNative","_index","_Icon","_Text","_jsxRuntime","SIZES","sm","paddingH","paddingV","gap","trackPadding","text","icon","radius","md","SegmentedButton","options","value","defaultValue","onChange","size","shape","fullWidth","width","disabled","bordered","trackColor","selectedColor","selectedTextColor","textColor","iconSize","animated","style","accessibilityLabel","testID","theme","useTheme","cfg","isControlled","undefined","uncontrolled","setUncontrolled","useState","selected","select","next","layouts","useRef","thumbX","Animated","Value","current","thumbW","placed","measured","setMeasured","placeThumb","x","withAnim","parallel","timing","toValue","duration","easing","Easing","out","cubic","useNativeDriver","start","setValue","useEffect","l","onSegmentLayout","e","nativeEvent","layout","trackRadius","radii","pill","xl","segmentRadius","Math","max","selectedBg","colors","action","inverse","selectedFg","inverseForeground","restFg","secondary","resolvedIconSize","jsx","View","accessibilityRole","padding","borderRadius","borderWidth","borderColor","border","default","backgroundColor","background","muted","alignSelf","opacity","children","jsxs","flexDirection","alignItems","position","pointerEvents","top","bottom","left","map","opt","isSelected","isDisabled","fg","iconNode","Icon","name","color","iconRight","iconPosition","Pressable","onLayout","onPress","accessibilityState","label","pressed","flex","justifyContent","paddingHorizontal","paddingVertical","Text","variant","weight","numberOfLines"],"sourceRoot":"..\\..\\..\\..\\src","sources":["components/SegmentedButton/SegmentedButton.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAUA,IAAAE,MAAA,GAAAF,OAAA;AAGA,IAAAG,KAAA,GAAAH,OAAA;AAEA,IAAAI,KAAA,GAAAJ,OAAA;AAAoC,IAAAK,WAAA,GAAAL,OAAA;AAGpC;;AA0DA,MAAMM,KAWL,GAAG;EACFC,EAAE,EAAE;IAAEC,QAAQ,EAAE,EAAE;IAAEC,QAAQ,EAAE,EAAE;IAAEC,GAAG,EAAE,CAAC;IAAEC,YAAY,EAAE,CAAC;IAAEC,IAAI,EAAE,YAAY;IAAEC,IAAI,EAAE,EAAE;IA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EAAEmF,GAAG,CAACc,KAAM;UAC9BhG,MAAM,EAAE,WAAWkF,GAAG,CAACnG,KAAK,EAAG;UAC/Be,KAAK,EAAEA,CAAC;YAAEmG;UAAoC,CAAC,MAA4B;YACzEC,IAAI,EAAE9G,SAAS,IAAIC,KAAK,IAAI,IAAI,GAAG,CAAC,GAAGgB,SAAS;YAChDqE,aAAa,EAAE,KAAK;YACpBC,UAAU,EAAE,QAAQ;YACpBwB,cAAc,EAAE,QAAQ;YACxB5H,GAAG,EAAE4B,GAAG,CAAC5B,GAAG;YACZ6H,iBAAiB,EAAEjG,GAAG,CAAC9B,QAAQ;YAC/BgI,eAAe,EAAElG,GAAG,CAAC7B,QAAQ;YAC7BwF,YAAY,EAAEhB,aAAa;YAC3ByB,OAAO,EAAEW,GAAG,CAAC5F,QAAQ,GAAG,GAAG,GAAG2G,OAAO,IAAI,CAACd,UAAU,GAAG,GAAG,GAAG;UAC/D,CAAC,CAAE;UAAAX,QAAA,GAEFc,QAAQ,IAAI,CAACI,SAAS,GAAGJ,QAAQ,GAAG,IAAI,eACzC,IAAApH,WAAA,CAAAwF,GAAA,EAACzF,KAAA,CAAAqI,IAAI;YAACC,OAAO,EAAEpG,GAAG,CAAC1B,IAAK;YAAC+H,MAAM,EAAC,QAAQ;YAACf,KAAK,EAAEJ,EAAG;YAACoB,aAAa,EAAE,CAAE;YAAAjC,QAAA,EAClEU,GAAG,CAACc;UAAK,CACN,CAAC,EACNV,QAAQ,IAAII,SAAS,GAAGJ,QAAQ,GAAG,IAAI;QAAA,GAxBnCJ,GAAG,CAACnG,KAyBA,CAAC;MAEhB,CAAC,CAAC;IAAA,CACE;EAAC,CACH,CAAC;AAEX","ignoreList":[]}
@@ -0,0 +1,215 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = exports.WithIcons = exports.TwoOptions = exports.Themed = exports.Sizes = exports.Round = exports.ManyOptions = exports.FullWidth = exports.FixedWidth = exports.Disabled = exports.Default = exports.CustomRadius = void 0;
7
+ var _react = require("react");
8
+ var _reactNative = require("react-native");
9
+ var _SegmentedButton = require("./SegmentedButton.js");
10
+ var _Text = require("../Text/Text.js");
11
+ var _jsxRuntime = require("react/jsx-runtime");
12
+ const meta = {
13
+ title: 'Components/SegmentedButton',
14
+ component: _SegmentedButton.SegmentedButton
15
+ };
16
+ var _default = exports.default = meta;
17
+ const THREE = [{
18
+ label: 'Option 01',
19
+ value: '1'
20
+ }, {
21
+ label: 'Option 02',
22
+ value: '2'
23
+ }, {
24
+ label: 'Option 03',
25
+ value: '3'
26
+ }];
27
+ function Demo(props) {
28
+ const [value, setValue] = (0, _react.useState)(props.defaultValue ?? '1');
29
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
30
+ style: {
31
+ gap: 8,
32
+ alignItems: 'flex-start'
33
+ },
34
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_SegmentedButton.SegmentedButton, {
35
+ options: THREE,
36
+ ...props,
37
+ value: value,
38
+ onChange: setValue
39
+ }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_Text.Text, {
40
+ variant: "caption",
41
+ color: "secondary",
42
+ children: ["value: ", value]
43
+ })]
44
+ });
45
+ }
46
+
47
+ /** Default (rounded rectangle), md size. */
48
+ const Default = exports.Default = {
49
+ render: () => /*#__PURE__*/(0, _jsxRuntime.jsx)(Demo, {})
50
+ };
51
+
52
+ /** Round (pill) shape. */
53
+ const Round = exports.Round = {
54
+ render: () => /*#__PURE__*/(0, _jsxRuntime.jsx)(Demo, {
55
+ shape: "round"
56
+ })
57
+ };
58
+
59
+ /** Both sizes. */
60
+ const Sizes = exports.Sizes = {
61
+ render: () => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
62
+ style: {
63
+ gap: 24,
64
+ alignItems: 'flex-start'
65
+ },
66
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Demo, {
67
+ size: "md"
68
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Demo, {
69
+ size: "sm"
70
+ })]
71
+ })
72
+ };
73
+
74
+ /** Two options (the common A/B toggle). */
75
+ const TwoOptions = exports.TwoOptions = {
76
+ render: () => /*#__PURE__*/(0, _jsxRuntime.jsx)(Demo, {
77
+ options: [{
78
+ label: 'Dine in',
79
+ value: 'dine'
80
+ }, {
81
+ label: 'Take out',
82
+ value: 'take'
83
+ }]
84
+ })
85
+ };
86
+
87
+ /** Many options. */
88
+ const ManyOptions = exports.ManyOptions = {
89
+ render: () => /*#__PURE__*/(0, _jsxRuntime.jsx)(Demo, {
90
+ options: [{
91
+ label: 'Day',
92
+ value: 'day'
93
+ }, {
94
+ label: 'Week',
95
+ value: 'week'
96
+ }, {
97
+ label: 'Month',
98
+ value: 'month'
99
+ }, {
100
+ label: 'Quarter',
101
+ value: 'quarter'
102
+ }, {
103
+ label: 'Year',
104
+ value: 'year'
105
+ }]
106
+ })
107
+ };
108
+
109
+ /** With icons (left and right positions). */
110
+ const WithIcons = exports.WithIcons = {
111
+ render: () => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
112
+ style: {
113
+ gap: 24,
114
+ alignItems: 'flex-start'
115
+ },
116
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Demo, {
117
+ shape: "round",
118
+ options: [{
119
+ label: 'List',
120
+ value: 'list',
121
+ icon: 'menu-02'
122
+ }, {
123
+ label: 'Grid',
124
+ value: 'grid',
125
+ icon: 'layout1'
126
+ }, {
127
+ label: 'Table',
128
+ value: 'table',
129
+ icon: 'table'
130
+ }]
131
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Demo, {
132
+ options: [{
133
+ label: 'Prev',
134
+ value: 'prev',
135
+ icon: 'arrow-left'
136
+ }, {
137
+ label: 'Next',
138
+ value: 'next',
139
+ icon: 'chevron-forward',
140
+ iconPosition: 'right'
141
+ }]
142
+ })]
143
+ })
144
+ };
145
+
146
+ /** Full width — segments share the container equally. */
147
+ const FullWidth = exports.FullWidth = {
148
+ render: () => /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
149
+ style: {
150
+ width: 520
151
+ },
152
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(Demo, {
153
+ fullWidth: true
154
+ })
155
+ })
156
+ };
157
+
158
+ /** Fixed width. */
159
+ const FixedWidth = exports.FixedWidth = {
160
+ render: () => /*#__PURE__*/(0, _jsxRuntime.jsx)(Demo, {
161
+ width: 420
162
+ })
163
+ };
164
+
165
+ /** Custom radius (overrides shape). */
166
+ const CustomRadius = exports.CustomRadius = {
167
+ render: () => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
168
+ style: {
169
+ gap: 24,
170
+ alignItems: 'flex-start'
171
+ },
172
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Demo, {
173
+ radius: 6
174
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Demo, {
175
+ radius: 24
176
+ })]
177
+ })
178
+ };
179
+
180
+ /** Disabled control and per-segment disabling. */
181
+ const Disabled = exports.Disabled = {
182
+ render: () => /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
183
+ style: {
184
+ gap: 24,
185
+ alignItems: 'flex-start'
186
+ },
187
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Demo, {
188
+ disabled: true
189
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(Demo, {
190
+ options: [{
191
+ label: 'Available',
192
+ value: 'a'
193
+ }, {
194
+ label: 'Soon',
195
+ value: 'b',
196
+ disabled: true
197
+ }, {
198
+ label: 'Also',
199
+ value: 'c'
200
+ }]
201
+ })]
202
+ })
203
+ };
204
+
205
+ /** Color overrides and no border. */
206
+ const Themed = exports.Themed = {
207
+ render: () => /*#__PURE__*/(0, _jsxRuntime.jsx)(Demo, {
208
+ shape: "round",
209
+ bordered: false,
210
+ selectedColor: "#008C57",
211
+ selectedTextColor: "#FFFFFF",
212
+ trackColor: "#E6F5EE"
213
+ })
214
+ };
215
+ //# sourceMappingURL=SegmentedButton.stories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_reactNative","_SegmentedButton","_Text","_jsxRuntime","meta","title","component","SegmentedButton","_default","exports","default","THREE","label","value","Demo","props","setValue","useState","defaultValue","jsxs","View","style","gap","alignItems","children","jsx","options","onChange","Text","variant","color","Default","render","Round","shape","Sizes","size","TwoOptions","ManyOptions","WithIcons","icon","iconPosition","FullWidth","width","fullWidth","FixedWidth","CustomRadius","radius","Disabled","disabled","Themed","bordered","selectedColor","selectedTextColor","trackColor"],"sourceRoot":"..\\..\\..\\..\\src","sources":["components/SegmentedButton/SegmentedButton.stories.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAAoC,IAAAI,WAAA,GAAAJ,OAAA;AAEpC,MAAMK,IAAI,GAAG;EACXC,KAAK,EAAE,4BAA4B;EACnCC,SAAS,EAAEC;AACb,CAAwC;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAE1BN,IAAI;AAGnB,MAAMO,KAAwB,GAAG,CAC/B;EAAEC,KAAK,EAAE,WAAW;EAAEC,KAAK,EAAE;AAAI,CAAC,EAClC;EAAED,KAAK,EAAE,WAAW;EAAEC,KAAK,EAAE;AAAI,CAAC,EAClC;EAAED,KAAK,EAAE,WAAW;EAAEC,KAAK,EAAE;AAAI,CAAC,CACnC;AAED,SAASC,IAAIA,CAACC,KAA4D,EAAE;EAC1E,MAAM,CAACF,KAAK,EAAEG,QAAQ,CAAC,GAAG,IAAAC,eAAQ,EAACF,KAAK,CAACG,YAAY,IAAI,GAAG,CAAC;EAC7D,oBACE,IAAAf,WAAA,CAAAgB,IAAA,EAACnB,YAAA,CAAAoB,IAAI;IAACC,KAAK,EAAE;MAAEC,GAAG,EAA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AC,eACnB,IAAA5C,WAAA,CAAAsB,GAAA,EAACX,IAAI;MAACiC,MAAM,EAAE;IAAG,CAAE,CAAC;EAAA,CAChB;AAEV,CAAC;;AAED;AACO,MAAMC,QAAe,GAAAvC,OAAA,CAAAuC,QAAA,GAAG;EAC7BhB,MAAM,EAAEA,CAAA,kBACN,IAAA7B,WAAA,CAAAgB,IAAA,EAACnB,YAAA,CAAAoB,IAAI;IAACC,KAAK,EAAE;MAAEC,GAAG,EAAE,EAAE;MAAEC,UAAU,EAAE;IAAa,CAAE;IAAAC,QAAA,gBACjD,IAAArB,WAAA,CAAAsB,GAAA,EAACX,IAAI;MAACmC,QAAQ;IAAA,CAAE,CAAC,eACjB,IAAA9C,WAAA,CAAAsB,GAAA,EAACX,IAAI;MACHY,OAAO,EAAE,CACP;QAAEd,KAAK,EAAE,WAAW;QAAEC,KAAK,EAAE;MAAI,CAAC,EAClC;QAAED,KAAK,EAAE,MAAM;QAAEC,KAAK,EAAE,GAAG;QAAEoC,QAAQ,EAAE;MAAK,CAAC,EAC7C;QAAErC,KAAK,EAAE,MAAM;QAAEC,KAAK,EAAE;MAAI,CAAC;IAC7B,CACH,CAAC;EAAA,CACE;AAEV,CAAC;;AAED;AACO,MAAMqC,MAAa,GAAAzC,OAAA,CAAAyC,MAAA,GAAG;EAC3BlB,MAAM,EAAEA,CAAA,kBACN,IAAA7B,WAAA,CAAAsB,GAAA,EAACX,IAAI;IACHoB,KAAK,EAAC,OAAO;IACbiB,QAAQ,EAAE,KAAM;IAChBC,aAAa,EAAC,SAAS;IACvBC,iBAAiB,EAAC,SAAS;IAC3BC,UAAU,EAAC;EAAS,CACrB;AAEL,CAAC","ignoreList":[]}
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ var _react = _interopRequireDefault(require("react"));
4
+ var _reactNative = require("@testing-library/react-native");
5
+ var _SegmentedButton = require("./SegmentedButton.js");
6
+ var _index = require("../../theme/index.js");
7
+ var _jsxRuntime = require("react/jsx-runtime");
8
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ function renderWithTheme(ui) {
10
+ return (0, _reactNative.render)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_index.ThemeProvider, {
11
+ children: ui
12
+ }));
13
+ }
14
+ const OPTS = [{
15
+ label: 'One',
16
+ value: '1'
17
+ }, {
18
+ label: 'Two',
19
+ value: '2'
20
+ }, {
21
+ label: 'Three',
22
+ value: '3'
23
+ }];
24
+ describe('SegmentedButton', () => {
25
+ it('renders one segment per option', () => {
26
+ renderWithTheme(/*#__PURE__*/(0, _jsxRuntime.jsx)(_SegmentedButton.SegmentedButton, {
27
+ options: OPTS
28
+ }));
29
+ expect(_reactNative.screen.getByText('One')).toBeTruthy();
30
+ expect(_reactNative.screen.getByText('Two')).toBeTruthy();
31
+ expect(_reactNative.screen.getByText('Three')).toBeTruthy();
32
+ });
33
+ it('selects the first option by default (uncontrolled) and reports changes', () => {
34
+ const onChange = jest.fn();
35
+ renderWithTheme(/*#__PURE__*/(0, _jsxRuntime.jsx)(_SegmentedButton.SegmentedButton, {
36
+ options: OPTS,
37
+ onChange: onChange
38
+ }));
39
+ expect(_reactNative.screen.getByTestId('segment-1').props.accessibilityState.selected).toBe(true);
40
+ _reactNative.fireEvent.press(_reactNative.screen.getByText('Two'));
41
+ expect(onChange).toHaveBeenCalledWith('2');
42
+ expect(_reactNative.screen.getByTestId('segment-2').props.accessibilityState.selected).toBe(true);
43
+ });
44
+ it('honors defaultValue', () => {
45
+ renderWithTheme(/*#__PURE__*/(0, _jsxRuntime.jsx)(_SegmentedButton.SegmentedButton, {
46
+ options: OPTS,
47
+ defaultValue: "3"
48
+ }));
49
+ expect(_reactNative.screen.getByTestId('segment-3').props.accessibilityState.selected).toBe(true);
50
+ });
51
+ it('respects a controlled value and does not self-update', () => {
52
+ const onChange = jest.fn();
53
+ renderWithTheme(/*#__PURE__*/(0, _jsxRuntime.jsx)(_SegmentedButton.SegmentedButton, {
54
+ options: OPTS,
55
+ value: "2",
56
+ onChange: onChange
57
+ }));
58
+ expect(_reactNative.screen.getByTestId('segment-2').props.accessibilityState.selected).toBe(true);
59
+ _reactNative.fireEvent.press(_reactNative.screen.getByText('Three'));
60
+ expect(onChange).toHaveBeenCalledWith('3');
61
+ // value prop still "2" → stays selected
62
+ expect(_reactNative.screen.getByTestId('segment-2').props.accessibilityState.selected).toBe(true);
63
+ });
64
+ it('does not fire when the whole control is disabled', () => {
65
+ const onChange = jest.fn();
66
+ renderWithTheme(/*#__PURE__*/(0, _jsxRuntime.jsx)(_SegmentedButton.SegmentedButton, {
67
+ options: OPTS,
68
+ disabled: true,
69
+ onChange: onChange
70
+ }));
71
+ _reactNative.fireEvent.press(_reactNative.screen.getByText('Two'));
72
+ expect(onChange).not.toHaveBeenCalled();
73
+ });
74
+ it('does not fire for a disabled segment but works for others', () => {
75
+ const onChange = jest.fn();
76
+ const opts = [{
77
+ label: 'A',
78
+ value: 'a'
79
+ }, {
80
+ label: 'B',
81
+ value: 'b',
82
+ disabled: true
83
+ }, {
84
+ label: 'C',
85
+ value: 'c'
86
+ }];
87
+ renderWithTheme(/*#__PURE__*/(0, _jsxRuntime.jsx)(_SegmentedButton.SegmentedButton, {
88
+ options: opts,
89
+ onChange: onChange
90
+ }));
91
+ _reactNative.fireEvent.press(_reactNative.screen.getByText('B'));
92
+ expect(onChange).not.toHaveBeenCalled();
93
+ _reactNative.fireEvent.press(_reactNative.screen.getByText('C'));
94
+ expect(onChange).toHaveBeenCalledWith('c');
95
+ });
96
+ });
97
+ //# sourceMappingURL=SegmentedButton.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","_SegmentedButton","_index","_jsxRuntime","e","__esModule","default","renderWithTheme","ui","render","jsx","ThemeProvider","children","OPTS","label","value","describe","it","SegmentedButton","options","expect","screen","getByText","toBeTruthy","onChange","jest","fn","getByTestId","props","accessibilityState","selected","toBe","fireEvent","press","toHaveBeenCalledWith","defaultValue","disabled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,EAAE,GAAG;MAAEC,KAAK,EAAE;IAAI,CAAC,CAC3B;IACDR,eAAe,cAAC,IAAAJ,WAAA,CAAAO,GAAA,EAACT,gBAAA,CAAAiB,eAAe;MAACC,OAAO,EAAEoB,IAAK;MAACf,QAAQ,EAAEA;IAAS,CAAE,CAAC,CAAC;IACvEQ,sBAAS,CAACC,KAAK,CAACZ,mBAAM,CAACC,SAAS,CAAC,GAAG,CAAC,CAAC;IACtCF,MAAM,CAACI,QAAQ,CAAC,CAACa,GAAG,CAACC,gBAAgB,CAAC,CAAC;IACvCN,sBAAS,CAACC,KAAK,CAACZ,mBAAM,CAACC,SAAS,CAAC,GAAG,CAAC,CAAC;IACtCF,MAAM,CAACI,QAAQ,CAAC,CAACU,oBAAoB,CAAC,GAAG,CAAC;EAC5C,CAAC,CAAC;AACJ,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "SegmentedButton", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _SegmentedButton.SegmentedButton;
10
+ }
11
+ });
12
+ var _SegmentedButton = require("./SegmentedButton.js");
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_SegmentedButton","require"],"sourceRoot":"..\\..\\..\\..\\src","sources":["components/SegmentedButton/index.ts"],"mappings":";;;;;;;;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA","ignoreList":[]}