@dxos/react-ui-tabs 0.8.4-main.84f28bd → 0.8.4-main.ae835ea

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-tabs",
3
- "version": "0.8.4-main.84f28bd",
3
+ "version": "0.8.4-main.ae835ea",
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,6 +10,7 @@
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
16
  "node": "./dist/lib/node-esm/index.mjs"
@@ -32,25 +33,25 @@
32
33
  "@radix-ui/react-slot": "1.1.2",
33
34
  "@radix-ui/react-tabs": "1.1.3",
34
35
  "@radix-ui/react-use-controllable-state": "1.1.0",
35
- "@dxos/react-ui-attention": "0.8.4-main.84f28bd",
36
- "@dxos/util": "0.8.4-main.84f28bd"
36
+ "@dxos/react-ui-attention": "0.8.4-main.ae835ea",
37
+ "@dxos/util": "0.8.4-main.ae835ea"
37
38
  },
38
39
  "devDependencies": {
39
- "@types/react": "~18.2.0",
40
- "@types/react-dom": "~18.2.0",
41
- "react": "~18.2.0",
42
- "react-dom": "~18.2.0",
43
- "vite": "5.4.7",
44
- "@dxos/random": "0.8.4-main.84f28bd",
45
- "@dxos/react-ui": "0.8.4-main.84f28bd",
46
- "@dxos/react-ui-theme": "0.8.4-main.84f28bd",
47
- "@dxos/storybook-utils": "0.8.4-main.84f28bd"
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.ae835ea",
46
+ "@dxos/react-ui-theme": "0.8.4-main.ae835ea",
47
+ "@dxos/react-ui": "0.8.4-main.ae835ea",
48
+ "@dxos/storybook-utils": "0.8.4-main.ae835ea"
48
49
  },
49
50
  "peerDependencies": {
50
- "react": "~18.2.0",
51
- "react-dom": "~18.2.0",
52
- "@dxos/react-ui": "0.8.4-main.84f28bd",
53
- "@dxos/react-ui-theme": "0.8.4-main.84f28bd"
51
+ "react": "^19.0.0",
52
+ "react-dom": "^19.0.0",
53
+ "@dxos/react-ui": "0.8.4-main.ae835ea",
54
+ "@dxos/react-ui-theme": "0.8.4-main.ae835ea"
54
55
  },
55
56
  "publishConfig": {
56
57
  "access": "public"
@@ -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/storybook-utils';
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
- export default {
59
+ const meta = {
24
60
  title: 'ui/react-ui-tabs/Tabs',
25
61
  component: NaturalTabs.Root,
62
+ render: DefaultStory,
26
63
  decorators: [withTheme],
27
- // parameters: { translations },
28
- };
64
+ } satisfies Meta<typeof DefaultStory>;
29
65
 
30
- export const Tabs = {
31
- render: () => {
32
- return (
33
- <Dialog.Root open>
34
- <Dialog.Overlay blockAlign='start'>
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 { useFocusFinders, useArrowNavigationGroup, useFocusableGroup } from '@fluentui/react-tabster';
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 { ghostHover, ghostSelectedContainerMd, mx } from '@dxos/react-ui-theme';
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,