react-overflow-tabs 1.0.0
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 +21 -0
- package/README.md +228 -0
- package/dist/index.d.mts +27 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.js +1 -0
- package/dist/index.mjs +1 -0
- package/package.json +79 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Baver Bozdağ
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
# react-overflow-tabs
|
|
2
|
+
|
|
3
|
+
A headless React hook to gracefully collapse overflowing tabs into a dropdown menu.
|
|
4
|
+
Works with any UI framework (Tailwind, Bootstrap, MUI, custom CSS).
|
|
5
|
+
|
|
6
|
+
[](https://www.npmjs.com/package/react-overflow-tabs)
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
|
|
9
|
+
A lightweight React hook for responsive tab navigation with automatic overflow handling.
|
|
10
|
+
Perfect for building tab systems, breadcrumbs, or step navigators.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## 🎥 Demo
|
|
15
|
+
|
|
16
|
+

|
|
17
|
+
|
|
18
|
+
---
|
|
19
|
+
|
|
20
|
+
## ✨ Features
|
|
21
|
+
|
|
22
|
+
- 🔗 **Headless** – no styles, works with your own UI
|
|
23
|
+
- 📏 **Responsive** – detects tab overflow using `IntersectionObserver`
|
|
24
|
+
- ⚡ **Lightweight** – tree-shakeable, no dependencies
|
|
25
|
+
- 🎯 **Framework-agnostic** – use with Tailwind, Bootstrap, MUI, or custom CSS
|
|
26
|
+
|
|
27
|
+
---
|
|
28
|
+
|
|
29
|
+
## 📦 Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
npm install react-overflow-tabs
|
|
33
|
+
# or
|
|
34
|
+
yarn add react-overflow-tabs
|
|
35
|
+
# or
|
|
36
|
+
pnpm add react-overflow-tabs
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Peer dependencies:
|
|
40
|
+
|
|
41
|
+
- `react >=18 <20`
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## 🚀 Quickstart
|
|
46
|
+
|
|
47
|
+
⚠️ Do not use `display: none` or move elements out of flow with `position: absolute;`
|
|
48
|
+
Both will cause `IntersectionObserver` to stop tracking the element. Instead:
|
|
49
|
+
|
|
50
|
+
- Use `visibility: hidden`
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
import { useRef } from "react";
|
|
54
|
+
import { useOverflowTabs } from "react-overflow-tabs";
|
|
55
|
+
|
|
56
|
+
const Example = () => {
|
|
57
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
58
|
+
|
|
59
|
+
const { overflowKeys, isOverflowing } = useOverflowTabs({
|
|
60
|
+
container: containerRef,
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const KEYS = [
|
|
64
|
+
"home-1",
|
|
65
|
+
"profile-1",
|
|
66
|
+
"settings-1",
|
|
67
|
+
"home-2",
|
|
68
|
+
"profile-2",
|
|
69
|
+
"settings-2",
|
|
70
|
+
"home-3",
|
|
71
|
+
"profile-3",
|
|
72
|
+
"settings-3",
|
|
73
|
+
"home-4",
|
|
74
|
+
"profile-4",
|
|
75
|
+
"settings-4",
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
return (
|
|
79
|
+
<div
|
|
80
|
+
ref={containerRef}
|
|
81
|
+
style={{
|
|
82
|
+
display: "flex",
|
|
83
|
+
gap: 12,
|
|
84
|
+
overflow: "hidden",
|
|
85
|
+
}}
|
|
86
|
+
>
|
|
87
|
+
{KEYS.map((k) => (
|
|
88
|
+
<button
|
|
89
|
+
key={k}
|
|
90
|
+
data-overflow-key={k}
|
|
91
|
+
style={{
|
|
92
|
+
whiteSpace: "nowrap",
|
|
93
|
+
visibility: overflowKeys.includes(k) ? "hidden" : "visible",
|
|
94
|
+
}}
|
|
95
|
+
>
|
|
96
|
+
{k}
|
|
97
|
+
</button>
|
|
98
|
+
))}
|
|
99
|
+
{isOverflowing && (
|
|
100
|
+
<div style={{ marginLeft: "auto" }}>
|
|
101
|
+
<div
|
|
102
|
+
style={{
|
|
103
|
+
position: "absolute",
|
|
104
|
+
marginTop: 40,
|
|
105
|
+
right: 4,
|
|
106
|
+
border: "1px solid red",
|
|
107
|
+
padding: 6,
|
|
108
|
+
}}
|
|
109
|
+
>
|
|
110
|
+
{overflowKeys.map((key) => (
|
|
111
|
+
<div key={key} style={{ padding: "6px 10px", whiteSpace: "nowrap" }}>
|
|
112
|
+
{key}
|
|
113
|
+
</div>
|
|
114
|
+
))}
|
|
115
|
+
</div>
|
|
116
|
+
</div>
|
|
117
|
+
)}
|
|
118
|
+
</div>
|
|
119
|
+
);
|
|
120
|
+
};
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
---
|
|
124
|
+
|
|
125
|
+
## ⚙️ API
|
|
126
|
+
|
|
127
|
+
### `useOverflowTabs(options: IOverflowTabsOptions): IOverflowState`
|
|
128
|
+
|
|
129
|
+
#### Options (`IOverflowTabsOptions`)
|
|
130
|
+
|
|
131
|
+
| Option | Type | Default | Description |
|
|
132
|
+
| ------------- | ----------------------------------------- | ----------------------- | --------------------------------------------------------------------------- |
|
|
133
|
+
| `container` | `RefObject<HTMLElement>` \| `HTMLElement` | **required** | The container element to observe. |
|
|
134
|
+
| `tabSelector` | `string` | `"[data-overflow-key]"` | Selector for tab elements. Each tab must have a unique `data-overflow-key`. |
|
|
135
|
+
| `disabled` | `boolean` | `false` | Temporarily disable overflow tracking. |
|
|
136
|
+
|
|
137
|
+
#### Return (`IOverflowState`)
|
|
138
|
+
|
|
139
|
+
| Key | Type | Description |
|
|
140
|
+
| --------------- | ---------- | ------------------------------------------------ |
|
|
141
|
+
| `visibleKeys` | `string[]` | Keys of tabs currently visible in the container. |
|
|
142
|
+
| `overflowKeys` | `string[]` | Keys of tabs pushed into overflow (hidden). |
|
|
143
|
+
| `isOverflowing` | `boolean` | Whether overflow is currently happening. |
|
|
144
|
+
|
|
145
|
+
---
|
|
146
|
+
|
|
147
|
+
## 🛠 Example with Tailwind
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
import { useRef } from "react";
|
|
151
|
+
import useOverflowTabs from "./useOverflowTabs";
|
|
152
|
+
|
|
153
|
+
const Example = () => {
|
|
154
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
155
|
+
|
|
156
|
+
const { overflowKeys, isOverflowing } = useOverflowTabs({
|
|
157
|
+
container: containerRef,
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
const KEYS = [
|
|
161
|
+
"home-1",
|
|
162
|
+
"profile-1",
|
|
163
|
+
"settings-1",
|
|
164
|
+
"home-2",
|
|
165
|
+
"profile-2",
|
|
166
|
+
"settings-2",
|
|
167
|
+
"home-3",
|
|
168
|
+
"profile-3",
|
|
169
|
+
"settings-3",
|
|
170
|
+
"home-4",
|
|
171
|
+
"profile-4",
|
|
172
|
+
"settings-4",
|
|
173
|
+
];
|
|
174
|
+
|
|
175
|
+
return (
|
|
176
|
+
<div ref={containerRef} className="flex gap-3 overflow-hidden">
|
|
177
|
+
{KEYS.map((k) => (
|
|
178
|
+
<button
|
|
179
|
+
key={k}
|
|
180
|
+
data-overflow-key={k}
|
|
181
|
+
className={"p-2 whitespace-nowrap border" + (overflowKeys.includes(k) ? " invisible" : "")}
|
|
182
|
+
>
|
|
183
|
+
{k}
|
|
184
|
+
</button>
|
|
185
|
+
))}
|
|
186
|
+
|
|
187
|
+
{isOverflowing && (
|
|
188
|
+
<div className="ml-auto">
|
|
189
|
+
<div className="absolute right-4 mt-14 border">
|
|
190
|
+
{overflowKeys.map((key) => (
|
|
191
|
+
<div key={key} className="p-2 whitespace-nowrap">
|
|
192
|
+
{key}
|
|
193
|
+
</div>
|
|
194
|
+
))}
|
|
195
|
+
</div>
|
|
196
|
+
</div>
|
|
197
|
+
)}
|
|
198
|
+
</div>
|
|
199
|
+
);
|
|
200
|
+
};
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
---
|
|
204
|
+
|
|
205
|
+
## 📖 Notes
|
|
206
|
+
|
|
207
|
+
- Uses **`IntersectionObserver`** under the hood → supported in modern browsers.
|
|
208
|
+
- `threshold: 0.999` by default → requires _full visibility_ to count as visible.
|
|
209
|
+
- Works with **RTL** layouts, as it only tracks visibility.
|
|
210
|
+
|
|
211
|
+
---
|
|
212
|
+
|
|
213
|
+
## 🤝 Contributing
|
|
214
|
+
|
|
215
|
+
Contributions, issues, and feature requests are welcome!
|
|
216
|
+
Feel free to open an [issue](https://github.com/bawerbozdag/react-overflow-tabs/issues) or submit a PR.
|
|
217
|
+
|
|
218
|
+
1. Fork the repo
|
|
219
|
+
2. Create your feature branch (`git checkout -b feature/my-feature`)
|
|
220
|
+
3. Commit your changes (`git commit -m 'Add some feature'`)
|
|
221
|
+
4. Push to the branch (`git push origin feature/my-feature`)
|
|
222
|
+
5. Open a Pull Request
|
|
223
|
+
|
|
224
|
+
---
|
|
225
|
+
|
|
226
|
+
## 📜 License
|
|
227
|
+
|
|
228
|
+
MIT © [Baver Bozdağ](https://github.com/bawerbozdag)
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
|
|
3
|
+
type TOverflowDirection = "start" | "end";
|
|
4
|
+
interface IOverflowTabsOptions<T extends HTMLElement = HTMLElement> {
|
|
5
|
+
/**
|
|
6
|
+
* Container element:
|
|
7
|
+
* - React ref (current: T | null)
|
|
8
|
+
* - or direct element (via query selector)
|
|
9
|
+
*/
|
|
10
|
+
container: RefObject<T | null> | T;
|
|
11
|
+
/**
|
|
12
|
+
* Attribute name for tabs.
|
|
13
|
+
* Each tab must have this attribute with a unique value.
|
|
14
|
+
* Default: "data-overflow-key" or "[data-overflow-key]"
|
|
15
|
+
*/
|
|
16
|
+
tabSelector?: string;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
}
|
|
19
|
+
interface IOverflowState {
|
|
20
|
+
visibleKeys: string[];
|
|
21
|
+
overflowKeys: string[];
|
|
22
|
+
isOverflowing: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
declare const useOverflowTabs: <T extends HTMLElement = HTMLElement>(options: IOverflowTabsOptions<T>) => IOverflowState;
|
|
26
|
+
|
|
27
|
+
export { type IOverflowState, type IOverflowTabsOptions, type TOverflowDirection, useOverflowTabs };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
|
|
3
|
+
type TOverflowDirection = "start" | "end";
|
|
4
|
+
interface IOverflowTabsOptions<T extends HTMLElement = HTMLElement> {
|
|
5
|
+
/**
|
|
6
|
+
* Container element:
|
|
7
|
+
* - React ref (current: T | null)
|
|
8
|
+
* - or direct element (via query selector)
|
|
9
|
+
*/
|
|
10
|
+
container: RefObject<T | null> | T;
|
|
11
|
+
/**
|
|
12
|
+
* Attribute name for tabs.
|
|
13
|
+
* Each tab must have this attribute with a unique value.
|
|
14
|
+
* Default: "data-overflow-key" or "[data-overflow-key]"
|
|
15
|
+
*/
|
|
16
|
+
tabSelector?: string;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
}
|
|
19
|
+
interface IOverflowState {
|
|
20
|
+
visibleKeys: string[];
|
|
21
|
+
overflowKeys: string[];
|
|
22
|
+
isOverflowing: boolean;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
declare const useOverflowTabs: <T extends HTMLElement = HTMLElement>(options: IOverflowTabsOptions<T>) => IOverflowState;
|
|
26
|
+
|
|
27
|
+
export { type IOverflowState, type IOverflowTabsOptions, type TOverflowDirection, useOverflowTabs };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var u=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var I=Object.getOwnPropertyNames;var K=Object.prototype.hasOwnProperty;var h=(e,t)=>{for(var o in t)u(e,o,{get:t[o],enumerable:!0})},x=(e,t,o,a)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of I(t))!K.call(e,r)&&r!==o&&u(e,r,{get:()=>t[r],enumerable:!(a=E(t,r))||a.enumerable});return e};var z=e=>x(u({},"__esModule",{value:!0}),e);var M={};h(M,{useOverflowTabs:()=>w});module.exports=z(M);var l=require("react");var A=e=>e?typeof e=="object"&&"current"in e?e.current:e:null,y=A;var H=e=>{let t=e!=null?e:"[data-overflow-key]";return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t},p=H;var L=e=>{let[t,o]=(0,l.useState)([]),[a,r]=(0,l.useState)([]),[g,b]=(0,l.useState)(!1);return(0,l.useEffect)(()=>{let c=y(e.container);if(!c)return;let m=p(e.tabSelector),v=Array.from(c.querySelectorAll(`[${m}]`));if(o(v.map(f=>f.getAttribute(m))),e.disabled==!0){r([]),b(!1);return}let O=new Set,i=new Set,T=new IntersectionObserver(f=>{let d=!1;for(let n of f){let s=n.target.getAttribute(m);if(!s)continue;O.add(s);let S=i.size;n.intersectionRatio<1?i.add(s):i.delete(s),i.size!=S&&(d=!0)}if(d){let n=Array.from(i);r(n.reverse()),o(Array.from(O).filter(s=>!n.includes(s))),b(n.length>0)}},{root:c,threshold:.999});return v.forEach(f=>T.observe(f)),()=>{T.disconnect()}},[e.container,e.tabSelector,e.disabled]),{visibleKeys:t,overflowKeys:a,isOverflowing:g}},w=L;0&&(module.exports={useOverflowTabs});
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useEffect as E,useState as f}from"react";var g=e=>e?typeof e=="object"&&"current"in e?e.current:e:null,T=g;var S=e=>{let t=e!=null?e:"[data-overflow-key]";return t.startsWith("[")&&t.endsWith("]")?t.slice(1,-1):t},d=S;var I=e=>{let[t,a]=f([]),[y,c]=f([]),[p,m]=f(!1);return E(()=>{let l=T(e.container);if(!l)return;let i=d(e.tabSelector),u=Array.from(l.querySelectorAll(`[${i}]`));if(a(u.map(s=>s.getAttribute(i))),e.disabled==!0){c([]),m(!1);return}let b=new Set,n=new Set,v=new IntersectionObserver(s=>{let O=!1;for(let r of s){let o=r.target.getAttribute(i);if(!o)continue;b.add(o);let w=n.size;r.intersectionRatio<1?n.add(o):n.delete(o),n.size!=w&&(O=!0)}if(O){let r=Array.from(n);c(r.reverse()),a(Array.from(b).filter(o=>!r.includes(o))),m(r.length>0)}},{root:l,threshold:.999});return u.forEach(s=>v.observe(s)),()=>{v.disconnect()}},[e.container,e.tabSelector,e.disabled]),{visibleKeys:t,overflowKeys:y,isOverflowing:p}},K=I;export{K as useOverflowTabs};
|
package/package.json
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-overflow-tabs",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "A lightweight React hook for responsive tab navigation with automatic overflow handling. Works with any UI framework (Tailwind, Bootstrap, MUI, custom CSS).",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs",
|
|
12
|
+
"require": "./dist/index.js"
|
|
13
|
+
},
|
|
14
|
+
"./package.json": "./package.json"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"sideEffects": false,
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "tsup",
|
|
22
|
+
"format": "prettier --write ./**/*.{js,jsx,ts,tsx,cjs,json,css,scss}",
|
|
23
|
+
"typecheck": "tsc -p tsconfig.json --noEmit"
|
|
24
|
+
},
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "git+https://github.com/bawerbozdag/react-overflow-tabs.git"
|
|
28
|
+
},
|
|
29
|
+
"keywords": [
|
|
30
|
+
"react",
|
|
31
|
+
"tabs",
|
|
32
|
+
"overflow",
|
|
33
|
+
"dropdown",
|
|
34
|
+
"headless",
|
|
35
|
+
"hook",
|
|
36
|
+
"responsive",
|
|
37
|
+
"navigation",
|
|
38
|
+
"responsive-tabs",
|
|
39
|
+
"tab-navigation",
|
|
40
|
+
"react-tabs-overflow",
|
|
41
|
+
"intersection-observer",
|
|
42
|
+
"resize-observer",
|
|
43
|
+
"ui-agnostic",
|
|
44
|
+
"tabbar",
|
|
45
|
+
"navbar",
|
|
46
|
+
"bootstrap",
|
|
47
|
+
"tailwind",
|
|
48
|
+
"mui",
|
|
49
|
+
"menu",
|
|
50
|
+
"react-hook",
|
|
51
|
+
"overflow-tabs",
|
|
52
|
+
"headless-ui"
|
|
53
|
+
],
|
|
54
|
+
"author": "Baver Bozdağ",
|
|
55
|
+
"license": "MIT",
|
|
56
|
+
"bugs": {
|
|
57
|
+
"url": "https://github.com/bawerbozdag/react-overflow-tabs/issues"
|
|
58
|
+
},
|
|
59
|
+
"homepage": "https://github.com/bawerbozdag/react-overflow-tabs#readme",
|
|
60
|
+
"peerDependencies": {
|
|
61
|
+
"react": ">=18 <20"
|
|
62
|
+
},
|
|
63
|
+
"devDependencies": {
|
|
64
|
+
"@semantic-release/changelog": "^6.0.3",
|
|
65
|
+
"@semantic-release/git": "^10.0.1",
|
|
66
|
+
"@semantic-release/github": "^11.0.4",
|
|
67
|
+
"@semantic-release/npm": "^12.0.2",
|
|
68
|
+
"@types/react": "^19.1.10",
|
|
69
|
+
"conventional-changelog-conventionalcommits": "^9.1.0",
|
|
70
|
+
"prettier": "^3.6.2",
|
|
71
|
+
"react": "^19.1.1",
|
|
72
|
+
"semantic-release": "^24.2.7",
|
|
73
|
+
"tsup": "^8.5.0",
|
|
74
|
+
"typescript": "^5.9.2"
|
|
75
|
+
},
|
|
76
|
+
"engines": {
|
|
77
|
+
"node": ">=18"
|
|
78
|
+
}
|
|
79
|
+
}
|