Skip to content

Commit

Permalink
Use classnames for cell alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
talldan committed Jun 27, 2019
1 parent 806b46b commit 7fdde45
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
7 changes: 4 additions & 3 deletions packages/block-library/src/table/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -410,16 +410,17 @@ export class TableEdit extends Component {
columnIndex,
};

const cellClasses = classnames( { 'is-selected': isSelected } );
const cellStyles = align ? { textAlign: align } : undefined;
const cellClasses = classnames( {
'is-selected': isSelected,
[ `has-text-align-${ align }` ]: align,
} );

return (
<CellTag
key={ columnIndex }
className={ cellClasses }
>
<RichText
style={ cellStyles }
className="wp-block-table__cell-content"
value={ content }
onChange={ this.onChange }
Expand Down
6 changes: 4 additions & 2 deletions packages/block-library/src/table/save.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@ export default function save( { attributes } ) {
{ rows.map( ( { cells }, rowIndex ) => (
<tr key={ rowIndex }>
{ cells.map( ( { content, tag, align }, cellIndex ) => {
const cellStyles = align ? { textAlign: align } : undefined;
const cellClasses = classnames( {
[ `has-text-align-${ align }` ]: align,
} );

return (
<RichText.Content
style={ cellStyles }
className={ cellClasses ? cellClasses : undefined }
tagName={ tag }
value={ content }
key={ cellIndex }
Expand Down
12 changes: 12 additions & 0 deletions packages/block-library/src/table/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,18 @@
th,
td {
border-color: transparent;

&.has-text-align-left {
text-align: left;
}

&.has-text-align-center {
text-align: center;
}

&.has-text-align-right {
text-align: right;
}
}

border-bottom: 1px solid $light-gray-200;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

exports[`Table allows cells to be aligned 1`] = `
"<!-- wp:table -->
<table class=\\"wp-block-table\\"><tbody><tr><td>None</td><td style=\\"text-align:left\\" data-align=\\"left\\">To the left</td></tr><tr><td style=\\"text-align:center\\" data-align=\\"center\\">Centered</td><td style=\\"text-align:right\\" data-align=\\"right\\">To the right</td></tr></tbody></table>
<table class=\\"wp-block-table\\"><tbody><tr><td>None</td><td class=\\"has-text-align-left\\" data-align=\\"left\\">To the left</td></tr><tr><td class=\\"has-text-align-center\\" data-align=\\"center\\">Centered</td><td class=\\"has-text-align-right\\" data-align=\\"right\\">To the right</td></tr></tbody></table>
<!-- /wp:table -->"
`;
Expand Down

0 comments on commit 7fdde45

Please sign in to comment.