Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
UnitControl: mark unit prop as deprecated
  • Loading branch information
ciampo committed Mar 21, 2022
commit d945b80778ed39e224a5ab57501b09c0e9dbb738
10 changes: 10 additions & 0 deletions packages/components/src/unit-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import classnames from 'classnames';
/**
* WordPress dependencies
*/
import deprecated from '@wordpress/deprecated';
import { forwardRef, useMemo, useRef, useEffect } from '@wordpress/element';
import { __ } from '@wordpress/i18n';

Expand Down Expand Up @@ -57,6 +58,15 @@ function UnforwardedUnitControl(
}: WordPressComponentProps< UnitControlProps, 'input', false >,
forwardedRef: ForwardedRef< any >
) {
if ( typeof unitProp !== 'undefined' ) {
deprecated( 'UnitControl unit prop', {
since: '5.6',
hint:
'Please provide a unit with a value through the `value` prop.',
version: '6.2',
} );
}

// The `value` prop, in theory, should not be `null`, but the following line
// ensures it fallback to `undefined` in case a consumer of `UnitControl`
// still passes `null` as a `value`.
Expand Down
8 changes: 7 additions & 1 deletion packages/components/src/unit-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export type UnitSelectControlProps = {
};

// TODO: when available, should (partially) extend `NumberControl` props.
export type UnitControlProps = UnitSelectControlProps &
export type UnitControlProps = Omit< UnitSelectControlProps, 'unit' > &
Pick< InputControlProps, 'hideLabelFromVision' > & {
__unstableStateReducer?: StateReducer;
__unstableInputWidth?: CSSProperties[ 'width' ];
Expand Down Expand Up @@ -105,6 +105,12 @@ export type UnitControlProps = UnitSelectControlProps &
* Callback when the `unit` changes.
*/
onUnitChange?: UnitControlOnChangeCallback;
/**
* Current unit. _Note: this prop is deprecated. Instead, provide a unit with a value through the `value` prop._
*
* @deprecated
*/
unit?: string;
/**
* Current value. If passed as a string, the current unit will be inferred from this value.
* For example, a `value` of "50%" will set the current unit to `%`.
Expand Down