123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- import React from 'react';
- import {withInfo} from '@storybook/addon-info';
- import Button from 'app/components/button';
- import DropdownAutoComplete from 'app/components/dropdownAutoComplete';
- import DropdownButton from 'app/components/dropdownButton';
- const items = [
- {
- value: 'apple',
- label: 'π Apple',
- },
- {
- value: 'bacon',
- label: 'π₯ Bacon',
- },
- {
- value: 'corn',
- label: 'π½ Corn',
- },
- ];
- const groupedItems = [
- {
- value: 'defaults',
- hideGroupLabel: true,
- items: [
- {
- value: 'recent thing',
- label: 'recent thing',
- },
- {
- value: 'other recent thing',
- label: 'other recent thing',
- },
- {
- value: 'yet another recent thing',
- label: 'yet another recent thing',
- },
- ],
- },
- {
- value: 'countries',
- label: (
- <div>
- Countries{' '}
- <a style={{float: 'right'}} href="#">
- + Add
- </a>
- </div>
- ),
- items: [
- {
- value: 'new zealand',
- label: <div>π¨π· New Zealand</div>,
- },
- {
- value: 'australia',
- label: <div>π¦πΊ Australia</div>,
- },
- {
- value: 'brazil',
- label: <div>π§π· Brazil</div>,
- },
- ],
- },
- {
- value: 'foods',
- label: 'Foods',
- items: [
- {
- value: 'apple',
- label: <div>π Apple</div>,
- },
- {
- value: 'bacon',
- label: <div>π₯ Bacon</div>,
- },
- {
- value: 'corn',
- label: <div>π½ Corn</div>,
- },
- ],
- },
- ];
- export default {
- title: 'UI/Dropdowns/DropdownAutoComplete',
- };
- export const Ungrouped = withInfo('The item label can be a component or a string')(() => (
- <DropdownAutoComplete items={items}>
- {({selectedItem}) => (selectedItem ? selectedItem.label : 'Click me!')}
- </DropdownAutoComplete>
- ));
- Ungrouped.story = {
- name: 'ungrouped',
- };
- export const Grouped = withInfo('Group labels can receive a component too')(() => (
- <DropdownAutoComplete
- items={groupedItems}
- virtualizedHeight={44}
- virtualizedLabelHeight={28}
- >
- {({selectedItem}) => (selectedItem ? selectedItem.label : 'Click me!')}
- </DropdownAutoComplete>
- ));
- Grouped.story = {
- name: 'grouped',
- };
- export const WithDropdownButton = withInfo(
- 'Use it with dropdownbutton for maximum fun'
- )(() => (
- <DropdownAutoComplete items={groupedItems}>
- {({isOpen, selectedItem}) => (
- <DropdownButton isOpen={isOpen}>
- {selectedItem ? selectedItem.label : 'Click me!'}
- </DropdownButton>
- )}
- </DropdownAutoComplete>
- ));
- WithDropdownButton.story = {
- name: 'with dropdownButton',
- };
- export const WithExtraAction = withInfo('Add a call to action button')(() => (
- <DropdownAutoComplete
- items={items}
- action={<Button priority="primary">Now click me!</Button>}
- >
- {({isOpen, selectedItem}) => (
- <DropdownButton isOpen={isOpen}>
- {selectedItem ? selectedItem.label : 'Click me!'}
- </DropdownButton>
- )}
- </DropdownAutoComplete>
- ));
- WithExtraAction.story = {
- name: 'with extra action',
- };
|