@dxos/react-ui-tabs 0.8.4-main.ae835ea → 0.8.4-main.bc2380dfbc
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/LICENSE +102 -5
- package/dist/lib/browser/index.mjs +142 -188
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +142 -188
- 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 +10 -6
- package/dist/types/src/Tabs.d.ts.map +1 -1
- package/dist/types/src/Tabs.stories.d.ts +17 -4
- package/dist/types/src/Tabs.stories.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +23 -23
- package/src/Tabs.stories.tsx +48 -41
- package/src/Tabs.tsx +125 -124
package/LICENSE
CHANGED
|
@@ -1,8 +1,105 @@
|
|
|
1
|
-
|
|
2
|
-
Copyright (c) 2024 DXOS
|
|
1
|
+
# Functional Source License, Version 1.1, ALv2 Future License
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
## Abbreviation
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
FSL-1.1-Apache-2.0
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
## Notice
|
|
8
|
+
|
|
9
|
+
Copyright 2026 DXOS
|
|
10
|
+
|
|
11
|
+
## Terms and Conditions
|
|
12
|
+
|
|
13
|
+
### Licensor ("We")
|
|
14
|
+
|
|
15
|
+
The party offering the Software under these Terms and Conditions.
|
|
16
|
+
|
|
17
|
+
### The Software
|
|
18
|
+
|
|
19
|
+
The "Software" is each version of the software that we make available under
|
|
20
|
+
these Terms and Conditions, as indicated by our inclusion of these Terms and
|
|
21
|
+
Conditions with the Software.
|
|
22
|
+
|
|
23
|
+
### License Grant
|
|
24
|
+
|
|
25
|
+
Subject to your compliance with this License Grant and the Patents,
|
|
26
|
+
Redistribution and Trademark clauses below, we hereby grant you the right to
|
|
27
|
+
use, copy, modify, create derivative works, publicly perform, publicly display
|
|
28
|
+
and redistribute the Software for any Permitted Purpose identified below.
|
|
29
|
+
|
|
30
|
+
### Permitted Purpose
|
|
31
|
+
|
|
32
|
+
A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
|
|
33
|
+
means making the Software available to others in a commercial product or
|
|
34
|
+
service that:
|
|
35
|
+
|
|
36
|
+
1. substitutes for the Software;
|
|
37
|
+
|
|
38
|
+
2. substitutes for any other product or service we offer using the Software
|
|
39
|
+
that exists as of the date we make the Software available; or
|
|
40
|
+
|
|
41
|
+
3. offers the same or substantially similar functionality as the Software.
|
|
42
|
+
|
|
43
|
+
Permitted Purposes specifically include using the Software:
|
|
44
|
+
|
|
45
|
+
1. for your internal use and access;
|
|
46
|
+
|
|
47
|
+
2. for non-commercial education;
|
|
48
|
+
|
|
49
|
+
3. for non-commercial research; and
|
|
50
|
+
|
|
51
|
+
4. in connection with professional services that you provide to a licensee
|
|
52
|
+
using the Software in accordance with these Terms and Conditions.
|
|
53
|
+
|
|
54
|
+
### Patents
|
|
55
|
+
|
|
56
|
+
To the extent your use for a Permitted Purpose would necessarily infringe our
|
|
57
|
+
patents, the license grant above includes a license under our patents. If you
|
|
58
|
+
make a claim against any party that the Software infringes or contributes to
|
|
59
|
+
the infringement of any patent, then your patent license to the Software ends
|
|
60
|
+
immediately.
|
|
61
|
+
|
|
62
|
+
### Redistribution
|
|
63
|
+
|
|
64
|
+
The Terms and Conditions apply to all copies, modifications and derivatives of
|
|
65
|
+
the Software.
|
|
66
|
+
|
|
67
|
+
If you redistribute any copies, modifications or derivatives of the Software,
|
|
68
|
+
you must include a copy of or a link to these Terms and Conditions and not
|
|
69
|
+
remove any copyright notices provided in or with the Software.
|
|
70
|
+
|
|
71
|
+
### Disclaimer
|
|
72
|
+
|
|
73
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
|
|
74
|
+
IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
|
|
75
|
+
PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
|
|
76
|
+
|
|
77
|
+
IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
|
|
78
|
+
SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
|
|
79
|
+
EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
|
|
80
|
+
|
|
81
|
+
### Trademarks
|
|
82
|
+
|
|
83
|
+
Except for displaying the License Details and identifying us as the origin of
|
|
84
|
+
the Software, you have no right under these Terms and Conditions to use our
|
|
85
|
+
trademarks, trade names, service marks or product names.
|
|
86
|
+
|
|
87
|
+
## Grant of Future License
|
|
88
|
+
|
|
89
|
+
We hereby irrevocably grant you an additional license to use the Software under
|
|
90
|
+
the Apache License, Version 2.0 that is effective on the second anniversary of
|
|
91
|
+
the date we make the Software available. On or after that date, you may use the
|
|
92
|
+
Software under the Apache License, Version 2.0, in which case the following
|
|
93
|
+
will apply:
|
|
94
|
+
|
|
95
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
|
|
96
|
+
this file except in compliance with the License.
|
|
97
|
+
|
|
98
|
+
You may obtain a copy of the License at
|
|
99
|
+
|
|
100
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
101
|
+
|
|
102
|
+
Unless required by applicable law or agreed to in writing, software distributed
|
|
103
|
+
under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
|
104
|
+
CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
|
105
|
+
specific language governing permissions and limitations under the License.
|
|
@@ -1,215 +1,169 @@
|
|
|
1
1
|
// src/Tabs.tsx
|
|
2
|
-
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
3
2
|
import { useArrowNavigationGroup, useFocusFinders, useFocusableGroup } from "@fluentui/react-tabster";
|
|
4
3
|
import { createContext } from "@radix-ui/react-context";
|
|
5
4
|
import * as TabsPrimitive from "@radix-ui/react-tabs";
|
|
6
5
|
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
7
|
-
import React, { useCallback, useLayoutEffect
|
|
8
|
-
import { Button, IconButton } from "@dxos/react-ui";
|
|
6
|
+
import React, { Activity, forwardRef, useCallback, useLayoutEffect } from "react";
|
|
7
|
+
import { Button, IconButton, useForwardedRef } from "@dxos/react-ui";
|
|
9
8
|
import { useAttention } from "@dxos/react-ui-attention";
|
|
10
|
-
import {
|
|
9
|
+
import { mx } from "@dxos/ui-theme";
|
|
11
10
|
var TABS_NAME = "Tabs";
|
|
12
11
|
var [TabsContextProvider, useTabsContext] = createContext(TABS_NAME, {
|
|
12
|
+
orientation: "vertical",
|
|
13
13
|
activePart: "list",
|
|
14
14
|
setActivePart: () => {
|
|
15
|
-
},
|
|
16
|
-
orientation: "vertical"
|
|
17
|
-
});
|
|
18
|
-
var TabsRoot = ({ children, classNames, activePart: propsActivePart, onActivePartChange, defaultActivePart, value: propsValue, onValueChange, defaultValue, orientation = "vertical", activationMode = "manual", verticalVariant = "stateful", attendableId, ...props }) => {
|
|
19
|
-
var _effect = _useSignals();
|
|
20
|
-
try {
|
|
21
|
-
const _1 = useArrowNavigationGroup();
|
|
22
|
-
const _2 = useFocusableGroup();
|
|
23
|
-
const [activePart = "list", setActivePart] = useControllableState({
|
|
24
|
-
prop: propsActivePart,
|
|
25
|
-
onChange: onActivePartChange,
|
|
26
|
-
defaultProp: defaultActivePart
|
|
27
|
-
});
|
|
28
|
-
const [value, setValue] = useControllableState({
|
|
29
|
-
prop: propsValue,
|
|
30
|
-
onChange: onValueChange,
|
|
31
|
-
defaultProp: defaultValue
|
|
32
|
-
});
|
|
33
|
-
const handleValueChange = useCallback((nextValue) => {
|
|
34
|
-
setActivePart("panel");
|
|
35
|
-
setValue(nextValue);
|
|
36
|
-
}, [
|
|
37
|
-
value
|
|
38
|
-
]);
|
|
39
|
-
const { findFirstFocusable } = useFocusFinders();
|
|
40
|
-
const tabsRoot = useRef(null);
|
|
41
|
-
useLayoutEffect(() => {
|
|
42
|
-
if (tabsRoot.current) {
|
|
43
|
-
findFirstFocusable(tabsRoot.current)?.focus();
|
|
44
|
-
}
|
|
45
|
-
}, [
|
|
46
|
-
activePart
|
|
47
|
-
]);
|
|
48
|
-
return /* @__PURE__ */ React.createElement(TabsContextProvider, {
|
|
49
|
-
orientation,
|
|
50
|
-
activePart,
|
|
51
|
-
setActivePart,
|
|
52
|
-
value,
|
|
53
|
-
attendableId,
|
|
54
|
-
verticalVariant
|
|
55
|
-
}, /* @__PURE__ */ React.createElement(TabsPrimitive.Root, {
|
|
56
|
-
activationMode,
|
|
57
|
-
"data-active": activePart,
|
|
58
|
-
orientation,
|
|
59
|
-
...props,
|
|
60
|
-
value,
|
|
61
|
-
onValueChange: handleValueChange,
|
|
62
|
-
className: mx("overflow-hidden", orientation === "vertical" && verticalVariant === "stateful" && "[&[data-active=list]_[role=tabpanel]]:invisible @md:[&[data-active=list]_[role=tabpanel]]:visible", classNames),
|
|
63
|
-
ref: tabsRoot
|
|
64
|
-
}, children));
|
|
65
|
-
} finally {
|
|
66
|
-
_effect.f();
|
|
67
15
|
}
|
|
68
|
-
};
|
|
16
|
+
});
|
|
17
|
+
var TabsRoot = /* @__PURE__ */ forwardRef(({ children, classNames, activePart: propsActivePart, onActivePartChange, defaultActivePart, value: propsValue, onValueChange, defaultValue, orientation = "vertical", activationMode = "manual", attendableId, ...props }, forwardedRef) => {
|
|
18
|
+
const tabsRoot = useForwardedRef(forwardedRef);
|
|
19
|
+
const _1 = useArrowNavigationGroup();
|
|
20
|
+
const _2 = useFocusableGroup();
|
|
21
|
+
const [activePart = "list", setActivePart] = useControllableState({
|
|
22
|
+
prop: propsActivePart,
|
|
23
|
+
onChange: onActivePartChange,
|
|
24
|
+
defaultProp: defaultActivePart
|
|
25
|
+
});
|
|
26
|
+
const [value, setValue] = useControllableState({
|
|
27
|
+
prop: propsValue,
|
|
28
|
+
onChange: onValueChange,
|
|
29
|
+
defaultProp: defaultValue
|
|
30
|
+
});
|
|
31
|
+
const handleValueChange = useCallback((nextValue) => {
|
|
32
|
+
setActivePart("panel");
|
|
33
|
+
setValue(nextValue);
|
|
34
|
+
}, [
|
|
35
|
+
value
|
|
36
|
+
]);
|
|
37
|
+
const { findFirstFocusable } = useFocusFinders();
|
|
38
|
+
useLayoutEffect(() => {
|
|
39
|
+
if (tabsRoot.current) {
|
|
40
|
+
findFirstFocusable(tabsRoot.current)?.focus();
|
|
41
|
+
}
|
|
42
|
+
}, [
|
|
43
|
+
activePart
|
|
44
|
+
]);
|
|
45
|
+
return /* @__PURE__ */ React.createElement(TabsContextProvider, {
|
|
46
|
+
orientation,
|
|
47
|
+
activePart,
|
|
48
|
+
setActivePart,
|
|
49
|
+
value,
|
|
50
|
+
attendableId
|
|
51
|
+
}, /* @__PURE__ */ React.createElement(TabsPrimitive.Root, {
|
|
52
|
+
...props,
|
|
53
|
+
className: mx("overflow-hidden", classNames),
|
|
54
|
+
orientation,
|
|
55
|
+
activationMode,
|
|
56
|
+
"data-active": activePart,
|
|
57
|
+
value,
|
|
58
|
+
onValueChange: handleValueChange,
|
|
59
|
+
ref: tabsRoot
|
|
60
|
+
}, children));
|
|
61
|
+
});
|
|
69
62
|
var TabsViewport = ({ classNames, children, ...props }) => {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
"data-active": activePart,
|
|
77
|
-
className: mx(orientation === "vertical" && verticalVariant === "stateful" && [
|
|
78
|
-
"grid is-[200%] grid-cols-2 data-[active=panel]:mis-[-100%]",
|
|
79
|
-
"@md:is-auto @md:data-[active=panel]:mis-0 @md:grid-cols-[minmax(min-content,1fr)_3fr] @md:gap-1"
|
|
80
|
-
], classNames)
|
|
81
|
-
}, children);
|
|
82
|
-
} finally {
|
|
83
|
-
_effect.f();
|
|
84
|
-
}
|
|
63
|
+
const { activePart } = useTabsContext("TabsViewport");
|
|
64
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
65
|
+
...props,
|
|
66
|
+
"data-active": activePart,
|
|
67
|
+
className: mx(classNames)
|
|
68
|
+
}, children);
|
|
85
69
|
};
|
|
86
70
|
var TabsTablist = ({ children, classNames, ...props }) => {
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
"
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
classNames
|
|
99
|
-
)
|
|
100
|
-
}, children);
|
|
101
|
-
} finally {
|
|
102
|
-
_effect.f();
|
|
103
|
-
}
|
|
71
|
+
const { orientation } = useTabsContext("TabsTablist");
|
|
72
|
+
return /* @__PURE__ */ React.createElement(TabsPrimitive.List, {
|
|
73
|
+
...props,
|
|
74
|
+
"data-arrow-keys": orientation === "vertical" ? "up down" : "left right",
|
|
75
|
+
className: mx(
|
|
76
|
+
"max-h-full w-full",
|
|
77
|
+
// TODO(burdon): Should be embeddable inside Toolbar (if horizontal).
|
|
78
|
+
orientation === "vertical" ? "overflow-y-auto" : "flex p-1 gap-1 items-stretch justify-start overflow-x-auto",
|
|
79
|
+
classNames
|
|
80
|
+
)
|
|
81
|
+
}, children);
|
|
104
82
|
};
|
|
105
83
|
var TabsBackButton = ({ onClick, classNames, ...props }) => {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
classNames
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
onClick: handleClick
|
|
123
|
-
});
|
|
124
|
-
} finally {
|
|
125
|
-
_effect.f();
|
|
126
|
-
}
|
|
84
|
+
const { setActivePart } = useTabsContext("TabsBackButton");
|
|
85
|
+
const handleClick = useCallback((event) => {
|
|
86
|
+
setActivePart("list");
|
|
87
|
+
return onClick?.(event);
|
|
88
|
+
}, [
|
|
89
|
+
setActivePart,
|
|
90
|
+
onClick
|
|
91
|
+
]);
|
|
92
|
+
return /* @__PURE__ */ React.createElement(Button, {
|
|
93
|
+
...props,
|
|
94
|
+
classNames: [
|
|
95
|
+
"@md:hidden text-start",
|
|
96
|
+
classNames
|
|
97
|
+
],
|
|
98
|
+
onClick: handleClick
|
|
99
|
+
});
|
|
127
100
|
};
|
|
128
101
|
var TabsTabGroupHeading = ({ children, classNames, ...props }) => {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
className: mx("mlb-1 pli-2 text-sm text-unAccent", classNames)
|
|
134
|
-
}, children);
|
|
135
|
-
} finally {
|
|
136
|
-
_effect.f();
|
|
137
|
-
}
|
|
102
|
+
return /* @__PURE__ */ React.createElement("h2", {
|
|
103
|
+
...props,
|
|
104
|
+
className: mx("my-1 px-2 text-sm text-un-accent", classNames)
|
|
105
|
+
}, children);
|
|
138
106
|
};
|
|
139
107
|
var TabsTab = ({ value, classNames, children, onClick, ...props }) => {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
// NOTE: This handler is only called if the tab is *already active*.
|
|
146
|
-
(event) => {
|
|
147
|
-
setActivePart("panel");
|
|
148
|
-
onClick?.(event);
|
|
149
|
-
},
|
|
150
|
-
[
|
|
151
|
-
setActivePart,
|
|
152
|
-
onClick
|
|
153
|
-
]
|
|
154
|
-
);
|
|
155
|
-
return /* @__PURE__ */ React.createElement(TabsPrimitive.Trigger, {
|
|
156
|
-
value,
|
|
157
|
-
asChild: true
|
|
158
|
-
}, /* @__PURE__ */ React.createElement(Button, {
|
|
159
|
-
density: "fine",
|
|
160
|
-
variant: orientation === "horizontal" && contextValue === value ? hasAttention ? "primary" : "default" : "ghost",
|
|
161
|
-
...props,
|
|
162
|
-
onClick: handleClick,
|
|
163
|
-
classNames: [
|
|
164
|
-
orientation === "vertical" && "block justify-start text-start is-full",
|
|
165
|
-
orientation === "vertical" && ghostSelectedContainerMd,
|
|
166
|
-
classNames
|
|
167
|
-
]
|
|
168
|
-
}, children));
|
|
169
|
-
} finally {
|
|
170
|
-
_effect.f();
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
var TabsIconTab = ({ value, classNames, onClick, ...props }) => {
|
|
174
|
-
var _effect = _useSignals();
|
|
175
|
-
try {
|
|
176
|
-
const { setActivePart, orientation, value: contextValue, attendableId } = useTabsContext("TabsTab");
|
|
177
|
-
const { hasAttention } = useAttention(attendableId);
|
|
178
|
-
const handleClick = useCallback((event) => {
|
|
108
|
+
const { setActivePart, orientation, value: contextValue, attendableId } = useTabsContext("TabsTab");
|
|
109
|
+
const { hasAttention } = useAttention(attendableId);
|
|
110
|
+
const handleClick = useCallback(
|
|
111
|
+
// NOTE: This handler is only called if the tab is *already active*.
|
|
112
|
+
(event) => {
|
|
179
113
|
setActivePart("panel");
|
|
180
114
|
onClick?.(event);
|
|
181
|
-
},
|
|
115
|
+
},
|
|
116
|
+
[
|
|
182
117
|
setActivePart,
|
|
183
118
|
onClick
|
|
184
|
-
]
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
} finally {
|
|
200
|
-
_effect.f();
|
|
201
|
-
}
|
|
119
|
+
]
|
|
120
|
+
);
|
|
121
|
+
return /* @__PURE__ */ React.createElement(TabsPrimitive.Trigger, {
|
|
122
|
+
value,
|
|
123
|
+
asChild: true
|
|
124
|
+
}, /* @__PURE__ */ React.createElement(Button, {
|
|
125
|
+
...props,
|
|
126
|
+
variant: orientation === "horizontal" && contextValue === value ? hasAttention ? "primary" : "default" : "ghost",
|
|
127
|
+
classNames: [
|
|
128
|
+
orientation === "vertical" && "block justify-start text-start w-full",
|
|
129
|
+
orientation === "vertical" && "dx-selected",
|
|
130
|
+
classNames
|
|
131
|
+
],
|
|
132
|
+
onClick: handleClick
|
|
133
|
+
}, children));
|
|
202
134
|
};
|
|
203
|
-
var
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
135
|
+
var TabsIconTab = ({ value, classNames, onClick, ...props }) => {
|
|
136
|
+
const { setActivePart, orientation, value: contextValue, attendableId } = useTabsContext("TabsTab");
|
|
137
|
+
const { hasAttention } = useAttention(attendableId);
|
|
138
|
+
const handleClick = useCallback((event) => {
|
|
139
|
+
setActivePart("panel");
|
|
140
|
+
onClick?.(event);
|
|
141
|
+
}, [
|
|
142
|
+
setActivePart,
|
|
143
|
+
onClick
|
|
144
|
+
]);
|
|
145
|
+
return /* @__PURE__ */ React.createElement(TabsPrimitive.Trigger, {
|
|
146
|
+
value,
|
|
147
|
+
asChild: true
|
|
148
|
+
}, /* @__PURE__ */ React.createElement(IconButton, {
|
|
149
|
+
...props,
|
|
150
|
+
variant: orientation === "horizontal" && contextValue === value ? hasAttention ? "primary" : "default" : "ghost",
|
|
151
|
+
classNames: [
|
|
152
|
+
orientation === "vertical" && "justify-start text-start w-full",
|
|
153
|
+
orientation === "vertical" && "dx-selected",
|
|
154
|
+
classNames
|
|
155
|
+
],
|
|
156
|
+
onClick: handleClick
|
|
157
|
+
}));
|
|
158
|
+
};
|
|
159
|
+
var TabsPanel = ({ classNames, children, ...props }) => {
|
|
160
|
+
const { value: contextValue } = useTabsContext("TabsTab");
|
|
161
|
+
return /* @__PURE__ */ React.createElement(Activity, {
|
|
162
|
+
mode: contextValue === props.value ? "visible" : "hidden"
|
|
163
|
+
}, /* @__PURE__ */ React.createElement(TabsPrimitive.Content, {
|
|
164
|
+
...props,
|
|
165
|
+
className: mx("p-0! dx-focus-ring-inset-over-all", classNames)
|
|
166
|
+
}, children));
|
|
213
167
|
};
|
|
214
168
|
var Tabs = {
|
|
215
169
|
Root: TabsRoot,
|
|
@@ -218,7 +172,7 @@ var Tabs = {
|
|
|
218
172
|
IconTab: TabsIconTab,
|
|
219
173
|
TabPrimitive: TabsPrimitive.Trigger,
|
|
220
174
|
TabGroupHeading: TabsTabGroupHeading,
|
|
221
|
-
|
|
175
|
+
Panel: TabsPanel,
|
|
222
176
|
BackButton: TabsBackButton,
|
|
223
177
|
Viewport: TabsViewport
|
|
224
178
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/Tabs.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { useArrowNavigationGroup, useFocusFinders, useFocusableGroup } from '@fluentui/react-tabster';\nimport { createContext } from '@radix-ui/react-context';\nimport * as TabsPrimitive from '@radix-ui/react-tabs';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport React, {
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["useArrowNavigationGroup", "useFocusFinders", "useFocusableGroup", "createContext", "TabsPrimitive", "useControllableState", "React", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { useArrowNavigationGroup, useFocusFinders, useFocusableGroup } from '@fluentui/react-tabster';\nimport { createContext } from '@radix-ui/react-context';\nimport * as TabsPrimitive from '@radix-ui/react-tabs';\nimport { useControllableState } from '@radix-ui/react-use-controllable-state';\nimport React, {\n Activity,\n type ComponentPropsWithoutRef,\n type MouseEvent,\n forwardRef,\n useCallback,\n useLayoutEffect,\n} from 'react';\n\nimport {\n Button,\n type ButtonProps,\n IconButton,\n type IconButtonProps,\n type ThemedClassName,\n useForwardedRef,\n} from '@dxos/react-ui';\nimport { useAttention } from '@dxos/react-ui-attention';\nimport { mx } from '@dxos/ui-theme';\n\ntype TabsActivePart = 'list' | 'panel';\n\nconst TABS_NAME = 'Tabs';\n\ntype TabsContextValue = {\n activePart: TabsActivePart;\n setActivePart: (nextActivePart: TabsActivePart) => void;\n attendableId?: string;\n} & Pick<TabsPrimitive.TabsProps, 'orientation' | 'value'>;\n\nconst [TabsContextProvider, useTabsContext] = createContext<TabsContextValue>(TABS_NAME, {\n orientation: 'vertical',\n activePart: 'list',\n setActivePart: () => {},\n});\n\ntype TabsRootProps = ThemedClassName<TabsPrimitive.TabsProps> &\n Partial<\n Pick<TabsContextValue, 'activePart' | 'attendableId'> & {\n onActivePartChange: (nextActivePart: TabsActivePart) => void;\n defaultActivePart: TabsActivePart;\n }\n >;\n\nconst TabsRoot = forwardRef<HTMLDivElement, TabsRootProps>(\n (\n {\n children,\n classNames,\n activePart: propsActivePart,\n onActivePartChange,\n defaultActivePart,\n value: propsValue,\n onValueChange,\n defaultValue,\n orientation = 'vertical',\n activationMode = 'manual',\n attendableId,\n ...props\n },\n forwardedRef,\n ) => {\n // const tabsRoot = useRef<HTMLDivElement | null>(null);\n const tabsRoot = useForwardedRef(forwardedRef);\n\n // TODO(thure): Without these, we get Groupper/Mover `API used before initialization`, but why?\n const _1 = useArrowNavigationGroup();\n const _2 = useFocusableGroup();\n const [activePart = 'list', setActivePart] = useControllableState({\n prop: propsActivePart,\n onChange: onActivePartChange,\n defaultProp: defaultActivePart,\n });\n\n const [value, setValue] = useControllableState({\n prop: propsValue,\n onChange: onValueChange,\n defaultProp: defaultValue,\n });\n\n const handleValueChange = useCallback(\n (nextValue: string) => {\n setActivePart('panel');\n setValue(nextValue);\n },\n [value],\n );\n\n const { findFirstFocusable } = useFocusFinders();\n\n useLayoutEffect(() => {\n if (tabsRoot.current) {\n findFirstFocusable(tabsRoot.current)?.focus();\n }\n }, [activePart]);\n\n return (\n <TabsContextProvider\n orientation={orientation}\n activePart={activePart}\n setActivePart={setActivePart}\n value={value}\n attendableId={attendableId}\n >\n <TabsPrimitive.Root\n {...props}\n className={mx('overflow-hidden', classNames)}\n orientation={orientation}\n activationMode={activationMode}\n data-active={activePart}\n value={value}\n onValueChange={handleValueChange}\n ref={tabsRoot}\n >\n {children}\n </TabsPrimitive.Root>\n </TabsContextProvider>\n );\n },\n);\n\ntype TabsViewportProps = ThemedClassName<ComponentPropsWithoutRef<'div'>>;\n\nconst TabsViewport = ({ classNames, children, ...props }: TabsViewportProps) => {\n const { activePart } = useTabsContext('TabsViewport');\n return (\n <div {...props} data-active={activePart} className={mx(classNames)}>\n {children}\n </div>\n );\n};\n\ntype TabsTablistProps = ThemedClassName<TabsPrimitive.TabsListProps>;\n\nconst TabsTablist = ({ children, classNames, ...props }: TabsTablistProps) => {\n const { orientation } = useTabsContext('TabsTablist');\n return (\n <TabsPrimitive.List\n {...props}\n data-arrow-keys={orientation === 'vertical' ? 'up down' : 'left right'}\n className={mx(\n 'max-h-full w-full',\n // TODO(burdon): Should be embeddable inside Toolbar (if horizontal).\n orientation === 'vertical' ? 'overflow-y-auto' : 'flex p-1 gap-1 items-stretch justify-start overflow-x-auto',\n classNames,\n )}\n >\n {children}\n </TabsPrimitive.List>\n );\n};\n\nconst TabsBackButton = ({ onClick, classNames, ...props }: ButtonProps) => {\n const { setActivePart } = useTabsContext('TabsBackButton');\n const handleClick = useCallback(\n (event: MouseEvent<HTMLButtonElement>) => {\n setActivePart('list');\n return onClick?.(event);\n },\n [setActivePart, onClick],\n );\n\n return <Button {...props} classNames={['@md:hidden text-start', classNames]} onClick={handleClick} />;\n};\n\ntype TabsTabGroupHeadingProps = ThemedClassName<ComponentPropsWithoutRef<'h2'>>;\n\nconst TabsTabGroupHeading = ({ children, classNames, ...props }: ThemedClassName<TabsTabGroupHeadingProps>) => {\n return (\n <h2 {...props} className={mx('my-1 px-2 text-sm text-un-accent', classNames)}>\n {children}\n </h2>\n );\n};\n\ntype TabsTabProps = ButtonProps & Pick<TabsPrimitive.TabsTriggerProps, 'value'>;\n\nconst TabsTab = ({ value, classNames, children, onClick, ...props }: TabsTabProps) => {\n const { setActivePart, orientation, value: contextValue, attendableId } = useTabsContext('TabsTab');\n const { hasAttention } = useAttention(attendableId);\n\n const handleClick = useCallback(\n // NOTE: This handler is only called if the tab is *already active*.\n (event: MouseEvent<HTMLButtonElement>) => {\n setActivePart('panel');\n onClick?.(event);\n },\n [setActivePart, onClick],\n );\n\n return (\n <TabsPrimitive.Trigger value={value} asChild>\n <Button\n {...props}\n variant={\n orientation === 'horizontal' && contextValue === value ? (hasAttention ? 'primary' : 'default') : 'ghost'\n }\n classNames={[\n orientation === 'vertical' && 'block justify-start text-start w-full',\n orientation === 'vertical' && 'dx-selected',\n classNames,\n ]}\n onClick={handleClick}\n >\n {children}\n </Button>\n </TabsPrimitive.Trigger>\n );\n};\n\ntype TabsIconTabProps = IconButtonProps & Pick<TabsPrimitive.TabsTriggerProps, 'value'>;\n\nconst TabsIconTab = ({ value, classNames, onClick, ...props }: TabsIconTabProps) => {\n const { setActivePart, orientation, value: contextValue, attendableId } = useTabsContext('TabsTab');\n const { hasAttention } = useAttention(attendableId);\n\n // NOTE: This handler is only called if the tab is *already active*.\n const handleClick = useCallback(\n (event: MouseEvent<HTMLButtonElement>) => {\n setActivePart('panel');\n onClick?.(event);\n },\n [setActivePart, onClick],\n );\n\n return (\n <TabsPrimitive.Trigger value={value} asChild>\n <IconButton\n {...props}\n variant={\n orientation === 'horizontal' && contextValue === value ? (hasAttention ? 'primary' : 'default') : 'ghost'\n }\n classNames={[\n orientation === 'vertical' && 'justify-start text-start w-full',\n orientation === 'vertical' && 'dx-selected',\n classNames,\n ]}\n onClick={handleClick}\n />\n </TabsPrimitive.Trigger>\n );\n};\n\ntype TabsPanelProps = ThemedClassName<TabsPrimitive.TabsContentProps>;\n\nconst TabsPanel = ({ classNames, children, ...props }: TabsPanelProps) => {\n const { value: contextValue } = useTabsContext('TabsTab');\n return (\n <Activity mode={contextValue === props.value ? 'visible' : 'hidden'}>\n <TabsPrimitive.Content {...props} className={mx('p-0! dx-focus-ring-inset-over-all', classNames)}>\n {children}\n </TabsPrimitive.Content>\n </Activity>\n );\n};\n\ntype TabsTabPrimitiveProps = TabsPrimitive.TabsTriggerProps;\n\nexport const Tabs = {\n Root: TabsRoot,\n Tablist: TabsTablist,\n Tab: TabsTab,\n IconTab: TabsIconTab,\n TabPrimitive: TabsPrimitive.Trigger,\n TabGroupHeading: TabsTabGroupHeading,\n Panel: TabsPanel,\n BackButton: TabsBackButton,\n Viewport: TabsViewport,\n};\n\nexport type {\n TabsActivePart,\n TabsRootProps,\n TabsTablistProps,\n TabsTabProps,\n TabsTabPrimitiveProps,\n TabsTabGroupHeadingProps,\n TabsPanelProps,\n TabsViewportProps,\n};\n"],
|
|
5
|
+
"mappings": ";AAIA,SAASA,yBAAyBC,iBAAiBC,yBAAyB;AAC5E,SAASC,qBAAqB;AAC9B,YAAYC,mBAAmB;AAC/B,SAASC,4BAA4B;AACrC,OAAOC,SACLC,UAGAC,YACAC,aACAC,uBACK;AAEP,SACEC,QAEAC,YAGAC,uBACK;AACP,SAASC,oBAAoB;AAC7B,SAASC,UAAU;AAInB,IAAMC,YAAY;AAQlB,IAAM,CAACC,qBAAqBC,cAAAA,IAAkBf,cAAgCa,WAAW;EACvFG,aAAa;EACbC,YAAY;EACZC,eAAe,MAAA;EAAO;AACxB,CAAA;AAUA,IAAMC,WAAWd,2BACf,CACE,EACEe,UACAC,YACAJ,YAAYK,iBACZC,oBACAC,mBACAC,OAAOC,YACPC,eACAC,cACAZ,cAAc,YACda,iBAAiB,UACjBC,cACA,GAAGC,MAAAA,GAELC,iBAAAA;AAGA,QAAMC,WAAWvB,gBAAgBsB,YAAAA;AAGjC,QAAME,KAAKrC,wBAAAA;AACX,QAAMsC,KAAKpC,kBAAAA;AACX,QAAM,CAACkB,aAAa,QAAQC,aAAAA,IAAiBhB,qBAAqB;IAChEkC,MAAMd;IACNe,UAAUd;IACVe,aAAad;EACf,CAAA;AAEA,QAAM,CA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AAGtC,QAAM0B,cAAclD,YAClB,CAACmD,UAAAA;AACCvC,kBAAc,OAAA;AACdqC,cAAUE,KAAAA;EACZ,GACA;IAACvC;IAAeqC;GAAQ;AAG1B,SACE,sBAAA,cAAeQ,uBAAO;IAACtC;IAAcuC,SAAAA;KACnC,sBAAA,cAACvD,YAAAA;IACE,GAAGsB;IACJkC,SACEjD,gBAAgB,gBAAgB6C,iBAAiBpC,QAASqC,eAAe,YAAY,YAAa;IAEpGzC,YAAY;MACVL,gBAAgB,cAAc;MAC9BA,gBAAgB,cAAc;MAC9BK;;IAEFkC,SAASC;;AAIjB;AAIA,IAAMW,YAAY,CAAC,EAAE9C,YAAYD,UAAU,GAAGW,MAAAA,MAAuB;AACnE,QAAM,EAAEN,OAAOoC,aAAY,IAAK9C,eAAe,SAAA;AAC/C,SACE,sBAAA,cAACX,UAAAA;IAASgE,MAAMP,iBAAiB9B,MAAMN,QAAQ,YAAY;KACzD,sBAAA,cAAe4C,uBAAO;IAAE,GAAGtC;IAAOe,WAAWlC,GAAG,qCAAqCS,UAAAA;KAClFD,QAAAA,CAAAA;AAIT;AAIO,IAAMkD,OAAO;EAClBzB,MAAM1B;EACNoD,SAASpB;EACTqB,KAAKZ;EACLa,SAASP;EACTQ,cAA4BX;EAC5BY,iBAAiBjB;EACjBkB,OAAOT;EACPU,YAAYvB;EACZwB,UAAU7B;AACZ;",
|
|
6
|
+
"names": ["useArrowNavigationGroup", "useFocusFinders", "useFocusableGroup", "createContext", "TabsPrimitive", "useControllableState", "React", "Activity", "forwardRef", "useCallback", "useLayoutEffect", "Button", "IconButton", "useForwardedRef", "useAttention", "mx", "TABS_NAME", "TabsContextProvider", "useTabsContext", "orientation", "activePart", "setActivePart", "TabsRoot", "children", "classNames", "propsActivePart", "onActivePartChange", "defaultActivePart", "value", "propsValue", "onValueChange", "defaultValue", "activationMode", "attendableId", "props", "forwardedRef", "tabsRoot", "_1", "_2", "prop", "onChange", "defaultProp", "setValue", "handleValueChange", "nextValue", "findFirstFocusable", "current", "focus", "Root", "className", "data-active", "ref", "TabsViewport", "div", "TabsTablist", "List", "data-arrow-keys", "TabsBackButton", "onClick", "handleClick", "event", "TabsTabGroupHeading", "h2", "TabsTab", "contextValue", "hasAttention", "Trigger", "asChild", "variant", "TabsIconTab", "TabsPanel", "mode", "Content", "Tabs", "Tablist", "Tab", "IconTab", "TabPrimitive", "TabGroupHeading", "Panel", "BackButton", "Viewport"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/Tabs.tsx":{"bytes":
|
|
1
|
+
{"inputs":{"src/Tabs.tsx":{"bytes":25015,"imports":[{"path":"@fluentui/react-tabster","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-tabs","kind":"import-statement","external":true},{"path":"@radix-ui/react-use-controllable-state","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-attention","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true}],"format":"esm"},"src/index.ts":{"bytes":368,"imports":[{"path":"src/Tabs.tsx","kind":"import-statement","original":"./Tabs"}],"format":"esm"}},"outputs":{"dist/lib/browser/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":13455},"dist/lib/browser/index.mjs":{"imports":[{"path":"@fluentui/react-tabster","kind":"import-statement","external":true},{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"@radix-ui/react-tabs","kind":"import-statement","external":true},{"path":"@radix-ui/react-use-controllable-state","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-attention","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true}],"exports":["Tabs"],"entryPoint":"src/index.ts","inputs":{"src/Tabs.tsx":{"bytesInOutput":6152},"src/index.ts":{"bytesInOutput":0}},"bytes":6222}}}
|