UNPKG

@dialpad/dialtone-vue

Version:

Vue component library for Dialpad's design system Dialtone

2 lines • 6.47 kB
Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}}),require(`../../chunk-Bmb41Sf3.cjs`);const e=require(`../../common/utils/index.cjs`),t=require(`../../_plugin-vue_export-helper-D8jCH6HB.cjs`),n=require(`../combobox/combobox-loading-list.cjs`),r=require(`../combobox/combobox-empty-list.cjs`),i=require(`../../combobox-DhjZxfUw.cjs`),a=require(`../combobox/combobox-constants.cjs`),o=require(`../popover/popover-constants.cjs`),s=require(`../popover/popover.cjs`),c=require(`../dropdown/dropdown-constants.cjs`);let l=require(`vue`);var u={compatConfig:{MODE:3},name:`DtComboboxWithPopover`,components:{DtCombobox:i.t,DtPopover:s.default,ComboboxLoadingList:n.default,ComboboxEmptyList:r.default},props:{label:{type:String,required:!0},labelVisible:{type:Boolean,default:!0},size:{type:String,default:null,validator:e=>Object.values(a.COMBOBOX_LABEL_SIZES).includes(e)},description:{type:String,default:``},showList:{type:Boolean,default:null},listId:{type:String,default(){return e.getUniqueString()}},listClass:{type:[String,Array,Object],default:``},dialogClass:{type:[String,Array,Object],default:``},onBeginningOfList:{type:Function,default:null},onEndOfList:{type:Function,default:null},maxHeight:{type:String,default:``},maxWidth:{type:String,default:``},padding:{type:String,default:`small`,validator:e=>Object.keys(c.DROPDOWN_PADDING_CLASSES).some(t=>t===e)},contentWidth:{type:String,default:null,validator:e=>o.POPOVER_CONTENT_WIDTHS.includes(e)},openWithArrowKeys:{type:Boolean,default:!1},popoverOffset:{type:Array,default:()=>[0,4]},popoverSticky:{type:[Boolean,String],default:!1},hasSuggestionList:{type:Boolean,default:!0},loading:{type:Boolean,default:!1},emptyList:{type:Boolean,default:!1},emptyStateMessage:{type:String,default:``},appendTo:{type:[HTMLElement,String],default:`body`,validator:e=>o.POPOVER_APPEND_TO_VALUES.includes(e)||e instanceof HTMLElement},transition:{type:String,default:`fade`}},emits:[`select`,`escape`,`highlight`,`opened`],data(){return{DROPDOWN_PADDING_CLASSES:c.DROPDOWN_PADDING_CLASSES,isListShown:!1,isInputFocused:!1,isListFocused:!1,externalAnchor:e.getUniqueString(),hasSlotContent:e.hasSlotContent}},computed:{comboboxListeners(){return{...this.$attrs,onSelect:this.onSelect,onEscape:this.onEscape,onHighlight:this.onHighlight}}},watch:{showList:{handler:function(e){e!==null&&(this.isListShown=e)},immediate:!0},isListShown(e){e?window.addEventListener(`mousedown`,this.onFocusOut):window.removeEventListener(`mousedown`,this.onFocusOut),this.onOpened(e)}},methods:{handleDisplayList(e){!this.hasSuggestionList&&e&&this.showComboboxList(),!this.hasSuggestionList&&!e&&this.closeComboboxList()},showComboboxList(){this.showList??(this.isListShown=!0)},closeComboboxList(){this.showList??(this.isListShown=!1)},onSelect(e){this.loading||(this.$emit(`select`,e),this.hasSuggestionList||this.closeComboboxList())},onEscape(){this.$emit(`escape`),this.closeComboboxList()},onHighlight(e){this.loading||this.$emit(`highlight`,e)},onOpened(e){this.$emit(`opened`,e)},onFocusIn(e){this.hasSuggestionList&&e&&this.$refs.input?.querySelector(`input`)===e.target&&this.showComboboxList()},onFocusOut(e){let t=this.$refs.popover?.tip?.popper,n=this.$refs.input;e.composedPath()?.some(e=>[t,n].includes(e))||this.closeComboboxList()},openOnArrowKeyPress(){this.showList!==null||this.isListShown||!this.openWithArrowKeys||this.showComboboxList()}}},d=[`id`],f={ref:`header`},p=[`onMouseleave`,`onFocusout`],m={ref:`footer`};function h(e,t,n,r,i,a){let o=(0,l.resolveComponent)(`combobox-loading-list`),s=(0,l.resolveComponent)(`combobox-empty-list`),c=(0,l.resolveComponent)(`dt-popover`),u=(0,l.resolveComponent)(`dt-combobox`);return(0,l.openBlock)(),(0,l.createBlock)(u,(0,l.mergeProps)({ref:`combobox`,loading:n.loading,label:n.label,"label-visible":n.labelVisible,size:n.size,description:n.description,"empty-list":n.emptyList,"empty-state-message":n.emptyStateMessage,"show-list":i.isListShown,"on-beginning-of-list":n.onBeginningOfList,"on-end-of-list":n.onEndOfList,"list-rendered-outside":!0,"list-id":n.listId,"data-qa":`dt-combobox`},a.comboboxListeners),{input:(0,l.withCtx)(({inputProps:n})=>[(0,l.createElementVNode)(`div`,{id:i.externalAnchor,ref:`input`,onFocusin:t[0]||(t[0]=(...e)=>a.onFocusIn&&a.onFocusIn(...e)),onKeydown:[t[1]||(t[1]=(0,l.withKeys)(e=>a.openOnArrowKeyPress(e),[`up`])),t[2]||(t[2]=(0,l.withKeys)(e=>a.openOnArrowKeyPress(e),[`down`]))]},[(0,l.renderSlot)(e.$slots,`input`,{inputProps:n,onInput:a.handleDisplayList})],40,d)]),list:(0,l.withCtx)(({opened:r,listProps:a,clearHighlightIndex:u})=>[(0,l.createVNode)(c,{ref:`popover`,open:i.isListShown,"onUpdate:open":t[3]||(t[3]=e=>i.isListShown=e),"hide-on-click":!1,"max-height":n.maxHeight,"max-width":n.maxWidth,offset:n.popoverOffset,sticky:n.popoverSticky,placement:`bottom-start`,"initial-focus-element":`none`,padding:`none`,role:`listbox`,"external-anchor":i.externalAnchor,"content-width":n.contentWidth,"content-appear":!0,"content-tabindex":null,modal:!1,"auto-focus":!1,"append-to":n.appendTo,"dialog-class":n.dialogClass,transition:n.transition,onOpened:r},(0,l.createSlots)({content:(0,l.withCtx)(()=>[(0,l.createElementVNode)(`div`,{ref:`listWrapper`,class:(0,l.normalizeClass)([`d-recipe-combobox-with-popover__list`,i.DROPDOWN_PADDING_CLASSES[n.padding],n.listClass]),onMouseleave:u,onFocusout:u},[n.loading?((0,l.openBlock)(),(0,l.createBlock)(o,(0,l.normalizeProps)((0,l.mergeProps)({key:0},a)),null,16)):n.emptyList&&n.emptyStateMessage?((0,l.openBlock)(),(0,l.createBlock)(s,(0,l.mergeProps)({key:1},a,{message:n.emptyStateMessage}),null,16,[`message`])):(0,l.renderSlot)(e.$slots,`list`,{key:2,listProps:a})],42,p)]),_:2},[i.hasSlotContent(e.$slots.header)?{name:`headerContent`,fn:(0,l.withCtx)(()=>[(0,l.createElementVNode)(`div`,f,[(0,l.renderSlot)(e.$slots,`header`)],512)]),key:`0`}:void 0,i.hasSlotContent(e.$slots.footer)?{name:`footerContent`,fn:(0,l.withCtx)(()=>[(0,l.createElementVNode)(`div`,m,[(0,l.renderSlot)(e.$slots,`footer`)],512)]),key:`1`}:void 0]),1032,[`open`,`max-height`,`max-width`,`offset`,`sticky`,`external-anchor`,`content-width`,`append-to`,`dialog-class`,`transition`,`onOpened`])]),_:3},16,[`loading`,`label`,`label-visible`,`size`,`description`,`empty-list`,`empty-state-message`,`show-list`,`on-beginning-of-list`,`on-end-of-list`,`list-id`])}var g=t.t(u,[[`render`,h]]);exports.default=g; //# sourceMappingURL=combobox-with-popover.cjs.map