Files
mixtape/zero.Backoffice.UI/old_app/components/pickers/iconPicker/iconpicker.vue
T

117 lines
2.2 KiB
Vue
Raw Normal View History

2020-04-24 15:13:54 +02:00
<template>
2020-09-29 16:19:24 +02:00
<div v-if="output" class="ui-iconpicker" :class="{'is-disabled': disabled }">
2020-04-25 19:38:45 +02:00
<input ref="input" type="hidden" :value="value" />
2020-04-30 15:35:09 +02:00
<ui-select-button :icon="previewIcon" label="@ui.icon" :description="buttonDescription" @click="pick" :disabled="disabled" />
2020-04-24 15:13:54 +02:00
</div>
</template>
<script>
2020-11-01 22:20:29 +01:00
import PickIconOverlay from './overlay.vue';
import Overlay from 'zero/helpers/overlay.js';
2020-04-24 15:13:54 +02:00
import { extend as _extend } from 'underscore';
export default {
name: 'uiIconpicker',
props: {
value: {
type: String,
default: null
},
disabled: {
type: Boolean,
default: false
},
colors: {
type: Boolean,
default: false
},
2020-09-29 16:19:24 +02:00
output: {
type: Boolean,
default: true
},
set: {
type: String,
default: 'feather'
},
2020-04-24 15:13:54 +02:00
options: {
type: Object,
default: () =>
{
return {
};
}
}
},
data: () => ({
iconSet: null
}),
watch: {
set()
{
this.loadSet();
}
},
created()
{
this.loadSet();
},
2020-04-24 15:13:54 +02:00
computed: {
buttonDescription()
{
return this.value ? this.value.split(' ')[0] : '@ui.icon_select';
2020-04-30 15:35:09 +02:00
},
previewIcon()
{
return this.value || 'fth-plus';
2020-04-24 15:13:54 +02:00
}
},
methods: {
2020-04-24 19:38:33 +02:00
onChange(value)
2020-04-24 15:13:54 +02:00
{
2020-04-24 19:38:33 +02:00
this.$emit('change', value);
this.$emit('input', value);
// TODO this does not trigger the forms dirty flag
2020-04-24 15:13:54 +02:00
},
loadSet()
{
this.iconSet = __zero.icons.find(x => x.alias === this.set);
},
2020-04-24 15:13:54 +02:00
pick()
{
2020-04-28 14:51:17 +02:00
if (this.disabled)
{
return;
}
2020-04-24 15:13:54 +02:00
let options = _extend({
title: '@iconpicker.title',
closeLabel: '@ui.close',
component: PickIconOverlay,
display: 'editor',
set: this.iconSet,
model: this.value,
colors: this.colors,
2021-01-17 20:04:43 +01:00
width: 660
2020-04-24 15:13:54 +02:00
}, typeof this.options === 'object' ? this.options : {});
return Overlay.open(options).then(value =>
{
2020-04-24 19:38:33 +02:00
this.onChange(value);
//this.$refs.input.value = value;
2020-04-24 15:13:54 +02:00
});
}
}
}
2020-04-28 14:51:17 +02:00
</script>