-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(depreciated-components): replaces UnnnicAutocomplete to UnnnicSe…
…lectSmart with autocomplete
- Loading branch information
1 parent
95ab759
commit 00cb8cb
Showing
8 changed files
with
199 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<template> | ||
<UnnnicSelectSmart | ||
:value="[ | ||
finalOptions.find(({ value: insideValue }) => insideValue === value), | ||
]" | ||
@input="$emit('input', $event[0].value)" | ||
:options="finalOptions" | ||
orderedByIndex | ||
autocomplete | ||
autocompleteClearOnFocus | ||
v-bind="$attrs" | ||
/> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
props: { | ||
value: String, | ||
placeholder: { | ||
type: String, | ||
default: '', | ||
}, | ||
options: Array, | ||
}, | ||
computed: { | ||
finalOptions() { | ||
return [{ value: '', label: this.placeholder }].concat( | ||
this.options.map((value) => ({ value, label: value })), | ||
); | ||
}, | ||
}, | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,111 +1,111 @@ | ||
<template> | ||
<fetch-choice-input | ||
v-if="fetch" | ||
:fetch="fetch" | ||
:label-placeholder="labelPlaceholder" | ||
v-model="value" | ||
@input="update()"/> | ||
<unnnic-autocomplete | ||
v-else-if="compact" | ||
v-model="value" | ||
:placeholder="labelPlaceholder" | ||
:custom-formatter="formatter" | ||
:data="filteredChoices" | ||
dropdown-position="bottom" | ||
openWithFocus | ||
@input="updateInput" | ||
@choose="selectOption"/> | ||
<unnnic-select-smart | ||
v-else | ||
:value="choicesSelectSmart.value" | ||
:options="choicesSelectSmart.options" | ||
@input="update($event[0].value)" | ||
></unnnic-select-smart> | ||
</template> | ||
|
||
<script> | ||
import { formatters, useSelectSmart } from '@/utils'; | ||
import FetchChoiceInput from './FetchChoiceInput'; | ||
export default { | ||
components: { | ||
FetchChoiceInput, | ||
}, | ||
props: { | ||
choices: { | ||
type: Array, | ||
default: () => [], | ||
}, | ||
fetch: { | ||
type: Function, | ||
default: null, | ||
}, | ||
initialData: { | ||
type: [Array, String], | ||
default: null, | ||
}, | ||
compact: { | ||
type: Boolean, | ||
default: null, | ||
}, | ||
labelPlaceholder: { | ||
type: String, | ||
default: '', | ||
}, | ||
}, | ||
data() { | ||
return { | ||
value: this.initialData, | ||
formatter: choice => choice.display_name, | ||
}; | ||
}, | ||
computed: { | ||
filteredChoices() { | ||
if (!this.value || this.value.length === 0) { return this.choices; } | ||
const search = new RegExp(formatters.bothubItemKey()(this.value.toLowerCase())); | ||
return this.choices | ||
.filter( | ||
choice => search.test(formatters.bothubItemKey()(choice.display_name.toLowerCase())), | ||
); | ||
}, | ||
choicesSelectSmart() { | ||
return useSelectSmart({ | ||
from: this.choices, | ||
value: 'value', | ||
label: 'display_name', | ||
placeholder: '', | ||
currentValue: this.value, | ||
}); | ||
}, | ||
}, | ||
mounted() { | ||
this.update(); | ||
}, | ||
methods: { | ||
updateInput() { | ||
const search = formatters.bothubItemKey()(this.value.toLowerCase()); | ||
const option = this.choices.find( | ||
choice => formatters.bothubItemKey()(choice.display_name.toLowerCase()) | ||
=== search, | ||
); | ||
if (option) { | ||
this.$emit('input', option.value); | ||
} else { | ||
this.$emit('input', ''); | ||
} | ||
}, | ||
selectOption(option) { | ||
if (option) { | ||
this.$emit('input', option.value); | ||
} else { | ||
this.$emit('input', ''); | ||
} | ||
}, | ||
update(value) { | ||
this.value = value; | ||
this.$emit('input', this.value); | ||
}, | ||
}, | ||
}; | ||
</script> | ||
<template> | ||
<fetch-choice-input | ||
v-if="fetch" | ||
:fetch="fetch" | ||
:label-placeholder="labelPlaceholder" | ||
v-model="value" | ||
@input="update()"/> | ||
<unnnic-autocomplete | ||
v-else-if="compact" | ||
v-model="value" | ||
:placeholder="labelPlaceholder" | ||
:custom-formatter="formatter" | ||
:data="filteredChoices" | ||
dropdown-position="bottom" | ||
openWithFocus | ||
@input="updateInput" | ||
@choose="selectOption"/> | ||
<unnnic-select-smart | ||
v-else | ||
:value="choicesSelectSmart.value" | ||
:options="choicesSelectSmart.options" | ||
@input="update($event[0].value)" | ||
></unnnic-select-smart> | ||
</template> | ||
|
||
<script> | ||
import { formatters, useSelectSmart } from '@/utils'; | ||
import FetchChoiceInput from './FetchChoiceInput'; | ||
export default { | ||
components: { | ||
FetchChoiceInput, | ||
}, | ||
props: { | ||
choices: { | ||
type: Array, | ||
default: () => [], | ||
}, | ||
fetch: { | ||
type: Function, | ||
default: null, | ||
}, | ||
initialData: { | ||
type: [Array, String], | ||
default: null, | ||
}, | ||
compact: { | ||
type: Boolean, | ||
default: null, | ||
}, | ||
labelPlaceholder: { | ||
type: String, | ||
default: '', | ||
}, | ||
}, | ||
data() { | ||
return { | ||
value: this.initialData, | ||
formatter: choice => choice.display_name, | ||
}; | ||
}, | ||
computed: { | ||
filteredChoices() { | ||
if (!this.value || this.value.length === 0) { return this.choices; } | ||
const search = new RegExp(formatters.bothubItemKey()(this.value.toLowerCase())); | ||
return this.choices | ||
.filter( | ||
choice => search.test(formatters.bothubItemKey()(choice.display_name.toLowerCase())), | ||
); | ||
}, | ||
choicesSelectSmart() { | ||
return useSelectSmart({ | ||
from: this.choices, | ||
value: 'value', | ||
label: 'display_name', | ||
placeholder: '', | ||
currentValue: this.value, | ||
}); | ||
}, | ||
}, | ||
mounted() { | ||
this.update(); | ||
}, | ||
methods: { | ||
updateInput() { | ||
const search = formatters.bothubItemKey()(this.value.toLowerCase()); | ||
const option = this.choices.find( | ||
choice => formatters.bothubItemKey()(choice.display_name.toLowerCase()) | ||
=== search, | ||
); | ||
if (option) { | ||
this.$emit('input', option.value); | ||
} else { | ||
this.$emit('input', ''); | ||
} | ||
}, | ||
selectOption(option) { | ||
if (option) { | ||
this.$emit('input', option.value); | ||
} else { | ||
this.$emit('input', ''); | ||
} | ||
}, | ||
update(value) { | ||
this.value = value; | ||
this.$emit('input', this.value); | ||
}, | ||
}, | ||
}; | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.