import clsx from 'clsx'; import { RichText, useBlockProps, __experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles, __experimentalGetColorClassesAndStyles as getColorClassesAndStyles, __experimentalGetElementClassName, getBackgroundClassesAndStyles, } from '@wordpress/block-editor'; import type { BlockSaveProps } from '@wordpress/blocks'; import type { SectionProps, TableAttributes } from './types'; export default function save( { attributes, }: BlockSaveProps< TableAttributes > ) { const { hasFixedLayout, head, body, foot, caption, style } = attributes; const isEmpty = ! head.length && ! body.length && ! foot.length; if ( isEmpty ) { return null; } // The colour block support puts `has-link-color` on the figure. const colorProps = getColorClassesAndStyles( { ...attributes, style: { ...style, elements: undefined }, } ); const borderProps = getBorderClassesAndStyles( attributes ); const backgroundProps = getBackgroundClassesAndStyles( attributes ); const textAlign = style?.typography?.textAlign; const classes = clsx( colorProps.className, borderProps.className, backgroundProps.className, { 'has-fixed-layout': hasFixedLayout, [ `has-text-align-${ textAlign }` ]: textAlign, } ); const hasCaption = ! RichText.isEmpty( caption ); const Section = ( { type, rows }: SectionProps ) => { if ( ! rows.length ) { return null; } const Tag = `t${ type }` as 'thead' | 'tbody' | 'tfoot'; return ( { rows.map( ( { cells }, rowIndex ) => ( { cells.map( ( { content, tag, scope, align, colspan, rowspan, }, cellIndex ) => { const cellClasses = clsx( { [ `has-text-align-${ align }` ]: align, } ); return ( ); } ) } ) ) } ); }; return (
{ hasCaption && ( ) }
); }