-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Expand file tree
/
Copy pathindex.js
More file actions
66 lines (61 loc) · 1.39 KB
/
index.js
File metadata and controls
66 lines (61 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* External dependencies
*/
import { connect } from 'react-redux';
/**
* Internal dependencies
*/
import './style.scss';
import Dashicon from '../../components/dashicon';
/**
* Set of available mode options.
*
* @type {Array}
*/
const MODES = [
{
value: 'visual',
label: wp.i18n.__( 'Visual' )
},
{
value: 'text',
label: wp.i18n._x( 'Text', 'Name for the Text editor tab (formerly HTML)' )
}
];
function ModeSwitcher( { mode, onSwitch } ) {
// Disable reason: Toggling between modes should take effect immediately,
// arguably even with keyboard navigation. `onBlur` only would require
// another action to remove focus from the select (tabbing or clicking
// outside the field), which is unexpected when submit button is omitted.
/* eslint-disable jsx-a11y/no-onchange */
return (
<div className="editor-mode-switcher">
<select
value={ mode }
onChange={ ( event ) => onSwitch( event.target.value ) }
className="editor-mode-switcher__input"
>
{ MODES.map( ( { value, label } ) =>
<option key={ value } value={ value }>
{ label }
</option>
) }
</select>
<Dashicon icon="arrow-down" />
</div>
);
/* eslint-enable jsx-a11y/no-onchange */
}
export default connect(
( state ) => ( {
mode: state.mode
} ),
( dispatch ) => ( {
onSwitch( mode ) {
dispatch( {
type: 'SWITCH_MODE',
mode: mode
} );
}
} )
)( ModeSwitcher );