@appscode/design-system 2.2.21 → 2.2.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appscode/design-system",
3
- "version": "2.2.21",
3
+ "version": "2.2.22",
4
4
  "description": "A design system for Appscode websites and dashboards made using Bulma",
5
5
  "main": "main.scss",
6
6
  "scripts": {
@@ -0,0 +1,135 @@
1
+ <template>
2
+ <div
3
+ ref="multiselectDivId"
4
+ class="multi-select-wrapper"
5
+ :class="{
6
+ multiselectCustomClass,
7
+ 'has-refresh-button': hasRefreshBtn,
8
+ 'is-disable': disabled || isLoaderActive,
9
+ 'has-clear-button': allowEmpty && model,
10
+ }"
11
+ data-testid="cluster-status-select-header"
12
+ >
13
+ <label
14
+ v-if="label.length"
15
+ :class="{ 'show-label': isLabelHoisted }"
16
+ data-testid="ac-multiselect-label"
17
+ @click.prevent="onClickLabel"
18
+ >
19
+ {{ isLabelHoisted ? label : `Select ${label}` }}
20
+ <span v-if="showStar" class="is-required has-text-danger"> * </span>
21
+ </label>
22
+ <button v-if="allowEmpty && model" class="button ac-button is-clear is-transparent" @click.prevent="model = ''">
23
+ <i class="fa fa-times" />
24
+ </button>
25
+ <button
26
+ v-if="hasRefreshBtn"
27
+ class="button ac-button is-primary is-refresh is-transparent"
28
+ :class="{ spin: isLoaderActive }"
29
+ @click.prevent="$emit('refresh-btn-click')"
30
+ >
31
+ <i class="fa fa-refresh" />
32
+ </button>
33
+ <multiselect
34
+ ref="multiselectElement"
35
+ v-model="model"
36
+ :track-by="trackBy"
37
+ :label="showBy"
38
+ :class="multiselectCustomClass"
39
+ :options="options"
40
+ :placeholder="placeholderText"
41
+ :disabled="disabled || isLoaderActive"
42
+ :allow-empty="false"
43
+ :show-labels="false"
44
+ :close-on-select="true"
45
+ data-testid="simple-select-box"
46
+ @open="openDropDown"
47
+ @close="closeDropDown"
48
+ @select="onSelect"
49
+ @remove="onRemove"
50
+ >
51
+ <template #noResult>
52
+ <span> {{ noResultText }} </span>
53
+ </template>
54
+ </multiselect>
55
+ <p v-show="errorMsg" class="is-danger">
56
+ {{ errorMsg }}
57
+ </p>
58
+ </div>
59
+ </template>
60
+ <script setup lang="ts">
61
+ import { computed, ref } from "vue";
62
+ import Multiselect from "vue-multiselect";
63
+
64
+ interface Props {
65
+ errorMsg: string;
66
+ placeholderText: string;
67
+ disabled: boolean;
68
+ label: string;
69
+ allowEmpty: boolean;
70
+ options: unknown[];
71
+ trackBy: string;
72
+ showBy: string;
73
+ closeOnSelect: boolean;
74
+ hasRefreshBtn: boolean;
75
+ isLoaderActive: boolean;
76
+ noResultText: string;
77
+ showStar: boolean;
78
+ wrapperDivCustomClass: string;
79
+ multiselectCustomClass: string;
80
+ }
81
+
82
+ const props = withDefaults(defineProps<Props>(), {
83
+ errorMsg: "",
84
+ placeholderText: "",
85
+ disabled: false,
86
+ label: "",
87
+ allowEmpty: false,
88
+ options: () => [],
89
+ wrapperDivCustomClass: "",
90
+ multiselectCustomClass: "",
91
+ trackBy: "",
92
+ showBy: "",
93
+ closeOnSelect: false,
94
+ hasRefreshBtn: false,
95
+ isLoaderActive: false,
96
+ noResultText: "",
97
+ showStar: false,
98
+ });
99
+
100
+ const emit = defineEmits(["select", "remove", "refresh-btn-click"]);
101
+
102
+ const multiselectElement = ref<HTMLInputElement | null>(null);
103
+ const multiselectDivId = ref<HTMLInputElement | null>(null);
104
+
105
+ const model = defineModel<unknown>({ required: true });
106
+ const isDropdownOpen = ref(false);
107
+
108
+ const isLabelHoisted = computed(() => {
109
+ return props.label && ((model.value && model.value !== "") || isDropdownOpen.value);
110
+ });
111
+
112
+ const onClickLabel = () => {
113
+ if (multiselectElement.value) {
114
+ multiselectDivId.value?.focus();
115
+ }
116
+ };
117
+
118
+ const openDropDown = () => {
119
+ isDropdownOpen.value = true;
120
+ if (multiselectDivId.value) {
121
+ multiselectDivId.value.style.zIndex = "799";
122
+ }
123
+ };
124
+
125
+ const closeDropDown = () => {
126
+ isDropdownOpen.value = false;
127
+ if (multiselectDivId.value) {
128
+ multiselectDivId.value.style.zIndex = "";
129
+ }
130
+ };
131
+
132
+ const onRemove = (removedOption: unknown, id: string) => emit("remove", removedOption, id);
133
+
134
+ const onSelect = (selectedOption: unknown, id: string) => emit("select", selectedOption, id);
135
+ </script>