Sha256: 7b2b5ca1cf6a9258c638d48675e6ac91fa847aaca16c8f3737cdea8c401f9a1f

Contents?: true

Size: 1.23 KB

Versions: 1068

Compression:

Stored size: 1.23 KB

Contents

import React from 'react'
import { Typeahead } from 'playbook-ui'

/**
 *
 * @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

1,068 entries across 1,068 versions & 2 rubygems

Version Path
playbook_ui_docs-14.14.0.pre.rc.1 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-14.14.0.pre.rc.1 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui_docs-14.13.0.pre.alpha.play1753updatepbcontenttags6065 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-14.13.0.pre.alpha.play1753updatepbcontenttags6065 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui_docs-14.13.0.pre.alpha.play1884progresspill6064 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-14.13.0.pre.alpha.play1884progresspill6064 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui_docs-14.13.0.pre.alpha.play1753updatepbcontenttags6060 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-14.13.0.pre.alpha.play1753updatepbcontenttags6060 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui_docs-14.13.0.pre.alpha.PBNTR5596029 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-14.13.0.pre.alpha.PBNTR5596029 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui_docs-14.13.0.pre.alpha.play1834depupdatesass6024 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-14.13.0.pre.alpha.play1834depupdatesass6024 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui_docs-14.14.0.pre.rc.0 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-14.14.0.pre.rc.0 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-14.13.0 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui_docs-14.12.0.pre.alpha.PLAY1888initializeOncereactdatepickerslowdown5956 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-14.12.0.pre.alpha.PLAY1888initializeOncereactdatepickerslowdown5956 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui_docs-14.13.0.pre.rc.10 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui-14.13.0.pre.rc.10 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx
playbook_ui_docs-14.13.0.pre.rc.9 app/pb_kits/playbook/pb_typeahead/docs/_typeahead_async_createable.jsx