kevlar-tabs
Advanced tools
Comparing version 1.0.1 to 1.1.0
# Changelog | ||
## [1.1.0](https://github.com/neolitec/kevlar-tabs/compare/v1.0.1...v1.1.0) (2022-12-08) | ||
### Miscellaneous Chores | ||
* trigger release ([#31](https://github.com/neolitec/kevlar-tabs/issues/31)) ([17f083b](https://github.com/neolitec/kevlar-tabs/commit/17f083be485efa3b1034453812510b704a041dcb)) | ||
## [1.0.1](https://github.com/neolitec/kevlar-tabs/compare/v1.0.0...v1.0.1) (2022-12-08) | ||
@@ -4,0 +11,0 @@ |
@@ -1,4 +0,4 @@ | ||
import m, { forwardRef as z, useRef as E, useEffect as B, useCallback as v, useLayoutEffect as A, isValidElement as G, useId as H, useMemo as _, useState as J } from "react"; | ||
import { jsx as g } from "react/jsx-runtime"; | ||
var D = { exports: {} }; | ||
import m, { forwardRef as A, useRef as E, useEffect as D, useCallback as T, useLayoutEffect as G, isValidElement as H, useId as J, useMemo as j, useState as Q } from "react"; | ||
import { jsx as C } from "react/jsx-runtime"; | ||
var F = { exports: {} }; | ||
/*! | ||
@@ -11,6 +11,6 @@ Copyright (c) 2018 Jed Watson. | ||
(function() { | ||
var r = {}.hasOwnProperty; | ||
function t() { | ||
for (var e = [], f = 0; f < arguments.length; f++) { | ||
var i = arguments[f]; | ||
var t = {}.hasOwnProperty; | ||
function r() { | ||
for (var e = [], l = 0; l < arguments.length; l++) { | ||
var i = arguments[l]; | ||
if (!!i) { | ||
@@ -22,4 +22,4 @@ var o = typeof i; | ||
if (i.length) { | ||
var d = t.apply(null, i); | ||
d && e.push(d); | ||
var b = r.apply(null, i); | ||
b && e.push(b); | ||
} | ||
@@ -32,3 +32,3 @@ } else if (o === "object") { | ||
for (var u in i) | ||
r.call(i, u) && i[u] && e.push(u); | ||
t.call(i, u) && i[u] && e.push(u); | ||
} | ||
@@ -39,19 +39,19 @@ } | ||
} | ||
n.exports ? (t.default = t, n.exports = t) : window.classNames = t; | ||
n.exports ? (r.default = r, n.exports = r) : window.classNames = r; | ||
})(); | ||
})(D); | ||
const F = D.exports, M = ({ | ||
})(F); | ||
const M = F.exports, V = ({ | ||
active: n, | ||
children: r, | ||
className: t, | ||
children: t, | ||
className: r, | ||
classNameActive: e, | ||
classNameDisabled: f, | ||
classNameDisabled: l, | ||
disabled: i, | ||
onClick: o, | ||
...d | ||
...b | ||
}, u) => { | ||
const a = E(null); | ||
return B(() => { | ||
return D(() => { | ||
n && a.current && a.current.focus(); | ||
}, [n]), /* @__PURE__ */ g("li", { | ||
}, [n]), /* @__PURE__ */ C("li", { | ||
ref: (s) => { | ||
@@ -61,5 +61,5 @@ a.current = s, typeof u == "function" ? u(s) : u && (u.current = s); | ||
role: "tab", | ||
className: F([t || "tab", { | ||
className: M([r || "tab", { | ||
[e || "tab--active"]: n, | ||
[f || "tab--disabled"]: i | ||
[l || "tab--disabled"]: i | ||
}]), | ||
@@ -69,24 +69,24 @@ tabIndex: n ? 0 : -1, | ||
"aria-disabled": i, | ||
...d, | ||
...b, | ||
onClick: i ? void 0 : o, | ||
children: r | ||
children: t | ||
}); | ||
}; | ||
M.displayName = "Tab"; | ||
const Q = z(M); | ||
Q.displayName = "Tab"; | ||
const U = ({ | ||
V.displayName = "Tab"; | ||
const U = A(V); | ||
U.displayName = "Tab"; | ||
const X = ({ | ||
children: n, | ||
className: r, | ||
onArrowLeftKeyDown: t, | ||
className: t, | ||
onArrowLeftKeyDown: r, | ||
onArrowRightKeyDown: e, | ||
...f | ||
...l | ||
}) => { | ||
const i = v((o) => { | ||
o.key === "ArrowLeft" ? (t == null || t(), o.preventDefault()) : o.key === "ArrowRight" && (e == null || e(), o.preventDefault()); | ||
}, [t, e]); | ||
return /* @__PURE__ */ g("ul", { | ||
const i = T((o) => { | ||
o.key === "ArrowLeft" ? (r == null || r(), o.preventDefault()) : o.key === "ArrowRight" && (e == null || e(), o.preventDefault()); | ||
}, [r, e]); | ||
return /* @__PURE__ */ C("ul", { | ||
role: "tablist", | ||
className: r || "tablist", | ||
...f, | ||
className: t || "tablist", | ||
...l, | ||
onKeyDown: i, | ||
@@ -96,20 +96,20 @@ children: n | ||
}; | ||
U.displayName = "TabList"; | ||
const X = ({ | ||
X.displayName = "TabList"; | ||
const Y = ({ | ||
active: n, | ||
children: r, | ||
className: t, | ||
children: t, | ||
className: r, | ||
classNameActive: e, | ||
classNameDisabled: f, | ||
classNameDisabled: l, | ||
disabled: i, | ||
...o | ||
}) => { | ||
const d = E(n); | ||
return A(() => { | ||
!d.current && n && (d.current = !0); | ||
}, [n]), /* @__PURE__ */ g("div", { | ||
const b = E(n); | ||
return G(() => { | ||
!b.current && n && (b.current = !0); | ||
}, [n]), /* @__PURE__ */ C("div", { | ||
role: "tabpanel", | ||
className: F(t || "tabpanel", { | ||
className: M(r || "tabpanel", { | ||
[e || "tabpanel--active"]: n, | ||
[f || "tabpanel--disabled"]: i | ||
[l || "tabpanel--disabled"]: i | ||
}), | ||
@@ -120,45 +120,45 @@ style: n ? void 0 : { | ||
...o, | ||
children: (n || d.current) && r | ||
children: (n || b.current) && t | ||
}); | ||
}; | ||
X.displayName = "TabPanel"; | ||
function P(n) { | ||
return G(n) && !!n.type.displayName; | ||
Y.displayName = "TabPanel"; | ||
function $(n) { | ||
return H(n) && !!n.type.displayName; | ||
} | ||
function V(n) { | ||
return P(n) && n.type.displayName === "TabList"; | ||
} | ||
function W(n) { | ||
return P(n) && n.type.displayName === "Tab"; | ||
return $(n) && n.type.displayName === "TabList"; | ||
} | ||
function Y(n) { | ||
return P(n) && n.type.displayName === "TabPanel"; | ||
function q(n) { | ||
return $(n) && n.type.displayName === "Tab"; | ||
} | ||
function Z(n) { | ||
const r = m.Children.toArray(n).find( | ||
(t) => V(t) | ||
); | ||
return m.Children.toArray(r.props.children).filter( | ||
(t) => W(t) | ||
); | ||
return $(n) && n.type.displayName === "TabPanel"; | ||
} | ||
function S(n) { | ||
return Z(n).map((r) => r.props); | ||
const t = m.Children.toArray(n).find( | ||
(r) => W(r) | ||
); | ||
return t ? m.Children.toArray(t.props.children).filter( | ||
(r) => q(r) | ||
) : []; | ||
} | ||
const en = ({ | ||
function w(n) { | ||
return S(n).map((t) => t.props); | ||
} | ||
const tn = ({ | ||
autoActivate: n = !0, | ||
children: r, | ||
className: t, | ||
children: t, | ||
className: r, | ||
classNames: e, | ||
onNameSelect: f, | ||
onNameSelect: l, | ||
onSelect: i, | ||
selected: o | ||
}) => { | ||
var R; | ||
const d = H(), u = _(() => S(r), [r]), a = _(() => u.map((p) => p.name), [u]), s = E(u.map((p, c) => `${d}-${c}`)), C = E([]), h = E((R = typeof o == "string" ? a.indexOf(o) : o) != null ? R : 0), [{ | ||
index: T, | ||
name: $ | ||
}, k] = J(j(a, o)); | ||
B(() => { | ||
k(j(a, o)); | ||
var _; | ||
const b = J(), u = j(() => w(t), [t]), a = j(() => u.map((p) => p.name), [u]), s = E(u.map((p, c) => `${b}-${c}`)), P = E([]), h = E((_ = typeof o == "string" ? a.indexOf(o) : o) != null ? _ : 0), [{ | ||
index: v, | ||
name: k | ||
}, O] = Q(B(a, o)); | ||
D(() => { | ||
O(B(a, o)); | ||
}, [ | ||
@@ -168,72 +168,73 @@ o, | ||
]); | ||
const x = v((p, c) => { | ||
k({ | ||
const x = T((p, c) => { | ||
O({ | ||
index: p, | ||
name: c | ||
}), i == null || i(p, T), f == null || f(c, $), h.current = p; | ||
}, [T, $, f, i]), O = v(() => { | ||
if (u.every((l) => l.disabled)) | ||
}), i == null || i(p, v), l == null || l(c, k), h.current = p; | ||
}, [v, k, l, i]), L = T(() => { | ||
if (u.every((f) => f.disabled)) | ||
return; | ||
const p = w(h.current, u), c = a[p]; | ||
n ? x(p, c) : (h.current = p, C.current[p].focus()); | ||
}, [n, x, a, u]), L = v(() => { | ||
if (u.every((l) => l.disabled)) | ||
const p = K(h.current, u), c = a[p]; | ||
n ? x(p, c) : (h.current = p, P.current[p].focus()); | ||
}, [n, x, a, u]), R = T(() => { | ||
if (u.every((f) => f.disabled)) | ||
return; | ||
const p = K(h.current, u), c = a[p]; | ||
n ? x(p, c) : (h.current = p, C.current[p].focus()); | ||
}, [n, x, a, u]), q = v(() => { | ||
const p = N(h.current, u), c = a[p]; | ||
n ? x(p, c) : (h.current = p, P.current[p].focus()); | ||
}, [n, x, a, u]), z = T(() => { | ||
let p = 0; | ||
const c = a.length - s.current.length; | ||
return s.current.push(...Array.from(new Array(c)).map((l, b) => `${d}-${a.length + b - 1}`)), m.Children.map(r, (l) => { | ||
if (V(l)) | ||
return m.cloneElement(l, { | ||
...l.props, | ||
children: m.Children.map(l.props.children, (b, y) => W(b) ? m.cloneElement(b, { | ||
return s.current.push(...Array.from(new Array(c)).map((f, I) => `${b}-${a.length + I - 1}`)), m.Children.map(t, (f) => { | ||
var I; | ||
if (W(f)) | ||
return m.cloneElement(f, { | ||
...f.props, | ||
children: m.Children.map(f.props.children, (d, y) => q(d) ? m.cloneElement(d, { | ||
className: e == null ? void 0 : e.tab, | ||
classNameActive: e == null ? void 0 : e.tabActive, | ||
classNameDisabled: e == null ? void 0 : e.tabDisabled, | ||
...b.props, | ||
active: y === T, | ||
...d.props, | ||
active: y === v, | ||
"aria-controls": `${s.current[y]}-panel`, | ||
id: `${s.current[y]}-tab`, | ||
onClick: () => x(y, b.props.name), | ||
onKeyDown: n ? void 0 : (I) => { | ||
(I.key === "Enter" || I.key === " ") && x(y, b.props.name); | ||
onClick: () => x(y, d.props.name), | ||
onKeyDown: n ? void 0 : (g) => { | ||
(g.key === "Enter" || g.key === " ") && x(y, d.props.name); | ||
}, | ||
ref: (I) => { | ||
C.current[y] = I; | ||
ref: (g) => { | ||
P.current[y] = g; | ||
} | ||
}) : b), | ||
}) : d), | ||
className: e == null ? void 0 : e.tabList, | ||
onArrowLeftKeyDown: L, | ||
onArrowRightKeyDown: O | ||
onArrowLeftKeyDown: R, | ||
onArrowRightKeyDown: L | ||
}); | ||
if (Y(l)) { | ||
const b = Number.isInteger(l.props.index) ? l.props.index : p, y = m.cloneElement(l, { | ||
if (Z(f)) { | ||
const d = Number.isInteger(f.props.index) ? f.props.index : p, y = m.cloneElement(f, { | ||
className: e == null ? void 0 : e.tabPanel, | ||
classNameActive: e == null ? void 0 : e.tabPanelActive, | ||
classNameDisabled: e == null ? void 0 : e.tabPanelDisabled, | ||
...l.props, | ||
active: b === T, | ||
disabled: u[b].disabled, | ||
id: `${s.current[b]}-panel`, | ||
"aria-labelledby": `${s.current[b]}-tab` | ||
...f.props, | ||
active: d === v, | ||
disabled: (I = u[d]) == null ? void 0 : I.disabled, | ||
id: s.current[d] ? `${s.current[d]}-panel` : void 0, | ||
"aria-labelledby": s.current[d] ? `${s.current[d]}-tab` : void 0 | ||
}); | ||
return p += 1, y; | ||
} | ||
return l; | ||
return f; | ||
}); | ||
}, [n, r, e, T, x, d, O, L, a.length, u]); | ||
return /* @__PURE__ */ g("div", { | ||
className: t, | ||
children: q() | ||
}, [n, t, e, v, x, b, L, R, a.length, u]); | ||
return /* @__PURE__ */ C("div", { | ||
className: r, | ||
children: z() | ||
}); | ||
}; | ||
function j(n, r) { | ||
return Number.isInteger(r) ? { | ||
index: r, | ||
name: n[r] | ||
} : r ? { | ||
index: n.indexOf(r), | ||
name: r | ||
function B(n, t) { | ||
return Number.isInteger(t) ? { | ||
index: t, | ||
name: n[t] | ||
} : t ? { | ||
index: n.indexOf(t), | ||
name: t | ||
} : { | ||
@@ -244,20 +245,20 @@ index: 0, | ||
} | ||
function w(n, r) { | ||
let t = n < r.length - 1 ? n + 1 : 0; | ||
for (; r[t].disabled; ) | ||
t = t < r.length - 1 ? t + 1 : 0; | ||
return t; | ||
function K(n, t) { | ||
let r = n < t.length - 1 ? n + 1 : 0; | ||
for (; t[r].disabled; ) | ||
r = r < t.length - 1 ? r + 1 : 0; | ||
return r; | ||
} | ||
function K(n, r) { | ||
let t = n > 0 ? n - 1 : r.length - 1; | ||
for (; r[t].disabled; ) | ||
t = t > 0 ? t - 1 : r.length - 1; | ||
return t; | ||
function N(n, t) { | ||
let r = n > 0 ? n - 1 : t.length - 1; | ||
for (; t[r].disabled; ) | ||
r = r > 0 ? r - 1 : t.length - 1; | ||
return r; | ||
} | ||
export { | ||
Q as Tab, | ||
U as TabList, | ||
X as TabPanel, | ||
en as Tabs | ||
U as Tab, | ||
X as TabList, | ||
Y as TabPanel, | ||
tn as Tabs | ||
}; | ||
//# sourceMappingURL=kevlar-tabs.es.js.map |
@@ -1,6 +0,6 @@ | ||
(function(c,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("react"),require("react/jsx-runtime")):typeof define=="function"&&define.amd?define(["exports","react","react/jsx-runtime"],i):(c=typeof globalThis<"u"?globalThis:c||self,i(c["kevlar-tabs"]={},c.React,c.jsxRuntime))})(this,function(c,i,C){"use strict";const h=(e=>e&&typeof e=="object"&&"default"in e?e:{default:e})(i);var k={exports:{}};/*! | ||
(function(y,i){typeof exports=="object"&&typeof module<"u"?i(exports,require("react"),require("react/jsx-runtime")):typeof define=="function"&&define.amd?define(["exports","react","react/jsx-runtime"],i):(y=typeof globalThis<"u"?globalThis:y||self,i(y["kevlar-tabs"]={},y.React,y.jsxRuntime))})(this,function(y,i,C){"use strict";const h=(e=>e&&typeof e=="object"&&"default"in e?e:{default:e})(i);var _={exports:{}};/*! | ||
Copyright (c) 2018 Jed Watson. | ||
Licensed under the MIT License (MIT), see | ||
http://jedwatson.github.io/classnames | ||
*/(function(e){(function(){var r={}.hasOwnProperty;function t(){for(var n=[],d=0;d<arguments.length;d++){var u=arguments[d];if(!!u){var l=typeof u;if(l==="string"||l==="number")n.push(u);else if(Array.isArray(u)){if(u.length){var b=t.apply(null,u);b&&n.push(b)}}else if(l==="object"){if(u.toString!==Object.prototype.toString&&!u.toString.toString().includes("[native code]")){n.push(u.toString());continue}for(var f in u)r.call(u,f)&&u[f]&&n.push(f)}}}return n.join(" ")}e.exports?(t.default=t,e.exports=t):window.classNames=t})()})(k);const _=k.exports,$=({active:e,children:r,className:t,classNameActive:n,classNameDisabled:d,disabled:u,onClick:l,...b},f)=>{const a=i.useRef(null);return i.useEffect(()=>{e&&a.current&&a.current.focus()},[e]),C.jsx("li",{ref:y=>{a.current=y,typeof f=="function"?f(y):f&&(f.current=y)},role:"tab",className:_([t||"tab",{[n||"tab--active"]:e,[d||"tab--disabled"]:u}]),tabIndex:e?0:-1,"aria-selected":e,"aria-disabled":u,...b,onClick:u?void 0:l,children:r})};$.displayName="Tab";const j=i.forwardRef($);j.displayName="Tab";const L=({children:e,className:r,onArrowLeftKeyDown:t,onArrowRightKeyDown:n,...d})=>{const u=i.useCallback(l=>{l.key==="ArrowLeft"?(t==null||t(),l.preventDefault()):l.key==="ArrowRight"&&(n==null||n(),l.preventDefault())},[t,n]);return C.jsx("ul",{role:"tablist",className:r||"tablist",...d,onKeyDown:u,children:e})};L.displayName="TabList";const O=({active:e,children:r,className:t,classNameActive:n,classNameDisabled:d,disabled:u,...l})=>{const b=i.useRef(e);return i.useLayoutEffect(()=>{!b.current&&e&&(b.current=!0)},[e]),C.jsx("div",{role:"tabpanel",className:_(t||"tabpanel",{[n||"tabpanel--active"]:e,[d||"tabpanel--disabled"]:u}),style:e?void 0:{display:"none"},...l,children:(e||b.current)&&r})};O.displayName="TabPanel";function g(e){return i.isValidElement(e)&&!!e.type.displayName}function M(e){return g(e)&&e.type.displayName==="TabList"}function D(e){return g(e)&&e.type.displayName==="Tab"}function z(e){return g(e)&&e.type.displayName==="TabPanel"}function A(e){const r=h.default.Children.toArray(e).find(t=>M(t));return h.default.Children.toArray(r.props.children).filter(t=>D(t))}function G(e){return A(e).map(r=>r.props)}const H=({autoActivate:e=!0,children:r,className:t,classNames:n,onNameSelect:d,onSelect:u,selected:l})=>{var W;const b=i.useId(),f=i.useMemo(()=>G(r),[r]),a=i.useMemo(()=>f.map(o=>o.name),[f]),y=i.useRef(f.map((o,T)=>`${b}-${T}`)),P=i.useRef([]),v=i.useRef((W=typeof l=="string"?a.indexOf(l):l)!=null?W:0),[{index:E,name:B},F]=i.useState(q(a,l));i.useEffect(()=>{F(q(a,l))},[l,a.join(",")]);const m=i.useCallback((o,T)=>{F({index:o,name:T}),u==null||u(o,E),d==null||d(T,B),v.current=o},[E,B,d,u]),S=i.useCallback(()=>{if(f.every(p=>p.disabled))return;const o=J(v.current,f),T=a[o];e?m(o,T):(v.current=o,P.current[o].focus())},[e,m,a,f]),V=i.useCallback(()=>{if(f.every(p=>p.disabled))return;const o=Q(v.current,f),T=a[o];e?m(o,T):(v.current=o,P.current[o].focus())},[e,m,a,f]),U=i.useCallback(()=>{let o=0;const T=a.length-y.current.length;return y.current.push(...Array.from(new Array(T)).map((p,s)=>`${b}-${a.length+s-1}`)),h.default.Children.map(r,p=>{if(M(p))return h.default.cloneElement(p,{...p.props,children:h.default.Children.map(p.props.children,(s,x)=>D(s)?h.default.cloneElement(s,{className:n==null?void 0:n.tab,classNameActive:n==null?void 0:n.tabActive,classNameDisabled:n==null?void 0:n.tabDisabled,...s.props,active:x===E,"aria-controls":`${y.current[x]}-panel`,id:`${y.current[x]}-tab`,onClick:()=>m(x,s.props.name),onKeyDown:e?void 0:I=>{(I.key==="Enter"||I.key===" ")&&m(x,s.props.name)},ref:I=>{P.current[x]=I}}):s),className:n==null?void 0:n.tabList,onArrowLeftKeyDown:V,onArrowRightKeyDown:S});if(z(p)){const s=Number.isInteger(p.props.index)?p.props.index:o,x=h.default.cloneElement(p,{className:n==null?void 0:n.tabPanel,classNameActive:n==null?void 0:n.tabPanelActive,classNameDisabled:n==null?void 0:n.tabPanelDisabled,...p.props,active:s===E,disabled:f[s].disabled,id:`${y.current[s]}-panel`,"aria-labelledby":`${y.current[s]}-tab`});return o+=1,x}return p})},[e,r,n,E,m,b,S,V,a.length,f]);return C.jsx("div",{className:t,children:U()})};function q(e,r){return Number.isInteger(r)?{index:r,name:e[r]}:r?{index:e.indexOf(r),name:r}:{index:0,name:e[0]}}function J(e,r){let t=e<r.length-1?e+1:0;for(;r[t].disabled;)t=t<r.length-1?t+1:0;return t}function Q(e,r){let t=e>0?e-1:r.length-1;for(;r[t].disabled;)t=t>0?t-1:r.length-1;return t}c.Tab=j,c.TabList=L,c.TabPanel=O,c.Tabs=H,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
*/(function(e){(function(){var t={}.hasOwnProperty;function r(){for(var n=[],d=0;d<arguments.length;d++){var u=arguments[d];if(!!u){var l=typeof u;if(l==="string"||l==="number")n.push(u);else if(Array.isArray(u)){if(u.length){var b=r.apply(null,u);b&&n.push(b)}}else if(l==="object"){if(u.toString!==Object.prototype.toString&&!u.toString.toString().includes("[native code]")){n.push(u.toString());continue}for(var f in u)t.call(u,f)&&u[f]&&n.push(f)}}}return n.join(" ")}e.exports?(r.default=r,e.exports=r):window.classNames=r})()})(_);const $=_.exports,j=({active:e,children:t,className:r,classNameActive:n,classNameDisabled:d,disabled:u,onClick:l,...b},f)=>{const a=i.useRef(null);return i.useEffect(()=>{e&&a.current&&a.current.focus()},[e]),C.jsx("li",{ref:c=>{a.current=c,typeof f=="function"?f(c):f&&(f.current=c)},role:"tab",className:$([r||"tab",{[n||"tab--active"]:e,[d||"tab--disabled"]:u}]),tabIndex:e?0:-1,"aria-selected":e,"aria-disabled":u,...b,onClick:u?void 0:l,children:t})};j.displayName="Tab";const L=i.forwardRef(j);L.displayName="Tab";const O=({children:e,className:t,onArrowLeftKeyDown:r,onArrowRightKeyDown:n,...d})=>{const u=i.useCallback(l=>{l.key==="ArrowLeft"?(r==null||r(),l.preventDefault()):l.key==="ArrowRight"&&(n==null||n(),l.preventDefault())},[r,n]);return C.jsx("ul",{role:"tablist",className:t||"tablist",...d,onKeyDown:u,children:e})};O.displayName="TabList";const M=({active:e,children:t,className:r,classNameActive:n,classNameDisabled:d,disabled:u,...l})=>{const b=i.useRef(e);return i.useLayoutEffect(()=>{!b.current&&e&&(b.current=!0)},[e]),C.jsx("div",{role:"tabpanel",className:$(r||"tabpanel",{[n||"tabpanel--active"]:e,[d||"tabpanel--disabled"]:u}),style:e?void 0:{display:"none"},...l,children:(e||b.current)&&t})};M.displayName="TabPanel";function P(e){return i.isValidElement(e)&&!!e.type.displayName}function D(e){return P(e)&&e.type.displayName==="TabList"}function q(e){return P(e)&&e.type.displayName==="Tab"}function A(e){return P(e)&&e.type.displayName==="TabPanel"}function G(e){const t=h.default.Children.toArray(e).find(r=>D(r));return t?h.default.Children.toArray(t.props.children).filter(r=>q(r)):[]}function H(e){return G(e).map(t=>t.props)}const J=({autoActivate:e=!0,children:t,className:r,classNames:n,onNameSelect:d,onSelect:u,selected:l})=>{var z;const b=i.useId(),f=i.useMemo(()=>H(t),[t]),a=i.useMemo(()=>f.map(o=>o.name),[f]),c=i.useRef(f.map((o,T)=>`${b}-${T}`)),k=i.useRef([]),m=i.useRef((z=typeof l=="string"?a.indexOf(l):l)!=null?z:0),[{index:E,name:F},S]=i.useState(B(a,l));i.useEffect(()=>{S(B(a,l))},[l,a.join(",")]);const v=i.useCallback((o,T)=>{S({index:o,name:T}),u==null||u(o,E),d==null||d(T,F),m.current=o},[E,F,d,u]),V=i.useCallback(()=>{if(f.every(p=>p.disabled))return;const o=Q(m.current,f),T=a[o];e?v(o,T):(m.current=o,k.current[o].focus())},[e,v,a,f]),W=i.useCallback(()=>{if(f.every(p=>p.disabled))return;const o=U(m.current,f),T=a[o];e?v(o,T):(m.current=o,k.current[o].focus())},[e,v,a,f]),X=i.useCallback(()=>{let o=0;const T=a.length-c.current.length;return c.current.push(...Array.from(new Array(T)).map((p,I)=>`${b}-${a.length+I-1}`)),h.default.Children.map(t,p=>{var I;if(D(p))return h.default.cloneElement(p,{...p.props,children:h.default.Children.map(p.props.children,(s,x)=>q(s)?h.default.cloneElement(s,{className:n==null?void 0:n.tab,classNameActive:n==null?void 0:n.tabActive,classNameDisabled:n==null?void 0:n.tabDisabled,...s.props,active:x===E,"aria-controls":`${c.current[x]}-panel`,id:`${c.current[x]}-tab`,onClick:()=>v(x,s.props.name),onKeyDown:e?void 0:g=>{(g.key==="Enter"||g.key===" ")&&v(x,s.props.name)},ref:g=>{k.current[x]=g}}):s),className:n==null?void 0:n.tabList,onArrowLeftKeyDown:W,onArrowRightKeyDown:V});if(A(p)){const s=Number.isInteger(p.props.index)?p.props.index:o,x=h.default.cloneElement(p,{className:n==null?void 0:n.tabPanel,classNameActive:n==null?void 0:n.tabPanelActive,classNameDisabled:n==null?void 0:n.tabPanelDisabled,...p.props,active:s===E,disabled:(I=f[s])==null?void 0:I.disabled,id:c.current[s]?`${c.current[s]}-panel`:void 0,"aria-labelledby":c.current[s]?`${c.current[s]}-tab`:void 0});return o+=1,x}return p})},[e,t,n,E,v,b,V,W,a.length,f]);return C.jsx("div",{className:r,children:X()})};function B(e,t){return Number.isInteger(t)?{index:t,name:e[t]}:t?{index:e.indexOf(t),name:t}:{index:0,name:e[0]}}function Q(e,t){let r=e<t.length-1?e+1:0;for(;t[r].disabled;)r=r<t.length-1?r+1:0;return r}function U(e,t){let r=e>0?e-1:t.length-1;for(;t[r].disabled;)r=r>0?r-1:t.length-1;return r}y.Tab=L,y.TabList=O,y.TabPanel=M,y.Tabs=J,Object.defineProperties(y,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})}); | ||
//# sourceMappingURL=kevlar-tabs.umd.js.map |
{ | ||
"name": "kevlar-tabs", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "Yet another better tabs library for React", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
156311
411