@itfin/components 1.0.73 → 1.0.77
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 +1 -1
- package/src/components/datepicker/DatePicker.vue +20 -2
- package/src/components/form/Label.vue +6 -4
- package/src/components/modal/Modal.vue +1 -1
- package/src/components/overlay/SensitiveOverlay.vue +1 -0
- package/src/components/select/AirSelect.vue +350 -0
- package/src/components/select/Dropdown.vue +275 -0
- package/src/components/select/Select.vue +3 -1
- package/src/components/select/index.stories.js +28 -0
- package/src/components/select/useOutsideClick.js +32 -0
- package/src/components/tabs/TabContent.vue +1 -1
- package/src/components/text-field/Textarea.vue +1 -1
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="itf-datepicker" :class="{'with-addon addon-start': prependIcon}">
|
|
2
|
+
<div class="itf-datepicker input-group" :class="{'with-addon addon-start': prependIcon, 'with-addon addon-end': clearable}">
|
|
3
3
|
<div class="addon" v-if="prependIcon">
|
|
4
4
|
<slot name="addon">
|
|
5
5
|
<itf-icon :name="prependIcon" />
|
|
@@ -22,6 +22,18 @@
|
|
|
22
22
|
:lazy="!focused"
|
|
23
23
|
:placeholder="placeholder"
|
|
24
24
|
/>
|
|
25
|
+
|
|
26
|
+
<div class="addon-end" v-if="clearable && value">
|
|
27
|
+
<slot name="clear">
|
|
28
|
+
<itf-button
|
|
29
|
+
icon
|
|
30
|
+
small
|
|
31
|
+
@click="$emit('input', '')"
|
|
32
|
+
>
|
|
33
|
+
<itf-icon name="close" />
|
|
34
|
+
</itf-button>
|
|
35
|
+
</slot>
|
|
36
|
+
</div>
|
|
25
37
|
<div style="display: none">
|
|
26
38
|
<div ref="dropdown" class="itf-datepicker__dropdown">
|
|
27
39
|
<itf-date-picker-inline
|
|
@@ -42,10 +54,13 @@
|
|
|
42
54
|
@import '../../assets/scss/input-addon';
|
|
43
55
|
|
|
44
56
|
.itf-datepicker {
|
|
45
|
-
.addon-end {
|
|
57
|
+
&.with-addon .addon-end {
|
|
46
58
|
pointer-events: all;
|
|
47
59
|
padding-right: 0.25rem;
|
|
48
60
|
}
|
|
61
|
+
.form-control {
|
|
62
|
+
border-radius: $input-border-radius !important;
|
|
63
|
+
}
|
|
49
64
|
|
|
50
65
|
&__dropdown {
|
|
51
66
|
width: max-content;
|
|
@@ -75,6 +90,7 @@ import { DateTime } from 'luxon';
|
|
|
75
90
|
import { debounce } from '../../helpers/debounce';
|
|
76
91
|
import tippy from 'tippy.js';
|
|
77
92
|
import itfIcon from '../icon/Icon.vue';
|
|
93
|
+
import itfButton from '../button/Button.vue';
|
|
78
94
|
import itfDatePickerInline from './DatePickerInline.vue';
|
|
79
95
|
import ITFSettings from '../../ITFSettings';
|
|
80
96
|
|
|
@@ -82,6 +98,7 @@ export default @Component({
|
|
|
82
98
|
name: 'itfDatePicker',
|
|
83
99
|
components: {
|
|
84
100
|
itfIcon,
|
|
101
|
+
itfButton,
|
|
85
102
|
itfDatePickerInline,
|
|
86
103
|
IMaskComponent,
|
|
87
104
|
},
|
|
@@ -97,6 +114,7 @@ class itfDatePicker extends Vue {
|
|
|
97
114
|
@Prop({ type: Boolean, default: false }) onlyCalendar;
|
|
98
115
|
@Prop({ type: String, default: '' }) placeholder;
|
|
99
116
|
@Prop({ type: String, default: '' }) prependIcon;
|
|
117
|
+
@Prop(Boolean) clearable;
|
|
100
118
|
|
|
101
119
|
focused = false;
|
|
102
120
|
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
|
|
3
3
|
<div class="itf-label" :class="{'has-validation': hasState, 'no-details': hideDetails}">
|
|
4
|
-
<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
<slot name="label" v-bind="{ required, label }">
|
|
5
|
+
<label class="itf-label__label form-label" v-if="label">
|
|
6
|
+
{{label}}
|
|
7
|
+
<span class="star" v-if="required">*</span>
|
|
8
|
+
</label>
|
|
9
|
+
</slot>
|
|
8
10
|
|
|
9
11
|
<div :class="{'is-invalid': hasState && hasError, 'is-valid': hasState && hasSuccess}">
|
|
10
12
|
<slot :validate="doValidation"></slot>
|
|
@@ -124,7 +124,7 @@ class itfModal extends Vue {
|
|
|
124
124
|
document.body.appendChild(this.$el); // should append only to body
|
|
125
125
|
}
|
|
126
126
|
const { default: Modal } = await import('bootstrap/js/src/modal.js');
|
|
127
|
-
this.modalEl = new Modal(this.$el);
|
|
127
|
+
this.modalEl = new Modal(this.$el, { backdrop: 'static' });
|
|
128
128
|
this.onVisibleChanged(this.value);
|
|
129
129
|
this.bindEvents();
|
|
130
130
|
}
|
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="select"
|
|
4
|
+
ref="selectRef"
|
|
5
|
+
:class="[variant]"
|
|
6
|
+
@keydown="handleFocusedSelectKeydown"
|
|
7
|
+
>
|
|
8
|
+
<div
|
|
9
|
+
class="valueContainer text-textDarkest"
|
|
10
|
+
:data-testid="name ? `select:${name}` : 'select'"
|
|
11
|
+
@click="activateDropdown"
|
|
12
|
+
>
|
|
13
|
+
<div class="placeholder" v-if="isValueEmpty">{{ placeholder }}</div>
|
|
14
|
+
|
|
15
|
+
<slot
|
|
16
|
+
v-if="!isValueEmpty && !multiple && customRender"
|
|
17
|
+
v-bind="getOption(localValue)"
|
|
18
|
+
/>
|
|
19
|
+
<template v-else>
|
|
20
|
+
{{ getOptionLabel(localValue) }}
|
|
21
|
+
</template>
|
|
22
|
+
|
|
23
|
+
<div v-if="!isValueEmpty && multiple" class="valueMulti text-textDarkest">
|
|
24
|
+
<div
|
|
25
|
+
class="my-1 mx-1 flex items-center"
|
|
26
|
+
v-for="optionValue in localValue"
|
|
27
|
+
:key="optionValue"
|
|
28
|
+
>
|
|
29
|
+
<slot
|
|
30
|
+
v-if="customRender"
|
|
31
|
+
v-bind="{
|
|
32
|
+
...getOption(optionValue),
|
|
33
|
+
optionValue,
|
|
34
|
+
remove: removeOptionValue
|
|
35
|
+
}"
|
|
36
|
+
/>
|
|
37
|
+
<div v-else class="valueMultiItem text-textDarkest">
|
|
38
|
+
<div class="valueMultiItemLabel">
|
|
39
|
+
{{ getOptionLabel(optionValue) }}
|
|
40
|
+
</div>
|
|
41
|
+
<div
|
|
42
|
+
@click="removeOptionValue(optionValue)"
|
|
43
|
+
class="valueMultiItemClose"
|
|
44
|
+
>
|
|
45
|
+
<svg class="icon" viewBox="0 0 24 24">
|
|
46
|
+
<path
|
|
47
|
+
d="M16.192 6.344L11.949 10.586 7.707 6.344 6.293 7.758 10.535 12 6.293 16.242 7.707 17.656 11.949 13.414 16.192 17.656 17.606 16.242 13.364 12 17.606 7.758z"
|
|
48
|
+
/>
|
|
49
|
+
</svg>
|
|
50
|
+
</div>
|
|
51
|
+
</div>
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<div class="addMore m-1">
|
|
55
|
+
<svg
|
|
56
|
+
class="icon"
|
|
57
|
+
viewBox="0 0 24 24"
|
|
58
|
+
focusable="false"
|
|
59
|
+
role="presentation"
|
|
60
|
+
>
|
|
61
|
+
<path
|
|
62
|
+
d="M13 11V3.993A.997.997 0 0 0 12 3c-.556 0-1 .445-1 .993V11H3.993A.997.997 0 0 0 3 12c0 .557.445 1 .993 1H11v7.007c0 .548.448.993 1 .993.556 0 1-.445 1-.993V13h7.007A.997.997 0 0 0 21 12c0-.556-.445-1-.993-1H13z"
|
|
63
|
+
fill="currentColor"
|
|
64
|
+
fill-rule="evenodd"
|
|
65
|
+
></path>
|
|
66
|
+
</svg>
|
|
67
|
+
<div class="font-medium">Add more</div>
|
|
68
|
+
</div>
|
|
69
|
+
</div>
|
|
70
|
+
|
|
71
|
+
<j-icon
|
|
72
|
+
v-if="(!multiple || isValueEmpty) && variant !== 'empty'"
|
|
73
|
+
class="ml-auto mr-1"
|
|
74
|
+
name="chevron-down"
|
|
75
|
+
></j-icon>
|
|
76
|
+
</div>
|
|
77
|
+
|
|
78
|
+
<Dropdown
|
|
79
|
+
v-if="isDropdownOpen"
|
|
80
|
+
ref="dropdownRef"
|
|
81
|
+
isValueEmpty
|
|
82
|
+
:dropdownWidth="dropdownWidth"
|
|
83
|
+
:searchable="searchable"
|
|
84
|
+
:searchValue="searchValue"
|
|
85
|
+
:value="localValue"
|
|
86
|
+
:deactivateDropdown="deactivateDropdown"
|
|
87
|
+
:options="options"
|
|
88
|
+
:multiple="multiple"
|
|
89
|
+
:withClearValue="withClearValue"
|
|
90
|
+
@change="handleChange"
|
|
91
|
+
@searchValueChange="handleSearchValueChange"
|
|
92
|
+
>
|
|
93
|
+
<template v-slot:option="props">
|
|
94
|
+
<slot v-if="customRenderOption" name="option" v-bind="props" />
|
|
95
|
+
<slot v-else v-bind="props" />
|
|
96
|
+
</template>
|
|
97
|
+
</Dropdown>
|
|
98
|
+
</div>
|
|
99
|
+
</template>
|
|
100
|
+
|
|
101
|
+
<script>
|
|
102
|
+
import { Component, Model, Prop, Ref } from 'vue-property-decorator';
|
|
103
|
+
import Vue from 'vue';
|
|
104
|
+
import Dropdown from './Dropdown.vue';
|
|
105
|
+
import { useOutsideClick } from './useOutsideClick';
|
|
106
|
+
|
|
107
|
+
const { bind, unbind } = useOutsideClick();
|
|
108
|
+
|
|
109
|
+
export default @Component({
|
|
110
|
+
name: 'itfAirSelect',
|
|
111
|
+
components: { Dropdown },
|
|
112
|
+
})
|
|
113
|
+
class itfAirSelect extends Vue {
|
|
114
|
+
@Model('input', { type: [Array, String, Number], default: undefined }) value;
|
|
115
|
+
|
|
116
|
+
@Prop({ type: Number, default: undefined }) dropdownWidth;
|
|
117
|
+
|
|
118
|
+
@Prop({ type: String, default: 'normal' }) variant;
|
|
119
|
+
|
|
120
|
+
@Prop({ type: String, default: undefined }) name;
|
|
121
|
+
|
|
122
|
+
@Prop({ type: Boolean, default: false }) searchable;
|
|
123
|
+
|
|
124
|
+
@Prop({ type: [String, Array, Number], default: undefined }) defaultValue;
|
|
125
|
+
|
|
126
|
+
@Prop({ type: String, default: 'Select' }) placeholder;
|
|
127
|
+
|
|
128
|
+
@Prop({ type: Boolean, default: false }) invalid;
|
|
129
|
+
|
|
130
|
+
@Prop({ type: Array, required: true }) options;
|
|
131
|
+
|
|
132
|
+
@Prop({ type: Boolean, default: false }) multiple;
|
|
133
|
+
|
|
134
|
+
@Prop({ type: Boolean, default: false }) withClearValue;
|
|
135
|
+
|
|
136
|
+
@Ref('selectRef') selectRef;
|
|
137
|
+
|
|
138
|
+
@Ref('dropdownRef') dropdownRef;
|
|
139
|
+
|
|
140
|
+
isDropdownOpen = false;
|
|
141
|
+
|
|
142
|
+
searchValue = '';
|
|
143
|
+
|
|
144
|
+
get customRender() {
|
|
145
|
+
return !!this.$slots.default;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
get customRenderOption() {
|
|
149
|
+
return !!this.$slots.option;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
data() {
|
|
153
|
+
return {
|
|
154
|
+
stateValue: this.defaultValue || (this.multiple ? [] : null),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
getOption(optionValue) {
|
|
159
|
+
return this.options.find((option) => option.value === optionValue);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
getOptionLabel(optionValue) {
|
|
163
|
+
return (this.getOption(optionValue) || { label: '' }).label;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
get isControlled() {
|
|
167
|
+
return this.value !== undefined;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
get localValue() {
|
|
171
|
+
return this.isControlled ? this.value : this.stateValue;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
preserveValueType(newValue) {
|
|
175
|
+
const areOptionValuesNumbers = this.options.some(
|
|
176
|
+
(option) => typeof option.value === 'number',
|
|
177
|
+
);
|
|
178
|
+
if (areOptionValuesNumbers) {
|
|
179
|
+
if (this.multiple) {
|
|
180
|
+
return (newValue).map(Number);
|
|
181
|
+
}
|
|
182
|
+
if (newValue) {
|
|
183
|
+
return Number(newValue);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return newValue;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
handleChange(newValue) {
|
|
190
|
+
if (!this.isControlled) {
|
|
191
|
+
this.stateValue = this.preserveValueType(newValue);
|
|
192
|
+
}
|
|
193
|
+
this.$emit('input', this.preserveValueType(newValue));
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
removeOptionValue(optionValue) {
|
|
197
|
+
this.handleChange(this.localValue.filter((val) => val !== optionValue));
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
get isValueEmpty() {
|
|
201
|
+
return this.multiple ? !this.localValue.length : !this.getOption(this.localValue);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
handleFocusedSelectKeydown(event) {
|
|
205
|
+
if (this.isDropdownOpen) return;
|
|
206
|
+
if (event.keyCode === 13) {
|
|
207
|
+
event.preventDefault();
|
|
208
|
+
}
|
|
209
|
+
if (event.keyCode !== 27 && event.keyCode !== 9 && !event.shiftKey) {
|
|
210
|
+
this.isDropdownOpen = true;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
async deactivateDropdown() {
|
|
215
|
+
this.isDropdownOpen = false;
|
|
216
|
+
this.searchValue = '';
|
|
217
|
+
await this.$nextTick();
|
|
218
|
+
this.selectRef && this.selectRef.focus();
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async activateDropdown() {
|
|
222
|
+
this.isDropdownOpen = true;
|
|
223
|
+
await this.$nextTick();
|
|
224
|
+
this.selectRef && this.selectRef.blur();
|
|
225
|
+
// eslint-disable-next-line
|
|
226
|
+
this.searchable && this.dropdownRef && this.dropdownRef.$refs.inputRef.focus()
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
handleSearchValueChange(newValue) {
|
|
230
|
+
this.searchValue = newValue;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
mounted () {
|
|
234
|
+
bind(this.selectRef, this.deactivateDropdown);
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
beforeDestroy () {
|
|
238
|
+
unbind();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
</script>
|
|
242
|
+
|
|
243
|
+
<style lang="scss" scoped>
|
|
244
|
+
.select {
|
|
245
|
+
position: relative;
|
|
246
|
+
border-radius: 4px;
|
|
247
|
+
cursor: pointer;
|
|
248
|
+
font-size: 14px;
|
|
249
|
+
transition: background 0.1s;
|
|
250
|
+
&:focus {
|
|
251
|
+
outline: none;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
.valueContainer {
|
|
255
|
+
display: flex;
|
|
256
|
+
align-items: center;
|
|
257
|
+
width: 100%;
|
|
258
|
+
min-height: 32px;
|
|
259
|
+
}
|
|
260
|
+
.placeholder {
|
|
261
|
+
color: #8993a4;
|
|
262
|
+
}
|
|
263
|
+
.valueMulti {
|
|
264
|
+
display: flex;
|
|
265
|
+
align-items: center;
|
|
266
|
+
flex-wrap: wrap;
|
|
267
|
+
// padding-top: 5px;
|
|
268
|
+
}
|
|
269
|
+
.valueMultiItem {
|
|
270
|
+
height: 22px;
|
|
271
|
+
overflow: hidden;
|
|
272
|
+
border-radius: 3px;
|
|
273
|
+
display: flex;
|
|
274
|
+
align-items: center;
|
|
275
|
+
user-select: none;
|
|
276
|
+
background: #f0f0f0;
|
|
277
|
+
font-size: 14px;
|
|
278
|
+
.valueMultiItemLabel {
|
|
279
|
+
flex: auto;
|
|
280
|
+
padding: 0 4px;
|
|
281
|
+
height: 100%;
|
|
282
|
+
display: flex;
|
|
283
|
+
align-items: center;
|
|
284
|
+
border-right: 1px solid #ddd;
|
|
285
|
+
}
|
|
286
|
+
.valueMultiItemClose {
|
|
287
|
+
border-left: none;
|
|
288
|
+
overflow: hidden;
|
|
289
|
+
padding: 0 2px;
|
|
290
|
+
height: 100%;
|
|
291
|
+
display: flex;
|
|
292
|
+
align-items: center;
|
|
293
|
+
justify-content: center;
|
|
294
|
+
&:hover {
|
|
295
|
+
background: #ff4757;
|
|
296
|
+
color: white;
|
|
297
|
+
}
|
|
298
|
+
.icon {
|
|
299
|
+
width: 18px;
|
|
300
|
+
height: 18px;
|
|
301
|
+
fill: currentColor;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
.addMore {
|
|
306
|
+
font-size: 12.5px;
|
|
307
|
+
cursor: pointer;
|
|
308
|
+
display: flex;
|
|
309
|
+
align-items: center;
|
|
310
|
+
color: #0052cc;
|
|
311
|
+
&:hover,
|
|
312
|
+
&:visited,
|
|
313
|
+
&:active {
|
|
314
|
+
color: #0052cc;
|
|
315
|
+
}
|
|
316
|
+
&:hover {
|
|
317
|
+
text-decoration: underline;
|
|
318
|
+
}
|
|
319
|
+
.icon {
|
|
320
|
+
width: 16px;
|
|
321
|
+
height: 16px;
|
|
322
|
+
fill: currentColor;
|
|
323
|
+
margin-right: 2px;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
.select.normal {
|
|
327
|
+
width: 100%;
|
|
328
|
+
padding-left: 0.5rem;
|
|
329
|
+
padding-right: 0.5rem;
|
|
330
|
+
border-width: 1px;
|
|
331
|
+
border-color: #dfe1e6;
|
|
332
|
+
background-color: #f4f5f7;
|
|
333
|
+
position: relative;
|
|
334
|
+
border-radius: 4px;
|
|
335
|
+
cursor: pointer;
|
|
336
|
+
font-size: 14px;
|
|
337
|
+
-webkit-transition: background .1s;
|
|
338
|
+
transition: background .1s;
|
|
339
|
+
}
|
|
340
|
+
.select.normal:hover {
|
|
341
|
+
@apply bg-backgroundLight;
|
|
342
|
+
}
|
|
343
|
+
.select.normal:focus {
|
|
344
|
+
@apply border border-borderInputFocus bg-white text-borderInputFocus;
|
|
345
|
+
box-shadow: 0 0 0 1px currentColor;
|
|
346
|
+
}
|
|
347
|
+
.select.empty {
|
|
348
|
+
display: inline-block;
|
|
349
|
+
}
|
|
350
|
+
</style>
|
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="dropdown" :style="{ width: `${dropdownWidth}px` }">
|
|
3
|
+
<input
|
|
4
|
+
v-if="searchable"
|
|
5
|
+
class="dropdownInput"
|
|
6
|
+
type="text"
|
|
7
|
+
ref="inputRef"
|
|
8
|
+
placeholder="Search"
|
|
9
|
+
@input="handleSearchValueChange"
|
|
10
|
+
@keydown="handleInputKeyDown"
|
|
11
|
+
/>
|
|
12
|
+
|
|
13
|
+
<div class="options" ref="optionsRef">
|
|
14
|
+
<div
|
|
15
|
+
class="option text-textDarkest"
|
|
16
|
+
v-for="option in filteredOptions"
|
|
17
|
+
:key="option.value"
|
|
18
|
+
:data-select-option-value="option.value"
|
|
19
|
+
:data-testid="`select-option:${option.label}`"
|
|
20
|
+
@mouseenter="handleOptionMouseEnter"
|
|
21
|
+
@click="selectOptionValue(option.value)"
|
|
22
|
+
>
|
|
23
|
+
<slot name="option" v-bind="option">{{ option.label }}</slot>
|
|
24
|
+
</div>
|
|
25
|
+
|
|
26
|
+
<div
|
|
27
|
+
v-if="isOptionCreatable"
|
|
28
|
+
class="option text-textDarkest"
|
|
29
|
+
:data-create-option-label="{ searchValue }"
|
|
30
|
+
@mouseenter="handleOptionMouseEnter"
|
|
31
|
+
@click="createOption(searchValue)"
|
|
32
|
+
>
|
|
33
|
+
{{
|
|
34
|
+
isCreatingOption
|
|
35
|
+
? `Creating "${searchValue}"...`
|
|
36
|
+
: `Create
|
|
37
|
+
"${searchValue}"`
|
|
38
|
+
}}
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
|
|
42
|
+
<div v-if="filteredOptions.length === 0" class="optionsNoResults">
|
|
43
|
+
No results
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
</template>
|
|
47
|
+
|
|
48
|
+
<script>
|
|
49
|
+
import Vue from 'vue';
|
|
50
|
+
import { Component, Prop, Ref } from 'vue-property-decorator';
|
|
51
|
+
|
|
52
|
+
const activeOptionClass = 'select-option-is-active';
|
|
53
|
+
|
|
54
|
+
export default @Component({
|
|
55
|
+
name: 'itfDropdown',
|
|
56
|
+
components: {}
|
|
57
|
+
})
|
|
58
|
+
class itfSegmentedControl extends Vue {
|
|
59
|
+
@Prop({ type: Number, default: undefined }) dropdownWidth;
|
|
60
|
+
@Prop({ type: [Array, String, Number], default: undefined }) value;
|
|
61
|
+
@Prop({ type: Boolean }) isValueEmpty;
|
|
62
|
+
@Prop({ type: Boolean }) searchable;
|
|
63
|
+
@Prop({ type: String, default: '' }) searchValue;
|
|
64
|
+
@Prop({ type: Function, required: true }) deactivateDropdown;
|
|
65
|
+
@Prop({ type: Array, required: true }) options;
|
|
66
|
+
@Prop({ type: Function, default: undefined }) onCreate;
|
|
67
|
+
@Prop({ type: Boolean }) multiple;
|
|
68
|
+
@Prop({ type: Boolean }) withClearValue;
|
|
69
|
+
|
|
70
|
+
@Ref('optionsRef') optionsRef;
|
|
71
|
+
@Ref('inputRef') inputRef;
|
|
72
|
+
|
|
73
|
+
isCreatingOption = false;
|
|
74
|
+
|
|
75
|
+
get optionsFilteredBySearchValue() {
|
|
76
|
+
return this.options.filter((option) => option.label
|
|
77
|
+
.toString()
|
|
78
|
+
.toLowerCase()
|
|
79
|
+
.includes(this.searchValue.toLowerCase()));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
get filteredOptions() {
|
|
83
|
+
return this.multiple
|
|
84
|
+
? this.optionsFilteredBySearchValue.filter(
|
|
85
|
+
(option) => !(this.value).includes(option.value),
|
|
86
|
+
)
|
|
87
|
+
: this.optionsFilteredBySearchValue.filter(
|
|
88
|
+
(option) => this.value !== option.value,
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
get isOptionCreatable() {
|
|
93
|
+
return this.onCreate
|
|
94
|
+
&& this.searchValue
|
|
95
|
+
&& !this.options.map((option) => option.label).includes(this.searchValue);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
handleSearchValueChange(event) {
|
|
99
|
+
this.$emit('searchValueChange', (event.target).value);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async getActiveOptionNode() {
|
|
103
|
+
await this.$nextTick();
|
|
104
|
+
return this.optionsRef
|
|
105
|
+
? this.optionsRef.querySelector(`.${activeOptionClass}`)
|
|
106
|
+
: null;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
selectOptionValue (optionValue) {
|
|
110
|
+
if (this.multiple) {
|
|
111
|
+
this.$emit('change', [
|
|
112
|
+
...new Set([...(this.value), optionValue]),
|
|
113
|
+
]);
|
|
114
|
+
} else {
|
|
115
|
+
this.deactivateDropdown();
|
|
116
|
+
this.$emit('change', optionValue);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
createOption (newOptionLabel) {
|
|
121
|
+
this.isCreatingOption = true;
|
|
122
|
+
this.onCreate(
|
|
123
|
+
newOptionLabel,
|
|
124
|
+
(createdOptionValue) => {
|
|
125
|
+
this.isCreatingOption = false;
|
|
126
|
+
this.selectOptionValue(createdOptionValue);
|
|
127
|
+
},
|
|
128
|
+
);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
async handleInputEnterKeyDown (event) {
|
|
132
|
+
event.preventDefault();
|
|
133
|
+
const $active = await this.getActiveOptionNode();
|
|
134
|
+
if (!$active) return;
|
|
135
|
+
const optionValueToSelect = $active.getAttribute(
|
|
136
|
+
'data-select-option-value',
|
|
137
|
+
);
|
|
138
|
+
const optionLabelToCreate = $active.getAttribute(
|
|
139
|
+
'data-create-option-label',
|
|
140
|
+
);
|
|
141
|
+
console.info($active, optionValueToSelect);
|
|
142
|
+
if (optionValueToSelect) {
|
|
143
|
+
this.selectOptionValue(optionValueToSelect);
|
|
144
|
+
} else if (optionLabelToCreate) {
|
|
145
|
+
this.createOption(optionLabelToCreate);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async handleInputArrowUpOrDownKeyDown (event) {
|
|
150
|
+
const $active = (await this.getActiveOptionNode());
|
|
151
|
+
const $options = this.optionsRef;
|
|
152
|
+
if (!$active || !$options) return;
|
|
153
|
+
const $optionsHeight = $options.getBoundingClientRect().height;
|
|
154
|
+
const $activeHeight = $active.getBoundingClientRect().height;
|
|
155
|
+
if (event.keyCode === 40) {
|
|
156
|
+
if ($options.lastElementChild === $active) {
|
|
157
|
+
$active.classList.remove(activeOptionClass);
|
|
158
|
+
$options.firstElementChild?.classList.add(activeOptionClass);
|
|
159
|
+
$options.scrollTop = 0;
|
|
160
|
+
} else {
|
|
161
|
+
$active.classList.remove(activeOptionClass);
|
|
162
|
+
$active.nextElementSibling?.classList.add(activeOptionClass);
|
|
163
|
+
if ($active.offsetTop > $options.scrollTop + $optionsHeight / 1.4) {
|
|
164
|
+
$options.scrollTop += $activeHeight;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
} else if (event.keyCode === 38) {
|
|
168
|
+
if ($options.firstElementChild === $active) {
|
|
169
|
+
$active.classList.remove(activeOptionClass);
|
|
170
|
+
$options.lastElementChild?.classList.add(activeOptionClass);
|
|
171
|
+
$options.scrollTop = $options.scrollHeight;
|
|
172
|
+
} else {
|
|
173
|
+
$active.classList.remove(activeOptionClass);
|
|
174
|
+
$active.previousElementSibling?.classList.add(activeOptionClass);
|
|
175
|
+
if ($active.offsetTop < $options.scrollTop + $optionsHeight / 2.4) {
|
|
176
|
+
$options.scrollTop -= $activeHeight;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
handleInputEscapeKeyDown(event) {
|
|
183
|
+
event.stopImmediatePropagation();
|
|
184
|
+
this.deactivateDropdown();
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
handleInputKeyDown(event) {
|
|
188
|
+
if (event.keyCode === 27) {
|
|
189
|
+
this.handleInputEscapeKeyDown(event);
|
|
190
|
+
} else if (event.keyCode === 13) {
|
|
191
|
+
this.handleInputEnterKeyDown(event);
|
|
192
|
+
} else if (event.keyCode === 40 || event.keyCode === 38) {
|
|
193
|
+
this.handleInputArrowUpOrDownKeyDown(event);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
async handleOptionMouseEnter(event) {
|
|
198
|
+
const $active = await this.getActiveOptionNode();
|
|
199
|
+
if ($active) $active.classList.remove(activeOptionClass);
|
|
200
|
+
(event.currentTarget).classList.add(activeOptionClass);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
async setFirstOptionAsActive() {
|
|
204
|
+
const $active = await this.getActiveOptionNode();
|
|
205
|
+
if (!this.optionsRef) return;
|
|
206
|
+
if ($active) $active.classList.remove(activeOptionClass);
|
|
207
|
+
if (this.optionsRef.firstElementChild) {
|
|
208
|
+
this.optionsRef.firstElementChild.classList.add(activeOptionClass);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
mounted() {
|
|
213
|
+
this.setFirstOptionAsActive();
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
</script>
|
|
217
|
+
|
|
218
|
+
<style scoped lang="scss">
|
|
219
|
+
.dropdown {
|
|
220
|
+
z-index: 101;
|
|
221
|
+
position: absolute;
|
|
222
|
+
top: calc(100% + 4px);
|
|
223
|
+
left: -1px;
|
|
224
|
+
border-radius: 0 0 4px 4px;
|
|
225
|
+
background: #fff;
|
|
226
|
+
box-shadow: rgba(9, 30, 66, 0.25) 0px 4px 8px -2px,
|
|
227
|
+
rgba(9, 30, 66, 0.31) 0px 0px 1px;
|
|
228
|
+
width: 100%;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
.dropdownInput {
|
|
232
|
+
padding: 10px 14px 8px;
|
|
233
|
+
width: 100%;
|
|
234
|
+
border: none;
|
|
235
|
+
color: #172b4d;
|
|
236
|
+
background: none;
|
|
237
|
+
|
|
238
|
+
&:focus {
|
|
239
|
+
outline: none;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
.options {
|
|
244
|
+
padding: 5px 0;
|
|
245
|
+
max-height: 200px;
|
|
246
|
+
overflow-x: hidden;
|
|
247
|
+
overflow-y: auto;
|
|
248
|
+
-webkit-overflow-scrolling: touch;
|
|
249
|
+
// &::-webkit-scrollbar {
|
|
250
|
+
// width: 7px;
|
|
251
|
+
// }
|
|
252
|
+
// &::-webkit-scrollbar-track {
|
|
253
|
+
// background: none;
|
|
254
|
+
// }
|
|
255
|
+
// &::-webkit-scrollbar-thumb {
|
|
256
|
+
// // border-radius: 99px;
|
|
257
|
+
// background: #d1d1d1;
|
|
258
|
+
// }
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
.option {
|
|
262
|
+
padding: 8px 14px;
|
|
263
|
+
word-break: break-word;
|
|
264
|
+
cursor: pointer;
|
|
265
|
+
|
|
266
|
+
&.select-option-is-active {
|
|
267
|
+
background: #e8ecee;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
.optionsNoResults {
|
|
272
|
+
padding: 0px 15px 10px;
|
|
273
|
+
color: #8993a4;
|
|
274
|
+
}
|
|
275
|
+
</style>
|
|
@@ -195,12 +195,14 @@
|
|
|
195
195
|
}
|
|
196
196
|
&__dropdown-menu {
|
|
197
197
|
background-color: $body-bg;
|
|
198
|
-
border: 2px solid $input-focus-border;
|
|
198
|
+
//border: 2px solid $input-focus-border;
|
|
199
|
+
border: 0 none;
|
|
199
200
|
padding-left: 0.125rem !important;
|
|
200
201
|
padding-right: 0.125rem !important;
|
|
201
202
|
left: -2px;
|
|
202
203
|
right: -2px;
|
|
203
204
|
width: auto;
|
|
205
|
+
box-shadow: rgb(9 30 66 / 25%) 0px 4px 8px -2px, rgb(9 30 66 / 31%) 0px 0px 1px;
|
|
204
206
|
|
|
205
207
|
@media (prefers-color-scheme: notdark) {
|
|
206
208
|
background-color: $dark-body-bg;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { storiesOf } from '@storybook/vue';
|
|
2
2
|
import itfSelect from './Select.vue';
|
|
3
|
+
import itfDropdown from './Dropdown';
|
|
4
|
+
import itfSelect2 from './AirSelect';
|
|
3
5
|
import itfForm from '../form/Form.vue';
|
|
4
6
|
import itfLabel from '../form/Label.vue';
|
|
5
7
|
import itfButton from '../button/Button.vue';
|
|
@@ -15,6 +17,8 @@ storiesOf('Common', module)
|
|
|
15
17
|
itfLabel,
|
|
16
18
|
itfButton,
|
|
17
19
|
itfSelect,
|
|
20
|
+
itfSelect2,
|
|
21
|
+
itfDropdown,
|
|
18
22
|
itfDatePicker,
|
|
19
23
|
itfDateRangePicker
|
|
20
24
|
},
|
|
@@ -29,11 +33,16 @@ storiesOf('Common', module)
|
|
|
29
33
|
customDays: {
|
|
30
34
|
'2021-10-21': { text: '🎉', class: 'test' }
|
|
31
35
|
},
|
|
36
|
+
value: [],
|
|
32
37
|
countries: [
|
|
33
38
|
{code: 'CA', country: 'Canada'},
|
|
34
39
|
{code: 'US', country: 'United states'},
|
|
35
40
|
{code: 'UA', country: 'Ukraine'},
|
|
36
41
|
{code: 'TEST', country: 'ASdasd sdas dasd sad sadas da ad asdsad ad d ada dsadsadsadasd sadsa das dasd asdasd asdas da '}
|
|
42
|
+
],
|
|
43
|
+
issuePriorityOptions: [
|
|
44
|
+
{ label: 'High', value: 1 },
|
|
45
|
+
{ label: 'Low', value: 2 }
|
|
37
46
|
]
|
|
38
47
|
}
|
|
39
48
|
},
|
|
@@ -65,6 +74,25 @@ storiesOf('Common', module)
|
|
|
65
74
|
|
|
66
75
|
<itf-form ref="form">
|
|
67
76
|
|
|
77
|
+
<itf-select2
|
|
78
|
+
multiple
|
|
79
|
+
searchable
|
|
80
|
+
variant="normal"
|
|
81
|
+
:dropdownWidth="300"
|
|
82
|
+
v-model="value"
|
|
83
|
+
:options="issuePriorityOptions"
|
|
84
|
+
customRender
|
|
85
|
+
>
|
|
86
|
+
<template #default="{ label, icon, color }">
|
|
87
|
+
<itf-button secondary>
|
|
88
|
+
<div class="flex items-center">
|
|
89
|
+
<div class="pr-1 pl-2">
|
|
90
|
+
{{ label }}
|
|
91
|
+
</div>
|
|
92
|
+
</div>
|
|
93
|
+
</itf-button>
|
|
94
|
+
</template>
|
|
95
|
+
</itf-select2>
|
|
68
96
|
<div class="row">
|
|
69
97
|
<div class="col-6">
|
|
70
98
|
<itf-label :rules="[$v.emptyValidation()]" :value="selected" label="From" required>
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export const useOutsideClick = () => {
|
|
2
|
+
const root = document.body;
|
|
3
|
+
let handleClickOutside = null;
|
|
4
|
+
let handleKeydown = null;
|
|
5
|
+
|
|
6
|
+
return {
|
|
7
|
+
bind(element, onOutsideClick) {
|
|
8
|
+
handleClickOutside = (e) => {
|
|
9
|
+
if (element && !element.contains(e.target)) {
|
|
10
|
+
onOutsideClick();
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
handleKeydown = (e) => {
|
|
14
|
+
if (e.key === 'Escape') {
|
|
15
|
+
onOutsideClick();
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
root.addEventListener(
|
|
19
|
+
'mousedown',
|
|
20
|
+
handleClickOutside,
|
|
21
|
+
);
|
|
22
|
+
root.addEventListener('keydown', handleKeydown);
|
|
23
|
+
},
|
|
24
|
+
unbind() {
|
|
25
|
+
root.removeEventListener(
|
|
26
|
+
'mousedown',
|
|
27
|
+
handleClickOutside,
|
|
28
|
+
);
|
|
29
|
+
root.removeEventListener('keydown', handleKeydown);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div v-
|
|
2
|
+
<div v-if="tabsManager && tabsManager.getValue() === id" :class="{ filled }" class="itf-tab-content" :data-test="`itf-tab-content-${id || _uid}`">
|
|
3
3
|
<slot />
|
|
4
4
|
</div>
|
|
5
5
|
</template>
|