forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LineHeightControl: Migrate internals to
NumberControl
(WordPress#37160
) * Add story for LineHeightControl * Keep legacy styling * Add deprecation warning * Update docs * Update changelog * Update style deprecation to match new guidelines * Update usage in Typography Panel * Update usage in Global Styles * Update docs * Tweak stories * Update story for ToolsPanel * Add deprecation note to prop readme * LineHeightControl: Migrate internals to `NumberControl` (Part 2: Behavior) (WordPress#37164) * Maintain previous behavior via state reducer * Add tests * Add comment about strange reducer behavior * Fix tests * Remove temporary code
- Loading branch information
Showing
12 changed files
with
193 additions
and
60 deletions.
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