Skip to content

Commit 40f841c

Browse files
richtaborchad1008
andauthored
RangeControl: Add support for large 40px number input size (#49105)
Co-authored-by: chad1008 <13856531+chad1008@users.noreply.github.com>
1 parent 31d691d commit 40f841c

File tree

8 files changed

+36
-8
lines changed

8 files changed

+36
-8
lines changed

packages/block-editor/src/components/block-inspector/style.scss

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
// Reset unwanted margin-bottom from being applied to BaseControls within certain components.
2222
.components-focal-point-picker-control,
23-
.components-query-controls {
23+
.components-query-controls,
24+
.components-range-control {
2425
.components-base-control {
2526
margin-bottom: 0;
2627
}

packages/block-library/src/cover/edit/inspector-controls.js

+1
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ export default function CoverInspectorControls( {
303303
max={ 100 }
304304
step={ 10 }
305305
required
306+
__next40pxDefaultSize
306307
/>
307308
</ToolsPanelItem>
308309
</InspectorControls>

packages/components/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
- `SelectControl`: Added option to set hidden options. ([#51545](https://github.com/WordPress/gutenberg/pull/51545))
88
- `UnitControl`: Revamp support for changing unit by typing ([#39303](https://github.com/WordPress/gutenberg/pull/39303)).
9+
- `RangeControl`: Add `__next40pxDefaultSize` prop to opt into the new 40px default size ([#49105](https://github.com/WordPress/gutenberg/pull/49105)).
910
- `Modal`: Update corner radius to be between buttons and the site view frame, in a 2-4-8 system. ([#51254](https://github.com/WordPress/gutenberg/pull/51254)).
1011
- `Button`: Introduce `size` prop with `default`, `compact`, and `small` variants ([#51842](https://github.com/WordPress/gutenberg/pull/51842)).
1112
- `ItemGroup`: Update button focus state styles to be inline with other button focus states in the editor. ([#51576](https://github.com/WordPress/gutenberg/pull/51576)).

packages/components/src/number-control/index.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ function UnforwardedNumberControl(
6060
} );
6161
spinControls = 'none';
6262
}
63-
6463
const inputRef = useRef< HTMLInputElement >();
6564
const mergedRef = useMergeRefs( [ inputRef, forwardedRef ] );
6665

packages/components/src/range-control/index.tsx

+14-2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import {
3737

3838
import type { RangeControlProps } from './types';
3939
import type { WordPressComponentProps } from '../ui/context';
40+
import { space } from '../ui/utils/space';
4041

4142
const noop = () => {};
4243

@@ -69,6 +70,7 @@ function UnforwardedRangeControl(
6970
railColor,
7071
renderTooltipContent = ( v ) => v,
7172
resetFallbackValue,
73+
__next40pxDefaultSize = false,
7274
shiftStep = 10,
7375
showTooltip: showTooltipProp,
7476
step = 1,
@@ -208,7 +210,6 @@ function UnforwardedRangeControl(
208210
const offsetStyle = {
209211
[ isRTL() ? 'right' : 'left' ]: fillValueOffset,
210212
};
211-
212213
return (
213214
<BaseControl
214215
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
@@ -218,7 +219,10 @@ function UnforwardedRangeControl(
218219
id={ `${ id }` }
219220
help={ help }
220221
>
221-
<Root className="components-range-control__root">
222+
<Root
223+
className="components-range-control__root"
224+
__next40pxDefaultSize={ __next40pxDefaultSize }
225+
>
222226
{ beforeIcon && (
223227
<BeforeIconWrapper>
224228
<Icon icon={ beforeIcon } />
@@ -305,6 +309,14 @@ function UnforwardedRangeControl(
305309
onBlur={ handleOnInputNumberBlur }
306310
onChange={ handleOnChange }
307311
shiftStep={ shiftStep }
312+
size={
313+
__next40pxDefaultSize
314+
? '__unstable-large'
315+
: 'default'
316+
}
317+
__unstableInputWidth={
318+
__next40pxDefaultSize ? space( 20 ) : space( 16 )
319+
}
308320
step={ step }
309321
// @ts-expect-error TODO: Investigate if the `null` value is necessary
310322
value={ inputSliderValue }

packages/components/src/range-control/input-range.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ function InputRange(
1616
ref: React.ForwardedRef< HTMLInputElement >
1717
) {
1818
const { describedBy, label, value, ...otherProps } = props;
19-
2019
return (
2120
<BaseInputRange
2221
{ ...otherProps }

packages/components/src/range-control/styles/range-control-styles.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import type {
1818
TooltipProps,
1919
TrackProps,
2020
WrapperProps,
21+
RangeControlProps,
2122
} from '../types';
2223

2324
const rangeHeightValue = 30;
@@ -26,15 +27,24 @@ const rangeHeight = () =>
2627
css( { height: rangeHeightValue, minHeight: rangeHeightValue } );
2728
const thumbSize = 12;
2829

29-
export const Root = styled.div`
30+
const deprecatedHeight = ( {
31+
__next40pxDefaultSize,
32+
}: Pick< RangeControlProps, '__next40pxDefaultSize' > ) =>
33+
! __next40pxDefaultSize && css( { minHeight: rangeHeightValue } );
34+
35+
type RootProps = Pick< RangeControlProps, '__next40pxDefaultSize' >;
36+
export const Root = styled.div< RootProps >`
3037
-webkit-tap-highlight-color: transparent;
31-
align-items: flex-start;
38+
align-items: center;
3239
display: flex;
3340
justify-content: flex-start;
3441
padding: 0;
3542
position: relative;
3643
touch-action: none;
3744
width: 100%;
45+
min-height: 40px;
46+
/* TODO: remove after removing the __next40pxDefaultSize prop */
47+
${ deprecatedHeight };
3848
`;
3949

4050
const wrapperColor = ( { color = COLORS.ui.borderFocus }: WrapperProps ) =>
@@ -296,7 +306,6 @@ export const InputNumber = styled( NumberControl )`
296306
display: inline-block;
297307
font-size: 13px;
298308
margin-top: 0;
299-
width: ${ space( 16 ) } !important;
300309
301310
input[type='number']& {
302311
${ rangeHeight };

packages/components/src/range-control/types.ts

+6
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ export type RangeControlProps = Pick<
203203
* @default 10
204204
*/
205205
shiftStep?: number;
206+
/**
207+
* Start opting into the larger default height that will become the default size in a future version.
208+
*
209+
* @default false
210+
*/
211+
__next40pxDefaultSize?: boolean;
206212
/**
207213
* Forcing the Tooltip UI to show or hide. This is overridden to `false`
208214
* when `step` is set to the special string value `any`.

0 commit comments

Comments
 (0)