From 9017d1f0aa4f97277d801f19b5e53d686ee4498f Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Tue, 15 Aug 2023 08:38:50 +0900 Subject: [PATCH 01/13] InputControl: Add opt-in prop for next 40px default size --- .../components/src/input-control/index.tsx | 26 ++++++++++++------- .../src/input-control/input-base.tsx | 19 ++++++++------ .../src/input-control/input-field.tsx | 17 +++++++----- .../styles/input-control-styles.tsx | 10 +++---- .../components/src/input-control/types.ts | 9 ++++++- 5 files changed, 50 insertions(+), 31 deletions(-) diff --git a/packages/components/src/input-control/index.tsx b/packages/components/src/input-control/index.tsx index b1586995caa54e..991b6a7a08569e 100644 --- a/packages/components/src/input-control/index.tsx +++ b/packages/components/src/input-control/index.tsx @@ -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 = () => {}; @@ -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, @@ -50,10 +54,12 @@ export function UnforwardedInputControl( style, suffix, value, - ...props - }: InputControlProps, - ref: ForwardedRef< HTMLInputElement > -) { + ...restProps + } = useDeprecated36pxDefaultSizeProp< InputControlProps >( + props, + 'wp.components.InputControl' + ); + const [ isFocused, setIsFocused ] = useState( false ); const id = useUniqueId( idProp ); @@ -61,7 +67,7 @@ export function UnforwardedInputControl( const draftHookProps = useDraft( { value, - onBlur: props.onBlur, + onBlur: restProps.onBlur, onChange, } ); @@ -78,7 +84,7 @@ export function UnforwardedInputControl( __nextHasNoMarginBottom > , + ref: ForwardedRef< HTMLDivElement > +) { + const { + __next40pxDefaultSize, __unstableInputWidth, children, className, @@ -74,16 +78,15 @@ export function InputBase( prefix, size = 'default', suffix, - ...props - }: WordPressComponentProps< InputBaseProps, 'div' >, - ref: ForwardedRef< HTMLDivElement > -) { + ...restProps + } = useDeprecated36pxDefaultSizeProp( props, 'wp.components.InputBase' ); + const id = useUniqueId( idProp ); const hideLabel = hideLabelFromVision || ! label; const { paddingLeft, paddingRight } = getSizeConfig( { inputSize: size, - __next36pxDefaultSize, + __next40pxDefaultSize, } ); const prefixSuffixContextValue = useMemo( () => { return { @@ -95,7 +98,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. {}; function InputField( - { + props: WordPressComponentProps< InputFieldProps, 'input', false >, + ref: ForwardedRef< HTMLInputElement > +) { + const { disabled = false, dragDirection = 'n', dragThreshold = 10, @@ -49,10 +53,9 @@ function InputField( stateReducer = ( state: any ) => state, value: valueProp, type, - ...props - }: WordPressComponentProps< InputFieldProps, 'input', false >, - ref: ForwardedRef< HTMLInputElement > -) { + ...restProps + } = useDeprecated36pxDefaultSizeProp( props, 'wp.components.InputField' ); + const { // State. state, @@ -200,7 +203,7 @@ function InputField( let handleOnMouseDown; if ( type === 'number' ) { handleOnMouseDown = ( event: MouseEvent< HTMLInputElement > ) => { - props.onMouseDown?.( event ); + restProps.onMouseDown?.( event ); if ( event.currentTarget !== event.currentTarget.ownerDocument.activeElement @@ -212,7 +215,7 @@ function InputField( return ( ` `; type InputProps = { - __next36pxDefaultSize?: boolean; + __next40pxDefaultSize?: boolean; disabled?: boolean; inputSize?: Size; isDragging?: boolean; @@ -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 ), }, @@ -147,7 +147,7 @@ export const getSizeConfig = ( { }, }; - if ( ! __next36pxDefaultSize ) { + if ( ! __next40pxDefaultSize ) { sizes.default = { height: 30, lineHeight: 1, diff --git a/packages/components/src/input-control/types.ts b/packages/components/src/input-control/types.ts index 44c791f263e46e..9885c45a86150a 100644 --- a/packages/components/src/input-control/types.ts +++ b/packages/components/src/input-control/types.ts @@ -27,11 +27,18 @@ export type Size = 'default' | 'small' | '__unstable-large'; interface BaseProps { /** - * Start opting into the larger default height that will become the default size in a future version. + * Deprecated. Use `__next40pxDefaultSize` instead. * * @default false + * @deprecated */ __next36pxDefaultSize?: boolean; + /** + * Start opting into the larger default height that will become the default size in a future version. + * + * @default false + */ + __next40pxDefaultSize?: boolean; __unstableInputWidth?: CSSProperties[ 'width' ]; /** * If true, the label will only be visible to screen readers. From a1eadb3ac71832baf102ff3d82dd8ceb858da1d7 Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Tue, 15 Aug 2023 09:10:30 +0900 Subject: [PATCH 02/13] Fixup --- .../src/input-control/input-field.tsx | 17 +++++++---------- packages/components/src/input-control/types.ts | 3 ++- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/components/src/input-control/input-field.tsx b/packages/components/src/input-control/input-field.tsx index 14be3a7a9a9f77..37e2bf4351c002 100644 --- a/packages/components/src/input-control/input-field.tsx +++ b/packages/components/src/input-control/input-field.tsx @@ -24,15 +24,11 @@ import { useDragCursor } from './utils'; import { Input } from './styles/input-control-styles'; import { useInputControlStateReducer } from './reducer/reducer'; import type { InputFieldProps } from './types'; -import { useDeprecated36pxDefaultSizeProp } from '../utils/use-deprecated-props'; const noop = () => {}; function InputField( - props: WordPressComponentProps< InputFieldProps, 'input', false >, - ref: ForwardedRef< HTMLInputElement > -) { - const { + { disabled = false, dragDirection = 'n', dragThreshold = 10, @@ -53,9 +49,10 @@ function InputField( stateReducer = ( state: any ) => state, value: valueProp, type, - ...restProps - } = useDeprecated36pxDefaultSizeProp( props, 'wp.components.InputField' ); - + ...props + }: WordPressComponentProps< InputFieldProps, 'input', false >, + ref: ForwardedRef< HTMLInputElement > +) { const { // State. state, @@ -203,7 +200,7 @@ function InputField( let handleOnMouseDown; if ( type === 'number' ) { handleOnMouseDown = ( event: MouseEvent< HTMLInputElement > ) => { - restProps.onMouseDown?.( event ); + props.onMouseDown?.( event ); if ( event.currentTarget !== event.currentTarget.ownerDocument.activeElement @@ -215,7 +212,7 @@ function InputField( return ( = ( extra: { event: SyntheticEvent } & P ) => void; -export interface InputFieldProps extends BaseProps { +export interface InputFieldProps + extends Omit< BaseProps, '__next36pxDefaultSize' > { /** * Determines the drag axis. * From 83f2b32c3fde08b61ea9ffa4cbed1a873290e623 Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Tue, 15 Aug 2023 09:14:40 +0900 Subject: [PATCH 03/13] Add since version parameter --- packages/components/src/input-control/index.tsx | 3 ++- packages/components/src/input-control/input-base.tsx | 6 +++++- packages/components/src/utils/use-deprecated-props.ts | 6 ++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/components/src/input-control/index.tsx b/packages/components/src/input-control/index.tsx index 991b6a7a08569e..41afdd3e40d5ed 100644 --- a/packages/components/src/input-control/index.tsx +++ b/packages/components/src/input-control/index.tsx @@ -57,7 +57,8 @@ export function UnforwardedInputControl( ...restProps } = useDeprecated36pxDefaultSizeProp< InputControlProps >( props, - 'wp.components.InputControl' + 'wp.components.InputControl', + '6.4' ); const [ isFocused, setIsFocused ] = useState( false ); diff --git a/packages/components/src/input-control/input-base.tsx b/packages/components/src/input-control/input-base.tsx index fe5e6d46c99fff..64544971840b34 100644 --- a/packages/components/src/input-control/input-base.tsx +++ b/packages/components/src/input-control/input-base.tsx @@ -79,7 +79,11 @@ export function InputBase( size = 'default', suffix, ...restProps - } = useDeprecated36pxDefaultSizeProp( props, 'wp.components.InputBase' ); + } = useDeprecated36pxDefaultSizeProp( + props, + 'wp.components.InputBase', + '6.4' + ); const id = useUniqueId( idProp ); const hideLabel = hideLabelFromVision || ! label; diff --git a/packages/components/src/utils/use-deprecated-props.ts b/packages/components/src/utils/use-deprecated-props.ts index 8c102906970d0e..6df8e25303738c 100644 --- a/packages/components/src/utils/use-deprecated-props.ts +++ b/packages/components/src/utils/use-deprecated-props.ts @@ -11,14 +11,16 @@ export function useDeprecated36pxDefaultSizeProp< >( props: P, /** The component identifier in dot notation, e.g. `wp.components.ComponentName`. */ - componentIdentifier: string + componentIdentifier: string, + /** Version in which the prop was deprecated. */ + since: string = '6.3' ) { const { __next36pxDefaultSize, __next40pxDefaultSize, ...otherProps } = props; if ( typeof __next36pxDefaultSize !== 'undefined' ) { deprecated( '`__next36pxDefaultSize` prop in ' + componentIdentifier, { alternative: '`__next40pxDefaultSize`', - since: '6.3', + since, } ); } From 3b6ef4942774802f16cbb97db5b92191fcfef000 Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Tue, 15 Aug 2023 09:17:02 +0900 Subject: [PATCH 04/13] SelectControl: Add opt-in prop for next 40px default size --- packages/components/src/select-control/index.tsx | 13 +++++++++---- .../select-control/styles/select-control-styles.ts | 14 +++++++------- packages/components/src/select-control/types.ts | 1 + 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/packages/components/src/select-control/index.tsx b/packages/components/src/select-control/index.tsx index c7408ea26f18a2..9c6ce0aba5d27e 100644 --- a/packages/components/src/select-control/index.tsx +++ b/packages/components/src/select-control/index.tsx @@ -18,6 +18,7 @@ import { Select } from './styles/select-control-styles'; import type { WordPressComponentProps } from '../context'; import type { SelectControlProps } from './types'; import SelectControlChevronDown from './chevron-down'; +import { useDeprecated36pxDefaultSizeProp } from '../utils/use-deprecated-props'; const noop = () => {}; @@ -50,10 +51,14 @@ function UnforwardedSelectControl( children, prefix, suffix, - __next36pxDefaultSize = false, + __next40pxDefaultSize = false, __nextHasNoMarginBottom = false, ...restProps - } = props; + } = useDeprecated36pxDefaultSizeProp( + props, + 'wp.components.SelectControl', + '6.4' + ); const [ isFocused, setIsFocused ] = useState( false ); const id = useUniqueId( idProp ); const helpId = help ? `${ id }__help` : undefined; @@ -107,11 +112,11 @@ function UnforwardedSelectControl( } prefix={ prefix } labelPosition={ labelPosition } - __next36pxDefaultSize={ __next36pxDefaultSize } + __next40pxDefaultSize={ __next40pxDefaultSize } > Date: Wed, 6 Sep 2023 15:39:11 +0300 Subject: [PATCH 09/13] UnitControl: Add opt-in prop for next 40px default size --- packages/components/src/unit-control/index.tsx | 14 ++++++++++++-- .../src/unit-control/styles/unit-control-styles.ts | 12 ++++++------ packages/components/src/unit-control/types.ts | 12 ++++++++---- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/packages/components/src/unit-control/index.tsx b/packages/components/src/unit-control/index.tsx index 24b849199946db..cc657f5fd67f40 100644 --- a/packages/components/src/unit-control/index.tsx +++ b/packages/components/src/unit-control/index.tsx @@ -26,6 +26,7 @@ import { import { useControlledState } from '../utils/hooks'; import { escapeRegExp } from '../utils/strings'; import type { UnitControlProps, UnitControlOnChangeCallback } from './types'; +import { useDeprecated36pxDefaultSizeProp } from '../utils/use-deprecated-props'; function UnforwardedUnitControl( unitControlProps: WordPressComponentProps< @@ -55,7 +56,11 @@ function UnforwardedUnitControl( value: valueProp, onFocus: onFocusProp, ...props - } = unitControlProps; + } = useDeprecated36pxDefaultSizeProp( + unitControlProps, + 'wp.components.UnitControl', + '6.4' + ); if ( 'unit' in unitControlProps ) { deprecated( 'UnitControl unit prop', { @@ -182,7 +187,12 @@ function UnforwardedUnitControl( disabled={ disabled } isUnitSelectTabbable={ isUnitSelectTabbable } onChange={ handleOnUnitChange } - size={ size } + size={ + size === 'small' || + ( size === 'default' && ! props.__next40pxDefaultSize ) + ? 'small' + : 'default' + } unit={ unit } units={ units } onFocus={ onFocusProp } diff --git a/packages/components/src/unit-control/styles/unit-control-styles.ts b/packages/components/src/unit-control/styles/unit-control-styles.ts index 92b1f5f2fd8b4e..5ff1fa9a3ef00b 100644 --- a/packages/components/src/unit-control/styles/unit-control-styles.ts +++ b/packages/components/src/unit-control/styles/unit-control-styles.ts @@ -36,7 +36,7 @@ export const ValueInput = styled( NumberControl )` const baseUnitLabelStyles = ( { selectSize }: SelectProps ) => { const sizes = { - default: css` + small: css` box-sizing: border-box; padding: 2px 1px; width: 20px; @@ -47,7 +47,7 @@ const baseUnitLabelStyles = ( { selectSize }: SelectProps ) => { text-transform: uppercase; text-align-last: center; `, - large: css` + default: css` box-sizing: border-box; min-width: 24px; max-width: 48px; @@ -64,7 +64,7 @@ const baseUnitLabelStyles = ( { selectSize }: SelectProps ) => { `, }; - return selectSize === '__unstable-large' ? sizes.large : sizes.default; + return sizes[ selectSize ]; }; export const UnitLabel = styled.div< SelectProps >` @@ -79,7 +79,7 @@ export const UnitLabel = styled.div< SelectProps >` const unitSelectSizes = ( { selectSize = 'default' }: SelectProps ) => { const sizes = { - default: css` + small: css` height: 100%; border: 1px solid transparent; transition: @@ -101,7 +101,7 @@ const unitSelectSizes = ( { selectSize = 'default' }: SelectProps ) => { z-index: 1; } `, - large: css` + default: css` display: flex; justify-content: center; align-items: center; @@ -121,7 +121,7 @@ const unitSelectSizes = ( { selectSize = 'default' }: SelectProps ) => { `, }; - return selectSize === '__unstable-large' ? sizes.large : sizes.default; + return sizes[ selectSize ]; }; export const UnitSelect = styled.select< SelectProps >` diff --git a/packages/components/src/unit-control/types.ts b/packages/components/src/unit-control/types.ts index f97d168e7f10ee..9164502668a2b0 100644 --- a/packages/components/src/unit-control/types.ts +++ b/packages/components/src/unit-control/types.ts @@ -9,11 +9,10 @@ import type { FocusEventHandler } from 'react'; import type { InputChangeCallback, InputControlProps, - Size as InputSize, } from '../input-control/types'; import type { NumberControlProps } from '../number-control/types'; -export type SelectSize = InputSize; +export type SelectSize = 'default' | 'small'; export type WPUnitControlUnit = { /** @@ -42,7 +41,7 @@ export type UnitControlOnChangeCallback = InputChangeCallback< { data?: WPUnitControlUnit; } >; -export type UnitSelectControlProps = Pick< InputControlProps, 'size' > & { +export type UnitSelectControlProps = { /** * Whether the control can be focused via keyboard navigation. * @@ -53,6 +52,10 @@ export type UnitSelectControlProps = Pick< InputControlProps, 'size' > & { * A callback function invoked when the value is changed. */ onChange?: UnitControlOnChangeCallback; + /** + * The size of the unit select. + */ + size?: SelectSize; /** * Current unit. */ @@ -65,7 +68,8 @@ export type UnitSelectControlProps = Pick< InputControlProps, 'size' > & { units?: WPUnitControlUnit[]; }; -export type UnitControlProps = Omit< UnitSelectControlProps, 'unit' > & +export type UnitControlProps = Pick< InputControlProps, 'size' > & + Omit< UnitSelectControlProps, 'size' | 'unit' > & Omit< NumberControlProps, 'spinControls' | 'suffix' | 'type' > & { /** * If `true`, the unit `