Skip to content

Commit

Permalink
RangeControl: Add support for large 40px number input size (WordPress…
Browse files Browse the repository at this point in the history
…#49105)

Co-authored-by: chad1008 <13856531+chad1008@users.noreply.github.com>
  • Loading branch information
2 people authored and sethrubenstein committed Jul 13, 2023
1 parent 2134899 commit 799f353
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

// Reset unwanted margin-bottom from being applied to BaseControls within certain components.
.components-focal-point-picker-control,
.components-query-controls {
.components-query-controls,
.components-range-control {
.components-base-control {
margin-bottom: 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ export default function CoverInspectorControls( {
max={ 100 }
step={ 10 }
required
__next40pxDefaultSize
/>
</ToolsPanelItem>
</InspectorControls>
Expand Down
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- `SelectControl`: Added option to set hidden options. ([#51545](https://github.com/WordPress/gutenberg/pull/51545))
- `UnitControl`: Revamp support for changing unit by typing ([#39303](https://github.com/WordPress/gutenberg/pull/39303)).
- `RangeControl`: Add `__next40pxDefaultSize` prop to opt into the new 40px default size ([#49105](https://github.com/WordPress/gutenberg/pull/49105)).
- `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)).
- `Button`: Introduce `size` prop with `default`, `compact`, and `small` variants ([#51842](https://github.com/WordPress/gutenberg/pull/51842)).
- `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)).
Expand Down
1 change: 0 additions & 1 deletion packages/components/src/number-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ function UnforwardedNumberControl(
} );
spinControls = 'none';
}

const inputRef = useRef< HTMLInputElement >();
const mergedRef = useMergeRefs( [ inputRef, forwardedRef ] );

Expand Down
16 changes: 14 additions & 2 deletions packages/components/src/range-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {

import type { RangeControlProps } from './types';
import type { WordPressComponentProps } from '../ui/context';
import { space } from '../ui/utils/space';

const noop = () => {};

Expand Down Expand Up @@ -69,6 +70,7 @@ function UnforwardedRangeControl(
railColor,
renderTooltipContent = ( v ) => v,
resetFallbackValue,
__next40pxDefaultSize = false,
shiftStep = 10,
showTooltip: showTooltipProp,
step = 1,
Expand Down Expand Up @@ -208,7 +210,6 @@ function UnforwardedRangeControl(
const offsetStyle = {
[ isRTL() ? 'right' : 'left' ]: fillValueOffset,
};

return (
<BaseControl
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
Expand All @@ -218,7 +219,10 @@ function UnforwardedRangeControl(
id={ `${ id }` }
help={ help }
>
<Root className="components-range-control__root">
<Root
className="components-range-control__root"
__next40pxDefaultSize={ __next40pxDefaultSize }
>
{ beforeIcon && (
<BeforeIconWrapper>
<Icon icon={ beforeIcon } />
Expand Down Expand Up @@ -305,6 +309,14 @@ function UnforwardedRangeControl(
onBlur={ handleOnInputNumberBlur }
onChange={ handleOnChange }
shiftStep={ shiftStep }
size={
__next40pxDefaultSize
? '__unstable-large'
: 'default'
}
__unstableInputWidth={
__next40pxDefaultSize ? space( 20 ) : space( 16 )
}
step={ step }
// @ts-expect-error TODO: Investigate if the `null` value is necessary
value={ inputSliderValue }
Expand Down
1 change: 0 additions & 1 deletion packages/components/src/range-control/input-range.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ function InputRange(
ref: React.ForwardedRef< HTMLInputElement >
) {
const { describedBy, label, value, ...otherProps } = props;

return (
<BaseInputRange
{ ...otherProps }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import type {
TooltipProps,
TrackProps,
WrapperProps,
RangeControlProps,
} from '../types';

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

export const Root = styled.div`
const deprecatedHeight = ( {
__next40pxDefaultSize,
}: Pick< RangeControlProps, '__next40pxDefaultSize' > ) =>
! __next40pxDefaultSize && css( { minHeight: rangeHeightValue } );

type RootProps = Pick< RangeControlProps, '__next40pxDefaultSize' >;
export const Root = styled.div< RootProps >`
-webkit-tap-highlight-color: transparent;
align-items: flex-start;
align-items: center;
display: flex;
justify-content: flex-start;
padding: 0;
position: relative;
touch-action: none;
width: 100%;
min-height: 40px;
/* TODO: remove after removing the __next40pxDefaultSize prop */
${ deprecatedHeight };
`;

const wrapperColor = ( { color = COLORS.ui.borderFocus }: WrapperProps ) =>
Expand Down Expand Up @@ -296,7 +306,6 @@ export const InputNumber = styled( NumberControl )`
display: inline-block;
font-size: 13px;
margin-top: 0;
width: ${ space( 16 ) } !important;
input[type='number']& {
${ rangeHeight };
Expand Down
6 changes: 6 additions & 0 deletions packages/components/src/range-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,12 @@ export type RangeControlProps = Pick<
* @default 10
*/
shiftStep?: number;
/**
* Start opting into the larger default height that will become the default size in a future version.
*
* @default false
*/
__next40pxDefaultSize?: boolean;
/**
* Forcing the Tooltip UI to show or hide. This is overridden to `false`
* when `step` is set to the special string value `any`.
Expand Down

0 comments on commit 799f353

Please sign in to comment.