PluginProbe ʕ •ᴥ•ʔ
GenerateBlocks / 1.7.1
GenerateBlocks v1.7.1
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-picker / index.js
generateblocks / src / components / unit-picker Last commit date
editor.scss 3 years ago index.js 3 years ago
index.js
82 lines
1 // Import CSS
2 import './editor.scss';
3
4 import {
5 Component,
6 } from '@wordpress/element';
7
8 import {
9 __,
10 sprintf,
11 _x,
12 } from '@wordpress/i18n';
13
14 import {
15 ButtonGroup,
16 Button,
17 Tooltip,
18 BaseControl,
19 } from '@wordpress/components';
20
21 export default class UnitChooser extends Component {
22 render() {
23 const {
24 label,
25 value,
26 onClick,
27 units,
28 id,
29 singleOption = false,
30 } = this.props;
31
32 const allUnits = singleOption ? [ value ] : units;
33
34 return (
35 <BaseControl label={ label } id={ id } className="components-gblocks-units-control-header__units">
36 <div className="components-gblocks-control__units">
37 <ButtonGroup className="components-gblocks-control-buttons__units" aria-label={ __( 'Select Units', 'generateblocks' ) }>
38 { allUnits.map( ( unit ) => {
39 let unitName = unit;
40
41 if ( 'px' === unit ) {
42 unitName = _x( 'Pixel', 'A size unit for CSS markup', 'generateblocks' );
43 }
44
45 if ( 'em' === unit ) {
46 unitName = _x( 'Em', 'A size unit for CSS markup', 'generateblocks' );
47 }
48
49 if ( '%' === unit ) {
50 unitName = _x( 'Percentage', 'A size unit for CSS markup', 'generateblocks' );
51 }
52
53 if ( 'deg' === unit ) {
54 unitName = _x( 'Degree', 'A size unit for CSS markup', 'generateblocks' );
55 }
56
57 return <Tooltip
58 /* translators: Unit type (px, em, %) */
59 text={ sprintf( __( '%s Units', 'generateblocks' ), unitName ) }
60 key={ unit }
61 >
62 <Button
63 key={ unit }
64 className={ 'components-gblocks-control-button__units--' + unit }
65 isSmall
66 isPrimary={ value === unit }
67 aria-pressed={ value === unit }
68 /* translators: %s: values associated with CSS syntax, 'Pixel', 'Em', 'Percentage' */
69 aria-label={ sprintf( __( '%s Units', 'generateblocks' ), unitName ) }
70 onClick={ () => onClick( unit ) }
71 >
72 { unit }
73 </Button>
74 </Tooltip>;
75 } ) }
76 </ButtonGroup>
77 </div>
78 </BaseControl>
79 );
80 }
81 }
82