-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
LineHeightControl: Enhance interactions by migrating internals to NumberControl
on Style options.
#37160
Merged
Merged
LineHeightControl: Enhance interactions by migrating internals to NumberControl
on Style options.
#37160
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8dd786b
Add story for LineHeightControl
mirka d0ad242
Keep legacy styling
mirka 3dd0171
Add deprecation warning
mirka f9ff0a3
Update docs
mirka b8d0660
Update changelog
mirka a8eabce
Update style deprecation to match new guidelines
mirka 56d86ec
Update usage in Typography Panel
mirka ec0b9ad
Update usage in Global Styles
mirka f5c7dbf
Update docs
mirka 9440108
Tweak stories
mirka 8744cc1
Update story for ToolsPanel
mirka d56a3c1
Add deprecation note to prop readme
mirka d4e38a0
LineHeightControl: Migrate internals to `NumberControl` (Part 2: Beha…
mirka e379dd3
Remove temporary code
mirka 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
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
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
33 changes: 33 additions & 0 deletions
33
packages/block-editor/src/components/line-height-control/stories/index.js
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState } from '@wordpress/element'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import LineHeightControl from '../'; | ||
|
||
export default { | ||
component: LineHeightControl, | ||
title: 'BlockEditor/LineHeightControl', | ||
}; | ||
|
||
const Template = ( props ) => { | ||
const [ value, setValue ] = useState(); | ||
return ( | ||
<LineHeightControl onChange={ setValue } value={ value } { ...props } /> | ||
); | ||
}; | ||
|
||
export const Default = Template.bind( {} ); | ||
Default.args = { | ||
__nextHasNoMarginBottom: true, | ||
__unstableInputWidth: '60px', | ||
}; | ||
|
||
export const UnconstrainedWidth = Template.bind( {} ); | ||
UnconstrainedWidth.args = { | ||
...Default.args, | ||
__unstableInputWidth: '100%', | ||
}; |
8 changes: 0 additions & 8 deletions
8
packages/block-editor/src/components/line-height-control/style.scss
This file was deleted.
Oops, something went wrong.
61 changes: 61 additions & 0 deletions
61
packages/block-editor/src/components/line-height-control/test/index.js
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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { fireEvent, render, screen } from '@testing-library/react'; | ||
|
||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useState } from '@wordpress/element'; | ||
import { UP, DOWN } from '@wordpress/keycodes'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import LineHeightControl from '../'; | ||
import { BASE_DEFAULT_VALUE, STEP } from '../utils'; | ||
|
||
const ControlledLineHeightControl = () => { | ||
const [ value, setValue ] = useState(); | ||
return ( | ||
<LineHeightControl | ||
value={ value } | ||
onChange={ setValue } | ||
__nextHasNoMarginBottom={ true } | ||
/> | ||
); | ||
}; | ||
|
||
describe( 'LineHeightControl', () => { | ||
it( 'should immediately step up from the default value if up-arrowed from an unset state', () => { | ||
render( <ControlledLineHeightControl /> ); | ||
const input = screen.getByRole( 'spinbutton' ); | ||
input.focus(); | ||
fireEvent.keyDown( input, { keyCode: UP } ); | ||
expect( input ).toHaveValue( BASE_DEFAULT_VALUE + STEP ); | ||
} ); | ||
|
||
it( 'should immediately step down from the default value if down-arrowed from an unset state', () => { | ||
render( <ControlledLineHeightControl /> ); | ||
const input = screen.getByRole( 'spinbutton' ); | ||
input.focus(); | ||
fireEvent.keyDown( input, { keyCode: DOWN } ); | ||
expect( input ).toHaveValue( BASE_DEFAULT_VALUE - STEP ); | ||
} ); | ||
|
||
it( 'should immediately step up from the default value if spin button up was clicked from an unset state', () => { | ||
render( <ControlledLineHeightControl /> ); | ||
const input = screen.getByRole( 'spinbutton' ); | ||
input.focus(); | ||
fireEvent.change( input, { target: { value: 0.1 } } ); // simulates click on spin button up | ||
expect( input ).toHaveValue( BASE_DEFAULT_VALUE + STEP ); | ||
} ); | ||
|
||
it( 'should immediately step down from the default value if spin button down was clicked from an unset state', () => { | ||
render( <ControlledLineHeightControl /> ); | ||
const input = screen.getByRole( 'spinbutton' ); | ||
input.focus(); | ||
fireEvent.change( input, { target: { value: 0 } } ); // simulates click on spin button down | ||
expect( input ).toHaveValue( BASE_DEFAULT_VALUE - STEP ); | ||
} ); | ||
} ); |
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
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
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
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
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
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.
I hope this is simple and ephemeral enough to put in here as an inline style. The
@wordpress/block-editor
package itself doesn't really use Emotion yet, and we can avoid a hardcoded classname here if we just do it inline.