uikit-react-public 0.29.5 → 0.30.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Accordion/Accordion.stories.d.ts +1 -1
- package/dist/components/Alert/Alert.stories.d.ts +1 -1
- package/dist/components/AppHeader/AppHeader.stories.d.ts +1 -1
- package/dist/components/AppMenu/AppMenu.stories.d.ts +1 -1
- package/dist/components/Avatar/Avatar.stories.d.ts +1 -1
- package/dist/components/Badge/Badge.stories.d.ts +1 -1
- package/dist/components/BaseCheckbox/BaseCheckbox.stories.d.ts +1 -1
- package/dist/components/Blanket/Blanket.stories.d.ts +1 -1
- package/dist/components/Breadcrumbs/Breadcrumbs.stories.d.ts +1 -1
- package/dist/components/Button/Button.stories.d.ts +1 -1
- package/dist/components/Calendar/Calendar.stories.d.ts +1 -1
- package/dist/components/Calendar/subcomponents/Day.stories.d.ts +1 -1
- package/dist/components/Checkbox/Checkbox.stories.d.ts +1 -1
- package/dist/components/Chip/Chip.stories.d.ts +1 -1
- package/dist/components/Datepicker/Datepicker.stories.d.ts +1 -1
- package/dist/components/Dialog/Dialog.stories.d.ts +1 -1
- package/dist/components/Divider/Divider.stories.d.ts +1 -1
- package/dist/components/Dropdown/Dropdown.stories.d.ts +1 -1
- package/dist/components/FeedbackDialog/FeedbackDialog.stories.d.ts +1 -1
- package/dist/components/Field/Field.stories.d.ts +1 -1
- package/dist/components/FileInput/FileInput.stories.d.ts +1 -1
- package/dist/components/Footer/Footer.stories.d.ts +1 -1
- package/dist/components/Header/Header.stories.d.ts +1 -1
- package/dist/components/Heading/Heading.stories.d.ts +1 -1
- package/dist/components/Icon/Icon.stories.d.ts +1 -1
- package/dist/components/IconButton/IconButton.stories.d.ts +1 -1
- package/dist/components/Input/Input.stories.d.ts +1 -1
- package/dist/components/Label/Label.stories.d.ts +1 -1
- package/dist/components/Layout/Layout.stories.d.ts +1 -1
- package/dist/components/Link/Link.stories.d.ts +1 -1
- package/dist/components/Main/Main.stories.d.ts +1 -1
- package/dist/components/Modal/Modal.stories.d.ts +1 -1
- package/dist/components/NativeDatepicker/NativeDatepicker.stories.d.ts +1 -1
- package/dist/components/Overlay/Overlay.d.ts +14 -3
- package/dist/components/Overlay/Overlay.stories.d.ts +33 -4
- package/dist/components/Overlay/__tests__/Overlay.test.d.ts +1 -0
- package/dist/components/Overlay/index.d.ts +1 -1
- package/dist/components/Pagination/Pagination.stories.d.ts +1 -1
- package/dist/components/Paragraph/Paragraph.stories.d.ts +1 -1
- package/dist/components/Radio/Radio.stories.d.ts +1 -1
- package/dist/components/Search/Search.stories.d.ts +1 -1
- package/dist/components/Select/Select.stories.d.ts +13 -1
- package/dist/components/Select/Select.types.d.ts +7 -0
- package/dist/components/Select/subcomponents/CustomSelect.d.ts +1 -1
- package/dist/components/Select/subcomponents/Panel.d.ts +8 -2
- package/dist/components/Snackbar/Snackbar.stories.d.ts +1 -1
- package/dist/components/Spinner/Spinner.stories.d.ts +1 -1
- package/dist/components/StandaloneLink/StandaloneLink.stories.d.ts +1 -1
- package/dist/components/Table/Table.stories.d.ts +1 -1
- package/dist/components/Table/subcomponents/Cell/Cell.stories.d.ts +2 -2
- package/dist/components/Table/subcomponents/HeadCell/HeadCell.stories.d.ts +2 -2
- package/dist/components/Tabs/Tab.d.ts +11 -5
- package/dist/components/Tabs/TabContext.d.ts +14 -8
- package/dist/components/Tabs/Tabs.d.ts +25 -8
- package/dist/components/Tabs/Tabs.stories.d.ts +5 -9
- package/dist/components/Tabs/TabsList.d.ts +9 -0
- package/dist/components/Tabs/TabsPanel.d.ts +10 -0
- package/dist/components/Tabs/index.d.ts +2 -1
- package/dist/components/Textarea/Textarea.stories.d.ts +1 -1
- package/dist/components/Timepicker/Timepicker.stories.d.ts +1 -1
- package/dist/components/Toggle/Toggle.stories.d.ts +1 -1
- package/dist/components/Tooltip/Tooltip.stories.d.ts +1 -1
- package/dist/components/UclLogo/UclLogo.stories.d.ts +1 -1
- package/dist/components/WeekPicker/WeekPicker.stories.d.ts +1 -1
- package/dist/components/index.d.ts +1 -1
- package/dist/index.js +5094 -4723
- package/lib/Welcome.mdx +1 -1
- package/lib/components/Accordion/Accordion.stories.tsx +1 -1
- package/lib/components/Alert/Alert.mdx +1 -1
- package/lib/components/Alert/Alert.stories.tsx +1 -1
- package/lib/components/AppHeader/AppHeader.stories.tsx +1 -1
- package/lib/components/AppMenu/AppMenu.stories.tsx +1 -1
- package/lib/components/Avatar/Avatar.mdx +1 -1
- package/lib/components/Avatar/Avatar.stories.tsx +1 -1
- package/lib/components/Badge/Badge.stories.tsx +1 -1
- package/lib/components/BaseCheckbox/BaseCheckbox.stories.tsx +2 -2
- package/lib/components/Blanket/Blanket.stories.tsx +1 -1
- package/lib/components/Breadcrumbs/Breadcrumbs.stories.tsx +1 -1
- package/lib/components/Button/Button.mdx +1 -1
- package/lib/components/Button/Button.stories.tsx +2 -2
- package/lib/components/Calendar/Calendar.stories.tsx +2 -2
- package/lib/components/Calendar/subcomponents/Day.stories.tsx +1 -1
- package/lib/components/Checkbox/Checkbox.stories.tsx +2 -2
- package/lib/components/Chip/Chip.stories.tsx +2 -2
- package/lib/components/Datepicker/Datepicker.stories.tsx +2 -2
- package/lib/components/Dialog/Dialog.stories.tsx +1 -1
- package/lib/components/Divider/Divider.stories.tsx +1 -1
- package/lib/components/Dropdown/Dropdown.stories.tsx +1 -1
- package/lib/components/FeedbackDialog/FeedbackDialog.stories.tsx +1 -1
- package/lib/components/Field/Field.stories.tsx +2 -2
- package/lib/components/FileInput/FileInput.stories.tsx +1 -1
- package/lib/components/Footer/Footer.stories.tsx +1 -1
- package/lib/components/Header/Header.mdx +1 -1
- package/lib/components/Header/Header.stories.tsx +1 -1
- package/lib/components/Heading/Documentation.mdx +1 -1
- package/lib/components/Heading/Heading.stories.tsx +1 -1
- package/lib/components/Icon/Icon.stories.tsx +1 -1
- package/lib/components/IconButton/IconButton.stories.tsx +1 -1
- package/lib/components/Input/Documentation.mdx +1 -1
- package/lib/components/Input/Input.stories.tsx +1 -1
- package/lib/components/Label/Label.stories.tsx +1 -1
- package/lib/components/Layout/Layout.stories.tsx +1 -1
- package/lib/components/Link/Link.stories.tsx +1 -1
- package/lib/components/Main/Main.stories.tsx +1 -1
- package/lib/components/Modal/Modal.stories.tsx +1 -1
- package/lib/components/NativeDatepicker/NativeDatepicker.stories.tsx +2 -2
- package/lib/components/Overlay/Overlay.stories.tsx +1 -1
- package/lib/components/Overlay/Overlay.tsx +64 -21
- package/lib/components/Overlay/__tests__/Overlay.test.tsx +81 -0
- package/lib/components/Overlay/index.ts +1 -1
- package/lib/components/Pagination/Pagination.stories.tsx +1 -1
- package/lib/components/Paragraph/Paragraph.stories.tsx +1 -1
- package/lib/components/Radio/Radio.stories.tsx +2 -2
- package/lib/components/Search/Search.stories.tsx +1 -1
- package/lib/components/Select/Select.mdx +1 -1
- package/lib/components/Select/Select.stories.tsx +9 -2
- package/lib/components/Select/Select.tsx +7 -0
- package/lib/components/Select/Select.types.ts +9 -2
- package/lib/components/Select/__tests__/Select.test.tsx +181 -1
- package/lib/components/Select/subcomponents/CustomSelect.tsx +109 -27
- package/lib/components/Select/subcomponents/Panel.tsx +40 -10
- package/lib/components/Snackbar/Snackbar.stories.tsx +1 -1
- package/lib/components/Spinner/Spinner.stories.tsx +1 -1
- package/lib/components/StandaloneLink/StandaloneLink.stories.tsx +1 -1
- package/lib/components/Table/Table.stories.tsx +1 -1
- package/lib/components/Table/subcomponents/Cell/Cell.stories.tsx +2 -2
- package/lib/components/Table/subcomponents/HeadCell/HeadCell.stories.tsx +1 -1
- package/lib/components/Tabs/Tab.tsx +209 -36
- package/lib/components/Tabs/TabContext.tsx +20 -7
- package/lib/components/Tabs/Tabs.stories.tsx +87 -68
- package/lib/components/Tabs/Tabs.tsx +129 -37
- package/lib/components/Tabs/TabsList.tsx +134 -0
- package/lib/components/Tabs/TabsPanel.tsx +55 -0
- package/lib/components/Tabs/__tests__/Tabs.test.tsx +173 -105
- package/lib/components/Tabs/index.ts +8 -1
- package/lib/components/Textarea/Textarea.stories.tsx +1 -1
- package/lib/components/Timepicker/Timepicker.stories.tsx +1 -1
- package/lib/components/Toggle/Documentation.mdx +1 -1
- package/lib/components/Toggle/Toggle.stories.tsx +1 -1
- package/lib/components/Tooltip/Tooltip.stories.tsx +1 -1
- package/lib/components/UclLogo/UclLogo.stories.tsx +1 -1
- package/lib/components/WeekPicker/WeekPicker.stories.tsx +2 -2
- package/lib/components/common/Common.mdx +1 -1
- package/lib/components/index.ts +7 -1
- package/lib/theme/Icons.mdx +1 -1
- package/lib/theme/Typography.mdx +1 -1
- package/package.json +8 -11
- package/lib/components/Tabs/__tests__/__snapshots__/Tabs.test.tsx.snap +0 -185
|
@@ -1,81 +1,254 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Children,
|
|
3
|
+
HTMLAttributes,
|
|
4
|
+
ReactElement,
|
|
5
|
+
ReactNode,
|
|
6
|
+
cloneElement,
|
|
7
|
+
isValidElement,
|
|
8
|
+
memo,
|
|
9
|
+
} from 'react';
|
|
2
10
|
import { css, cx } from '@emotion/css';
|
|
3
11
|
import { useTheme } from '../../theme';
|
|
4
|
-
import
|
|
12
|
+
import Text from '../Text';
|
|
13
|
+
import { getTabId, getTabPanelId, useTabContext } from './TabContext';
|
|
5
14
|
|
|
6
15
|
export const NAME = 'ucl-uikit-tabs__tab';
|
|
7
16
|
|
|
8
|
-
|
|
17
|
+
type TabElementProps = HTMLAttributes<HTMLElement> & {
|
|
18
|
+
disabled?: boolean;
|
|
19
|
+
href?: string;
|
|
20
|
+
ref?: React.Ref<HTMLElement>;
|
|
21
|
+
type?: 'button' | 'submit' | 'reset';
|
|
22
|
+
'data-state'?: string;
|
|
23
|
+
'data-testid'?: string;
|
|
24
|
+
'data-ucl-tabs-value'?: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export interface TabProps extends HTMLAttributes<HTMLElement> {
|
|
9
28
|
testId?: string;
|
|
10
|
-
label: string;
|
|
11
29
|
value: string;
|
|
30
|
+
children?: ReactNode;
|
|
31
|
+
count?: number;
|
|
32
|
+
/** @deprecated Use count instead. */
|
|
12
33
|
counter?: number;
|
|
13
|
-
|
|
34
|
+
disabled?: boolean;
|
|
35
|
+
asChild?: boolean;
|
|
36
|
+
ref?: React.Ref<HTMLElement>;
|
|
37
|
+
/** @deprecated Prefer children for the tab content. */
|
|
38
|
+
label?: ReactNode;
|
|
14
39
|
}
|
|
15
40
|
|
|
41
|
+
const mergeEventHandlers =
|
|
42
|
+
<EventType,>(
|
|
43
|
+
userHandler: ((event: EventType) => void) | undefined,
|
|
44
|
+
childHandler: ((event: EventType) => void) | undefined
|
|
45
|
+
) =>
|
|
46
|
+
(event: EventType) => {
|
|
47
|
+
userHandler?.(event);
|
|
48
|
+
childHandler?.(event);
|
|
49
|
+
};
|
|
50
|
+
|
|
16
51
|
const Tab = ({
|
|
17
52
|
testId = NAME,
|
|
18
53
|
className,
|
|
54
|
+
children,
|
|
19
55
|
label,
|
|
20
56
|
value,
|
|
57
|
+
count,
|
|
21
58
|
counter,
|
|
59
|
+
disabled = false,
|
|
60
|
+
asChild = false,
|
|
61
|
+
onClick,
|
|
22
62
|
ref,
|
|
23
63
|
...props
|
|
24
64
|
}: TabProps) => {
|
|
25
65
|
const [theme] = useTheme();
|
|
26
|
-
const {
|
|
27
|
-
|
|
66
|
+
const {
|
|
67
|
+
value: selectedValue,
|
|
68
|
+
setValue,
|
|
69
|
+
baseId,
|
|
70
|
+
fullWidth,
|
|
71
|
+
panelValues,
|
|
72
|
+
} = useTabContext();
|
|
73
|
+
const isSelected = selectedValue === value;
|
|
74
|
+
const labelContent = children ?? label;
|
|
75
|
+
const resolvedCount = count ?? counter;
|
|
28
76
|
|
|
29
77
|
const baseStyle = css`
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
border-bottom: 4px solid transparent;
|
|
36
|
-
text-align: center;
|
|
37
|
-
font-style: normal;
|
|
38
|
-
line-height: 140%;
|
|
39
|
-
font-size: ${theme.font.size.f16};
|
|
78
|
+
all: unset;
|
|
79
|
+
box-sizing: border-box;
|
|
80
|
+
height: 40px;
|
|
81
|
+
display: inline-flex;
|
|
82
|
+
flex-direction: column;
|
|
40
83
|
align-items: center;
|
|
41
84
|
justify-content: center;
|
|
42
|
-
|
|
43
|
-
|
|
85
|
+
gap: 0;
|
|
86
|
+
padding: 0 ${theme.padding.p16};
|
|
87
|
+
border-bottom: 4px solid transparent;
|
|
88
|
+
color: ${theme.colour.text.default};
|
|
89
|
+
background-color: transparent;
|
|
90
|
+
cursor: pointer;
|
|
91
|
+
text-align: center;
|
|
92
|
+
text-decoration: none;
|
|
93
|
+
white-space: nowrap;
|
|
94
|
+
position: relative;
|
|
95
|
+
outline: none;
|
|
96
|
+
|
|
97
|
+
&:visited {
|
|
98
|
+
color: ${theme.colour.text.default};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
&:hover {
|
|
102
|
+
color: ${theme.colour.text.default};
|
|
103
|
+
background-color: ${theme.colour.fill.brandSubtleHover};
|
|
104
|
+
}
|
|
44
105
|
|
|
45
106
|
&:focus-visible {
|
|
46
|
-
outline: none;
|
|
47
107
|
box-shadow: ${theme.boxShadow.focus};
|
|
108
|
+
z-index: 1;
|
|
48
109
|
}
|
|
110
|
+
`;
|
|
111
|
+
|
|
112
|
+
const fullWidthStyle = css`
|
|
113
|
+
flex: 1 1 0;
|
|
114
|
+
`;
|
|
49
115
|
|
|
116
|
+
const autoWidthStyle = css`
|
|
117
|
+
flex: 0 0 auto;
|
|
118
|
+
`;
|
|
119
|
+
|
|
120
|
+
const selectedStyle = css`
|
|
121
|
+
color: ${theme.colour.text.default};
|
|
122
|
+
border-bottom-color: ${theme.colour.border.brand};
|
|
123
|
+
|
|
124
|
+
&:visited,
|
|
50
125
|
&:hover {
|
|
51
|
-
|
|
126
|
+
color: ${theme.colour.text.default};
|
|
52
127
|
}
|
|
53
128
|
`;
|
|
54
129
|
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
margin-bottom: -1px;
|
|
59
|
-
font-weight: 700;
|
|
130
|
+
const disabledStyle = css`
|
|
131
|
+
color: ${theme.colour.text.disabled};
|
|
132
|
+
cursor: not-allowed;
|
|
60
133
|
|
|
134
|
+
&:visited,
|
|
61
135
|
&:hover {
|
|
62
|
-
|
|
136
|
+
color: ${theme.colour.text.disabled};
|
|
137
|
+
background-color: transparent;
|
|
63
138
|
}
|
|
64
139
|
`;
|
|
65
140
|
|
|
66
|
-
const
|
|
141
|
+
const textStyle = css`
|
|
142
|
+
color: inherit;
|
|
143
|
+
`;
|
|
144
|
+
|
|
145
|
+
const hiddenTextStyle = css`
|
|
146
|
+
height: 0;
|
|
147
|
+
overflow: hidden;
|
|
148
|
+
visibility: hidden;
|
|
149
|
+
pointer-events: none;
|
|
150
|
+
`;
|
|
151
|
+
|
|
152
|
+
const style = cx(
|
|
153
|
+
NAME,
|
|
154
|
+
baseStyle,
|
|
155
|
+
fullWidth ? fullWidthStyle : autoWidthStyle,
|
|
156
|
+
isSelected && selectedStyle,
|
|
157
|
+
disabled && disabledStyle,
|
|
158
|
+
className
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
const handleClick = (event: React.MouseEvent<HTMLElement>) => {
|
|
162
|
+
onClick?.(event);
|
|
163
|
+
|
|
164
|
+
if (event.defaultPrevented || disabled) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
setValue(value);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
const commonProps: TabElementProps = {
|
|
172
|
+
...props,
|
|
173
|
+
ref,
|
|
174
|
+
className: style,
|
|
175
|
+
role: 'tab',
|
|
176
|
+
id: getTabId(baseId, value),
|
|
177
|
+
...(panelValues.has(value)
|
|
178
|
+
? { 'aria-controls': getTabPanelId(baseId, value) }
|
|
179
|
+
: {}),
|
|
180
|
+
'aria-selected': isSelected,
|
|
181
|
+
'aria-disabled': disabled || undefined,
|
|
182
|
+
tabIndex: isSelected ? 0 : -1,
|
|
183
|
+
'data-testid': testId,
|
|
184
|
+
'data-state': isSelected ? 'active' : 'inactive',
|
|
185
|
+
'data-ucl-tabs-value': value,
|
|
186
|
+
onClick: handleClick,
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
if (asChild) {
|
|
190
|
+
const child = Children.only(children) as ReactElement<TabElementProps>;
|
|
191
|
+
|
|
192
|
+
if (isValidElement(child)) {
|
|
193
|
+
return cloneElement(child, {
|
|
194
|
+
...commonProps,
|
|
195
|
+
className: cx(style, child.props.className),
|
|
196
|
+
tabIndex: disabled ? -1 : (props.tabIndex ?? commonProps.tabIndex),
|
|
197
|
+
onClick: disabled
|
|
198
|
+
? (event: React.MouseEvent<HTMLElement>) => {
|
|
199
|
+
event.preventDefault();
|
|
200
|
+
event.stopPropagation();
|
|
201
|
+
}
|
|
202
|
+
: mergeEventHandlers(handleClick, child.props.onClick),
|
|
203
|
+
children: (
|
|
204
|
+
<>
|
|
205
|
+
<Text
|
|
206
|
+
level={isSelected ? 'md-semibold' : 'md'}
|
|
207
|
+
className={textStyle}
|
|
208
|
+
>
|
|
209
|
+
{child.props.children}
|
|
210
|
+
{resolvedCount !== undefined ? ` ${resolvedCount}` : ''}
|
|
211
|
+
</Text>
|
|
212
|
+
<Text
|
|
213
|
+
aria-hidden
|
|
214
|
+
level='md-semibold'
|
|
215
|
+
className={cx(textStyle, hiddenTextStyle)}
|
|
216
|
+
>
|
|
217
|
+
{child.props.children}
|
|
218
|
+
{resolvedCount !== undefined ? ` ${resolvedCount}` : ''}
|
|
219
|
+
</Text>
|
|
220
|
+
</>
|
|
221
|
+
),
|
|
222
|
+
});
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const { ref: buttonRef, ...buttonProps } = commonProps;
|
|
67
227
|
|
|
68
228
|
return (
|
|
69
229
|
<button
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
{...props}
|
|
230
|
+
{...buttonProps}
|
|
231
|
+
ref={buttonRef as React.Ref<HTMLButtonElement>}
|
|
232
|
+
disabled={disabled}
|
|
233
|
+
type={
|
|
234
|
+
(props as { type?: 'button' | 'submit' | 'reset' }).type ?? 'button'
|
|
235
|
+
}
|
|
77
236
|
>
|
|
78
|
-
|
|
237
|
+
<Text
|
|
238
|
+
level={isSelected ? 'md-semibold' : 'md'}
|
|
239
|
+
className={textStyle}
|
|
240
|
+
>
|
|
241
|
+
{labelContent}
|
|
242
|
+
{resolvedCount !== undefined ? ` ${resolvedCount}` : ''}
|
|
243
|
+
</Text>
|
|
244
|
+
<Text
|
|
245
|
+
aria-hidden
|
|
246
|
+
level='md-semibold'
|
|
247
|
+
className={cx(textStyle, hiddenTextStyle)}
|
|
248
|
+
>
|
|
249
|
+
{labelContent}
|
|
250
|
+
{resolvedCount !== undefined ? ` ${resolvedCount}` : ''}
|
|
251
|
+
</Text>
|
|
79
252
|
</button>
|
|
80
253
|
);
|
|
81
254
|
};
|
|
@@ -1,20 +1,33 @@
|
|
|
1
1
|
import { createContext, use } from 'react';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
export type TabsActivationMode = 'automatic' | 'manual';
|
|
4
|
+
export type TabsOrientation = 'horizontal' | 'vertical';
|
|
5
|
+
|
|
6
|
+
export interface TabsContextType {
|
|
7
|
+
value: string | undefined;
|
|
8
|
+
setValue: (value: string) => void;
|
|
9
|
+
baseId: string;
|
|
10
|
+
activationMode: TabsActivationMode;
|
|
11
|
+
orientation: TabsOrientation;
|
|
12
|
+
fullWidth: boolean;
|
|
13
|
+
panelValues: Set<string>;
|
|
9
14
|
}
|
|
10
15
|
|
|
11
|
-
const TabContext = createContext<
|
|
16
|
+
const TabContext = createContext<TabsContextType | undefined>(undefined);
|
|
17
|
+
|
|
18
|
+
export const getTabId = (baseId: string, value: string) =>
|
|
19
|
+
`${baseId}-tab-${value}`.replace(/[^a-zA-Z0-9_-]/g, '-');
|
|
20
|
+
|
|
21
|
+
export const getTabPanelId = (baseId: string, value: string) =>
|
|
22
|
+
`${baseId}-panel-${value}`.replace(/[^a-zA-Z0-9_-]/g, '-');
|
|
12
23
|
|
|
13
24
|
export const useTabContext = () => {
|
|
14
25
|
const context = use(TabContext);
|
|
26
|
+
|
|
15
27
|
if (!context) {
|
|
16
28
|
throw new Error('Tab components must be used within a Tabs component');
|
|
17
29
|
}
|
|
30
|
+
|
|
18
31
|
return context;
|
|
19
32
|
};
|
|
20
33
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react-vite';
|
|
2
3
|
import Tabs from './Tabs';
|
|
3
4
|
|
|
4
5
|
const meta = {
|
|
@@ -7,89 +8,107 @@ const meta = {
|
|
|
7
8
|
parameters: {
|
|
8
9
|
layout: 'padded',
|
|
9
10
|
},
|
|
10
|
-
args: {
|
|
11
|
-
activeTab: '',
|
|
12
|
-
},
|
|
13
11
|
} satisfies Meta<typeof Tabs>;
|
|
14
12
|
|
|
15
13
|
export default meta;
|
|
16
14
|
type Story = StoryObj<typeof meta>;
|
|
17
15
|
|
|
18
|
-
export const
|
|
19
|
-
|
|
16
|
+
export const Controlled: Story = {
|
|
17
|
+
render: () => {
|
|
18
|
+
const [value, setValue] = useState('overview');
|
|
19
|
+
|
|
20
|
+
return (
|
|
21
|
+
<Tabs
|
|
22
|
+
value={value}
|
|
23
|
+
onValueChange={setValue}
|
|
24
|
+
>
|
|
25
|
+
<Tabs.List fullWidth>
|
|
26
|
+
<Tabs.Tab value='overview'>Overview</Tabs.Tab>
|
|
27
|
+
<Tabs.Tab value='modules'>Modules</Tabs.Tab>
|
|
28
|
+
<Tabs.Tab value='people'>People</Tabs.Tab>
|
|
29
|
+
<Tabs.Tab value='settings'>Settings</Tabs.Tab>
|
|
30
|
+
</Tabs.List>
|
|
31
|
+
<Tabs.Panel value='overview'>Overview content</Tabs.Panel>
|
|
32
|
+
<Tabs.Panel value='modules'>Modules content</Tabs.Panel>
|
|
33
|
+
<Tabs.Panel value='people'>People content</Tabs.Panel>
|
|
34
|
+
<Tabs.Panel value='settings'>Settings content</Tabs.Panel>
|
|
35
|
+
</Tabs>
|
|
36
|
+
);
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const AutoWidth: Story = {
|
|
41
|
+
name: 'Auto width',
|
|
20
42
|
render: () => (
|
|
21
|
-
<Tabs
|
|
22
|
-
<Tabs.
|
|
23
|
-
|
|
24
|
-
value='
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
<Tabs.Tab
|
|
31
|
-
label='Tab Item 3'
|
|
32
|
-
value='3'
|
|
33
|
-
/>
|
|
34
|
-
<Tabs.Tab
|
|
35
|
-
label='Tab Item 4'
|
|
36
|
-
value='4'
|
|
37
|
-
/>
|
|
43
|
+
<Tabs defaultValue='overview'>
|
|
44
|
+
<Tabs.List>
|
|
45
|
+
<Tabs.Tab value='overview'>Overview</Tabs.Tab>
|
|
46
|
+
<Tabs.Tab value='modules'>Modules</Tabs.Tab>
|
|
47
|
+
<Tabs.Tab value='people'>People</Tabs.Tab>
|
|
48
|
+
<Tabs.Tab value='long-label'>
|
|
49
|
+
A longer tab item showing auto width
|
|
50
|
+
</Tabs.Tab>
|
|
51
|
+
</Tabs.List>
|
|
38
52
|
</Tabs>
|
|
39
53
|
),
|
|
40
54
|
};
|
|
41
55
|
|
|
42
|
-
export const
|
|
43
|
-
name: 'Auto width',
|
|
56
|
+
export const Count: Story = {
|
|
44
57
|
render: () => (
|
|
45
|
-
<Tabs
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
58
|
+
<Tabs defaultValue='overview'>
|
|
59
|
+
<Tabs.List fullWidth>
|
|
60
|
+
<Tabs.Tab
|
|
61
|
+
count={12}
|
|
62
|
+
value='overview'
|
|
63
|
+
>
|
|
64
|
+
Overview
|
|
65
|
+
</Tabs.Tab>
|
|
66
|
+
<Tabs.Tab
|
|
67
|
+
count={6}
|
|
68
|
+
value='modules'
|
|
69
|
+
>
|
|
70
|
+
Modules
|
|
71
|
+
</Tabs.Tab>
|
|
72
|
+
<Tabs.Tab
|
|
73
|
+
count={9}
|
|
74
|
+
value='people'
|
|
75
|
+
>
|
|
76
|
+
People
|
|
77
|
+
</Tabs.Tab>
|
|
78
|
+
<Tabs.Tab
|
|
79
|
+
count={0}
|
|
80
|
+
value='settings'
|
|
81
|
+
>
|
|
82
|
+
Settings
|
|
83
|
+
</Tabs.Tab>
|
|
84
|
+
</Tabs.List>
|
|
65
85
|
</Tabs>
|
|
66
86
|
),
|
|
67
87
|
};
|
|
68
88
|
|
|
69
|
-
export const
|
|
70
|
-
name: 'Counter',
|
|
89
|
+
export const Links: Story = {
|
|
71
90
|
render: () => (
|
|
72
|
-
<Tabs
|
|
73
|
-
<Tabs.
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
91
|
+
<Tabs value='overview'>
|
|
92
|
+
<Tabs.List>
|
|
93
|
+
<Tabs.Tab
|
|
94
|
+
value='overview'
|
|
95
|
+
asChild
|
|
96
|
+
>
|
|
97
|
+
<a href='#overview'>Overview</a>
|
|
98
|
+
</Tabs.Tab>
|
|
99
|
+
<Tabs.Tab
|
|
100
|
+
value='modules'
|
|
101
|
+
asChild
|
|
102
|
+
>
|
|
103
|
+
<a href='#modules'>Modules</a>
|
|
104
|
+
</Tabs.Tab>
|
|
105
|
+
<Tabs.Tab
|
|
106
|
+
value='people'
|
|
107
|
+
asChild
|
|
108
|
+
>
|
|
109
|
+
<a href='#people'>People</a>
|
|
110
|
+
</Tabs.Tab>
|
|
111
|
+
</Tabs.List>
|
|
93
112
|
</Tabs>
|
|
94
113
|
),
|
|
95
114
|
};
|