Profectus/src/components/fields/Select.vue

63 lines
1.2 KiB
Vue
Raw Normal View History

2021-05-22 15:29:06 -05:00
<template>
<div class="field">
2021-06-11 23:38:16 -05:00
<span class="field-title" v-if="title">{{ title }}</span>
2021-07-24 17:08:52 -05:00
<vue-select :options="options" :model-value="value" @update:modelValue="setSelected" label-by="label" :value-by="getValue" :placeholder="placeholder" :close-on-select="closeOnSelect" />
2021-05-22 15:29:06 -05:00
</div>
</template>
<script>
export default {
name: 'Select',
props: {
title: String,
options: Array, // https://vue-select.org/guide/options.html#options-prop
2021-06-11 23:38:16 -05:00
value: [ String, Object ],
2021-07-24 17:08:52 -05:00
default: [ String, Object ],
placeholder: String,
closeOnSelect: Boolean
2021-05-22 15:29:06 -05:00
},
2021-07-24 17:08:52 -05:00
emits: [ 'change' ],
2021-05-22 15:29:06 -05:00
methods: {
2021-07-24 17:08:52 -05:00
setSelected(value) {
value = value || this.default;
2021-05-22 15:29:06 -05:00
this.$emit('change', value);
2021-07-24 17:08:52 -05:00
},
getValue(item) {
return item?.value;
2021-05-22 15:29:06 -05:00
}
}
};
</script>
<style>
2021-07-24 17:08:52 -05:00
.vue-select {
2021-05-22 15:29:06 -05:00
width: 50%;
}
2021-07-24 17:08:52 -05:00
.field-buttons .vue-select {
width: unset;
2021-05-22 15:29:06 -05:00
}
2021-07-24 17:08:52 -05:00
.vue-select,
.vue-dropdown {
border-color: rgba(var(--color), .26);
2021-05-22 15:29:06 -05:00
}
2021-07-24 17:08:52 -05:00
.vue-dropdown {
background: var(--secondary-background);
2021-05-22 15:29:06 -05:00
}
2021-07-24 17:08:52 -05:00
.vue-dropdown-item {
color: var(--color);
2021-05-22 15:29:06 -05:00
}
2021-07-24 17:08:52 -05:00
.vue-dropdown-item.highlighted {
background-color: var(--background-tooltip);
2021-05-22 15:29:06 -05:00
}
2021-06-20 23:29:55 -05:00
2021-07-24 17:08:52 -05:00
.vue-dropdown-item.selected,
.vue-dropdown-item.highlighted.selected {
background-color: var(--bought);
2021-06-20 23:29:55 -05:00
}
2021-05-22 15:29:06 -05:00
</style>