@yamatozhen/design_system 1.0.1 → 1.2.1
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/LICENSE +201 -201
- package/README.md +101 -101
- package/package.json +50 -50
- package/scripts/postinstall.js +91 -91
- package/template/app/ClientNav.tsx +258 -310
- package/template/app/globals.css +2 -167
- package/template/app/layout.tsx +94 -82
- package/template/app/themes/dark-mc.css +51 -51
- package/template/app/themes/dark.css +51 -51
- package/template/app/themes/light-mc.css +51 -51
- package/template/app/themes/light.css +51 -51
- package/template/app/themes/theme.css +272 -82
- package/template/components/{layout/button → (buttons)}/Button.module.css +351 -305
- package/template/components/{layout/button → (buttons)}/ButtonGroup.tsx +414 -503
- package/template/components/{layout/button → (buttons)}/FAB.tsx +119 -118
- package/template/components/(buttons)/button.tsx +164 -0
- package/template/components/(controls)/slider/Slider.module.css +250 -0
- package/template/components/(controls)/slider/Slider.tsx +386 -0
- package/template/components/{layout → (controls)}/switch/Switch.module.css +108 -102
- package/template/components/{layout → (controls)}/switch/Switch.tsx +69 -48
- package/template/components/(date & time)/calendar/Calendar.module.css +125 -0
- package/template/components/(date & time)/calendar/Calendar.tsx +206 -0
- package/template/components/(date & time)/dateField/DateField.module.css +25 -0
- package/template/components/(date & time)/dateField/DateField.tsx +193 -0
- package/template/components/(date & time)/datePicker/DatePicker.tsx +118 -0
- package/template/components/(date & time)/dateRangePicker/DateRangePicker.tsx +144 -0
- package/template/components/(date & time)/rangeCalendar/RangeCalendar.module.css +203 -0
- package/template/components/(date & time)/rangeCalendar/RangeCalendar.tsx +263 -0
- package/template/components/(date & time)/shared/dateUtils.ts +107 -0
- package/template/components/(date & time)/timeField/TimeField.module.css +39 -0
- package/template/components/(date & time)/timeField/TimeField.tsx +158 -0
- package/template/components/(feedback)/circularProgress/CircularProgress.tsx +646 -0
- package/template/components/(feedback)/linearProgress/LinearProgress.tsx +337 -0
- package/template/components/(feedback)/meter/Meter.tsx +111 -0
- package/template/components/(feedback)/skeleton/Skeleton.module.css +49 -0
- package/template/components/(feedback)/skeleton/Skeleton.tsx +32 -0
- package/template/components/(feedback)/spinner/Spinner.module.css +27 -0
- package/template/components/(feedback)/spinner/Spinner.tsx +60 -0
- package/template/components/(forms)/checkbox/Checkbox.tsx +121 -0
- package/template/components/(forms)/checkboxGroup/CheckboxGroup.tsx +83 -0
- package/template/components/(forms)/description/Description.tsx +34 -0
- package/template/components/(forms)/errorMessage/ErrorMessage.tsx +31 -0
- package/template/components/(forms)/fieldError/FieldError.tsx +39 -0
- package/template/components/(forms)/fieldset/Fieldset.tsx +51 -0
- package/template/components/(forms)/form/Form.tsx +54 -0
- package/template/components/(forms)/input/Input.tsx +50 -0
- package/template/components/(forms)/inputGroup/InputGroup.tsx +65 -0
- package/template/components/(forms)/inputOtp/InputOtp.tsx +139 -0
- package/template/components/(forms)/label/Label.tsx +46 -0
- package/template/components/(forms)/numberField/NumberField.tsx +292 -0
- package/template/components/(forms)/radioGroup/RadioGroup.tsx +175 -0
- package/template/components/(forms)/searchField/SearchField.tsx +139 -0
- package/template/components/(forms)/shared/field.module.css +75 -0
- package/template/components/(forms)/shared/fieldContext.ts +28 -0
- package/template/components/(forms)/textArea/TextArea.tsx +55 -0
- package/template/components/(forms)/textField/TextField.tsx +91 -0
- package/template/components/{layout → (layout)}/Lightbox/LightboxCard.tsx +100 -100
- package/template/components/{layout → (layout)}/Lightbox/LightboxGallery.module.css +249 -249
- package/template/components/{layout → (layout)}/Lightbox/LightboxGallery.tsx +72 -72
- package/template/components/{layout → (layout)}/Lightbox/LightboxGrid.tsx +185 -186
- package/template/components/{layout → (layout)}/Lightbox/LightboxModal.module.css +395 -395
- package/template/components/{layout → (layout)}/Lightbox/LightboxModal.tsx +498 -500
- package/template/components/{layout → (layout)}/Lightbox/demo.tsx +396 -412
- package/template/components/{layout → (layout)}/Lightbox/index.ts +30 -30
- package/template/components/{layout → (layout)}/Lightbox/types.ts +101 -113
- package/template/components/{layout → (layout)}/Lightbox/useLightboxFilters.ts +140 -140
- package/template/components/(layout)/accordion/Accordion.module.css +108 -0
- package/template/components/(layout)/accordion/Accordion.tsx +251 -0
- package/template/components/(layout)/card/Card.module.css +136 -0
- package/template/components/(layout)/card/Card.tsx +371 -0
- package/template/components/(layout)/list/List.module.css +83 -0
- package/template/components/(layout)/list/List.tsx +332 -0
- package/template/components/{layout → (layout)}/navigation/Wrap.tsx +41 -41
- package/template/components/(layout)/navigation/breadcrumbs/Breadcrumbs.tsx +145 -0
- package/template/components/{layout/navigation/nav/Nav.module.css → (layout)/navigation/nav/Nav.module.css.old} +474 -508
- package/template/components/{layout → (layout)}/navigation/nav/Nav.tsx +186 -167
- package/template/components/{layout → (layout)}/navigation/nav/NavBar.tsx +396 -419
- package/template/components/{layout → (layout)}/navigation/nav/NavContext.tsx +259 -259
- package/template/components/{layout → (layout)}/navigation/nav/NavItem.tsx +195 -173
- package/template/components/{layout → (layout)}/navigation/nav/NavNew.module.css +406 -373
- package/template/components/{layout → (layout)}/navigation/nav/NavRail.tsx +317 -315
- package/template/components/{layout → (layout)}/navigation/nav/NavSection.tsx +101 -102
- package/template/components/{layout → (layout)}/navigation/nav/NavTab.tsx +25 -25
- package/template/components/{layout → (layout)}/navigation/nav/navftb/NavFTB.module.css +253 -252
- package/template/components/{layout → (layout)}/navigation/nav/navftb/NavFTB.tsx +448 -399
- package/template/components/{layout → (layout)}/navigation/nav/navftb/useTabIndicator.ts +498 -484
- package/template/components/{layout → (layout)}/navigation/nav/navheader/NavHeader.module.css +59 -59
- package/template/components/{layout → (layout)}/navigation/nav/navheader/NavHeader.tsx +465 -473
- package/template/components/(layout)/navigation/pagination/Pagination.tsx +261 -0
- package/template/components/{layout → (layout)}/pages/loadingScreen.tsx +117 -102
- package/template/components/{layout → (layout)}/pages/maintenance/Maintenance.tsx +52 -52
- package/template/components/{layout → (layout)}/pages/maintenance/maintenance.module.css +162 -162
- package/template/components/(layout)/scrollShadow/ScrollShadow.module.css +81 -0
- package/template/components/(layout)/scrollShadow/ScrollShadow.tsx +161 -0
- package/template/components/(layout)/scrollShadow/useScrollShadow.ts +130 -0
- package/template/components/(layout)/separator/Separator.tsx +112 -0
- package/template/components/(overlays)/accessibilityModal/AccessibilityModal.tsx +307 -0
- package/template/components/(overlays)/drawer/Drawer.tsx +953 -0
- package/template/components/(overlays)/modal/Modal.tsx +654 -0
- package/template/components/(overlays)/popover/Popover.tsx +420 -0
- package/template/components/(overlays)/toast/Toast.tsx +692 -0
- package/template/components/(pickers)/autocomplete/Autocomplete.tsx +24 -0
- package/template/components/(pickers)/comboBox/ComboBox.tsx +21 -0
- package/template/components/(pickers)/select/Select.tsx +188 -0
- package/template/components/(pickers)/shared/FilterableField.tsx +223 -0
- package/template/components/(pickers)/shared/PickerItem.ts +13 -0
- package/template/components/tools/CustomScrollbar.tsx +107 -0
- package/template/components/tools/Divider.tsx +11 -11
- package/template/components/tools/ReduceMotionContext.tsx +5 -5
- package/template/components/tools/Sinewave.tsx +396 -199
- package/template/components/tools/SinewaveProgress.tsx +140 -135
- package/template/components/tools/badge/Badge.tsx +28 -28
- package/template/components/tools/dropdown/drop.module.css +196 -0
- package/template/components/tools/dropdown/drop.tsx +568 -0
- package/template/components/tools/easing.ts +118 -0
- package/template/components/tools/flubber.d.ts +6 -6
- package/template/components/tools/footer/Footer.tsx +20 -0
- package/template/components/tools/input/Input.module.css +45 -0
- package/template/components/tools/input/Input.tsx +99 -0
- package/template/components/tools/label/Icon.tsx +39 -0
- package/template/components/tools/label/Label.tsx +156 -0
- package/template/components/tools/mobileViewProvider.tsx +53 -58
- package/template/components/tools/ripple/ripple.css +38 -41
- package/template/components/tools/ripple/ripple.tsx +78 -53
- package/template/components/tools/shape/Shape.module.css +25 -0
- package/template/components/tools/shape/{ShapeMorph.tsx → Shape.tsx} +316 -190
- package/template/components/tools/shape/ShapeLoader.tsx +104 -101
- package/template/components/tools/shape/ShapePaths.ts +116 -116
- package/template/components/tools/switch/Switch.module.css +102 -102
- package/template/components/tools/switch/Switch.tsx +48 -48
- package/template/components/tools/useBodyScrollLock.tsx +27 -27
- package/template/components/tools/useImageColor.ts +47 -47
- package/template/components/tools/useNavSheetDrag.tsx +196 -196
- package/template/components/layout/accordion/Accordion.module.css +0 -149
- package/template/components/layout/accordion/Accordion.tsx +0 -114
- package/template/components/layout/button/button.tsx +0 -128
- package/template/components/layout/button/drop.module.css +0 -229
- package/template/components/layout/button/drop.tsx +0 -516
- package/template/components/layout/hero/v1/heroSlideshow.module.css +0 -107
- package/template/components/layout/hero/v1/heroSlideshow.tsx +0 -233
- package/template/components/layout/modals/accessibilityModal/AccessibilityModal.module.css +0 -126
- package/template/components/layout/modals/accessibilityModal/AccessibilityModal.tsx +0 -290
- package/template/components/layout/modals/alert/Alert.tsx +0 -188
- package/template/components/layout/navigation/MioCard.module.css +0 -88
- package/template/components/layout/navigation/MioCard.tsx +0 -266
- package/template/components/tools/ProgressiveBlur.tsx +0 -73
- package/template/components/tools/icon/icon.module.css +0 -0
- package/template/components/tools/icon/icon.tsx +0 -125
- package/template/components/tools/react-bits/ClickSpark.tsx +0 -177
- package/template/components/tools/react-bits/FadeContent.tsx +0 -90
- package/template/components/tools/react-bits/GlareHover.tsx +0 -73
- package/template/components/tools/react-bits/GradientText/GradientText.css +0 -70
- package/template/components/tools/react-bits/GradientText/GradientText.tsx +0 -44
- package/template/components/tools/react-bits/Magnet.tsx +0 -118
- package/template/components/tools/react-bits/Stepper/Stepper.css +0 -134
- package/template/components/tools/react-bits/Stepper/Stepper.tsx +0 -412
|
@@ -1,503 +1,414 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
|
|
3
|
-
import React, {
|
|
4
|
-
createContext,
|
|
5
|
-
useContext,
|
|
6
|
-
useEffect,
|
|
7
|
-
useRef,
|
|
8
|
-
useState,
|
|
9
|
-
} from "react";
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
// ---------------- config knobs ----------------
|
|
14
|
-
|
|
15
|
-
const GAP = 4;
|
|
16
|
-
const TRANSITION =
|
|
17
|
-
"all var(--transition-expressive-color), border-radius var(--transition-expressive), padding-inline var(--transition-expressive)";
|
|
18
|
-
|
|
19
|
-
const SIZE_TO_PADDING = {
|
|
20
|
-
xs: 4,
|
|
21
|
-
sm: 6,
|
|
22
|
-
m: 8,
|
|
23
|
-
l: 12,
|
|
24
|
-
xl: 18,
|
|
25
|
-
} as const;
|
|
26
|
-
|
|
27
|
-
// ---------------- types ----------------
|
|
28
|
-
|
|
29
|
-
type Variant =
|
|
30
|
-
| "primary"
|
|
31
|
-
| "secondary"
|
|
32
|
-
| "tertiary"
|
|
33
|
-
| "outlined"
|
|
34
|
-
| "text"
|
|
35
|
-
| "link";
|
|
36
|
-
|
|
37
|
-
type VariantBools = {
|
|
38
|
-
primary?: boolean;
|
|
39
|
-
secondary?: boolean;
|
|
40
|
-
tertiary?: boolean;
|
|
41
|
-
outlined?: boolean;
|
|
42
|
-
text?: boolean;
|
|
43
|
-
link?: boolean;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
type SizeBools = {
|
|
47
|
-
xs?: boolean;
|
|
48
|
-
sm?: boolean;
|
|
49
|
-
m?: boolean;
|
|
50
|
-
l?: boolean;
|
|
51
|
-
xl?: boolean;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
type LabelConfig = string | { text: string; hideWhenInactive?: boolean };
|
|
55
|
-
|
|
56
|
-
type GroupContextValue = {
|
|
57
|
-
variant: Variant;
|
|
58
|
-
btnPadding: number;
|
|
59
|
-
isExclusive: boolean;
|
|
60
|
-
springLayout: boolean;
|
|
61
|
-
isActive: (index: number) => boolean;
|
|
62
|
-
onTabClick: (index: number, toggle: boolean | undefined) => void;
|
|
63
|
-
};
|
|
64
|
-
|
|
65
|
-
const GroupContext = createContext<GroupContextValue | null>(null);
|
|
66
|
-
|
|
67
|
-
// ---------------- usePressed hook ----------------
|
|
68
|
-
|
|
69
|
-
function usePressed(minDurationMs = 350) {
|
|
70
|
-
const [pressed, setPressed] = useState(false);
|
|
71
|
-
const pressedAtRef = useRef<number | null>(null);
|
|
72
|
-
const releaseTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
73
|
-
|
|
74
|
-
useEffect(
|
|
75
|
-
() => () => {
|
|
76
|
-
if (releaseTimerRef.current) clearTimeout(releaseTimerRef.current);
|
|
77
|
-
},
|
|
78
|
-
[],
|
|
79
|
-
);
|
|
80
|
-
|
|
81
|
-
const press = () => {
|
|
82
|
-
if (releaseTimerRef.current) {
|
|
83
|
-
clearTimeout(releaseTimerRef.current);
|
|
84
|
-
releaseTimerRef.current = null;
|
|
85
|
-
}
|
|
86
|
-
pressedAtRef.current = Date.now();
|
|
87
|
-
setPressed(true);
|
|
88
|
-
};
|
|
89
|
-
|
|
90
|
-
const release = () => {
|
|
91
|
-
const heldFor = pressedAtRef.current
|
|
92
|
-
? Date.now() - pressedAtRef.current
|
|
93
|
-
: minDurationMs;
|
|
94
|
-
const remaining = Math.max(0, minDurationMs - heldFor);
|
|
95
|
-
if (releaseTimerRef.current) clearTimeout(releaseTimerRef.current);
|
|
96
|
-
releaseTimerRef.current = setTimeout(() => setPressed(false), remaining);
|
|
97
|
-
};
|
|
98
|
-
|
|
99
|
-
return { pressed, press, release };
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function resolveVariant(p: VariantBools): Variant {
|
|
103
|
-
if (p.primary) return "primary";
|
|
104
|
-
if (p.secondary) return "secondary";
|
|
105
|
-
if (p.tertiary) return "tertiary";
|
|
106
|
-
if (p.outlined) return "outlined";
|
|
107
|
-
if (p.text) return "text";
|
|
108
|
-
if (p.link) return "link";
|
|
109
|
-
return "primary";
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function resolveSize(p: SizeBools): number {
|
|
113
|
-
if (p.xs) return SIZE_TO_PADDING.xs;
|
|
114
|
-
if (p.sm) return SIZE_TO_PADDING.sm;
|
|
115
|
-
if (p.l) return SIZE_TO_PADDING.l;
|
|
116
|
-
if (p.xl) return SIZE_TO_PADDING.xl;
|
|
117
|
-
return SIZE_TO_PADDING.m;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// shared style derivation for Tab and CTA
|
|
121
|
-
function deriveStyles(opts: {
|
|
122
|
-
variant: Variant;
|
|
123
|
-
toggle: boolean | undefined;
|
|
124
|
-
isActive: boolean;
|
|
125
|
-
pressed: boolean;
|
|
126
|
-
hasLabel: boolean;
|
|
127
|
-
hideWhenInactive?: boolean;
|
|
128
|
-
square?: boolean;
|
|
129
|
-
circle?: boolean;
|
|
130
|
-
btnPadding: number;
|
|
131
|
-
}) {
|
|
132
|
-
const {
|
|
133
|
-
variant,
|
|
134
|
-
toggle,
|
|
135
|
-
isActive,
|
|
136
|
-
pressed,
|
|
137
|
-
hasLabel,
|
|
138
|
-
hideWhenInactive,
|
|
139
|
-
square,
|
|
140
|
-
circle,
|
|
141
|
-
btnPadding,
|
|
142
|
-
} = opts;
|
|
143
|
-
|
|
144
|
-
// Padding shape selection:
|
|
145
|
-
// - `square` or `circle` force square padding
|
|
146
|
-
// - Buttons with an always-visible label → square
|
|
147
|
-
// - Icon-only OR labels that hide when inactive → pill
|
|
148
|
-
const useSquare = square || circle || (hasLabel && !hideWhenInactive);
|
|
149
|
-
|
|
150
|
-
// Base settled padding (no press)
|
|
151
|
-
// - Square: always btnPadding
|
|
152
|
-
// - Pill: btnPadding when toggle && active, else btnPadding - btnPadding/1.6
|
|
153
|
-
const basePadding = useSquare
|
|
154
|
-
? btnPadding
|
|
155
|
-
: toggle && isActive
|
|
156
|
-
? btnPadding
|
|
157
|
-
: btnPadding - btnPadding / 1.6;
|
|
158
|
-
|
|
159
|
-
// Press bounce: always-positive expansion while pressed
|
|
160
|
-
const bounceMag = Math.min(Math.max(btnPadding / 4, 8), 24);
|
|
161
|
-
const paddingInline = basePadding + (pressed ? bounceMag : 0);
|
|
162
|
-
|
|
163
|
-
// Border radius:
|
|
164
|
-
// - `square` → 14 always
|
|
165
|
-
// - `circle` → 36 always
|
|
166
|
-
// - Else: 36 when toggle && active, 14 otherwise
|
|
167
|
-
const borderRadius = square ? 14 : circle ? 36 : toggle && isActive ? 36 : 14;
|
|
168
|
-
|
|
169
|
-
// Variant key:
|
|
170
|
-
// - primary / secondary / tertiary → -bold when active
|
|
171
|
-
// - outlined → secondary-bold when active
|
|
172
|
-
// - text / link → no change when active
|
|
173
|
-
let variantKey: string = variant;
|
|
174
|
-
if (toggle && isActive) {
|
|
175
|
-
if (
|
|
176
|
-
variant === "primary" ||
|
|
177
|
-
variant === "secondary" ||
|
|
178
|
-
variant === "tertiary"
|
|
179
|
-
) {
|
|
180
|
-
variantKey = `${variant}-bold`;
|
|
181
|
-
} else if (variant === "outlined") {
|
|
182
|
-
variantKey = "secondary-bold";
|
|
183
|
-
}
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return { paddingInline, borderRadius, variantKey };
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// ---------------- Tab ----------------
|
|
190
|
-
|
|
191
|
-
type TabProps = {
|
|
192
|
-
default?: boolean;
|
|
193
|
-
systemName?: string;
|
|
194
|
-
label?: LabelConfig;
|
|
195
|
-
toggle?: boolean;
|
|
196
|
-
/** Force border-radius 14 and square padding regardless of active state */
|
|
197
|
-
square?: boolean;
|
|
198
|
-
/** Force border-radius 36 and square padding regardless of active state */
|
|
199
|
-
circle?: boolean;
|
|
200
|
-
onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;
|
|
201
|
-
} & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onClick">;
|
|
202
|
-
|
|
203
|
-
type TabInternalProps = TabProps & { _index?: number };
|
|
204
|
-
|
|
205
|
-
function Tab({
|
|
206
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
207
|
-
default: _isDefault,
|
|
208
|
-
systemName,
|
|
209
|
-
label,
|
|
210
|
-
toggle,
|
|
211
|
-
square = false,
|
|
212
|
-
circle = false,
|
|
213
|
-
onClick,
|
|
214
|
-
_index,
|
|
215
|
-
style,
|
|
216
|
-
...rest
|
|
217
|
-
}: TabInternalProps) {
|
|
218
|
-
const ctx = useContext(GroupContext);
|
|
219
|
-
if (!ctx || _index === undefined) {
|
|
220
|
-
throw new Error("Button.
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const { pressed, press, release } = usePressed();
|
|
224
|
-
const isActive = ctx.isActive(_index);
|
|
225
|
-
|
|
226
|
-
const labelText = typeof label === "string" ? label : label?.text;
|
|
227
|
-
const hideWhenInactive =
|
|
228
|
-
typeof label === "object" ? !!label.hideWhenInactive : false;
|
|
229
|
-
const labelVisible =
|
|
230
|
-
labelText !== undefined && (!hideWhenInactive || isActive);
|
|
231
|
-
const iconLabel = labelVisible ? labelText :
|
|
232
|
-
const hasLabel = label !== undefined;
|
|
233
|
-
|
|
234
|
-
const { paddingInline, borderRadius, variantKey } = deriveStyles({
|
|
235
|
-
variant: ctx.variant,
|
|
236
|
-
toggle,
|
|
237
|
-
isActive,
|
|
238
|
-
pressed,
|
|
239
|
-
hasLabel,
|
|
240
|
-
hideWhenInactive,
|
|
241
|
-
square,
|
|
242
|
-
circle,
|
|
243
|
-
btnPadding: ctx.btnPadding,
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
247
|
-
const isAlreadyActiveExclusive =
|
|
248
|
-
ctx.isExclusive && toggle && ctx.isActive(_index);
|
|
249
|
-
ctx.onTabClick(_index, toggle);
|
|
250
|
-
if (!isAlreadyActiveExclusive) onClick?.(e);
|
|
251
|
-
};
|
|
252
|
-
|
|
253
|
-
return (
|
|
254
|
-
<
|
|
255
|
-
{...{ [variantKey]: true }}
|
|
256
|
-
onClick={handleClick}
|
|
257
|
-
onPointerDown={press}
|
|
258
|
-
onPointerUp={release}
|
|
259
|
-
onPointerLeave={release}
|
|
260
|
-
onPointerCancel={release}
|
|
261
|
-
style={{
|
|
262
|
-
padding: ctx.btnPadding,
|
|
263
|
-
paddingInline,
|
|
264
|
-
margin: 0,
|
|
265
|
-
borderRadius,
|
|
266
|
-
transition: TRANSITION,
|
|
267
|
-
...(ctx.springLayout
|
|
268
|
-
? { flex: "1 1 auto", minWidth: 0, width: "max-content" }
|
|
269
|
-
: {}),
|
|
270
|
-
...style,
|
|
271
|
-
}}
|
|
272
|
-
{...rest}
|
|
273
|
-
>
|
|
274
|
-
<
|
|
275
|
-
</
|
|
276
|
-
);
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
//
|
|
280
|
-
|
|
281
|
-
type
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
function
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
const
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
}
|
|
416
|
-
});
|
|
417
|
-
return defaults;
|
|
418
|
-
});
|
|
419
|
-
|
|
420
|
-
const handleTabClick = (index: number, toggle: boolean | undefined) => {
|
|
421
|
-
if (!toggle) return;
|
|
422
|
-
|
|
423
|
-
const next = new Set(activeIndices);
|
|
424
|
-
const wasActive = next.has(index);
|
|
425
|
-
|
|
426
|
-
// In exclusive mode, can't deactivate the currently-active tab by clicking it
|
|
427
|
-
if (wasActive && isExclusive) return;
|
|
428
|
-
|
|
429
|
-
if (wasActive) {
|
|
430
|
-
next.delete(index);
|
|
431
|
-
} else {
|
|
432
|
-
if (isExclusive) next.clear();
|
|
433
|
-
next.add(index);
|
|
434
|
-
}
|
|
435
|
-
setActiveIndices(next);
|
|
436
|
-
};
|
|
437
|
-
|
|
438
|
-
const ctxValue: GroupContextValue = {
|
|
439
|
-
variant,
|
|
440
|
-
btnPadding,
|
|
441
|
-
isExclusive,
|
|
442
|
-
springLayout,
|
|
443
|
-
isActive: (i) => activeIndices.has(i),
|
|
444
|
-
onTabClick: handleTabClick,
|
|
445
|
-
};
|
|
446
|
-
|
|
447
|
-
const bounceMag = Math.min(Math.max(btnPadding / 4, 8), 24);
|
|
448
|
-
|
|
449
|
-
const computedMaxWidth =
|
|
450
|
-
width !== undefined ? `${Number(width) + bounceMag * 0}px` : "100%";
|
|
451
|
-
|
|
452
|
-
return (
|
|
453
|
-
<GroupContext.Provider value={ctxValue}>
|
|
454
|
-
<div
|
|
455
|
-
style={{
|
|
456
|
-
display: "flex",
|
|
457
|
-
flexDirection: "row",
|
|
458
|
-
alignItems: "center",
|
|
459
|
-
justifyContent: "center",
|
|
460
|
-
overflow: "hidden",
|
|
461
|
-
overflowX: "auto",
|
|
462
|
-
width: width
|
|
463
|
-
? computedMaxWidth
|
|
464
|
-
: width == "fullWidth"
|
|
465
|
-
? "100%"
|
|
466
|
-
: "max-content",
|
|
467
|
-
maxWidth: computedMaxWidth,
|
|
468
|
-
gap: `${GAP * 2}px`,
|
|
469
|
-
}}
|
|
470
|
-
>
|
|
471
|
-
<div
|
|
472
|
-
style={{
|
|
473
|
-
display: "flex",
|
|
474
|
-
flexDirection: "row",
|
|
475
|
-
overflow: "hidden",
|
|
476
|
-
overflowX: "auto",
|
|
477
|
-
flex: springLayout || width == "fullWidth" ? "1 1 auto" : undefined,
|
|
478
|
-
minWidth: 0,
|
|
479
|
-
gap: `${GAP}px`,
|
|
480
|
-
}}
|
|
481
|
-
>
|
|
482
|
-
{tabs.map((tab, index) =>
|
|
483
|
-
React.cloneElement(tab as React.ReactElement<TabInternalProps>, {
|
|
484
|
-
_index: index,
|
|
485
|
-
key: index,
|
|
486
|
-
}),
|
|
487
|
-
)}
|
|
488
|
-
</div>
|
|
489
|
-
{cta && (
|
|
490
|
-
<CTAButton
|
|
491
|
-
{...cta}
|
|
492
|
-
btnPadding={btnPadding}
|
|
493
|
-
springLayout={springLayout}
|
|
494
|
-
/>
|
|
495
|
-
)}
|
|
496
|
-
</div>
|
|
497
|
-
</GroupContext.Provider>
|
|
498
|
-
);
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
ButtonGroup.Tab = Tab;
|
|
502
|
-
|
|
503
|
-
export default ButtonGroup;
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import React, {
|
|
4
|
+
createContext,
|
|
5
|
+
useContext,
|
|
6
|
+
useEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
useState,
|
|
9
|
+
} from "react";
|
|
10
|
+
import Label from "@/components/tools/label/Label";
|
|
11
|
+
import BaseButton from "./button";
|
|
12
|
+
|
|
13
|
+
// ---------------- config knobs ----------------
|
|
14
|
+
|
|
15
|
+
const GAP = 4;
|
|
16
|
+
const TRANSITION =
|
|
17
|
+
"all var(--transition-expressive-color), border-radius var(--transition-expressive), padding-inline var(--transition-expressive)";
|
|
18
|
+
|
|
19
|
+
const SIZE_TO_PADDING = {
|
|
20
|
+
xs: 4,
|
|
21
|
+
sm: 6,
|
|
22
|
+
m: 8,
|
|
23
|
+
l: 12,
|
|
24
|
+
xl: 18,
|
|
25
|
+
} as const;
|
|
26
|
+
|
|
27
|
+
// ---------------- types ----------------
|
|
28
|
+
|
|
29
|
+
type Variant =
|
|
30
|
+
| "primary"
|
|
31
|
+
| "secondary"
|
|
32
|
+
| "tertiary"
|
|
33
|
+
| "outlined"
|
|
34
|
+
| "text"
|
|
35
|
+
| "link";
|
|
36
|
+
|
|
37
|
+
type VariantBools = {
|
|
38
|
+
primary?: boolean;
|
|
39
|
+
secondary?: boolean;
|
|
40
|
+
tertiary?: boolean;
|
|
41
|
+
outlined?: boolean;
|
|
42
|
+
text?: boolean;
|
|
43
|
+
link?: boolean;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
type SizeBools = {
|
|
47
|
+
xs?: boolean;
|
|
48
|
+
sm?: boolean;
|
|
49
|
+
m?: boolean;
|
|
50
|
+
l?: boolean;
|
|
51
|
+
xl?: boolean;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
type LabelConfig = string | { text: string; hideWhenInactive?: boolean };
|
|
55
|
+
|
|
56
|
+
type GroupContextValue = {
|
|
57
|
+
variant: Variant;
|
|
58
|
+
btnPadding: number;
|
|
59
|
+
isExclusive: boolean;
|
|
60
|
+
springLayout: boolean;
|
|
61
|
+
isActive: (index: number) => boolean;
|
|
62
|
+
onTabClick: (index: number, toggle: boolean | undefined) => void;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
const GroupContext = createContext<GroupContextValue | null>(null);
|
|
66
|
+
|
|
67
|
+
// ---------------- usePressed hook ----------------
|
|
68
|
+
|
|
69
|
+
function usePressed(minDurationMs = 350) {
|
|
70
|
+
const [pressed, setPressed] = useState(false);
|
|
71
|
+
const pressedAtRef = useRef<number | null>(null);
|
|
72
|
+
const releaseTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
73
|
+
|
|
74
|
+
useEffect(
|
|
75
|
+
() => () => {
|
|
76
|
+
if (releaseTimerRef.current) clearTimeout(releaseTimerRef.current);
|
|
77
|
+
},
|
|
78
|
+
[],
|
|
79
|
+
);
|
|
80
|
+
|
|
81
|
+
const press = () => {
|
|
82
|
+
if (releaseTimerRef.current) {
|
|
83
|
+
clearTimeout(releaseTimerRef.current);
|
|
84
|
+
releaseTimerRef.current = null;
|
|
85
|
+
}
|
|
86
|
+
pressedAtRef.current = Date.now();
|
|
87
|
+
setPressed(true);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const release = () => {
|
|
91
|
+
const heldFor = pressedAtRef.current
|
|
92
|
+
? Date.now() - pressedAtRef.current
|
|
93
|
+
: minDurationMs;
|
|
94
|
+
const remaining = Math.max(0, minDurationMs - heldFor);
|
|
95
|
+
if (releaseTimerRef.current) clearTimeout(releaseTimerRef.current);
|
|
96
|
+
releaseTimerRef.current = setTimeout(() => setPressed(false), remaining);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
return { pressed, press, release };
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function resolveVariant(p: VariantBools): Variant {
|
|
103
|
+
if (p.primary) return "primary";
|
|
104
|
+
if (p.secondary) return "secondary";
|
|
105
|
+
if (p.tertiary) return "tertiary";
|
|
106
|
+
if (p.outlined) return "outlined";
|
|
107
|
+
if (p.text) return "text";
|
|
108
|
+
if (p.link) return "link";
|
|
109
|
+
return "primary";
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function resolveSize(p: SizeBools): number {
|
|
113
|
+
if (p.xs) return SIZE_TO_PADDING.xs;
|
|
114
|
+
if (p.sm) return SIZE_TO_PADDING.sm;
|
|
115
|
+
if (p.l) return SIZE_TO_PADDING.l;
|
|
116
|
+
if (p.xl) return SIZE_TO_PADDING.xl;
|
|
117
|
+
return SIZE_TO_PADDING.m;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// shared style derivation for Tab and CTA
|
|
121
|
+
function deriveStyles(opts: {
|
|
122
|
+
variant: Variant;
|
|
123
|
+
toggle: boolean | undefined;
|
|
124
|
+
isActive: boolean;
|
|
125
|
+
pressed: boolean;
|
|
126
|
+
hasLabel: boolean;
|
|
127
|
+
hideWhenInactive?: boolean;
|
|
128
|
+
square?: boolean;
|
|
129
|
+
circle?: boolean;
|
|
130
|
+
btnPadding: number;
|
|
131
|
+
}) {
|
|
132
|
+
const {
|
|
133
|
+
variant,
|
|
134
|
+
toggle,
|
|
135
|
+
isActive,
|
|
136
|
+
pressed,
|
|
137
|
+
hasLabel,
|
|
138
|
+
hideWhenInactive,
|
|
139
|
+
square,
|
|
140
|
+
circle,
|
|
141
|
+
btnPadding,
|
|
142
|
+
} = opts;
|
|
143
|
+
|
|
144
|
+
// Padding shape selection:
|
|
145
|
+
// - `square` or `circle` force square padding
|
|
146
|
+
// - Buttons with an always-visible label → square
|
|
147
|
+
// - Icon-only OR labels that hide when inactive → pill
|
|
148
|
+
const useSquare = square || circle || (hasLabel && !hideWhenInactive);
|
|
149
|
+
|
|
150
|
+
// Base settled padding (no press)
|
|
151
|
+
// - Square: always btnPadding
|
|
152
|
+
// - Pill: btnPadding when toggle && active, else btnPadding - btnPadding/1.6
|
|
153
|
+
const basePadding = useSquare
|
|
154
|
+
? btnPadding
|
|
155
|
+
: toggle && isActive
|
|
156
|
+
? btnPadding
|
|
157
|
+
: btnPadding - btnPadding / 1.6;
|
|
158
|
+
|
|
159
|
+
// Press bounce: always-positive expansion while pressed
|
|
160
|
+
const bounceMag = Math.min(Math.max(btnPadding / 4, 8), 24);
|
|
161
|
+
const paddingInline = basePadding + (pressed ? bounceMag : 0);
|
|
162
|
+
|
|
163
|
+
// Border radius:
|
|
164
|
+
// - `square` → 14 always
|
|
165
|
+
// - `circle` → 36 always
|
|
166
|
+
// - Else: 36 when toggle && active, 14 otherwise
|
|
167
|
+
const borderRadius = square ? 14 : circle ? 36 : toggle && isActive ? 36 : 14;
|
|
168
|
+
|
|
169
|
+
// Variant key:
|
|
170
|
+
// - primary / secondary / tertiary → -bold when active
|
|
171
|
+
// - outlined → secondary-bold when active
|
|
172
|
+
// - text / link → no change when active
|
|
173
|
+
let variantKey: string = variant;
|
|
174
|
+
if (toggle && isActive) {
|
|
175
|
+
if (
|
|
176
|
+
variant === "primary" ||
|
|
177
|
+
variant === "secondary" ||
|
|
178
|
+
variant === "tertiary"
|
|
179
|
+
) {
|
|
180
|
+
variantKey = `${variant}-bold`;
|
|
181
|
+
} else if (variant === "outlined") {
|
|
182
|
+
variantKey = "secondary-bold";
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return { paddingInline, borderRadius, variantKey };
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// ---------------- Tab ----------------
|
|
190
|
+
|
|
191
|
+
type TabProps = {
|
|
192
|
+
default?: boolean;
|
|
193
|
+
systemName?: string;
|
|
194
|
+
label?: LabelConfig;
|
|
195
|
+
toggle?: boolean;
|
|
196
|
+
/** Force border-radius 14 and square padding regardless of active state */
|
|
197
|
+
square?: boolean;
|
|
198
|
+
/** Force border-radius 36 and square padding regardless of active state */
|
|
199
|
+
circle?: boolean;
|
|
200
|
+
onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;
|
|
201
|
+
} & Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onClick">;
|
|
202
|
+
|
|
203
|
+
type TabInternalProps = TabProps & { _index?: number };
|
|
204
|
+
|
|
205
|
+
function Tab({
|
|
206
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
207
|
+
default: _isDefault,
|
|
208
|
+
systemName,
|
|
209
|
+
label,
|
|
210
|
+
toggle,
|
|
211
|
+
square = false,
|
|
212
|
+
circle = false,
|
|
213
|
+
onClick,
|
|
214
|
+
_index,
|
|
215
|
+
style,
|
|
216
|
+
...rest
|
|
217
|
+
}: TabInternalProps) {
|
|
218
|
+
const ctx = useContext(GroupContext);
|
|
219
|
+
if (!ctx || _index === undefined) {
|
|
220
|
+
throw new Error("Button.Tab must be a direct child of Button.Group");
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const { pressed, press, release } = usePressed();
|
|
224
|
+
const isActive = ctx.isActive(_index);
|
|
225
|
+
|
|
226
|
+
const labelText = typeof label === "string" ? label : label?.text;
|
|
227
|
+
const hideWhenInactive =
|
|
228
|
+
typeof label === "object" ? !!label.hideWhenInactive : false;
|
|
229
|
+
const labelVisible =
|
|
230
|
+
labelText !== undefined && (!hideWhenInactive || isActive);
|
|
231
|
+
const iconLabel = labelVisible ? labelText : "";
|
|
232
|
+
const hasLabel = label !== undefined;
|
|
233
|
+
|
|
234
|
+
const { paddingInline, borderRadius, variantKey } = deriveStyles({
|
|
235
|
+
variant: ctx.variant,
|
|
236
|
+
toggle,
|
|
237
|
+
isActive,
|
|
238
|
+
pressed,
|
|
239
|
+
hasLabel,
|
|
240
|
+
hideWhenInactive,
|
|
241
|
+
square,
|
|
242
|
+
circle,
|
|
243
|
+
btnPadding: ctx.btnPadding,
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
247
|
+
const isAlreadyActiveExclusive =
|
|
248
|
+
ctx.isExclusive && toggle && ctx.isActive(_index);
|
|
249
|
+
ctx.onTabClick(_index, toggle);
|
|
250
|
+
if (!isAlreadyActiveExclusive) onClick?.(e);
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
return (
|
|
254
|
+
<BaseButton
|
|
255
|
+
{...{ [variantKey]: true }}
|
|
256
|
+
onClick={handleClick}
|
|
257
|
+
onPointerDown={press}
|
|
258
|
+
onPointerUp={release}
|
|
259
|
+
onPointerLeave={release}
|
|
260
|
+
onPointerCancel={release}
|
|
261
|
+
style={{
|
|
262
|
+
padding: ctx.btnPadding,
|
|
263
|
+
paddingInline,
|
|
264
|
+
margin: 0,
|
|
265
|
+
borderRadius,
|
|
266
|
+
transition: TRANSITION,
|
|
267
|
+
...(ctx.springLayout
|
|
268
|
+
? { flex: "1 1 auto", minWidth: 0, width: "max-content" }
|
|
269
|
+
: {}),
|
|
270
|
+
...style,
|
|
271
|
+
}}
|
|
272
|
+
{...rest}
|
|
273
|
+
>
|
|
274
|
+
<Label systemName={systemName} reverse label={iconLabel} />
|
|
275
|
+
</BaseButton>
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// MARK: Group
|
|
280
|
+
|
|
281
|
+
type ButtonGroupProps = {
|
|
282
|
+
children: React.ReactNode;
|
|
283
|
+
/** When true (default), only one tab can be active at a time. */
|
|
284
|
+
exclusive?: boolean;
|
|
285
|
+
/** Inverse of `exclusive`. If both are set, this wins. */
|
|
286
|
+
multiSelect?: boolean;
|
|
287
|
+
/**
|
|
288
|
+
* Fixed width for the group. When set, tabs share the width with `flex: 1 1 auto`
|
|
289
|
+
* — pressing one tab visibly squeezes its siblings (spring effect).
|
|
290
|
+
* When unset, the group sits at `max-content` (no spring, natural sizes).
|
|
291
|
+
*/
|
|
292
|
+
width?: number | string | "fullWidth";
|
|
293
|
+
} & VariantBools &
|
|
294
|
+
SizeBools;
|
|
295
|
+
|
|
296
|
+
function Group({
|
|
297
|
+
children,
|
|
298
|
+
exclusive = true,
|
|
299
|
+
multiSelect,
|
|
300
|
+
width,
|
|
301
|
+
// size bools
|
|
302
|
+
xs,
|
|
303
|
+
sm,
|
|
304
|
+
m,
|
|
305
|
+
l,
|
|
306
|
+
xl,
|
|
307
|
+
// variant bools
|
|
308
|
+
...variantBools
|
|
309
|
+
}: ButtonGroupProps) {
|
|
310
|
+
const isExclusive = multiSelect !== undefined ? !multiSelect : exclusive;
|
|
311
|
+
const variant = resolveVariant(variantBools);
|
|
312
|
+
const btnPadding = resolveSize({ xs, sm, m, l, xl });
|
|
313
|
+
const isFullWidth = width === "fullWidth";
|
|
314
|
+
const springLayout = width !== undefined && !isFullWidth;
|
|
315
|
+
|
|
316
|
+
const childArray = React.Children.toArray(children).filter(
|
|
317
|
+
React.isValidElement,
|
|
318
|
+
);
|
|
319
|
+
const tabs = childArray.filter((child) => child.type === Tab);
|
|
320
|
+
const otherChildren = childArray.filter((child) => child.type !== Tab);
|
|
321
|
+
|
|
322
|
+
const [activeIndices, setActiveIndices] = useState<Set<number>>(() => {
|
|
323
|
+
const defaults = new Set<number>();
|
|
324
|
+
tabs.forEach((child, idx) => {
|
|
325
|
+
const props = (child as React.ReactElement<TabProps>).props;
|
|
326
|
+
if (props.default) {
|
|
327
|
+
if (isExclusive && defaults.size > 0) return;
|
|
328
|
+
defaults.add(idx);
|
|
329
|
+
}
|
|
330
|
+
});
|
|
331
|
+
return defaults;
|
|
332
|
+
});
|
|
333
|
+
|
|
334
|
+
const handleTabClick = (index: number, toggle: boolean | undefined) => {
|
|
335
|
+
if (!toggle) return;
|
|
336
|
+
|
|
337
|
+
const next = new Set(activeIndices);
|
|
338
|
+
const wasActive = next.has(index);
|
|
339
|
+
|
|
340
|
+
// In exclusive mode, can't deactivate the currently-active tab by clicking it
|
|
341
|
+
if (wasActive && isExclusive) return;
|
|
342
|
+
|
|
343
|
+
if (wasActive) {
|
|
344
|
+
next.delete(index);
|
|
345
|
+
} else {
|
|
346
|
+
if (isExclusive) next.clear();
|
|
347
|
+
next.add(index);
|
|
348
|
+
}
|
|
349
|
+
setActiveIndices(next);
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
const ctxValue: GroupContextValue = {
|
|
353
|
+
variant,
|
|
354
|
+
btnPadding,
|
|
355
|
+
isExclusive,
|
|
356
|
+
springLayout,
|
|
357
|
+
isActive: (i) => activeIndices.has(i),
|
|
358
|
+
onTabClick: handleTabClick,
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
const computedMaxWidth = springLayout ? `${Number(width)}px` : "100%";
|
|
362
|
+
|
|
363
|
+
return (
|
|
364
|
+
<GroupContext.Provider value={ctxValue}>
|
|
365
|
+
<div
|
|
366
|
+
style={{
|
|
367
|
+
display: "flex",
|
|
368
|
+
flexDirection: "row",
|
|
369
|
+
alignItems: "center",
|
|
370
|
+
justifyContent: "center",
|
|
371
|
+
overflow: "hidden",
|
|
372
|
+
overflowX: "auto",
|
|
373
|
+
width: springLayout
|
|
374
|
+
? computedMaxWidth
|
|
375
|
+
: isFullWidth
|
|
376
|
+
? "100%"
|
|
377
|
+
: "max-content",
|
|
378
|
+
maxWidth: computedMaxWidth,
|
|
379
|
+
gap: `${GAP * 2}px`,
|
|
380
|
+
}}
|
|
381
|
+
>
|
|
382
|
+
<div
|
|
383
|
+
style={{
|
|
384
|
+
display: "flex",
|
|
385
|
+
flexDirection: "row",
|
|
386
|
+
overflow: "hidden",
|
|
387
|
+
overflowX: "auto",
|
|
388
|
+
flex: springLayout || isFullWidth ? "1 1 auto" : undefined,
|
|
389
|
+
minWidth: 0,
|
|
390
|
+
gap: `${GAP}px`,
|
|
391
|
+
}}
|
|
392
|
+
>
|
|
393
|
+
{tabs.map((tab, index) =>
|
|
394
|
+
React.cloneElement(tab as React.ReactElement<TabInternalProps>, {
|
|
395
|
+
_index: index,
|
|
396
|
+
key: index,
|
|
397
|
+
}),
|
|
398
|
+
)}
|
|
399
|
+
</div>
|
|
400
|
+
{otherChildren}
|
|
401
|
+
</div>
|
|
402
|
+
</GroupContext.Provider>
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
Object.assign(BaseButton, { Group, Tab });
|
|
407
|
+
|
|
408
|
+
type ButtonWithStatics = typeof BaseButton & {
|
|
409
|
+
Group: typeof Group;
|
|
410
|
+
Tab: typeof Tab;
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
export { Group, Tab };
|
|
414
|
+
export default BaseButton as ButtonWithStatics;
|