Skip to content
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

InputControl-based components: Add opt-in prop for next 40px default size #53819

Merged
merged 13 commits into from
Sep 29, 2023
2 changes: 1 addition & 1 deletion packages/block-editor/src/hooks/position.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ export function PositionPanel( props ) {
>
<CustomSelectControl
__nextUnconstrainedWidth
__next36pxDefaultSize
__next40pxDefaultSize
className="block-editor-hooks__position-selection__select-control"
label={ __( 'Position' ) }
hideLabelFromVision
Expand Down
8 changes: 6 additions & 2 deletions packages/block-library/src/rss/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +69,19 @@ export default function RSSEdit( { attributes, setAttributes } ) {
>
<HStack wrap>
<InputControl
__next36pxDefaultSize
__next40pxDefaultSize
placeholder={ __( 'Enter URL here…' ) }
value={ feedURL }
onChange={ ( value ) =>
setAttributes( { feedURL: value } )
}
className="wp-block-rss__placeholder-input"
/>
<Button variant="primary" type="submit">
<Button
__next40pxDefaultSize
variant="primary"
type="submit"
>
{ __( 'Use URL' ) }
</Button>
</HStack>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function TemplatePartImportControls( { area, setAttributes } ) {
options={ options }
onChange={ ( value ) => setSelectedSidebar( value ) }
disabled={ ! options.length }
__next36pxDefaultSize
__next40pxDefaultSize
__nextHasNoMarginBottom
/>
</FlexBlock>
Expand All @@ -158,6 +158,7 @@ export function TemplatePartImportControls( { area, setAttributes } ) {
} }
>
<Button
__next40pxDefaultSize
variant="primary"
type="submit"
isBusy={ isBusy }
Expand Down
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- `Button`: deprecating `isPressed` prop in favour of `aria-pressed` ([#54740](https://github.com/WordPress/gutenberg/pull/54740)).
- `DuotonePicker/ColorListPicker`: Adds appropriate label and description to 'Duotone Filter' picker ([#54473](https://github.com/WordPress/gutenberg/pull/54473)).
- `Modal`: Accessibly hide/show outer modal when nested ([#54743](https://github.com/WordPress/gutenberg/pull/54743)).
- `InputControl`, `NumberControl`, `UnitControl`, `SelectControl`, `CustomSelectControl`, `TreeSelect`: Add opt-in prop for next 40px default size, superseding the `__next36pxDefaultSize` prop ([#53819](https://github.com/WordPress/gutenberg/pull/53819)).

### Bug Fix

Expand Down
17 changes: 11 additions & 6 deletions packages/components/src/custom-select-control/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { Select as SelectControlSelect } from '../select-control/styles/select-c
import SelectControlChevronDown from '../select-control/chevron-down';
import { InputBaseWithBackCompatMinWidth } from './styles';
import { StyledLabel } from '../base-control/styles/base-control-styles';
import { useDeprecated36pxDefaultSizeProp } from '../utils/use-deprecated-props';

const itemToString = ( item ) => item?.name;
// This is needed so that in Windows, where
Expand Down Expand Up @@ -65,7 +66,7 @@ const stateReducer = (
export default function CustomSelectControl( props ) {
const {
/** Start opting into the larger default height that will become the default size in a future version. */
__next36pxDefaultSize = false,
__next40pxDefaultSize = false,
/** Start opting into the unconstrained width that will become the default in a future version. */
__nextUnconstrainedWidth = false,
className,
Expand All @@ -82,7 +83,11 @@ export default function CustomSelectControl( props ) {
onFocus,
onBlur,
__experimentalShowSelectedHint = false,
} = props;
} = useDeprecated36pxDefaultSizeProp(
props,
'wp.components.CustomSelectControl',
'6.4'
);

const {
getLabelProps,
Expand Down Expand Up @@ -180,7 +185,7 @@ export default function CustomSelectControl( props ) {
</StyledLabel>
) }
<InputBaseWithBackCompatMinWidth
__next36pxDefaultSize={ __next36pxDefaultSize }
__next40pxDefaultSize={ __next40pxDefaultSize }
__nextUnconstrainedWidth={ __nextUnconstrainedWidth }
isFocused={ isOpen || isFocused }
__unstableInputWidth={
Expand All @@ -197,7 +202,7 @@ export default function CustomSelectControl( props ) {
onFocus={ handleOnFocus }
onBlur={ handleOnBlur }
selectSize={ size }
__next36pxDefaultSize={ __next36pxDefaultSize }
__next40pxDefaultSize={ __next40pxDefaultSize }
{ ...getToggleButtonProps( {
// This is needed because some speech recognition software don't support `aria-labelledby`.
'aria-label': label,
Expand Down Expand Up @@ -232,8 +237,8 @@ export default function CustomSelectControl( props ) {
'is-highlighted':
index === highlightedIndex,
'has-hint': !! item.__experimentalHint,
'is-next-36px-default-size':
__next36pxDefaultSize,
'is-next-40px-default-size':
__next40pxDefaultSize,
}
),
style: item.style,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default {
title: 'Components/CustomSelectControl',
component: CustomSelectControl,
argTypes: {
__next36pxDefaultSize: { control: { type: 'boolean' } },
__next40pxDefaultSize: { control: { type: 'boolean' } },
__experimentalShowSelectedHint: { control: { type: 'boolean' } },
size: {
options: [ 'small', 'default', '__unstable-large' ],
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/custom-select-control/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
cursor: default;
line-height: $icon-size + $grid-unit-05;

&:not(.is-next-36px-default-size) {
&:not(.is-next-40px-default-size) {
padding: $grid-unit-10;
}

Expand Down
15 changes: 9 additions & 6 deletions packages/components/src/date-time/time/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { __ } from '@wordpress/i18n';
import BaseControl from '../../base-control';
import Button from '../../button';
import ButtonGroup from '../../button-group';
import SelectControl from '../../select-control';
import TimeZone from './timezone';
import type { TimePickerProps } from '../types';
import {
Expand All @@ -24,7 +25,6 @@ import {
TimeSeparator,
MinutesInput,
MonthSelectWrapper,
MonthSelect,
DayInput,
YearInput,
TimeWrapper,
Expand Down Expand Up @@ -181,7 +181,7 @@ export function TimePicker( {
className="components-datetime__time-field components-datetime__time-field-day" // Unused, for backwards compatibility.
label={ __( 'Day' ) }
hideLabelFromVision
__next36pxDefaultSize
__next40pxDefaultSize
value={ day }
step={ 1 }
min={ 1 }
Expand All @@ -197,10 +197,11 @@ export function TimePicker( {

const monthField = (
<MonthSelectWrapper>
<MonthSelect
<SelectControl
chad1008 marked this conversation as resolved.
Show resolved Hide resolved
className="components-datetime__time-field components-datetime__time-field-month" // Unused, for backwards compatibility.
label={ __( 'Month' ) }
hideLabelFromVision
__next40pxDefaultSize
__nextHasNoMarginBottom
value={ month }
options={ [
Expand Down Expand Up @@ -247,7 +248,7 @@ export function TimePicker( {
className="components-datetime__time-field-hours-input" // Unused, for backwards compatibility.
label={ __( 'Hours' ) }
hideLabelFromVision
__next36pxDefaultSize
__next40pxDefaultSize
value={ hours }
step={ 1 }
min={ is12Hour ? 1 : 0 }
Expand All @@ -274,7 +275,7 @@ export function TimePicker( {
className="components-datetime__time-field-minutes-input" // Unused, for backwards compatibility.
label={ __( 'Minutes' ) }
hideLabelFromVision
__next36pxDefaultSize
__next40pxDefaultSize
value={ minutes }
step={ 1 }
min={ 0 }
Expand All @@ -301,6 +302,7 @@ export function TimePicker( {
variant={
am === 'AM' ? 'primary' : 'secondary'
}
__next40pxDefaultSize
onClick={ buildAmPmChangeCallback( 'AM' ) }
>
{ __( 'AM' ) }
Expand All @@ -310,6 +312,7 @@ export function TimePicker( {
variant={
am === 'PM' ? 'primary' : 'secondary'
}
__next40pxDefaultSize
onClick={ buildAmPmChangeCallback( 'PM' ) }
>
{ __( 'PM' ) }
Expand Down Expand Up @@ -345,7 +348,7 @@ export function TimePicker( {
className="components-datetime__time-field components-datetime__time-field-year" // Unused, for backwards compatibility.
label={ __( 'Year' ) }
hideLabelFromVision
__next36pxDefaultSize
__next40pxDefaultSize
value={ year }
step={ 1 }
min={ 1 }
Expand Down
10 changes: 0 additions & 10 deletions packages/components/src/date-time/time/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ import {
BackdropUI,
} from '../../input-control/styles/input-control-styles';
import NumberControl from '../../number-control';
import SelectControl from '../../select-control';
import { Select } from '../../select-control/styles/select-control-styles';

export const Wrapper = styled.div`
box-sizing: border-box;
Expand Down Expand Up @@ -92,14 +90,6 @@ export const MonthSelectWrapper = styled.div`
flex-grow: 1;
`;

export const MonthSelect = styled( SelectControl )`
height: 36px;

${ Select } {
line-height: 30px;
}
`;

export const DayInput = styled( NumberControl )`
${ baseInput }

Expand Down
27 changes: 17 additions & 10 deletions packages/components/src/input-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import type { InputControlProps } from './types';
import { space } from '../ui/utils/space';
import { useDraft } from './utils';
import BaseControl from '../base-control';
import { useDeprecated36pxDefaultSizeProp } from '../utils/use-deprecated-props';

const noop = () => {};

Expand All @@ -30,8 +31,11 @@ function useUniqueId( idProp?: string ) {
}

export function UnforwardedInputControl(
{
__next36pxDefaultSize,
props: InputControlProps,
ref: ForwardedRef< HTMLInputElement >
) {
const {
__next40pxDefaultSize,
__unstableStateReducer: stateReducer = ( state ) => state,
__unstableInputWidth,
className,
Expand All @@ -50,18 +54,21 @@ export function UnforwardedInputControl(
style,
suffix,
value,
...props
}: InputControlProps,
ref: ForwardedRef< HTMLInputElement >
) {
...restProps
} = useDeprecated36pxDefaultSizeProp< InputControlProps >(
props,
'wp.components.InputControl',
'6.4'
);

const [ isFocused, setIsFocused ] = useState( false );

const id = useUniqueId( idProp );
const classes = classNames( 'components-input-control', className );

const draftHookProps = useDraft( {
value,
onBlur: props.onBlur,
onBlur: restProps.onBlur,
onChange,
} );

Expand All @@ -78,7 +85,7 @@ export function UnforwardedInputControl(
__nextHasNoMarginBottom
>
<InputBase
__next36pxDefaultSize={ __next36pxDefaultSize }
__next40pxDefaultSize={ __next40pxDefaultSize }
__unstableInputWidth={ __unstableInputWidth }
disabled={ disabled }
gap={ 3 }
Expand All @@ -94,9 +101,9 @@ export function UnforwardedInputControl(
suffix={ suffix }
>
<InputField
{ ...props }
{ ...restProps }
{ ...helpProp }
__next36pxDefaultSize={ __next36pxDefaultSize }
__next40pxDefaultSize={ __next40pxDefaultSize }
className="components-input-control__input"
disabled={ disabled }
id={ id }
Expand Down
23 changes: 15 additions & 8 deletions packages/components/src/input-control/input-base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import type { InputBaseProps, LabelPosition } from './types';
import type { WordPressComponentProps } from '../context';
import { ContextSystemProvider } from '../context';
import { useDeprecated36pxDefaultSizeProp } from '../utils/use-deprecated-props';

function useUniqueId( idProp?: string ) {
const instanceId = useInstanceId( InputBase );
Expand Down Expand Up @@ -60,8 +61,11 @@ function getUIFlexProps( labelPosition?: LabelPosition ) {
}

export function InputBase(
{
__next36pxDefaultSize,
props: WordPressComponentProps< InputBaseProps, 'div' >,
ref: ForwardedRef< HTMLDivElement >
) {
const {
__next40pxDefaultSize,
__unstableInputWidth,
children,
className,
Expand All @@ -74,16 +78,19 @@ export function InputBase(
prefix,
size = 'default',
suffix,
...props
}: WordPressComponentProps< InputBaseProps, 'div' >,
ref: ForwardedRef< HTMLDivElement >
) {
...restProps
} = useDeprecated36pxDefaultSizeProp(
props,
'wp.components.InputBase',
'6.4'
);

const id = useUniqueId( idProp );
const hideLabel = hideLabelFromVision || ! label;

const { paddingLeft, paddingRight } = getSizeConfig( {
inputSize: size,
__next36pxDefaultSize,
__next40pxDefaultSize,
} );
const prefixSuffixContextValue = useMemo( () => {
return {
Expand All @@ -95,7 +102,7 @@ export function InputBase(
return (
// @ts-expect-error The `direction` prop from Flex (FlexDirection) conflicts with legacy SVGAttributes `direction` (string) that come from React intrinsic prop definitions.
<Root
{ ...props }
{ ...restProps }
{ ...getUIFlexProps( labelPosition ) }
className={ className }
gap={ 2 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export const Container = styled.div< ContainerProps >`
`;

type InputProps = {
__next36pxDefaultSize?: boolean;
__next40pxDefaultSize?: boolean;
disabled?: boolean;
inputSize?: Size;
isDragging?: boolean;
Expand Down Expand Up @@ -120,14 +120,14 @@ const fontSizeStyles = ( { inputSize: size }: InputProps ) => {

export const getSizeConfig = ( {
inputSize: size,
__next36pxDefaultSize,
__next40pxDefaultSize,
}: InputProps ) => {
// Paddings may be overridden by the custom paddings props.
const sizes = {
default: {
height: 36,
height: 40,
lineHeight: 1,
minHeight: 36,
minHeight: 40,
paddingLeft: space( 4 ),
paddingRight: space( 4 ),
},
Expand All @@ -147,7 +147,7 @@ export const getSizeConfig = ( {
},
};

if ( ! __next36pxDefaultSize ) {
if ( ! __next40pxDefaultSize ) {
sizes.default = {
height: 30,
lineHeight: 1,
Expand Down
Loading
Loading