index.js
53 lines
| 1 | /** |
| 2 | * WordPress dependencies |
| 3 | */ |
| 4 | import { __ } from '@wordpress/i18n'; |
| 5 | import { TextControl } from '@wordpress/components'; |
| 6 | |
| 7 | const AdvancedViewportControl = (props) => { |
| 8 | const { attributes, setAttributes, initial } = props; |
| 9 | let { pc, tablet, mobile } = attributes; |
| 10 | const { iPc, iTablet, iMobile } = initial; |
| 11 | |
| 12 | if (isNaN(pc)) { |
| 13 | pc = iPc; |
| 14 | } |
| 15 | if (isNaN(tablet)) { |
| 16 | tablet = iTablet; |
| 17 | } |
| 18 | if (isNaN(mobile)) { |
| 19 | mobile = iMobile; |
| 20 | } |
| 21 | |
| 22 | return ( |
| 23 | <> |
| 24 | <TextControl |
| 25 | label={__('PC', 'vk-blocks')} |
| 26 | value={pc} |
| 27 | onChange={(value) => setAttributes({ pc: parseFloat(value) })} |
| 28 | type={'number'} |
| 29 | min={0} |
| 30 | /> |
| 31 | <TextControl |
| 32 | label={__('Tablet', 'vk-blocks')} |
| 33 | value={tablet} |
| 34 | onChange={(value) => |
| 35 | setAttributes({ tablet: parseFloat(value) }) |
| 36 | } |
| 37 | type={'number'} |
| 38 | min={0} |
| 39 | /> |
| 40 | <TextControl |
| 41 | label={__('Mobile', 'vk-blocks')} |
| 42 | value={mobile} |
| 43 | onChange={(value) => |
| 44 | setAttributes({ mobile: parseFloat(value) }) |
| 45 | } |
| 46 | type={'number'} |
| 47 | min={0} |
| 48 | /> |
| 49 | </> |
| 50 | ); |
| 51 | }; |
| 52 | export default AdvancedViewportControl; |
| 53 |