| 1 |
import classnames from 'classnames/dedupe'; |
| 2 |
|
| 3 |
import { |
| 4 |
RichText, |
| 5 |
useBlockProps, |
| 6 |
useInnerBlocksProps, |
| 7 |
} from '@wordpress/block-editor'; |
| 8 |
import { applyFilters } from '@wordpress/hooks'; |
| 9 |
|
| 10 |
import metadata from './block.json'; |
| 11 |
|
| 12 |
const { name } = metadata; |
| 13 |
|
| 14 |
export default [ |
| 15 |
// v3.1.2 |
| 16 |
{ |
| 17 |
...metadata, |
| 18 |
save: function BlockSave(props) { |
| 19 |
const { |
| 20 |
tabActive, |
| 21 |
trigger, |
| 22 |
buttonsVerticalAlign, |
| 23 |
buttonsAlign, |
| 24 |
tabsData = [], |
| 25 |
} = props.attributes; |
| 26 |
|
| 27 |
let className = classnames( |
| 28 |
'ghostkit-tabs', |
| 29 |
buttonsVerticalAlign && 'ghostkit-tabs-buttons-vertical', |
| 30 |
trigger && `ghostkit-tabs-buttons-trigger-${trigger}` |
| 31 |
); |
| 32 |
|
| 33 |
className = applyFilters('ghostkit.blocks.className', className, { |
| 34 |
...{ name }, |
| 35 |
...props, |
| 36 |
}); |
| 37 |
|
| 38 |
const blockProps = useBlockProps.save({ |
| 39 |
className, |
| 40 |
'data-tab-active': tabActive, |
| 41 |
}); |
| 42 |
const innerBlockProps = useInnerBlocksProps.save({ |
| 43 |
className: 'ghostkit-tabs-content', |
| 44 |
}); |
| 45 |
|
| 46 |
return ( |
| 47 |
<div {...blockProps}> |
| 48 |
<div |
| 49 |
className={classnames( |
| 50 |
'ghostkit-tabs-buttons', |
| 51 |
`ghostkit-tabs-buttons-align-${buttonsAlign}` |
| 52 |
)} |
| 53 |
> |
| 54 |
{tabsData.map((tabData) => ( |
| 55 |
<RichText.Content |
| 56 |
tagName="a" |
| 57 |
href={`#${tabData.slug}`} |
| 58 |
className="ghostkit-tabs-buttons-item" |
| 59 |
key={`tab_button_${tabData.slug}`} |
| 60 |
value={tabData.title} |
| 61 |
/> |
| 62 |
))} |
| 63 |
</div> |
| 64 |
<div {...innerBlockProps} /> |
| 65 |
</div> |
| 66 |
); |
| 67 |
}, |
| 68 |
}, |
| 69 |
]; |
| 70 |
|