UNPKG

@bothub-chat/ui

Version:

Bothub UI Components

2 lines (1 loc) 4.4 kB
import{__rest as e}from"tslib";import{jsx as l,jsxs as t,Fragment as a}from"react/jsx-runtime";import{useCallback as r,useState as i,useMemo as o}from"react";import{SelectFieldLabel as n,SelectFieldStyled as d,SelectFieldInput as s,SelectFieldSkeleton as c,SelectFieldInputLeftSide as u,SelectFieldSearchIcon as p,SelectFieldInputNative as h,SelectFieldPlaceholder as m,SelectFieldInputSide as b,SelectFieldClearButton as f,SelectFieldLoader as S,SelectFieldArrow as y,SelectFieldErrorText as C}from"./styled.js";export{SelectFieldColorValueText,SelectFieldValue,SelectFieldValueColor,SelectFieldValueList,SelectFieldValueListItem,SelectFieldValueText,SelectFieldValues}from"./styled.js";import{Skeleton as g}from"../skeleton/index.js";import{SelectModal as $}from"./select-modal/index.js";import{SelectFieldInputValue as v}from"./nodes/value/index.js";import{SelectFieldProvider as k}from"./context.js";export{SelectFieldConsumer,SelectFieldContext,useSelectFieldContext}from"./context.js";import{useSelectField as x}from"./useSelectField.js";const V=V=>{var{className:F,label:W,placeholder:j,data:P,fullWidth:O=!1,contentWidth:I,error:T,skeleton:A=!1,blur:L=!1,size:z="small",disableSelect:M=!1,disableScrollbar:N=!1,empty:R,after:w,loading:B=!1,enableInput:D=!1,inputType:q="text",inputValue:E,clearable:G=!1,disablePortal:H,tabs:J,search:K,searchPlaceholder:Q,resetStyleState:U,children:X,modalWidth:Y,dataTest:Z,selectedColor:_,compactWidth:ee,modalStyles:le,openedModel:te,onSearch:ae,onOptionClick:re,onInputChange:ie,onPointerLeave:oe}=V,ne=e(V,["className","label","placeholder","data","fullWidth","contentWidth","error","skeleton","blur","size","disableSelect","disableScrollbar","empty","after","loading","enableInput","inputType","inputValue","clearable","disablePortal","tabs","search","searchPlaceholder","resetStyleState","children","modalWidth","dataTest","selectedColor","compactWidth","modalStyles","openedModel","onSearch","onOptionClick","onInputChange","onPointerLeave"]);const de=x(ne),{isOpen:se,triggerRef:ce,value:ue,disabled:pe,multiple:he,handleClose:me,handleInputClick:be,setValue:fe}=de,Se=e(de,["isOpen","triggerRef","value","disabled","multiple","handleClose","handleInputClick","setValue"]),ye=r((e=>{null==ie||ie(e)}),[ie]),[Ce,ge]=void 0===E?i(""):[E,ye],[$e,ve]=i(!1),ke=o((()=>D&&"search"===q),[D,q]),xe=o((()=>he&&Array.isArray(ue)&&ue.length>0),[he,ue]),Ve=o((()=>A?l(n,{children:l(g,{width:100})}):"string"==typeof W?l(n,{children:W}):W),[A,W]),Fe=r(((e,l)=>{if(l.stopPropagation(),Array.isArray(ue)){if("string"==typeof e)return void fe(ue.filter((l=>"string"==typeof l?l!==e:l.value!==e)));fe(ue.filter((l=>"string"==typeof l?l!==e.value:l.value!==e.value)))}me()}),[ue]),We=r((e=>{ge(e.currentTarget.value)}),[ge]),je=r((()=>{fe(null),ge("")}),[fe,ge]);return l(k,{selectRef:ce,handleSelectClick:be.bind(null,!1),children:t(d,{$fullWidth:O,$disabled:pe,className:F,onPointerLeave:oe,children:[Ve,null!=X?X:l(a,{children:A?l(s,{$open:!1,$error:!1,$disabled:!1,$skeleton:!0,$loading:!1,$blur:L,$multiple:!1,ref:ce,children:l(c,{})}):t(s,{$open:se,$error:!!T,$disabled:pe,$skeleton:!1,$blur:L,$loading:B,$multiple:xe,ref:ce,onClick:be.bind(null,!1),"data-test":Z,children:[t(u,{children:[(!ue||Array.isArray(ue)&&0===ue.length)&&t(a,{children:[ke&&l(p,{$focus:$e}),D?l(h,{type:q,value:Ce,placeholder:j,disabled:pe,onClick:be.bind(null,!0),onChange:We,onFocus:ve.bind(null,!0),onBlur:ve.bind(null,!1)}):l(m,{$open:se,children:j})]}),l(v,{value:ue,handleValueDelete:Fe})]}),t(b,{children:[(ue&&(G||D)||ke&&!B&&Ce)&&l(f,{onClick:je}),B&&l(S,{}),l(y,{$isOpen:se})]})]})}),l($,Object.assign({},Se,{isOpen:se,data:P,contentWidth:I,size:z,disableSelect:M,disableScrollbar:N,empty:R,after:w,tabs:J,search:K,searchPlaceholder:Q,resetStyleState:U,blur:L,disablePortal:H,value:ue,multiple:he,onSearch:ae,onOptionClick:re,handleClose:me,setValue:fe,modalWidth:Y,selectedColor:_,compactWidth:ee,modalStyles:le,openedModel:te})),T&&l(C,{children:T})]})})};export{V as SelectField,y as SelectFieldArrow,f as SelectFieldClearButton,C as SelectFieldErrorText,s as SelectFieldInput,u as SelectFieldInputLeftSide,h as SelectFieldInputNative,b as SelectFieldInputSide,n as SelectFieldLabel,S as SelectFieldLoader,m as SelectFieldPlaceholder,k as SelectFieldProvider,p as SelectFieldSearchIcon,c as SelectFieldSkeleton,d as SelectFieldStyled,$ as SelectModal,x as useSelectField};