-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathinline-icon-picker.tsx
45 lines (39 loc) · 1.31 KB
/
inline-icon-picker.tsx
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
import styled from '@emotion/styled';
import { Dropdown } from '@wordpress/components';
import { useCallback } from '@wordpress/element';
import { IconPicker, IconPickerProps } from './icon-picker';
import { Icon } from './icon';
const StyledIconPickerDropdown = styled(IconPicker)`
margin: 6px;
width: 248px;
height: 248px;
`;
interface InlineIconPickerProps extends IconPickerProps {
/**
* Render function for the toggle button
* @param props
*/
renderToggle: (props: { onToggle: () => void }) => React.JSX.Element;
}
export const IconPickerDropdown: React.FC<InlineIconPickerProps> = (props) => {
const { renderToggle, ...iconPickerProps } = props;
return (
<Dropdown
className="component-icon-picker-inline-button"
contentClassName="component-icon-picker-inline__content"
popoverProps={{ placement: 'bottom-start' }}
renderToggle={renderToggle}
renderContent={() => <StyledIconPickerDropdown {...iconPickerProps} />}
/>
);
};
export const InlineIconPicker: React.FC<IconPickerProps> = (props) => {
const { value, ...rest } = props;
const IconButton = useCallback(
({ onToggle }: { onToggle: () => void }) => (
<Icon name={value?.name} iconSet={value?.iconSet} onClick={onToggle} {...rest} />
),
[value, rest],
);
return <IconPickerDropdown renderToggle={IconButton} {...props} />;
};