@fvc/tabs 1.0.0-next-11b4ecc91aa3b77b53faa32e4cefb2e81c195686
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/CHANGELOG.md +11 -0
- package/README.md +294 -0
- package/dist/lib/index.js +6 -0
- package/dist/lib/tabs/src/Tabs.d.ts +7 -0
- package/dist/lib/tabs/src/components/DraggableTabNode.d.ts +3 -0
- package/dist/lib/tabs/src/hooks/useDraggableTabs.d.ts +21 -0
- package/dist/lib/tabs/src/index.d.ts +1 -0
- package/dist/lib/tabs/src/types/Tabs.types.d.ts +16 -0
- package/dist/lib/tabs/src/types/index.d.ts +1 -0
- package/package.json +47 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# @fvc/tabs
|
|
2
|
+
|
|
3
|
+
## 1.0.0-next-11b4ecc91aa3b77b53faa32e4cefb2e81c195686
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- d9bcdee: New @fvc/tabs package: pill-shaped Ant Design tabs matching Figma 27398-8819. Supports M/L sizes, 2-6 items, Toggles-sourced hover styling, controlled and uncontrolled modes, keyboard navigation, disabled items, icons, extra tab-bar content, horizontal/vertical orientation, typed CSS variables, and optional content panels.
|
|
8
|
+
|
|
9
|
+
### Minor Changes
|
|
10
|
+
|
|
11
|
+
- 6770e17: Add drag-and-drop tab reordering via the `draggable` and `onOrderChange` props, built on `@dnd-kit`.
|
package/README.md
ADDED
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
# @fvc/tabs
|
|
2
|
+
|
|
3
|
+
`@fvc/tabs` provides FE-VIS styled tabs on top of Ant Design. It preserves
|
|
4
|
+
Ant Design's tablist, tabpanel, keyboard, focus, and panel-mounting behavior
|
|
5
|
+
while applying the AVIS UI kit pill design.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
bun add @fvc/tabs
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Peer Dependencies
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
bun add react antd
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
The `draggable` prop additionally requires `@dnd-kit`:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
bun add @dnd-kit/core @dnd-kit/sortable @dnd-kit/utilities
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Import
|
|
26
|
+
|
|
27
|
+
```tsx
|
|
28
|
+
import { Tabs } from '@fvc/tabs';
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Quick Start
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
import { useState } from 'react';
|
|
35
|
+
import { Tabs } from '@fvc/tabs';
|
|
36
|
+
|
|
37
|
+
const items = [
|
|
38
|
+
{ key: 'overview', label: 'Overview', children: <Overview /> },
|
|
39
|
+
{ key: 'details', label: 'Details', children: <Details /> },
|
|
40
|
+
{ key: 'history', label: 'History', children: <History /> },
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
export function PageHeader() {
|
|
44
|
+
const [activeKey, setActiveKey] = useState('overview');
|
|
45
|
+
|
|
46
|
+
return <Tabs items={items} activeKey={activeKey} onChange={setActiveKey} />;
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Usage
|
|
51
|
+
|
|
52
|
+
### Controlled
|
|
53
|
+
|
|
54
|
+
`activeKey` remains the source of truth. Clicking another tab calls
|
|
55
|
+
`onChange`, but the visible tab changes only when the parent supplies a new
|
|
56
|
+
`activeKey`.
|
|
57
|
+
|
|
58
|
+
```tsx
|
|
59
|
+
<Tabs items={items} activeKey={activeKey} onChange={setActiveKey} />
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Uncontrolled
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
<Tabs items={items} defaultActiveKey="details" />
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Figma Size M (default)
|
|
69
|
+
|
|
70
|
+
Size M uses Roboto Bold at `14px/16px` with `8px` vertical and `12px`
|
|
71
|
+
horizontal padding. The browser computes the final item height from those
|
|
72
|
+
values.
|
|
73
|
+
|
|
74
|
+
```tsx
|
|
75
|
+
<Tabs items={items} size="middle" />
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Figma Size L
|
|
79
|
+
|
|
80
|
+
Size L uses Roboto Bold at `20px/20px` with `10px` vertical and `12px`
|
|
81
|
+
horizontal padding. The browser computes the final item height from those
|
|
82
|
+
values.
|
|
83
|
+
|
|
84
|
+
```tsx
|
|
85
|
+
<Tabs items={items} size="large" />
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Disabled Item
|
|
89
|
+
|
|
90
|
+
Disabled click and keyboard behavior remains owned by Ant Design.
|
|
91
|
+
|
|
92
|
+
```tsx
|
|
93
|
+
<Tabs
|
|
94
|
+
items={[
|
|
95
|
+
{ key: 'active', label: 'Active' },
|
|
96
|
+
{ key: 'locked', label: 'Locked', disabled: true },
|
|
97
|
+
]}
|
|
98
|
+
/>
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Icon
|
|
102
|
+
|
|
103
|
+
`icon` accepts any `ReactNode`. The package does not require an icon library.
|
|
104
|
+
|
|
105
|
+
```tsx
|
|
106
|
+
<Tabs
|
|
107
|
+
items={[
|
|
108
|
+
{ key: 'home', label: 'Home', icon: <HomeIcon /> },
|
|
109
|
+
{ key: 'history', label: 'History', icon: <HistoryIcon /> },
|
|
110
|
+
]}
|
|
111
|
+
/>
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### Extra Content
|
|
115
|
+
|
|
116
|
+
```tsx
|
|
117
|
+
<Tabs
|
|
118
|
+
items={items}
|
|
119
|
+
tabBarExtraContent={{
|
|
120
|
+
left: <span>Filters</span>,
|
|
121
|
+
right: <button type="button">Add</button>,
|
|
122
|
+
}}
|
|
123
|
+
/>
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Without Content Panels
|
|
127
|
+
|
|
128
|
+
Omit `children` when the active key controls content outside this component.
|
|
129
|
+
|
|
130
|
+
```tsx
|
|
131
|
+
<Tabs
|
|
132
|
+
items={[
|
|
133
|
+
{ key: 'day', label: 'Day' },
|
|
134
|
+
{ key: 'week', label: 'Week' },
|
|
135
|
+
{ key: 'month', label: 'Month' },
|
|
136
|
+
]}
|
|
137
|
+
activeKey={range}
|
|
138
|
+
onChange={setRange}
|
|
139
|
+
/>
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
### Draggable
|
|
143
|
+
|
|
144
|
+
```tsx
|
|
145
|
+
const [items, setItems] = useState(initialItems);
|
|
146
|
+
|
|
147
|
+
<Tabs items={items} draggable onOrderChange={setItems} />;
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Enables drag-and-drop reordering via [`@dnd-kit`](https://dndkit.com/) —
|
|
151
|
+
the same approach as the
|
|
152
|
+
[official Ant Design drag-and-drop tabs example](https://5x.ant.design/components/tabs).
|
|
153
|
+
`onOrderChange` is called with the reordered `TabItem[]` after each drop; the
|
|
154
|
+
consumer owns committing that order back into `items`.
|
|
155
|
+
|
|
156
|
+
## Props
|
|
157
|
+
|
|
158
|
+
| Prop | Type | Default | Description |
|
|
159
|
+
| ------------------------ | ------------------------------------------------------ | ---------- | ------------------------------------------------ |
|
|
160
|
+
| `items` | `AntTabsProps['items']` | - | Required tab descriptors. |
|
|
161
|
+
| `activeKey` | `string` | - | Controlled active key. |
|
|
162
|
+
| `defaultActiveKey` | `string` | first item | Initial uncontrolled active key. |
|
|
163
|
+
| `onChange` | `(key: string) => void` | - | Called with the selected key. |
|
|
164
|
+
| `size` | `AntTabsProps['size']` | `middle` | Uses Ant Design size names. |
|
|
165
|
+
| `tabBarExtraContent` | `ReactNode \| { left?: ReactNode; right?: ReactNode }` | - | Content around the tab list. |
|
|
166
|
+
| `destroyInactiveTabPane` | `boolean` | `false` | Removes inactive panels when enabled. |
|
|
167
|
+
| `draggable` | `boolean` | `false` | Enables drag-and-drop reordering via `@dnd-kit`. |
|
|
168
|
+
| `onOrderChange` | `(items: TabItem[]) => void` | - | Called with the reordered items after each drop. |
|
|
169
|
+
| `className` | `string` | - | Additional root class. |
|
|
170
|
+
| `style` | `TabsStyle` | - | Root styles with typed `--tabs-*` variables. |
|
|
171
|
+
| `testId` | `string` | - | Root `data-testid`. |
|
|
172
|
+
|
|
173
|
+
### TabItem
|
|
174
|
+
|
|
175
|
+
| Field | Type | Description |
|
|
176
|
+
| ---------- | ----------- | ------------------------------- |
|
|
177
|
+
| `key` | `string` | Required unique key. |
|
|
178
|
+
| `label` | `ReactNode` | Required label. |
|
|
179
|
+
| `children` | `ReactNode` | Optional panel content. |
|
|
180
|
+
| `disabled` | `boolean` | Prevents selection. |
|
|
181
|
+
| `icon` | `ReactNode` | Optional icon before the label. |
|
|
182
|
+
|
|
183
|
+
## Panel Mounting
|
|
184
|
+
|
|
185
|
+
Inactive panels remain mounted by default (`destroyInactiveTabPane=false`).
|
|
186
|
+
This preserves form values and component state but also retains subscriptions
|
|
187
|
+
and expensive resources. Set `destroyInactiveTabPane` when cleanup is more
|
|
188
|
+
important than state preservation. Lazy code splitting remains the consumer's
|
|
189
|
+
responsibility.
|
|
190
|
+
|
|
191
|
+
## Theming
|
|
192
|
+
|
|
193
|
+
All design values are declared in `src/styles/variables.scss`, matching the
|
|
194
|
+
style-file layout used by `@fvc/input`.
|
|
195
|
+
|
|
196
|
+
Inline overrides are type-safe:
|
|
197
|
+
|
|
198
|
+
```tsx
|
|
199
|
+
<Tabs
|
|
200
|
+
items={items}
|
|
201
|
+
style={{
|
|
202
|
+
'--tabs-item-active-bg-color': '#24568a',
|
|
203
|
+
'--tabs-item-hover-bg-color': '#f2f2f2',
|
|
204
|
+
}}
|
|
205
|
+
/>
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
### Container
|
|
209
|
+
|
|
210
|
+
| Variable | Default |
|
|
211
|
+
| ---------------------- | ------------------ |
|
|
212
|
+
| `--tabs-bg-color` | `var(--neutral-0)` |
|
|
213
|
+
| `--tabs-border-width` | `1px` |
|
|
214
|
+
| `--tabs-border-color` | `var(--blue-250)` |
|
|
215
|
+
| `--tabs-border-radius` | `18px` |
|
|
216
|
+
|
|
217
|
+
### Item
|
|
218
|
+
|
|
219
|
+
| Variable | Default |
|
|
220
|
+
| --------------------------- | ------------------- |
|
|
221
|
+
| `--tabs-item-padding-x` | `9px` |
|
|
222
|
+
| `--tabs-item-border-width` | `3px` |
|
|
223
|
+
| `--tabs-item-border-color` | `transparent` |
|
|
224
|
+
| `--tabs-item-border-radius` | `32px` |
|
|
225
|
+
| `--tabs-item-text-color` | `var(--black-1000)` |
|
|
226
|
+
| `--tabs-item-fw` | `700` |
|
|
227
|
+
|
|
228
|
+
### Selected Item
|
|
229
|
+
|
|
230
|
+
| Variable | Default |
|
|
231
|
+
| --------------------------------- | --------------------------- |
|
|
232
|
+
| `--tabs-item-active-bg-color` | `var(--blue-400)` |
|
|
233
|
+
| `--tabs-item-active-text-color` | `var(--white-text-color-0)` |
|
|
234
|
+
| `--tabs-item-active-border-color` | `var(--gray-100)` |
|
|
235
|
+
|
|
236
|
+
### Hover Item
|
|
237
|
+
|
|
238
|
+
Hover is the only state sourced from the adjacent Figma `<Toggles />`
|
|
239
|
+
component because the Figma `<Tabs />` variants do not expose a hover state.
|
|
240
|
+
|
|
241
|
+
| Variable | Default |
|
|
242
|
+
| -------------------------------- | ----------------------------- |
|
|
243
|
+
| `--tabs-item-hover-bg-color` | `var(--gray-50)` (`#f2f2f2`) |
|
|
244
|
+
| `--tabs-item-hover-border-color` | `var(--gray-100)` (`#fafafa`) |
|
|
245
|
+
|
|
246
|
+
### Size M
|
|
247
|
+
|
|
248
|
+
| Variable | Default |
|
|
249
|
+
| ------------------------------ | -------- |
|
|
250
|
+
| `--tabs-font-family` | `Roboto` |
|
|
251
|
+
| `--tabs-middle-size-fz` | `14px` |
|
|
252
|
+
| `--tabs-middle-size-lh` | `16px` |
|
|
253
|
+
| `--tabs-middle-size-padding-y` | `4px` |
|
|
254
|
+
|
|
255
|
+
The CSS padding values compensate for the real `3px` item border and `1px`
|
|
256
|
+
container border. This preserves Figma's visual `8px` padding and `32px`
|
|
257
|
+
overall height.
|
|
258
|
+
|
|
259
|
+
### Size L
|
|
260
|
+
|
|
261
|
+
| Variable | Default |
|
|
262
|
+
| ----------------------------- | ------- |
|
|
263
|
+
| `--tabs-large-size-fz` | `20px` |
|
|
264
|
+
| `--tabs-large-size-lh` | `20px` |
|
|
265
|
+
| `--tabs-large-size-padding-y` | `6px` |
|
|
266
|
+
|
|
267
|
+
The `7px` CSS padding preserves Figma's visual `10px` padding and `40px`
|
|
268
|
+
overall height after the real borders are included.
|
|
269
|
+
|
|
270
|
+
## Figma Mapping
|
|
271
|
+
|
|
272
|
+
- [Tabs variants: M/L and counts 2-6](https://www.figma.com/design/mIoVgiLS8kZgKfqfUoL9Pa/AVIS-UI-kit-new?node-id=27398-8819&m=dev)
|
|
273
|
+
- Hover only: adjacent `<Toggles />` node `27384:17118` / `27384:17120`
|
|
274
|
+
|
|
275
|
+
The transparent base item border reserves the same space used by the selected
|
|
276
|
+
and hover strokes. With the Figma `Secondary` label, two M items remain
|
|
277
|
+
`182x32` and two L items remain `272x40`.
|
|
278
|
+
|
|
279
|
+
## Accessibility
|
|
280
|
+
|
|
281
|
+
The wrapper keeps Ant Design's `tablist`, `tab`, and `tabpanel` roles,
|
|
282
|
+
`aria-selected`, `aria-controls`, `aria-labelledby`, disabled handling,
|
|
283
|
+
keyboard navigation, and focus-visible behavior. Horizontal tabs use
|
|
284
|
+
Left/Right; Home/End jump to the edges; Enter/Space activate the
|
|
285
|
+
keyboard-focused tab.
|
|
286
|
+
|
|
287
|
+
## Development
|
|
288
|
+
|
|
289
|
+
```bash
|
|
290
|
+
bun run lint
|
|
291
|
+
bun run type-check
|
|
292
|
+
bun run test
|
|
293
|
+
bun run build
|
|
294
|
+
```
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import{Tabs as t}from"antd";import e,{cloneElement as a,useCallback as n,forwardRef as r}from"react";import{useSensor as s,PointerSensor as o,DndContext as i,closestCenter as b}from"@dnd-kit/core";import{useSortable as c,SortableContext as d,horizontalListSortingStrategy as l,arrayMove as v}from"@dnd-kit/sortable";import{CSS as f}from"@dnd-kit/utilities";function m(t,e){var a={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(a[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(n=Object.getOwnPropertySymbols(t);r<n.length;r++)e.indexOf(n[r])<0&&Object.prototype.propertyIsEnumerable.call(t,n[r])&&(a[n[r]]=t[n[r]])}return a}function p(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}"function"==typeof SuppressedError&&SuppressedError;var g,u={exports:{}};
|
|
2
|
+
/*!
|
|
3
|
+
Copyright (c) 2018 Jed Watson.
|
|
4
|
+
Licensed under the MIT License (MIT), see
|
|
5
|
+
http://jedwatson.github.io/classnames
|
|
6
|
+
*/var h,y=p((g||(g=1,h=u,function(){var t={}.hasOwnProperty;function e(){for(var t="",e=0;e<arguments.length;e++){var r=arguments[e];r&&(t=n(t,a(r)))}return t}function a(a){if("string"==typeof a||"number"==typeof a)return a;if("object"!=typeof a)return"";if(Array.isArray(a))return e.apply(null,a);if(a.toString!==Object.prototype.toString&&!a.toString.toString().includes("[native code]"))return a.toString();var r="";for(var s in a)t.call(a,s)&&a[s]&&(r=n(r,s));return r}function n(t,e){return e?t?t+" "+e:t+e:t}h.exports?(e.default=e,h.exports=e):window.classNames=e}()),u.exports));const x=t=>{var{className:e}=t,n=m(t,["className"]);const{attributes:r,listeners:s,setNodeRef:o,transform:i,transition:b}=c({id:n["data-node-key"]}),d=Object.assign(Object.assign({},n.style),{transform:f.Translate.toString(i),transition:b,cursor:"move"});return a(n.children,Object.assign(Object.assign({ref:o,style:d},r),s))},T={activationConstraint:{distance:10}},O=({items:t,onOrderChange:a})=>{const r=s(o,T),c=n(({active:e,over:n})=>{const r=((t,e,a)=>{if(!t||e===a)return null;const n=t.findIndex(t=>t.key===e),r=t.findIndex(t=>t.key===a);return-1===n||-1===r?null:v(t,n,r)})(t,e.id,null==n?void 0:n.id);r&&(null==a||a(r))},[t,a]);return n((a,n)=>e.createElement(i,{sensors:[r],onDragEnd:c,collisionDetection:b},e.createElement(d,{items:(null!=t?t:[]).map(t=>t.key),strategy:l},e.createElement(n,Object.assign({},a),t=>e.createElement(x,Object.assign({},t.props,{key:t.key}),t)))),[r,c,t])};!function(t,e){void 0===e&&(e={});var a=e.insertAt;if("undefined"!=typeof document){var n=document.head||document.getElementsByTagName("head")[0],r=document.createElement("style");r.type="text/css","top"===a&&n.firstChild?n.insertBefore(r,n.firstChild):n.appendChild(r),r.styleSheet?r.styleSheet.cssText=t:r.appendChild(document.createTextNode(t))}}("@charset \"UTF-8\";\n:root {\n /* Tabs Container Variables - Figma Tabs */\n --tabs-bg-color: var(--neutral-0);\n --tabs-border-width: 1px;\n --tabs-border-color: var(--blue-250);\n --tabs-border-radius: 18px;\n /* Tabs Item Variables - Figma Tabs */\n /* Figma measures padding from the frame edge and draws the 3px stroke inside\n it, so the CSS padding is Figma's 12px minus the border width. */\n --tabs-item-padding-x: 9px;\n --tabs-item-border-width: 3px;\n --tabs-item-border-color: transparent;\n --tabs-item-border-radius: 32px;\n --tabs-item-text-color: var(--black-1000);\n --tabs-item-fw: 700;\n /* Tabs Active State - Figma Tabs */\n --tabs-item-active-bg-color: var(--blue-400);\n --tabs-item-active-text-color: var(--white-text-color-0);\n --tabs-item-active-border-color: var(--gray-100);\n /* Tabs Hover State - sourced from the adjacent Figma Toggles component;\n the Figma Tabs variants themselves do not expose a hover state. */\n --tabs-item-hover-bg-color: var(--gray-50);\n --tabs-item-hover-border-color: var(--gray-100);\n /* Tabs Size Variables - Figma Tabs */\n --tabs-font-family: 'Roboto', sans-serif;\n --tabs-middle-size-fz: 14px;\n --tabs-middle-size-lh: 16px;\n --tabs-middle-size-padding-y: 4px;\n --tabs-large-size-fz: 20px;\n --tabs-large-size-lh: 20px;\n --tabs-large-size-padding-y: 6px;\n}\n.fvc-tabs {\n /* NAV */\n}\n.fvc-tabs > .fvc-tabs-nav {\n display: flex;\n align-items: center;\n overflow: clip;\n border: var(--tabs-border-width) solid var(--tabs-border-color);\n border-radius: var(--tabs-border-radius);\n background: var(--tabs-bg-color);\n}\n.fvc-tabs > .fvc-tabs-nav::before {\n display: none;\n}\n.fvc-tabs {\n /* NAV WRAP */\n}\n.fvc-tabs .fvc-tabs-nav-wrap::before, .fvc-tabs .fvc-tabs-nav-wrap::after {\n display: none;\n}\n.fvc-tabs {\n /* NAV LIST */\n}\n.fvc-tabs .fvc-tabs-nav-list {\n display: flex;\n align-items: center;\n}\n.fvc-tabs {\n /* TAB */\n}\n.fvc-tabs .fvc-tabs-tab {\n padding: var(--tabs-middle-size-padding-y) var(--tabs-item-padding-x);\n display: inline-flex;\n align-items: center;\n overflow: clip;\n margin: 0;\n border: var(--tabs-item-border-width) solid var(--tabs-item-border-color);\n border-radius: var(--tabs-item-border-radius);\n}\n.fvc-tabs .fvc-tabs-tab + .fvc-tabs-tab {\n margin-inline-start: 0;\n}\n.fvc-tabs {\n /* TAB LABEL */\n}\n.fvc-tabs .fvc-tabs-tab-btn {\n font-family: var(--tabs-font-family);\n font-size: var(--tabs-middle-size-fz);\n line-height: var(--tabs-middle-size-lh);\n color: var(--tabs-item-text-color);\n font-weight: var(--tabs-item-fw);\n letter-spacing: 0;\n}\n.fvc-tabs {\n /* ACTIVE */\n}\n.fvc-tabs .fvc-tabs-tab.fvc-tabs-tab-active {\n background: var(--tabs-item-active-bg-color);\n border-color: var(--tabs-item-active-border-color);\n}\n.fvc-tabs .fvc-tabs-tab.fvc-tabs-tab-active .fvc-tabs-tab-btn {\n color: var(--tabs-item-active-text-color);\n}\n.fvc-tabs {\n /* HOVER — sourced from the adjacent Figma Toggles component; the Figma\n Tabs variants themselves expose no hover state. antd only recolors the\n label on hover, and our own unconditional tab-btn rule above already\n pins that color, so this only needs to add the background and stroke. */\n}\n.fvc-tabs .fvc-tabs-tab:not(.fvc-tabs-tab-active):not(.fvc-tabs-tab-disabled):hover {\n background: var(--tabs-item-hover-bg-color);\n border-color: var(--tabs-item-hover-border-color);\n}\n.fvc-tabs {\n /* INK BAR */\n}\n.fvc-tabs .fvc-tabs-ink-bar {\n display: none;\n}\n.fvc-tabs {\n /* HORIZONTAL */\n}\n.fvc-tabs--horizontal > .fvc-tabs-nav {\n margin: 0;\n}\n.fvc-tabs-large > .fvc-tabs-nav .fvc-tabs-tab {\n padding: var(--tabs-large-size-padding-y) var(--tabs-item-padding-x);\n}\n.fvc-tabs-large .fvc-tabs-tab-btn {\n font-family: var(--tabs-font-family);\n font-size: var(--tabs-large-size-fz);\n line-height: var(--tabs-large-size-lh);\n}");const w=r((a,n)=>{var{className:r,testId:s,draggable:o,onOrderChange:i,items:b,renderTabBar:c}=a,d=m(a,["className","testId","draggable","onOrderChange","items","renderTabBar"]);const l=y(r),v=O({items:b,onOrderChange:i});return e.createElement(t,Object.assign({ref:n,prefixCls:"fvc-tabs",items:b,className:l,"data-testid":s,renderTabBar:o?v:c},d))});w.displayName="Tabs";export{w as Tabs};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import './styles/Tabs.scss';
|
|
3
|
+
export declare const Tabs: React.ForwardRefExoticComponent<Omit<import("antd").TabsProps, "prefixCls" | "tabPosition"> & {
|
|
4
|
+
testId?: string;
|
|
5
|
+
draggable?: boolean;
|
|
6
|
+
onOrderChange?: (items: import("./types").TabItem[]) => void;
|
|
7
|
+
} & React.RefAttributes<import("antd/es/tabs").TabsRef>>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { UniqueIdentifier } from '@dnd-kit/core';
|
|
2
|
+
import type { TabItem, TabsProps, UseDraggableTabsOptions } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the reordered item list for a completed drag, or `null` when the
|
|
5
|
+
* drag should not change anything.
|
|
6
|
+
*
|
|
7
|
+
* Returns `null` when the tab was dropped on itself, when there are no items,
|
|
8
|
+
* and when either end of the drag does not resolve to a known item — the last
|
|
9
|
+
* case covers `over` being `null`, which dnd-kit reports when the pointer is
|
|
10
|
+
* released outside every droppable.
|
|
11
|
+
*/
|
|
12
|
+
export declare const getReorderedItems: (items: TabsProps["items"], activeId: UniqueIdentifier, overId?: UniqueIdentifier) => TabItem[] | null;
|
|
13
|
+
/**
|
|
14
|
+
* Builds the `renderTabBar` implementation that makes the tab bar sortable.
|
|
15
|
+
*
|
|
16
|
+
* The returned value is passed straight to Ant Design's `renderTabBar`, so the
|
|
17
|
+
* caller decides whether drag-and-drop is active by choosing between this and
|
|
18
|
+
* its own renderer. Hook order stays stable either way — the hook is always
|
|
19
|
+
* called, only its result may go unused.
|
|
20
|
+
*/
|
|
21
|
+
export declare const useDraggableTabs: ({ items, onOrderChange, }: UseDraggableTabsOptions) => NonNullable<TabsProps["renderTabBar"]>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Tabs } from './Tabs';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Tabs as DefaultTabs, type TabsProps as DefaultTabsProps } from 'antd';
|
|
2
|
+
import type { ElementRef, HTMLAttributes } from 'react';
|
|
3
|
+
export type TabsRef = ElementRef<typeof DefaultTabs>;
|
|
4
|
+
export type TabItem = NonNullable<DefaultTabsProps['items']>[number];
|
|
5
|
+
export type TabsProps = Omit<DefaultTabsProps, 'prefixCls' | 'tabPosition'> & {
|
|
6
|
+
testId?: string;
|
|
7
|
+
draggable?: boolean;
|
|
8
|
+
onOrderChange?: (items: TabItem[]) => void;
|
|
9
|
+
};
|
|
10
|
+
export interface DraggableTabNodeProps extends HTMLAttributes<HTMLDivElement> {
|
|
11
|
+
'data-node-key': string;
|
|
12
|
+
}
|
|
13
|
+
export interface UseDraggableTabsOptions {
|
|
14
|
+
items: TabsProps['items'];
|
|
15
|
+
onOrderChange: TabsProps['onOrderChange'];
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Tabs.types';
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fvc/tabs",
|
|
3
|
+
"version": "1.0.0-next-11b4ecc91aa3b77b53faa32e4cefb2e81c195686",
|
|
4
|
+
"main": "./dist/lib/index.js",
|
|
5
|
+
"types": "./dist/lib/tabs/src/index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"dist/lib/index.js",
|
|
8
|
+
"dist/lib/tabs",
|
|
9
|
+
"package.json",
|
|
10
|
+
"CHANGELOG.md"
|
|
11
|
+
],
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"import": "./dist/lib/index.js",
|
|
15
|
+
"types": "./dist/lib/tabs/src/index.d.ts"
|
|
16
|
+
},
|
|
17
|
+
"./types": {
|
|
18
|
+
"types": "./dist/lib/tabs/src/types/index.d.ts"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "rollup -c ./rollup.config.mjs",
|
|
23
|
+
"clean": "rm -rf dist && rm -rf .rollup.cache && rm -rf .turbo",
|
|
24
|
+
"lint": "eslint --config ../../eslint.config.js \"src/**/*.{ts,tsx}\"",
|
|
25
|
+
"lint:fix": "eslint --config ../../eslint.config.js \"src/**/*.{ts,tsx}\" --fix",
|
|
26
|
+
"format": "prettier --write \"src/**/*.{ts,tsx}\"",
|
|
27
|
+
"type-check": "tsc --noEmit",
|
|
28
|
+
"test": "bun test --preload ../../tests/happydom.ts --preload ../../tests/testing-library.tsx"
|
|
29
|
+
},
|
|
30
|
+
"keywords": [
|
|
31
|
+
"react",
|
|
32
|
+
"react-component",
|
|
33
|
+
"fvc",
|
|
34
|
+
"fe-vis-core",
|
|
35
|
+
"ui",
|
|
36
|
+
"tabs",
|
|
37
|
+
"design-system",
|
|
38
|
+
"antd"
|
|
39
|
+
],
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"react": "^18.0.0",
|
|
42
|
+
"antd": "^5.0.0",
|
|
43
|
+
"@dnd-kit/core": "^6.3.1",
|
|
44
|
+
"@dnd-kit/sortable": "^10.0.0",
|
|
45
|
+
"@dnd-kit/utilities": "^3.2.2"
|
|
46
|
+
}
|
|
47
|
+
}
|