ldc-supportweb/resources/ts/bo/components/LabelSelectComponent.vue

79 lines
1.7 KiB
Vue
Raw Permalink Normal View History

2022-08-30 13:21:07 +00:00
<template>
<div>
<VueSelect
v-model="selectedLabels"
:multiple="true"
:clearable="true"
label="label"
:options="labels"
>
<template #option="{ label, color }: { label: string, color: string }">
2022-08-30 13:21:07 +00:00
<span
class="py-1 px-2"
:style="`background-color: ${color};color: ${invertColor(color, true)};`"
2022-08-30 13:21:07 +00:00
>
{{ String(label) }}
2022-08-30 13:21:07 +00:00
</span>
</template>
<template #no-options>
{{ __("Plus de label disponibles") }}
2022-08-30 13:21:07 +00:00
</template>
</VueSelect>
<input
v-for="label of selectedLabels"
type="hidden"
:key="label.value"
:value="label.value"
:name="`${name}[]`"
>
</div>
</template>
<script lang="ts">
import { defineComponent } from "vue";
import VueSelect from "vue-select";
import colors from "../../modules/colors";
import trans from "../../modules/trans";
2022-08-30 13:21:07 +00:00
export default defineComponent({
mixins: [trans, colors],
components: {
VueSelect,
},
mounted() {
const json = String(this.$attrs.json ?? "{}"),
data = JSON.parse(json);
this.name = data.name;
for (const label of data.value ?? []) {
2022-08-30 13:21:07 +00:00
this.selectedLabels.push({
label: label.name,
value: label.id,
color: label.color,
});
}
for (const label of data.labels) {
2022-08-30 13:21:07 +00:00
this.labels.push({
label: label.name,
value: label.id,
color: label.color,
});
}
},
data(): {
name: string;
selectedLabels: SelectModel[];
labels: SelectModel[];
} {
return {
name: "",
selectedLabels: [],
labels: [],
};
},
});
</script>
<style lang="scss">
@import "vue-select/dist/vue-select.css";
</style>