PluginProbe
BeyondWords – AI audio for publishers / 7.0.0
BeyondWords – AI audio for publishers v7.0.0
7.1.0 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.1.0 4.1.1 4.1.2 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.3.0 4.4.0 4.5.0 4.5.1 4.6.0 4.6.1 4.6.2 4.7.0 All 43 releases
speechkit / src / editor / components / toggle / index.js

index.js in BeyondWords – AI audio for publishers 7.0.0, at src/editor/components/toggle/index.js

50 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /**
2 * WordPress dependencies
3 */
4 import { Flex, FlexBlock, FlexItem, FormToggle } from '@wordpress/components';
5 import { useInstanceId } from '@wordpress/compose';
6
7 /**
8 * BeyondWords toggle control: switch on the left, clickable label to its right.
9 *
10 * @param {Object} props
11 * @param {string} [props.className] Extra class for the Flex wrapper.
12 * @param {string} props.label Visible, clickable label.
13 * @param {boolean} props.checked Whether the toggle is on.
14 * @param {Function} props.onChange Change handler.
15 * @param {boolean} [props.disabled] Whether the toggle is disabled.
16 *
17 * @return {Element} The toggle.
18 */
19 export function Toggle( {
20 className,
21 label,
22 checked,
23 onChange,
24 disabled = false,
25 } ) {
26 const instanceId = useInstanceId( Toggle, 'beyondwords-toggle' );
27
28 const classes = [ 'beyondwords-toggle', className ]
29 .filter( Boolean )
30 .join( ' ' );
31
32 return (
33 <Flex className={ classes } justify="flex-start" align="center">
34 <FlexItem>
35 <FormToggle
36 id={ instanceId }
37 checked={ checked }
38 onChange={ onChange }
39 disabled={ disabled }
40 />
41 </FlexItem>
42 <FlexBlock>
43 <label htmlFor={ instanceId }>{ label }</label>
44 </FlexBlock>
45 </Flex>
46 );
47 }
48
49 export default Toggle;
50