Skip to content

Commit

Permalink
Add table block deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Sep 18, 2018
1 parent 614534c commit 3aad4db
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions packages/block-library/src/table/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,63 @@ export const settings = {
</div>
);
},

deprecated: [
{
attributes: {
hasFixedLayout: {
type: 'boolean',
default: false,
},
head: getTableSectionAttributeSchema( 'head' ),
body: getTableSectionAttributeSchema( 'body' ),
foot: getTableSectionAttributeSchema( 'foot' ),
},

supports: {
align: true,
},

save( { attributes } ) {
const { hasFixedLayout, head, body, foot } = attributes;
const isEmpty = ! head.length && ! body.length && ! foot.length;

if ( isEmpty ) {
return null;
}

const classes = classnames( {
'has-fixed-layout': hasFixedLayout,
} );

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 }, cellIndex ) =>
<RichText.Content tagName={ tag } value={ content } key={ cellIndex } />
) }
</tr>
) }
</Tag>
);
};

return (
<table className={ classes }>
<Section type="head" rows={ head } />
<Section type="body" rows={ body } />
<Section type="foot" rows={ foot } />
</table>
);
},
},
],
};

0 comments on commit 3aad4db

Please sign in to comment.