import { PureComponent } from 'react';
import SelectDropdown from '..';
import Gridicon from '../../gridicon';
class SelectDropdownExample extends PureComponent {
static displayName = 'SelectDropdownExample';
static defaultProps = {
options: [
{ value: 'status-options', label: 'Statuses', isLabel: true },
{ value: 'published', label: 'Published', count: 12 },
{ value: 'scheduled', label: 'Scheduled' },
{ value: 'drafts', label: 'Drafts' },
null,
{ value: 'trashed', label: 'Trashed' },
],
};
state = {
childSelected: 'Published',
selectedCount: 10,
compactButtons: false,
selectedIcon: ,
};
toggleButtons = () => {
this.setState( { compactButtons: ! this.state.compactButtons } );
};
render() {
const toggleButtonsText = this.state.compactButtons ? 'Normal Buttons' : 'Compact Buttons';
return (
Items passed as options prop
Items passed as children
Statuses
Published
Scheduled
Drafts
Trashed
With Icons in Items Passed as Options
,
},
{
value: 'scheduled',
label: 'Scheduled',
icon: ,
},
{
value: 'drafts',
label: 'Drafts',
icon: ,
},
{
value: 'trashed',
label: 'Trashed',
icon: ,
},
] }
/>
With Icons in Items Passed as Children
Statuses
}
onClick={ this.getSelectItemHandler(
'Published',
10,
) }
>
Published
}
onClick={ this.getSelectItemHandler(
'Scheduled',
4,
) }
>
Scheduled
}
onClick={ this.getSelectItemHandler(
'Drafts',
3343,
) }
>
Drafts
}
onClick={ this.getSelectItemHandler(
'Trashed',
3,
) }
>
Trashed
max-width: 220px;
Statuses
Published publish publish publish
Scheduled scheduled
Drafts
Disabled Item
Trashed
Disabled State
);
}
getSelectItemHandler = ( name, count, icon ) => {
return ( event ) => {
event.preventDefault();
this.selectItem( name, count, icon );
};
};
selectItem = ( childSelected, count, icon ) => {
this.setState( {
childSelected: childSelected,
selectedCount: count,
selectedIcon: icon,
} );
// eslint-disable-next-line no-console
console.log( 'Select Dropdown Item (selected):', childSelected );
};
onDropdownSelect( option ) {
// eslint-disable-next-line no-console
console.log( 'Select Dropdown (selected):', option );
}
}
export default SelectDropdownExample;