@dxos/react-ui-tabs 0.8.4-main.5acf9ea → 0.8.4-main.5ea62a8
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 +34 -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 +34 -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 +12 -12
- package/src/Tabs.stories.tsx +44 -39
- package/src/Tabs.tsx +39 -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.5ea62a8",
|
|
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.5ea62a8",
|
|
37
|
+
"@dxos/util": "0.8.4-main.5ea62a8"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/react": "~18.2.0",
|
|
41
41
|
"@types/react-dom": "~18.2.0",
|
|
42
42
|
"react": "~18.2.0",
|
|
43
43
|
"react-dom": "~18.2.0",
|
|
44
|
-
"vite": "
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/storybook-utils": "0.8.4-main.
|
|
44
|
+
"vite": "7.1.1",
|
|
45
|
+
"@dxos/random": "0.8.4-main.5ea62a8",
|
|
46
|
+
"@dxos/react-ui": "0.8.4-main.5ea62a8",
|
|
47
|
+
"@dxos/react-ui-theme": "0.8.4-main.5ea62a8",
|
|
48
|
+
"@dxos/storybook-utils": "0.8.4-main.5ea62a8"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
|
51
51
|
"react": "~18.2.0",
|
|
52
52
|
"react-dom": "~18.2.0",
|
|
53
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
54
|
-
"@dxos/react-ui
|
|
53
|
+
"@dxos/react-ui-theme": "0.8.4-main.5ea62a8",
|
|
54
|
+
"@dxos/react-ui": "0.8.4-main.5ea62a8"
|
|
55
55
|
},
|
|
56
56
|
"publishConfig": {
|
|
57
57
|
"access": "public"
|
package/src/Tabs.stories.tsx
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
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';
|
|
@@ -12,6 +13,41 @@ 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
|
|
|
@@ -185,6 +185,7 @@ type TabsTabProps = ButtonProps & Pick<TabsPrimitive.TabsTriggerProps, 'value'>;
|
|
|
185
185
|
const TabsTab = ({ value, classNames, children, onClick, ...props }: TabsTabProps) => {
|
|
186
186
|
const { setActivePart, orientation, value: contextValue, attendableId } = useTabsContext('TabsTab');
|
|
187
187
|
const { hasAttention } = useAttention(attendableId);
|
|
188
|
+
|
|
188
189
|
const handleClick = useCallback(
|
|
189
190
|
// NOTE: This handler is only called if the tab is *already active*.
|
|
190
191
|
(event: MouseEvent<HTMLButtonElement>) => {
|
|
@@ -204,10 +205,8 @@ const TabsTab = ({ value, classNames, children, onClick, ...props }: TabsTabProp
|
|
|
204
205
|
{...props}
|
|
205
206
|
onClick={handleClick}
|
|
206
207
|
classNames={[
|
|
207
|
-
'pli-2 rounded-sm',
|
|
208
208
|
orientation === 'vertical' && 'block justify-start text-start is-full',
|
|
209
209
|
orientation === 'vertical' && ghostSelectedContainerMd,
|
|
210
|
-
ghostHover,
|
|
211
210
|
classNames,
|
|
212
211
|
]}
|
|
213
212
|
>
|
|
@@ -217,6 +216,40 @@ const TabsTab = ({ value, classNames, children, onClick, ...props }: TabsTabProp
|
|
|
217
216
|
);
|
|
218
217
|
};
|
|
219
218
|
|
|
219
|
+
type TabsIconTabProps = IconButtonProps & Pick<TabsPrimitive.TabsTriggerProps, 'value'>;
|
|
220
|
+
|
|
221
|
+
const TabsIconTab = ({ value, classNames, onClick, ...props }: TabsIconTabProps) => {
|
|
222
|
+
const { setActivePart, orientation, value: contextValue, attendableId } = useTabsContext('TabsTab');
|
|
223
|
+
const { hasAttention } = useAttention(attendableId);
|
|
224
|
+
|
|
225
|
+
// NOTE: This handler is only called if the tab is *already active*.
|
|
226
|
+
const handleClick = useCallback(
|
|
227
|
+
(event: MouseEvent<HTMLButtonElement>) => {
|
|
228
|
+
setActivePart('panel');
|
|
229
|
+
onClick?.(event);
|
|
230
|
+
},
|
|
231
|
+
[setActivePart, onClick],
|
|
232
|
+
);
|
|
233
|
+
|
|
234
|
+
return (
|
|
235
|
+
<TabsPrimitive.Trigger value={value} asChild>
|
|
236
|
+
<IconButton
|
|
237
|
+
density='fine'
|
|
238
|
+
variant={
|
|
239
|
+
orientation === 'horizontal' && contextValue === value ? (hasAttention ? 'primary' : 'default') : 'ghost'
|
|
240
|
+
}
|
|
241
|
+
{...props}
|
|
242
|
+
onClick={handleClick}
|
|
243
|
+
classNames={[
|
|
244
|
+
orientation === 'vertical' && 'justify-start text-start is-full',
|
|
245
|
+
orientation === 'vertical' && ghostSelectedContainerMd,
|
|
246
|
+
classNames,
|
|
247
|
+
]}
|
|
248
|
+
/>
|
|
249
|
+
</TabsPrimitive.Trigger>
|
|
250
|
+
);
|
|
251
|
+
};
|
|
252
|
+
|
|
220
253
|
type TabsTabpanelProps = ThemedClassName<TabsPrimitive.TabsContentProps>;
|
|
221
254
|
|
|
222
255
|
const TabsTabpanel = ({ classNames, children, ...props }: TabsTabpanelProps) => {
|
|
@@ -233,6 +266,7 @@ export const Tabs = {
|
|
|
233
266
|
Root: TabsRoot,
|
|
234
267
|
Tablist: TabsTablist,
|
|
235
268
|
Tab: TabsTab,
|
|
269
|
+
IconTab: TabsIconTab,
|
|
236
270
|
TabPrimitive: TabsPrimitive.Trigger,
|
|
237
271
|
TabGroupHeading: TabsTabGroupHeading,
|
|
238
272
|
Tabpanel: TabsTabpanel,
|