| 1 |
/** |
| 2 |
* WordPress dependencies |
| 3 |
*/ |
| 4 |
import { __ } from '@wordpress/i18n'; |
| 5 |
import { useState } from '@wordpress/element'; |
| 6 |
import { ButtonGroup, Button } from '@wordpress/components'; |
| 7 |
|
| 8 |
const tabOptions = [ |
| 9 |
{ |
| 10 |
label: __('Normal', 'slider-blocks'), |
| 11 |
value: 'normal' |
| 12 |
}, |
| 13 |
{ |
| 14 |
label: __('Hover', 'slider-blocks'), |
| 15 |
value: 'hover' |
| 16 |
} |
| 17 |
]; |
| 18 |
const SwitcherControl = ({ normal, hover, options = [] }) => { |
| 19 |
const [tab, setTab] = useState('normal'); |
| 20 |
|
| 21 |
const Tabs = options.length > 0 ? options : tabOptions; |
| 22 |
|
| 23 |
return ( |
| 24 |
<div className="gkits-control-container gkits-switcher gkits-mb-24"> |
| 25 |
<ButtonGroup> |
| 26 |
{Tabs && |
| 27 |
Tabs.map((item, index) => { |
| 28 |
return ( |
| 29 |
<Button |
| 30 |
key={index} |
| 31 |
className={`switcher-button ${tab === item.value ? 'gkits-active' : ''}`} |
| 32 |
onClick={() => setTab(item.value)} |
| 33 |
> |
| 34 |
{item.label} |
| 35 |
</Button> |
| 36 |
); |
| 37 |
})} |
| 38 |
</ButtonGroup> |
| 39 |
<div className="gkits-switcher-content"> |
| 40 |
{tab === 'normal' && <div className="gkits-normal-content">{normal}</div>} |
| 41 |
{tab === 'hover' && <div className="gkits-hover-content">{hover}</div>} |
| 42 |
</div> |
| 43 |
</div> |
| 44 |
); |
| 45 |
}; |
| 46 |
|
| 47 |
export default SwitcherControl; |
| 48 |
|