UNPKG

vuetify-swatches

Version:
13 lines (11 loc) 5.25 kB
/** * vuetify-swatches * * @description Color Swatch component for Vuetify3. * @author Logue <logue@hotmail.co.jp> * @copyright 2022-2026 By Masashi Yoshikawa All rights reserved. * @license MIT * @version 2.0.1 * @see {@link https://github.com/logue/vuetify-swatches} */ (function(a,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("vuetify/components"),require("vuetify/util/colors")):typeof define=="function"&&define.amd?define(["exports","vue","vuetify/components","vuetify/util/colors"],e):(a=typeof globalThis<"u"?globalThis:a||self,e(a.VSwatches={},a.Vue,a["Vuetify/components"],a.colors))})(this,(function(a,e,c,k){"use strict";function b(i){return i&&typeof i=="object"&&"default"in i?i:{default:i}}var u=b(k);function B(...i){let d=0;for(let n=0;n<i.length;n++)i[n].length>d&&(d=i[n].length);const o=i.length,t=Array(d);for(let n=0;n<d;++n){const r=Array(o);for(let l=0;l<o;++l)r[l]=i[l][n];t[n]=r}return t}var h=e.defineComponent({__name:"SwatchButton",props:{color:{default:void 0},isSelected:{type:Boolean,default:!1},size:{default:"2rem"},icon:{default:"mdi-checkbox-marked-circle"},iconSize:{default:"1rem"},variant:{default:void 0},disabled:{type:Boolean,default:!1},rounded:{type:[String,Number,Boolean],default:void 0},border:{type:[String,Number,Boolean],default:!1},elevation:{default:void 0},tooltip:{type:Boolean,default:!1},tooltipLocation:{default:void 0}},emits:["click"],setup(i,{emit:d}){const o=i,t=d;return(n,r)=>o.color?(e.openBlock(),e.createBlock(e.unref(c.VTooltip),{key:0,disabled:!o.tooltip,location:o.tooltipLocation,text:o.color},{activator:e.withCtx(({props:l})=>[e.createVNode(e.unref(c.VBtn),e.mergeProps(l,{border:o.border,class:[o.color===e.unref(u.default).shades.transparent?"bg-transparent":"","p-0"],color:o.color,disabled:o.disabled,elevation:o.elevation,height:o.size,variant:o.variant,width:o.size,"min-width":"auto",onClick:r[0]||(r[0]=p=>t("click"))}),{default:e.withCtx(()=>[o.isSelected?(e.openBlock(),e.createBlock(e.unref(c.VIcon),{key:0,size:o.iconSize,color:o.color!==e.unref(u.default).shades.transparent?o.color:void 0,icon:o.icon},null,8,["size","color","icon"])):e.createCommentVNode("",!0)]),_:1},16,["border","class","color","disabled","elevation","height","variant","width"])]),_:1},8,["disabled","location","text"])):(e.openBlock(),e.createBlock(e.unref(c.VBtn),{key:1,height:o.size,width:o.size,class:"p-0",disabled:"","min-width":"auto",variant:"text"},null,8,["height","width"]))}}),y=e.defineComponent({__name:"VSwatches",props:{modelValue:{type:String,default:u.default.shades.white},swatches:{type:Array,default:()=>[]},size:{type:String,default:"2rem"},icon:{type:String,default:"mdi-checkbox-marked-circle"},iconSize:{type:String,default:"1rem"},inline:{type:Boolean,default:!1},variant:{type:String,default:void 0},disabled:{type:Boolean,default:!1},rounded:{type:[String,Number,Boolean],default:void 0},border:{type:[String,Number,Boolean],default:!1},elevation:{type:[String,Number],default:void 0},transpose:{type:Boolean,default:!1},tooltip:{type:Boolean,default:!1},tooltipLocation:{type:String,default:void 0}},emits:{"update:modelValue":i=>!0},setup(i,{emit:d}){const o=d,t=i,n=e.computed(()=>{const l=Array.isArray(t.swatches)?t.swatches:Object.values(t.swatches);return t.inline?[l.flat(1/0)]:t.transpose?B(...l):l}),r=e.ref(u.default.shades.white);return e.watch(()=>r.value,l=>o("update:modelValue",l)),e.watch(()=>t.modelValue,l=>{l&&(r.value=l)},{immediate:!0}),(l,p)=>(e.openBlock(),e.createBlock(e.unref(c.VItemGroup),{modelValue:r.value,"onUpdate:modelValue":p[0]||(p[0]=s=>r.value=s),class:e.normalizeClass([{"d-inline":t.inline},"v-swatches"]),mandatory:""},{default:e.withCtx(()=>[t.inline?(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:0},e.renderList(n.value[0],s=>(e.openBlock(),e.createBlock(e.unref(c.VItem),{key:s,value:s},{default:e.withCtx(({isSelected:m,toggle:f})=>[e.createVNode(h,{border:t.border,color:s,disabled:t.disabled,elevation:t.elevation,"icon-size":t.iconSize,icon:t.icon,"is-selected":m,rounded:t.rounded,size:t.size,"tooltip-location":t.tooltipLocation,tooltip:t.tooltip,variant:t.variant,onClick:f},null,8,["border","color","disabled","elevation","icon-size","icon","is-selected","rounded","size","tooltip-location","tooltip","variant","onClick"])]),_:2},1032,["value"]))),128)):(e.openBlock(!0),e.createElementBlock(e.Fragment,{key:1},e.renderList(n.value,(s,m)=>(e.openBlock(),e.createElementBlock("div",{key:m},[(e.openBlock(!0),e.createElementBlock(e.Fragment,null,e.renderList(s,f=>(e.openBlock(),e.createBlock(e.unref(c.VItem),{key:f,value:f},{default:e.withCtx(({isSelected:z,toggle:S})=>[e.createVNode(h,{border:t.border,color:f,disabled:t.disabled,elevation:t.elevation,"icon-size":t.iconSize,icon:t.icon,"is-selected":z,rounded:t.rounded,size:t.size,"tooltip-location":t.tooltipLocation,tooltip:t.tooltip,variant:t.variant,onClick:S},null,8,["border","color","disabled","elevation","icon-size","icon","is-selected","rounded","size","tooltip-location","tooltip","variant","onClick"])]),_:2},1032,["value"]))),128))]))),128))]),_:1},8,["modelValue","class"]))}});const w=i=>i.component("VSwatches",y);a.default=y,a.install=w,Object.defineProperty(a,"__esModule",{value:!0})}));