-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Introduce a ResizableBox component #10347
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
Merged
chrisvanpatten
merged 7 commits into
WordPress:master
from
TomodomoCo:feature/resizable-box-component
Oct 7, 2018
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
aa1acad
Introduce a ResizableBox component and apply to image/spacer blocks
chrisvanpatten c847d00
Add a shared class to all drag handles to simplify CSS selectors
chrisvanpatten c06e8e9
Add additional documentation and an example
chrisvanpatten 3d00599
chore: Tweak docs
tofumatt d3dc6d7
Add changelog comment and update readme
chrisvanpatten 7f07c4e
Removed a stray "the"
chrisvanpatten 29afb11
s/5.0.0/4.1.0/g
chrisvanpatten 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
Next
Next commit
Introduce a ResizableBox component and apply to image/spacer blocks
- Loading branch information
commit aa1acadbfe1570631ea233a480e495b76af4407c
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,22 +1,3 @@ | ||
| .block-library-spacer__resize-container.is-selected { | ||
| .block-library-spacer__resize-handler-bottom { | ||
| display: block; | ||
| } | ||
| } | ||
|
|
||
| .block-library-spacer__resize-container.is-selected { | ||
| background: $light-gray-200; | ||
| } | ||
|
|
||
| .block-library-spacer__resize-handler-bottom { | ||
| @include resize-handler__container(); | ||
|
|
||
| // Offset the handle container's position. | ||
| position: absolute; | ||
| bottom: calc(#{$resize-handler-container-size / 2} * -1); | ||
| left: calc(50% - #{$resize-handler-container-size / 2}); | ||
| } | ||
|
|
||
| .block-library-spacer__resize-handler-bottom::before { | ||
| @include resize-handler__visible-handle(); | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| # ResizableBox | ||
|
|
||
| ResizableBox is a wrapper around the [re-resizable package](https://github.com/bokuweb/re-resizable) with pre-defined classes and styles. | ||
|
|
||
|
|
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| /** | ||
| * External dependencies | ||
| */ | ||
| import classnames from 'classnames'; | ||
| import ReResizableBox from 're-resizable'; | ||
|
|
||
| function ResizableBox( { className, ...props } ) { | ||
| // Removes the inline styles in the drag handles. | ||
| const handleStylesOverrides = { | ||
| width: null, | ||
| height: null, | ||
| top: null, | ||
| right: null, | ||
| bottom: null, | ||
| left: null, | ||
| }; | ||
|
|
||
| return ( | ||
| <ReResizableBox | ||
| className={ classnames( | ||
| 'components-resizable-box__container', | ||
| className, | ||
| ) } | ||
| handleClasses={ { | ||
| top: 'components-resizable-box__handle-top', | ||
| right: 'components-resizable-box__handle-right', | ||
| bottom: 'components-resizable-box__handle-bottom', | ||
| left: 'components-resizable-box__handle-left', | ||
| } } | ||
| handleStyles={ { | ||
| top: handleStylesOverrides, | ||
| right: handleStylesOverrides, | ||
| bottom: handleStylesOverrides, | ||
| left: handleStylesOverrides, | ||
| } } | ||
| { ...props } | ||
| /> | ||
| ); | ||
| } | ||
|
|
||
| export default ResizableBox; |
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| .components-resizable-box__handle-top, | ||
| .components-resizable-box__handle-right, | ||
| .components-resizable-box__handle-bottom, | ||
| .components-resizable-box__handle-left { | ||
| display: none; | ||
|
|
||
| // Show the resize handle when selected. | ||
| .components-resizable-box__container.is-selected & { | ||
| display: block; | ||
| } | ||
|
|
||
| // The handle itself is a pseudo element, and will sit inside this larger | ||
| // container size. | ||
| width: $resize-handler-container-size; | ||
| height: $resize-handler-container-size; | ||
| padding: $grid-size-small; | ||
| } | ||
|
|
||
| .components-resizable-box__handle-top::before, | ||
| .components-resizable-box__handle-right::before, | ||
| .components-resizable-box__handle-bottom::before, | ||
| .components-resizable-box__handle-left::before { | ||
| display: block; | ||
| content: ""; | ||
| width: $resize-handler-size; | ||
| height: $resize-handler-size; | ||
| border: 2px solid $white; | ||
| border-radius: 50%; | ||
| background: theme(primary); | ||
| cursor: inherit; | ||
| } | ||
|
|
||
| /*!rtl:begin:ignore*/ | ||
| .components-resizable-box__handle-right { | ||
| top: calc(50% - #{$resize-handler-container-size / 2}); | ||
| right: calc(#{$resize-handler-container-size / 2} * -1); | ||
| } | ||
|
|
||
| .components-resizable-box__handle-bottom { | ||
| bottom: calc(#{$resize-handler-container-size / 2} * -1); | ||
| left: calc(50% - #{$resize-handler-container-size / 2}); | ||
| } | ||
|
|
||
| .components-resizable-box__handle-left { | ||
| top: calc(50% - #{$resize-handler-container-size / 2}); | ||
| left: calc(#{$resize-handler-container-size / 2} * -1); | ||
| } | ||
| /*!rtl:end:ignore*/ | ||
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.
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.
Where do we document how a resizable box becomes "selected" to unhide itself? The current documentation for
ResizableBoxhas no indication of this default hidden state. It was quite the journey to find my way here, as I've found it quite difficult to use the component with the documentation as written.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.
The behavior here was inherited from the original, non-componentized usages of ResizableBox; you can see it in previous PRs as well such as here.
There are probably other use-cases that would provide more valuable context, and could certainly be referenced and improved in the documentation.
Uh oh!
There was an error while loading. Please reload this page.
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.
While I'd agree it often needs contextualized styling, the main problem for me was that in using the example from the documentation, there is nothing visual which appears. It took me quite a while to realize that the handles are hidden by default.
I understand this is largely a result of how it was used prior to this pull request, but it seems to me that as a generic component, there's no reason to hide those controls by default. I could imagine we might want to keep this behavior for blocks in a block list, but rather than styling in ResizableBox and in individual block stylesheets, it seems like something which should be managed in one of the stylesheets for the block list (apply consistently and exclusively to ResizableBox within blocks).
I could create an issue if it seems reasonable.