Skip to content

Commit

Permalink
Keep legacy styling
Browse files Browse the repository at this point in the history
  • Loading branch information
mirka committed Dec 6, 2021
1 parent fc7bb08 commit 05b3631
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 5 deletions.
44 changes: 41 additions & 3 deletions packages/block-editor/src/components/line-height-control/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
/**
* External dependencies
*/
import classNames from 'classnames';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { TextControl } from '@wordpress/components';
import {
__experimentalNumberControl as NumberControl,
TextControl,
} from '@wordpress/components';
import { ZERO } from '@wordpress/keycodes';

/**
Expand All @@ -15,7 +23,8 @@ import {
isLineHeightDefined,
} from './utils';

export default function LineHeightControl( { value: lineHeight, onChange } ) {
// TODO: Remove before merging
export function LegacyLineHeightControl( { value: lineHeight, onChange } ) {
const isDefined = isLineHeightDefined( lineHeight );

const handleOnKeyDown = ( event ) => {
Expand Down Expand Up @@ -64,7 +73,7 @@ export default function LineHeightControl( { value: lineHeight, onChange } ) {
const value = isDefined ? lineHeight : RESET_VALUE;

return (
<div className="block-editor-line-height-control">
<div className="block-editor-line-height-control-legacy">
<TextControl
autoComplete="off"
onKeyDown={ handleOnKeyDown }
Expand All @@ -79,3 +88,32 @@ export default function LineHeightControl( { value: lineHeight, onChange } ) {
</div>
);
}

export default function LineHeightControl( {
value: lineHeight,
onChange,
__unstableHasLegacyStyles = true,
} ) {
const isDefined = isLineHeightDefined( lineHeight );
const value = isDefined ? lineHeight : RESET_VALUE;

return (
<div
className={ classNames( 'block-editor-line-height-control', {
'has-legacy-styles': __unstableHasLegacyStyles,
} ) }
>
<NumberControl
__unstableInputWidth={
__unstableHasLegacyStyles ? '60px' : undefined
}
onChange={ onChange }
label={ __( 'Line height' ) }
placeholder={ BASE_DEFAULT_VALUE }
step={ STEP }
value={ value }
min={ 0 }
/>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useState } from '@wordpress/element';
/**
* Internal dependencies
*/
import LineHeightControl from '../';
import LineHeightControl, { LegacyLineHeightControl } from '../';

export default {
component: LineHeightControl,
Expand All @@ -30,3 +30,36 @@ const Template = ( props ) => {
};

export const Default = Template.bind( {} );
Default.args = {
__unstableHasLegacyStyles: true,
};

// TODO: Remove before merge
export const TemporaryTest = () => {
const [ value, setValue ] = useState();
return (
<div
style={ {
display: 'grid',
gap: 20,
gridTemplateColumns: '1fr 1fr',
width: 300,
} }
>
<div>
<h2>Migrated</h2>
<Template />
</div>
<div>
<h2>Legacy</h2>
<LegacyLineHeightControl
onChange={ setValue }
value={ value }
/>
<hr />
<p>value: { value }</p>
<p>type: { typeof value }</p>
</div>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,21 @@
.block-editor-line-height-control {
// TODO: Remove this class before merging
.block-editor-line-height-control-legacy {
margin-bottom: 24px;

input {
display: block;
max-width: 60px;
}
}
// end TODO

.block-editor-line-height-control {
&.has-legacy-styles {
margin-bottom: 24px;
line-height: 1.4;

.components-input-control__container {
margin-top: 4px;
}
}
}

0 comments on commit 05b3631

Please sign in to comment.