@foxford/ui 2.54.0 → 2.55.0-beta-8e3c324-20241210

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,2 +1,2 @@
1
- 'use strict';var React=require('react');var fuse=require('../../external/.pnpm/fuse.js@7.0.0/node_modules/fuse.js/dist/fuse.js');var index_browser=require('../../external/.pnpm/nanoid@5.0.7/node_modules/nanoid/index.browser.js');var withMergedProps=require('../../hocs/withMergedProps.js');var dom=require('../../shared/utils/dom.js');var constants$1=require('../../shared/constants.js');var DropdownMenu=require('./DropdownMenu.js');var DropdownMenuNoOptions=require('./DropdownMenuNoOptions.js');var constants=require('./constants.js');var utils=require('./utils.js');var style=require('./style.js');var require$$0=require('react/jsx-runtime');var FormInputLabel=require('../FormInputLabel/FormInputLabel.js');var FormInput=require('../FormInput/FormInput.js');var Chip=require('../Chip/Chip.js');var MenuList=require('../MenuList/MenuList.js');var ListItem=require('../ListItem/ListItem.js');var InputCheckbox=require('../InputCheckbox/InputCheckbox.js');var MenuDivider=require('../MenuDivider/MenuDivider.js');const Dropdown=withMergedProps.withMergedProps(React.forwardRef(((e,t)=>{const{size:o="m",name:r="fox-dropdown",labelPosition:n="dynamic",searchable:s=!0,primary:a=!0,optionsMultiToggle:c=!0,loading:i=!1,iconProps:u={},menuProps:l={},loadingIconProps:d={},optionsEmptyIconProps:p={},autoFocus:b,disableAutoScrollToSelectedOption:g,closeMenuOnScroll:m,contrast:v,selectedOption:f,defaultSelectedOption:x,icon:C,inputMode:h,loadingMessage:k,loadingIcon:I,maxLength:w,multiple:y,onCloseMenu:$,onOpenMenu:D,onSelectOption:q,options:M,groupSelectedOptions:R,optionsMultiToggleCaption:j,optionsEmptyMessage:S,optionsEmptyIcon:L,palette:E,placeholder:P,readOnly:F,required:T,status:O,sizeXXS:z,sizeXS:B,sizeS:K,sizeM:X,sizeL:N,sizeXL:_,form:H,...Z}=e;const A={size:o,sizeXXS:z,sizeXS:B,sizeS:K,sizeM:X,sizeL:N,sizeXL:_};const U={sizes:constants.SIZES_ICON,color:Z.disabled?'content-disabled':'content-onmain-tertiary'};const G=React.useMemo((()=>index_browser.nanoid()),[]);const J=React.useMemo((()=>{const e=new fuse.default(M,{threshold:.4,ignoreLocation:!0,keys:[constants.FuseSearchKeys.text,constants.FuseSearchKeys.label,constants.FuseSearchKeys.tags]});return t=>t.length===0?M:e.search(t).map((e=>e.item))}),[M]);const[Q,V]=React.useState((()=>utils.getDropdownSelectedOption(f!==void 0?f:x,y)));const[W,Y]=React.useState((()=>utils.getDropdownInputText(Q,y)));const[ee,te]=React.useState(!1);const[oe,re]=React.useState((()=>J(W)));const[ne,se]=React.useState(!1);const ae=y?utils.groupDropdownOptions(M,Q):[[],[]];const ce=ne&&!Z.disabled;const ie=oe.length===0||i;const ue=W===utils.getDropdownInputText(Q);const le=T&&Q.length===0;const de=Boolean(ce||W||ee);const pe=ae[0].length>0&&ae[1].length===0;const be=ae[0].length>0&&ae[1].length>0;const ge=React.useRef(null);const me=React.useRef(null);const ve=React.useRef(null);const fe=React.useRef(null);const xe=React.useRef(null);const Ce=React.useRef(W);const he=React.useRef(ce);return React.useEffect((()=>(W===Ce.current?re(J(W)):(Ce.current=W,xe.current=setTimeout((()=>{re(J(W))}),150)),()=>{xe.current&&clearTimeout(xe.current)})),[J,W]),React.useLayoutEffect((()=>{f!==void 0&&(y||Y(utils.getDropdownInputText(f)),V(utils.getDropdownSelectedOption(f,y)))}),[y,f]),React.useEffect((()=>{ce!==he.current&&(ce&&D&&D(),!ce&&$&&$(),he.current=ce)}),[ce,$,D]),React.useEffect((()=>{if(!y&&!g&&ce&&me.current&&fe.current){const e=me.current.getBoundingClientRect();const t=fe.current.getBoundingClientRect();(t.top<e.top||t.bottom>e.bottom)&&me.current.scrollTo(0,fe.current.offsetTop)}}),[y,g,ce]),React.useEffect((()=>{const handleScroll=e=>{ge.current?.focus(),se(!1),e.currentTarget&&e.currentTarget.removeEventListener(e.type,handleScroll)};return m&&ce&&document.addEventListener('scroll',handleScroll),()=>{document.removeEventListener('scroll',handleScroll)}}),[m,ce]),require$$0.jsx(FormInputLabel.FormInputLabel,{...Z,...A,ref:t,labelId:G,labelPosition:n,active:de,onColored:v,primary:a,error:O==='error',success:O==='success',icon:[C,require$$0.jsx(style.ChevronIcon,{up:ce},'chevron')],iconProps:{...A,...U,...u},palette:{color:Z.disabled?E.labelColorDisabled:E.labelColor,backgroundColor:Z.disabled?E.backgroundColorDisabled:E.backgroundColor,backgroundColorHover:Z.disabled?E.backgroundColorDisabled:E.backgroundColorHover,borderColor:Z.disabled?E.borderColorDisabled:E.borderColor},onClick:e=>{Z.onClick&&Z.onClick(e),Z.disabled||(ge.current?.focus(),ce?me.current&&e.target instanceof Node&&!me.current.contains(e.target)&&se(!1):(se(!0),s&&!y&&ue&&(Y(''),re(J('')))))},onKeyUp:e=>{Z.onKeyUp&&Z.onKeyUp(e),constants$1.keyboardKeys.Esc.validate(e.key)&&(ge.current?.focus(),se(!1))},onPointerDown:e=>{Z.onPointerDown&&Z.onPointerDown(e),e.target!==ge.current&&e.target instanceof Node&&e.currentTarget.contains(e.target)&&e.preventDefault()},onFocus:e=>{Z.onFocus&&Z.onFocus(e),ge.current&&e.target===ge.current&&(te(!0),s&&!y&&ue&&!ce&&(Y(''),re(J(''))))},onBlur:e=>{Z.onBlur&&Z.onBlur(e),ge.current&&e.target===ge.current&&te(!1),e.currentTarget.contains(e.relatedTarget)||(Y(utils.getDropdownInputText(Q,y)),se(!1))},input:require$$0.jsxs(require$$0.Fragment,{children:[le&&!s&&!F&&require$$0.jsx(style.InputMimic,{required:!0,type:"text",inputMode:"none",form:H,tabIndex:-1,onFocus:()=>{ge.current?.focus()}}),require$$0.jsx(FormInput.FormInput,{ref:ge,"aria-labelledby":Z.label?G:void 0,type:"text",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",form:H,autoFocus:b,inputMode:s?h:'none',maxLength:w,placeholder:P,readOnly:F||!s,required:le,disabled:Z.disabled,value:W,palette:{color:E.color,colorDisabled:E.colorDisabled,placeholderColor:E.placeholderColor,placeholderColorDisabled:E.placeholderColorDisabled},onClick:e=>{ce&&e.currentTarget.selectionStart!==e.currentTarget.selectionEnd&&e.stopPropagation()},onChange:e=>{Y(e.currentTarget.value),se(!0)},onKeyDown:e=>{constants$1.keyboardKeys.Enter.validate(e.key)&&(Y(utils.getDropdownInputText(Q,y)),se(!1)),!constants$1.keyboardKeys.Space.validate(e.key)||ce&&e.currentTarget.selectionStart!==0||(e.preventDefault(),s&&!y&&ue&&!ce&&(Y(''),re(J(''))),se((e=>!e))),constants$1.keyboardKeys.ArrowDown.validate(e.key)&&ve.current&&(e.preventDefault(),dom.focusFirstFocusable(ve.current))}}),Q.map((e=>require$$0.jsx("input",{type:"hidden",name:r,value:e.value,form:H,disabled:Z.disabled},e.value)))]}),addon:y&&Q.length>0?require$$0.jsx(Chip.Chip,{size:"xs",active:!0,black:!0,marginLeft:12,disabled:Z.disabled,cursor:Z.disabled?'not-allowed':void 0,text:Q.length,textProps:{appearance:'caption',size:'xs'},palette:Z.disabled?{color:'content-disabled',colorHover:'content-disabled',backgroundColor:'bg-disabled-small',backgroundColorHover:'bg-disabled-small'}:void 0,onPointerDown:e=>{e.preventDefault()},discardButtonProps:{contrast:!Z.disabled,onKeyDown:e=>{constants$1.keyboardKeys.ArrowDown.validate(e.key)&&ve.current&&(e.preventDefault(),dom.focusFirstFocusable(ve.current))},onClick:e=>{e.stopPropagation(),F||(f===void 0&&V([]),q&&q([]),ge.current?.focus(),se(!0))}}}):void 0,dropdown:ce?require$$0.jsx(DropdownMenu.DropdownMenu,{...l,ref:me,tabIndex:ie?void 0:0,secondary:!v,elevated:v,disableAutoFocus:!0,palette:{backgroundColor:E.menuBackgroundColor,borderColor:E.menuBorderColor},onFocus:e=>{ve.current&&e.target===e.currentTarget&&(ve.current.contains(e.relatedTarget)?ge.current?.focus():dom.focusFirstFocusable(ve.current))},onKeyDown:e=>{constants$1.keyboardKeys.Enter.validate(e.key)&&(ge.current?.focus(),Y(utils.getDropdownInputText(Q,y)),se(!1))},children:ie?require$$0.jsx(DropdownMenuNoOptions.DropdownMenuNoOptions,{loading:i,loadingMessage:k,loadingIcon:I,loadingIconProps:{...A,...U,...d},emptyMessage:S,emptyIcon:L,emptyIconProps:{...A,...U,...p}}):require$$0.jsx(MenuList.MenuList,y?{ref:ve,children:W.length===0?require$$0.jsxs(require$$0.Fragment,{children:[c&&require$$0.jsx(ListItem.ListItem,{...A,text:j,disabled:Z.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:require$$0.jsx(InputCheckbox.InputCheckbox,{sizes:constants.SIZES_CHECKBOX,form:"none",name:r,checked:pe,indeterminate:be,error:(pe||be)&&O==='error',success:(pe||be)&&O==='success',onChange:()=>{if(!F){const e=pe||be?[]:[...M];f===void 0&&V(e),q&&q(e)}}})}),c&&require$$0.jsx(MenuDivider.MenuDivider,{}),R&&ae[0].map((e=>{const t=e.status??O;const o=t==='error';const n=t==='success';return React.createElement(ListItem.ListItem,{...A,key:e.value,active:!0,text:e.text,danger:o,success:n,disabled:Z.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation(),ge.current?.focus()},control:require$$0.jsx(InputCheckbox.InputCheckbox,{sizes:constants.SIZES_CHECKBOX,form:"none",name:r,value:e.value,checked:!0,error:o,success:n,onChange:e=>{if(!F){const t=Q.filter((t=>t.value!==e.currentTarget.value));f===void 0&&V(t),q&&q(t)}}})})})),R&&ae[0].length>0&&ae[1].length>0&&require$$0.jsx(MenuDivider.MenuDivider,{}),R&&ae[1].map((e=>React.createElement(ListItem.ListItem,{...A,key:e.value,text:e.text,disabled:Z.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation(),ge.current?.focus()},control:require$$0.jsx(InputCheckbox.InputCheckbox,{sizes:constants.SIZES_CHECKBOX,form:"none",name:r,value:e.value,checked:!1,onChange:()=>{if(!F){const t=[...Q,e];f===void 0&&V(t),q&&q(t)}}})}))),!R&&M.map((e=>{const t=Q.findIndex((t=>t.value===e.value))!==-1;const o=e.status??O;const n=t&&o==='error';const s=t&&o==='success';return React.createElement(ListItem.ListItem,{...A,key:e.value,text:e.text,danger:n,success:s,disabled:Z.disabled,active:t,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:require$$0.jsx(InputCheckbox.InputCheckbox,{sizes:constants.SIZES_CHECKBOX,form:"none",name:r,value:e.value,checked:t,error:n,success:s,onChange:o=>{if(!F){const r=t?Q.filter((e=>e.value!==o.currentTarget.value)):[...Q,e];f===void 0&&V(r),q&&q(r)}}})})}))]}):require$$0.jsx(require$$0.Fragment,{children:oe.map((e=>{const t=Q.findIndex((t=>t.value===e.value))!==-1;const o=e.status??O;const n=t&&o==='error';const s=t&&o==='success';return React.createElement(ListItem.ListItem,{...A,key:e.value,text:e.text,danger:n,success:s,disabled:Z.disabled,active:t,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:require$$0.jsx(InputCheckbox.InputCheckbox,{sizes:constants.SIZES_CHECKBOX,form:"none",name:r,value:e.value,checked:t,error:n,success:s,onChange:o=>{if(!F){const r=t?Q.filter((e=>e.value!==o.currentTarget.value)):[...Q,e];f===void 0&&V(r),q&&q(r)}}})})}))})}:{ref:ve,children:(s?oe:M).map(((e,t,o)=>{const r=Q.findIndex((t=>t.value===e.value))!==-1;return React.createElement(ListItem.ListItem,{...A,ref:r?fe:void 0,key:e.value,text:e.text,active:r,danger:r&&O==='error',success:r&&O==='success',disabled:Z.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:t=>{if(t.stopPropagation(),!F){const t=r?null:e;f===void 0&&(Y(utils.getDropdownInputText(t)),V(utils.getDropdownSelectedOption(t))),q&&q(t),(t||o===oe)&&ge.current?.focus(),se(!t)}}})}))})}):void 0})})),{sizes:constants.SIZES,displayName:"Dropdown"});exports.COMPONENT_NAME="Dropdown",exports.Dropdown=Dropdown;
1
+ 'use strict';var React=require('react');var fuse=require('../../external/.pnpm/fuse.js@7.0.0/node_modules/fuse.js/dist/fuse.js');var index_browser=require('../../external/.pnpm/nanoid@5.0.7/node_modules/nanoid/index.browser.js');var withMergedProps=require('../../hocs/withMergedProps.js');var useScrollMonitor=require('../../hooks/useScrollMonitor.js');var dom=require('../../shared/utils/dom.js');var constants$1=require('../../shared/constants.js');var DropdownMenu=require('./DropdownMenu.js');var constants=require('./constants.js');var utils=require('./utils.js');var style=require('./style.js');var require$$0=require('react/jsx-runtime');var FormInputLabel=require('../FormInputLabel/FormInputLabel.js');var FormInput=require('../FormInput/FormInput.js');var Chip=require('../Chip/Chip.js');var IconButton=require('../IconButton/IconButton.js');var MenuList=require('../MenuList/MenuList.js');var ListItem=require('../ListItem/ListItem.js');var InputCheckbox=require('../InputCheckbox/InputCheckbox.js');var MenuDivider=require('../MenuDivider/MenuDivider.js');const Dropdown=withMergedProps.withMergedProps(React.forwardRef(((e,t)=>{const{size:o="m",name:r="fox-dropdown",labelPosition:n="dynamic",searchable:s=!0,primary:a=!0,optionsMultiToggle:i=!0,loading:c=!1,iconProps:l={},menuProps:u={},loadingIconProps:d={},optionsEmptyIconProps:p={},autoFocus:b,disableAutoScrollToSelectedOption:g,closeMenuOnScroll:m,scrollMonitorTarget:v,contrast:f,selectedOption:x,defaultSelectedOption:k,icon:h,inputMode:C,loadingMessage:I,loadingIcon:y,maxLength:$,multiple:w,clearable:q,onCloseMenu:D,onOpenMenu:M,onSelectOption:S,options:R,groupSelectedOptions:j,optionsMultiToggleCaption:L,optionsEmptyMessage:P,optionsEmptyIcon:E,palette:F,placeholder:T,readOnly:B,required:z,status:O,sizeXXS:K,sizeXS:X,sizeS:_,sizeM:H,sizeL:N,sizeXL:Z,form:A,...U}=e;const G={size:o,sizeXXS:K,sizeXS:X,sizeS:_,sizeM:H,sizeL:N,sizeXL:Z};const J={sizes:constants.SIZES_ICON,color:U.disabled?'content-disabled':'content-onmain-tertiary'};const Q=React.useMemo((()=>U.id??`${r}-${index_browser.nanoid()}`),[r,U.id]);const V=React.useMemo((()=>index_browser.nanoid()),[]);const W=React.useMemo((()=>index_browser.nanoid()),[]);const Y=React.useMemo((()=>{const e=new fuse.default(R,{threshold:.4,ignoreLocation:!0,keys:[constants.FuseSearchKeys.text,constants.FuseSearchKeys.label,constants.FuseSearchKeys.tags]});return t=>t.length===0?R:e.search(t).map((e=>e.item))}),[R]);const[ee,te]=React.useState((()=>utils.getDropdownSelectedOption(x!==void 0?x:k,w)));const[oe,re]=React.useState((()=>utils.getDropdownInputText(ee,w)));const[ne,se]=React.useState(!1);const[ae,ie]=React.useState((()=>Y(oe)));const[ce,le]=React.useState(!1);const ue=w?utils.groupDropdownOptions(R,ee):[[],[]];const de=ce&&!U.disabled;const pe=oe===utils.getDropdownInputText(ee);const be=z&&ee.length===0;const ge=Boolean(de||oe||ne);const me=ue[0].length>0&&ue[1].length===0;const ve=ue[0].length>0&&ue[1].length>0;const fe=React.useRef(null);const[xe,ke]=React.useState(null);const he=React.useRef(null);const Ce=React.useRef(null);const Ie=React.useRef(null);const ye=React.useRef(oe);const $e=React.useRef(de);return useScrollMonitor.useScrollMonitor({target:v,onScrollStart:()=>{m&&de&&(fe.current?.focus(),le(!1))}}),React.useEffect((()=>(oe===ye.current?ie(Y(oe)):(ye.current=oe,Ie.current=setTimeout((()=>{ie(Y(oe))}),150)),()=>{Ie.current&&clearTimeout(Ie.current)})),[Y,oe]),React.useLayoutEffect((()=>{x!==void 0&&(w||re(utils.getDropdownInputText(x)),te(utils.getDropdownSelectedOption(x,w)))}),[w,x]),React.useEffect((()=>{de!==$e.current&&(de&&M&&M(),!de&&D&&D(),$e.current=de)}),[de,D,M]),React.useEffect((()=>{if(!w&&!g&&de&&xe&&Ce.current){const e=xe.getBoundingClientRect();const t=Ce.current.getBoundingClientRect();(t.top<e.top||t.bottom>e.bottom)&&xe.scrollTo(0,Ce.current.offsetTop)}}),[w,g,de,xe]),require$$0.jsx(FormInputLabel.FormInputLabel,{...U,...G,ref:t,id:Q,labelId:V,labelPosition:n,active:ge,onColored:f,primary:a,error:O==='error',success:O==='success',focus:ne,icon:[h,require$$0.jsx(style.ChevronIcon,{up:de},'chevron')],iconProps:{...G,...J,...l},palette:{color:U.disabled?F.labelColorDisabled:F.labelColor,backgroundColor:U.disabled?F.backgroundColorDisabled:F.backgroundColor,backgroundColorHover:U.disabled?F.backgroundColorDisabled:F.backgroundColorHover,borderColor:U.disabled?F.borderColorDisabled:F.borderColor},onClick:e=>{U.onClick&&U.onClick(e),U.disabled||(fe.current?.focus(),de?xe&&e.target instanceof Node&&!xe.contains(e.target)&&le(!1):(le(!0),s&&!w&&pe&&(re(''),ie(Y('')))))},onPointerDown:e=>{U.onPointerDown&&U.onPointerDown(e),e.target!==fe.current&&e.target instanceof Node&&(e.currentTarget.contains(e.target)||u.renderInPortal&&de&&xe&&xe.contains(e.target))&&e.preventDefault()},onFocus:e=>{U.onFocus&&U.onFocus(e),se(!0),fe.current&&e.target===fe.current&&s&&!w&&pe&&!de&&(re(''),ie(Y('')))},onBlur:e=>{U.onBlur&&U.onBlur(e),e.currentTarget.contains(e.relatedTarget)||u.renderInPortal&&de&&xe&&xe.contains(e.relatedTarget)||(se(!1),re(utils.getDropdownInputText(ee,w)),le(!1))},input:require$$0.jsxs(require$$0.Fragment,{children:[be&&!s&&!B&&require$$0.jsx(style.InputMimic,{required:!0,type:"text",inputMode:"none",form:A,tabIndex:-1,onFocus:()=>{fe.current?.focus()}}),require$$0.jsx(FormInput.FormInput,{ref:fe,role:"combobox","aria-controls":W,"aria-expanded":de,"aria-labelledby":U.label?V:void 0,type:"text",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",form:A,autoFocus:b,inputMode:s?C:'none',maxLength:$,placeholder:T,readOnly:B||!s,required:be,disabled:U.disabled,value:oe,palette:{color:F.color,colorDisabled:F.colorDisabled,placeholderColor:F.placeholderColor,placeholderColorDisabled:F.placeholderColorDisabled},onClick:e=>{de&&e.currentTarget.selectionStart!==e.currentTarget.selectionEnd&&e.stopPropagation()},onChange:e=>{re(e.currentTarget.value),le(!0)},onKeyDown:e=>{if(constants$1.keyboardKeys.Enter.validate(e.key)&&(re(utils.getDropdownInputText(ee,w)),le(!1)),!constants$1.keyboardKeys.Space.validate(e.key)||de&&e.currentTarget.selectionStart!==0||(e.preventDefault(),s&&!w&&pe&&!de&&(re(''),ie(Y(''))),le((e=>!e))),constants$1.keyboardKeys.Esc.validate(e.key)&&le(!1),constants$1.keyboardKeys.Tab.validate(e.key)&&de&&(e.preventDefault(),le(!1)),constants$1.keyboardKeys.ArrowDown.validate(e.key)&&de&&he.current)if(e.preventDefault(),!w&&Ce.current){const e=[...he.current.children];const t=e.findIndex((e=>e.contains(Ce.current)));const o=e[t+1]??e[0];o instanceof HTMLElement&&dom.focusFirstFocusable(o)}else dom.focusFirstFocusable(he.current);if(constants$1.keyboardKeys.ArrowUp.validate(e.key)&&de&&he.current)if(e.preventDefault(),!w&&Ce.current){const e=[...he.current.children];const t=e.findIndex((e=>e.contains(Ce.current)));const o=e[t-1]??e[e.length-1];o instanceof HTMLElement&&dom.focusFirstFocusable(o)}else dom.focusLastFocusable(he.current)}}),ee.map((e=>require$$0.jsx("input",{type:"hidden",name:r,value:e.value,form:A,disabled:U.disabled},e.value)))]}),addon:require$$0.jsxs(require$$0.Fragment,{children:[w&&ee.length>0&&require$$0.jsx(Chip.Chip,{size:"xs",active:!0,black:!0,marginLeft:12,disabled:U.disabled,cursor:U.disabled?'not-allowed':void 0,text:ee.length,textProps:{appearance:'caption',size:'xs'},palette:U.disabled?{color:'content-disabled',colorHover:'content-disabled',backgroundColor:'bg-disabled-small',backgroundColorHover:'bg-disabled-small'}:void 0,onPointerDown:e=>{e.preventDefault()},discardButtonProps:{contrast:!U.disabled,onClick:e=>{e.stopPropagation(),B||(x===void 0&&te([]),S&&S(w?[]:null),fe.current?.focus(),le(!0))}}}),!w&&q&&ee.length>0&&require$$0.jsx(IconButton.IconButton,{icon:"close",size:"l",square:!0,marginLeft:12,disabled:U.disabled,onClick:e=>{e.stopPropagation(),B||(pe&&(re(''),ie(Y(''))),x===void 0&&te([]),S&&S(w?[]:null),fe.current?.focus(),le(!0))}})]}),dropdown:require$$0.jsx(DropdownMenu.DropdownMenu,{...u,setRef:ke,open:de,popperReferenceId:Q,secondary:!f,elevated:f,disableAutoFocus:!0,palette:{backgroundColor:F.menuBackgroundColor,borderColor:F.menuBorderColor},empty:ae.length===0,loading:c,loadingMessage:I,loadingIcon:y,loadingIconProps:{...G,...J,...d},emptyMessage:P,emptyIcon:E,emptyIconProps:{...G,...J,...p},onKeyDown:e=>{constants$1.keyboardKeys.Tab.validate(e.key)&&(e.preventDefault(),fe.current?.focus(),le(!1)),constants$1.keyboardKeys.Enter.validate(e.key)&&(fe.current?.focus(),re(utils.getDropdownInputText(ee,w)),le(!1)),constants$1.keyboardKeys.Esc.validate(e.key)&&(fe.current?.focus(),le(!1)),constants$1.keyboardKeys.Backspace.validate(e.key)&&!B&&(w||!w&&q)&&(x===void 0&&te([]),S&&S(w?[]:null))},children:require$$0.jsx(MenuList.MenuList,w?{ref:he,id:W,role:"listbox","aria-labelledby":U.label?V:void 0,"aria-multiselectable":!0,children:oe.length===0?require$$0.jsxs(require$$0.Fragment,{children:[i&&require$$0.jsx(ListItem.ListItem,{...G,text:L,disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:require$$0.jsx(InputCheckbox.InputCheckbox,{sizes:constants.SIZES_CHECKBOX,form:"none",name:r,checked:me,indeterminate:ve,error:(me||ve)&&O==='error',success:(me||ve)&&O==='success',onChange:()=>{if(!B){const e=me||ve?[]:[...R];x===void 0&&te(e),S&&S(e)}}})}),i&&require$$0.jsx(MenuDivider.MenuDivider,{}),j&&ue[0].map((e=>{const t=e.status??O;const o=t==='error';const n=t==='success';return React.createElement(ListItem.ListItem,{...G,key:e.value,active:!0,text:e.text,danger:o,success:n,disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation(),fe.current?.focus()},control:require$$0.jsx(InputCheckbox.InputCheckbox,{sizes:constants.SIZES_CHECKBOX,form:"none",role:"option","aria-selected":!0,name:r,value:e.value,checked:!0,error:o,success:n,onChange:e=>{if(!B){const t=ee.filter((t=>t.value!==e.currentTarget.value));x===void 0&&te(t),S&&S(t)}}})})})),j&&ue[0].length>0&&ue[1].length>0&&require$$0.jsx(MenuDivider.MenuDivider,{}),j&&ue[1].map((e=>React.createElement(ListItem.ListItem,{...G,key:e.value,text:e.text,disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation(),fe.current?.focus()},control:require$$0.jsx(InputCheckbox.InputCheckbox,{sizes:constants.SIZES_CHECKBOX,form:"none",role:"option","aria-selected":!1,name:r,value:e.value,checked:!1,onChange:()=>{if(!B){const t=[...ee,e];x===void 0&&te(t),S&&S(t)}}})}))),!j&&R.map((e=>{const t=ee.findIndex((t=>t.value===e.value))!==-1;const o=e.status??O;const n=t&&o==='error';const s=t&&o==='success';return React.createElement(ListItem.ListItem,{...G,key:e.value,text:e.text,danger:n,success:s,disabled:U.disabled,active:t,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:require$$0.jsx(InputCheckbox.InputCheckbox,{sizes:constants.SIZES_CHECKBOX,form:"none",role:"option","aria-selected":t,name:r,value:e.value,checked:t,error:n,success:s,onChange:o=>{if(!B){const r=t?ee.filter((e=>e.value!==o.currentTarget.value)):[...ee,e];x===void 0&&te(r),S&&S(r)}}})})}))]}):require$$0.jsx(require$$0.Fragment,{children:ae.map((e=>{const t=ee.findIndex((t=>t.value===e.value))!==-1;const o=e.status??O;const n=t&&o==='error';const s=t&&o==='success';return React.createElement(ListItem.ListItem,{...G,key:e.value,text:e.text,danger:n,success:s,disabled:U.disabled,active:t,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:require$$0.jsx(InputCheckbox.InputCheckbox,{sizes:constants.SIZES_CHECKBOX,form:"none",role:"option","aria-selected":t,name:r,value:e.value,checked:t,error:n,success:s,onChange:o=>{if(!B){const r=t?ee.filter((e=>e.value!==o.currentTarget.value)):[...ee,e];x===void 0&&te(r),S&&S(r)}}})})}))})}:{ref:he,id:W,role:"listbox","aria-labelledby":U.label?V:void 0,children:(s?ae:R).map((e=>{const t=ee.findIndex((t=>t.value===e.value))!==-1;return React.createElement(ListItem.ListItem,{...G,role:"option","aria-selected":t,ref:t?Ce:void 0,key:e.value,text:e.text,active:t,danger:t&&O==='error',success:t&&O==='success',disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:t=>{if(t.stopPropagation(),!B){const t={...e};x===void 0&&(re(utils.getDropdownInputText(t)),te(utils.getDropdownSelectedOption(t))),S&&S(t),fe.current?.focus(),le(!1)}}})}))})})})})),{sizes:constants.SIZES,displayName:"Dropdown"});exports.COMPONENT_NAME="Dropdown",exports.Dropdown=Dropdown;
2
2
  //# sourceMappingURL=Dropdown.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Dropdown.js","sources":["../../../../src/components/Dropdown/Dropdown.tsx"],"sourcesContent":["import { forwardRef, useState, useRef, useEffect, useLayoutEffect, useMemo } from 'react'\nimport Fuse from 'fuse.js'\nimport { nanoid } from 'nanoid'\nimport { withMergedProps } from 'hocs/withMergedProps'\nimport { focusFirstFocusable } from 'shared/utils/dom'\nimport { keyboardKeys } from 'shared/constants'\nimport { FormInput } from 'components/FormInput'\nimport { FormInputLabel } from 'components/FormInputLabel'\nimport { MenuList } from 'components/MenuList'\nimport { MenuDivider } from 'components/MenuDivider'\nimport { ListItem } from 'components/ListItem'\nimport { InputCheckbox } from 'components/InputCheckbox'\nimport { Chip } from 'components/Chip'\nimport type { IconProps } from 'components/Icon'\nimport { DropdownMenu } from './DropdownMenu'\nimport { DropdownMenuNoOptions } from './DropdownMenuNoOptions'\nimport { SIZES, SIZES_CHECKBOX, SIZES_ICON, FuseSearchKeys } from './constants'\nimport { getDropdownInputText, getDropdownSelectedOption, groupDropdownOptions } from './utils'\nimport * as Styled from './style'\nimport type { DropdownProps, DropdownOption } from './types'\n\nconst COMPONENT_NAME = 'Dropdown'\n\n/**\n *\n * Компонент поддерживает все атрибуты \\<div\\> элемента.\n *\n * Можно передать \"ref\", который будет ассоциирован с рутовым элементом.\n *\n * Поддерживаются пропсы определения размеров и внешних отступов в зависимости от ширины вьюпорта.\n *\n * Полный интерфейс можно посмотреть [тут](https://github.com/foxford/ui/blob/master/src/components/Dropdown/types.ts).\n */\nconst Dropdown: React.ForwardRefExoticComponent<DropdownProps> = withMergedProps<DropdownProps, HTMLDivElement>(\n forwardRef((props, ref) => {\n const {\n size = 'm',\n name = 'fox-dropdown',\n labelPosition = 'dynamic',\n searchable = true,\n primary = true,\n optionsMultiToggle = true,\n loading = false,\n iconProps = {},\n menuProps = {},\n loadingIconProps = {},\n optionsEmptyIconProps = {},\n autoFocus,\n disableAutoScrollToSelectedOption,\n closeMenuOnScroll,\n contrast,\n selectedOption,\n defaultSelectedOption,\n icon,\n inputMode,\n loadingMessage,\n loadingIcon,\n maxLength,\n multiple,\n onCloseMenu,\n onOpenMenu,\n onSelectOption,\n options,\n groupSelectedOptions,\n optionsMultiToggleCaption,\n optionsEmptyMessage,\n optionsEmptyIcon,\n palette,\n placeholder,\n readOnly,\n required,\n status,\n sizeXXS,\n sizeXS,\n sizeS,\n sizeM,\n sizeL,\n sizeXL,\n form,\n ...rootProps\n } = props\n\n const sizeProps = {\n size,\n sizeXXS,\n sizeXS,\n sizeS,\n sizeM,\n sizeL,\n sizeXL,\n }\n\n const iconBaseProps: IconProps = {\n sizes: SIZES_ICON,\n color: rootProps.disabled ? 'content-disabled' : 'content-onmain-tertiary',\n }\n\n const inputLabelId = useMemo(() => nanoid(), [])\n\n const getRelevantOptions = useMemo(() => {\n const fuse = new Fuse<DropdownOption>(options, {\n threshold: 0.4,\n ignoreLocation: true,\n keys: [FuseSearchKeys.text, FuseSearchKeys.label, FuseSearchKeys.tags],\n })\n\n return (pattern: string): DropdownOption[] =>\n pattern.length === 0 ? options : fuse.search(pattern).map((result) => result.item)\n }, [options])\n\n const [dropdownSelectedOption, setDropdownSelectedOption] = useState<DropdownOption[]>(() =>\n getDropdownSelectedOption(selectedOption !== undefined ? selectedOption : defaultSelectedOption, multiple)\n )\n\n const [inputText, setInputText] = useState<string>(() => getDropdownInputText(dropdownSelectedOption, multiple))\n\n const [inputFocused, setInputFocused] = useState<boolean>(false)\n\n const [menuRelevantOptions, setMenuRelevantOptions] = useState<DropdownOption[]>(() =>\n getRelevantOptions(inputText)\n )\n\n const [menuOpenRequest, setMenuOpenRequest] = useState<boolean>(false)\n\n const menuOptionsGroups: ReturnType<typeof groupDropdownOptions> = multiple\n ? groupDropdownOptions(options, dropdownSelectedOption)\n : [[], []]\n\n const menuOpen = menuOpenRequest && !rootProps.disabled\n const menuNoRelevantOptions = menuRelevantOptions.length === 0 || loading\n\n const inputSynced = inputText === getDropdownInputText(dropdownSelectedOption)\n const inputRequired = required && dropdownSelectedOption.length === 0\n const inputActive = Boolean(menuOpen || inputText || inputFocused)\n\n const multiToggleChecked = menuOptionsGroups[0].length > 0 && menuOptionsGroups[1].length === 0\n const multiToggleIndeterminate = menuOptionsGroups[0].length > 0 && menuOptionsGroups[1].length > 0\n\n const inputRef = useRef<HTMLInputElement | null>(null)\n const menuRef = useRef<HTMLDivElement | null>(null)\n const menuListRef = useRef<HTMLUListElement | null>(null)\n const selectedOptionRef = useRef<HTMLElement | null>(null)\n\n const timeoutIdRef = useRef<ReturnType<typeof setTimeout> | null>(null)\n\n const inputTextPrevRef = useRef<string>(inputText)\n const menuOpenPrevRef = useRef<boolean>(menuOpen)\n\n useEffect(() => {\n if (inputText === inputTextPrevRef.current) {\n setMenuRelevantOptions(getRelevantOptions(inputText))\n } else {\n inputTextPrevRef.current = inputText\n timeoutIdRef.current = setTimeout(() => {\n setMenuRelevantOptions(getRelevantOptions(inputText))\n }, 150)\n }\n\n return () => {\n if (timeoutIdRef.current) {\n clearTimeout(timeoutIdRef.current)\n }\n }\n }, [getRelevantOptions, inputText])\n\n useLayoutEffect(() => {\n if (selectedOption === undefined) return\n\n if (!multiple) setInputText(getDropdownInputText(selectedOption))\n setDropdownSelectedOption(getDropdownSelectedOption(selectedOption, multiple))\n }, [multiple, selectedOption])\n\n useEffect(() => {\n if (menuOpen === menuOpenPrevRef.current) return\n\n if (menuOpen && onOpenMenu) onOpenMenu()\n if (!menuOpen && onCloseMenu) onCloseMenu()\n\n menuOpenPrevRef.current = menuOpen\n }, [menuOpen, onCloseMenu, onOpenMenu])\n\n useEffect(() => {\n if (!multiple && !disableAutoScrollToSelectedOption && menuOpen && menuRef.current && selectedOptionRef.current) {\n const menuRect = menuRef.current.getBoundingClientRect()\n const selectedOptionRect = selectedOptionRef.current.getBoundingClientRect()\n\n if (selectedOptionRect.top < menuRect.top || selectedOptionRect.bottom > menuRect.bottom) {\n menuRef.current.scrollTo(0, selectedOptionRef.current.offsetTop)\n }\n }\n }, [multiple, disableAutoScrollToSelectedOption, menuOpen])\n\n useEffect(() => {\n const handleScroll = (evt: Event) => {\n inputRef.current?.focus()\n setMenuOpenRequest(false)\n\n if (evt.currentTarget) {\n evt.currentTarget.removeEventListener(evt.type, handleScroll)\n }\n }\n\n if (closeMenuOnScroll && menuOpen) {\n document.addEventListener('scroll', handleScroll)\n }\n\n return () => {\n document.removeEventListener('scroll', handleScroll)\n }\n }, [closeMenuOnScroll, menuOpen])\n\n return (\n <FormInputLabel\n {...rootProps}\n {...sizeProps}\n ref={ref}\n labelId={inputLabelId}\n labelPosition={labelPosition}\n active={inputActive}\n onColored={contrast}\n primary={primary}\n error={status === 'error'}\n success={status === 'success'}\n icon={[icon, <Styled.ChevronIcon key='chevron' up={menuOpen} />]}\n iconProps={{\n ...sizeProps,\n ...iconBaseProps,\n ...iconProps,\n }}\n palette={{\n color: rootProps.disabled ? palette.labelColorDisabled : palette.labelColor,\n backgroundColor: rootProps.disabled ? palette.backgroundColorDisabled : palette.backgroundColor,\n backgroundColorHover: rootProps.disabled ? palette.backgroundColorDisabled : palette.backgroundColorHover,\n borderColor: rootProps.disabled ? palette.borderColorDisabled : palette.borderColor,\n }}\n onClick={(evt) => {\n if (rootProps.onClick) rootProps.onClick(evt)\n\n if (rootProps.disabled) return\n\n inputRef.current?.focus()\n\n if (!menuOpen) {\n setMenuOpenRequest(true)\n\n if (searchable && !multiple && inputSynced) {\n setInputText('')\n setMenuRelevantOptions(getRelevantOptions(''))\n }\n } else if (menuRef.current && evt.target instanceof Node && !menuRef.current.contains(evt.target)) {\n setMenuOpenRequest(false)\n }\n }}\n onKeyUp={(evt) => {\n if (rootProps.onKeyUp) rootProps.onKeyUp(evt)\n\n if (keyboardKeys.Esc.validate(evt.key)) {\n inputRef.current?.focus()\n setMenuOpenRequest(false)\n }\n }}\n onPointerDown={(evt) => {\n if (rootProps.onPointerDown) rootProps.onPointerDown(evt)\n\n if (evt.target !== inputRef.current && evt.target instanceof Node && evt.currentTarget.contains(evt.target)) {\n evt.preventDefault()\n }\n }}\n onFocus={(evt) => {\n if (rootProps.onFocus) rootProps.onFocus(evt)\n\n if (inputRef.current && evt.target === inputRef.current) {\n setInputFocused(true)\n\n if (searchable && !multiple && inputSynced && !menuOpen) {\n setInputText('')\n setMenuRelevantOptions(getRelevantOptions(''))\n }\n }\n }}\n onBlur={(evt) => {\n if (rootProps.onBlur) rootProps.onBlur(evt)\n\n if (inputRef.current && evt.target === inputRef.current) {\n setInputFocused(false)\n }\n\n if (!evt.currentTarget.contains(evt.relatedTarget)) {\n setInputText(getDropdownInputText(dropdownSelectedOption, multiple))\n setMenuOpenRequest(false)\n }\n }}\n input={\n <>\n {inputRequired && !searchable && !readOnly && (\n <Styled.InputMimic\n required\n type='text'\n inputMode='none'\n form={form}\n tabIndex={-1}\n onFocus={() => {\n inputRef.current?.focus()\n }}\n />\n )}\n <FormInput\n ref={inputRef}\n aria-labelledby={rootProps.label ? inputLabelId : undefined}\n type='text'\n autoComplete='off'\n autoCapitalize='off'\n autoCorrect='off'\n spellCheck='false'\n form={form}\n autoFocus={autoFocus}\n inputMode={searchable ? inputMode : 'none'}\n maxLength={maxLength}\n placeholder={placeholder}\n readOnly={readOnly || !searchable}\n required={inputRequired}\n disabled={rootProps.disabled}\n value={inputText}\n palette={{\n color: palette.color,\n colorDisabled: palette.colorDisabled,\n placeholderColor: palette.placeholderColor,\n placeholderColorDisabled: palette.placeholderColorDisabled,\n }}\n onClick={(evt) => {\n if (menuOpen && evt.currentTarget.selectionStart !== evt.currentTarget.selectionEnd) {\n evt.stopPropagation()\n }\n }}\n onChange={(evt) => {\n setInputText(evt.currentTarget.value)\n setMenuOpenRequest(true)\n }}\n onKeyDown={(evt) => {\n if (keyboardKeys.Enter.validate(evt.key)) {\n setInputText(getDropdownInputText(dropdownSelectedOption, multiple))\n setMenuOpenRequest(false)\n }\n\n if (keyboardKeys.Space.validate(evt.key) && (!menuOpen || evt.currentTarget.selectionStart === 0)) {\n evt.preventDefault()\n\n if (searchable && !multiple && inputSynced && !menuOpen) {\n setInputText('')\n setMenuRelevantOptions(getRelevantOptions(''))\n }\n\n setMenuOpenRequest((prev) => !prev)\n }\n\n if (keyboardKeys.ArrowDown.validate(evt.key) && menuListRef.current) {\n evt.preventDefault()\n focusFirstFocusable(menuListRef.current)\n }\n }}\n />\n {dropdownSelectedOption.map((item) => (\n <input\n key={item.value}\n type='hidden'\n name={name}\n value={item.value}\n form={form}\n disabled={rootProps.disabled}\n />\n ))}\n </>\n }\n addon={\n multiple && dropdownSelectedOption.length > 0 ? (\n <Chip\n size='xs'\n active\n black\n marginLeft={12}\n disabled={rootProps.disabled}\n cursor={rootProps.disabled ? 'not-allowed' : undefined}\n text={dropdownSelectedOption.length}\n textProps={{\n appearance: 'caption',\n size: 'xs',\n }}\n palette={\n rootProps.disabled\n ? {\n color: 'content-disabled',\n colorHover: 'content-disabled',\n backgroundColor: 'bg-disabled-small',\n backgroundColorHover: 'bg-disabled-small',\n }\n : undefined\n }\n onPointerDown={(evt) => {\n evt.preventDefault()\n }}\n discardButtonProps={{\n contrast: !rootProps.disabled,\n onKeyDown: (evt) => {\n if (keyboardKeys.ArrowDown.validate(evt.key) && menuListRef.current) {\n evt.preventDefault()\n focusFirstFocusable(menuListRef.current)\n }\n },\n onClick: (evt) => {\n evt.stopPropagation()\n\n if (!readOnly) {\n if (selectedOption === undefined) {\n setDropdownSelectedOption([])\n }\n\n if (onSelectOption) onSelectOption([])\n\n inputRef.current?.focus()\n setMenuOpenRequest(true)\n }\n },\n }}\n />\n ) : undefined\n }\n dropdown={\n menuOpen ? (\n <DropdownMenu\n {...menuProps}\n ref={menuRef}\n tabIndex={menuNoRelevantOptions ? undefined : 0}\n secondary={!contrast}\n elevated={contrast}\n disableAutoFocus\n palette={{\n backgroundColor: palette.menuBackgroundColor,\n borderColor: palette.menuBorderColor,\n }}\n onFocus={(evt) => {\n if (!menuListRef.current) return\n\n if (evt.target === evt.currentTarget) {\n if (menuListRef.current.contains(evt.relatedTarget)) {\n inputRef.current?.focus()\n } else {\n focusFirstFocusable(menuListRef.current)\n }\n }\n }}\n onKeyDown={(evt) => {\n if (keyboardKeys.Enter.validate(evt.key)) {\n inputRef.current?.focus()\n setInputText(getDropdownInputText(dropdownSelectedOption, multiple))\n setMenuOpenRequest(false)\n }\n }}\n >\n {menuNoRelevantOptions ? (\n <DropdownMenuNoOptions\n loading={loading}\n loadingMessage={loadingMessage}\n loadingIcon={loadingIcon}\n loadingIconProps={{\n ...sizeProps,\n ...iconBaseProps,\n ...loadingIconProps,\n }}\n emptyMessage={optionsEmptyMessage}\n emptyIcon={optionsEmptyIcon}\n emptyIconProps={{\n ...sizeProps,\n ...iconBaseProps,\n ...optionsEmptyIconProps,\n }}\n />\n ) : multiple ? (\n <MenuList ref={menuListRef}>\n {inputText.length === 0 ? (\n <>\n {optionsMultiToggle && (\n <ListItem\n {...sizeProps}\n text={optionsMultiToggleCaption}\n disabled={rootProps.disabled}\n borderRadius={8}\n ellipsis={false}\n textProps={{ wordBreak: 'break-word' }}\n onClick={(evt) => {\n evt.stopPropagation()\n }}\n control={\n <InputCheckbox\n sizes={SIZES_CHECKBOX}\n form='none'\n name={name}\n checked={multiToggleChecked}\n indeterminate={multiToggleIndeterminate}\n error={(multiToggleChecked || multiToggleIndeterminate) && status === 'error'}\n success={(multiToggleChecked || multiToggleIndeterminate) && status === 'success'}\n onChange={() => {\n if (!readOnly) {\n const update = multiToggleChecked || multiToggleIndeterminate ? [] : [...options]\n\n if (selectedOption === undefined) {\n setDropdownSelectedOption(update)\n }\n\n if (onSelectOption) onSelectOption(update)\n }\n }}\n />\n }\n />\n )}\n {optionsMultiToggle && <MenuDivider />}\n {groupSelectedOptions &&\n menuOptionsGroups[0].map((option) => {\n const optionStatus = option.status ?? status\n const optionErrorStatus = optionStatus === 'error'\n const optionSuccessStatus = optionStatus === 'success'\n\n return (\n <ListItem\n {...sizeProps}\n key={option.value}\n active\n text={option.text}\n danger={optionErrorStatus}\n success={optionSuccessStatus}\n disabled={rootProps.disabled}\n borderRadius={8}\n ellipsis={false}\n textProps={{ wordBreak: 'break-word' }}\n onClick={(evt) => {\n evt.stopPropagation()\n inputRef.current?.focus()\n }}\n control={\n <InputCheckbox\n sizes={SIZES_CHECKBOX}\n form='none'\n name={name}\n value={option.value}\n checked\n error={optionErrorStatus}\n success={optionSuccessStatus}\n onChange={(evt) => {\n if (!readOnly) {\n const update = dropdownSelectedOption.filter(\n (item) => item.value !== evt.currentTarget.value\n )\n\n if (selectedOption === undefined) {\n setDropdownSelectedOption(update)\n }\n\n if (onSelectOption) onSelectOption(update)\n }\n }}\n />\n }\n />\n )\n })}\n {groupSelectedOptions && menuOptionsGroups[0].length > 0 && menuOptionsGroups[1].length > 0 && (\n <MenuDivider />\n )}\n {groupSelectedOptions &&\n menuOptionsGroups[1].map((option) => (\n <ListItem\n {...sizeProps}\n key={option.value}\n text={option.text}\n disabled={rootProps.disabled}\n borderRadius={8}\n ellipsis={false}\n textProps={{ wordBreak: 'break-word' }}\n onClick={(evt) => {\n evt.stopPropagation()\n inputRef.current?.focus()\n }}\n control={\n <InputCheckbox\n sizes={SIZES_CHECKBOX}\n form='none'\n name={name}\n value={option.value}\n checked={false}\n onChange={() => {\n if (!readOnly) {\n const update = [...dropdownSelectedOption, option]\n\n if (selectedOption === undefined) {\n setDropdownSelectedOption(update)\n }\n\n if (onSelectOption) onSelectOption(update)\n }\n }}\n />\n }\n />\n ))}\n {!groupSelectedOptions &&\n options.map((option) => {\n const selected =\n dropdownSelectedOption.findIndex((item) => item.value === option.value) !== -1\n\n const optionStatus = option.status ?? status\n const optionErrorStatus = selected && optionStatus === 'error'\n const optionSuccessStatus = selected && optionStatus === 'success'\n\n return (\n <ListItem\n {...sizeProps}\n key={option.value}\n text={option.text}\n danger={optionErrorStatus}\n success={optionSuccessStatus}\n disabled={rootProps.disabled}\n active={selected}\n borderRadius={8}\n ellipsis={false}\n textProps={{ wordBreak: 'break-word' }}\n onClick={(evt) => {\n evt.stopPropagation()\n }}\n control={\n <InputCheckbox\n sizes={SIZES_CHECKBOX}\n form='none'\n name={name}\n value={option.value}\n checked={selected}\n error={optionErrorStatus}\n success={optionSuccessStatus}\n onChange={(evt) => {\n if (!readOnly) {\n const update = selected\n ? dropdownSelectedOption.filter(\n (item) => item.value !== evt.currentTarget.value\n )\n : [...dropdownSelectedOption, option]\n\n if (selectedOption === undefined) {\n setDropdownSelectedOption(update)\n }\n\n if (onSelectOption) onSelectOption(update)\n }\n }}\n />\n }\n />\n )\n })}\n </>\n ) : (\n <>\n {menuRelevantOptions.map((option) => {\n const selected = dropdownSelectedOption.findIndex((item) => item.value === option.value) !== -1\n\n const optionStatus = option.status ?? status\n const optionErrorStatus = selected && optionStatus === 'error'\n const optionSuccessStatus = selected && optionStatus === 'success'\n\n return (\n <ListItem\n {...sizeProps}\n key={option.value}\n text={option.text}\n danger={optionErrorStatus}\n success={optionSuccessStatus}\n disabled={rootProps.disabled}\n active={selected}\n borderRadius={8}\n ellipsis={false}\n textProps={{ wordBreak: 'break-word' }}\n onClick={(evt) => {\n evt.stopPropagation()\n }}\n control={\n <InputCheckbox\n sizes={SIZES_CHECKBOX}\n form='none'\n name={name}\n value={option.value}\n checked={selected}\n error={optionErrorStatus}\n success={optionSuccessStatus}\n onChange={(evt) => {\n if (!readOnly) {\n const update = selected\n ? dropdownSelectedOption.filter((item) => item.value !== evt.currentTarget.value)\n : [...dropdownSelectedOption, option]\n\n if (selectedOption === undefined) {\n setDropdownSelectedOption(update)\n }\n\n if (onSelectOption) onSelectOption(update)\n }\n }}\n />\n }\n />\n )\n })}\n </>\n )}\n </MenuList>\n ) : (\n <MenuList ref={menuListRef}>\n {(searchable ? menuRelevantOptions : options).map((option, _, optionsRendered) => {\n const selected = dropdownSelectedOption.findIndex((item) => item.value === option.value) !== -1\n\n return (\n <ListItem\n {...sizeProps}\n ref={selected ? selectedOptionRef : undefined}\n key={option.value}\n text={option.text}\n active={selected}\n danger={selected && status === 'error'}\n success={selected && status === 'success'}\n disabled={rootProps.disabled}\n borderRadius={8}\n ellipsis={false}\n textProps={{ wordBreak: 'break-word' }}\n onClick={(evt) => {\n evt.stopPropagation()\n\n if (!readOnly) {\n const update = selected ? null : option\n\n if (selectedOption === undefined) {\n setInputText(getDropdownInputText(update))\n setDropdownSelectedOption(getDropdownSelectedOption(update))\n }\n\n if (onSelectOption) onSelectOption(update)\n\n if (update || optionsRendered === menuRelevantOptions) {\n inputRef.current?.focus()\n }\n\n setMenuOpenRequest(!update)\n }\n }}\n />\n )\n })}\n </MenuList>\n )}\n </DropdownMenu>\n ) : undefined\n }\n />\n )\n }),\n {\n sizes: SIZES,\n displayName: COMPONENT_NAME,\n }\n)\n\nexport { Dropdown, COMPONENT_NAME }\n"],"names":["Dropdown","withMergedProps","forwardRef","props","ref","size","name","labelPosition","searchable","primary","optionsMultiToggle","loading","iconProps","menuProps","loadingIconProps","optionsEmptyIconProps","autoFocus","disableAutoScrollToSelectedOption","closeMenuOnScroll","contrast","selectedOption","defaultSelectedOption","icon","inputMode","loadingMessage","loadingIcon","maxLength","multiple","onCloseMenu","onOpenMenu","onSelectOption","options","groupSelectedOptions","optionsMultiToggleCaption","optionsEmptyMessage","optionsEmptyIcon","palette","placeholder","readOnly","required","status","sizeXXS","sizeXS","sizeS","sizeM","sizeL","sizeXL","form","rootProps","sizeProps","iconBaseProps","sizes","SIZES_ICON","color","disabled","inputLabelId","useMemo","nanoid","getRelevantOptions","fuse","Fuse","default","threshold","ignoreLocation","keys","FuseSearchKeys","text","label","tags","pattern","length","search","map","result","item","dropdownSelectedOption","setDropdownSelectedOption","useState","getDropdownSelectedOption","undefined","inputText","setInputText","getDropdownInputText","inputFocused","setInputFocused","menuRelevantOptions","setMenuRelevantOptions","menuOpenRequest","setMenuOpenRequest","menuOptionsGroups","groupDropdownOptions","menuOpen","menuNoRelevantOptions","inputSynced","inputRequired","inputActive","Boolean","multiToggleChecked","multiToggleIndeterminate","inputRef","useRef","menuRef","menuListRef","selectedOptionRef","timeoutIdRef","inputTextPrevRef","menuOpenPrevRef","useEffect","current","setTimeout","clearTimeout","useLayoutEffect","menuRect","getBoundingClientRect","selectedOptionRect","top","bottom","scrollTo","offsetTop","handleScroll","evt","focus","currentTarget","removeEventListener","type","document","addEventListener","_jsx","FormInputLabel","labelId","active","onColored","error","success","jsx","Styled","up","labelColorDisabled","labelColor","backgroundColor","backgroundColorDisabled","backgroundColorHover","borderColor","borderColorDisabled","onClick","target","Node","contains","onKeyUp","keyboardKeys","Esc","validate","key","onPointerDown","preventDefault","onFocus","onBlur","relatedTarget","input","_jsxs","jsxs","_Fragment","children","tabIndex","FormInput","autoComplete","autoCapitalize","autoCorrect","spellCheck","value","colorDisabled","placeholderColor","placeholderColorDisabled","selectionStart","selectionEnd","stopPropagation","onChange","onKeyDown","Enter","Space","prev","ArrowDown","focusFirstFocusable","addon","Chip","black","marginLeft","cursor","textProps","appearance","colorHover","discardButtonProps","dropdown","DropdownMenu","secondary","elevated","disableAutoFocus","menuBackgroundColor","menuBorderColor","DropdownMenuNoOptions","emptyMessage","emptyIcon","emptyIconProps","MenuList","ListItem","borderRadius","ellipsis","wordBreak","control","InputCheckbox","SIZES_CHECKBOX","checked","indeterminate","update","MenuDivider","option","optionStatus","optionErrorStatus","optionSuccessStatus","_createElement","danger","filter","createElement","selected","findIndex","_","optionsRendered","SIZES","displayName"],"mappings":"u/BAiCMA,MAAAA,SAA2DC,gBAAAA,gBAC/DC,MAAAA,YAAW,CAACC,EAAOC,KACjB,MAAMC,KACJA,EAAO,IAAGC,KACVA,EAAO,eAAcC,cACrBA,EAAgB,UAASC,WACzBA,GAAa,EAAIC,QACjBA,GAAU,EAAIC,mBACdA,GAAqB,EAAIC,QACzBA,GAAU,EAAKC,UACfA,EAAY,CAAE,EAAAC,UACdA,EAAY,CAAE,EAAAC,iBACdA,EAAmB,CAAE,EAAAC,sBACrBA,EAAwB,CAAE,EAAAC,UAC1BA,EAASC,kCACTA,EAAiCC,kBACjCA,EAAiBC,SACjBA,EAAQC,eACRA,EAAcC,sBACdA,EAAqBC,KACrBA,EAAIC,UACJA,EAASC,eACTA,EAAcC,YACdA,EAAWC,UACXA,EAASC,SACTA,EAAQC,YACRA,EAAWC,WACXA,EAAUC,eACVA,EAAcC,QACdA,EAAOC,qBACPA,EAAoBC,0BACpBA,EAAyBC,oBACzBA,EAAmBC,iBACnBA,EAAgBC,QAChBA,EAAOC,YACPA,EAAWC,SACXA,EAAQC,SACRA,EAAQC,OACRA,EAAMC,QACNA,EAAOC,OACPA,EAAMC,MACNA,EAAKC,MACLA,EAAKC,MACLA,EAAKC,OACLA,EAAMC,KAC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3J,EACJ7C,IAAK2N,EAAWxH,QAAoBxB,EACpCyE,IAAK+D,EAAO9C,MACZvG,KAAMqJ,EAAOrJ,KACbgE,OAAQ6F,EACRH,OAAQG,GAAYvL,IAAW,QAC/B6F,QAAS0F,GAAYvL,IAAW,UAChCc,SAAUN,EAAUM,SACpBuJ,aAAc,EACdC,UAAU,EACVlB,UAAW,CAAEmB,UAAW,cACxB/D,QAAUxB,IAGR,GAFAA,EAAIuD,mBAECzI,EAAU,CACb,MAAM+K,EAASU,EAAW,KAAOR,EAE7BnM,SAAmB2D,IACrBE,EAAaC,MAAAA,qBAAqBmI,IAClCzI,EAA0BE,MAAAA,0BAA0BuI,KAGlDvL,GAAgBA,EAAeuL,IAE/BA,GAAUa,IAAoB7I,KAChCc,GAASS,SAASa,QAGpBjC,IAAoB6H,EACtB,IAEF,aAMVtI,GAEN,IAGN,CACE5B,MAAOgL,UAAKA,MACZC,YAtuBmB,oCAAA"}
1
+ {"version":3,"file":"Dropdown.js","sources":["../../../../src/components/Dropdown/Dropdown.tsx"],"sourcesContent":["import { forwardRef, useState, useRef, useEffect, useLayoutEffect, useMemo } from 'react'\nimport Fuse from 'fuse.js'\nimport { nanoid } from 'nanoid'\nimport { withMergedProps } from 'hocs/withMergedProps'\nimport { useScrollMonitor } from 'hooks/useScrollMonitor'\nimport { focusFirstFocusable, focusLastFocusable } from 'shared/utils/dom'\nimport { keyboardKeys } from 'shared/constants'\nimport type { Nullable } from 'shared/types'\nimport { FormInput } from 'components/FormInput'\nimport { FormInputLabel } from 'components/FormInputLabel'\nimport { MenuList } from 'components/MenuList'\nimport { MenuDivider } from 'components/MenuDivider'\nimport { ListItem } from 'components/ListItem'\nimport { InputCheckbox } from 'components/InputCheckbox'\nimport { Chip } from 'components/Chip'\nimport { IconButton } from 'components/IconButton'\nimport type { IconProps } from 'components/Icon'\nimport { DropdownMenu } from './DropdownMenu'\nimport { SIZES, SIZES_CHECKBOX, SIZES_ICON, FuseSearchKeys } from './constants'\nimport { getDropdownInputText, getDropdownSelectedOption, groupDropdownOptions } from './utils'\nimport * as Styled from './style'\nimport type { DropdownProps, DropdownOption } from './types'\n\nconst COMPONENT_NAME = 'Dropdown'\n\n/**\n *\n * Компонент поддерживает все атрибуты \\<div\\> элемента.\n *\n * Можно передать \"ref\", который будет ассоциирован с рутовым элементом.\n *\n * Поддерживаются пропсы определения размеров и внешних отступов в зависимости от ширины вьюпорта.\n *\n * Полный интерфейс можно посмотреть [тут](https://github.com/foxford/ui/blob/master/src/components/Dropdown/types.ts).\n */\nconst Dropdown: React.ForwardRefExoticComponent<DropdownProps> = withMergedProps<DropdownProps, HTMLDivElement>(\n forwardRef((props, ref) => {\n const {\n size = 'm',\n name = 'fox-dropdown',\n labelPosition = 'dynamic',\n searchable = true,\n primary = true,\n optionsMultiToggle = true,\n loading = false,\n iconProps = {},\n menuProps = {},\n loadingIconProps = {},\n optionsEmptyIconProps = {},\n autoFocus,\n disableAutoScrollToSelectedOption,\n closeMenuOnScroll,\n scrollMonitorTarget,\n contrast,\n selectedOption,\n defaultSelectedOption,\n icon,\n inputMode,\n loadingMessage,\n loadingIcon,\n maxLength,\n multiple,\n clearable,\n onCloseMenu,\n onOpenMenu,\n onSelectOption,\n options,\n groupSelectedOptions,\n optionsMultiToggleCaption,\n optionsEmptyMessage,\n optionsEmptyIcon,\n palette,\n placeholder,\n readOnly,\n required,\n status,\n sizeXXS,\n sizeXS,\n sizeS,\n sizeM,\n sizeL,\n sizeXL,\n form,\n ...rootProps\n } = props\n\n const sizeProps = {\n size,\n sizeXXS,\n sizeXS,\n sizeS,\n sizeM,\n sizeL,\n sizeXL,\n }\n\n const iconBaseProps: IconProps = {\n sizes: SIZES_ICON,\n color: rootProps.disabled ? 'content-disabled' : 'content-onmain-tertiary',\n }\n\n const formInputLabelId = useMemo(() => rootProps.id ?? `${name}-${nanoid()}`, [name, rootProps.id])\n const inputLabelId = useMemo(() => nanoid(), [])\n const menuListId = useMemo(() => nanoid(), [])\n\n const getRelevantOptions = useMemo(() => {\n const fuse = new Fuse<DropdownOption>(options, {\n threshold: 0.4,\n ignoreLocation: true,\n keys: [FuseSearchKeys.text, FuseSearchKeys.label, FuseSearchKeys.tags],\n })\n\n return (pattern: string): DropdownOption[] =>\n pattern.length === 0 ? options : fuse.search(pattern).map((result) => result.item)\n }, [options])\n\n const [dropdownSelectedOption, setDropdownSelectedOption] = useState<DropdownOption[]>(() =>\n getDropdownSelectedOption(selectedOption !== undefined ? selectedOption : defaultSelectedOption, multiple)\n )\n\n const [inputText, setInputText] = useState<string>(() => getDropdownInputText(dropdownSelectedOption, multiple))\n\n const [focusWithin, setFocusWithin] = useState<boolean>(false)\n\n const [menuRelevantOptions, setMenuRelevantOptions] = useState<DropdownOption[]>(() =>\n getRelevantOptions(inputText)\n )\n\n const [menuOpenRequest, setMenuOpenRequest] = useState<boolean>(false)\n\n const menuOptionsGroups: ReturnType<typeof groupDropdownOptions> = multiple\n ? groupDropdownOptions(options, dropdownSelectedOption)\n : [[], []]\n\n const menuOpen = menuOpenRequest && !rootProps.disabled\n\n const inputSynced = inputText === getDropdownInputText(dropdownSelectedOption)\n const inputRequired = required && dropdownSelectedOption.length === 0\n const inputActive = Boolean(menuOpen || inputText || focusWithin)\n\n const multiToggleChecked = menuOptionsGroups[0].length > 0 && menuOptionsGroups[1].length === 0\n const multiToggleIndeterminate = menuOptionsGroups[0].length > 0 && menuOptionsGroups[1].length > 0\n\n const inputRef = useRef<HTMLInputElement>(null)\n const [menuRef, setMenuRef] = useState<Nullable<HTMLElement>>(null)\n const menuListRef = useRef<HTMLUListElement>(null)\n const selectedOptionRef = useRef<HTMLElement>(null)\n\n const timeoutIdRef = useRef<Nullable<ReturnType<typeof setTimeout>>>(null)\n\n const inputTextPrevRef = useRef<string>(inputText)\n const menuOpenPrevRef = useRef<boolean>(menuOpen)\n\n useScrollMonitor({\n target: scrollMonitorTarget,\n onScrollStart: () => {\n if (closeMenuOnScroll && menuOpen) {\n inputRef.current?.focus()\n setMenuOpenRequest(false)\n }\n },\n })\n\n useEffect(() => {\n if (inputText === inputTextPrevRef.current) {\n setMenuRelevantOptions(getRelevantOptions(inputText))\n } else {\n inputTextPrevRef.current = inputText\n timeoutIdRef.current = setTimeout(() => {\n setMenuRelevantOptions(getRelevantOptions(inputText))\n }, 150)\n }\n\n return () => {\n if (timeoutIdRef.current) {\n clearTimeout(timeoutIdRef.current)\n }\n }\n }, [getRelevantOptions, inputText])\n\n useLayoutEffect(() => {\n if (selectedOption === undefined) return\n\n if (!multiple) setInputText(getDropdownInputText(selectedOption))\n setDropdownSelectedOption(getDropdownSelectedOption(selectedOption, multiple))\n }, [multiple, selectedOption])\n\n useEffect(() => {\n if (menuOpen === menuOpenPrevRef.current) return\n\n if (menuOpen && onOpenMenu) onOpenMenu()\n if (!menuOpen && onCloseMenu) onCloseMenu()\n\n menuOpenPrevRef.current = menuOpen\n }, [menuOpen, onCloseMenu, onOpenMenu])\n\n useEffect(() => {\n if (!multiple && !disableAutoScrollToSelectedOption && menuOpen && menuRef && selectedOptionRef.current) {\n const menuRect = menuRef.getBoundingClientRect()\n const selectedOptionRect = selectedOptionRef.current.getBoundingClientRect()\n\n if (selectedOptionRect.top < menuRect.top || selectedOptionRect.bottom > menuRect.bottom) {\n menuRef.scrollTo(0, selectedOptionRef.current.offsetTop)\n }\n }\n }, [multiple, disableAutoScrollToSelectedOption, menuOpen, menuRef])\n\n return (\n <FormInputLabel\n {...rootProps}\n {...sizeProps}\n ref={ref}\n id={formInputLabelId}\n labelId={inputLabelId}\n labelPosition={labelPosition}\n active={inputActive}\n onColored={contrast}\n primary={primary}\n error={status === 'error'}\n success={status === 'success'}\n focus={focusWithin}\n icon={[icon, <Styled.ChevronIcon key='chevron' up={menuOpen} />]}\n iconProps={{\n ...sizeProps,\n ...iconBaseProps,\n ...iconProps,\n }}\n palette={{\n color: rootProps.disabled ? palette.labelColorDisabled : palette.labelColor,\n backgroundColor: rootProps.disabled ? palette.backgroundColorDisabled : palette.backgroundColor,\n backgroundColorHover: rootProps.disabled ? palette.backgroundColorDisabled : palette.backgroundColorHover,\n borderColor: rootProps.disabled ? palette.borderColorDisabled : palette.borderColor,\n }}\n onClick={(evt) => {\n if (rootProps.onClick) rootProps.onClick(evt)\n\n if (rootProps.disabled) return\n\n inputRef.current?.focus()\n\n if (!menuOpen) {\n setMenuOpenRequest(true)\n\n if (searchable && !multiple && inputSynced) {\n setInputText('')\n setMenuRelevantOptions(getRelevantOptions(''))\n }\n } else if (menuRef && evt.target instanceof Node && !menuRef.contains(evt.target)) {\n setMenuOpenRequest(false)\n }\n }}\n onPointerDown={(evt) => {\n if (rootProps.onPointerDown) rootProps.onPointerDown(evt)\n\n if (\n evt.target !== inputRef.current &&\n evt.target instanceof Node &&\n (evt.currentTarget.contains(evt.target) ||\n (menuProps.renderInPortal && menuOpen && menuRef && menuRef.contains(evt.target)))\n ) {\n evt.preventDefault()\n }\n }}\n onFocus={(evt) => {\n if (rootProps.onFocus) rootProps.onFocus(evt)\n\n setFocusWithin(true)\n\n if (\n inputRef.current &&\n evt.target === inputRef.current &&\n searchable &&\n !multiple &&\n inputSynced &&\n !menuOpen\n ) {\n setInputText('')\n setMenuRelevantOptions(getRelevantOptions(''))\n }\n }}\n onBlur={(evt) => {\n if (rootProps.onBlur) rootProps.onBlur(evt)\n\n if (\n evt.currentTarget.contains(evt.relatedTarget) ||\n (menuProps.renderInPortal && menuOpen && menuRef && menuRef.contains(evt.relatedTarget))\n ) {\n return\n }\n\n setFocusWithin(false)\n setInputText(getDropdownInputText(dropdownSelectedOption, multiple))\n setMenuOpenRequest(false)\n }}\n input={\n <>\n {inputRequired && !searchable && !readOnly && (\n <Styled.InputMimic\n required\n type='text'\n inputMode='none'\n form={form}\n tabIndex={-1}\n onFocus={() => {\n inputRef.current?.focus()\n }}\n />\n )}\n <FormInput\n ref={inputRef}\n role='combobox'\n aria-controls={menuListId}\n aria-expanded={menuOpen}\n aria-labelledby={rootProps.label ? inputLabelId : undefined}\n type='text'\n autoComplete='off'\n autoCapitalize='off'\n autoCorrect='off'\n spellCheck='false'\n form={form}\n autoFocus={autoFocus}\n inputMode={searchable ? inputMode : 'none'}\n maxLength={maxLength}\n placeholder={placeholder}\n readOnly={readOnly || !searchable}\n required={inputRequired}\n disabled={rootProps.disabled}\n value={inputText}\n palette={{\n color: palette.color,\n colorDisabled: palette.colorDisabled,\n placeholderColor: palette.placeholderColor,\n placeholderColorDisabled: palette.placeholderColorDisabled,\n }}\n onClick={(evt) => {\n if (menuOpen && evt.currentTarget.selectionStart !== evt.currentTarget.selectionEnd) {\n evt.stopPropagation()\n }\n }}\n onChange={(evt) => {\n setInputText(evt.currentTarget.value)\n setMenuOpenRequest(true)\n }}\n onKeyDown={(evt) => {\n if (keyboardKeys.Enter.validate(evt.key)) {\n setInputText(getDropdownInputText(dropdownSelectedOption, multiple))\n setMenuOpenRequest(false)\n }\n\n if (keyboardKeys.Space.validate(evt.key) && (!menuOpen || evt.currentTarget.selectionStart === 0)) {\n evt.preventDefault()\n\n if (searchable && !multiple && inputSynced && !menuOpen) {\n setInputText('')\n setMenuRelevantOptions(getRelevantOptions(''))\n }\n\n setMenuOpenRequest((prev) => !prev)\n }\n\n if (keyboardKeys.Esc.validate(evt.key)) {\n setMenuOpenRequest(false)\n }\n\n if (keyboardKeys.Tab.validate(evt.key) && menuOpen) {\n evt.preventDefault()\n setMenuOpenRequest(false)\n }\n\n if (keyboardKeys.ArrowDown.validate(evt.key) && menuOpen && menuListRef.current) {\n evt.preventDefault()\n\n if (!multiple && selectedOptionRef.current) {\n const menuItems = [...menuListRef.current.children]\n\n const idx = menuItems.findIndex((item) => item.contains(selectedOptionRef.current as Node))\n\n const focusTarget = menuItems[idx + 1] ?? menuItems[0]\n\n if (focusTarget instanceof HTMLElement) {\n focusFirstFocusable(focusTarget)\n }\n } else {\n focusFirstFocusable(menuListRef.current)\n }\n }\n\n if (keyboardKeys.ArrowUp.validate(evt.key) && menuOpen && menuListRef.current) {\n evt.preventDefault()\n\n if (!multiple && selectedOptionRef.current) {\n const menuItems = [...menuListRef.current.children]\n\n const idx = menuItems.findIndex((item) => item.contains(selectedOptionRef.current as Node))\n\n const focusTarget = menuItems[idx - 1] ?? menuItems[menuItems.length - 1]\n\n if (focusTarget instanceof HTMLElement) {\n focusFirstFocusable(focusTarget)\n }\n } else {\n focusLastFocusable(menuListRef.current)\n }\n }\n }}\n />\n {dropdownSelectedOption.map((item) => (\n <input\n key={item.value}\n type='hidden'\n name={name}\n value={item.value}\n form={form}\n disabled={rootProps.disabled}\n />\n ))}\n </>\n }\n addon={\n <>\n {multiple && dropdownSelectedOption.length > 0 && (\n <Chip\n size='xs'\n active\n black\n marginLeft={12}\n disabled={rootProps.disabled}\n cursor={rootProps.disabled ? 'not-allowed' : undefined}\n text={dropdownSelectedOption.length}\n textProps={{\n appearance: 'caption',\n size: 'xs',\n }}\n palette={\n rootProps.disabled\n ? {\n color: 'content-disabled',\n colorHover: 'content-disabled',\n backgroundColor: 'bg-disabled-small',\n backgroundColorHover: 'bg-disabled-small',\n }\n : undefined\n }\n onPointerDown={(evt) => {\n evt.preventDefault()\n }}\n discardButtonProps={{\n contrast: !rootProps.disabled,\n onClick: (evt) => {\n evt.stopPropagation()\n\n if (!readOnly) {\n if (selectedOption === undefined) {\n setDropdownSelectedOption([])\n }\n\n if (onSelectOption) onSelectOption(multiple ? [] : null)\n\n inputRef.current?.focus()\n setMenuOpenRequest(true)\n }\n },\n }}\n />\n )}\n {!multiple && clearable && dropdownSelectedOption.length > 0 && (\n <IconButton\n icon='close'\n size='l'\n square\n marginLeft={12}\n disabled={rootProps.disabled}\n onClick={(evt) => {\n evt.stopPropagation()\n\n if (!readOnly) {\n if (inputSynced) {\n setInputText('')\n setMenuRelevantOptions(getRelevantOptions(''))\n }\n\n if (selectedOption === undefined) {\n setDropdownSelectedOption([])\n }\n\n if (onSelectOption) onSelectOption(multiple ? [] : null)\n\n inputRef.current?.focus()\n setMenuOpenRequest(true)\n }\n }}\n />\n )}\n </>\n }\n dropdown={\n <DropdownMenu\n {...menuProps}\n setRef={setMenuRef}\n open={menuOpen}\n popperReferenceId={formInputLabelId}\n secondary={!contrast}\n elevated={contrast}\n disableAutoFocus\n palette={{\n backgroundColor: palette.menuBackgroundColor,\n borderColor: palette.menuBorderColor,\n }}\n empty={menuRelevantOptions.length === 0}\n loading={loading}\n loadingMessage={loadingMessage}\n loadingIcon={loadingIcon}\n loadingIconProps={{\n ...sizeProps,\n ...iconBaseProps,\n ...loadingIconProps,\n }}\n emptyMessage={optionsEmptyMessage}\n emptyIcon={optionsEmptyIcon}\n emptyIconProps={{\n ...sizeProps,\n ...iconBaseProps,\n ...optionsEmptyIconProps,\n }}\n onKeyDown={(evt) => {\n if (keyboardKeys.Tab.validate(evt.key)) {\n evt.preventDefault()\n inputRef.current?.focus()\n setMenuOpenRequest(false)\n }\n\n if (keyboardKeys.Enter.validate(evt.key)) {\n inputRef.current?.focus()\n setInputText(getDropdownInputText(dropdownSelectedOption, multiple))\n setMenuOpenRequest(false)\n }\n\n if (keyboardKeys.Esc.validate(evt.key)) {\n inputRef.current?.focus()\n setMenuOpenRequest(false)\n }\n\n if (keyboardKeys.Backspace.validate(evt.key) && !readOnly && (multiple || (!multiple && clearable))) {\n if (selectedOption === undefined) {\n setDropdownSelectedOption([])\n }\n\n if (onSelectOption) onSelectOption(multiple ? [] : null)\n }\n }}\n >\n {multiple ? (\n <MenuList\n ref={menuListRef}\n id={menuListId}\n role='listbox'\n aria-labelledby={rootProps.label ? inputLabelId : undefined}\n aria-multiselectable\n >\n {inputText.length === 0 ? (\n <>\n {optionsMultiToggle && (\n <ListItem\n {...sizeProps}\n text={optionsMultiToggleCaption}\n disabled={rootProps.disabled}\n borderRadius={8}\n ellipsis={false}\n textProps={{ wordBreak: 'break-word' }}\n onClick={(evt) => {\n evt.stopPropagation()\n }}\n control={\n <InputCheckbox\n sizes={SIZES_CHECKBOX}\n form='none'\n name={name}\n checked={multiToggleChecked}\n indeterminate={multiToggleIndeterminate}\n error={(multiToggleChecked || multiToggleIndeterminate) && status === 'error'}\n success={(multiToggleChecked || multiToggleIndeterminate) && status === 'success'}\n onChange={() => {\n if (!readOnly) {\n const update = multiToggleChecked || multiToggleIndeterminate ? [] : [...options]\n\n if (selectedOption === undefined) {\n setDropdownSelectedOption(update)\n }\n\n if (onSelectOption) onSelectOption(update)\n }\n }}\n />\n }\n />\n )}\n {optionsMultiToggle && <MenuDivider />}\n {groupSelectedOptions &&\n menuOptionsGroups[0].map((option) => {\n const optionStatus = option.status ?? status\n const optionErrorStatus = optionStatus === 'error'\n const optionSuccessStatus = optionStatus === 'success'\n\n return (\n <ListItem\n {...sizeProps}\n key={option.value}\n active\n text={option.text}\n danger={optionErrorStatus}\n success={optionSuccessStatus}\n disabled={rootProps.disabled}\n borderRadius={8}\n ellipsis={false}\n textProps={{ wordBreak: 'break-word' }}\n onClick={(evt) => {\n evt.stopPropagation()\n inputRef.current?.focus()\n }}\n control={\n <InputCheckbox\n sizes={SIZES_CHECKBOX}\n form='none'\n role='option'\n aria-selected\n name={name}\n value={option.value}\n checked\n error={optionErrorStatus}\n success={optionSuccessStatus}\n onChange={(evt) => {\n if (!readOnly) {\n const update = dropdownSelectedOption.filter(\n (item) => item.value !== evt.currentTarget.value\n )\n\n if (selectedOption === undefined) {\n setDropdownSelectedOption(update)\n }\n\n if (onSelectOption) onSelectOption(update)\n }\n }}\n />\n }\n />\n )\n })}\n {groupSelectedOptions && menuOptionsGroups[0].length > 0 && menuOptionsGroups[1].length > 0 && (\n <MenuDivider />\n )}\n {groupSelectedOptions &&\n menuOptionsGroups[1].map((option) => (\n <ListItem\n {...sizeProps}\n key={option.value}\n text={option.text}\n disabled={rootProps.disabled}\n borderRadius={8}\n ellipsis={false}\n textProps={{ wordBreak: 'break-word' }}\n onClick={(evt) => {\n evt.stopPropagation()\n inputRef.current?.focus()\n }}\n control={\n <InputCheckbox\n sizes={SIZES_CHECKBOX}\n form='none'\n role='option'\n aria-selected={false}\n name={name}\n value={option.value}\n checked={false}\n onChange={() => {\n if (!readOnly) {\n const update = [...dropdownSelectedOption, option]\n\n if (selectedOption === undefined) {\n setDropdownSelectedOption(update)\n }\n\n if (onSelectOption) onSelectOption(update)\n }\n }}\n />\n }\n />\n ))}\n {!groupSelectedOptions &&\n options.map((option) => {\n const selected = dropdownSelectedOption.findIndex((item) => item.value === option.value) !== -1\n\n const optionStatus = option.status ?? status\n const optionErrorStatus = selected && optionStatus === 'error'\n const optionSuccessStatus = selected && optionStatus === 'success'\n\n return (\n <ListItem\n {...sizeProps}\n key={option.value}\n text={option.text}\n danger={optionErrorStatus}\n success={optionSuccessStatus}\n disabled={rootProps.disabled}\n active={selected}\n borderRadius={8}\n ellipsis={false}\n textProps={{ wordBreak: 'break-word' }}\n onClick={(evt) => {\n evt.stopPropagation()\n }}\n control={\n <InputCheckbox\n sizes={SIZES_CHECKBOX}\n form='none'\n role='option'\n aria-selected={selected}\n name={name}\n value={option.value}\n checked={selected}\n error={optionErrorStatus}\n success={optionSuccessStatus}\n onChange={(evt) => {\n if (!readOnly) {\n const update = selected\n ? dropdownSelectedOption.filter((item) => item.value !== evt.currentTarget.value)\n : [...dropdownSelectedOption, option]\n\n if (selectedOption === undefined) {\n setDropdownSelectedOption(update)\n }\n\n if (onSelectOption) onSelectOption(update)\n }\n }}\n />\n }\n />\n )\n })}\n </>\n ) : (\n <>\n {menuRelevantOptions.map((option) => {\n const selected = dropdownSelectedOption.findIndex((item) => item.value === option.value) !== -1\n\n const optionStatus = option.status ?? status\n const optionErrorStatus = selected && optionStatus === 'error'\n const optionSuccessStatus = selected && optionStatus === 'success'\n\n return (\n <ListItem\n {...sizeProps}\n key={option.value}\n text={option.text}\n danger={optionErrorStatus}\n success={optionSuccessStatus}\n disabled={rootProps.disabled}\n active={selected}\n borderRadius={8}\n ellipsis={false}\n textProps={{ wordBreak: 'break-word' }}\n onClick={(evt) => {\n evt.stopPropagation()\n }}\n control={\n <InputCheckbox\n sizes={SIZES_CHECKBOX}\n form='none'\n role='option'\n aria-selected={selected}\n name={name}\n value={option.value}\n checked={selected}\n error={optionErrorStatus}\n success={optionSuccessStatus}\n onChange={(evt) => {\n if (!readOnly) {\n const update = selected\n ? dropdownSelectedOption.filter((item) => item.value !== evt.currentTarget.value)\n : [...dropdownSelectedOption, option]\n\n if (selectedOption === undefined) {\n setDropdownSelectedOption(update)\n }\n\n if (onSelectOption) onSelectOption(update)\n }\n }}\n />\n }\n />\n )\n })}\n </>\n )}\n </MenuList>\n ) : (\n <MenuList\n ref={menuListRef}\n id={menuListId}\n role='listbox'\n aria-labelledby={rootProps.label ? inputLabelId : undefined}\n >\n {(searchable ? menuRelevantOptions : options).map((option) => {\n const selected = dropdownSelectedOption.findIndex((item) => item.value === option.value) !== -1\n\n return (\n <ListItem\n {...sizeProps}\n role='option'\n aria-selected={selected}\n ref={selected ? selectedOptionRef : undefined}\n key={option.value}\n text={option.text}\n active={selected}\n danger={selected && status === 'error'}\n success={selected && status === 'success'}\n disabled={rootProps.disabled}\n borderRadius={8}\n ellipsis={false}\n textProps={{ wordBreak: 'break-word' }}\n onClick={(evt) => {\n evt.stopPropagation()\n\n if (!readOnly) {\n const update = { ...option }\n\n if (selectedOption === undefined) {\n setInputText(getDropdownInputText(update))\n setDropdownSelectedOption(getDropdownSelectedOption(update))\n }\n\n if (onSelectOption) onSelectOption(update)\n\n inputRef.current?.focus()\n setMenuOpenRequest(false)\n }\n }}\n />\n )\n })}\n </MenuList>\n )}\n </DropdownMenu>\n }\n />\n )\n }),\n {\n sizes: SIZES,\n displayName: COMPONENT_NAME,\n }\n)\n\nexport { Dropdown, COMPONENT_NAME }\n"],"names":["Dropdown","withMergedProps","forwardRef","props","ref","size","name","labelPosition","searchable","primary","optionsMultiToggle","loading","iconProps","menuProps","loadingIconProps","optionsEmptyIconProps","autoFocus","disableAutoScrollToSelectedOption","closeMenuOnScroll","scrollMonitorTarget","contrast","selectedOption","defaultSelectedOption","icon","inputMode","loadingMessage","loadingIcon","maxLength","multiple","clearable","onCloseMenu","onOpenMenu","onSelectOption","options","groupSelectedOptions","optionsMultiToggleCaption","optionsEmptyMessage","optionsEmptyIcon","palette","placeholder","readOnly","required","status","sizeXXS","sizeXS","sizeS","sizeM","sizeL","sizeXL","form","rootProps","sizeProps","iconBaseProps","sizes","SIZES_ICON","color","disabled","formInputLabelId","useMemo","id","nanoid","inputLabelId","menuListId","getRelevantOptions","fuse","Fuse","default","threshold","ignoreLocation","keys","FuseSearchKeys","text","label","tags","pattern","length","search","map","result","item","dropdownSelectedOption","setDropdownSelectedOption","useState","getDropdownSelectedOption","undefined","inputText","setInputText","getDropdownInputText","focusWithin","setFocusWithin","menuRelevantOptions","setMenuRelevantOptions","menuOpenRequest","setMenuOpenRequest","menuOptionsGroups","groupDropdownOptions","menuOpen","inputSynced","inputRequired","inputActive","Boolean","multiToggleChecked","multiToggleIndeterminate","inputRef","useRef","menuRef","setMenuRef","menuListRef","selectedOptionRef","timeoutIdRef","inputTextPrevRef","menuOpenPrevRef","useScrollMonitor","target","onScrollStart","current","focus","useEffect","setTimeout","clearTimeout","useLayoutEffect","menuRect","getBoundingClientRect","selectedOptionRect","top","bottom","scrollTo","offsetTop","_jsx","FormInputLabel","labelId","active","onColored","error","success","jsx","Styled","up","labelColorDisabled","labelColor","backgroundColor","backgroundColorDisabled","backgroundColorHover","borderColor","borderColorDisabled","onClick","evt","Node","contains","onPointerDown","currentTarget","renderInPortal","preventDefault","onFocus","onBlur","relatedTarget","input","_jsxs","jsxs","_Fragment","children","type","tabIndex","FormInput","role","autoComplete","autoCapitalize","autoCorrect","spellCheck","value","colorDisabled","placeholderColor","placeholderColorDisabled","selectionStart","selectionEnd","stopPropagation","onChange","onKeyDown","keyboardKeys","Enter","validate","key","Space","prev","Esc","Tab","ArrowDown","menuItems","idx","findIndex","focusTarget","HTMLElement","focusFirstFocusable","ArrowUp","focusLastFocusable","addon","Chip","black","marginLeft","cursor","textProps","appearance","colorHover","discardButtonProps","IconButton","square","dropdown","DropdownMenu","setRef","open","popperReferenceId","secondary","elevated","disableAutoFocus","menuBackgroundColor","menuBorderColor","empty","emptyMessage","emptyIcon","emptyIconProps","Backspace","MenuList","ListItem","borderRadius","ellipsis","wordBreak","control","InputCheckbox","SIZES_CHECKBOX","checked","indeterminate","update","MenuDivider","option","optionStatus","optionErrorStatus","optionSuccessStatus","_createElement","danger","filter","createElement","selected","SIZES","displayName"],"mappings":"6iCAmCMA,MAAAA,SAA2DC,gBAAAA,gBAC/DC,MAAAA,YAAW,CAACC,EAAOC,KACjB,MAAMC,KACJA,EAAO,IAAGC,KACVA,EAAO,eAAcC,cACrBA,EAAgB,UAASC,WACzBA,GAAa,EAAIC,QACjBA,GAAU,EAAIC,mBACdA,GAAqB,EAAIC,QACzBA,GAAU,EAAKC,UACfA,EAAY,CAAE,EAAAC,UACdA,EAAY,CAAE,EAAAC,iBACdA,EAAmB,CAAE,EAAAC,sBACrBA,EAAwB,CAAE,EAAAC,UAC1BA,EAASC,kCACTA,EAAiCC,kBACjCA,EAAiBC,oBACjBA,EAAmBC,SACnBA,EAAQC,eACRA,EAAcC,sBACdA,EAAqBC,KACrBA,EAAIC,UACJA,EAASC,eACTA,EAAcC,YACdA,EAAWC,UACXA,EAASC,SACTA,EAAQC,UACRA,EAASC,YACTA,EAAWC,WACXA,EAAUC,eACVA,EAAcC,QACdA,EAAOC,qBACPA,EAAoBC,0BACpBA,EAAyBC,oBACzBA,EAAmBC,iBACnBA,EAAgBC,QAChBA,EAAOC,YACPA,EAAWC,SACXA,EAAQC,SACRA,EAAQC,OACRA,EAAMC,QACNA,EAAOC,OACPA,EAAMC,MACNA,EAAKC,MACLA,EAAKC,MACLA,EAAKC,OACLA,EAAMC,KACNA,KACGC,GACD/C,EAEJ,MAAMgD,EAAY,CAChB9C,OACAsC,UACAC,SACAC,QACAC,QACAC,QACAC,UAGF,MAAMI,EAA2B,CAC/BC,MAAOC,UAAUA,WACjBC,MAAOL,EAAUM,SAAW,mBAAqB,2BAGnD,MAAM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,KAAMkK,EAAOlK,KACb4D,OAAQ8G,EACRH,OAAQG,GAAYvM,IAAW,QAC/B4F,QAAS2G,GAAYvM,IAAW,UAChCc,SAAUN,EAAUM,SACpBuK,aAAc,EACdC,UAAU,EACVxB,UAAW,CAAEyB,UAAW,cACxBhF,QAAUC,IAGR,GAFAA,EAAI6B,mBAECvI,EAAU,CACb,MAAM+L,EAAS,IAAKE,GAEhBpN,SAAmB+D,IACrBE,GAAaC,MAAAA,qBAAqBgJ,IAClCtJ,GAA0BE,MAAAA,0BAA0BoJ,KAGlDvM,GAAgBA,EAAeuM,GAEnChI,GAASY,SAASC,QAClBvB,IAAmB,EACrB,IAEF,SAOd,IAGN,CACExC,MAAO6L,UAAKA,MACZC,YA7zBmB,oCAAA"}
@@ -1,2 +1,2 @@
1
- import{forwardRef,useMemo,useState,useRef,useEffect,useLayoutEffect,createElement}from'react';import Fuse from'../../external/.pnpm/fuse.js@7.0.0/node_modules/fuse.js/dist/fuse.mjs';import{nanoid}from'../../external/.pnpm/nanoid@5.0.7/node_modules/nanoid/index.browser.mjs';import{withMergedProps}from'../../hocs/withMergedProps.mjs';import{focusFirstFocusable}from'../../shared/utils/dom.mjs';import{keyboardKeys}from'../../shared/constants.mjs';import{DropdownMenu}from'./DropdownMenu.mjs';import{DropdownMenuNoOptions}from'./DropdownMenuNoOptions.mjs';import{SIZES,SIZES_ICON,FuseSearchKeys,SIZES_CHECKBOX}from'./constants.mjs';import{getDropdownSelectedOption,getDropdownInputText,groupDropdownOptions}from'./utils.mjs';import{ChevronIcon,InputMimic}from'./style.mjs';import{jsx,jsxs,Fragment}from'react/jsx-runtime';import{FormInputLabel}from'../FormInputLabel/FormInputLabel.mjs';import{FormInput}from'../FormInput/FormInput.mjs';import{Chip}from'../Chip/Chip.mjs';import{MenuList}from'../MenuList/MenuList.mjs';import{ListItem}from'../ListItem/ListItem.mjs';import{InputCheckbox}from'../InputCheckbox/InputCheckbox.mjs';import{MenuDivider}from'../MenuDivider/MenuDivider.mjs';const COMPONENT_NAME='Dropdown';const Dropdown=withMergedProps(forwardRef(((e,o)=>{const{size:t="m",name:r="fox-dropdown",labelPosition:n="dynamic",searchable:s=!0,primary:a=!0,optionsMultiToggle:c=!0,loading:i=!1,iconProps:l={},menuProps:u={},loadingIconProps:d={},optionsEmptyIconProps:p={},autoFocus:m,disableAutoScrollToSelectedOption:g,closeMenuOnScroll:b,contrast:f,selectedOption:v,defaultSelectedOption:C,icon:x,inputMode:h,loadingMessage:k,loadingIcon:I,maxLength:y,multiple:w,onCloseMenu:D,onOpenMenu:S,onSelectOption:E,options:j,groupSelectedOptions:M,optionsMultiToggleCaption:F,optionsEmptyMessage:P,optionsEmptyIcon:T,palette:L,placeholder:O,readOnly:z,required:K,status:B,sizeXXS:R,sizeXS:N,sizeS:X,sizeM:_,sizeL:H,sizeXL:Z,form:A,...q}=e;const U={size:t,sizeXXS:R,sizeXS:N,sizeS:X,sizeM:_,sizeL:H,sizeXL:Z};const G={sizes:SIZES_ICON,color:q.disabled?'content-disabled':'content-onmain-tertiary'};const J=useMemo((()=>nanoid()),[]);const Q=useMemo((()=>{const e=new Fuse(j,{threshold:.4,ignoreLocation:!0,keys:[FuseSearchKeys.text,FuseSearchKeys.label,FuseSearchKeys.tags]});return o=>o.length===0?j:e.search(o).map((e=>e.item))}),[j]);const[V,W]=useState((()=>getDropdownSelectedOption(v!==void 0?v:C,w)));const[Y,$]=useState((()=>getDropdownInputText(V,w)));const[ee,oe]=useState(!1);const[te,re]=useState((()=>Q(Y)));const[ne,se]=useState(!1);const ae=w?groupDropdownOptions(j,V):[[],[]];const ce=ne&&!q.disabled;const ie=te.length===0||i;const le=Y===getDropdownInputText(V);const ue=K&&V.length===0;const de=Boolean(ce||Y||ee);const pe=ae[0].length>0&&ae[1].length===0;const me=ae[0].length>0&&ae[1].length>0;const ge=useRef(null);const be=useRef(null);const fe=useRef(null);const ve=useRef(null);const Ce=useRef(null);const xe=useRef(Y);const he=useRef(ce);return useEffect((()=>(Y===xe.current?re(Q(Y)):(xe.current=Y,Ce.current=setTimeout((()=>{re(Q(Y))}),150)),()=>{Ce.current&&clearTimeout(Ce.current)})),[Q,Y]),useLayoutEffect((()=>{v!==void 0&&(w||$(getDropdownInputText(v)),W(getDropdownSelectedOption(v,w)))}),[w,v]),useEffect((()=>{ce!==he.current&&(ce&&S&&S(),!ce&&D&&D(),he.current=ce)}),[ce,D,S]),useEffect((()=>{if(!w&&!g&&ce&&be.current&&ve.current){const e=be.current.getBoundingClientRect();const o=ve.current.getBoundingClientRect();(o.top<e.top||o.bottom>e.bottom)&&be.current.scrollTo(0,ve.current.offsetTop)}}),[w,g,ce]),useEffect((()=>{const handleScroll=e=>{ge.current?.focus(),se(!1),e.currentTarget&&e.currentTarget.removeEventListener(e.type,handleScroll)};return b&&ce&&document.addEventListener('scroll',handleScroll),()=>{document.removeEventListener('scroll',handleScroll)}}),[b,ce]),jsx(FormInputLabel,{...q,...U,ref:o,labelId:J,labelPosition:n,active:de,onColored:f,primary:a,error:B==='error',success:B==='success',icon:[x,jsx(ChevronIcon,{up:ce},'chevron')],iconProps:{...U,...G,...l},palette:{color:q.disabled?L.labelColorDisabled:L.labelColor,backgroundColor:q.disabled?L.backgroundColorDisabled:L.backgroundColor,backgroundColorHover:q.disabled?L.backgroundColorDisabled:L.backgroundColorHover,borderColor:q.disabled?L.borderColorDisabled:L.borderColor},onClick:e=>{q.onClick&&q.onClick(e),q.disabled||(ge.current?.focus(),ce?be.current&&e.target instanceof Node&&!be.current.contains(e.target)&&se(!1):(se(!0),s&&!w&&le&&($(''),re(Q('')))))},onKeyUp:e=>{q.onKeyUp&&q.onKeyUp(e),keyboardKeys.Esc.validate(e.key)&&(ge.current?.focus(),se(!1))},onPointerDown:e=>{q.onPointerDown&&q.onPointerDown(e),e.target!==ge.current&&e.target instanceof Node&&e.currentTarget.contains(e.target)&&e.preventDefault()},onFocus:e=>{q.onFocus&&q.onFocus(e),ge.current&&e.target===ge.current&&(oe(!0),s&&!w&&le&&!ce&&($(''),re(Q(''))))},onBlur:e=>{q.onBlur&&q.onBlur(e),ge.current&&e.target===ge.current&&oe(!1),e.currentTarget.contains(e.relatedTarget)||($(getDropdownInputText(V,w)),se(!1))},input:jsxs(Fragment,{children:[ue&&!s&&!z&&jsx(InputMimic,{required:!0,type:"text",inputMode:"none",form:A,tabIndex:-1,onFocus:()=>{ge.current?.focus()}}),jsx(FormInput,{ref:ge,"aria-labelledby":q.label?J:void 0,type:"text",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",form:A,autoFocus:m,inputMode:s?h:'none',maxLength:y,placeholder:O,readOnly:z||!s,required:ue,disabled:q.disabled,value:Y,palette:{color:L.color,colorDisabled:L.colorDisabled,placeholderColor:L.placeholderColor,placeholderColorDisabled:L.placeholderColorDisabled},onClick:e=>{ce&&e.currentTarget.selectionStart!==e.currentTarget.selectionEnd&&e.stopPropagation()},onChange:e=>{$(e.currentTarget.value),se(!0)},onKeyDown:e=>{keyboardKeys.Enter.validate(e.key)&&($(getDropdownInputText(V,w)),se(!1)),!keyboardKeys.Space.validate(e.key)||ce&&e.currentTarget.selectionStart!==0||(e.preventDefault(),s&&!w&&le&&!ce&&($(''),re(Q(''))),se((e=>!e))),keyboardKeys.ArrowDown.validate(e.key)&&fe.current&&(e.preventDefault(),focusFirstFocusable(fe.current))}}),V.map((e=>jsx("input",{type:"hidden",name:r,value:e.value,form:A,disabled:q.disabled},e.value)))]}),addon:w&&V.length>0?jsx(Chip,{size:"xs",active:!0,black:!0,marginLeft:12,disabled:q.disabled,cursor:q.disabled?'not-allowed':void 0,text:V.length,textProps:{appearance:'caption',size:'xs'},palette:q.disabled?{color:'content-disabled',colorHover:'content-disabled',backgroundColor:'bg-disabled-small',backgroundColorHover:'bg-disabled-small'}:void 0,onPointerDown:e=>{e.preventDefault()},discardButtonProps:{contrast:!q.disabled,onKeyDown:e=>{keyboardKeys.ArrowDown.validate(e.key)&&fe.current&&(e.preventDefault(),focusFirstFocusable(fe.current))},onClick:e=>{e.stopPropagation(),z||(v===void 0&&W([]),E&&E([]),ge.current?.focus(),se(!0))}}}):void 0,dropdown:ce?jsx(DropdownMenu,{...u,ref:be,tabIndex:ie?void 0:0,secondary:!f,elevated:f,disableAutoFocus:!0,palette:{backgroundColor:L.menuBackgroundColor,borderColor:L.menuBorderColor},onFocus:e=>{fe.current&&e.target===e.currentTarget&&(fe.current.contains(e.relatedTarget)?ge.current?.focus():focusFirstFocusable(fe.current))},onKeyDown:e=>{keyboardKeys.Enter.validate(e.key)&&(ge.current?.focus(),$(getDropdownInputText(V,w)),se(!1))},children:ie?jsx(DropdownMenuNoOptions,{loading:i,loadingMessage:k,loadingIcon:I,loadingIconProps:{...U,...G,...d},emptyMessage:P,emptyIcon:T,emptyIconProps:{...U,...G,...p}}):jsx(MenuList,w?{ref:fe,children:Y.length===0?jsxs(Fragment,{children:[c&&jsx(ListItem,{...U,text:F,disabled:q.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:jsx(InputCheckbox,{sizes:SIZES_CHECKBOX,form:"none",name:r,checked:pe,indeterminate:me,error:(pe||me)&&B==='error',success:(pe||me)&&B==='success',onChange:()=>{if(!z){const e=pe||me?[]:[...j];v===void 0&&W(e),E&&E(e)}}})}),c&&jsx(MenuDivider,{}),M&&ae[0].map((e=>{const o=e.status??B;const t=o==='error';const n=o==='success';return createElement(ListItem,{...U,key:e.value,active:!0,text:e.text,danger:t,success:n,disabled:q.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation(),ge.current?.focus()},control:jsx(InputCheckbox,{sizes:SIZES_CHECKBOX,form:"none",name:r,value:e.value,checked:!0,error:t,success:n,onChange:e=>{if(!z){const o=V.filter((o=>o.value!==e.currentTarget.value));v===void 0&&W(o),E&&E(o)}}})})})),M&&ae[0].length>0&&ae[1].length>0&&jsx(MenuDivider,{}),M&&ae[1].map((e=>createElement(ListItem,{...U,key:e.value,text:e.text,disabled:q.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation(),ge.current?.focus()},control:jsx(InputCheckbox,{sizes:SIZES_CHECKBOX,form:"none",name:r,value:e.value,checked:!1,onChange:()=>{if(!z){const o=[...V,e];v===void 0&&W(o),E&&E(o)}}})}))),!M&&j.map((e=>{const o=V.findIndex((o=>o.value===e.value))!==-1;const t=e.status??B;const n=o&&t==='error';const s=o&&t==='success';return createElement(ListItem,{...U,key:e.value,text:e.text,danger:n,success:s,disabled:q.disabled,active:o,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:jsx(InputCheckbox,{sizes:SIZES_CHECKBOX,form:"none",name:r,value:e.value,checked:o,error:n,success:s,onChange:t=>{if(!z){const r=o?V.filter((e=>e.value!==t.currentTarget.value)):[...V,e];v===void 0&&W(r),E&&E(r)}}})})}))]}):jsx(Fragment,{children:te.map((e=>{const o=V.findIndex((o=>o.value===e.value))!==-1;const t=e.status??B;const n=o&&t==='error';const s=o&&t==='success';return createElement(ListItem,{...U,key:e.value,text:e.text,danger:n,success:s,disabled:q.disabled,active:o,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:jsx(InputCheckbox,{sizes:SIZES_CHECKBOX,form:"none",name:r,value:e.value,checked:o,error:n,success:s,onChange:t=>{if(!z){const r=o?V.filter((e=>e.value!==t.currentTarget.value)):[...V,e];v===void 0&&W(r),E&&E(r)}}})})}))})}:{ref:fe,children:(s?te:j).map(((e,o,t)=>{const r=V.findIndex((o=>o.value===e.value))!==-1;return createElement(ListItem,{...U,ref:r?ve:void 0,key:e.value,text:e.text,active:r,danger:r&&B==='error',success:r&&B==='success',disabled:q.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:o=>{if(o.stopPropagation(),!z){const o=r?null:e;v===void 0&&($(getDropdownInputText(o)),W(getDropdownSelectedOption(o))),E&&E(o),(o||t===te)&&ge.current?.focus(),se(!o)}}})}))})}):void 0})})),{sizes:SIZES,displayName:"Dropdown"});export{COMPONENT_NAME,Dropdown};
1
+ import{forwardRef,useMemo,useState,useRef,useEffect,useLayoutEffect,createElement}from'react';import Fuse from'../../external/.pnpm/fuse.js@7.0.0/node_modules/fuse.js/dist/fuse.mjs';import{nanoid}from'../../external/.pnpm/nanoid@5.0.7/node_modules/nanoid/index.browser.mjs';import{withMergedProps}from'../../hocs/withMergedProps.mjs';import{useScrollMonitor}from'../../hooks/useScrollMonitor.mjs';import{focusFirstFocusable,focusLastFocusable}from'../../shared/utils/dom.mjs';import{keyboardKeys}from'../../shared/constants.mjs';import{DropdownMenu}from'./DropdownMenu.mjs';import{SIZES,SIZES_ICON,FuseSearchKeys,SIZES_CHECKBOX}from'./constants.mjs';import{getDropdownSelectedOption,getDropdownInputText,groupDropdownOptions}from'./utils.mjs';import{ChevronIcon,InputMimic}from'./style.mjs';import{jsx,jsxs,Fragment}from'react/jsx-runtime';import{FormInputLabel}from'../FormInputLabel/FormInputLabel.mjs';import{FormInput}from'../FormInput/FormInput.mjs';import{Chip}from'../Chip/Chip.mjs';import{IconButton}from'../IconButton/IconButton.mjs';import{MenuList}from'../MenuList/MenuList.mjs';import{ListItem}from'../ListItem/ListItem.mjs';import{InputCheckbox}from'../InputCheckbox/InputCheckbox.mjs';import{MenuDivider}from'../MenuDivider/MenuDivider.mjs';const COMPONENT_NAME='Dropdown';const Dropdown=withMergedProps(forwardRef(((e,o)=>{const{size:t="m",name:r="fox-dropdown",labelPosition:n="dynamic",searchable:s=!0,primary:a=!0,optionsMultiToggle:l=!0,loading:i=!1,iconProps:c={},menuProps:d={},loadingIconProps:u={},optionsEmptyIconProps:p={},autoFocus:m,disableAutoScrollToSelectedOption:b,closeMenuOnScroll:f,scrollMonitorTarget:g,contrast:v,selectedOption:x,defaultSelectedOption:k,icon:C,inputMode:h,loadingMessage:I,loadingIcon:y,maxLength:S,multiple:w,clearable:D,onCloseMenu:M,onOpenMenu:j,onSelectOption:E,options:P,groupSelectedOptions:F,optionsMultiToggleCaption:T,optionsEmptyMessage:L,optionsEmptyIcon:O,palette:B,placeholder:z,readOnly:K,required:R,status:X,sizeXXS:H,sizeXS:_,sizeS:N,sizeM:Z,sizeL:A,sizeXL:q,form:$,...U}=e;const G={size:t,sizeXXS:H,sizeXS:_,sizeS:N,sizeM:Z,sizeL:A,sizeXL:q};const J={sizes:SIZES_ICON,color:U.disabled?'content-disabled':'content-onmain-tertiary'};const Q=useMemo((()=>U.id??`${r}-${nanoid()}`),[r,U.id]);const V=useMemo((()=>nanoid()),[]);const W=useMemo((()=>nanoid()),[]);const Y=useMemo((()=>{const e=new Fuse(P,{threshold:.4,ignoreLocation:!0,keys:[FuseSearchKeys.text,FuseSearchKeys.label,FuseSearchKeys.tags]});return o=>o.length===0?P:e.search(o).map((e=>e.item))}),[P]);const[ee,oe]=useState((()=>getDropdownSelectedOption(x!==void 0?x:k,w)));const[te,re]=useState((()=>getDropdownInputText(ee,w)));const[ne,se]=useState(!1);const[ae,le]=useState((()=>Y(te)));const[ie,ce]=useState(!1);const de=w?groupDropdownOptions(P,ee):[[],[]];const ue=ie&&!U.disabled;const pe=te===getDropdownInputText(ee);const me=R&&ee.length===0;const be=Boolean(ue||te||ne);const fe=de[0].length>0&&de[1].length===0;const ge=de[0].length>0&&de[1].length>0;const ve=useRef(null);const[xe,ke]=useState(null);const Ce=useRef(null);const he=useRef(null);const Ie=useRef(null);const ye=useRef(te);const Se=useRef(ue);return useScrollMonitor({target:g,onScrollStart:()=>{f&&ue&&(ve.current?.focus(),ce(!1))}}),useEffect((()=>(te===ye.current?le(Y(te)):(ye.current=te,Ie.current=setTimeout((()=>{le(Y(te))}),150)),()=>{Ie.current&&clearTimeout(Ie.current)})),[Y,te]),useLayoutEffect((()=>{x!==void 0&&(w||re(getDropdownInputText(x)),oe(getDropdownSelectedOption(x,w)))}),[w,x]),useEffect((()=>{ue!==Se.current&&(ue&&j&&j(),!ue&&M&&M(),Se.current=ue)}),[ue,M,j]),useEffect((()=>{if(!w&&!b&&ue&&xe&&he.current){const e=xe.getBoundingClientRect();const o=he.current.getBoundingClientRect();(o.top<e.top||o.bottom>e.bottom)&&xe.scrollTo(0,he.current.offsetTop)}}),[w,b,ue,xe]),jsx(FormInputLabel,{...U,...G,ref:o,id:Q,labelId:V,labelPosition:n,active:be,onColored:v,primary:a,error:X==='error',success:X==='success',focus:ne,icon:[C,jsx(ChevronIcon,{up:ue},'chevron')],iconProps:{...G,...J,...c},palette:{color:U.disabled?B.labelColorDisabled:B.labelColor,backgroundColor:U.disabled?B.backgroundColorDisabled:B.backgroundColor,backgroundColorHover:U.disabled?B.backgroundColorDisabled:B.backgroundColorHover,borderColor:U.disabled?B.borderColorDisabled:B.borderColor},onClick:e=>{U.onClick&&U.onClick(e),U.disabled||(ve.current?.focus(),ue?xe&&e.target instanceof Node&&!xe.contains(e.target)&&ce(!1):(ce(!0),s&&!w&&pe&&(re(''),le(Y('')))))},onPointerDown:e=>{U.onPointerDown&&U.onPointerDown(e),e.target!==ve.current&&e.target instanceof Node&&(e.currentTarget.contains(e.target)||d.renderInPortal&&ue&&xe&&xe.contains(e.target))&&e.preventDefault()},onFocus:e=>{U.onFocus&&U.onFocus(e),se(!0),ve.current&&e.target===ve.current&&s&&!w&&pe&&!ue&&(re(''),le(Y('')))},onBlur:e=>{U.onBlur&&U.onBlur(e),e.currentTarget.contains(e.relatedTarget)||d.renderInPortal&&ue&&xe&&xe.contains(e.relatedTarget)||(se(!1),re(getDropdownInputText(ee,w)),ce(!1))},input:jsxs(Fragment,{children:[me&&!s&&!K&&jsx(InputMimic,{required:!0,type:"text",inputMode:"none",form:$,tabIndex:-1,onFocus:()=>{ve.current?.focus()}}),jsx(FormInput,{ref:ve,role:"combobox","aria-controls":W,"aria-expanded":ue,"aria-labelledby":U.label?V:void 0,type:"text",autoComplete:"off",autoCapitalize:"off",autoCorrect:"off",spellCheck:"false",form:$,autoFocus:m,inputMode:s?h:'none',maxLength:S,placeholder:z,readOnly:K||!s,required:me,disabled:U.disabled,value:te,palette:{color:B.color,colorDisabled:B.colorDisabled,placeholderColor:B.placeholderColor,placeholderColorDisabled:B.placeholderColorDisabled},onClick:e=>{ue&&e.currentTarget.selectionStart!==e.currentTarget.selectionEnd&&e.stopPropagation()},onChange:e=>{re(e.currentTarget.value),ce(!0)},onKeyDown:e=>{if(keyboardKeys.Enter.validate(e.key)&&(re(getDropdownInputText(ee,w)),ce(!1)),!keyboardKeys.Space.validate(e.key)||ue&&e.currentTarget.selectionStart!==0||(e.preventDefault(),s&&!w&&pe&&!ue&&(re(''),le(Y(''))),ce((e=>!e))),keyboardKeys.Esc.validate(e.key)&&ce(!1),keyboardKeys.Tab.validate(e.key)&&ue&&(e.preventDefault(),ce(!1)),keyboardKeys.ArrowDown.validate(e.key)&&ue&&Ce.current)if(e.preventDefault(),!w&&he.current){const e=[...Ce.current.children];const o=e.findIndex((e=>e.contains(he.current)));const t=e[o+1]??e[0];t instanceof HTMLElement&&focusFirstFocusable(t)}else focusFirstFocusable(Ce.current);if(keyboardKeys.ArrowUp.validate(e.key)&&ue&&Ce.current)if(e.preventDefault(),!w&&he.current){const e=[...Ce.current.children];const o=e.findIndex((e=>e.contains(he.current)));const t=e[o-1]??e[e.length-1];t instanceof HTMLElement&&focusFirstFocusable(t)}else focusLastFocusable(Ce.current)}}),ee.map((e=>jsx("input",{type:"hidden",name:r,value:e.value,form:$,disabled:U.disabled},e.value)))]}),addon:jsxs(Fragment,{children:[w&&ee.length>0&&jsx(Chip,{size:"xs",active:!0,black:!0,marginLeft:12,disabled:U.disabled,cursor:U.disabled?'not-allowed':void 0,text:ee.length,textProps:{appearance:'caption',size:'xs'},palette:U.disabled?{color:'content-disabled',colorHover:'content-disabled',backgroundColor:'bg-disabled-small',backgroundColorHover:'bg-disabled-small'}:void 0,onPointerDown:e=>{e.preventDefault()},discardButtonProps:{contrast:!U.disabled,onClick:e=>{e.stopPropagation(),K||(x===void 0&&oe([]),E&&E(w?[]:null),ve.current?.focus(),ce(!0))}}}),!w&&D&&ee.length>0&&jsx(IconButton,{icon:"close",size:"l",square:!0,marginLeft:12,disabled:U.disabled,onClick:e=>{e.stopPropagation(),K||(pe&&(re(''),le(Y(''))),x===void 0&&oe([]),E&&E(w?[]:null),ve.current?.focus(),ce(!0))}})]}),dropdown:jsx(DropdownMenu,{...d,setRef:ke,open:ue,popperReferenceId:Q,secondary:!v,elevated:v,disableAutoFocus:!0,palette:{backgroundColor:B.menuBackgroundColor,borderColor:B.menuBorderColor},empty:ae.length===0,loading:i,loadingMessage:I,loadingIcon:y,loadingIconProps:{...G,...J,...u},emptyMessage:L,emptyIcon:O,emptyIconProps:{...G,...J,...p},onKeyDown:e=>{keyboardKeys.Tab.validate(e.key)&&(e.preventDefault(),ve.current?.focus(),ce(!1)),keyboardKeys.Enter.validate(e.key)&&(ve.current?.focus(),re(getDropdownInputText(ee,w)),ce(!1)),keyboardKeys.Esc.validate(e.key)&&(ve.current?.focus(),ce(!1)),keyboardKeys.Backspace.validate(e.key)&&!K&&(w||!w&&D)&&(x===void 0&&oe([]),E&&E(w?[]:null))},children:jsx(MenuList,w?{ref:Ce,id:W,role:"listbox","aria-labelledby":U.label?V:void 0,"aria-multiselectable":!0,children:te.length===0?jsxs(Fragment,{children:[l&&jsx(ListItem,{...G,text:T,disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:jsx(InputCheckbox,{sizes:SIZES_CHECKBOX,form:"none",name:r,checked:fe,indeterminate:ge,error:(fe||ge)&&X==='error',success:(fe||ge)&&X==='success',onChange:()=>{if(!K){const e=fe||ge?[]:[...P];x===void 0&&oe(e),E&&E(e)}}})}),l&&jsx(MenuDivider,{}),F&&de[0].map((e=>{const o=e.status??X;const t=o==='error';const n=o==='success';return createElement(ListItem,{...G,key:e.value,active:!0,text:e.text,danger:t,success:n,disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation(),ve.current?.focus()},control:jsx(InputCheckbox,{sizes:SIZES_CHECKBOX,form:"none",role:"option","aria-selected":!0,name:r,value:e.value,checked:!0,error:t,success:n,onChange:e=>{if(!K){const o=ee.filter((o=>o.value!==e.currentTarget.value));x===void 0&&oe(o),E&&E(o)}}})})})),F&&de[0].length>0&&de[1].length>0&&jsx(MenuDivider,{}),F&&de[1].map((e=>createElement(ListItem,{...G,key:e.value,text:e.text,disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation(),ve.current?.focus()},control:jsx(InputCheckbox,{sizes:SIZES_CHECKBOX,form:"none",role:"option","aria-selected":!1,name:r,value:e.value,checked:!1,onChange:()=>{if(!K){const o=[...ee,e];x===void 0&&oe(o),E&&E(o)}}})}))),!F&&P.map((e=>{const o=ee.findIndex((o=>o.value===e.value))!==-1;const t=e.status??X;const n=o&&t==='error';const s=o&&t==='success';return createElement(ListItem,{...G,key:e.value,text:e.text,danger:n,success:s,disabled:U.disabled,active:o,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:jsx(InputCheckbox,{sizes:SIZES_CHECKBOX,form:"none",role:"option","aria-selected":o,name:r,value:e.value,checked:o,error:n,success:s,onChange:t=>{if(!K){const r=o?ee.filter((e=>e.value!==t.currentTarget.value)):[...ee,e];x===void 0&&oe(r),E&&E(r)}}})})}))]}):jsx(Fragment,{children:ae.map((e=>{const o=ee.findIndex((o=>o.value===e.value))!==-1;const t=e.status??X;const n=o&&t==='error';const s=o&&t==='success';return createElement(ListItem,{...G,key:e.value,text:e.text,danger:n,success:s,disabled:U.disabled,active:o,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:e=>{e.stopPropagation()},control:jsx(InputCheckbox,{sizes:SIZES_CHECKBOX,form:"none",role:"option","aria-selected":o,name:r,value:e.value,checked:o,error:n,success:s,onChange:t=>{if(!K){const r=o?ee.filter((e=>e.value!==t.currentTarget.value)):[...ee,e];x===void 0&&oe(r),E&&E(r)}}})})}))})}:{ref:Ce,id:W,role:"listbox","aria-labelledby":U.label?V:void 0,children:(s?ae:P).map((e=>{const o=ee.findIndex((o=>o.value===e.value))!==-1;return createElement(ListItem,{...G,role:"option","aria-selected":o,ref:o?he:void 0,key:e.value,text:e.text,active:o,danger:o&&X==='error',success:o&&X==='success',disabled:U.disabled,borderRadius:8,ellipsis:!1,textProps:{wordBreak:'break-word'},onClick:o=>{if(o.stopPropagation(),!K){const o={...e};x===void 0&&(re(getDropdownInputText(o)),oe(getDropdownSelectedOption(o))),E&&E(o),ve.current?.focus(),ce(!1)}}})}))})})})})),{sizes:SIZES,displayName:"Dropdown"});export{COMPONENT_NAME,Dropdown};
2
2
  //# sourceMappingURL=Dropdown.mjs.map