@vue-interface/select-field 1.0.0-beta.13 → 1.0.0-beta.15
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.
package/dist/select-field.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { defineComponent as
|
|
2
|
-
import { useFormControl as
|
|
3
|
-
const
|
|
1
|
+
import { defineComponent as A, ref as N, onMounted as w, useSlots as b, resolveComponent as E, openBlock as s, createElementBlock as u, normalizeClass as $, unref as o, renderSlot as t, toDisplayString as f, createCommentVNode as a, createElementVNode as i, normalizeProps as p, guardReactiveProps as c, withDirectives as M, mergeProps as P, isRef as D, vModelSelect as I, createVNode as B, Transition as R, withCtx as k, createBlock as h, createTextVNode as G } from "vue";
|
|
2
|
+
import { useFormControl as U, FormControlErrors as j, FormControlFeedback as q } from "@vue-interface/form-control";
|
|
3
|
+
const H = ["for"], J = { class: "form-group-inner" }, K = {
|
|
4
4
|
invalid: "",
|
|
5
5
|
class: "invalid-feedback"
|
|
6
|
-
},
|
|
6
|
+
}, L = /* @__PURE__ */ i("br", null, null, -1), O = {
|
|
7
7
|
valid: "",
|
|
8
8
|
class: "valid-feedback"
|
|
9
|
-
},
|
|
9
|
+
}, X = /* @__PURE__ */ A({
|
|
10
10
|
__name: "SelectField",
|
|
11
11
|
props: {
|
|
12
12
|
activity: { type: Boolean },
|
|
@@ -32,47 +32,54 @@ const q = ["for"], H = { class: "form-group-inner" }, J = {
|
|
|
32
32
|
},
|
|
33
33
|
emits: ["update:modelValue"],
|
|
34
34
|
setup(S, { emit: F }) {
|
|
35
|
-
const
|
|
36
|
-
controlAttributes:
|
|
37
|
-
formGroupClasses:
|
|
38
|
-
model:
|
|
39
|
-
onClick:
|
|
35
|
+
const g = S, {
|
|
36
|
+
controlAttributes: m,
|
|
37
|
+
formGroupClasses: T,
|
|
38
|
+
model: n,
|
|
39
|
+
onClick: C,
|
|
40
40
|
onBlur: v,
|
|
41
41
|
onFocus: y
|
|
42
|
-
} =
|
|
43
|
-
function
|
|
44
|
-
|
|
42
|
+
} = U({ props: g, emit: F }), d = N();
|
|
43
|
+
function V(e) {
|
|
44
|
+
C(e), d.value.focus();
|
|
45
45
|
}
|
|
46
|
-
return (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
46
|
+
return w(() => {
|
|
47
|
+
if (b().default)
|
|
48
|
+
for (const e of b().default()) {
|
|
49
|
+
if (!e.props)
|
|
50
|
+
return;
|
|
51
|
+
"selected" in e.props && (e.props.value ?? e.children) && (n.value = e.props.value ?? e.children);
|
|
52
|
+
}
|
|
53
|
+
}), (e, l) => {
|
|
54
|
+
const z = E("ActivityIndicator");
|
|
55
|
+
return s(), u("div", {
|
|
56
|
+
class: $(["select-field", o(T)])
|
|
50
57
|
}, [
|
|
51
58
|
t(e.$slots, "label", {}, () => [
|
|
52
|
-
e.label ? (s(),
|
|
59
|
+
e.label ? (s(), u("label", {
|
|
53
60
|
key: 0,
|
|
54
61
|
ref: "label",
|
|
55
|
-
for: o(
|
|
56
|
-
class:
|
|
57
|
-
},
|
|
62
|
+
for: o(m).id,
|
|
63
|
+
class: $(e.labelClass)
|
|
64
|
+
}, f(e.label), 11, H)) : a("", !0)
|
|
58
65
|
]),
|
|
59
|
-
i("div",
|
|
60
|
-
t(e.$slots, "control",
|
|
61
|
-
|
|
66
|
+
i("div", J, [
|
|
67
|
+
t(e.$slots, "control", p(c({ onClick: o(C), onBlur: o(v), onFocus: o(y), controlAttributes: o(m) })), () => [
|
|
68
|
+
b().icon ? (s(), u("div", {
|
|
62
69
|
key: 0,
|
|
63
70
|
class: "form-group-inner-icon",
|
|
64
71
|
onClick: l[0] || (l[0] = //@ts-ignore
|
|
65
|
-
(...r) =>
|
|
72
|
+
(...r) => d.value.focus && d.value.focus(...r))
|
|
66
73
|
}, [
|
|
67
74
|
t(e.$slots, "icon")
|
|
68
75
|
])) : a("", !0),
|
|
69
|
-
|
|
76
|
+
M(i("select", P({
|
|
70
77
|
ref_key: "field",
|
|
71
|
-
ref:
|
|
72
|
-
"onUpdate:modelValue": l[1] || (l[1] = (r) => D(
|
|
78
|
+
ref: d,
|
|
79
|
+
"onUpdate:modelValue": l[1] || (l[1] = (r) => D(n) ? n.value = r : null),
|
|
73
80
|
class: "form-select"
|
|
74
|
-
}, o(
|
|
75
|
-
onMousedown:
|
|
81
|
+
}, o(m), {
|
|
82
|
+
onMousedown: V,
|
|
76
83
|
onBlur: l[2] || (l[2] = //@ts-ignore
|
|
77
84
|
(...r) => o(v) && o(v)(...r)),
|
|
78
85
|
onFocus: l[3] || (l[3] = //@ts-ignore
|
|
@@ -80,13 +87,13 @@ const q = ["for"], H = { class: "form-group-inner" }, J = {
|
|
|
80
87
|
}), [
|
|
81
88
|
t(e.$slots, "default")
|
|
82
89
|
], 16), [
|
|
83
|
-
[I, o(
|
|
90
|
+
[I, o(n)]
|
|
84
91
|
])
|
|
85
92
|
]),
|
|
86
93
|
t(e.$slots, "activity", {}, () => [
|
|
87
|
-
|
|
88
|
-
default:
|
|
89
|
-
e.activity && e.indicator ? (s(),
|
|
94
|
+
B(R, { name: "select-field-fade" }, {
|
|
95
|
+
default: k(() => [
|
|
96
|
+
e.activity && e.indicator ? (s(), h(z, {
|
|
90
97
|
key: "activity",
|
|
91
98
|
ref: "activity",
|
|
92
99
|
type: e.indicator,
|
|
@@ -97,42 +104,42 @@ const q = ["for"], H = { class: "form-group-inner" }, J = {
|
|
|
97
104
|
})
|
|
98
105
|
])
|
|
99
106
|
]),
|
|
100
|
-
t(e.$slots, "errors",
|
|
101
|
-
e.error || e.errors ? (s(),
|
|
107
|
+
t(e.$slots, "errors", p(c({ error: e.error, errors: e.errors, id: e.$attrs.id, name: e.$attrs.name })), () => [
|
|
108
|
+
e.error || e.errors ? (s(), h(o(j), {
|
|
102
109
|
key: 0,
|
|
103
110
|
id: e.$attrs.id && String(e.$attrs.id),
|
|
104
111
|
name: e.$attrs.name && String(e.$attrs.name),
|
|
105
112
|
error: e.error,
|
|
106
113
|
errors: e.errors
|
|
107
114
|
}, {
|
|
108
|
-
default:
|
|
109
|
-
i("div",
|
|
110
|
-
|
|
111
|
-
|
|
115
|
+
default: k(({ error: r }) => [
|
|
116
|
+
i("div", K, [
|
|
117
|
+
G(f(r), 1),
|
|
118
|
+
L
|
|
112
119
|
])
|
|
113
120
|
]),
|
|
114
121
|
_: 1
|
|
115
122
|
}, 8, ["id", "name", "error", "errors"])) : a("", !0)
|
|
116
123
|
]),
|
|
117
|
-
t(e.$slots, "feedback",
|
|
118
|
-
|
|
119
|
-
default:
|
|
120
|
-
i("div",
|
|
124
|
+
t(e.$slots, "feedback", p(c({ feedback: e.feedback })), () => [
|
|
125
|
+
B(o(q), { feedback: e.feedback }, {
|
|
126
|
+
default: k(({ feedback: r }) => [
|
|
127
|
+
i("div", O, f(r), 1)
|
|
121
128
|
]),
|
|
122
129
|
_: 1
|
|
123
130
|
}, 8, ["feedback"])
|
|
124
131
|
]),
|
|
125
|
-
t(e.$slots, "help",
|
|
126
|
-
e.helpText ? (s(),
|
|
132
|
+
t(e.$slots, "help", p(c({ helpText: e.helpText })), () => [
|
|
133
|
+
e.helpText ? (s(), u("small", {
|
|
127
134
|
key: 0,
|
|
128
135
|
ref: "help"
|
|
129
|
-
},
|
|
136
|
+
}, f(e.helpText), 513)) : a("", !0)
|
|
130
137
|
])
|
|
131
138
|
], 2);
|
|
132
139
|
};
|
|
133
140
|
}
|
|
134
141
|
});
|
|
135
142
|
export {
|
|
136
|
-
|
|
143
|
+
X as SelectField
|
|
137
144
|
};
|
|
138
145
|
//# sourceMappingURL=select-field.js.map
|
package/dist/select-field.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-field.js","sources":["../src/SelectField.vue"],"sourcesContent":["<script setup lang=\"ts\" generic=\"T, V\">\nimport type { CheckedFormControlProps, FormControlSlots } from '@vue-interface/form-control';\nimport { FormControlErrors, FormControlFeedback, useFormControl } from '@vue-interface/form-control';\nimport { ref, useSlots } from 'vue';\n\ndefineSlots<FormControlSlots<T>>();\n\nconst emit = defineEmits<{\n (e: 'update:modelValue', value: T): void;\n}>();\n\nconst props = withDefaults(defineProps<CheckedFormControlProps<T, V>>(), {\n formControlClass: 'form-select',\n labelClass: 'form-label'\n});\n\nconst {\n controlAttributes,\n formGroupClasses,\n model,\n onClick,\n onBlur,\n onFocus\n} = useFormControl<T,V>(props, emit);\n\nconst field = ref<HTMLSelectElement>();\n\nfunction onMousedown(e) {\n onClick(e);\n\n field.value.focus();\n}\n</script>\n\n<template>\n <div\n class=\"select-field\"\n :class=\"formGroupClasses\">\n <slot name=\"label\">\n <label\n v-if=\"label\"\n ref=\"label\"\n :for=\"controlAttributes.id\"\n :class=\"labelClass\">\n {{ label }}\n </label>\n </slot>\n\n <div class=\"form-group-inner\">\n <slot\n name=\"control\"\n v-bind=\"{ onClick, onBlur, onFocus, controlAttributes }\">\n <div\n v-if=\"useSlots().icon\"\n class=\"form-group-inner-icon\"\n @click=\"field.focus\">\n <slot name=\"icon\" />\n </div>\n <select\n ref=\"field\"\n v-model=\"model\"\n class=\"form-select\"\n v-bind=\"controlAttributes\"\n @mousedown=\"onMousedown\"\n @blur=\"onBlur\"\n @focus=\"onFocus\">\n <slot />\n </select>\n </slot>\n\n <slot name=\"activity\">\n <Transition name=\"select-field-fade\">\n <ActivityIndicator\n v-if=\"activity && indicator\"\n key=\"activity\"\n ref=\"activity\"\n :type=\"indicator\"\n :size=\"indicatorSize\" />\n </Transition>\n </slot>\n </div>\n\n <slot\n name=\"errors\"\n v-bind=\"{ error, errors, id: $attrs.id, name: $attrs.name }\"> \n <FormControlErrors\n v-if=\"!!(error || errors)\"\n :id=\"$attrs.id && String($attrs.id)\"\n v-slot=\"{ error }\"\n :name=\"$attrs.name && String($attrs.name)\"\n :error=\"error\"\n :errors=\"errors\">\n <div\n invalid\n class=\"invalid-feedback\">\n {{ error }}<br>\n </div>\n </FormControlErrors>\n </slot>\n \n <slot\n name=\"feedback\"\n v-bind=\"{ feedback }\">\n <FormControlFeedback\n v-slot=\"{ feedback }\"\n :feedback=\"feedback\">\n <div\n valid\n class=\"valid-feedback\">\n {{ feedback }}\n </div>\n </FormControlFeedback>\n </slot>\n\n <slot\n name=\"help\"\n v-bind=\"{ helpText }\">\n <small\n v-if=\"helpText\"\n ref=\"help\">\n {{ helpText }}\n </small>\n </slot>\n </div>\n</template>"],"names":["controlAttributes","formGroupClasses","model","onClick","onBlur","onFocus","useFormControl","props","emit","field","ref","onMousedown"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgBM;AAAA,MACF,mBAAAA;AAAA,MACA,kBAAAC;AAAA,MACA,OAAAC;AAAA,MACA,SAAAC;AAAA,MACA,QAAAC;AAAA,MACA,SAAAC;AAAA,
|
|
1
|
+
{"version":3,"file":"select-field.js","sources":["../src/SelectField.vue"],"sourcesContent":["<script setup lang=\"ts\" generic=\"T, V\">\nimport type { CheckedFormControlProps, FormControlSlots } from '@vue-interface/form-control';\nimport { FormControlErrors, FormControlFeedback, useFormControl } from '@vue-interface/form-control';\nimport { onMounted, ref, useSlots } from 'vue';\n\ndefineSlots<FormControlSlots<T>>();\n\nconst emit = defineEmits<{\n (e: 'update:modelValue', value: T): void;\n}>();\n\nconst props = withDefaults(defineProps<CheckedFormControlProps<T, V>>(), {\n formControlClass: 'form-select',\n labelClass: 'form-label'\n});\n\nconst {\n controlAttributes,\n formGroupClasses,\n model,\n onClick,\n onBlur,\n onFocus\n} = useFormControl<T,V>({ props, emit });\n\nconst field = ref<HTMLSelectElement>();\n\nfunction onMousedown(e) {\n onClick(e);\n\n field.value.focus();\n}\n\n// Check the option slots for selected options. If the field has hardcoded\n// selected options, this will ensure the value of the field is always set to\n// the property. This will ensure the model is updated to the selected value.\nonMounted(() => {\n if(!useSlots().default) {\n return;\n }\n\n for(const child of useSlots().default()) {\n if(!child.props) {\n return;\n }\n \n if('selected' in child.props && (child.props.value ?? child.children)) {\n model.value = child.props.value ?? child.children;\n }\n }\n});\n</script>\n\n<template>\n <div\n class=\"select-field\"\n :class=\"formGroupClasses\">\n <slot name=\"label\">\n <label\n v-if=\"label\"\n ref=\"label\"\n :for=\"controlAttributes.id\"\n :class=\"labelClass\">\n {{ label }}\n </label>\n </slot>\n\n <div class=\"form-group-inner\">\n <slot\n name=\"control\"\n v-bind=\"{ onClick, onBlur, onFocus, controlAttributes }\">\n <div\n v-if=\"useSlots().icon\"\n class=\"form-group-inner-icon\"\n @click=\"field.focus\">\n <slot name=\"icon\" />\n </div>\n <select\n ref=\"field\"\n v-model=\"model\"\n class=\"form-select\"\n v-bind=\"controlAttributes\"\n @mousedown=\"onMousedown\"\n @blur=\"onBlur\"\n @focus=\"onFocus\">\n <slot />\n </select>\n </slot>\n\n <slot name=\"activity\">\n <Transition name=\"select-field-fade\">\n <ActivityIndicator\n v-if=\"activity && indicator\"\n key=\"activity\"\n ref=\"activity\"\n :type=\"indicator\"\n :size=\"indicatorSize\" />\n </Transition>\n </slot>\n </div>\n\n <slot\n name=\"errors\"\n v-bind=\"{ error, errors, id: $attrs.id, name: $attrs.name }\"> \n <FormControlErrors\n v-if=\"!!(error || errors)\"\n :id=\"$attrs.id && String($attrs.id)\"\n v-slot=\"{ error }\"\n :name=\"$attrs.name && String($attrs.name)\"\n :error=\"error\"\n :errors=\"errors\">\n <div\n invalid\n class=\"invalid-feedback\">\n {{ error }}<br>\n </div>\n </FormControlErrors>\n </slot>\n \n <slot\n name=\"feedback\"\n v-bind=\"{ feedback }\">\n <FormControlFeedback\n v-slot=\"{ feedback }\"\n :feedback=\"feedback\">\n <div\n valid\n class=\"valid-feedback\">\n {{ feedback }}\n </div>\n </FormControlFeedback>\n </slot>\n\n <slot\n name=\"help\"\n v-bind=\"{ helpText }\">\n <small\n v-if=\"helpText\"\n ref=\"help\">\n {{ helpText }}\n </small>\n </slot>\n </div>\n</template>"],"names":["controlAttributes","formGroupClasses","model","onClick","onBlur","onFocus","useFormControl","props","emit","field","ref","onMousedown","onMounted","useSlots","child"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgBM;AAAA,MACF,mBAAAA;AAAA,MACA,kBAAAC;AAAA,MACA,OAAAC;AAAA,MACA,SAAAC;AAAA,MACA,QAAAC;AAAA,MACA,SAAAC;AAAA,IACA,IAAAC,EAAoB,EAAE,OAAAC,GAAO,MAAAC,EAAM,CAAA,GAEjCC,IAAQC;AAEd,aAASC,EAAY,GAAG;AACpB,MAAAR,EAAQ,CAAC,GAETM,EAAM,MAAM;IAChB;AAKA,WAAAG,EAAU,MAAM;AACT,UAACC,EAAS,EAAE;AAIf,mBAAUC,KAASD,EAAW,EAAA,QAAA,GAAW;AAClC,cAAA,CAACC,EAAM;AACN;AAGJ,UAAG,cAAcA,EAAM,UAAUA,EAAM,MAAM,SAASA,EAAM,cACxDZ,EAAM,QAAQY,EAAM,MAAM,SAASA,EAAM;AAAA,QAEjD;AAAA,IAAA,CACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(function(t,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@vue-interface/form-control")):typeof define=="function"&&define.amd?define(["exports","vue","@vue-interface/form-control"],e):(t=typeof globalThis<"u"?globalThis:t||self,e(t.SelectField={},t.Vue,t.VueInterfaceFormControl))})(this,function(t,e,
|
|
1
|
+
(function(t,e){typeof exports=="object"&&typeof module<"u"?e(exports,require("vue"),require("@vue-interface/form-control")):typeof define=="function"&&define.amd?define(["exports","vue","@vue-interface/form-control"],e):(t=typeof globalThis<"u"?globalThis:t||self,e(t.SelectField={},t.Vue,t.VueInterfaceFormControl))})(this,function(t,e,s){"use strict";const p=["for"],m={class:"form-group-inner"},k={invalid:"",class:"invalid-feedback"},y=e.createElementVNode("br",null,null,-1),S={valid:"",class:"valid-feedback"},b=e.defineComponent({__name:"SelectField",props:{activity:{type:Boolean},disabled:{type:Boolean},error:{},errors:{},feedback:{},formControlClass:{default:"form-select"},helpText:{},id:{},indicator:{},indicatorSize:{},invalid:{type:Boolean},label:{},labelClass:{default:"form-label"},modelValue:{},name:{},plaintext:{type:Boolean},readonly:{type:Boolean},valid:{type:Boolean},value:{},checked:{type:Boolean}},emits:["update:modelValue"],setup(B,{emit:C}){const V=B,{controlAttributes:a,formGroupClasses:h,model:n,onClick:c,onBlur:d,onFocus:f}=s.useFormControl({props:V,emit:C}),i=e.ref();function u(o){c(o),i.value.focus()}return e.onMounted(()=>{if(e.useSlots().default)for(const o of e.useSlots().default()){if(!o.props)return;"selected"in o.props&&(o.props.value??o.children)&&(n.value=o.props.value??o.children)}}),(o,l)=>{const $=e.resolveComponent("ActivityIndicator");return e.openBlock(),e.createElementBlock("div",{class:e.normalizeClass(["select-field",e.unref(h)])},[e.renderSlot(o.$slots,"label",{},()=>[o.label?(e.openBlock(),e.createElementBlock("label",{key:0,ref:"label",for:e.unref(a).id,class:e.normalizeClass(o.labelClass)},e.toDisplayString(o.label),11,p)):e.createCommentVNode("",!0)]),e.createElementVNode("div",m,[e.renderSlot(o.$slots,"control",e.normalizeProps(e.guardReactiveProps({onClick:e.unref(c),onBlur:e.unref(d),onFocus:e.unref(f),controlAttributes:e.unref(a)})),()=>[e.useSlots().icon?(e.openBlock(),e.createElementBlock("div",{key:0,class:"form-group-inner-icon",onClick:l[0]||(l[0]=(...r)=>i.value.focus&&i.value.focus(...r))},[e.renderSlot(o.$slots,"icon")])):e.createCommentVNode("",!0),e.withDirectives(e.createElementVNode("select",e.mergeProps({ref_key:"field",ref:i,"onUpdate:modelValue":l[1]||(l[1]=r=>e.isRef(n)?n.value=r:null),class:"form-select"},e.unref(a),{onMousedown:u,onBlur:l[2]||(l[2]=(...r)=>e.unref(d)&&e.unref(d)(...r)),onFocus:l[3]||(l[3]=(...r)=>e.unref(f)&&e.unref(f)(...r))}),[e.renderSlot(o.$slots,"default")],16),[[e.vModelSelect,e.unref(n)]])]),e.renderSlot(o.$slots,"activity",{},()=>[e.createVNode(e.Transition,{name:"select-field-fade"},{default:e.withCtx(()=>[o.activity&&o.indicator?(e.openBlock(),e.createBlock($,{key:"activity",ref:"activity",type:o.indicator,size:o.indicatorSize},null,8,["type","size"])):e.createCommentVNode("",!0)]),_:1})])]),e.renderSlot(o.$slots,"errors",e.normalizeProps(e.guardReactiveProps({error:o.error,errors:o.errors,id:o.$attrs.id,name:o.$attrs.name})),()=>[o.error||o.errors?(e.openBlock(),e.createBlock(e.unref(s.FormControlErrors),{key:0,id:o.$attrs.id&&String(o.$attrs.id),name:o.$attrs.name&&String(o.$attrs.name),error:o.error,errors:o.errors},{default:e.withCtx(({error:r})=>[e.createElementVNode("div",k,[e.createTextVNode(e.toDisplayString(r),1),y])]),_:1},8,["id","name","error","errors"])):e.createCommentVNode("",!0)]),e.renderSlot(o.$slots,"feedback",e.normalizeProps(e.guardReactiveProps({feedback:o.feedback})),()=>[e.createVNode(e.unref(s.FormControlFeedback),{feedback:o.feedback},{default:e.withCtx(({feedback:r})=>[e.createElementVNode("div",S,e.toDisplayString(r),1)]),_:1},8,["feedback"])]),e.renderSlot(o.$slots,"help",e.normalizeProps(e.guardReactiveProps({helpText:o.helpText})),()=>[o.helpText?(e.openBlock(),e.createElementBlock("small",{key:0,ref:"help"},e.toDisplayString(o.helpText),513)):e.createCommentVNode("",!0)])],2)}}});t.SelectField=b,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
|
|
2
2
|
//# sourceMappingURL=select-field.umd.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"select-field.umd.cjs","sources":["../src/SelectField.vue"],"sourcesContent":["<script setup lang=\"ts\" generic=\"T, V\">\nimport type { CheckedFormControlProps, FormControlSlots } from '@vue-interface/form-control';\nimport { FormControlErrors, FormControlFeedback, useFormControl } from '@vue-interface/form-control';\nimport { ref, useSlots } from 'vue';\n\ndefineSlots<FormControlSlots<T>>();\n\nconst emit = defineEmits<{\n (e: 'update:modelValue', value: T): void;\n}>();\n\nconst props = withDefaults(defineProps<CheckedFormControlProps<T, V>>(), {\n formControlClass: 'form-select',\n labelClass: 'form-label'\n});\n\nconst {\n controlAttributes,\n formGroupClasses,\n model,\n onClick,\n onBlur,\n onFocus\n} = useFormControl<T,V>(props, emit);\n\nconst field = ref<HTMLSelectElement>();\n\nfunction onMousedown(e) {\n onClick(e);\n\n field.value.focus();\n}\n</script>\n\n<template>\n <div\n class=\"select-field\"\n :class=\"formGroupClasses\">\n <slot name=\"label\">\n <label\n v-if=\"label\"\n ref=\"label\"\n :for=\"controlAttributes.id\"\n :class=\"labelClass\">\n {{ label }}\n </label>\n </slot>\n\n <div class=\"form-group-inner\">\n <slot\n name=\"control\"\n v-bind=\"{ onClick, onBlur, onFocus, controlAttributes }\">\n <div\n v-if=\"useSlots().icon\"\n class=\"form-group-inner-icon\"\n @click=\"field.focus\">\n <slot name=\"icon\" />\n </div>\n <select\n ref=\"field\"\n v-model=\"model\"\n class=\"form-select\"\n v-bind=\"controlAttributes\"\n @mousedown=\"onMousedown\"\n @blur=\"onBlur\"\n @focus=\"onFocus\">\n <slot />\n </select>\n </slot>\n\n <slot name=\"activity\">\n <Transition name=\"select-field-fade\">\n <ActivityIndicator\n v-if=\"activity && indicator\"\n key=\"activity\"\n ref=\"activity\"\n :type=\"indicator\"\n :size=\"indicatorSize\" />\n </Transition>\n </slot>\n </div>\n\n <slot\n name=\"errors\"\n v-bind=\"{ error, errors, id: $attrs.id, name: $attrs.name }\"> \n <FormControlErrors\n v-if=\"!!(error || errors)\"\n :id=\"$attrs.id && String($attrs.id)\"\n v-slot=\"{ error }\"\n :name=\"$attrs.name && String($attrs.name)\"\n :error=\"error\"\n :errors=\"errors\">\n <div\n invalid\n class=\"invalid-feedback\">\n {{ error }}<br>\n </div>\n </FormControlErrors>\n </slot>\n \n <slot\n name=\"feedback\"\n v-bind=\"{ feedback }\">\n <FormControlFeedback\n v-slot=\"{ feedback }\"\n :feedback=\"feedback\">\n <div\n valid\n class=\"valid-feedback\">\n {{ feedback }}\n </div>\n </FormControlFeedback>\n </slot>\n\n <slot\n name=\"help\"\n v-bind=\"{ helpText }\">\n <small\n v-if=\"helpText\"\n ref=\"help\">\n {{ helpText }}\n </small>\n </slot>\n </div>\n</template>"],"names":["controlAttributes","formGroupClasses","model","onClick","onBlur","onFocus","useFormControl","props","emit","field","ref","onMousedown","e"],"mappings":"o9BAgBM,CACF,kBAAAA,EACA,iBAAAC,EACA,MAAAC,EACA,QAAAC,EACA,OAAAC,EACA,QAAAC,
|
|
1
|
+
{"version":3,"file":"select-field.umd.cjs","sources":["../src/SelectField.vue"],"sourcesContent":["<script setup lang=\"ts\" generic=\"T, V\">\nimport type { CheckedFormControlProps, FormControlSlots } from '@vue-interface/form-control';\nimport { FormControlErrors, FormControlFeedback, useFormControl } from '@vue-interface/form-control';\nimport { onMounted, ref, useSlots } from 'vue';\n\ndefineSlots<FormControlSlots<T>>();\n\nconst emit = defineEmits<{\n (e: 'update:modelValue', value: T): void;\n}>();\n\nconst props = withDefaults(defineProps<CheckedFormControlProps<T, V>>(), {\n formControlClass: 'form-select',\n labelClass: 'form-label'\n});\n\nconst {\n controlAttributes,\n formGroupClasses,\n model,\n onClick,\n onBlur,\n onFocus\n} = useFormControl<T,V>({ props, emit });\n\nconst field = ref<HTMLSelectElement>();\n\nfunction onMousedown(e) {\n onClick(e);\n\n field.value.focus();\n}\n\n// Check the option slots for selected options. If the field has hardcoded\n// selected options, this will ensure the value of the field is always set to\n// the property. This will ensure the model is updated to the selected value.\nonMounted(() => {\n if(!useSlots().default) {\n return;\n }\n\n for(const child of useSlots().default()) {\n if(!child.props) {\n return;\n }\n \n if('selected' in child.props && (child.props.value ?? child.children)) {\n model.value = child.props.value ?? child.children;\n }\n }\n});\n</script>\n\n<template>\n <div\n class=\"select-field\"\n :class=\"formGroupClasses\">\n <slot name=\"label\">\n <label\n v-if=\"label\"\n ref=\"label\"\n :for=\"controlAttributes.id\"\n :class=\"labelClass\">\n {{ label }}\n </label>\n </slot>\n\n <div class=\"form-group-inner\">\n <slot\n name=\"control\"\n v-bind=\"{ onClick, onBlur, onFocus, controlAttributes }\">\n <div\n v-if=\"useSlots().icon\"\n class=\"form-group-inner-icon\"\n @click=\"field.focus\">\n <slot name=\"icon\" />\n </div>\n <select\n ref=\"field\"\n v-model=\"model\"\n class=\"form-select\"\n v-bind=\"controlAttributes\"\n @mousedown=\"onMousedown\"\n @blur=\"onBlur\"\n @focus=\"onFocus\">\n <slot />\n </select>\n </slot>\n\n <slot name=\"activity\">\n <Transition name=\"select-field-fade\">\n <ActivityIndicator\n v-if=\"activity && indicator\"\n key=\"activity\"\n ref=\"activity\"\n :type=\"indicator\"\n :size=\"indicatorSize\" />\n </Transition>\n </slot>\n </div>\n\n <slot\n name=\"errors\"\n v-bind=\"{ error, errors, id: $attrs.id, name: $attrs.name }\"> \n <FormControlErrors\n v-if=\"!!(error || errors)\"\n :id=\"$attrs.id && String($attrs.id)\"\n v-slot=\"{ error }\"\n :name=\"$attrs.name && String($attrs.name)\"\n :error=\"error\"\n :errors=\"errors\">\n <div\n invalid\n class=\"invalid-feedback\">\n {{ error }}<br>\n </div>\n </FormControlErrors>\n </slot>\n \n <slot\n name=\"feedback\"\n v-bind=\"{ feedback }\">\n <FormControlFeedback\n v-slot=\"{ feedback }\"\n :feedback=\"feedback\">\n <div\n valid\n class=\"valid-feedback\">\n {{ feedback }}\n </div>\n </FormControlFeedback>\n </slot>\n\n <slot\n name=\"help\"\n v-bind=\"{ helpText }\">\n <small\n v-if=\"helpText\"\n ref=\"help\">\n {{ helpText }}\n </small>\n </slot>\n </div>\n</template>"],"names":["controlAttributes","formGroupClasses","model","onClick","onBlur","onFocus","useFormControl","props","emit","field","ref","onMousedown","e","onMounted","useSlots","child"],"mappings":"o9BAgBM,CACF,kBAAAA,EACA,iBAAAC,EACA,MAAAC,EACA,QAAAC,EACA,OAAAC,EACA,QAAAC,CACA,EAAAC,iBAAoB,CAAE,MAAAC,EAAO,KAAAC,CAAM,CAAA,EAEjCC,EAAQC,EAAAA,MAEd,SAASC,EAAYC,EAAG,CACpBT,EAAQS,CAAC,EAETH,EAAM,MAAM,OAChB,CAKAI,OAAAA,EAAAA,UAAU,IAAM,CACT,GAACC,EAAAA,SAAS,EAAE,QAIf,UAAUC,KAASD,WAAW,EAAA,QAAA,EAAW,CAClC,GAAA,CAACC,EAAM,MACN,OAGD,aAAcA,EAAM,QAAUA,EAAM,MAAM,OAASA,EAAM,YACxDb,EAAM,MAAQa,EAAM,MAAM,OAASA,EAAM,SAEjD,CAAA,CACH"}
|
|
@@ -9,7 +9,7 @@ declare const _default: <T, V>(__VLS_props: import("@vue-interface/form-control"
|
|
|
9
9
|
attrs: any;
|
|
10
10
|
slots: FormControlSlots<T>;
|
|
11
11
|
emit: (e: 'update:modelValue', value: T) => void;
|
|
12
|
-
}, "attrs" | "emit" | "slots">, __VLS_setup?: Promise<{
|
|
12
|
+
}, "attrs" | "emit" | "slots">, __VLS_expose?: (exposed: {}) => void, __VLS_setup?: Promise<{
|
|
13
13
|
props: import("@vue-interface/form-control").FormControlProps<T, V> & {
|
|
14
14
|
checked?: boolean;
|
|
15
15
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vue-interface/select-field",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.15",
|
|
4
4
|
"description": "A Vue select field component.",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist"
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"homepage": "https://github.com/vue-interface/select-field",
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"@vue-interface/activity-indicator": "^2.0.0-beta.11",
|
|
45
|
-
"@vue-interface/form-control": "^1.0.0-beta.
|
|
45
|
+
"@vue-interface/form-control": "^1.0.0-beta.40"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
48
|
"vue": "^3.3.4"
|