@signal24/vue-foundation 4.25.6 → 4.25.8

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.
@@ -55,14 +55,46 @@
55
55
 
56
56
  Selected value: {{ selectedDelayedOption3 ?? '-' }}
57
57
  </div>
58
+
59
+ <div>
60
+ <VfSmartSelect
61
+ v-model="selectedCreateOption"
62
+ :options="createOptions"
63
+ :formatter="o => o.label"
64
+ :value-extractor="o => o.value"
65
+ :on-create-item="createOption"
66
+ :show-create-text-on-new-item="true"
67
+ />
68
+
69
+ Selected value: {{ selectedCreateOption ?? '-' }}
70
+ </div>
71
+
72
+ <div>
73
+ <VfSmartSelect v-model="selectedLoadedOption" :load-options="loadOptions" :formatter="o => o.label" :value-extractor="o => o.value" />
74
+
75
+ Selected value: {{ selectedLoadedOption ?? '-' }}
76
+ </div>
77
+
78
+ <div>
79
+ <VfSmartSelect v-model="selectedLoadedOption2" :load-options="loadOptions" :formatter="o => o.label" :value-extractor="o => o.value" />
80
+
81
+ Selected value: {{ selectedLoadedOption2 ?? '-' }}
82
+ </div>
83
+
84
+ <div>
85
+ <VfSmartSelect v-model="selectedLoadedOption3" :load-options="loadOptions" :formatter="o => o.label" />
86
+
87
+ Selected value: {{ selectedLoadedOption3 ?? '-' }}
88
+ </div>
58
89
  </div>
59
90
  </template>
60
91
 
61
92
  <script lang="ts" setup>
62
- import { cloneDeep } from 'lodash';
63
- import { onMounted, ref } from 'vue';
93
+ import { cloneDeep, compact } from 'lodash';
94
+ import { computed, onMounted, ref } from 'vue';
64
95
 
65
96
  import VfSmartSelect from '@/components/vf-smart-select.vue';
97
+ import { sleepSecs } from '@/helpers';
66
98
 
67
99
  interface IOption {
68
100
  label: string;
@@ -90,11 +122,30 @@ const selectedInstantOption2 = ref<IOption | null>(null);
90
122
  const selectedDelayedOption1 = ref<IOption | null>(options[1]);
91
123
  const selectedDelayedOption2 = ref<string | null>('2');
92
124
  const selectedDelayedOption3 = ref<string | null>('19'); // intentionally invalid value
125
+ const selectedCreateOption = ref<string | null>(null);
126
+ const selectedLoadedOption = ref<string | null>(null);
127
+ const selectedLoadedOption2 = ref<string | null>('5');
128
+ const selectedLoadedOption3 = ref<IOption | null>({ value: '5', label: 'Option 5', group: 'Set 1' });
129
+
130
+ const createdOptionTitle = ref<string>();
131
+ const createOptions = computed(() =>
132
+ compact([createdOptionTitle.value && { label: createdOptionTitle.value, value: 'new' }, ...(delayedOptions.value || [])])
133
+ );
93
134
 
94
135
  function setDelayedOptions() {
95
136
  delayedOptions.value = cloneDeep(options);
96
137
  }
97
138
 
139
+ async function loadOptions() {
140
+ await sleepSecs(0.25);
141
+ return [...options];
142
+ }
143
+
144
+ function createOption(name: string) {
145
+ createdOptionTitle.value = name;
146
+ selectedCreateOption.value = 'new';
147
+ }
148
+
98
149
  onMounted(() => setTimeout(setDelayedOptions, 1000));
99
150
  </script>
100
151