Sha256: dfae209b58e313bedb2d08d8f4a4f66856ff8609b204d99c8894158c310b1b23

Contents?: true

Size: 1.24 KB

Versions: 972

Compression:

Stored size: 1.24 KB

Contents

// @flow

import React from 'react'
import { Typeahead } from '../..'

/**
 *
 * @const filterResults
 * @ignore
 * @returns {[Object]} - a custom mapping of objects, minimally containing
 * `value` and `label` among other possible fields
 * @summary - for doc example purposes only
 */

const filterResults = (results) =>
  results.items.map((result) => {
    return {
      label: result.login,
      value: result.id,
    }
  })

/**
*
* @const promiseOptions
* @ignore
* @returns {Promise} - fetch API data results from Typeahead input text
* @see - https://react-select.com/home#async
* @summary - for doc example purposes only
*/

const promiseOptions = (inputValue) =>
  new Promise((resolve) => {
    if (inputValue) {
      fetch(`https://api.github.com/search/users?q=${inputValue}`)
        .then((response) => response.json())
        .then((results) => {
          resolve(results.items ? filterResults(results) : [])
        })
    } else {
      resolve([])
    }
  })

const TypeaheadAsyncCreateable = (props) => {
  return (
    <Typeahead
        async
        createable
        isMulti
        label="Existing or User Created Options"
        loadOptions={promiseOptions}
        {...props}
    />
  )
}

export default TypeaheadAsyncCreateable

Version data entries

972 entries across 972 versions & 2 rubygems

Version Path
playbook_ui_docs-13.34.1.pre.alpha.play1407statvaluekitinconsistencies3388 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-13.34.1.pre.alpha.play1407statvaluekitinconsistencies3388 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui_docs-13.34.1.pre.alpha.PLAY14703378 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-13.34.1.pre.alpha.PLAY14703378 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui_docs-13.34.1 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-13.34.1 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui_docs-13.34.0.pre.alpha.PBNTR358responsiveadvancedtablereact3370 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-13.34.0.pre.alpha.PBNTR358responsiveadvancedtablereact3370 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui_docs-13.34.0.pre.alpha.PBNTR358responsiveadvancedtablereact3369 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-13.34.0.pre.alpha.PBNTR358responsiveadvancedtablereact3369 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-13.34.0.pre.alpha.PBNTR358responsiveadvancedtablereact3368 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui_docs-13.34.0.pre.alpha.PBNTR358responsiveadvancedtablereact3366 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-13.34.0.pre.alpha.PBNTR358responsiveadvancedtablereact3366 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-13.34.0 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui_docs-13.33.1.pre.alpha.play1407statvaluekitinconsistencies3352 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-13.33.1.pre.alpha.play1407statvaluekitinconsistencies3352 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui_docs-13.33.1.pre.alpha.PLAY14063320 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-13.33.1.pre.alpha.PLAY14063320 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-13.33.1 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui_docs-13.33.0.pre.alpha.PBNTR405dropdownformfixesrails3311 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx