@itfin/components 1.0.77 → 1.0.78

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": "@itfin/components",
3
- "version": "1.0.77",
3
+ "version": "1.0.78",
4
4
  "main": "dist/itfin-components.umd.js",
5
5
  "unpkg": "dist/itfin-components.common.js",
6
6
  "author": "Vitalii Savchuk <esvit666@gmail.com>",
@@ -34,7 +34,7 @@
34
34
  remove: removeOptionValue
35
35
  }"
36
36
  />
37
- <div v-else class="valueMultiItem text-textDarkest">
37
+ <div v-else class="valueMultiItem text-textDarkest" :style="getOptionColor(optionValue) ? `background-color: #${getOptionColor(optionValue)}; color: #fff` : ''">
38
38
  <div class="valueMultiItemLabel">
39
39
  {{ getOptionLabel(optionValue) }}
40
40
  </div>
@@ -86,6 +86,8 @@
86
86
  :deactivateDropdown="deactivateDropdown"
87
87
  :options="options"
88
88
  :multiple="multiple"
89
+ :item-key="itemKey"
90
+ :item-text="itemText"
89
91
  :withClearValue="withClearValue"
90
92
  @change="handleChange"
91
93
  @searchValueChange="handleSearchValueChange"
@@ -117,6 +119,10 @@ class itfAirSelect extends Vue {
117
119
 
118
120
  @Prop({ type: String, default: 'normal' }) variant;
119
121
 
122
+ @Prop({ type: String, default: 'value' }) itemKey;
123
+ @Prop({ type: String, default: 'label' }) itemText;
124
+ @Prop({ type: String, default: 'color' }) itemColor;
125
+
120
126
  @Prop({ type: String, default: undefined }) name;
121
127
 
122
128
  @Prop({ type: Boolean, default: false }) searchable;
@@ -156,11 +162,16 @@ class itfAirSelect extends Vue {
156
162
  }
157
163
 
158
164
  getOption(optionValue) {
159
- return this.options.find((option) => option.value === optionValue);
165
+ return this.options.find((option) => option[this.itemKey] === optionValue);
160
166
  }
161
167
 
162
168
  getOptionLabel(optionValue) {
163
- return (this.getOption(optionValue) || { label: '' }).label;
169
+ return (this.getOption(optionValue) || { [this.itemText]: '' })[this.itemText];
170
+ }
171
+
172
+ getOptionColor(optionValue) {
173
+ console.info((this.getOption(optionValue) || { [this.itemColor]: '' })[this.itemColor])
174
+ return (this.getOption(optionValue) || { [this.itemColor]: '' })[this.itemColor];
164
175
  }
165
176
 
166
177
  get isControlled() {
@@ -173,7 +184,7 @@ class itfAirSelect extends Vue {
173
184
 
174
185
  preserveValueType(newValue) {
175
186
  const areOptionValuesNumbers = this.options.some(
176
- (option) => typeof option.value === 'number',
187
+ (option) => typeof option[this.itemKey] === 'number',
177
188
  );
178
189
  if (areOptionValuesNumbers) {
179
190
  if (this.multiple) {
@@ -14,13 +14,13 @@
14
14
  <div
15
15
  class="option text-textDarkest"
16
16
  v-for="option in filteredOptions"
17
- :key="option.value"
18
- :data-select-option-value="option.value"
19
- :data-testid="`select-option:${option.label}`"
17
+ :key="option[itemKey]"
18
+ :data-select-option-value="option[itemKey]"
19
+ :data-testid="`select-option:${option[itemText]}`"
20
20
  @mouseenter="handleOptionMouseEnter"
21
- @click="selectOptionValue(option.value)"
21
+ @click="selectOptionValue(option[itemKey])"
22
22
  >
23
- <slot name="option" v-bind="option">{{ option.label }}</slot>
23
+ <slot name="option" v-bind="option">{{ option[itemText] }}</slot>
24
24
  </div>
25
25
 
26
26
  <div
@@ -60,6 +60,8 @@ class itfSegmentedControl extends Vue {
60
60
  @Prop({ type: [Array, String, Number], default: undefined }) value;
61
61
  @Prop({ type: Boolean }) isValueEmpty;
62
62
  @Prop({ type: Boolean }) searchable;
63
+ @Prop({ type: String, default: 'value' }) itemKey;
64
+ @Prop({ type: String, default: 'label' }) itemText;
63
65
  @Prop({ type: String, default: '' }) searchValue;
64
66
  @Prop({ type: Function, required: true }) deactivateDropdown;
65
67
  @Prop({ type: Array, required: true }) options;
@@ -73,7 +75,7 @@ class itfSegmentedControl extends Vue {
73
75
  isCreatingOption = false;
74
76
 
75
77
  get optionsFilteredBySearchValue() {
76
- return this.options.filter((option) => option.label
78
+ return this.options.filter((option) => option[this.itemText]
77
79
  .toString()
78
80
  .toLowerCase()
79
81
  .includes(this.searchValue.toLowerCase()));
@@ -82,21 +84,21 @@ class itfSegmentedControl extends Vue {
82
84
  get filteredOptions() {
83
85
  return this.multiple
84
86
  ? this.optionsFilteredBySearchValue.filter(
85
- (option) => !(this.value).includes(option.value),
87
+ (option) => !(this.value).includes(option[this.itemKey]),
86
88
  )
87
89
  : this.optionsFilteredBySearchValue.filter(
88
- (option) => this.value !== option.value,
90
+ (option) => this.value !== option[this.itemKey],
89
91
  );
90
92
  }
91
93
 
92
94
  get isOptionCreatable() {
93
95
  return this.onCreate
94
96
  && this.searchValue
95
- && !this.options.map((option) => option.label).includes(this.searchValue);
97
+ && !this.options.map((option) => option[this.itemText]).includes(this.searchValue);
96
98
  }
97
99
 
98
100
  handleSearchValueChange(event) {
99
- this.$emit('searchValueChange', (event.target).value);
101
+ this.$emit('searchValueChange', (event.target)[this.itemKey]);
100
102
  }
101
103
 
102
104
  async getActiveOptionNode() {
@@ -1,5 +1,5 @@
1
1
  export const useOutsideClick = () => {
2
- const root = document.body;
2
+ const root = typeof document !== 'undefined' ? document.body : null;
3
3
  let handleClickOutside = null;
4
4
  let handleKeydown = null;
5
5
 
@@ -15,18 +15,22 @@ export const useOutsideClick = () => {
15
15
  onOutsideClick();
16
16
  }
17
17
  };
18
- root.addEventListener(
19
- 'mousedown',
20
- handleClickOutside,
21
- );
22
- root.addEventListener('keydown', handleKeydown);
18
+ if (root) {
19
+ root.addEventListener(
20
+ 'mousedown',
21
+ handleClickOutside,
22
+ );
23
+ root.addEventListener('keydown', handleKeydown);
24
+ }
23
25
  },
24
26
  unbind() {
25
- root.removeEventListener(
26
- 'mousedown',
27
- handleClickOutside,
28
- );
29
- root.removeEventListener('keydown', handleKeydown);
27
+ if (root) {
28
+ root.removeEventListener(
29
+ 'mousedown',
30
+ handleClickOutside,
31
+ );
32
+ root.removeEventListener('keydown', handleKeydown);
33
+ }
30
34
  }
31
35
  };
32
36
  };