Skip to content

Commit

Permalink
feat(dashboard): Adding TomSelect for link tags
Browse files Browse the repository at this point in the history
Signed-off-by: Binyamin Yawitz <316103+byawitz@users.noreply.github.com>
  • Loading branch information
byawitz committed Apr 12, 2024
1 parent 705f499 commit aa58fe7
Show file tree
Hide file tree
Showing 7 changed files with 102 additions and 4 deletions.
36 changes: 36 additions & 0 deletions apps/dashboard/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions apps/dashboard/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"litepicker": "^2.0.12",
"pinia": "^2.1.7",
"sass": "^1.74.1",
"tom-select": "^2.3.1",
"vue": "^3.4.15",
"vue-i18n": "^9.10.2",
"vue-router": "^4.2.5",
Expand Down
4 changes: 2 additions & 2 deletions apps/dashboard/src/assets/scss/tabler.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@import "core";
@import "vendor/tom-select";

html[dir="rtl"] {
@import "tabler.rtl.min";
}

}
56 changes: 56 additions & 0 deletions apps/dashboard/src/components/form/TomSelect.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<template>
<div :class="`mb-${mb}`">
<label class="form-label">{{ label }}</label>
<select class="form-select" v-model="model" ref="el" multiple style="display: none">
<option v-for="option in options" :value="option.value" :key="option.value" v-text="option.text" />
</select>
</div>
</template>

<script setup lang="ts">
import { onMounted, type PropType, ref } from 'vue';
import TomSelect from 'tom-select';
import { useI18n } from 'vue-i18n';
declare type SelectOptions = { value: any; text: string };
defineProps({
options: { default: [], type: Array as PropType<SelectOptions[]> },
label: { default: '', type: String },
mb: { default: '3', type: String }
});
const model = defineModel();
const el = ref();
const { t } = useI18n();
onMounted(() => {
new TomSelect(el.value, {
createOnBlur: true,
create: true,
render: {
option: (data: any, escape: any) => {
return '<div>' + escape(data.text) + '</div>';
},
item: function (data: any, escape: any) {
return '<div>' + escape(data.text) + '</div>';
},
option_create: function (data: any, escape: any) {
return `<div class="create">${t('Add')} <strong>${escape(data.input)}</strong>&hellip;</div>`;
},
no_results: function (data: any, escape: any) {
return `<div class="no-results">${t('no-results-for')} "${escape(data.input)}"</div>`;
},
not_loading: function (data: any, escape: any) {
// no default content
},
loading: function (data: any, escape: any) {
return '<div class="spinner"></div>';
},
dropdown: function () {
return '<div></div>';
}
}
});
});
</script>
3 changes: 2 additions & 1 deletion apps/dashboard/src/locale/languages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,6 @@
"Save": "Save",
"system-default": "System Default",
"dark": "Dark",
"light": "Light"
"light": "Light",
"no-results-for": "No results found for"
}
3 changes: 2 additions & 1 deletion apps/dashboard/src/locale/languages/he.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,6 @@
"Save": "שמירה",
"system-default": "ברירת מחדל של המערכת",
"dark": "כהה",
"light": "בהירה"
"light": "בהירה",
"no-results-for": "לא נמצאו תוצאות עבור"
}
3 changes: 3 additions & 0 deletions apps/dashboard/src/views/LinkFormView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

<div class="col-xl-6">
<InputSelect :label="$t('Campaign')" v-model="link.campaign_id" :options="[]" />
<TomSelect :label="$t('Tags')" v-model="tags" :options="[{ text: 'Tag', value: 'Tag' }]" />

<div class="mb-3">
<div class="form-label">{{ $t('Link options') }}</div>
Expand Down Expand Up @@ -90,6 +91,7 @@ import InputDate from '@/components/form/InputDate.vue';
import InputSelect from '@/components/form/InputSelect.vue';
import Container from '@/components/layouts/Container.vue';
import { useI18n } from 'vue-i18n';
import TomSelect from '@/components/form/TomSelect.vue';
const router = useRouter();
const { t } = useI18n();
Expand All @@ -107,6 +109,7 @@ const link: Ref<LinkModel> = ref(new LinkModel());
const loading = ref(isEdit.value);
const submitting = ref(false);
const submittedOnce = ref(false);
const tags = ref([]);
const pageTitle = computed(() => (isEdit.value ? t('Edit') : t('New link')));
Expand Down

0 comments on commit aa58fe7

Please sign in to comment.