-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathindex.js
More file actions
74 lines (69 loc) · 2.16 KB
/
index.js
File metadata and controls
74 lines (69 loc) · 2.16 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
67
68
69
70
71
72
73
74
import AdminBaseSetting from '../admin-base-setting'
import Button from '../button'
import { ButtonGroup } from '@wordpress/components'
import { __ } from '@wordpress/i18n'
import { i18n } from 'stackable'
const AdminToolbarSetting = props => {
return (
<AdminBaseSetting { ...props }>
<div className="ugb-admin-toolbar-setting__wrapper">
<a
href={ props.demoLink }
target="_blank"
rel="noopener noreferrer"
onClick={ ev => ev.stopPropagation() }
>
{ __( 'view demo', i18n ) }
</a>
<ButtonGroup
children={
props.controls.map( option => {
const isSelected = props.value ? props.value === option.value : props.placeholder === option.value
const tabindex = isSelected ? '0' : '-1'
return <Button
style={ option.selectedColor && isSelected ? { backgroundColor: option.selectedColor } : {} }
isPrimary={ ! option.selectedColor && isSelected }
key={ option.value }
label={ option.title || props.label }
tabIndex={ tabindex }
aria-pressed={ isSelected }
isSmall={ props.isSmall }
onClick={ () => {
if ( option.value === props.value ) {
return
}
props.onChange( option.value )
} }
onKeyDown={ e => {
const el = e.target
if ( el ) {
// On right, select the next value or loop to first.
if ( e.keyCode === 39 ) {
const nextEl = el.nextElementSibling || el.parentElement.firstElementChild
nextEl.focus()
nextEl.click()
// Trigger click on the previous option or loop to last.
} else if ( e.keyCode === 37 ) {
const prevEl = el.previousElementSibling || el.parentElement.lastElementChild
prevEl.focus()
prevEl.click()
}
}
} }
children={ <span className="ugb-admin-toolbar-setting__option">{ option.title }</span> }
/>
} )
}
className="ugb-admin-toolbar-setting"
/>
</div>
</AdminBaseSetting>
)
}
AdminToolbarSetting.defaultProps = {
controls: [],
label: '',
value: '',
onChange: () => {},
}
export default AdminToolbarSetting