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