2020-06-26 14:22:41 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2021-12-02 16:56:53 +00:00
|
|
|
import { omitBy } from 'lodash';
|
|
|
|
import { Story, Meta } from '@storybook/react';
|
2020-06-26 14:22:41 +00:00
|
|
|
import { useState } from '@wordpress/element';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import * as icons from '../index';
|
2021-12-02 16:56:53 +00:00
|
|
|
import { IconProps } from '../icon';
|
2020-06-26 14:22:41 +00:00
|
|
|
|
2021-12-02 16:56:53 +00:00
|
|
|
const { Icon, ...availableIcons } = icons;
|
2020-06-26 14:22:41 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
title: 'WooCommerce Blocks/@woocommerce/icons',
|
|
|
|
component: Icon,
|
2021-12-02 16:56:53 +00:00
|
|
|
argTypes: {
|
|
|
|
size: {
|
|
|
|
control: { type: 'range', min: 8, max: 96 },
|
|
|
|
},
|
|
|
|
srcElement: {
|
|
|
|
control: 'select',
|
|
|
|
mapping: availableIcons,
|
|
|
|
options: Object.keys( availableIcons ),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
} as Meta< IconProps >;
|
|
|
|
|
|
|
|
const Template: Story< IconProps > = ( args ) => <Icon { ...args } />;
|
|
|
|
|
|
|
|
export const BaseIcon = Template.bind( {} );
|
|
|
|
BaseIcon.args = {
|
|
|
|
srcElement: icons.woo,
|
|
|
|
size: 24,
|
2020-06-26 14:22:41 +00:00
|
|
|
};
|
|
|
|
|
2021-12-02 16:56:53 +00:00
|
|
|
export const Library: Story< IconProps > = ( args ) => {
|
2020-06-26 14:22:41 +00:00
|
|
|
const [ filter, setFilter ] = useState( '' );
|
2021-12-02 16:56:53 +00:00
|
|
|
const filteredIcons = omitBy( availableIcons, ( _, name ) => {
|
2020-06-26 14:22:41 +00:00
|
|
|
return ! name.includes( filter );
|
|
|
|
} );
|
2021-05-16 17:59:32 +00:00
|
|
|
|
2020-06-26 14:22:41 +00:00
|
|
|
return (
|
|
|
|
<div style={ { padding: '20px' } }>
|
|
|
|
<label htmlFor="filter-icons" style={ { paddingRight: '30px' } }>
|
|
|
|
Filter Icons
|
|
|
|
</label>
|
|
|
|
<input
|
|
|
|
id="filter-icons"
|
|
|
|
type="search"
|
|
|
|
value={ filter }
|
|
|
|
placeholder="Icon name"
|
|
|
|
onChange={ ( event ) => setFilter( event.target.value ) }
|
|
|
|
/>
|
|
|
|
<div
|
|
|
|
style={ {
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'bottom',
|
2021-05-16 17:59:32 +00:00
|
|
|
flexWrap: 'wrap',
|
2020-06-26 14:22:41 +00:00
|
|
|
} }
|
|
|
|
>
|
2021-05-16 17:59:32 +00:00
|
|
|
{ Object.entries( filteredIcons ).map( ( [ name, icon ] ) => {
|
2020-06-26 14:22:41 +00:00
|
|
|
return (
|
|
|
|
<div
|
|
|
|
key={ name }
|
|
|
|
style={ {
|
|
|
|
display: 'flex',
|
2021-05-16 17:59:32 +00:00
|
|
|
flexDirection: 'column',
|
2020-06-26 14:22:41 +00:00
|
|
|
width: '25%',
|
|
|
|
padding: '25px 0 25px 0',
|
|
|
|
} }
|
|
|
|
>
|
|
|
|
<strong
|
|
|
|
style={ {
|
|
|
|
width: '200px',
|
|
|
|
} }
|
|
|
|
>
|
|
|
|
{ name }
|
|
|
|
</strong>
|
|
|
|
<div
|
|
|
|
style={ {
|
|
|
|
display: 'flex',
|
|
|
|
alignItems: 'center',
|
|
|
|
} }
|
|
|
|
>
|
|
|
|
<Icon
|
2021-12-02 16:56:53 +00:00
|
|
|
className={ args.className }
|
|
|
|
srcElement={ icon }
|
|
|
|
/>
|
|
|
|
<Icon
|
|
|
|
className={ args.className }
|
2021-05-16 17:59:32 +00:00
|
|
|
style={ { paddingLeft: '10px' } }
|
2020-06-26 14:22:41 +00:00
|
|
|
srcElement={ icon }
|
|
|
|
size={ 36 }
|
|
|
|
/>
|
|
|
|
<Icon
|
2021-12-02 16:56:53 +00:00
|
|
|
className={ args.className }
|
2021-05-16 17:59:32 +00:00
|
|
|
style={ { paddingLeft: '10px' } }
|
2020-06-26 14:22:41 +00:00
|
|
|
srcElement={ icon }
|
|
|
|
size={ 48 }
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
} ) }
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
2021-12-02 16:56:53 +00:00
|
|
|
Library.parameters = {
|
|
|
|
controls: { include: [], hideNoControlsWarning: true },
|
|
|
|
};
|
|
|
|
Library.storyName = 'Icon Library';
|