@altruist03/ui 0.1.0 → 0.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/assets/images/noData.webp +0 -0
- package/dist/index.js +15237 -650
- package/dist/index.js.map +1 -1
- package/dist/noData-XPRHKMFR.webp +0 -0
- package/package.json +21 -7
- package/src/ThemeProvider/ThemeContext.tsx +75 -0
- package/src/ThemeProvider/index.ts +7 -0
- package/src/assets/images/noData.webp +0 -0
- package/src/assets.d.ts +10 -0
- package/src/components/Accordion/Accordion.stories.tsx +64 -0
- package/src/components/Accordion/Accordion.tsx +219 -0
- package/src/components/Accordion/Accordion.types.ts +16 -0
- package/src/components/Avatar/Avatar.stories.tsx +304 -0
- package/src/components/Avatar/Avatar.tsx +211 -0
- package/src/components/Avatar/Avatar.types.ts +33 -0
- package/src/components/Badge/Badge.stories.tsx +143 -0
- package/src/components/Badge/Badge.tsx +138 -0
- package/src/components/Badge/Badge.types.ts +24 -0
- package/src/components/Breadcrumb/Breadcrumb.stories.tsx +114 -0
- package/src/components/Breadcrumb/Breadcrumb.tsx +120 -0
- package/src/components/Breadcrumb/Breadcrumb.types.ts +22 -0
- package/src/components/Button/Button.stories.tsx +457 -0
- package/src/components/Button/Button.tsx +202 -0
- package/src/components/Button/Button.types.ts +18 -0
- package/src/components/Checkbox/Checkbox.stories.tsx +254 -0
- package/src/components/Checkbox/Checkbox.tsx +352 -0
- package/src/components/Checkbox/Checkbox.types.ts +123 -0
- package/src/components/CloseButton/CloseButton.stories.tsx +100 -0
- package/src/components/CloseButton/CloseButton.tsx +117 -0
- package/src/components/CloseButton/CloseButton.types.ts +15 -0
- package/src/components/CollapsibleSearch/CollapsibleSearch.tsx +120 -0
- package/src/components/DataTable/DataTable.stories.tsx +233 -0
- package/src/components/DataTable/DataTable.tsx +968 -0
- package/src/components/DataTable/DataTable.types.ts +49 -0
- package/src/components/DatePicker/DatePicker.stories.tsx +341 -0
- package/src/components/DatePicker/DatePicker.tsx +669 -0
- package/src/components/DatePicker/DatePicker.types.ts +105 -0
- package/src/components/DatePicker/DateTimePicker.tsx +35 -0
- package/src/components/DateRangePicker/DateRangePicker.tsx +179 -0
- package/src/components/DateRangePicker/DateRangePicker.types.ts +34 -0
- package/src/components/Drawer/Drawer.stories.tsx +243 -0
- package/src/components/Drawer/Drawer.tsx +196 -0
- package/src/components/Drawer/Drawer.types.ts +60 -0
- package/src/components/FileUpload/FileUpload.stories.tsx +162 -0
- package/src/components/FileUpload/FileUpload.tsx +216 -0
- package/src/components/FileUpload/FileUpload.types.ts +80 -0
- package/src/components/FilterPopover/FilterPopover.stories.tsx +173 -0
- package/src/components/FilterPopover/FilterPopover.tsx +310 -0
- package/src/components/FilterPopover/FilterPopover.types.ts +26 -0
- package/src/components/ImageViewer/ImageViewerToolbar.jsx +81 -0
- package/src/components/ImageViewer/useImagePanRotate.js +102 -0
- package/src/components/IpWhitelistField/IpWhitelistField.stories.tsx +138 -0
- package/src/components/IpWhitelistField/IpWhitelistField.tsx +164 -0
- package/src/components/IpWhitelistField/IpWhitelistField.types.ts +42 -0
- package/src/components/Loader/Loader.stories.tsx +95 -0
- package/src/components/Loader/Loader.tsx +132 -0
- package/src/components/Loader/Loader.types.ts +6 -0
- package/src/components/Menu/Menu.tsx +143 -0
- package/src/components/Menu/Menu.types.ts +28 -0
- package/src/components/MenuButton/MenuButton.stories.tsx +140 -0
- package/src/components/MenuButton/MenuButton.tsx +45 -0
- package/src/components/MenuButton/MenuButton.types.ts +21 -0
- package/src/components/Modal/Modal.stories.tsx +266 -0
- package/src/components/Modal/Modal.tsx +399 -0
- package/src/components/Modal/index.ts +2 -0
- package/src/components/Modal/types.ts +126 -0
- package/src/components/Pagination/Pagination.stories.tsx +167 -0
- package/src/components/Pagination/Pagination.tsx +266 -0
- package/src/components/Pagination/Pagination.types.ts +20 -0
- package/src/components/PeriodSelector/PeriodSelector.stories.tsx +50 -0
- package/src/components/PeriodSelector/PeriodSelector.tsx +47 -0
- package/src/components/PeriodSelector/PeriodSelector.types.ts +10 -0
- package/src/components/PhoneField/PhoneField.stories.tsx +141 -0
- package/src/components/PhoneField/PhoneField.tsx +284 -0
- package/src/components/PhoneField/PhoneField.types.ts +89 -0
- package/src/components/PhoneField/countryCodes.ts +236 -0
- package/src/components/Progress/Progress.stories.tsx +83 -0
- package/src/components/Progress/Progress.tsx +91 -0
- package/src/components/Progress/Progress.types.ts +22 -0
- package/src/components/RadioButton/RadioButton.stories.tsx +332 -0
- package/src/components/RadioButton/RadioButton.tsx +427 -0
- package/src/components/RadioButton/RadioButton.types.ts +117 -0
- package/src/components/ReportCard/ReportCard.tsx +183 -0
- package/src/components/ReportCard/ReportCard.types.ts +17 -0
- package/src/components/SectionIcon/SectionIcon.tsx +87 -0
- package/src/components/SectionIcon/SectionIcon.types.ts +23 -0
- package/src/components/SegmentedInputField/SegmentedInputField.stories.tsx +165 -0
- package/src/components/SegmentedInputField/SegmentedInputField.tsx +174 -0
- package/src/components/SegmentedInputField/SegmentedInputField.types.ts +51 -0
- package/src/components/SelectScroll/SelectScroll.stories.tsx +336 -0
- package/src/components/SelectScroll/SelectScroll.tsx +1119 -0
- package/src/components/SelectScroll/SelectScroll.types.ts +60 -0
- package/src/components/Selector/Selector.stories.tsx +382 -0
- package/src/components/Selector/Selector.tsx +1310 -0
- package/src/components/Selector/Selector.types.ts +71 -0
- package/src/components/Skeleton/Skeleton.stories.tsx +133 -0
- package/src/components/Skeleton/Skeleton.tsx +20 -0
- package/src/components/Skeleton/Skeleton.types.ts +3 -0
- package/src/components/Spinner/Spinner.stories.tsx +84 -0
- package/src/components/Spinner/Spinner.tsx +79 -0
- package/src/components/Spinner/Spinner.types.ts +8 -0
- package/src/components/StatCard/StatCard.stories.tsx +125 -0
- package/src/components/StatCard/StatCard.tsx +167 -0
- package/src/components/StatCard/StatCard.types.ts +20 -0
- package/src/components/StatusBadge/StatusBadge.stories.tsx +179 -0
- package/src/components/StatusBadge/StatusBadge.tsx +74 -0
- package/src/components/StatusBadge/StatusBadge.types.ts +23 -0
- package/src/components/Stepper/Stepper.stories.tsx +85 -0
- package/src/components/Stepper/Stepper.tsx +138 -0
- package/src/components/Stepper/Stepper.types.ts +16 -0
- package/src/components/SubTabs/SubTabs.stories.tsx +128 -0
- package/src/components/SubTabs/SubTabs.tsx +279 -0
- package/src/components/SubTabs/SubTabs.types.ts +44 -0
- package/src/components/SummaryCard/SummaryCard.stories.tsx +100 -0
- package/src/components/SummaryCard/SummaryCard.tsx +141 -0
- package/src/components/SummaryCard/SummaryCard.types.ts +22 -0
- package/src/components/Switch/Switch.stories.tsx +59 -0
- package/src/components/Switch/Switch.tsx +217 -0
- package/src/components/Switch/Switch.types.ts +22 -0
- package/src/components/Tabs/Tabs.stories.tsx +178 -0
- package/src/components/Tabs/Tabs.tsx +197 -0
- package/src/components/Tabs/Tabs.types.ts +34 -0
- package/src/components/TextField/TextField.stories.tsx +249 -0
- package/src/components/TextField/TextField.tsx +462 -0
- package/src/components/TextField/TextField.types.ts +141 -0
- package/src/components/Toast/Toast.stories.tsx +237 -0
- package/src/components/Toast/Toast.tsx +246 -0
- package/src/components/Toast/Toast.types.ts +31 -0
- package/src/components/ToggleButton/ToggleButton.stories.tsx +105 -0
- package/src/components/ToggleButton/ToggleButton.tsx +267 -0
- package/src/components/ToggleButton/ToggleButton.types.ts +19 -0
- package/src/components/UploadDropzone/UploadDropzone.jsx +78 -0
- package/src/components/UploadDropzone2/UploadDropzone.stories.tsx +94 -0
- package/src/components/UploadDropzone2/UploadDropzone.tsx +222 -0
- package/src/components/UploadDropzone2/UploadDropzone.types.ts +54 -0
- package/src/components/ViewEditToggle/ViewEditToggle.stories.tsx +40 -0
- package/src/components/ViewEditToggle/ViewEditToggle.tsx +239 -0
- package/src/components/ViewEditToggle/ViewEditToggle.types.ts +27 -0
- package/src/components/index.ts +157 -0
- package/src/icons/ReportDollarIcon.tsx +71 -0
- package/src/icons/index.ts +27 -0
- package/src/index.ts +214 -0
- package/src/storybook/preview.tsx +64 -0
- package/src/theme/index.ts +4 -0
- package/src/theme/types.d.ts +1 -0
- package/src/themes/cpc.ts +4 -0
- package/src/themes/firebird.ts +4 -0
- package/src/tokens/brands/cpc/themes/dark.json +82 -0
- package/src/tokens/brands/cpc/themes/light.json +1 -0
- package/src/tokens/brands/default/brand.json +20 -0
- package/src/tokens/brands/firebird/themes/dark.json +28 -0
- package/src/tokens/brands/firebird/themes/light.json +20 -0
- package/src/tokens/button.ts +24 -0
- package/src/tokens/components/accordion.json +52 -0
- package/src/tokens/components/avatar.json +40 -0
- package/src/tokens/components/badge.json +41 -0
- package/src/tokens/components/breadcrumb.json +13 -0
- package/src/tokens/components/button.json +67 -0
- package/src/tokens/components/card.json +39 -0
- package/src/tokens/components/checkbox.json +64 -0
- package/src/tokens/components/closebutton.json +55 -0
- package/src/tokens/components/datatable.json +40 -0
- package/src/tokens/components/datepicker.json +99 -0
- package/src/tokens/components/drawer.json +23 -0
- package/src/tokens/components/field.json +29 -0
- package/src/tokens/components/fileupload.json +57 -0
- package/src/tokens/components/filterpopover.json +29 -0
- package/src/tokens/components/input.json +31 -0
- package/src/tokens/components/ipwhitelistfield.json +16 -0
- package/src/tokens/components/loader.json +15 -0
- package/src/tokens/components/menu.json +21 -0
- package/src/tokens/components/modal.json +25 -0
- package/src/tokens/components/pagination.json +45 -0
- package/src/tokens/components/phonefield.json +41 -0
- package/src/tokens/components/progress.json +12 -0
- package/src/tokens/components/radio.json +87 -0
- package/src/tokens/components/reportcard.json +17 -0
- package/src/tokens/components/selector.json +87 -0
- package/src/tokens/components/selectscroll.json +65 -0
- package/src/tokens/components/skeleton.json +6 -0
- package/src/tokens/components/stepper.json +38 -0
- package/src/tokens/components/subtabs.json +45 -0
- package/src/tokens/components/switch.json +55 -0
- package/src/tokens/components/tabs.json +38 -0
- package/src/tokens/components/textfield.json +59 -0
- package/src/tokens/components/togglebutton.json +48 -0
- package/src/tokens/components/uploaddropzone.json +61 -0
- package/src/tokens/drawer.ts +37 -0
- package/src/tokens/foundation/breakpoints.json +10 -0
- package/src/tokens/foundation/colors.json +122 -0
- package/src/tokens/foundation/opacity.json +16 -0
- package/src/tokens/foundation/radius.json +14 -0
- package/src/tokens/foundation/size.json +38 -0
- package/src/tokens/foundation/spacing.json +19 -0
- package/src/tokens/foundation/typography.json +43 -0
- package/src/tokens/index.ts +3665 -0
- package/src/tokens/modal.ts +42 -0
- package/src/tokens/semantic/color.json +148 -0
- package/src/tokens/semantic/field.json +28 -0
- package/src/tokens/semantic/opacity.json +5 -0
- package/src/tokens/semantic/size.json +722 -0
- package/src/tokens/semantic/spacing.json +27 -0
- package/src/tokens/semantic/typography.json +87 -0
- package/src/utils/scrollLock.ts +44 -0
- package/dist/index.css +0 -514
- package/dist/index.css.map +0 -1
- package/dist/index.d.ts +0 -289
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
import React, { useCallback, useState } from "react";
|
|
2
|
+
import {
|
|
3
|
+
getSwitchTokensFromResolved,
|
|
4
|
+
getTextFieldTokensFromResolved,
|
|
5
|
+
} from "../../tokens";
|
|
6
|
+
import { useTokens } from "../../ThemeProvider/ThemeContext";
|
|
7
|
+
import type { SwitchProps } from "./Switch.types";
|
|
8
|
+
|
|
9
|
+
function parsePx(value: string): number {
|
|
10
|
+
const num = parseInt(String(value).replace(/px$/i, ""), 10);
|
|
11
|
+
return Number.isFinite(num) ? num : 0;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const Switch = ({
|
|
15
|
+
label,
|
|
16
|
+
caption,
|
|
17
|
+
helperText,
|
|
18
|
+
required,
|
|
19
|
+
checked,
|
|
20
|
+
defaultChecked = false,
|
|
21
|
+
onChange,
|
|
22
|
+
disabled = false,
|
|
23
|
+
size = "md",
|
|
24
|
+
style,
|
|
25
|
+
direction = "row",
|
|
26
|
+
id,
|
|
27
|
+
"aria-label": ariaLabel = "Toggle",
|
|
28
|
+
...rest
|
|
29
|
+
}: SwitchProps) => {
|
|
30
|
+
const [internalChecked, setInternalChecked] = useState(defaultChecked);
|
|
31
|
+
const isControlled = checked !== undefined;
|
|
32
|
+
const isChecked = isControlled ? checked : internalChecked;
|
|
33
|
+
|
|
34
|
+
const resolvedTokens = useTokens();
|
|
35
|
+
const t = getSwitchTokensFromResolved(resolvedTokens);
|
|
36
|
+
const sizeTokens =
|
|
37
|
+
size === "lg"
|
|
38
|
+
? {
|
|
39
|
+
width: t.sizeLgWidth,
|
|
40
|
+
height: t.sizeLgHeight,
|
|
41
|
+
thumbSize: t.sizeLgThumbSize,
|
|
42
|
+
trackPadding: t.sizeLgTrackPadding,
|
|
43
|
+
radius: t.sizeLgRadius,
|
|
44
|
+
borderWidth: t.sizeLgBorderWidth,
|
|
45
|
+
}
|
|
46
|
+
: size === "sm"
|
|
47
|
+
? {
|
|
48
|
+
width: t.sizeSmWidth,
|
|
49
|
+
height: t.sizeSmHeight,
|
|
50
|
+
thumbSize: t.sizeSmThumbSize,
|
|
51
|
+
trackPadding: t.sizeSmTrackPadding,
|
|
52
|
+
radius: t.sizeSmRadius,
|
|
53
|
+
borderWidth: t.sizeSmBorderWidth,
|
|
54
|
+
}
|
|
55
|
+
: {
|
|
56
|
+
width: t.sizeMdWidth,
|
|
57
|
+
height: t.sizeMdHeight,
|
|
58
|
+
thumbSize: t.sizeMdThumbSize,
|
|
59
|
+
trackPadding: t.sizeMdTrackPadding,
|
|
60
|
+
radius: t.sizeMdRadius,
|
|
61
|
+
borderWidth: t.sizeMdBorderWidth,
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const width = parsePx(sizeTokens.width);
|
|
65
|
+
const thumbSize = parsePx(sizeTokens.thumbSize);
|
|
66
|
+
const padding = parsePx(sizeTokens.trackPadding);
|
|
67
|
+
|
|
68
|
+
const translateX = isChecked
|
|
69
|
+
? Math.max(0, width - thumbSize - padding * 2)
|
|
70
|
+
: 0;
|
|
71
|
+
|
|
72
|
+
const trackStyle: React.CSSProperties = {
|
|
73
|
+
position: "relative",
|
|
74
|
+
width: sizeTokens.width,
|
|
75
|
+
height: sizeTokens.height,
|
|
76
|
+
borderRadius: sizeTokens.radius,
|
|
77
|
+
border: `${sizeTokens.borderWidth} solid ${
|
|
78
|
+
isChecked ? t.trackBorderActive : t.trackBorder
|
|
79
|
+
}`,
|
|
80
|
+
backgroundColor: isChecked ? t.trackBackgroundActive : t.trackBackground,
|
|
81
|
+
boxSizing: "border-box",
|
|
82
|
+
transition: "background-color 0.2s ease, border-color 0.2s ease",
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const thumbStyle: React.CSSProperties = {
|
|
86
|
+
position: "absolute",
|
|
87
|
+
top: "50%",
|
|
88
|
+
left: padding,
|
|
89
|
+
width: sizeTokens.thumbSize,
|
|
90
|
+
height: sizeTokens.thumbSize,
|
|
91
|
+
borderRadius: sizeTokens.radius,
|
|
92
|
+
backgroundColor: isChecked ? t.thumbBackgroundActive : t.thumbBackground,
|
|
93
|
+
transform: `translate(${translateX}px, -50%)`,
|
|
94
|
+
transition: "transform 0.2s ease, background-color 0.2s ease",
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const handleToggle = useCallback(() => {
|
|
98
|
+
if (disabled) return;
|
|
99
|
+
const next = !isChecked;
|
|
100
|
+
if (!isControlled) setInternalChecked(next);
|
|
101
|
+
onChange?.(next);
|
|
102
|
+
}, [disabled, isChecked, isControlled, onChange]);
|
|
103
|
+
|
|
104
|
+
const tfTokens = getTextFieldTokensFromResolved(resolvedTokens);
|
|
105
|
+
|
|
106
|
+
const labelStyle: React.CSSProperties = {
|
|
107
|
+
display: "block",
|
|
108
|
+
marginBottom: parseInt(String(t.labelMarginBottom), 10),
|
|
109
|
+
fontSize: t.labelFontSize,
|
|
110
|
+
fontWeight: t.labelFontWeight,
|
|
111
|
+
color: t.labelColor,
|
|
112
|
+
fontFamily: t.labelFontFamily,
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const captionStyle: React.CSSProperties = {
|
|
116
|
+
marginTop: 2,
|
|
117
|
+
fontSize: t.captionFontSize,
|
|
118
|
+
color: t.captionTextColor ?? t.labelColor,
|
|
119
|
+
fontFamily: t.labelFontFamily,
|
|
120
|
+
fontWeight: 400,
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const helperTextStyle: React.CSSProperties = {
|
|
124
|
+
marginTop: 4,
|
|
125
|
+
fontSize: t.switchHelperTextFontSize,
|
|
126
|
+
color: t.switchHelperTextColor,
|
|
127
|
+
fontFamily: tfTokens.fontFamily,
|
|
128
|
+
width: "max-content",
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const switchComponent = (
|
|
132
|
+
<button
|
|
133
|
+
type="button"
|
|
134
|
+
id={id}
|
|
135
|
+
role="switch"
|
|
136
|
+
aria-checked={!!isChecked}
|
|
137
|
+
aria-label={label && typeof label === "string" ? label : ariaLabel}
|
|
138
|
+
disabled={disabled}
|
|
139
|
+
onClick={handleToggle}
|
|
140
|
+
style={{
|
|
141
|
+
padding: 0,
|
|
142
|
+
border: "none",
|
|
143
|
+
background: "transparent",
|
|
144
|
+
cursor: disabled ? "not-allowed" : "pointer",
|
|
145
|
+
outline: "none",
|
|
146
|
+
display: "inline-flex",
|
|
147
|
+
alignItems: "center",
|
|
148
|
+
justifyContent: "center",
|
|
149
|
+
opacity: disabled ? 0.6 : 1,
|
|
150
|
+
...style,
|
|
151
|
+
}}
|
|
152
|
+
{...rest}
|
|
153
|
+
>
|
|
154
|
+
<span style={trackStyle}>
|
|
155
|
+
<span style={thumbStyle} />
|
|
156
|
+
</span>
|
|
157
|
+
</button>
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
if (label || helperText) {
|
|
161
|
+
const isColumn = direction === "column" || direction === "column-reverse";
|
|
162
|
+
return (
|
|
163
|
+
<div
|
|
164
|
+
style={{
|
|
165
|
+
width: label ? "100%" : "fit-content",
|
|
166
|
+
display: "flex",
|
|
167
|
+
flexDirection: direction,
|
|
168
|
+
alignItems: isColumn ? "flex-start" : "center",
|
|
169
|
+
gap: 16,
|
|
170
|
+
}}
|
|
171
|
+
>
|
|
172
|
+
<div
|
|
173
|
+
style={{
|
|
174
|
+
display: "flex",
|
|
175
|
+
flexDirection: direction,
|
|
176
|
+
alignItems: isColumn ? "flex-start" : "center",
|
|
177
|
+
gap: 24,
|
|
178
|
+
justifyContent:
|
|
179
|
+
direction === "row"
|
|
180
|
+
? "space-between"
|
|
181
|
+
: direction === "row-reverse"
|
|
182
|
+
? "flex-end"
|
|
183
|
+
: label
|
|
184
|
+
? "space-between"
|
|
185
|
+
: "flex-start",
|
|
186
|
+
width: label ? "100%" : "fit-content",
|
|
187
|
+
}}
|
|
188
|
+
>
|
|
189
|
+
{label && (
|
|
190
|
+
<div className="d-flex flex-column">
|
|
191
|
+
<label htmlFor={id} style={labelStyle} className="m-0">
|
|
192
|
+
{required && (
|
|
193
|
+
<span
|
|
194
|
+
style={{
|
|
195
|
+
color: "#c00",
|
|
196
|
+
marginRight: 4,
|
|
197
|
+
}}
|
|
198
|
+
>
|
|
199
|
+
*
|
|
200
|
+
</span>
|
|
201
|
+
)}
|
|
202
|
+
<span>{label}</span>
|
|
203
|
+
{caption && <div style={captionStyle}>{caption}</div>}
|
|
204
|
+
</label>
|
|
205
|
+
<span style={{ width: "max-content" }}>
|
|
206
|
+
{helperText && <div style={helperTextStyle}>{helperText}</div>}
|
|
207
|
+
</span>
|
|
208
|
+
</div>
|
|
209
|
+
)}
|
|
210
|
+
{switchComponent}
|
|
211
|
+
</div>
|
|
212
|
+
</div>
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return switchComponent;
|
|
217
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type SwitchSize = "sm" | "md" | "lg";
|
|
2
|
+
|
|
3
|
+
export interface SwitchProps extends Omit<
|
|
4
|
+
React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
5
|
+
"onChange"
|
|
6
|
+
> {
|
|
7
|
+
label?: React.ReactNode;
|
|
8
|
+
caption?: React.ReactNode;
|
|
9
|
+
helperText?: React.ReactNode;
|
|
10
|
+
required?: boolean;
|
|
11
|
+
checked?: boolean;
|
|
12
|
+
defaultChecked?: boolean;
|
|
13
|
+
onChange?: (checked: boolean) => void;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
size?: SwitchSize;
|
|
16
|
+
/**
|
|
17
|
+
* Layout direction for label + switch container.
|
|
18
|
+
* Controls flex-direction of the main content wrapper.
|
|
19
|
+
* Defaults to "row".
|
|
20
|
+
*/
|
|
21
|
+
direction?: "row" | "row-reverse" | "column" | "column-reverse";
|
|
22
|
+
}
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react";
|
|
2
|
+
import { useState } from "react";
|
|
3
|
+
import { Tabs } from "./Tabs";
|
|
4
|
+
import type { TabsProps, TabsOption } from "./Tabs.types";
|
|
5
|
+
|
|
6
|
+
const defaultOptions: TabsOption[] = [
|
|
7
|
+
{ value: "pending", label: "Pending", count: 0 },
|
|
8
|
+
{ value: "approved", label: "Approved", count: 2 },
|
|
9
|
+
{ value: "rejected", label: "Rejected", count: 0 },
|
|
10
|
+
{ value: "expired", label: "Expired", count: 0 },
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
const meta: Meta<typeof Tabs> = {
|
|
14
|
+
title: "Design System/Tabs",
|
|
15
|
+
component: Tabs,
|
|
16
|
+
tags: [],
|
|
17
|
+
decorators: [
|
|
18
|
+
(Story) => (
|
|
19
|
+
<div
|
|
20
|
+
style={{
|
|
21
|
+
padding: "24px",
|
|
22
|
+
maxWidth: "420px",
|
|
23
|
+
background: "#F3F5F6",
|
|
24
|
+
minHeight: "120px",
|
|
25
|
+
}}
|
|
26
|
+
>
|
|
27
|
+
<Story />
|
|
28
|
+
</div>
|
|
29
|
+
),
|
|
30
|
+
],
|
|
31
|
+
args: {
|
|
32
|
+
options: defaultOptions,
|
|
33
|
+
value: "pending",
|
|
34
|
+
disabled: false,
|
|
35
|
+
loading: false,
|
|
36
|
+
color: "grey",
|
|
37
|
+
} as TabsProps,
|
|
38
|
+
argTypes: {
|
|
39
|
+
color: {
|
|
40
|
+
control: { type: "radio" },
|
|
41
|
+
options: ["grey", "white"],
|
|
42
|
+
},
|
|
43
|
+
value: {
|
|
44
|
+
control: { type: "radio" },
|
|
45
|
+
options: ["pending", "approved", "rejected", "expired"],
|
|
46
|
+
},
|
|
47
|
+
disabled: {
|
|
48
|
+
control: { type: "boolean" },
|
|
49
|
+
},
|
|
50
|
+
loading: {
|
|
51
|
+
control: { type: "boolean" },
|
|
52
|
+
},
|
|
53
|
+
onChange: { action: "changed" },
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default meta;
|
|
58
|
+
|
|
59
|
+
type Story = StoryObj<typeof Tabs>;
|
|
60
|
+
|
|
61
|
+
export const Playground: Story = {
|
|
62
|
+
args: {
|
|
63
|
+
options: defaultOptions,
|
|
64
|
+
value: "pending",
|
|
65
|
+
},
|
|
66
|
+
render: function PlaygroundRender(args) {
|
|
67
|
+
const [value, setValue] = useState(args.value);
|
|
68
|
+
return (
|
|
69
|
+
<Tabs
|
|
70
|
+
{...args}
|
|
71
|
+
value={value}
|
|
72
|
+
onChange={(v) => {
|
|
73
|
+
setValue(v);
|
|
74
|
+
args.onChange?.(v);
|
|
75
|
+
}}
|
|
76
|
+
/>
|
|
77
|
+
);
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const optionsWithOneDisabled: TabsOption[] = [
|
|
82
|
+
{ value: "pending", label: "Pending", count: 0 },
|
|
83
|
+
{ value: "approved", label: "Approved", count: 2, disabled: true },
|
|
84
|
+
{ value: "rejected", label: "Rejected", count: 0 },
|
|
85
|
+
{ value: "expired", label: "Expired", count: 0 },
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
export const Showcase: Story = {
|
|
89
|
+
render: () => (
|
|
90
|
+
<div style={{ display: "flex", flexDirection: "column", gap: "24px" }}>
|
|
91
|
+
{/* With counts – first tab selected */}
|
|
92
|
+
<Tabs
|
|
93
|
+
options={[
|
|
94
|
+
{ value: "pending", label: "Pending", count: 0 },
|
|
95
|
+
{ value: "approved", label: "Approved", count: 2 },
|
|
96
|
+
{ value: "rejected", label: "Rejected", count: 0 },
|
|
97
|
+
{ value: "expired", label: "Expired", count: 0 },
|
|
98
|
+
]}
|
|
99
|
+
value="pending"
|
|
100
|
+
onChange={() => {}}
|
|
101
|
+
/>
|
|
102
|
+
|
|
103
|
+
{/* With counts – second tab selected */}
|
|
104
|
+
<Tabs
|
|
105
|
+
options={[
|
|
106
|
+
{ value: "pending", label: "Pending", count: 0 },
|
|
107
|
+
{ value: "approved", label: "Approved", count: 2 },
|
|
108
|
+
{ value: "rejected", label: "Rejected", count: 0 },
|
|
109
|
+
{ value: "expired", label: "Expired", count: 0 },
|
|
110
|
+
]}
|
|
111
|
+
value="approved"
|
|
112
|
+
onChange={() => {}}
|
|
113
|
+
/>
|
|
114
|
+
|
|
115
|
+
{/* Add Contact / View Contact – Add selected */}
|
|
116
|
+
<Tabs
|
|
117
|
+
options={[
|
|
118
|
+
{ value: "add", label: "Add Contact" },
|
|
119
|
+
{ value: "view", label: "View Contact" },
|
|
120
|
+
]}
|
|
121
|
+
value="add"
|
|
122
|
+
onChange={() => {}}
|
|
123
|
+
/>
|
|
124
|
+
|
|
125
|
+
{/* Add Contact / View Contact – View selected */}
|
|
126
|
+
<Tabs
|
|
127
|
+
options={[
|
|
128
|
+
{ value: "add", label: "Add Contact" },
|
|
129
|
+
{ value: "view", label: "View Contact" },
|
|
130
|
+
]}
|
|
131
|
+
value="view"
|
|
132
|
+
onChange={() => {}}
|
|
133
|
+
/>
|
|
134
|
+
|
|
135
|
+
{/* Without counts – three tabs */}
|
|
136
|
+
<Tabs
|
|
137
|
+
options={[
|
|
138
|
+
{ value: "all", label: "All" },
|
|
139
|
+
{ value: "active", label: "Active" },
|
|
140
|
+
{ value: "archived", label: "Archived" },
|
|
141
|
+
]}
|
|
142
|
+
value="active"
|
|
143
|
+
onChange={() => {}}
|
|
144
|
+
/>
|
|
145
|
+
|
|
146
|
+
{/* One tab disabled */}
|
|
147
|
+
<Tabs
|
|
148
|
+
options={optionsWithOneDisabled}
|
|
149
|
+
value="pending"
|
|
150
|
+
onChange={() => {}}
|
|
151
|
+
/>
|
|
152
|
+
|
|
153
|
+
{/* All disabled */}
|
|
154
|
+
<Tabs
|
|
155
|
+
options={defaultOptions}
|
|
156
|
+
value="pending"
|
|
157
|
+
disabled
|
|
158
|
+
onChange={() => {}}
|
|
159
|
+
/>
|
|
160
|
+
|
|
161
|
+
{/* Loading */}
|
|
162
|
+
<Tabs
|
|
163
|
+
options={defaultOptions}
|
|
164
|
+
value="approved"
|
|
165
|
+
loading
|
|
166
|
+
onChange={() => {}}
|
|
167
|
+
/>
|
|
168
|
+
|
|
169
|
+
{/* Color: white */}
|
|
170
|
+
<Tabs
|
|
171
|
+
options={defaultOptions}
|
|
172
|
+
value="pending"
|
|
173
|
+
onChange={() => {}}
|
|
174
|
+
color="white"
|
|
175
|
+
/>
|
|
176
|
+
</div>
|
|
177
|
+
),
|
|
178
|
+
};
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { getTabsTokensFromResolved } from '../../tokens';
|
|
2
|
+
import { useTokens } from '../../ThemeProvider/ThemeContext';
|
|
3
|
+
import type { TabsProps } from './Tabs.types';
|
|
4
|
+
|
|
5
|
+
function toColor(value: string | undefined, fallback: string): string {
|
|
6
|
+
if (!value || typeof value !== 'string') return fallback;
|
|
7
|
+
const s = value.trim();
|
|
8
|
+
if (s.includes('{')) return fallback;
|
|
9
|
+
if (s.startsWith('#') || s.startsWith('rgb') || s.startsWith('hsl')) return s;
|
|
10
|
+
if (/^[0-9A-Fa-f]{6}$/.test(s)) return `#${s}`;
|
|
11
|
+
return fallback;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const skeletonKeyframes = `
|
|
15
|
+
@keyframes tabs-skeleton-shimmer {
|
|
16
|
+
0% { opacity: 0.4; }
|
|
17
|
+
50% { opacity: 0.8; }
|
|
18
|
+
100% { opacity: 0.4; }
|
|
19
|
+
}
|
|
20
|
+
`;
|
|
21
|
+
|
|
22
|
+
function TabsSkeleton({
|
|
23
|
+
optionCount,
|
|
24
|
+
containerBg,
|
|
25
|
+
gap,
|
|
26
|
+
paddingY,
|
|
27
|
+
containerBorderRadius,
|
|
28
|
+
paddingX,
|
|
29
|
+
borderRadius,
|
|
30
|
+
height,
|
|
31
|
+
}: {
|
|
32
|
+
optionCount: number;
|
|
33
|
+
containerBg: string;
|
|
34
|
+
gap: string;
|
|
35
|
+
paddingY: string;
|
|
36
|
+
containerBorderRadius: string;
|
|
37
|
+
paddingX: string;
|
|
38
|
+
borderRadius: string;
|
|
39
|
+
height: string;
|
|
40
|
+
}) {
|
|
41
|
+
return (
|
|
42
|
+
<>
|
|
43
|
+
<style>{skeletonKeyframes}</style>
|
|
44
|
+
<div
|
|
45
|
+
role="status"
|
|
46
|
+
aria-label="Loading tabs"
|
|
47
|
+
style={{
|
|
48
|
+
display: 'inline-flex',
|
|
49
|
+
alignItems: 'center',
|
|
50
|
+
gap,
|
|
51
|
+
padding: paddingY,
|
|
52
|
+
borderRadius: containerBorderRadius,
|
|
53
|
+
backgroundColor: containerBg,
|
|
54
|
+
}}
|
|
55
|
+
>
|
|
56
|
+
{Array.from({ length: optionCount }, (_, i) => (
|
|
57
|
+
<div
|
|
58
|
+
key={i}
|
|
59
|
+
style={{
|
|
60
|
+
height,
|
|
61
|
+
minWidth: '64px',
|
|
62
|
+
paddingLeft: paddingX,
|
|
63
|
+
paddingRight: paddingX,
|
|
64
|
+
borderRadius,
|
|
65
|
+
backgroundColor: '#E5E7EB',
|
|
66
|
+
animation: 'tabs-skeleton-shimmer 1.5s ease-in-out infinite',
|
|
67
|
+
}}
|
|
68
|
+
/>
|
|
69
|
+
))}
|
|
70
|
+
</div>
|
|
71
|
+
</>
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export const Tabs = ({
|
|
76
|
+
options,
|
|
77
|
+
value,
|
|
78
|
+
onChange,
|
|
79
|
+
disabled = false,
|
|
80
|
+
getOptionDisabled,
|
|
81
|
+
loading = false,
|
|
82
|
+
size = 'md',
|
|
83
|
+
color = 'grey',
|
|
84
|
+
style,
|
|
85
|
+
...rest
|
|
86
|
+
}: TabsProps) => {
|
|
87
|
+
const resolvedTokens = useTokens();
|
|
88
|
+
const { tokens: t, sizes } = getTabsTokensFromResolved(resolvedTokens);
|
|
89
|
+
const sizeTokens = sizes[size];
|
|
90
|
+
const activeBg = toColor(t?.activeBackground, '#00545e');
|
|
91
|
+
const activeTextColor = activeBg;
|
|
92
|
+
const inactiveTextColor = toColor(t?.inactiveColor, '#56636a');
|
|
93
|
+
const containerBg = toColor(
|
|
94
|
+
color === 'white' ? t?.containerBackgroundWhite : t?.containerBackground,
|
|
95
|
+
'#F3F5F6'
|
|
96
|
+
);
|
|
97
|
+
const inactiveBg = toColor(
|
|
98
|
+
color === 'white' ? t?.inactiveBackgroundWhite : t?.inactiveBackground,
|
|
99
|
+
'#EEF1F2'
|
|
100
|
+
);
|
|
101
|
+
const fontWeight = sizeTokens.fontWeight;
|
|
102
|
+
|
|
103
|
+
if (loading) {
|
|
104
|
+
return (
|
|
105
|
+
<div style={style} {...rest}>
|
|
106
|
+
<TabsSkeleton
|
|
107
|
+
optionCount={options.length}
|
|
108
|
+
containerBg={containerBg}
|
|
109
|
+
gap={t.gap}
|
|
110
|
+
paddingY={t.paddingY}
|
|
111
|
+
containerBorderRadius={t.containerBorderRadius}
|
|
112
|
+
paddingX={t.paddingX}
|
|
113
|
+
borderRadius={sizeTokens.borderRadius}
|
|
114
|
+
height={sizeTokens.height}
|
|
115
|
+
/>
|
|
116
|
+
</div>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return (
|
|
121
|
+
<div
|
|
122
|
+
style={{
|
|
123
|
+
overflowX: 'auto',
|
|
124
|
+
overflowY: 'hidden',
|
|
125
|
+
paddingBottom: 3,
|
|
126
|
+
marginBottom: -4,
|
|
127
|
+
width: '100%',
|
|
128
|
+
...style,
|
|
129
|
+
}}
|
|
130
|
+
{...rest}
|
|
131
|
+
>
|
|
132
|
+
<div
|
|
133
|
+
role="tablist"
|
|
134
|
+
aria-orientation="horizontal"
|
|
135
|
+
aria-disabled={disabled}
|
|
136
|
+
style={{
|
|
137
|
+
display: 'flex',
|
|
138
|
+
alignItems: 'flex-end',
|
|
139
|
+
gap: t.gap,
|
|
140
|
+
padding: `0px ${t.paddingX}`,
|
|
141
|
+
width: 'max-content',
|
|
142
|
+
minWidth: '100%',
|
|
143
|
+
boxSizing: 'border-box',
|
|
144
|
+
position: 'relative',
|
|
145
|
+
}}
|
|
146
|
+
>
|
|
147
|
+
{options.map((option) => {
|
|
148
|
+
const isSelected = option.value === value;
|
|
149
|
+
const isOptionDisabled = option.disabled === true || getOptionDisabled?.(option) === true;
|
|
150
|
+
const isButtonDisabled = disabled || isOptionDisabled;
|
|
151
|
+
const labelWithCount =
|
|
152
|
+
option.count !== undefined ? `${option.label} (${option.count})` : option.label;
|
|
153
|
+
|
|
154
|
+
return (
|
|
155
|
+
<button
|
|
156
|
+
key={option.value}
|
|
157
|
+
type="button"
|
|
158
|
+
role="tab"
|
|
159
|
+
aria-selected={isSelected}
|
|
160
|
+
aria-label={labelWithCount}
|
|
161
|
+
aria-disabled={isOptionDisabled}
|
|
162
|
+
disabled={isButtonDisabled}
|
|
163
|
+
onClick={() => {
|
|
164
|
+
if (!isButtonDisabled) onChange?.(option.value);
|
|
165
|
+
}}
|
|
166
|
+
style={{
|
|
167
|
+
backgroundColor: isSelected ? '#FFFFFF' : inactiveBg || containerBg,
|
|
168
|
+
color: isSelected ? activeTextColor : inactiveTextColor,
|
|
169
|
+
border: `1px solid ${isSelected ? activeBg : '#D4DDE1'}`,
|
|
170
|
+
borderBottomColor: isSelected ? '#FFFFFF' : '#D4DDE1',
|
|
171
|
+
position: 'relative',
|
|
172
|
+
zIndex: isSelected ? 2 : 0,
|
|
173
|
+
height: sizeTokens.height,
|
|
174
|
+
minHeight: sizeTokens.height,
|
|
175
|
+
maxHeight: sizeTokens.height,
|
|
176
|
+
padding: sizeTokens.padding,
|
|
177
|
+
fontSize: `${sizeTokens.fontSize}px`,
|
|
178
|
+
borderTopLeftRadius: sizeTokens.borderRadius,
|
|
179
|
+
borderTopRightRadius: sizeTokens.borderRadius,
|
|
180
|
+
borderBottomLeftRadius: '0px',
|
|
181
|
+
borderBottomRightRadius: '0px',
|
|
182
|
+
fontWeight: isSelected ? fontWeight : '400',
|
|
183
|
+
whiteSpace: 'nowrap',
|
|
184
|
+
cursor: isButtonDisabled ? 'not-allowed' : 'pointer',
|
|
185
|
+
marginBottom: 0,
|
|
186
|
+
boxShadow: isSelected ? '0 3px 0 0 #FFFFFF' : 'none',
|
|
187
|
+
opacity: isOptionDisabled ? 0.5 : 1,
|
|
188
|
+
}}
|
|
189
|
+
>
|
|
190
|
+
{labelWithCount}
|
|
191
|
+
</button>
|
|
192
|
+
);
|
|
193
|
+
})}
|
|
194
|
+
</div>
|
|
195
|
+
</div>
|
|
196
|
+
);
|
|
197
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export interface TabsOption {
|
|
2
|
+
/** Value when this tab is selected */
|
|
3
|
+
value: string;
|
|
4
|
+
/** Label shown for the tab */
|
|
5
|
+
label: string;
|
|
6
|
+
/** Display / sort order from config (e.g. 1, 2, 3) */
|
|
7
|
+
sequence?: number;
|
|
8
|
+
/** Optional count shown in parentheses, e.g. "Pending (0)" */
|
|
9
|
+
count?: number;
|
|
10
|
+
/** Disable this tab only */
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export interface TabsProps extends Omit<
|
|
15
|
+
React.HTMLAttributes<HTMLDivElement>,
|
|
16
|
+
'onChange' | 'children'
|
|
17
|
+
> {
|
|
18
|
+
/** List of tab options; one can be selected */
|
|
19
|
+
options: TabsOption[];
|
|
20
|
+
/** Currently selected value (must match one option's value) */
|
|
21
|
+
value: string;
|
|
22
|
+
/** Called when user selects a different tab */
|
|
23
|
+
onChange?: (value: string) => void;
|
|
24
|
+
/** Disable all tabs */
|
|
25
|
+
disabled?: boolean;
|
|
26
|
+
/** Callback to disable a particular option; receives the option and returns true to disable */
|
|
27
|
+
getOptionDisabled?: (option: TabsOption) => boolean;
|
|
28
|
+
/** Loading state – shows skeleton placeholder (tabs are not disabled) */
|
|
29
|
+
loading?: boolean;
|
|
30
|
+
/** Size of the tabs */
|
|
31
|
+
size?: 'sm' | 'md' | 'lg';
|
|
32
|
+
/** Background color variant for inactive tabs and container */
|
|
33
|
+
color?: 'grey' | 'white';
|
|
34
|
+
}
|