/* eslint-disable react/no-multi-comp */ import React, { Component, useState } from 'react'; import { storiesOf } from '@storybook/react'; import { boolean } from '@storybook/addon-knobs'; import DropIcon from 'components/Icon/icons/arrows/dropdown'; import MenuIcon from 'components/Icon/icons/content/vmenu'; import PinFilledIcon from 'components/Icon/icons/maps/pinFilled'; import styled from '@emotion/styled'; import Dropdown from './index'; import BaseApp from '../BaseApp'; import { Item } from './types'; const ThinnerDropdown = styled(Dropdown)` width: 200px; `; const items = [ { value: 'hello', label: 'Hello world!', }, { value: 'bye', label: 'Bye!', }, ]; const itemsWithLongText = [ { value: 'hello', label: 'Hello world!', }, { value: 'bye', label: 'Bye!', }, { value: 'long text', label: 'Longgggg Texttttttttt Handlingggggg', }, ]; const itemsWithDisabled = [ { value: 'hello', label: 'Hello world!', disabled: false, }, { value: 'morning', label: 'Good morning, Dave.', disabled: true, tooltip: 'Dave is still asleep', }, { value: 'bye', label: 'Bye!', }, ]; const itemsWithSubmenu = [ { value: 'TH', label: 'Thailand', icon: , options: [ { value: 'TH_BKK', label: 'Bangkok', icon: , }, { value: 'TH_CNX', label: 'Chiang Mai', icon: , }, { value: 'TH_PYX', label: 'Chonburi', icon: , }, { value: 'TH_KSM', label: 'Ko Samui', icon: , }, ], }, { value: 'HK_HKG', label: 'Hong Kong', icon: , }, { value: 'VN_HCM', label: 'Vietnam', icon: , }, { value: 'PH', label: 'Philippines', icon: , options: [ { value: 'PH_MNL', label: 'Manila', icon: , }, { value: 'PH_CEB', label: 'Cebu', icon: , }, { value: 'PH_JOL', label: 'Pampanga', icon: , }, { value: 'PH_PAM', label: 'Cebu', icon: , }, ], }, { value: 'SG_SGN', label: 'Singapore', icon: , }, { value: 'TW_TPE', label: 'Taiwan', icon: , }, ]; const Basic = () => { const [selectedItem, setSelectedItem] = useState(items[0]); return (

Basic

Basic disabled

Basic with disabled item and tooltip

Basic with custom button icon

} />

Basic with item icon

({ ...item, icon: }))} />

Basic with checked label

void} checkSelectedItem />

Basic with item icon and long text handling

({ ...item, icon: , }))} selectedItem={itemsWithLongText[2]} checkSelectedItem />

Sizing Intrinsic

Sizing Fixed

Sizing Parent

Block

Compact

Compact disabled

Compact with custom button icon

} />

With CustomLabel

); }; class CascadingMenu extends Component { state = { dropdown1: itemsWithSubmenu[5], dropdown2: itemsWithSubmenu[1], dropdown3: itemsWithSubmenu[0], dropdown4: itemsWithSubmenu[0]?.[0], }; handleChange = (name, item) => { this.setState({ [name]: item }); }; render() { const { dropdown1, dropdown2, dropdown3, dropdown4 } = this.state; const rtl = boolean('Right-to-left', false); return (

Cascading menu with direction=auto

this.handleChange('dropdown1', item)} selectedItem={dropdown1} />

Cascading menu with direction=left

this.handleChange('dropdown2', item)} selectedItem={dropdown2} direction="left" />

Cascading menu with direction=right

this.handleChange('dropdown2', item)} selectedItem={dropdown2} direction="right" />

Cascading menu with listSize fixed and{' '} scroll=true

this.handleChange('dropdown1', item)} selectedItem={dropdown1} listSize="fixed" scroll />

Cascading menu with listSize intrinsic and{' '} scroll=true

this.handleChange('dropdown1', item)} selectedItem={dropdown1} listSize="intrinsic" scroll />

Cascading menu with listSize parent and{' '} scroll=true

this.handleChange('dropdown1', item)} selectedItem={dropdown1} listSize="parent" scroll />

Cascading menu with block=true

Container (shown with padding here):
this.handleChange('dropdown3', item)} selectedItem={dropdown3} block />

Cascading menu with block=true and{' '} scroll=true

Container (shown with padding here):
this.handleChange('dropdown3', item)} selectedItem={dropdown3} block scroll />

Cascading menu with scroll=true

this.handleChange('dropdown4', item)} selectedItem={dropdown4} direction="left" checkSelectedItem scroll />
); } } storiesOf('Components/Dropdown', module) .add('Basic', () => ) .add('Cascading menu', () => );