ivt
Version:
Ivt Components Library
3 lines (2 loc) • 6.43 kB
JavaScript
import{cva as e}from"class-variance-authority";import*as t from"react";import{c as r}from"../chunks/utils-C-nkZ_Ir.mjs";import{c as a}from"../chunks/createLucideIcon-D1jKv6AP.mjs";import{X as n}from"../chunks/x-COocN1ks.mjs";import{S as s}from"../chunks/separator-BvKHt1fs.mjs";import{C as o}from"../chunks/chevron-down-CxCeX9iY.mjs";import{C as m}from"../chunks/check-PTeDoR8O.mjs";import{C as l,b as c,c as i,d as u,e as d,f as p,h}from"../chunks/command-uwBExuyh.mjs";import{P as f,a as x,b as g}from"../chunks/popover-DLVlIkos.mjs";import{B as k}from"../chunks/button-CWf6NSDH.mjs";import{B as v}from"../chunks/badge-Dk_-nk4S.mjs";import"../chunks/bundle-mjs-DHbvkKp4.mjs";import"../chunks/index-DiPp8h7C.mjs";import"react-dom";import"@radix-ui/react-slot";import"react/jsx-runtime";import"../chunks/index-D1EuiH1M.mjs";import"../chunks/index-DVnblQ-a.mjs";import"../chunks/index-C-j8pU3U.mjs";import"../chunks/index-Dr5ObK3L.mjs";import"../chunks/index-UQBMY2z8.mjs";import"../chunks/index-0-u0cdz8.mjs";import"../chunks/index-BOUg6o32.mjs";import"../chunks/index-C_Mk3Jfk.mjs";import"../chunks/index-DSUHCtxx.mjs";import"../chunks/index-lVEpnR8T.mjs";import"../chunks/tslib.es6-Bvey-QDo.mjs";import"../chunks/index-1xuBLrml.mjs";import"../chunks/dialog-Dxotsves.mjs";import"../chunks/index-DtZD7YmJ.mjs";import"../chunks/index-CnLJ482V.mjs";const y=a("CircleX",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m15 9-6 6",key:"1uzhvr"}],["path",{d:"m9 9 6 6",key:"z0biqf"}]]),b=a("WandSparkles",[["path",{d:"m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72",key:"ul74o6"}],["path",{d:"m14 7 3 3",key:"1r5n42"}],["path",{d:"M5 6v4",key:"ilb8ba"}],["path",{d:"M19 14v4",key:"blhpug"}],["path",{d:"M10 2v2",key:"7u0qdc"}],["path",{d:"M7 8H3",key:"zfb6yr"}],["path",{d:"M21 16h-4",key:"1cnmox"}],["path",{d:"M11 3H9",key:"1obp7u"}]]),E=e("m-1 transition ease-in-out delay-150 hover:-translate-y-1 hover:scale-110 duration-300",{variants:{variant:{default:"border-foreground/10 text-foreground bg-card hover:bg-card/80",secondary:"border-foreground/10 bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground hover:bg-destructive/80",inverted:"inverted"}},defaultVariants:{variant:"default"}}),j=t.forwardRef(({options:e,onValueChange:a,variant:j,defaultValue:N=[],placeholder:w="Select options",animation:C=0,maxCount:S=3,modalPopover:M=!1,asChild:P=!1,className:B,...D},q)=>{const[z,L]=t.useState(N),[V,$]=t.useState(!1),[_,H]=t.useState(!1),K=e=>{const t=z.includes(e)?z.filter(t=>t!==e):[...z,e];L(t),a(t)},A=()=>{L([]),a([])};return t.createElement(f,{open:V,onOpenChange:$,modal:M},t.createElement(x,{asChild:!0},t.createElement(k,{ref:q,...D,onClick:()=>{$(e=>!e)},className:r("flex h-auto min-h-10 w-full items-center justify-between rounded-md border bg-inherit p-1 hover:bg-inherit [&_svg]:pointer-events-auto",B)},z.length>0?t.createElement("div",{className:"flex w-full items-center justify-between"},t.createElement("div",{className:"flex flex-wrap items-center"},z.slice(0,S).map(a=>{const n=e.find(e=>e.value===a),s=n?.icon;return t.createElement(v,{key:a,className:r(_?"animate-bounce":"",E({variant:j})),style:{animationDuration:`${C}s`}},s&&t.createElement(s,{className:"mr-2 h-4 w-4"}),n?.label,t.createElement(y,{className:"ml-2 h-4 w-4 cursor-pointer",onClick:e=>{e.stopPropagation(),K(a)}}))}),z.length>S&&t.createElement(v,{className:r("text-foreground border-foreground/1 bg-transparent hover:bg-transparent",_?"animate-bounce":"",E({variant:j})),style:{animationDuration:`${C}s`}},`+ ${z.length-S} more`,t.createElement(y,{className:"ml-2 h-4 w-4 cursor-pointer",onClick:e=>{e.stopPropagation(),(()=>{const e=z.slice(0,S);L(e),a(e)})()}}))),t.createElement("div",{className:"flex items-center justify-between"},t.createElement(n,{className:"text-muted-foreground mx-2 h-4 cursor-pointer",onClick:e=>{e.stopPropagation(),A()}}),t.createElement(s,{orientation:"vertical",className:"flex h-full min-h-6"}),t.createElement(o,{className:"text-muted-foreground mx-2 h-4 cursor-pointer"}))):t.createElement("div",{className:"mx-auto flex w-full items-center justify-between"},t.createElement("span",{className:"text-muted-foreground mx-3 text-sm"},w),t.createElement(o,{className:"text-muted-foreground mx-2 h-4 cursor-pointer"})))),t.createElement(g,{className:"w-auto p-0",align:"start",onEscapeKeyDown:()=>$(!1)},t.createElement(l,null,t.createElement(c,{placeholder:"Search...",onKeyDown:e=>{if("Enter"===e.key)$(!0);else if("Backspace"===e.key&&!e.currentTarget.value){const e=[...z];e.pop(),L(e),a(e)}}}),t.createElement(i,null,t.createElement(u,null,"No results found."),t.createElement(d,null,t.createElement(p,{key:"all",onSelect:()=>{if(z.length===e.length)A();else{const t=e.map(e=>e.value);L(t),a(t)}},className:"cursor-pointer"},t.createElement("div",{className:r("border-primary mr-2 flex h-4 w-4 items-center justify-center rounded-sm border",z.length===e.length?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible")},t.createElement(m,{className:"h-4 w-4 text-white"})),t.createElement("span",null,"(Select All)")),e.map(e=>{const a=z.includes(e.value);return t.createElement(p,{key:e.value,onSelect:()=>K(e.value),className:"cursor-pointer"},t.createElement("div",{className:r("border-primary mr-2 flex h-4 w-4 items-center justify-center rounded-sm border",a?"bg-primary text-primary-foreground":"opacity-50 [&_svg]:invisible")},t.createElement(m,{className:"h-4 w-4 text-white"})),e.icon&&t.createElement(e.icon,{className:"text-muted-foreground mr-2 h-4 w-4"}),t.createElement("span",null,e.label))})),t.createElement(h,null),t.createElement(d,null,t.createElement("div",{className:"flex items-center justify-between"},z.length>0&&t.createElement(t.Fragment,null,t.createElement(p,{onSelect:A,className:"flex-1 cursor-pointer justify-center"},"Clear"),t.createElement(s,{orientation:"vertical",className:"flex h-full min-h-6"})),t.createElement(p,{onSelect:()=>$(!1),className:"max-w-full flex-1 cursor-pointer justify-center"},"Close")))))),C>0&&z.length>0&&t.createElement(b,{className:r("text-foreground bg-background my-2 h-3 w-3 cursor-pointer",_?"":"text-muted-foreground"),onClick:()=>H(!_)}))});j.displayName="MultiSelect";export{j as MultiSelect};
//# sourceMappingURL=index.mjs.map