UNPKG

siegel

Version:

Web application development ecosystem

1 lines 2.39 kB
import e,{useState as t,useRef as r}from"react";import l from"../_internals/resolve_tag_attributes.js";import n from"../../../common/is/exists/index.js";import a from"../_internals/apply_classname.js";import o from"../_internals/component.js";import*as i from"../_internals/key_codes.js";import s from"../_internals/handle_keyboard_selection.js";import m from"../_internals/ref_apply.js";import c from"../_internals/children.js";import p from"./helpers/get_options.js";let d=void 0,_="-ui-select",f=()=>({isActive:!1,arrowSelectIndex:d}),u=o(_,{theme:{root:d,_filled:d,_active:d,_disabled:d,_error:d,children:d,label:d,reset:d,title_wrapper:d,title_text:d,error_text:d,input_wrapper:d,options:d,option:d,option__active:d,option__disabled:d},closeOnSelect:!0,listDisabledOptions:!0},o=>{let _,u,v,{theme:b,rootTagAttributes:h,options:x,getDisplayValue:D,selected:E,dropdownIcon:j,disabled:w,placeholder:N,store:g,resetIcon:y,closeOnSelect:P,children:S,label:k,errorMsg:A,className:F,onChange:I,onFocus:B,onBlur:M,onKeyDown:O}=o,K=g||t(f()),[T,q]=K,{isActive:z,arrowSelectIndex:C}=T,G=(e,t,r)=>{t.stopPropagation(),t.preventDefault(),I(e,t,r),P&&L.ref.current.blur()},H=n(E),J=n(A),L={className:a(F,[[b._active,z],[b._filled,H],[b._error,J],[b._disabled,w]]),ref:r(null)};w?H&&(u=x.find(e=>e.value==E)):({optionsElement:_,selectedOption:u,selectedOptionIndex:v}=p(o,G,C),L.tabIndex=0,L.onFocus=e=>{B?.(e),e.defaultPrevented||(T.isActive=!0,q({...T}))},z&&(L.onBlur=e=>{M?.(e),e.defaultPrevented||q(f())},L.onKeyDown=e=>{if(O?.(e),!e.defaultPrevented){let t=e.key;t!=i.TAB&&(e.preventDefault(),s({selectStore:K,keyCode:t,options:x,selectedOptionIndex:v},{onDelete(){G(d,e)},onEnter(){let{value:t,payload:r}=x[C];G(t,e,r)}}))}})),m(L,o),L=l(L,h);let Q=u?D?D(u):u.title:N,R=e.createElement(e.Fragment,null,e.createElement("div",{className:b.title_wrapper,onMouseDown:e=>{z&&(e.preventDefault(),L.ref.current.blur())}},e.createElement("div",{className:b.title_text,children:Q}),!w&&y&&e.createElement("div",{children:y,className:b.reset,onMouseDown:e=>{G(d,e)}}),j),J&&e.createElement("div",{className:b.error_text,children:A}),_);return e.createElement("div",{...L},k?e.createElement(e.Fragment,null,e.createElement("div",{className:b.label,children:k}),e.createElement("div",{className:b.input_wrapper,children:R})):R,c(S,b))});export default u;export{_ as componentID,f as getDefaultState};