forked from 10up/block-components
-
Notifications
You must be signed in to change notification settings - Fork 0
/
icon-picker-toolbar-button.js
55 lines (49 loc) · 1.31 KB
/
icon-picker-toolbar-button.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import PropTypes from 'prop-types';
import { __ } from '@wordpress/i18n';
import { Dropdown, ToolbarButton } from '@wordpress/components';
import styled from '@emotion/styled';
import { IconPicker } from './icon-picker';
import { Icon } from './icon';
const StyledIconPickerDropdown = styled(IconPicker)`
margin: 6px;
width: 306px;
`;
/**
* IconPickerToolbarButton
*
* @typedef IconPickerToolbarButtonProps
* @property {string} buttonLabel label
*
* @param {IconPickerToolbarButtonProps} props IconPickerToolbarButtonProps
* @returns {*}
*/
export const IconPickerToolbarButton = (props) => {
const {
value: { name, iconSet },
buttonLabel,
} = props;
return (
<Dropdown
className="component-icon-picker-toolbar-button"
contentClassName="component-icon-picker-toolbar-button__content"
position="bottom right"
renderToggle={({ isOpen, onToggle }) => (
<ToolbarButton
onClick={onToggle}
aria-expanded={isOpen}
icon={<Icon name={name} iconSet={iconSet} />}
>
{buttonLabel ?? __('Select Icon')}
</ToolbarButton>
)}
renderContent={() => <StyledIconPickerDropdown {...props} />}
/>
);
};
IconPickerToolbarButton.defaultProps = {
buttonLabel: __('Select Icon'),
};
IconPickerToolbarButton.propTypes = {
buttonLabel: PropTypes.string,
value: PropTypes.object.isRequired,
};