How to use emoji-mart - 10 common examples

To help you get started, weโ€™ve selected a few emoji-mart examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / emoji-mart / emoji-mart-tests.tsx View on Github external
if (match && match[2]) {
        // smiley is closed
        let emoji = emojiIndex.emojis[match[1]];
        const isSingleEmoji = (e: EmojiEntry): e is EmojiData => {
            return 'name' in e;
        };
        const isNativeEmoji = (e: EmojiData): e is BaseEmoji => {
            return 'native' in e;
        };
        if (!isSingleEmoji(emoji)) {
            emoji = emoji[1];
        }
        const native = (isNativeEmoji(emoji) && emoji.native) || '';
        setSearch(search.replace(match[0], native));
    } else if (match && match[1].length > 2) {
        suggestions = emojiIndex.search(match[1]) || [];
    }
    return (
        <div>
            {suggestions.map(emoji =&gt; {
                return 'native' in emoji &amp;&amp; <span>{emoji.native}</span>;
            })}
            {match &amp;&amp; <div>{match[0]}</div>}
            <input value="{search}" placeholder="enter a message..." type="text">
        </div>
    );
};
github DefinitelyTyped / DefinitelyTyped / types / emoji-mart / emoji-mart-tests.tsx View on Github external
const AutoCompleteExample: React.FC = () =&gt; {
    const [search, setSearch] = useState('');
    const changed = (e: React.ChangeEvent) =&gt; {
        const target = e.target as { value: any };
        setSearch(target.value);
    };

    const match = search.match(/:([a-z_]+)(:)?/);
    let suggestions: ReturnType = [];
    if (match &amp;&amp; match[2]) {
        // smiley is closed
        let emoji = emojiIndex.emojis[match[1]];
        const isSingleEmoji = (e: EmojiEntry): e is EmojiData =&gt; {
            return 'name' in e;
        };
        const isNativeEmoji = (e: EmojiData): e is BaseEmoji =&gt; {
            return 'native' in e;
        };
        if (!isSingleEmoji(emoji)) {
            emoji = emoji[1];
        }
        const native = (isNativeEmoji(emoji) &amp;&amp; emoji.native) || '';
        setSearch(search.replace(match[0], native));
    } else if (match &amp;&amp; match[1].length &gt; 2) {
        suggestions = emojiIndex.search(match[1]) || [];
    }
    return (
        <div></div>
github AugurProject / augur / packages / orbit-web / src / containers / SendMessage.js View on Github external
const handleInputChange = React.useCallback(() => {
    if (!inputRef.current) return
    const inputValue = inputRef.current.value
    const lastWord = inputValue.split(' ').pop()
    const emojiPickerActive = lastWord.startsWith(':') && useEmojis
    const lastEmojiIdx = emojiPickerActive ? inputValue.lastIndexOf(':') : null
    const emojiSearch = emojiPickerActive ? inputValue.slice(lastEmojiIdx) : null
    let emojiResults = emojiSearch ? emojiIndex.search(emojiSearch) : []

    if (emojiResults.length === 0) {
      // Slice the ':' prefix so we search for emojis instead of emoticons so
      // ':smile' => 'smile'
      // This is needed because we can also search for ':)' which requires the
      // ':' prefix
      emojiResults = emojiSearch ? emojiIndex.search(emojiSearch.slice(1)) : []
    }

    setInputValue(inputValue)
    setEmojiResults(emojiResults)
    setEmojiPickerActive(emojiPickerActive)
  }, [useEmojis])
github orbitdb / orbit-web / src / containers / SendMessage.js View on Github external
const handleInputChange = React.useCallback(() => {
    if (!inputRef.current) return
    const inputValue = inputRef.current.value
    const lastWord = inputValue.split(' ').pop()
    const emojiPickerActive = lastWord.startsWith(':') && useEmojis
    const lastEmojiIdx = emojiPickerActive ? inputValue.lastIndexOf(':') : null
    const emojiSearch = emojiPickerActive ? inputValue.slice(lastEmojiIdx) : null
    let emojiResults = emojiSearch ? emojiIndex.search(emojiSearch) : []

    if (emojiResults.length === 0) {
      // Slice the ':' prefix so we search for emojis instead of emoticons so
      // ':smile' => 'smile'
      // This is needed because we can also search for ':)' which requires the
      // ':' prefix
      emojiResults = emojiSearch ? emojiIndex.search(emojiSearch.slice(1)) : []
    }

    setInputValue(inputValue)
    setEmojiResults(emojiResults)
    setEmojiPickerActive(emojiPickerActive)
  }, [useEmojis])
github AugurProject / augur / packages / orbit-web / src / containers / SendMessage.js View on Github external
const handleInputChange = React.useCallback(() => {
    if (!inputRef.current) return
    const inputValue = inputRef.current.value
    const lastWord = inputValue.split(' ').pop()
    const emojiPickerActive = lastWord.startsWith(':') && useEmojis
    const lastEmojiIdx = emojiPickerActive ? inputValue.lastIndexOf(':') : null
    const emojiSearch = emojiPickerActive ? inputValue.slice(lastEmojiIdx) : null
    let emojiResults = emojiSearch ? emojiIndex.search(emojiSearch) : []

    if (emojiResults.length === 0) {
      // Slice the ':' prefix so we search for emojis instead of emoticons so
      // ':smile' => 'smile'
      // This is needed because we can also search for ':)' which requires the
      // ':' prefix
      emojiResults = emojiSearch ? emojiIndex.search(emojiSearch.slice(1)) : []
    }

    setInputValue(inputValue)
    setEmojiResults(emojiResults)
    setEmojiPickerActive(emojiPickerActive)
  }, [useEmojis])
github orbitdb / orbit-web / src / containers / SendMessage.js View on Github external
const handleInputChange = React.useCallback(() => {
    if (!inputRef.current) return
    const inputValue = inputRef.current.value
    const lastWord = inputValue.split(' ').pop()
    const emojiPickerActive = lastWord.startsWith(':') && useEmojis
    const lastEmojiIdx = emojiPickerActive ? inputValue.lastIndexOf(':') : null
    const emojiSearch = emojiPickerActive ? inputValue.slice(lastEmojiIdx) : null
    let emojiResults = emojiSearch ? emojiIndex.search(emojiSearch) : []

    if (emojiResults.length === 0) {
      // Slice the ':' prefix so we search for emojis instead of emoticons so
      // ':smile' => 'smile'
      // This is needed because we can also search for ':)' which requires the
      // ':' prefix
      emojiResults = emojiSearch ? emojiIndex.search(emojiSearch.slice(1)) : []
    }

    setInputValue(inputValue)
    setEmojiResults(emojiResults)
    setEmojiPickerActive(emojiPickerActive)
  }, [useEmojis])
github keybase / client / shared / chat / conversation / messages / react-button / emoji-picker / data.tsx View on Github external
'Activities',
  'Travel &amp; Places',
  'Objects',
  'Symbols',
  'Flags',
]
const categories: Array&lt;{
  category: string
  emojis: Array
}&gt; = categoryOrder.map(category =&gt; ({
  category,
  emojis: sorted[category],
}))

// Map from EmojiMart's `id` to EmojiDatasource's object
const emojiNameMap = Object.values(emojiIndex.emojis).reduce(
  (res: {[K in string]: EmojiData}, emoji: any) =&gt; {
    const shortName = emoji.id
    const emojiFromEmojiData = emojidata.find(e =&gt; e.short_name === shortName)
    if (emojiFromEmojiData) {
      res[shortName] = emojiFromEmojiData
    }
    return res
  },
  {}
)

export {categories, categoryOrder, emojiIndex, emojiNameMap}
github keybase / client / shared / actions / chat2 / index.tsx View on Github external
const onUpdateUserReacjis = (state: TypedState) => {
  if (isMobile) {
    return
  }
  const userReacjis = state.chat2.userReacjis
  // emoji-mart expects a frequency map so we convert the sorted list from the
  // service into a frequency map that will appease the lib.
  let i = 0
  let reacjis = {}
  userReacjis.topReacjis.forEach(el => {
    i++
    reacjis[el] = userReacjis.topReacjis.length - i
  })
  store.setHandlers({
    getter: key => {
      switch (key) {
        case 'frequently':
          return reacjis
        case 'last':
          return reacjis[0]
        case 'skin':
          return userReacjis.skinTone
      }
    },
  })
}
github keybase / client / shared / actions / chat2 / index.tsx View on Github external
const onUpdateUserReacjis = (state: TypedState) => {
  if (isMobile) {
    return
  }
  const userReacjis = state.chat2.userReacjis
  // emoji-mart expects a frequency map so we convert the sorted list from the
  // service into a frequency map that will appease the lib.
  let i = 0
  let reacjis = {}
  userReacjis.topReacjis.forEach(el => {
    i++
    reacjis[el] = userReacjis.topReacjis.length - i
  })
  store.setHandlers({
    getter: key => {
      switch (key) {
        case 'frequently':
          return reacjis
        case 'last':
          return reacjis[0]
        case 'skin':
          return userReacjis.skinTone
      }
    },
  })
}
github ifiokjr / remirror / @remirror / extension-emoji / build.js View on Github external
const emojiLib = require('emojilib');
const data = require('emoji-mart/data/all.json');
const { join, resolve } = require('path');
const { writeFileSync } = require('fs');
const { execSync } = require('child_process');
const { startCase, uniqueArray, omit, entries } = require('../core-helpers/lib');

const dir = (...paths) => resolve(__dirname, join(...paths));
const formatFile = path => execSync(`prettier ${path} --write`, { stdio: 'inherit' });

const baseEmojis = emojiLib.lib;
const enhancedEmojis = data.emojis;

const DESCRIPTION = 'a';
const KEYWORDS = 'j';

const files = {
  emojis: dir('src', 'data', 'emojis.ts'),
  categories: dir('src', 'data', 'categories.ts'),
};

const wrapInDefaultExport = json => `/* AUTOGENERATED FILE - DO NOT EDIT */
export default ${JSON.stringify(json, null, 2)}`;

const getStartCase = (category = '', name = '', firstKeyword = '') => {
  if (category === 'flags') {
    return `${name} flag`;
  }