PluginProbe
Block Animations, Motion & Scroll Effects – Ghost Kit / 3.7.0
Block Animations, Motion & Scroll Effects – Ghost Kit v3.7.0
3.7.2 3.7.1 3.7.0 3.6.1 trunk 1.6.3 2.25.0 3.3.0 3.3.1 3.3.2 3.3.3 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.6 3.5.0 3.5.1 3.6.0
ghostkit / gutenberg / components / select / index.js

index.js in Block Animations, Motion & Scroll Effects – Ghost Kit 3.7.0, at gutenberg/components/select/index.js

90 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import classnames from 'classnames/dedupe';
2 import selectStyles from 'gutenberg-react-select-styles';
3 import Select, { components } from 'react-select';
4 import { AutoSizer, List } from 'react-virtualized';
5
6 const rowHeight = 26;
7
8 function MenuList(props) {
9 const { children, maxHeight } = props;
10
11 if (!children.length) {
12 return null;
13 }
14
15 return (
16 <AutoSizer disableHeight>
17 {({ width }) => {
18 return (
19 <List
20 height={maxHeight}
21 rowCount={children.length}
22 rowHeight={rowHeight}
23 rowRenderer={({ index, key, style }) => {
24 return (
25 <div key={key} style={style}>
26 {children[index]}
27 </div>
28 );
29 }}
30 width={width}
31 />
32 );
33 }}
34 </AutoSizer>
35 );
36 }
37
38 const { Option: DefaultOption } = components;
39 function Option(props) {
40 return (
41 <DefaultOption {...props}>
42 {props?.data?.icon || ''}
43 {props.data.label}
44 </DefaultOption>
45 );
46 }
47
48 /**
49 * Component Class
50 *
51 * @param props
52 */
53 export default function SelectComponent(props) {
54 const { className, ...restProps } = props;
55
56 const selectProps = {
57 ...(props.grouped
58 ? {
59 groupHeaderHeight: 50,
60 }
61 : {}),
62 ...restProps,
63 };
64
65 // Add virtualized if there are > 30 items.
66 const withVirtualized = props?.options?.length > 30;
67
68 return (
69 <Select
70 styles={{
71 ...selectStyles,
72 option(styles, state) {
73 const newStyles = selectStyles.option(styles, state);
74
75 newStyles['> svg'] = {
76 width: '24px',
77 height: 'auto',
78 marginRight: '5px',
79 };
80
81 return newStyles;
82 },
83 }}
84 components={{ ...(withVirtualized ? { MenuList } : {}), Option }}
85 className={classnames('ghostkit-control-select', className)}
86 {...selectProps}
87 />
88 );
89 }
90