This commit is contained in:
Henry Jameson 2019-06-18 22:13:03 +03:00
parent 0032802f0a
commit 46e0122067
2 changed files with 11 additions and 13 deletions

View file

@ -6,7 +6,7 @@ import { take } from 'lodash'
* without having to give up the comfort of <input/> and <textarea/> elements * without having to give up the comfort of <input/> and <textarea/> elements
* *
* Intended usage is: * Intended usage is:
* <emoji-input v-model="something"> * <EmojiInput v-model="something">
* <input v-model="something"/> * <input v-model="something"/>
* </EmojiInput> * </EmojiInput>
* *

View file

@ -8,20 +8,18 @@
* Depending on data present one or both (or none) can be present, so if field * Depending on data present one or both (or none) can be present, so if field
* doesn't support user linking you can just provide only emoji. * doesn't support user linking you can just provide only emoji.
*/ */
export default function suggest (data) { export default data => input => {
return input => { const firstChar = input[0]
const firstChar = input[0] if (firstChar === ':' && data.emoji) {
if (firstChar === ':' && data.emoji) { return suggestEmoji(data.emoji)(input)
return suggestEmoji(data.emoji)(input)
}
if (firstChar === '@' && data.users) {
return suggestUsers(data.users)(input)
}
return []
} }
if (firstChar === '@' && data.users) {
return suggestUsers(data.users)(input)
}
return []
} }
export const suggestEmoji = (emojis) => input => { export const suggestEmoji = emojis => input => {
const noPrefix = input.toLowerCase().substr(1) const noPrefix = input.toLowerCase().substr(1)
return emojis return emojis
.filter(({ displayText }) => displayText.toLowerCase().startsWith(noPrefix)) .filter(({ displayText }) => displayText.toLowerCase().startsWith(noPrefix))
@ -40,7 +38,7 @@ export const suggestEmoji = (emojis) => input => {
}) })
} }
export const suggestUsers = (users) => input => { export const suggestUsers = users => input => {
const noPrefix = input.toLowerCase().substr(1) const noPrefix = input.toLowerCase().substr(1)
return users.filter( return users.filter(
user => user =>