@dotss/ui 1.4.0 → 1.5.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/Tab/Tab.cjs CHANGED
@@ -1,18 +1,18 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const A=require("@emotion/react/jsx-runtime"),i=require("react"),Q=require("@emotion/styled"),Z=o=>o&&o.__esModule?o:{default:o},M=Z(Q),B=M.default.div`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const L=require("@emotion/react/jsx-runtime"),c=require("react"),st=require("@emotion/styled"),it=o=>o&&o.__esModule?o:{default:o},R=it(st),ct=R.default.div`
2
2
  width: 100%;
3
3
  background-color: ${({theme:o})=>o.palette.grey.white};
4
- ${({scrollable:o})=>o?{overflow:"hidden"}:{}}
5
- `,tt=M.default.div`
4
+ ${({scrollable:o})=>o?{overflow:"hidden",cursor:"grab",'& [role="tab"]':{flex:"0 0 auto"}}:{}}
5
+ `,ot=R.default.div`
6
6
  display: flex;
7
7
  position: relative;
8
8
  background: ${({theme:o})=>o.palette.grey.white};
9
- ${({theme:o,isChipped:l})=>l?{gap:o.spacing.content(2)}:{}}
10
- `,et=M.default.div`
9
+ ${({theme:o,isChipped:m})=>m?{gap:o.spacing.content(2)}:{}}
10
+ `,at=R.default.div`
11
11
  position: absolute;
12
12
  height: 2px;
13
13
  bottom: 0;
14
- background: ${({theme:o,disabled:l})=>l?o.palette.brand.primary.disableLine:o.palette.brand.primary.main};
14
+ background: ${({theme:o,disabled:m})=>m?o.palette.brand.primary.disableLine:o.palette.brand.primary.main};
15
15
  transition: all 0.2s ease-in-out;
16
16
  transition-property: transform, width;
17
17
  ${({isChipped:o})=>o?{display:"none"}:{}}
