feat(v4): Update the campaigns page design (#10371)
<img width="1439" alt="Screenshot 2024-10-30 at 8 58 12 PM" src="https://github.com/user-attachments/assets/26231270-5e73-40fb-9efa-c661585ebe7c"> Fixes https://linear.app/chatwoot/project/campaign-redesign-f82bede26ca7/overview --------- Co-authored-by: Pranav <pranavrajs@gmail.com> Co-authored-by: Shivam Mishra <scm.mymail@gmail.com>
This commit is contained in:
@@ -4,6 +4,7 @@ import { OnClickOutside } from '@vueuse/components';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
import Button from 'dashboard/components-next/button/Button.vue';
|
||||
import ComboBoxDropdown from 'dashboard/components-next/combobox/ComboBoxDropdown.vue';
|
||||
|
||||
const props = defineProps({
|
||||
options: {
|
||||
@@ -36,6 +37,10 @@ const props = defineProps({
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
hasError: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:modelValue']);
|
||||
@@ -45,7 +50,7 @@ const { t } = useI18n();
|
||||
const selectedValue = ref(props.modelValue);
|
||||
const open = ref(false);
|
||||
const search = ref('');
|
||||
const searchInput = ref(null);
|
||||
const dropdownRef = ref(null);
|
||||
const comboboxRef = ref(null);
|
||||
|
||||
const filteredOptions = computed(() => {
|
||||
@@ -70,11 +75,13 @@ const selectOption = option => {
|
||||
open.value = false;
|
||||
search.value = '';
|
||||
};
|
||||
|
||||
const toggleDropdown = () => {
|
||||
if (props.disabled) return;
|
||||
open.value = !open.value;
|
||||
if (open.value) {
|
||||
search.value = '';
|
||||
nextTick(() => searchInput.value.focus());
|
||||
nextTick(() => dropdownRef.value?.focus());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -94,67 +101,40 @@ watch(
|
||||
'cursor-not-allowed': disabled,
|
||||
'group/combobox': !disabled,
|
||||
}"
|
||||
@click.prevent
|
||||
>
|
||||
<OnClickOutside @trigger="open = false">
|
||||
<Button
|
||||
variant="outline"
|
||||
color="slate"
|
||||
:color="hasError && !open ? 'ruby' : open ? 'blue' : 'slate'"
|
||||
:label="selectedLabel"
|
||||
trailing-icon
|
||||
:disabled="disabled"
|
||||
class="justify-between w-full !px-3 !py-2.5 text-n-slate-12 font-normal group-hover/combobox:border-n-slate-6"
|
||||
:class="{ focused: open }"
|
||||
:icon="open ? 'i-lucide-chevron-up' : 'i-lucide-chevron-down'"
|
||||
@click="toggleDropdown"
|
||||
/>
|
||||
<div
|
||||
v-show="open"
|
||||
class="absolute z-50 w-full mt-1 transition-opacity duration-200 border rounded-md shadow-lg bg-n-solid-1 border-n-strong"
|
||||
>
|
||||
<div class="relative border-b border-n-strong">
|
||||
<span class="absolute i-lucide-search top-2.5 size-4 left-3" />
|
||||
<input
|
||||
ref="searchInput"
|
||||
v-model="search"
|
||||
type="search"
|
||||
:placeholder="searchPlaceholder || t('COMBOBOX.SEARCH_PLACEHOLDER')"
|
||||
class="w-full py-2 pl-10 pr-2 text-sm border-none rounded-t-md bg-n-solid-1 text-slate-900 dark:text-slate-50"
|
||||
/>
|
||||
</div>
|
||||
<ul
|
||||
class="py-1 mb-0 overflow-auto max-h-60"
|
||||
role="listbox"
|
||||
:aria-activedescendant="selectedValue"
|
||||
>
|
||||
<li
|
||||
v-for="option in filteredOptions"
|
||||
:key="option.value"
|
||||
class="flex items-center justify-between !text-n-slate-12 w-full gap-2 px-3 py-2 text-sm transition-colors duration-150 cursor-pointer hover:bg-n-alpha-2"
|
||||
:class="{
|
||||
'bg-n-alpha-2': option.value === selectedValue,
|
||||
}"
|
||||
role="option"
|
||||
:aria-selected="option.value === selectedValue"
|
||||
@click="selectOption(option)"
|
||||
>
|
||||
<span :class="{ 'font-medium': option.value === selectedValue }">
|
||||
{{ option.label }}
|
||||
</span>
|
||||
<span
|
||||
v-if="option.value === selectedValue"
|
||||
class="flex-shrink-0 i-lucide-check size-4 text-n-slate-11"
|
||||
/>
|
||||
</li>
|
||||
<li
|
||||
v-if="filteredOptions.length === 0"
|
||||
class="px-3 py-2 text-sm text-slate-600 dark:text-slate-300"
|
||||
>
|
||||
{{ emptyState || t('COMBOBOX.EMPTY_STATE') }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<ComboBoxDropdown
|
||||
ref="dropdownRef"
|
||||
:open="open"
|
||||
:options="filteredOptions"
|
||||
:search-value="search"
|
||||
:search-placeholder="searchPlaceholder"
|
||||
:empty-state="emptyState"
|
||||
:selected-values="selectedValue"
|
||||
@update:search-value="search = $event"
|
||||
@select="selectOption"
|
||||
/>
|
||||
|
||||
<p
|
||||
v-if="message"
|
||||
class="mt-2 mb-0 text-xs truncate transition-all duration-500 ease-in-out text-n-slate-11 dark:text-n-slate-11"
|
||||
class="mt-2 mb-0 text-xs truncate transition-all duration-500 ease-in-out"
|
||||
:class="{
|
||||
'text-n-ruby-9': hasError,
|
||||
'text-n-slate-11': !hasError,
|
||||
}"
|
||||
>
|
||||
{{ message }}
|
||||
</p>
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
const props = defineProps({
|
||||
open: {
|
||||
type: Boolean,
|
||||
required: true,
|
||||
},
|
||||
options: {
|
||||
type: Array,
|
||||
required: true,
|
||||
},
|
||||
searchValue: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
searchPlaceholder: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
emptyState: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
multiple: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
selectedValues: {
|
||||
type: [String, Number, Array],
|
||||
default: () => [],
|
||||
},
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:searchValue', 'select']);
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const searchInput = ref(null);
|
||||
|
||||
const isSelected = option => {
|
||||
if (Array.isArray(props.selectedValues)) {
|
||||
return props.selectedValues.includes(option.value);
|
||||
}
|
||||
return option.value === props.selectedValues;
|
||||
};
|
||||
|
||||
defineExpose({
|
||||
focus: () => searchInput.value?.focus(),
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-show="open"
|
||||
class="absolute z-50 w-full mt-1 transition-opacity duration-200 border rounded-md shadow-lg bg-n-solid-1 border-n-strong"
|
||||
>
|
||||
<div class="relative border-b border-n-strong">
|
||||
<span class="absolute i-lucide-search top-2.5 size-4 left-3" />
|
||||
<input
|
||||
ref="searchInput"
|
||||
:value="searchValue"
|
||||
type="search"
|
||||
:placeholder="searchPlaceholder || t('COMBOBOX.SEARCH_PLACEHOLDER')"
|
||||
class="w-full py-2 pl-10 pr-2 text-sm border-none rounded-t-md bg-n-solid-1 text-slate-900 dark:text-slate-50"
|
||||
@input="emit('update:searchValue', $event.target.value)"
|
||||
/>
|
||||
</div>
|
||||
<ul
|
||||
class="py-1 mb-0 overflow-auto max-h-60"
|
||||
role="listbox"
|
||||
:aria-multiselectable="multiple"
|
||||
>
|
||||
<li
|
||||
v-for="option in options"
|
||||
:key="option.value"
|
||||
class="flex items-center justify-between w-full gap-2 px-3 py-2 text-sm transition-colors duration-150 cursor-pointer hover:bg-n-alpha-2"
|
||||
:class="{
|
||||
'bg-n-alpha-2': isSelected(option),
|
||||
}"
|
||||
role="option"
|
||||
:aria-selected="isSelected(option)"
|
||||
@click="emit('select', option)"
|
||||
>
|
||||
<span
|
||||
:class="{
|
||||
'font-medium': isSelected(option),
|
||||
}"
|
||||
class="text-n-slate-12"
|
||||
>
|
||||
{{ option.label }}
|
||||
</span>
|
||||
<span
|
||||
v-if="isSelected(option)"
|
||||
class="flex-shrink-0 i-lucide-check size-4 text-n-slate-11"
|
||||
/>
|
||||
</li>
|
||||
<li
|
||||
v-if="options.length === 0"
|
||||
class="px-3 py-2 text-sm text-slate-600 dark:text-slate-300"
|
||||
>
|
||||
{{ emptyState || t('COMBOBOX.EMPTY_STATE') }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,183 @@
|
||||
<script setup>
|
||||
import { ref, computed, watch, nextTick } from 'vue';
|
||||
import { OnClickOutside } from '@vueuse/components';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
import ComboBoxDropdown from 'dashboard/components-next/combobox/ComboBoxDropdown.vue';
|
||||
|
||||
const props = defineProps({
|
||||
options: {
|
||||
type: Array,
|
||||
required: true,
|
||||
validator: value =>
|
||||
value.every(option => 'value' in option && 'label' in option),
|
||||
},
|
||||
placeholder: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
modelValue: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
searchPlaceholder: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
emptyState: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
message: {
|
||||
type: String,
|
||||
default: '',
|
||||
},
|
||||
hasError: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:modelValue']);
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const selectedValues = ref(props.modelValue);
|
||||
const open = ref(false);
|
||||
const search = ref('');
|
||||
const dropdownRef = ref(null);
|
||||
const comboboxRef = ref(null);
|
||||
|
||||
const filteredOptions = computed(() => {
|
||||
const searchTerm = search.value.toLowerCase();
|
||||
return props.options.filter(option =>
|
||||
option.label?.toLowerCase().includes(searchTerm)
|
||||
);
|
||||
});
|
||||
|
||||
const selectPlaceholder = computed(() => {
|
||||
return props.placeholder || t('COMBOBOX.PLACEHOLDER');
|
||||
});
|
||||
|
||||
const selectedTags = computed(() => {
|
||||
return selectedValues.value.map(value => {
|
||||
const option = props.options.find(opt => opt.value === value);
|
||||
return option || { value, label: value };
|
||||
});
|
||||
});
|
||||
|
||||
const toggleOption = option => {
|
||||
const index = selectedValues.value.indexOf(option.value);
|
||||
if (index === -1) {
|
||||
selectedValues.value.push(option.value);
|
||||
} else {
|
||||
selectedValues.value.splice(index, 1);
|
||||
}
|
||||
emit('update:modelValue', selectedValues.value);
|
||||
};
|
||||
|
||||
const removeTag = value => {
|
||||
const index = selectedValues.value.indexOf(value);
|
||||
if (index !== -1) {
|
||||
selectedValues.value.splice(index, 1);
|
||||
emit('update:modelValue', selectedValues.value);
|
||||
}
|
||||
};
|
||||
|
||||
const toggleDropdown = () => {
|
||||
if (props.disabled) return;
|
||||
open.value = !open.value;
|
||||
if (open.value) {
|
||||
search.value = '';
|
||||
nextTick(() => dropdownRef.value?.focus());
|
||||
}
|
||||
};
|
||||
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
newValue => {
|
||||
selectedValues.value = newValue;
|
||||
}
|
||||
);
|
||||
|
||||
defineExpose({
|
||||
toggleDropdown,
|
||||
open,
|
||||
disabled: props.disabled,
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
ref="comboboxRef"
|
||||
class="relative w-full min-w-0"
|
||||
:class="{
|
||||
'cursor-not-allowed': disabled,
|
||||
'group/combobox': !disabled,
|
||||
}"
|
||||
@click.prevent
|
||||
>
|
||||
<OnClickOutside @trigger="open = false">
|
||||
<div
|
||||
class="flex flex-wrap w-full gap-2 px-3 py-2.5 border rounded-lg cursor-pointer bg-n-alpha-black2 min-h-[42px] transition-all duration-500 ease-in-out"
|
||||
:class="{
|
||||
'border-n-ruby-8': hasError,
|
||||
'border-n-weak dark:border-n-weak hover:border-n-slate-6 dark:hover:border-n-slate-6':
|
||||
!hasError && !open,
|
||||
'border-n-brand': open,
|
||||
'cursor-not-allowed pointer-events-none opacity-50': disabled,
|
||||
}"
|
||||
@click="toggleDropdown"
|
||||
>
|
||||
<div
|
||||
v-for="tag in selectedTags"
|
||||
:key="tag.value"
|
||||
class="flex items-center justify-center max-w-full gap-1 px-2 py-0.5 rounded-lg bg-n-alpha-black1"
|
||||
@click.stop
|
||||
>
|
||||
<span class="flex-grow min-w-0 text-sm truncate text-n-slate-12">
|
||||
{{ tag.label }}
|
||||
</span>
|
||||
<span
|
||||
class="flex-shrink-0 cursor-pointer i-lucide-x size-3 text-n-slate-11"
|
||||
@click="removeTag(tag.value)"
|
||||
/>
|
||||
</div>
|
||||
<span
|
||||
v-if="selectedTags.length === 0"
|
||||
class="flex items-center text-sm text-n-slate-11"
|
||||
>
|
||||
{{ selectPlaceholder }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<ComboBoxDropdown
|
||||
ref="dropdownRef"
|
||||
:open="open"
|
||||
:options="filteredOptions"
|
||||
:search-value="search"
|
||||
:search-placeholder="searchPlaceholder"
|
||||
:empty-state="emptyState"
|
||||
multiple
|
||||
:selected-values="selectedValues"
|
||||
@update:search-value="search = $event"
|
||||
@select="toggleOption"
|
||||
/>
|
||||
|
||||
<p
|
||||
v-if="message"
|
||||
class="mt-2 mb-0 text-xs truncate transition-all duration-500 ease-in-out"
|
||||
:class="{
|
||||
'text-n-ruby-9': hasError,
|
||||
'text-n-slate-11': !hasError,
|
||||
}"
|
||||
>
|
||||
{{ message }}
|
||||
</p>
|
||||
</OnClickOutside>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,55 @@
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import TagMultiSelectComboBox from './TagMultiSelectComboBox.vue';
|
||||
|
||||
const options = [
|
||||
{ value: 1, label: 'Option 1' },
|
||||
{ value: 2, label: 'Option 2' },
|
||||
{ value: 3, label: 'Option 3' },
|
||||
{ value: 4, label: 'Option 4' },
|
||||
{ value: 5, label: 'Option 5' },
|
||||
];
|
||||
const selectedValues = ref([]);
|
||||
|
||||
const preselectedValues = ref([1, 2]);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Story
|
||||
title="Components/TagMultiSelectComboBox"
|
||||
:layout="{ type: 'grid', width: '300px' }"
|
||||
>
|
||||
<Variant title="Default">
|
||||
<div class="w-full p-4 bg-white h-80 dark:bg-slate-900">
|
||||
<TagMultiSelectComboBox v-model="selectedValues" :options="options" />
|
||||
<p class="mt-2">Selected values: {{ selectedValues }}</p>
|
||||
</div>
|
||||
</Variant>
|
||||
|
||||
<Variant title="With Preselected Values">
|
||||
<div class="w-full p-4 bg-white h-80 dark:bg-slate-900">
|
||||
<TagMultiSelectComboBox
|
||||
v-model="preselectedValues"
|
||||
:options="options"
|
||||
placeholder="Select multiple options"
|
||||
/>
|
||||
</div>
|
||||
</Variant>
|
||||
|
||||
<Variant title="Disabled">
|
||||
<div class="w-full p-4 bg-white h-80 dark:bg-slate-900">
|
||||
<TagMultiSelectComboBox :options="options" disabled />
|
||||
</div>
|
||||
</Variant>
|
||||
|
||||
<Variant title="With Error">
|
||||
<div class="w-full p-4 bg-white h-80 dark:bg-slate-900">
|
||||
<TagMultiSelectComboBox
|
||||
:options="options"
|
||||
has-error
|
||||
message="This field is required"
|
||||
/>
|
||||
</div>
|
||||
</Variant>
|
||||
</Story>
|
||||
</template>
|
||||
Reference in New Issue
Block a user