@gearbox-protocol/ui-kit 3.14.0-next.58 → 3.14.0-next.59
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),v=require("class-variance-authority"),s=require("react");require("@gearbox-protocol/sdk");const x=require("../../utils/cn.cjs");require("sonner");require("@gearbox-protocol/sdk/common-utils");require("luxon");require("../../utils/z-index.cjs");function q(r){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const a=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(o,t,a.get?a:{enumerable:!0,get:()=>r[t]})}}return o.default=r,Object.freeze(o)}const w=q(s),j=v.cva("relative z-0
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("react/jsx-runtime"),v=require("class-variance-authority"),s=require("react");require("@gearbox-protocol/sdk");const x=require("../../utils/cn.cjs");require("sonner");require("@gearbox-protocol/sdk/common-utils");require("luxon");require("../../utils/z-index.cjs");function q(r){const o=Object.create(null,{[Symbol.toStringTag]:{value:"Module"}});if(r){for(const t in r)if(t!=="default"){const a=Object.getOwnPropertyDescriptor(r,t);Object.defineProperty(o,t,a.get?a:{enumerable:!0,get:()=>r[t]})}}return o.default=r,Object.freeze(o)}const w=q(s),j=v.cva("relative z-0 w-full grid grid-flow-col auto-cols-[1fr] bg-gray-30",{variants:{size:{sm:"h-[28px] rounded-sm text-xs leading-[130%]",md:"h-[40px] rounded-lg text-[0.9375rem] leading-[18px]"}},defaultVariants:{size:"md"}}),k=v.cva("",{variants:{size:{sm:"rounded-sm",md:"rounded-lg"}},defaultVariants:{size:"md"}}),C=w.forwardRef(({className:r,name:o,items:t,size:a="md",...h},n)=>{const l=t.findIndex(e=>e.checked),u=l<0?0:l,c=t.length,f=s.useRef(null),p=s.useRef([]),[b,y]=s.useState({left:0,width:0}),m=s.useCallback(()=>{const e=p.current[u];if(!e||c===0){y({left:0,width:0});return}y({left:e.offsetLeft,width:e.offsetWidth})},[c,u]);s.useLayoutEffect(()=>{m()},[m]),s.useLayoutEffect(()=>{const e=new ResizeObserver(()=>m()),d=f.current;d&&e.observe(d);for(const g of p.current)g&&e.observe(g);return()=>e.disconnect()},[m]);const S=s.useCallback(e=>{f.current=e,typeof n=="function"?n(e):n&&(n.current=e)},[n]);return i.jsxs("div",{ref:S,className:x.cn(j({size:a}),r),...h,children:[t.map((e,d)=>i.jsx(R,{...e,name:o,ref:g=>{p.current[d]=g}},typeof e.value=="string"?e.value:d)),i.jsx("div",{className:x.cn("pointer-events-none absolute top-0 left-0 z-[-1] h-full bg-gray-60 shadow-[0_2px_2px_rgba(0,0,0,0.25)] transition-[transform,width] duration-200 ease-in-out",k({size:a})),style:b.width>0?{width:`${b.width}px`,transform:`translateX(${b.left}px)`}:{width:c>0?`${100/c}%`:"0%",transform:c>0?`translateX(${100*u}%)`:"translateX(0)"}})]})});C.displayName="SegmentedControl";const R=w.forwardRef(function({name:o,switchLabel:t,label:a,onChange:h,onSelect:n,...l},u){const c=h??(n?f=>{f.preventDefault(),n()}:void 0);return i.jsxs("label",{ref:u,className:x.cn("relative m-0 h-full cursor-pointer select-none",l.disabled&&"cursor-default opacity-50"),"data-checked":l.checked,"data-disabled":l.disabled,children:[i.jsx("input",{type:"radio",name:o,className:"absolute h-0 w-0 cursor-pointer opacity-0",...l,onChange:c}),i.jsx("span",{className:"flex h-full grow shrink-0 basis-0 items-center justify-center px-2 py-1",children:t??a})]})});R.displayName="SegmentedControlItem";exports.SegmentedControl=C;exports.segmentedControlVariants=j;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsxs as C, jsx as f } from "react/jsx-runtime";
|
|
2
2
|
import { cva as R } from "class-variance-authority";
|
|
3
3
|
import * as N from "react";
|
|
4
|
-
import { useRef as
|
|
4
|
+
import { useRef as x, useState as I, useCallback as v, useLayoutEffect as y } from "react";
|
|
5
5
|
import "@gearbox-protocol/sdk";
|
|
6
6
|
import { cn as g } from "../../utils/cn.js";
|
|
7
7
|
import "sonner";
|
|
@@ -9,7 +9,7 @@ import "@gearbox-protocol/sdk/common-utils";
|
|
|
9
9
|
import "luxon";
|
|
10
10
|
import "../../utils/z-index.js";
|
|
11
11
|
const S = R(
|
|
12
|
-
"relative z-0
|
|
12
|
+
"relative z-0 w-full grid grid-flow-col auto-cols-[1fr] bg-gray-30",
|
|
13
13
|
{
|
|
14
14
|
variants: {
|
|
15
15
|
size: {
|
|
@@ -28,13 +28,13 @@ const S = R(
|
|
|
28
28
|
},
|
|
29
29
|
defaultVariants: { size: "md" }
|
|
30
30
|
}), $ = N.forwardRef(({ className: b, name: m, items: n, size: l = "md", ...u }, t) => {
|
|
31
|
-
const r = n.findIndex((e) => e.checked), s = r < 0 ? 0 : r, o = n.length, d =
|
|
31
|
+
const r = n.findIndex((e) => e.checked), s = r < 0 ? 0 : r, o = n.length, d = x(null), p = x([]), [h, w] = I({ left: 0, width: 0 }), i = v(() => {
|
|
32
32
|
const e = p.current[s];
|
|
33
33
|
if (!e || o === 0) {
|
|
34
|
-
|
|
34
|
+
w({ left: 0, width: 0 });
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
w({
|
|
38
38
|
left: e.offsetLeft,
|
|
39
39
|
width: e.offsetWidth
|
|
40
40
|
});
|