18
- `,S=3,nt=i.forwardRef(function({value:l,scrollable:d=!1,disabled:_=!1,onChange:R,size:w="medium",inlineCSS:I,wrapperProps:m,children:E,...j},F){const s=i.useRef(null),f=i.useRef(),b=i.useRef(0),N=i.useRef(!0),x=i.useRef(!1),g=i.useRef(!1),u=i.useRef(!1),[H,O]=i.useState(!1),[D,P]=i.useState(0),[T,V]=i.useState(0),[L,K]=i.useState(0),$=_,W=i.Children.toArray(E).every(t=>i.isValidElement(t)&&i.Children.toArray(t.props.children).every(n=>i.isValidElement(n)&&!Array.isArray(n.props.children))),z=t=>n=>{d&&!x.current||(R(t,n.currentTarget),x.current=!1)},U=t=>{if(!s.current)return;const n=s.current.querySelectorAll('[role="tab"]:not([disabled])'),a=Array.from(n).findIndex(e=>e===document.activeElement);if(t.key==="ArrowLeft"){t.preventDefault();const e=a<=0?n.length-1:a-1,r=n[e];r&&!r.getAttribute("disabled")&&r.focus()}else if(t.key==="ArrowRight"){t.preventDefault();const e=a>=n.length-1?0:a+1,r=n[e];r&&!r.getAttribute("disabled")&&r.focus()}else if(t.key==="Home"){t.preventDefault();const e=n[0];e&&!e.getAttribute("disabled")&&e.focus()}else if(t.key==="End"){t.preventDefault();const e=n[n.length-1];e&&!e.getAttribute("disabled")&&e.focus()}else if(t.key===" "||t.key==="Enter"){t.preventDefault();const e=n[a];if(e&&!e.getAttribute("disabled")){const r=e.getAttribute("value");if(r){R(r,e);const c=s.current.querySelector(".indicator");c&&(c.style.width=`${e.clientWidth}px`,c.style.transform=`translate3d(${e.offsetLeft}px, 0px, 0px)`,g.current?c.style.transition="all 0.2s ease-in-out":(c.style.transition="unset",g.current=!0))}}}},Y=(t,n)=>{P(t),V(n),K(b.current)},X=(t,n)=>{if(!u.current)return;u.current=!1;const a=D-t,e=T-n;t&&Math.abs(a)<S&&Math.abs(e)<S*2&&(x.current=!0),f.current&&(cancelAnimationFrame(f.current),f.current=void 0)},G=t=>{d&&(u.current=!0,Y(t.clientX,t.clientY))},J=t=>{d&&Y(t.touches[0].clientX,t.touches[0].clientY)},k=t=>X(t.changedTouches[0].clientX,t.changedTouches[0].clientY),q=t=>X(t.clientX,t.clientY);return i.useEffect(()=>{const t=()=>{var n;if(s.current){const a=s.current.querySelector(".indicator"),e=(n=s.current)==null?void 0:n.querySelectorAll('[role="tab"][data-selected="true"]')[0];if(e&&a&&(a.style.width=`${e.clientWidth}px`,a.style.transform=`translate3d(${e.offsetLeft}px, 0px, 0px)`,g.current?a.style.transition="all 0.2s ease-in-out":(a.style.transition="unset",g.current=!0),O(e.getAttribute("data-disabled")==="true")),e&&d){const r=e.offsetLeft,c=e.offsetLeft+e.clientWidth,p=b.current,y=b.current+s.current.clientWidth;if(r<p||c>y){const v=Math.min(r,Math.max(s.current.scrollWidth-s.current.clientWidth,s.current.scrollWidth-y));s.current.style.transition="all 0.2s ease-in-out",s.current.style.transform=`translate3d(-${v}px, 0px, 0px)`,b.current=v}}}};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[d,l,w]),i.useEffect(()=>{const t=s.current,n=(r,c,p)=>{if(!s.current)return;const y=D-r,v=T-c;if(u.current=u.current||Math.abs(y)>S&&Math.abs(v)<S*2,u.current&&p.cancelable&&(p.preventDefault(),p.stopPropagation()),u.current){let h=L+y;const C=s.current.scrollWidth-s.current.clientWidth;h<0?h=0:h>C&&(h=C),s.current&&(f.current&&cancelAnimationFrame(f.current),f.current=requestAnimationFrame(()=>{s.current&&(s.current.style.transition="unset",s.current.style.transform=`translate3d(-${h}px, 0px, 0px)`,b.current=h,N.current=!1)}))}},a=r=>{u.current&&n(r.clientX,r.clientY,r)},e=r=>{n(r.touches[0].clientX,r.touches[0].clientY,r)};return t==null||t.addEventListener("mousemove",a),t==null||t.addEventListener("touchmove",e),()=>{t==null||t.removeEventListener("mousemove",a),t==null||t.removeEventListener("touchmove",e)}},[D,T,L]),A.jsx(B,{className:"tab-wrapper",ref:F,scrollable:d,...m,css:m==null?void 0:m.inlineCSS,children:A.jsxs(tt,{className:"tab-list",role:"tablist",ref:s,isChipped:W,css:I,...j,onMouseDown:G,onMouseUp:q,onMouseLeave:q,onTouchStart:J,onTouchEnd:k,onTouchCancel:k,children:[i.Children.map(E,(t,n)=>{var r,c;if(!i.isValidElement(t))return null;const a=l===t.props.value,e=$||((r=t.props)==null?void 0:r.disabled);return i.cloneElement(t,{...t.props,className:`tab-block-${n}`,selected:a,"aria-selected":a,tabIndex:a?0:-1,onClick:(c=t.props)!=null&&c.disabled?void 0:z(t.props.value),onKeyDown:U,disabled:e,size:w})}),A.jsx(et,{className:"indicator",disabled:$||H,isChipped:W})]})})});exports.default=nt;
18
+ `,A=3,g=Object.freeze({FRICTION:.85,MIN_VELOCITY:.01,MAX_VELOCITY:1.62,STOP_VELOCITY:.02,SAMPLE_DURATION:100}),ut=c.forwardRef(function({value:m,scrollable:h=!1,disabled:k=!1,onChange:w,size:I="medium",inlineCSS:V,wrapperProps:M,children:C,...q},X){const s=c.useRef(null),u=c.useRef(),b=c.useRef(0),j=c.useRef(!0),S=c.useRef(!1),T=c.useRef(!1),l=c.useRef(!1),v=c.useRef([]),[U,H]=c.useState(!1),[E,z]=c.useState(0),[D,K]=c.useState(0),[O,G]=c.useState(0),_=k,Y=c.Children.toArray(C).every(t=>c.isValidElement(t)&&c.Children.toArray(t.props.children).every(r=>c.isValidElement(r)&&!Array.isArray(r.props.children))),J=t=>r=>{h&&!S.current||(w(t,r.currentTarget),S.current=!1)},Q=t=>{if(!s.current)return;const r=s.current.querySelectorAll('[role="tab"]:not([disabled])'),i=Array.from(r).findIndex(e=>e===document.activeElement);if(t.key==="ArrowLeft"){t.preventDefault();const e=i<=0?r.length-1:i-1,n=r[e];n&&!n.getAttribute("disabled")&&n.focus()}else if(t.key==="ArrowRight"){t.preventDefault();const e=i>=r.length-1?0:i+1,n=r[e];n&&!n.getAttribute("disabled")&&n.focus()}else if(t.key==="Home"){t.preventDefault();const e=r[0];e&&!e.getAttribute("disabled")&&e.focus()}else if(t.key==="End"){t.preventDefault();const e=r[r.length-1];e&&!e.getAttribute("disabled")&&e.focus()}else if(t.key===" "||t.key==="Enter"){t.preventDefault();const e=r[i];if(e&&!e.getAttribute("disabled")){const n=e.getAttribute("value");if(n){w(n,e);const a=s.current.querySelector(".indicator");a&&(a.style.width=`${e.clientWidth}px`,a.style.transform=`translate3d(${e.offsetLeft}px, 0px, 0px)`,T.current?a.style.transition="all 0.2s ease-in-out":(a.style.transition="unset",T.current=!0))}}}},Z=t=>{if(t.length<2)return 0;const r=t[0],i=t[t.length-1],e=i.time-r.time,n=i.x-r.x;if(e===0)return 0;const a=n/e;return Math.max(-g.MAX_VELOCITY,Math.min(g.MAX_VELOCITY,a))},p=c.useCallback(t=>{const r=s.current?s.current.scrollWidth-s.current.clientWidth:0;return Math.max(0,Math.min(t,r))},[]),x=c.useCallback(t=>{if(!s.current)return;const r=p(t);s.current.style.transition="unset",s.current.style.transform=`translate3d(-${r}px, 0px, 0px)`,b.current=r},[p]),B=c.useCallback(t=>{u.current&&cancelAnimationFrame(u.current);let r=t*-1,i=b.current,e=performance.now();const n=a=>{if(!s.current)return;const d=a-e;e=a,i=p(i+r*d);const f=i<=0,y=i>=s.current.scrollWidth-s.current.clientWidth;(f&&r<0||y&&r>0)&&(r=0),r*=g.FRICTION,x(i),Math.abs(r)>g.STOP_VELOCITY?u.current=requestAnimationFrame(n):u.current=void 0};u.current=requestAnimationFrame(n)},[p,x]),$=(t,r)=>{u.current&&(cancelAnimationFrame(u.current),u.current=void 0),S.current=!1,z(t),K(r),G(b.current),v.current=[{time:performance.now(),x:t}]},F=(t,r)=>{if(!l.current||!s.current)return;l.current=!1,s.current.style.cursor="grab";const i=E-t,e=D-r;t&&Math.abs(i)<A&&Math.abs(e)<A*2&&(S.current=!0);const n=Z(v.current);v.current=[],u.current&&(cancelAnimationFrame(u.current),u.current=void 0),!S.current&&Math.abs(n)>=g.MIN_VELOCITY&&B(n)},tt=t=>{h&&(l.current=!0,$(t.clientX,t.clientY))},et=t=>{h&&$(t.touches[0].clientX,t.touches[0].clientY)},N=t=>F(t.changedTouches[0].clientX,t.changedTouches[0].clientY),P=t=>F(t.clientX,t.clientY);return c.useEffect(()=>{const t=()=>{var r;if(s.current){const i=s.current.querySelector(".indicator"),e=(r=s.current)==null?void 0:r.querySelectorAll('[role="tab"][data-selected="true"]')[0];if(e&&i&&(i.style.width=`${e.clientWidth}px`,i.style.transform=`translate3d(${e.offsetLeft}px, 0px, 0px)`,T.current?i.style.transition="all 0.2s ease-in-out":(i.style.transition="unset",T.current=!0),H(e.getAttribute("data-disabled")==="true")),e&&h){const n=e.offsetLeft,a=e.offsetLeft+e.clientWidth,d=b.current,f=b.current+s.current.clientWidth;if(n<d||a>f){const y=Math.min(n,Math.max(s.current.scrollWidth-s.current.clientWidth,s.current.scrollWidth-f));s.current.style.transition="all 0.2s ease-in-out",s.current.style.transform=`translate3d(-${y}px, 0px, 0px)`,b.current=y}}}};return t(),window.addEventListener("resize",t),()=>{window.removeEventListener("resize",t)}},[h,m,I]),c.useEffect(()=>{const t=s.current,r=(n,a,d)=>{if(!s.current)return;const f=E-n,y=D-a;if(l.current=l.current||Math.abs(f)>A&&Math.abs(y)<A*2,l.current&&d.cancelable&&(d.preventDefault(),d.stopPropagation()),l.current){const rt=p(O+f),W=performance.now();v.current=[...v.current,{time:W,x:n}].filter(nt=>W-nt.time<=g.SAMPLE_DURATION),s.current&&(u.current&&cancelAnimationFrame(u.current),u.current=requestAnimationFrame(()=>{s.current&&(x(rt),s.current.style.cursor="grabbing",j.current=!1)}))}},i=n=>{l.current&&r(n.clientX,n.clientY,n)},e=n=>{n.stopPropagation(),r(n.touches[0].clientX,n.touches[0].clientY,n)};return t==null||t.addEventListener("mousemove",i),t==null||t.addEventListener("touchmove",e),()=>{t==null||t.removeEventListener("mousemove",i),t==null||t.removeEventListener("touchmove",e)}},[p,E,D,O,x]),c.useEffect(()=>()=>{u.current&&cancelAnimationFrame(u.current)},[]),L.jsx(ct,{className:"tab-wrapper",ref:X,scrollable:h,...M,css:M==null?void 0:M.inlineCSS,children:L.jsxs(ot,{className:"tab-list",role:"tablist",ref:s,isChipped:Y,css:V,...q,onMouseDown:tt,onMouseUp:P,onMouseLeave:P,onTouchStart:et,onTouchEnd:N,onTouchCancel:N,children:[c.Children.map(C,(t,r)=>{var n,a;if(!c.isValidElement(t))return null;const i=m===t.props.value,e=_||((n=t.props)==null?void 0:n.disabled);return c.cloneElement(t,{...t.props,className:`tab-block-${r}`,selected:i,"aria-selected":i,tabIndex:i?0:-1,onClick:(a=t.props)!=null&&a.disabled?void 0:J(t.props.value),onKeyDown:Q,disabled:e,size:I})}),L.jsx(at,{className:"indicator",disabled:_||U,isChipped:Y})]})})});exports.default=ut;
package/Tab/Tab.es.js CHANGED
@@ -1,47 +1,57 @@
1
- import { jsx as N, jsxs as et } from "@emotion/react/jsx-runtime";
2
- import { forwardRef as rt, useRef as l, useState as x, Children as w, isValidElement as M, useEffect as H, cloneElement as nt } from "react";
3
- import L from "@emotion/styled";
4
- const st = L.div`
1
+ import { jsx as U, jsxs as ut } from "@emotion/react/jsx-runtime";
2
+ import { forwardRef as lt, useRef as l, useState as M, Children as w, isValidElement as I, useCallback as O, useEffect as C, cloneElement as dt } from "react";
3
+ import Y from "@emotion/styled";
4
+ const ft = Y.div`
5
5
  width: 100%;
