/
githubmirror
/
gutenberg
Обзор
Документация
Войти
/
githubmirror
/
gutenberg
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
trunk
packages/block-library/src/table/save.js
99 строк
2 KB
Marco Ciampini
ESLint: Replace strict config with bulk suppressions (#81248)
07 авг 2026, 14:34
Не верифицирован
07 авг 2026, 14:34
7f43eaf
Код
Авторство
О чём код?
import clsx from 'clsx'; import { RichText, useBlockProps, __experimentalGetBorderClassesAndStyles as getBorderClassesAndStyles, __experimentalGetColorClassesAndStyles as getColorClassesAndStyles, __experimentalGetElementClassName, } from '@wordpress/block-editor'; export default function save( { attributes } ) { const { hasFixedLayout, head, body, foot, caption } = attributes; const isEmpty = ! head.length && ! body.length && ! foot.length; if ( isEmpty ) { return null; } const colorProps = getColorClassesAndStyles( attributes ); const borderProps = getBorderClassesAndStyles( attributes ); const classes = clsx( colorProps.className, borderProps.className, { 'has-fixed-layout': hasFixedLayout, } ); const hasCaption = ! RichText.isEmpty( caption ); const Section = ( { type, rows } ) => { if ( ! rows.length ) { return null; } const Tag = `t${ type }`; return ( <Tag> { rows.map( ( { cells }, rowIndex ) => ( <tr key={ rowIndex }> { cells.map( ( { content, tag, scope, align, colspan, rowspan, }, cellIndex ) => { const cellClasses = clsx( { [ `has-text-align-${ align }` ]: align, } ); return ( <RichText.Content className={ cellClasses ? cellClasses : undefined } data-align={ align } tagName={ tag } value={ content } key={ cellIndex } scope={ tag === 'th' ? scope : undefined } colSpan={ colspan } rowSpan={ rowspan } /> ); } ) } </tr> ) ) } </Tag> ); }; return ( <figure { ...useBlockProps.save() }> <table className={ classes === '' ? undefined : classes } style={ { ...colorProps.style, ...borderProps.style } } > <Section type="head" rows={ head } /> <Section type="body" rows={ body } /> <Section type="foot" rows={ foot } /> </table> { hasCaption && ( <RichText.Content tagName="figcaption" value={ caption } className={ __experimentalGetElementClassName( 'caption' ) } /> ) } </figure> ); }