@dxos/react-ui-tabs 0.8.4-main.fd6878d → 0.8.4-main.fffef41
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/lib/browser/index.mjs +40 -7
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +40 -7
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/Tabs.d.ts +3 -1
- package/dist/types/src/Tabs.d.ts.map +1 -1
- package/dist/types/src/Tabs.stories.d.ts +7 -5
- package/dist/types/src/Tabs.stories.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +16 -16
- package/src/Tabs.stories.tsx +45 -40
- package/src/Tabs.tsx +53 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-tabs",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.fffef41",
|
|
4
4
|
"description": "Components for facilitating a Tabs pattern.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -33,25 +33,25 @@
|
|
|
33
33
|
"@radix-ui/react-slot": "1.1.2",
|
|
34
34
|
"@radix-ui/react-tabs": "1.1.3",
|
|
35
35
|
"@radix-ui/react-use-controllable-state": "1.1.0",
|
|
36
|
-
"@dxos/react-ui-attention": "0.8.4-main.
|
|
37
|
-
"@dxos/util": "0.8.4-main.
|
|
36
|
+
"@dxos/react-ui-attention": "0.8.4-main.fffef41",
|
|
37
|
+
"@dxos/util": "0.8.4-main.fffef41"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@types/react": "~
|
|
41
|
-
"@types/react-dom": "~
|
|
42
|
-
"react": "~
|
|
43
|
-
"react-dom": "~
|
|
44
|
-
"vite": "
|
|
45
|
-
"@dxos/random": "0.8.4-main.
|
|
46
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
47
|
-
"@dxos/react-ui-theme": "0.8.4-main.
|
|
48
|
-
"@dxos/storybook-utils": "0.8.4-main.
|
|
40
|
+
"@types/react": "~19.2.2",
|
|
41
|
+
"@types/react-dom": "~19.2.2",
|
|
42
|
+
"react": "~19.2.0",
|
|
43
|
+
"react-dom": "~19.2.0",
|
|
44
|
+
"vite": "7.1.9",
|
|
45
|
+
"@dxos/random": "0.8.4-main.fffef41",
|
|
46
|
+
"@dxos/react-ui": "0.8.4-main.fffef41",
|
|
47
|
+
"@dxos/react-ui-theme": "0.8.4-main.fffef41",
|
|
48
|
+
"@dxos/storybook-utils": "0.8.4-main.fffef41"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
|
-
"react": "
|
|
52
|
-
"react-dom": "
|
|
53
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
54
|
-
"@dxos/react-ui-theme": "0.8.4-main.
|
|
51
|
+
"react": "^19.0.0",
|
|
52
|
+
"react-dom": "^19.0.0",
|
|
53
|
+
"@dxos/react-ui": "0.8.4-main.fffef41",
|
|
54
|
+
"@dxos/react-ui-theme": "0.8.4-main.fffef41"
|
|
55
55
|
},
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
package/src/Tabs.stories.tsx
CHANGED
|
@@ -2,16 +2,52 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
5
6
|
import React from 'react';
|
|
6
7
|
|
|
7
8
|
import { faker } from '@dxos/random';
|
|
8
9
|
import { Dialog, Icon } from '@dxos/react-ui';
|
|
9
|
-
import { withTheme } from '@dxos/
|
|
10
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
10
11
|
|
|
11
12
|
import { Tabs as NaturalTabs } from './Tabs';
|
|
12
13
|
|
|
13
14
|
faker.seed(1234);
|
|
14
15
|
|
|
16
|
+
export const DefaultStory = () => {
|
|
17
|
+
return (
|
|
18
|
+
<Dialog.Root open>
|
|
19
|
+
<Dialog.Overlay blockAlign='start'>
|
|
20
|
+
<Dialog.Content classNames='is-[calc(100dvw-4rem)] !max-is-full'>
|
|
21
|
+
<NaturalTabs.Root orientation='vertical' defaultValue={Object.keys(content)[3]} defaultActivePart='list'>
|
|
22
|
+
<NaturalTabs.Viewport>
|
|
23
|
+
<NaturalTabs.Tablist>
|
|
24
|
+
{Object.entries(content).map(([id, { title }]) => {
|
|
25
|
+
return (
|
|
26
|
+
<NaturalTabs.Tab key={id} value={id}>
|
|
27
|
+
{title}
|
|
28
|
+
</NaturalTabs.Tab>
|
|
29
|
+
);
|
|
30
|
+
})}
|
|
31
|
+
</NaturalTabs.Tablist>
|
|
32
|
+
{Object.entries(content).map(([id, { panel }]) => {
|
|
33
|
+
return (
|
|
34
|
+
<NaturalTabs.Tabpanel key={id} value={id} classNames='m-1'>
|
|
35
|
+
<NaturalTabs.BackButton density='fine'>
|
|
36
|
+
<Icon icon='ph--arrow-left--bold' size={4} />
|
|
37
|
+
<span>Back to tab list</span>
|
|
38
|
+
</NaturalTabs.BackButton>
|
|
39
|
+
<p className='pli-1'>{panel}</p>
|
|
40
|
+
</NaturalTabs.Tabpanel>
|
|
41
|
+
);
|
|
42
|
+
})}
|
|
43
|
+
</NaturalTabs.Viewport>
|
|
44
|
+
</NaturalTabs.Root>
|
|
45
|
+
</Dialog.Content>
|
|
46
|
+
</Dialog.Overlay>
|
|
47
|
+
</Dialog.Root>
|
|
48
|
+
);
|
|
49
|
+
};
|
|
50
|
+
|
|
15
51
|
const content = [...Array(24)].reduce((acc: { [key: string]: { title: string; panel: string } }, _, index) => {
|
|
16
52
|
acc[`t${index}`] = {
|
|
17
53
|
title: faker.commerce.productName(),
|
|
@@ -20,46 +56,15 @@ const content = [...Array(24)].reduce((acc: { [key: string]: { title: string; pa
|
|
|
20
56
|
return acc;
|
|
21
57
|
}, {});
|
|
22
58
|
|
|
23
|
-
|
|
59
|
+
const meta = {
|
|
24
60
|
title: 'ui/react-ui-tabs/Tabs',
|
|
25
61
|
component: NaturalTabs.Root,
|
|
62
|
+
render: DefaultStory,
|
|
26
63
|
decorators: [withTheme],
|
|
27
|
-
|
|
28
|
-
};
|
|
64
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
29
65
|
|
|
30
|
-
export
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
<Dialog.Content classNames='is-[calc(100dvw-4rem)] !max-is-full'>
|
|
36
|
-
<NaturalTabs.Root orientation='vertical' defaultValue={Object.keys(content)[3]} defaultActivePart='list'>
|
|
37
|
-
<NaturalTabs.Viewport>
|
|
38
|
-
<NaturalTabs.Tablist>
|
|
39
|
-
{Object.entries(content).map(([id, { title }]) => {
|
|
40
|
-
return (
|
|
41
|
-
<NaturalTabs.Tab key={id} value={id}>
|
|
42
|
-
{title}
|
|
43
|
-
</NaturalTabs.Tab>
|
|
44
|
-
);
|
|
45
|
-
})}
|
|
46
|
-
</NaturalTabs.Tablist>
|
|
47
|
-
{Object.entries(content).map(([id, { panel }]) => {
|
|
48
|
-
return (
|
|
49
|
-
<NaturalTabs.Tabpanel key={id} value={id} classNames='m-1'>
|
|
50
|
-
<NaturalTabs.BackButton density='fine'>
|
|
51
|
-
<Icon icon='ph--arrow-left--bold' size={4} />
|
|
52
|
-
<span>Back to tab list</span>
|
|
53
|
-
</NaturalTabs.BackButton>
|
|
54
|
-
<p className='pli-1'>{panel}</p>
|
|
55
|
-
</NaturalTabs.Tabpanel>
|
|
56
|
-
);
|
|
57
|
-
})}
|
|
58
|
-
</NaturalTabs.Viewport>
|
|
59
|
-
</NaturalTabs.Root>
|
|
60
|
-
</Dialog.Content>
|
|
61
|
-
</Dialog.Overlay>
|
|
62
|
-
</Dialog.Root>
|
|
63
|
-
);
|
|
64
|
-
},
|
|
65
|
-
};
|
|
66
|
+
export default meta;
|
|
67
|
+
|
|
68
|
+
type Story = StoryObj<typeof meta>;
|
|
69
|
+
|
|
70
|
+
export const Default: Story = {};
|
package/src/Tabs.tsx
CHANGED
|
@@ -6,11 +6,18 @@ import { useArrowNavigationGroup, useFocusFinders, useFocusableGroup } from '@fl
|
|
|
6
6
|
import { createContext } from '@radix-ui/react-context';
|
|
7
7
|
import * as TabsPrimitive from '@radix-ui/react-tabs';
|
|
8
8
|
import { useControllableState } from '@radix-ui/react-use-controllable-state';
|
|
9
|
-
import React, {
|
|
9
|
+
import React, {
|
|
10
|
+
Activity,
|
|
11
|
+
type ComponentPropsWithoutRef,
|
|
12
|
+
type MouseEvent,
|
|
13
|
+
useCallback,
|
|
14
|
+
useLayoutEffect,
|
|
15
|
+
useRef,
|
|
16
|
+
} from 'react';
|
|
10
17
|
|
|
11
|
-
import { Button, type ButtonProps, type ThemedClassName } from '@dxos/react-ui';
|
|
18
|
+
import { Button, type ButtonProps, IconButton, type IconButtonProps, type ThemedClassName } from '@dxos/react-ui';
|
|
12
19
|
import { useAttention } from '@dxos/react-ui-attention';
|
|
13
|
-
import {
|
|
20
|
+
import { ghostSelectedContainerMd, mx } from '@dxos/react-ui-theme';
|
|
14
21
|
|
|
15
22
|
type TabsActivePart = 'list' | 'panel';
|
|
16
23
|
|
|
@@ -144,6 +151,7 @@ const TabsTablist = ({ children, classNames, ...props }: TabsTablistProps) => {
|
|
|
144
151
|
return (
|
|
145
152
|
<TabsPrimitive.List
|
|
146
153
|
{...props}
|
|
154
|
+
data-arrow-keys={orientation === 'vertical' ? 'up down' : 'left right'}
|
|
147
155
|
className={mx(
|
|
148
156
|
'max-bs-full is-full',
|
|
149
157
|
// NOTE: Padding should be common to Toolbar.
|
|
@@ -185,6 +193,7 @@ type TabsTabProps = ButtonProps & Pick<TabsPrimitive.TabsTriggerProps, 'value'>;
|
|
|
185
193
|
const TabsTab = ({ value, classNames, children, onClick, ...props }: TabsTabProps) => {
|
|
186
194
|
const { setActivePart, orientation, value: contextValue, attendableId } = useTabsContext('TabsTab');
|
|
187
195
|
const { hasAttention } = useAttention(attendableId);
|
|
196
|
+
|
|
188
197
|
const handleClick = useCallback(
|
|
189
198
|
// NOTE: This handler is only called if the tab is *already active*.
|
|
190
199
|
(event: MouseEvent<HTMLButtonElement>) => {
|
|
@@ -204,10 +213,8 @@ const TabsTab = ({ value, classNames, children, onClick, ...props }: TabsTabProp
|
|
|
204
213
|
{...props}
|
|
205
214
|
onClick={handleClick}
|
|
206
215
|
classNames={[
|
|
207
|
-
'pli-2 rounded-sm',
|
|
208
216
|
orientation === 'vertical' && 'block justify-start text-start is-full',
|
|
209
217
|
orientation === 'vertical' && ghostSelectedContainerMd,
|
|
210
|
-
ghostHover,
|
|
211
218
|
classNames,
|
|
212
219
|
]}
|
|
213
220
|
>
|
|
@@ -217,13 +224,50 @@ const TabsTab = ({ value, classNames, children, onClick, ...props }: TabsTabProp
|
|
|
217
224
|
);
|
|
218
225
|
};
|
|
219
226
|
|
|
227
|
+
type TabsIconTabProps = IconButtonProps & Pick<TabsPrimitive.TabsTriggerProps, 'value'>;
|
|
228
|
+
|
|
229
|
+
const TabsIconTab = ({ value, classNames, onClick, ...props }: TabsIconTabProps) => {
|
|
230
|
+
const { setActivePart, orientation, value: contextValue, attendableId } = useTabsContext('TabsTab');
|
|
231
|
+
const { hasAttention } = useAttention(attendableId);
|
|
232
|
+
|
|
233
|
+
// NOTE: This handler is only called if the tab is *already active*.
|
|
234
|
+
const handleClick = useCallback(
|
|
235
|
+
(event: MouseEvent<HTMLButtonElement>) => {
|
|
236
|
+
setActivePart('panel');
|
|
237
|
+
onClick?.(event);
|
|
238
|
+
},
|
|
239
|
+
[setActivePart, onClick],
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
return (
|
|
243
|
+
<TabsPrimitive.Trigger value={value} asChild>
|
|
244
|
+
<IconButton
|
|
245
|
+
density='fine'
|
|
246
|
+
variant={
|
|
247
|
+
orientation === 'horizontal' && contextValue === value ? (hasAttention ? 'primary' : 'default') : 'ghost'
|
|
248
|
+
}
|
|
249
|
+
{...props}
|
|
250
|
+
onClick={handleClick}
|
|
251
|
+
classNames={[
|
|
252
|
+
orientation === 'vertical' && 'justify-start text-start is-full',
|
|
253
|
+
orientation === 'vertical' && ghostSelectedContainerMd,
|
|
254
|
+
classNames,
|
|
255
|
+
]}
|
|
256
|
+
/>
|
|
257
|
+
</TabsPrimitive.Trigger>
|
|
258
|
+
);
|
|
259
|
+
};
|
|
260
|
+
|
|
220
261
|
type TabsTabpanelProps = ThemedClassName<TabsPrimitive.TabsContentProps>;
|
|
221
262
|
|
|
222
263
|
const TabsTabpanel = ({ classNames, children, ...props }: TabsTabpanelProps) => {
|
|
264
|
+
const { value: contextValue } = useTabsContext('TabsTab');
|
|
223
265
|
return (
|
|
224
|
-
<
|
|
225
|
-
{
|
|
226
|
-
|
|
266
|
+
<Activity mode={contextValue === props.value ? 'visible' : 'hidden'}>
|
|
267
|
+
<TabsPrimitive.Content {...props} className={mx('dx-focus-ring-inset-over-all', classNames)}>
|
|
268
|
+
{children}
|
|
269
|
+
</TabsPrimitive.Content>
|
|
270
|
+
</Activity>
|
|
227
271
|
);
|
|
228
272
|
};
|
|
229
273
|
|
|
@@ -233,6 +277,7 @@ export const Tabs = {
|
|
|
233
277
|
Root: TabsRoot,
|
|
234
278
|
Tablist: TabsTablist,
|
|
235
279
|
Tab: TabsTab,
|
|
280
|
+
IconTab: TabsIconTab,
|
|
236
281
|
TabPrimitive: TabsPrimitive.Trigger,
|
|
237
282
|
TabGroupHeading: TabsTabGroupHeading,
|
|
238
283
|
Tabpanel: TabsTabpanel,
|