6
- background-color: ${({ theme: o }) => o.palette.grey.white};
7
- ${({ scrollable: o }) => o ? {
8
- overflow: "hidden"
6
+ background-color: ${({ theme: a }) => a.palette.grey.white};
7
+ ${({ scrollable: a }) => a ? {
8
+ overflow: "hidden",
9
+ cursor: "grab",
10
+ '& [role="tab"]': {
11
+ flex: "0 0 auto"
12
+ }
9
13
  } : {}}
10
- `, it = L.div`
14
+ `, mt = Y.div`
11
15
  display: flex;
12
16
  position: relative;
13
- background: ${({ theme: o }) => o.palette.grey.white};
14
- ${({ theme: o, isChipped: u }) => u ? {
15
- gap: o.spacing.content(2)
17
+ background: ${({ theme: a }) => a.palette.grey.white};
18
+ ${({ theme: a, isChipped: m }) => m ? {
19
+ gap: a.spacing.content(2)
16
20
  } : {}}
17
- `, ot = L.div`
21
+ `, ht = Y.div`
18
22
  position: absolute;
19
23
  height: 2px;
20
24
  bottom: 0;
21
- background: ${({ theme: o, disabled: u }) => u ? o.palette.brand.primary.disableLine : o.palette.brand.primary.main};
25
+ background: ${({ theme: a, disabled: m }) => m ? a.palette.brand.primary.disableLine : a.palette.brand.primary.main};
22
26
  transition: all 0.2s ease-in-out;
23
27
  transition-property: transform, width;
24
- ${({ isChipped: o }) => o ? {
28
+ ${({ isChipped: a }) => a ? {
25
29
  display: "none"
26
30
  } : {}}
27
- `, S = 3, ut = rt(function({
28
- value: u,
29
- scrollable: d = !1,
31
+ `, L = 3, g = Object.freeze({
32
+ FRICTION: 0.85,
33
+ MIN_VELOCITY: 0.01,
34
+ MAX_VELOCITY: 1.62,
35
+ STOP_VELOCITY: 0.02,
36
+ SAMPLE_DURATION: 100
37
+ }), gt = lt(function({
38
+ value: m,
39
+ scrollable: h = !1,
30
40
  disabled: j = !1,
31
- onChange: E,
41
+ onChange: R,
32
42
  size: $ = "medium",
33
- inlineCSS: K,
34
- wrapperProps: m,
35
- children: R,
36
- ...O
37
- }, P) {
38
- const s = l(null), f = l(), p = l(0), z = l(!0), D = l(!1), g = l(!1), c = l(!1), [U, V] = x(!1), [T, _] = x(0), [A, G] = x(0), [W, J] = x(0), Y = j, X = w.toArray(R).every((t) => M(t) && w.toArray(t.props.children).every(
39
- (r) => M(r) && !Array.isArray(r.props.children)
40
- )), Q = (t) => (r) => {
41
- d && !D.current || (E(t, r.currentTarget), D.current = !1);
42
- }, Z = (t) => {
43
- if (!s.current) return;
44
- const r = s.current.querySelectorAll(
43
+ inlineCSS: H,
44
+ wrapperProps: v,
45
+ children: F,
46
+ ...z
47
+ }, K) {
48
+ const o = l(null), c = l(), p = l(0), G = l(!0), S = l(!1), x = l(!1), u = l(!1), T = l([]), [J, Q] = M(!1), [D, Z] = M(0), [E, B] = M(0), [N, tt] = M(0), W = j, P = w.toArray(F).every((t) => I(t) && w.toArray(t.props.children).every(
49
+ (r) => I(r) && !Array.isArray(r.props.children)
50
+ )), et = (t) => (r) => {
51
+ h && !S.current || (R(t, r.currentTarget), S.current = !1);
52
+ }, rt = (t) => {
53
+ if (!o.current) return;
54
+ const r = o.current.querySelectorAll(
45
55
  '[role="tab"]:not([disabled])'
46
56
  ), i = Array.from(r).findIndex((e) => e === document.activeElement);
47
57
  if (t.key === "ArrowLeft") {
@@ -66,42 +76,77 @@ const st = L.div`
66
76
  if (e && !e.getAttribute("disabled")) {
67
77
  const n = e.getAttribute("value");
68
78
  if (n) {
69
- E(n, e);
70
- const a = s.current.querySelector(".indicator");
71
- a && (a.style.width = `${e.clientWidth}px`, a.style.transform = `translate3d(${e.offsetLeft}px, 0px, 0px)`, g.current ? a.style.transition = "all 0.2s ease-in-out" : (a.style.transition = "unset", g.current = !0));
79
+ R(n, e);
80
+ const s = o.current.querySelector(".indicator");
81
+ s && (s.style.width = `${e.clientWidth}px`, s.style.transform = `translate3d(${e.offsetLeft}px, 0px, 0px)`, x.current ? s.style.transition = "all 0.2s ease-in-out" : (s.style.transition = "unset", x.current = !0));
72
82
  }
73
83
  }
74
84
  }
75
- }, k = (t, r) => {
76
- _(t), G(r), J(p.current);
77
- }, I = (t, r) => {
78
- if (!c.current) return;
79
- c.current = !1;
80
- const i = T - t, e = A - r;
81
- t && Math.abs(i) < S && Math.abs(e) < S * 2 && (D.current = !0), f.current && (cancelAnimationFrame(f.current), f.current = void 0);
82
- }, B = (t) => {
83
- d && (c.current = !0, k(t.clientX, t.clientY));
84
- }, tt = (t) => {
85
- d && k(t.touches[0].clientX, t.touches[0].clientY);
86
- }, C = (t) => I(t.changedTouches[0].clientX, t.changedTouches[0].clientY), q = (t) => I(t.clientX, t.clientY);
87
- return H(() => {
85
+ }, nt = (t) => {
86
+ if (t.length < 2) return 0;
87
+ const r = t[0], i = t[t.length - 1], e = i.time - r.time, n = i.x - r.x;
88
+ if (e === 0) return 0;
89
+ const s = n / e;
90
+ return Math.max(
91
+ -g.MAX_VELOCITY,
92
+ Math.min(g.MAX_VELOCITY, s)
93
+ );
94
+ }, b = O((t) => {
95
+ const r = o.current ? o.current.scrollWidth - o.current.clientWidth : 0;
96
+ return Math.max(0, Math.min(t, r));
97
+ }, []), A = O(
98
+ (t) => {
99
+ if (!o.current) return;
100
+ const r = b(t);
101
+ o.current.style.transition = "unset", o.current.style.transform = `translate3d(-${r}px, 0px, 0px)`, p.current = r;
102
+ },
103
+ [b]
104
+ ), ot = O(
105
+ (t) => {
106
+ c.current && cancelAnimationFrame(c.current);
107
+ let r = t * -1, i = p.current, e = performance.now();
108
+ const n = (s) => {
109
+ if (!o.current) return;
110
+ const d = s - e;
111
+ e = s, i = b(i + r * d);
112
+ const f = i <= 0, y = i >= o.current.scrollWidth - o.current.clientWidth;
113
+ (f && r < 0 || y && r > 0) && (r = 0), r *= g.FRICTION, A(i), Math.abs(r) > g.STOP_VELOCITY ? c.current = requestAnimationFrame(n) : c.current = void 0;
114
+ };
115
+ c.current = requestAnimationFrame(n);
116
+ },
117
+ [b, A]
118
+ ), _ = (t, r) => {
119
+ c.current && (cancelAnimationFrame(c.current), c.current = void 0), S.current = !1, Z(t), B(r), tt(p.current), T.current = [{ time: performance.now(), x: t }];
120
+ }, X = (t, r) => {
121
+ if (!u.current || !o.current) return;
122
+ u.current = !1, o.current.style.cursor = "grab";
123
+ const i = D - t, e = E - r;
124
+ t && Math.abs(i) < L && Math.abs(e) < L * 2 && (S.current = !0);
125
+ const n = nt(T.current);
126
+ T.current = [], c.current && (cancelAnimationFrame(c.current), c.current = void 0), !S.current && Math.abs(n) >= g.MIN_VELOCITY && ot(n);
127
+ }, it = (t) => {
128
+ h && (u.current = !0, _(t.clientX, t.clientY));
129
+ }, st = (t) => {
130
+ h && _(t.touches[0].clientX, t.touches[0].clientY);
131
+ }, k = (t) => X(t.changedTouches[0].clientX, t.changedTouches[0].clientY), V = (t) => X(t.clientX, t.clientY);
132
+ return C(() => {
88
133
  const t = () => {
89
134
  var r;
90
- if (s.current) {
91
- const i = s.current.querySelector(".indicator"), e = (r = s.current) == null ? void 0 : r.querySelectorAll(
135
+ if (o.current) {
136
+ const i = o.current.querySelector(".indicator"), e = (r = o.current) == null ? void 0 : r.querySelectorAll(
92
137
  '[role="tab"][data-selected="true"]'
93
138
  )[0];
94
- if (e && i && (i.style.width = `${e.clientWidth}px`, i.style.transform = `translate3d(${e.offsetLeft}px, 0px, 0px)`, g.current ? i.style.transition = "all 0.2s ease-in-out" : (i.style.transition = "unset", g.current = !0), V(e.getAttribute("data-disabled") === "true")), e && d) {
95
- const n = e.offsetLeft, a = e.offsetLeft + e.clientWidth, b = p.current, y = p.current + s.current.clientWidth;
96
- if (n < b || a > y) {
97
- const v = Math.min(
139
+ if (e && i && (i.style.width = `${e.clientWidth}px`, i.style.transform = `translate3d(${e.offsetLeft}px, 0px, 0px)`, x.current ? i.style.transition = "all 0.2s ease-in-out" : (i.style.transition = "unset", x.current = !0), Q(e.getAttribute("data-disabled") === "true")), e && h) {
140
+ const n = e.offsetLeft, s = e.offsetLeft + e.clientWidth, d = p.current, f = p.current + o.current.clientWidth;
141
+ if (n < d || s > f) {
142
+ const y = Math.min(
98
143
  n,
99
144
  Math.max(
100
- s.current.scrollWidth - s.current.clientWidth,
101
- s.current.scrollWidth - y
145
+ o.current.scrollWidth - o.current.clientWidth,
146
+ o.current.scrollWidth - f
102
147
  )
103
148
  );
104
- s.current.style.transition = "all 0.2s ease-in-out", s.current.style.transform = `translate3d(-${v}px, 0px, 0px)`, p.current = v;
149
+ o.current.style.transition = "all 0.2s ease-in-out", o.current.style.transform = `translate3d(-${y}px, 0px, 0px)`, p.current = y;
105
150
  }
106
151
  }
107
152
  }
@@ -109,72 +154,76 @@ const st = L.div`
109
154
  return t(), window.addEventListener("resize", t), () => {
110
155
  window.removeEventListener("resize", t);
111
156
  };
112
- }, [d, u, $]), H(() => {
113
- const t = s.current, r = (n, a, b) => {
114
- if (!s.current) return;
115
- const y = T - n, v = A - a;
116
- if (c.current = c.current || Math.abs(y) > S && Math.abs(v) < S * 2, c.current && b.cancelable && (b.preventDefault(), b.stopPropagation()), c.current) {
117
- let h = W + y;
118
- const F = s.current.scrollWidth - s.current.clientWidth;
119
- h < 0 ? h = 0 : h > F && (h = F), s.current && (f.current && cancelAnimationFrame(f.current), f.current = requestAnimationFrame(() => {
120
- s.current && (s.current.style.transition = "unset", s.current.style.transform = `translate3d(-${h}px, 0px, 0px)`, p.current = h, z.current = !1);
157
+ }, [h, m, $]), C(() => {
158
+ const t = o.current, r = (n, s, d) => {
159
+ if (!o.current) return;
160
+ const f = D - n, y = E - s;
161
+ if (u.current = u.current || Math.abs(f) > L && Math.abs(y) < L * 2, u.current && d.cancelable && (d.preventDefault(), d.stopPropagation()), u.current) {
162
+ const ct = b(N + f), q = performance.now();
163
+ T.current = [
164
+ ...T.current,
165
+ { time: q, x: n }
166
+ ].filter((at) => q - at.time <= g.SAMPLE_DURATION), o.current && (c.current && cancelAnimationFrame(c.current), c.current = requestAnimationFrame(() => {
167
+ o.current && (A(ct), o.current.style.cursor = "grabbing", G.current = !1);
121
168
  }));
122
169
  }
123
170
  }, i = (n) => {
124
- c.current && r(n.clientX, n.clientY, n);
171
+ u.current && r(n.clientX, n.clientY, n);
125
172
  }, e = (n) => {
126
- r(n.touches[0].clientX, n.touches[0].clientY, n);
173
+ n.stopPropagation(), r(n.touches[0].clientX, n.touches[0].clientY, n);
127
174
  };
128
175
  return t == null || t.addEventListener("mousemove", i), t == null || t.addEventListener("touchmove", e), () => {
129
176
  t == null || t.removeEventListener("mousemove", i), t == null || t.removeEventListener("touchmove", e);
130
177
  };
131
- }, [T, A, W]), /* @__PURE__ */ N(
132
- st,
178
+ }, [b, D, E, N, A]), C(() => () => {
179
+ c.current && cancelAnimationFrame(c.current);
180
+ }, []), /* @__PURE__ */ U(
181
+ ft,
133
182
  {
134
183
  className: "tab-wrapper",
135
- ref: P,
136
- scrollable: d,
137
- ...m,
138
- css: m == null ? void 0 : m.inlineCSS,
139
- children: /* @__PURE__ */ et(
140
- it,
184
+ ref: K,
185
+ scrollable: h,
186
+ ...v,
187
+ css: v == null ? void 0 : v.inlineCSS,
188
+ children: /* @__PURE__ */ ut(
189
+ mt,
141
190
  {
142
191
  className: "tab-list",
143
192
  role: "tablist",
144
- ref: s,
145
- isChipped: X,
146
- css: K,
147
- ...O,
148
- onMouseDown: B,
149
- onMouseUp: q,
150
- onMouseLeave: q,
151
- onTouchStart: tt,
152
- onTouchEnd: C,
153
- onTouchCancel: C,
193
+ ref: o,
194
+ isChipped: P,
195
+ css: H,
196
+ ...z,
197
+ onMouseDown: it,
198
+ onMouseUp: V,
199
+ onMouseLeave: V,
200
+ onTouchStart: st,
201
+ onTouchEnd: k,
202
+ onTouchCancel: k,
154
203
  children: [
155
- w.map(R, (t, r) => {
156
- var n, a;
157
- if (!M(t))
204
+ w.map(F, (t, r) => {
205
+ var n, s;
206
+ if (!I(t))
158
207
  return null;
159
- const i = u === t.props.value, e = Y || ((n = t.props) == null ? void 0 : n.disabled);
160
- return nt(t, {
208
+ const i = m === t.props.value, e = W || ((n = t.props) == null ? void 0 : n.disabled);
209
+ return dt(t, {
161
210
  ...t.props,
162
211
  className: `tab-block-${r}`,
163
212
  selected: i,
164
213
  "aria-selected": i,
165
214
  tabIndex: i ? 0 : -1,
166
- onClick: (a = t.props) != null && a.disabled ? void 0 : Q(t.props.value),
167
- onKeyDown: Z,
215
+ onClick: (s = t.props) != null && s.disabled ? void 0 : et(t.props.value),
216
+ onKeyDown: rt,
168
217
  disabled: e,
169
218
  size: $
170
219
  });
171
220
  }),
172
- /* @__PURE__ */ N(
173
- ot,
221
+ /* @__PURE__ */ U(
222
+ ht,
174
223
  {
175
224
  className: "indicator",
176
- disabled: Y || U,
177
- isChipped: X
225
+ disabled: W || J,
226
+ isChipped: P
178
227
  }
179
228
  )
180
229
  ]
@@ -184,5 +233,5 @@ const st = L.div`
184
233
  );
185
234
  });
186
235
  export {
187
- ut as default
236
+ gt as default
188
237
  };
@@ -1,11 +1,11 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const c=require("@emotion/react/jsx-runtime"),d=require("react"),p=require("../../Chip/Chip.cjs"),h=require("@emotion/styled"),b=e=>e&&e.__esModule?e:{default:e},x=b(h),y=x.default.div`
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const f=require("@emotion/react/jsx-runtime"),d=require("react"),m=require("../../Chip/Chip.cjs"),p=require("@emotion/styled"),x=t=>t&&t.__esModule?t:{default:t},h=x(p),y=h.default.div`
2
2
  display: flex;
3
3
  flex: 1;
4
4
  justify-content: center;
5
5
  align-items: center;
6
- padding: ${({theme:{spacing:e},size:t})=>t==="small"?`${e.content(2)}px ${e.content(3)}px`:`${e.content(3)}px ${e.content(4)}px`};
7
- border-bottom: ${({theme:e})=>`1px solid ${e.palette.grey[10]}`};
8
- cursor: ${({disabled:e})=>e?"not-allowed":"pointer"};
6
+ padding: ${({theme:{spacing:t},size:r})=>r==="small"?`${t.content(2)}px ${t.content(3)}px`:`${t.content(3)}px ${t.content(4)}px`};
7
+ border-bottom: ${({theme:t})=>`1px solid ${t.palette.grey[10]}`};
8
+ cursor: ${({disabled:t})=>t?"not-allowed":"pointer"};
9
9
 
10
- ${({theme:{typography:e,palette:t},size:r,selected:o,disabled:i})=>{if(o){const{size:n,weight:s,lineHeight:g,letterSpacing:m}=e[r==="medium"?"h4B":"h5B"];return{fontSize:n,fontWeight:s,lineHeight:g,letterSpacing:m,color:i?t.grey[30]:t.grey[100]}}const{size:f,weight:a,lineHeight:l,letterSpacing:u}=e[r==="medium"?"b2R":"b4R"];return{fontSize:f,fontWeight:a,lineHeight:l,letterSpacing:u,color:i?t.grey[30]:t.grey[70]}}}}
11
- `,$=d.forwardRef(function({size:t="medium",selected:r,disabled:o=!1,inlineCSS:i,children:f,onClick:a,...l},u){return c.jsx(c.Fragment,{children:d.Children.map(f,n=>{var s;return d.isValidElement(n)&&!Array.isArray((s=n==null?void 0:n.props)==null?void 0:s.children)?c.jsx(p.default,{tag:"button",role:"tab",ref:u,"data-shape":"chip","data-selected":r,disabled:o,variant:r?"filled":"outlined",selected:r,onClick:a,inlineCSS:i,...n.props,...l}):c.jsx(y,{as:"button",role:"tab",ref:u,size:t,disabled:o,selected:r,"data-selected":r,"data-disabled":o,onClick:a,css:i,...l,children:n})})})});exports.default=$;
10
+ ${({theme:{typography:t,palette:r},size:e,selected:o,disabled:a})=>{if(o){const{size:g,weight:n,lineHeight:c,letterSpacing:b}=t[e==="medium"?"h4B":"h5B"];return{fontSize:g,fontWeight:n,lineHeight:c,letterSpacing:b,color:a?r.grey[30]:r.grey[100]}}const{size:i,weight:u,lineHeight:l,letterSpacing:s}=t[e==="medium"?"b2R":"b4R"];return{fontSize:i,fontWeight:u,lineHeight:l,letterSpacing:s,color:a?r.grey[30]:r.grey[70]}}}}
11
+ `,$=d.forwardRef(function({size:r="medium",selected:e,disabled:o=!1,inlineCSS:a,children:i,onClick:u,...l},s){var g;return((g=d.Children.toArray(i))==null?void 0:g.length)!==1?f.jsx(y,{as:"button",role:"tab",ref:s,size:r,disabled:o,selected:e,"data-selected":e,"data-disabled":o,onClick:u,css:a,...l,children:i}):f.jsx(f.Fragment,{children:d.Children.map(i,n=>{var c;return d.isValidElement(n)&&n.type===m.default&&!Array.isArray((c=n==null?void 0:n.props)==null?void 0:c.children)?f.jsx(m.default,{tag:"button",role:"tab",ref:s,"data-shape":"chip","data-selected":e,disabled:o,variant:e?"filled":"outlined",selected:e,onClick:u,inlineCSS:a,...n.props,...l}):f.jsx(y,{as:"button",role:"tab",ref:s,size:r,disabled:o,selected:e,"data-selected":e,"data-disabled":o,onClick:u,css:a,...l,children:n})})})});exports.default=$;
@@ -1,84 +1,101 @@
1
- import { jsx as u, Fragment as c } from "@emotion/react/jsx-runtime";
2
- import { forwardRef as d, Children as h, isValidElement as b } from "react";
3
- import x from "../../Chip/Chip.es.js";
4
- import y from "@emotion/styled";
5
- const $ = y.div`
1
+ import { jsx as p, Fragment as h } from "@emotion/react/jsx-runtime";
2
+ import { forwardRef as x, Children as s, isValidElement as $ } from "react";
3
+ import y from "../../Chip/Chip.es.js";
4
+ import d from "@emotion/styled";
5
+ const b = d.div`
6
6
  display: flex;
7
7
  flex: 1;
8
8
  justify-content: center;
9
9
  align-items: center;
10
- padding: ${({ theme: { spacing: t }, size: e }) => e === "small" ? `${t.content(2)}px ${t.content(3)}px` : `${t.content(3)}px ${t.content(4)}px`};
10
+ padding: ${({ theme: { spacing: t }, size: r }) => r === "small" ? `${t.content(2)}px ${t.content(3)}px` : `${t.content(3)}px ${t.content(4)}px`};
11
11
  border-bottom: ${({ theme: t }) => `1px solid ${t.palette.grey[10]}`};
12
12
  cursor: ${({ disabled: t }) => t ? "not-allowed" : "pointer"};
13
13
 
14
- ${({ theme: { typography: t, palette: e }, size: r, selected: o, disabled: i }) => {
15
- if (o) {
14
+ ${({ theme: { typography: t, palette: r }, size: e, selected: n, disabled: a }) => {
15
+ if (n) {
16
16
  const {
17
- size: n,
18
- weight: f,
19
- lineHeight: p,
20
- letterSpacing: s
21
- } = t[r === "medium" ? "h4B" : "h5B"];
17
+ size: u,
18
+ weight: o,
19
+ lineHeight: l,
20
+ letterSpacing: c
21
+ } = t[e === "medium" ? "h4B" : "h5B"];
22
22
  return {
23
- fontSize: n,
24
- fontWeight: f,
25
- lineHeight: p,
26
- letterSpacing: s,
27
- color: i ? e.grey[30] : e.grey[100]
23
+ fontSize: u,
24
+ fontWeight: o,
25
+ lineHeight: l,
26
+ letterSpacing: c,
27
+ color: a ? r.grey[30] : r.grey[100]
28
28
  };
29
29
  }
30
30
  const {
31
- size: g,
32
- weight: a,
33
- lineHeight: l,
34
- letterSpacing: m
35
- } = t[r === "medium" ? "b2R" : "b4R"];
31
+ size: i,
32
+ weight: m,
33
+ lineHeight: f,
34
+ letterSpacing: g
35
+ } = t[e === "medium" ? "b2R" : "b4R"];
36
36
  return {
37
- fontSize: g,
38
- fontWeight: a,
39
- lineHeight: l,
40
- letterSpacing: m,
41
- color: i ? e.grey[30] : e.grey[70]
37
+ fontSize: i,
38
+ fontWeight: m,
39
+ lineHeight: f,
40
+ letterSpacing: g,
41
+ color: a ? r.grey[30] : r.grey[70]
42
42
  };
43
43
  }}}
44
- `, H = d(function({ size: e = "medium", selected: r, disabled: o = !1, inlineCSS: i, children: g, onClick: a, ...l }, m) {
45
- return /* @__PURE__ */ u(c, { children: h.map(g, (n) => {
46
- var f;
47
- return b(n) && !Array.isArray((f = n == null ? void 0 : n.props) == null ? void 0 : f.children) ? /* @__PURE__ */ u(
48
- x,
44
+ `, z = x(function({ size: r = "medium", selected: e, disabled: n = !1, inlineCSS: a, children: i, onClick: m, ...f }, g) {
45
+ var u;
46
+ return ((u = s.toArray(i)) == null ? void 0 : u.length) !== 1 ? /* @__PURE__ */ p(
47
+ b,
48
+ {
49
+ as: "button",
50
+ role: "tab",
51
+ ref: g,
52
+ size: r,
53
+ disabled: n,
54
+ selected: e,
55
+ "data-selected": e,
56
+ "data-disabled": n,
57
+ onClick: m,
58
+ css: a,
59
+ ...f,
60
+ children: i
61
+ }
62
+ ) : /* @__PURE__ */ p(h, { children: s.map(i, (o) => {
63
+ var l;
64
+ return $(o) && o.type === y && !Array.isArray((l = o == null ? void 0 : o.props) == null ? void 0 : l.children) ? /* @__PURE__ */ p(
65
+ y,
49
66
  {
50
67
  tag: "button",
51
68
  role: "tab",
52
- ref: m,
69
+ ref: g,
53
70
  "data-shape": "chip",
54
- "data-selected": r,
55
- disabled: o,
56
- variant: r ? "filled" : "outlined",
57
- selected: r,
58
- onClick: a,
59
- inlineCSS: i,
60
- ...n.props,
61
- ...l
71
+ "data-selected": e,
72
+ disabled: n,
73
+ variant: e ? "filled" : "outlined",
74
+ selected: e,
75
+ onClick: m,
76
+ inlineCSS: a,
77
+ ...o.props,
78
+ ...f
62
79
  }
63
- ) : /* @__PURE__ */ u(
64
- $,
80
+ ) : /* @__PURE__ */ p(
81
+ b,
65
82
  {
66
83
  as: "button",
67
84
  role: "tab",
68
- ref: m,
69
- size: e,
70
- disabled: o,
71
- selected: r,
72
- "data-selected": r,
73
- "data-disabled": o,
74
- onClick: a,
75
- css: i,
76
- ...l,
77
- children: n
85
+ ref: g,
86
+ size: r,
87
+ disabled: n,
88
+ selected: e,
89
+ "data-selected": e,
90
+ "data-disabled": n,
91
+ onClick: m,
92
+ css: a,
93
+ ...f,
94
+ children: o
78
95
  }
79
96
  );
80
97
  }) });
81
98
  });
82
99
  export {
83
- H as default
100
+ z as default
84
101
  };