Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New package combobox #36

Merged
merged 2 commits into from
Oct 31, 2017
Merged

Conversation

jeroenransijn
Copy link
Contributor

Combobox

This package implements a Combobox component. This component combines a Autocomplete component with a TextInput and a Button.

Example

combobox

Key points

  • Uses a Autocomplete component
  • Clicking the button will show all items
  • Typing text will filter the list

Usage

<Combobox items={items} onChange={handleChange} />

Prop types and default props

static propTypes = {
  ...Box.propTypes,
  items: PropTypes.array,
  width: PropTypes.oneOf(PropTypes.string, PropTypes.number),
  height: PropTypes.number,
  onChange: PropTypes.func,
  inputProps: PropTypes.objectOf(TextInput.propTypes),
  buttonProps: PropTypes.objectOf(Button.propTypes),
}

Complete Story

import { storiesOf } from '@storybook/react'
import React from 'react'
import Box from 'ui-box'
import starWarsNames from 'starwars-names'
import { Combobox } from '../src/'

// Generate a big list of items
const items = [
  ...starWarsNames.all,
  ...starWarsNames.all.map(x => `${x} 2`),
  ...starWarsNames.all.map(x => `${x} 3`),
].sort((a, b) => {
  const nameA = a.toUpperCase()
  const nameB = b.toUpperCase()
  if (nameA < nameB) {
    return -1
  }
  if (nameA > nameB) {
    return 1
  }

  return 0
})

const handleChange = selectedItem => {
  // eslint-disable-next-line no-console
  console.log(selectedItem)
}

storiesOf('combobox', module).add('Combobox', () => (
  <Box padding={40}>
    {(() => {
      document.body.style.margin = '0'
      document.body.style.height = '100vh'
    })()}
    <Combobox items={items} onChange={handleChange} />
  </Box>
))

@jeroenransijn jeroenransijn merged commit 575075f into master Oct 31, 2017
@jeroenransijn jeroenransijn deleted the new-package/evergreen-combobox branch February 6, 2018 22:35
prateekgoel pushed a commit to prateekgoel/evergreen that referenced this pull request Oct 26, 2018
* new package combobox

* readme updated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant