index.js
21 lines
| 1 | import { ToggleControl } from '@wordpress/components'; |
| 2 | import { useState } from '@wordpress/element'; |
| 3 | |
| 4 | export const AdvancedToggleControl = (props) => { |
| 5 | const { initialFixedTable, label, helpYes, helpNo, schema, setAttributes } = |
| 6 | props; |
| 7 | |
| 8 | const [hasFixedTable, setHasFixedTable] = useState(initialFixedTable); |
| 9 | return ( |
| 10 | <ToggleControl |
| 11 | label={label} |
| 12 | help={hasFixedTable ? helpYes : helpNo} |
| 13 | checked={hasFixedTable} |
| 14 | onChange={() => { |
| 15 | setHasFixedTable(!hasFixedTable); |
| 16 | setAttributes({ [schema]: !hasFixedTable }); |
| 17 | }} |
| 18 | /> |
| 19 | ); |
| 20 | }; |
| 21 |