@dxos/react-ui-tabs 0.8.4-main.67995b8 → 0.8.4-main.a4bbb77
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 +35 -5
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +35 -5
- 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 +18 -18
- package/src/Tabs.stories.tsx +45 -40
- package/src/Tabs.tsx +40 -5
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.a4bbb77",
|
|
4
4
|
"description": "Components for facilitating a Tabs pattern.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
"type": "module",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
13
|
+
"source": "./src/index.ts",
|
|
13
14
|
"types": "./dist/types/src/index.d.ts",
|
|
14
15
|
"browser": "./dist/lib/browser/index.mjs",
|
|
15
|
-
"node": "./dist/lib/node-esm/index.mjs"
|
|
16
|
-
"source": "./src/index.ts"
|
|
16
|
+
"node": "./dist/lib/node-esm/index.mjs"
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"types": "dist/types/src/index.d.ts",
|
|
@@ -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.a4bbb77",
|
|
37
|
+
"@dxos/util": "0.8.4-main.a4bbb77"
|
|
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/
|
|
48
|
-
"@dxos/
|
|
40
|
+
"@types/react": "~19.2.0",
|
|
41
|
+
"@types/react-dom": "~19.2.0",
|
|
42
|
+
"react": "~19.2.0",
|
|
43
|
+
"react-dom": "~19.2.0",
|
|
44
|
+
"vite": "7.1.9",
|
|
45
|
+
"@dxos/random": "0.8.4-main.a4bbb77",
|
|
46
|
+
"@dxos/react-ui": "0.8.4-main.a4bbb77",
|
|
47
|
+
"@dxos/react-ui-theme": "0.8.4-main.a4bbb77",
|
|
48
|
+
"@dxos/storybook-utils": "0.8.4-main.a4bbb77"
|
|
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.a4bbb77",
|
|
54
|
+
"@dxos/react-ui-theme": "0.8.4-main.a4bbb77"
|
|
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
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { useArrowNavigationGroup, useFocusFinders, useFocusableGroup } from '@fluentui/react-tabster';
|
|
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
9
|
import React, { type ComponentPropsWithoutRef, type MouseEvent, useCallback, useLayoutEffect, useRef } from 'react';
|
|
10
10
|
|
|
11
|
-
import { Button, type ButtonProps, type ThemedClassName } from '@dxos/react-ui';
|
|
11
|
+
import { Button, type ButtonProps, IconButton, type IconButtonProps, type ThemedClassName } from '@dxos/react-ui';
|
|
12
12
|
import { useAttention } from '@dxos/react-ui-attention';
|
|
13
|
-
import {
|
|
13
|
+
import { ghostSelectedContainerMd, mx } from '@dxos/react-ui-theme';
|
|
14
14
|
|
|
15
15
|
type TabsActivePart = 'list' | 'panel';
|
|
16
16
|
|
|
@@ -144,6 +144,7 @@ const TabsTablist = ({ children, classNames, ...props }: TabsTablistProps) => {
|
|
|
144
144
|
return (
|
|
145
145
|
<TabsPrimitive.List
|
|
146
146
|
{...props}
|
|
147
|
+
data-arrow-keys={orientation === 'vertical' ? 'up down' : 'left right'}
|
|
147
148
|
className={mx(
|
|
148
149
|
'max-bs-full is-full',
|
|
149
150
|
// NOTE: Padding should be common to Toolbar.
|
|
@@ -185,6 +186,7 @@ type TabsTabProps = ButtonProps & Pick<TabsPrimitive.TabsTriggerProps, 'value'>;
|
|
|
185
186
|
const TabsTab = ({ value, classNames, children, onClick, ...props }: TabsTabProps) => {
|
|
186
187
|
const { setActivePart, orientation, value: contextValue, attendableId } = useTabsContext('TabsTab');
|
|
187
188
|
const { hasAttention } = useAttention(attendableId);
|
|
189
|
+
|
|
188
190
|
const handleClick = useCallback(
|
|
189
191
|
// NOTE: This handler is only called if the tab is *already active*.
|
|
190
192
|
(event: MouseEvent<HTMLButtonElement>) => {
|
|
@@ -204,10 +206,8 @@ const TabsTab = ({ value, classNames, children, onClick, ...props }: TabsTabProp
|
|
|
204
206
|
{...props}
|
|
205
207
|
onClick={handleClick}
|
|
206
208
|
classNames={[
|
|
207
|
-
'pli-2 rounded-sm',
|
|
208
209
|
orientation === 'vertical' && 'block justify-start text-start is-full',
|
|
209
210
|
orientation === 'vertical' && ghostSelectedContainerMd,
|
|
210
|
-
ghostHover,
|
|
211
211
|
classNames,
|
|
212
212
|
]}
|
|
213
213
|
>
|
|
@@ -217,6 +217,40 @@ const TabsTab = ({ value, classNames, children, onClick, ...props }: TabsTabProp
|
|
|
217
217
|
);
|
|
218
218
|
};
|
|
219
219
|
|
|
220
|
+
type TabsIconTabProps = IconButtonProps & Pick<TabsPrimitive.TabsTriggerProps, 'value'>;
|
|
221
|
+
|
|
222
|
+
const TabsIconTab = ({ value, classNames, onClick, ...props }: TabsIconTabProps) => {
|
|
223
|
+
const { setActivePart, orientation, value: contextValue, attendableId } = useTabsContext('TabsTab');
|
|
224
|
+
const { hasAttention } = useAttention(attendableId);
|
|
225
|
+
|
|
226
|
+
// NOTE: This handler is only called if the tab is *already active*.
|
|
227
|
+
const handleClick = useCallback(
|
|
228
|
+
(event: MouseEvent<HTMLButtonElement>) => {
|
|
229
|
+
setActivePart('panel');
|
|
230
|
+
onClick?.(event);
|
|
231
|
+
},
|
|
232
|
+
[setActivePart, onClick],
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
return (
|
|
236
|
+
<TabsPrimitive.Trigger value={value} asChild>
|
|
237
|
+
<IconButton
|
|
238
|
+
density='fine'
|
|
239
|
+
variant={
|
|
240
|
+
orientation === 'horizontal' && contextValue === value ? (hasAttention ? 'primary' : 'default') : 'ghost'
|
|
241
|
+
}
|
|
242
|
+
{...props}
|
|
243
|
+
onClick={handleClick}
|
|
244
|
+
classNames={[
|
|
245
|
+
orientation === 'vertical' && 'justify-start text-start is-full',
|
|
246
|
+
orientation === 'vertical' && ghostSelectedContainerMd,
|
|
247
|
+
classNames,
|
|
248
|
+
]}
|
|
249
|
+
/>
|
|
250
|
+
</TabsPrimitive.Trigger>
|
|
251
|
+
);
|
|
252
|
+
};
|
|
253
|
+
|
|
220
254
|
type TabsTabpanelProps = ThemedClassName<TabsPrimitive.TabsContentProps>;
|
|
221
255
|
|
|
222
256
|
const TabsTabpanel = ({ classNames, children, ...props }: TabsTabpanelProps) => {
|
|
@@ -233,6 +267,7 @@ export const Tabs = {
|
|
|
233
267
|
Root: TabsRoot,
|
|
234
268
|
Tablist: TabsTablist,
|
|
235
269
|
Tab: TabsTab,
|
|
270
|
+
IconTab: TabsIconTab,
|
|
236
271
|
TabPrimitive: TabsPrimitive.Trigger,
|
|
237
272
|
TabGroupHeading: TabsTabGroupHeading,
|
|
238
273
|
Tabpanel: TabsTabpanel,
|