-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Polish the Table block #6314
Merged
Merged
Polish the Table block #6314
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,30 @@ | ||
.wp-block-table { | ||
table { | ||
border-collapse: collapse; | ||
width: 100%; | ||
} | ||
|
||
td, | ||
th { | ||
padding: 0.5em; | ||
border: 1px solid currentColor; | ||
} | ||
|
||
td[data-mce-selected="1"], th[data-mce-selected="1"] { | ||
background-color: $light-gray-500; | ||
td[data-mce-selected="1"], | ||
th[data-mce-selected="1"] { | ||
background-color: $light-gray-300; | ||
} | ||
} | ||
|
||
// Style the resize handles | ||
.ephox-snooker-resizer-rows { | ||
cursor: row-resize; | ||
} | ||
|
||
.ephox-snooker-resizer-cols { | ||
cursor: col-resize; | ||
} | ||
|
||
.ephox-snooker-resizer-bar-dragging { | ||
background: $blue-medium-500; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing an empty line here :) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,24 @@ | |
* External dependencies | ||
*/ | ||
import { __ } from '@wordpress/i18n'; | ||
import classnames from 'classnames'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { Fragment } from '@wordpress/element'; | ||
import { getPhrasingContentSchema } from '@wordpress/blocks'; | ||
import { | ||
getPhrasingContentSchema, | ||
BlockControls, | ||
BlockAlignmentToolbar, | ||
RichText, | ||
} from '@wordpress/editor'; | ||
InspectorControls, | ||
} from '@wordpress/blocks'; | ||
|
||
import { | ||
PanelBody, | ||
ToggleControl, | ||
} from '@wordpress/components'; | ||
|
||
/** | ||
* Internal dependencies | ||
|
@@ -73,6 +80,10 @@ export const settings = { | |
align: { | ||
type: 'string', | ||
}, | ||
hasFixedLayout: { | ||
type: 'boolean', | ||
default: false, | ||
}, | ||
}, | ||
|
||
transforms: { | ||
|
@@ -93,8 +104,19 @@ export const settings = { | |
}, | ||
|
||
edit( { attributes, setAttributes, isSelected, className } ) { | ||
const { content } = attributes; | ||
const { content, hasFixedLayout } = attributes; | ||
const updateAlignment = ( nextAlign ) => setAttributes( { align: nextAlign } ); | ||
const toggleFixedLayout = () => { | ||
setAttributes( { hasFixedLayout: ! hasFixedLayout } ); | ||
}; | ||
|
||
const classes = classnames( | ||
className, | ||
{ | ||
'has-fixed-layout': hasFixedLayout, | ||
}, | ||
); | ||
|
||
return ( | ||
<Fragment> | ||
<BlockControls> | ||
|
@@ -103,22 +125,40 @@ export const settings = { | |
onChange={ updateAlignment } | ||
/> | ||
</BlockControls> | ||
<InspectorControls> | ||
<PanelBody title={ __( 'Table Settings' ) } className="blocks-table-settings"> | ||
<ToggleControl | ||
label={ __( 'Fixed width table cells' ) } | ||
checked={ !! hasFixedLayout } | ||
onChange={ toggleFixedLayout } | ||
/> | ||
</PanelBody> | ||
</InspectorControls> | ||
<TableBlock | ||
onChange={ ( nextContent ) => { | ||
setAttributes( { content: nextContent } ); | ||
} } | ||
content={ content } | ||
className={ className } | ||
className={ classes } | ||
isSelected={ isSelected } | ||
/> | ||
</Fragment> | ||
); | ||
}, | ||
|
||
save( { attributes } ) { | ||
const { content, align } = attributes; | ||
save( { attributes, className } ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's no className prop passed to the |
||
const { content, align, hasFixedLayout } = attributes; | ||
|
||
const classes = classnames( | ||
className, | ||
{ | ||
'has-fixed-layout': hasFixedLayout, | ||
[ `align${ align }` ]: align, | ||
}, | ||
); | ||
|
||
return ( | ||
<RichText.Content tagName="table" className={ align ? `align${ align }` : null } value={ content } /> | ||
<RichText.Content tagName="table" className={ classes } value={ content } /> | ||
); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,23 @@ | ||
.wp-block-table { | ||
overflow-x: auto; | ||
display: block; | ||
border-collapse: collapse; | ||
width: 100%; | ||
|
||
table { | ||
border-collapse: collapse; | ||
tbody { | ||
width: 100%; | ||
display: table; | ||
min-width: $break-mobile / 2; | ||
} | ||
|
||
td, | ||
th { | ||
padding: 0.5em; | ||
border: 1px solid currentColor; | ||
} | ||
|
||
// Fixed layout toggle | ||
&.has-fixed-layout tbody { | ||
table-layout: fixed; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should these styles be applied only within the context of the table block? As implemented, these will impact any table on the screen, regardless of within the block. Even if they're desirable globally, I don't think the styles should be implemented here (since a block's styles shouldn't be impacting the page as a whole).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wish I could scope these to be table block specific only. However these elements are inserted into the root of the DOM.
I can move them to the main stylesheet if you like?