PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 2.0.0
GenerateBlocks v2.0.0
trunk 1.0 1.0.1 1.0.2 1.1.0 1.1.1 1.1.2 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.7.0 1.7.1 1.7.2 1.7.3 1.8.0 1.8.1 1.8.2 1.8.3 1.9.0 1.9.1 2.0.0 2.0.1 2.0.2 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.3.0
generateblocks / src / components / unit-control / unit-dropdown.js
generateblocks / src / components / unit-control Last commit date
editor.scss 2 years ago index.js 1 year ago unit-dropdown.js 2 years ago unit-list.js 2 years ago
unit-dropdown.js
64 lines
1 import { DropdownMenu, MenuGroup, MenuItem } from '@wordpress/components';
2 import { __ } from '@wordpress/i18n';
3 import getIcon from '../../utils/get-icon';
4
5 export default function UnitDropdown( { value, onChange, units = [], disabled } ) {
6 if ( ! units.length ) {
7 return null;
8 }
9
10 // Replace the last item with our value if it's not a part of the visible list.
11 if ( ! units.includes( value ) ) {
12 units[ units.length - 1 ] = value;
13 }
14
15 return (
16 <>
17 <DropdownMenu
18 className="gblocks-unit-control-units"
19 label={ __( 'Select a unit', 'generateblocks' ) }
20 icon={ null }
21 toggleProps={ {
22 children: value,
23 disabled,
24 } }
25 popoverProps={ {
26 className: 'gblocks-unit-control-popover',
27 focusOnMount: true,
28 noArrow: false,
29 } }
30 >
31 { ( { onClose } ) => (
32 <>
33 <MenuGroup>
34 { units.map( ( unit ) => (
35 <MenuItem
36 key={ unit }
37 onClick={ () => {
38 onChange( unit );
39 onClose();
40 } }
41 isSelected={ unit === value }
42 variant={ unit === value ? 'primary' : '' }
43 >
44 { unit }
45 </MenuItem>
46 ) ) }
47
48 <MenuItem
49 onClick={ () => {
50 window.open( 'https://developer.mozilla.org/en-US/docs/Learn/CSS/Building_blocks/Values_and_units', '_blank' ).focus();
51 } }
52 label={ __( 'Learn more about units', 'generateblocks' ) }
53 showTooltip={ true }
54 >
55 { getIcon( 'info' ) }
56 </MenuItem>
57 </MenuGroup>
58 </>
59 ) }
60 </DropdownMenu>
61 </>
62 );
63 }
64