| 1 |
import classnames from 'classnames/dedupe'; |
| 2 |
|
| 3 |
import metadata from './block.json'; |
| 4 |
|
| 5 |
const { name } = metadata; |
| 6 |
|
| 7 |
import { |
| 8 |
RichText, |
| 9 |
useBlockProps, |
| 10 |
useInnerBlocksProps, |
| 11 |
} from '@wordpress/block-editor'; |
| 12 |
import { applyFilters } from '@wordpress/hooks'; |
| 13 |
|
| 14 |
/** |
| 15 |
* Block Save Class. |
| 16 |
* |
| 17 |
* @param props |
| 18 |
*/ |
| 19 |
export default function BlockSave(props) { |
| 20 |
const { |
| 21 |
tabActive, |
| 22 |
trigger, |
| 23 |
buttonsVerticalAlign, |
| 24 |
buttonsAlign, |
| 25 |
tabsData = [], |
| 26 |
} = props.attributes; |
| 27 |
|
| 28 |
let className = classnames( |
| 29 |
'ghostkit-tabs', |
| 30 |
buttonsVerticalAlign && 'ghostkit-tabs-buttons-vertical', |
| 31 |
trigger && `ghostkit-tabs-buttons-trigger-${trigger}` |
| 32 |
); |
| 33 |
|
| 34 |
className = applyFilters('ghostkit.blocks.className', className, { |
| 35 |
...{ name }, |
| 36 |
...props, |
| 37 |
}); |
| 38 |
|
| 39 |
const blockProps = useBlockProps.save({ |
| 40 |
className, |
| 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 |
role="tablist" |
| 54 |
aria-orientation={ |
| 55 |
buttonsVerticalAlign ? 'vertical' : 'horizontal' |
| 56 |
} |
| 57 |
> |
| 58 |
{tabsData.map((tabData) => ( |
| 59 |
<RichText.Content |
| 60 |
tagName="button" |
| 61 |
id={`${tabData.slug}-button`} |
| 62 |
className={classnames( |
| 63 |
'ghostkit-tabs-buttons-item', |
| 64 |
tabActive === tabData.slug && |
| 65 |
'ghostkit-tabs-buttons-item-active' |
| 66 |
)} |
| 67 |
type="button" |
| 68 |
role="tab" |
| 69 |
data-tab={tabData.slug} |
| 70 |
aria-controls={`${tabData.slug}-content`} |
| 71 |
aria-selected={ |
| 72 |
tabActive === tabData.slug ? 'true' : false |
| 73 |
} |
| 74 |
key={`tab_button_${tabData.slug}`} |
| 75 |
value={tabData.title} |
| 76 |
/> |
| 77 |
))} |
| 78 |
</div> |
| 79 |
<div {...innerBlockProps} /> |
| 80 |
</div> |
| 81 |
); |
| 82 |
} |
| 83 |
|