UNPKG

maz-ui

Version:

A standalone components library for Vue.Js 3 & Nuxt.Js 3

1 lines 5.9 kB
import{t as _plugin_vue_export_helper_default}from"./_plugin-vue_export-helper.ChmETRGw.js";import{t as hasSlotContent}from"./hasSlotContent.akaXJLAp.js";import{useInstanceUniqId}from"../composables/useInstanceUniqId.js";import{useStringMatching}from"../composables/useStringMatching.js";import{t as MazCardSpotlight_default}from"./MazCardSpotlight.D-Rfazpm.js";import{t as MazCheckbox_default}from"./MazCheckbox.Cx1KhB1Q.js";import{Fragment,computed,createBlock,createCommentVNode,createElementBlock,createElementVNode,createTextVNode,createVNode,defineAsyncComponent,defineComponent,mergeProps,openBlock,ref,renderList,renderSlot,toDisplayString,unref,watch,withCtx}from"vue";import{MazMagnifyingGlass}from"@maz-ui/icons/lazy/MazMagnifyingGlass";import{useTranslations}from"@maz-ui/translations/composables/useTranslations";import{MazNoSymbol}from"@maz-ui/icons/lazy/MazNoSymbol";import{normalizeString}from"@maz-ui/utils/helpers/normalizeString";import '../assets/MazChecklist.9Njv_TGP.css';var _hoisted_1={class:`m-checklist m-reset-css`};var _hoisted_2=[`for`];var _hoisted_3={key:0,class:`title`};var _hoisted_4={key:0,class:`no-results`};var _hoisted_5={class:`no-results-content`};var _hoisted_6={class:`no-results-text`};var _hoisted_7=[`for`];var _hoisted_8={class:`item-label`};var MazChecklist_default=_plugin_vue_export_helper_default(defineComponent({__name:`MazChecklist`,props:{modelValue:{},query:{},items:{},title:{},elevation:{type:Boolean,default:!1},search:{type:[Boolean,Object]},searchOptions:{},searchFunction:{type:Function},color:{default:`primary`},translations:{}},emits:[`update:query`,`update:model-value`],setup(__props,{emit:__emit}){let emits=__emit;let id=useInstanceUniqId({componentName:`MazChecklist`});let MazInput=defineAsyncComponent(()=>import(`../components/MazInput.js`));let internalQuery=ref(__props.query);watch(()=>__props.query,value=>{internalQuery.value=value});let{t}=useTranslations();let messages=computed(()=>({noResultsFound:__props.translations?.noResultsFound??t(`checklist.noResultsFound`),searchInput:{placeholder:__props.translations?.searchInput?.placeholder??t(`checklist.searchInput.placeholder`)}}));let filteredItems=computed(()=>{if(!internalQuery.value||!__props.search)return __props.items;let normalizedQuery=normalizeString(internalQuery.value,__props.searchOptions);return __props.searchFunction?__props.searchFunction(normalizedQuery,__props.items??[]):getFilteredOptionWithQuery(normalizedQuery)});function searchInValue(value,query){return query&&value&&normalizeString(value).includes(normalizeString(query))}function getFilteredOptionWithQuery(query){return __props.items?.filter(({label,value})=>{let threshold=__props.searchOptions?.threshold;let normalizedQuery=normalizeString(query,__props.searchOptions);let searchLabel=normalizeString(label,__props.searchOptions);let searchValue=normalizeString(value,__props.searchOptions);return searchInValue(searchLabel,normalizedQuery)||searchInValue(searchValue,normalizedQuery)||typeof searchLabel==`string`&&useStringMatching(searchLabel,normalizedQuery,threshold).isMatching.value||typeof searchValue==`string`&&useStringMatching(searchValue,normalizedQuery,threshold).isMatching.value})}function updateQuery(value){internalQuery.value=value,emits(`update:query`,value)}return(_ctx,_cache)=>(openBlock(),createElementBlock(`div`,_hoisted_1,[createElementVNode(`label`,{for:__props.search?`${unref(id)}-query`:void 0,class:`search-label`},[unref(hasSlotContent)(_ctx.$slots.title)||__props.title?(openBlock(),createElementBlock(`span`,_hoisted_3,[renderSlot(_ctx.$slots,`title`,{},()=>[createTextVNode(toDisplayString(__props.title),1)],!0)])):createCommentVNode(``,!0),__props.search?(openBlock(),createBlock(unref(MazInput),mergeProps({key:1,id:`${unref(id)}-query`,"model-value":internalQuery.value},typeof __props.search==`object`?__props.search:{},{color:typeof __props.search==`object`&&__props.search.color?__props.search.color:__props.color,"left-icon":typeof __props.search==`object`?__props.search.leftIcon??unref(MazMagnifyingGlass):void 0,debounce:typeof __props.search==`object`?__props.search.debounce??300:void 0,name:typeof __props.search==`object`?__props.search.name??`search`:void 0,placeholder:typeof __props.search==`object`&&__props.search.placeholder?__props.search.placeholder:messages.value.searchInput.placeholder,"onUpdate:modelValue":_cache[0]||=event=>updateQuery(event)}),null,16,[`id`,`model-value`,`color`,`left-icon`,`debounce`,`name`,`placeholder`])):createCommentVNode(``,!0)],8,_hoisted_2),createVNode(MazCardSpotlight_default,{color:__props.color,elevation:__props.elevation,padding:!1,"content-class":`card-content`},{default:withCtx(()=>[filteredItems.value?.length===0?(openBlock(),createElementBlock(`div`,_hoisted_4,[renderSlot(_ctx.$slots,`no-results`,{},()=>[createElementVNode(`div`,_hoisted_5,[createVNode(unref(MazNoSymbol),{class:`no-results-icon`}),createElementVNode(`span`,_hoisted_6,[renderSlot(_ctx.$slots,`no-results-text`,{},()=>[createTextVNode(toDisplayString(messages.value.noResultsFound),1)],!0)])])],!0)])):createCommentVNode(``,!0),(openBlock(!0),createElementBlock(Fragment,null,renderList(filteredItems.value,item=>(openBlock(),createElementBlock(`label`,{key:item.value,for:`${unref(id)}-checklist-item-${item.value}`,class:`m-checklist-item m-reset-css`},[createVNode(MazCheckbox_default,{id:`${unref(id)}-checklist-item-${item.value}`,"model-value":__props.modelValue,value:item.value,color:__props.color,"onUpdate:modelValue":_cache[1]||=event=>emits(`update:model-value`,event)},null,8,[`id`,`model-value`,`value`,`color`]),renderSlot(_ctx.$slots,`item`,{selectedValues:__props.modelValue,item},()=>[createElementVNode(`span`,_hoisted_8,toDisplayString(item.label),1)],!0)],8,_hoisted_7))),128))]),_:3},8,[`color`,`elevation`])]))}}),[[`__scopeId`,`data-v-51fc8f50`]]);export{MazChecklist_default as t};