diff --git a/packages/components/src/font-size-picker/index.tsx b/packages/components/src/font-size-picker/index.tsx index a47812640f1a2..582044f3757f7 100644 --- a/packages/components/src/font-size-picker/index.tsx +++ b/packages/components/src/font-size-picker/index.tsx @@ -36,6 +36,7 @@ import FontSizePickerSelect from './font-size-picker-select'; import FontSizePickerToggleGroup from './font-size-picker-toggle-group'; import { T_SHIRT_NAMES } from './constants'; import { maybeWarnDeprecated36pxSize } from '../utils/deprecated-36px-size'; +import BaseControl from '../base-control'; const DEFAULT_UNITS = [ 'px', 'em', 'rem', 'vw', 'vh' ]; @@ -56,6 +57,7 @@ const UnforwardedFontSizePicker = ( value, withSlider = false, withReset = true, + label = 'Size', } = props; const units = useCustomUnits( { @@ -131,171 +133,190 @@ const UnforwardedFontSizePicker = ( } ); return ( - - { __( 'Font size' ) } - -
- - { __( 'Size' ) } - { headerHint && ( - - { headerHint } - + + + + { __( 'Font size' ) } + + +
+ + { label } + { headerHint && ( + + { headerHint } + + ) } + + { ! disableCustomFontSizes && ( + + setUserRequestedCustom( + ! userRequestedCustom + ) + } + isPressed={ currentPickerType === 'custom' } + size="small" + /> ) } - - { ! disableCustomFontSizes && ( - + +
+ { currentPickerType === 'select' && ( + { + if ( newValue === undefined ) { + onChange?.( undefined ); + } else { + onChange?.( + hasUnits + ? newValue + : Number( newValue ), + fontSizes.find( + ( fontSize ) => + fontSize.size === newValue + ) + ); + } + } } + onSelectCustom={ () => + setUserRequestedCustom( true ) } - icon={ settings } - onClick={ () => - setUserRequestedCustom( ! userRequestedCustom ) - } - isPressed={ currentPickerType === 'custom' } - size="small" /> ) } -
-
-
- { currentPickerType === 'select' && ( - { - if ( newValue === undefined ) { - onChange?.( undefined ); - } else { - onChange?.( - hasUnits ? newValue : Number( newValue ), - fontSizes.find( - ( fontSize ) => - fontSize.size === newValue - ) - ); - } - } } - onSelectCustom={ () => setUserRequestedCustom( true ) } - /> - ) } - { currentPickerType === 'togglegroup' && ( - { - if ( newValue === undefined ) { - onChange?.( undefined ); - } else { - onChange?.( - hasUnits ? newValue : Number( newValue ), - fontSizes.find( - ( fontSize ) => - fontSize.size === newValue - ) - ); - } - } } - /> - ) } - { currentPickerType === 'custom' && ( - - - { - setUserRequestedCustom( true ); - - if ( newValue === undefined ) { - onChange?.( undefined ); - } else { - onChange?.( - hasUnits - ? newValue - : parseInt( newValue, 10 ) - ); - } - } } - size={ size } - units={ hasUnits ? units : [] } - min={ 0 } - /> - - { withSlider && ( + { currentPickerType === 'togglegroup' && ( + { + if ( newValue === undefined ) { + onChange?.( undefined ); + } else { + onChange?.( + hasUnits + ? newValue + : Number( newValue ), + fontSizes.find( + ( fontSize ) => + fontSize.size === newValue + ) + ); + } + } } + /> + ) } + { currentPickerType === 'custom' && ( + - - { + setUserRequestedCustom( true ); + + if ( newValue === undefined ) { + onChange?.( undefined ); + } else { + onChange?.( + hasUnits + ? newValue + : parseInt( newValue, 10 ) + ); } - __shouldNotWarnDeprecated36pxSize - className="components-font-size-picker__custom-input" - label={ __( 'Custom Size' ) } - hideLabelFromVision - value={ valueQuantity } - initialPosition={ fallbackFontSize } - withInputField={ false } - onChange={ ( newValue ) => { - setUserRequestedCustom( true ); + } } + size={ size } + units={ hasUnits ? units : [] } + min={ 0 } + /> + + { withSlider && ( + + + { + setUserRequestedCustom( true ); - if ( newValue === undefined ) { - onChange?.( undefined ); - } else if ( hasUnits ) { - onChange?.( - newValue + - ( valueUnit ?? 'px' ) - ); - } else { - onChange?.( newValue ); + if ( newValue === undefined ) { + onChange?.( undefined ); + } else if ( hasUnits ) { + onChange?.( + newValue + + ( valueUnit ?? + 'px' ) + ); + } else { + onChange?.( newValue ); + } + } } + min={ 0 } + max={ + isValueUnitRelative ? 10 : 100 } + step={ + isValueUnitRelative ? 0.1 : 1 + } + /> + + + ) } + { withReset && ( + + - - ) } - - ) } -
-
+ variant="secondary" + __next40pxDefaultSize + size={ + size === '__unstable-large' || + props.__next40pxDefaultSize + ? 'default' + : 'small' + } + > + { __( 'Reset' ) } + + + ) } + + ) } + + +
); }; diff --git a/packages/components/src/font-size-picker/types.ts b/packages/components/src/font-size-picker/types.ts index 2296e96856788..591ff4994a33d 100644 --- a/packages/components/src/font-size-picker/types.ts +++ b/packages/components/src/font-size-picker/types.ts @@ -74,6 +74,16 @@ export type FontSizePickerProps = { * @default 'default' */ size?: 'default' | '__unstable-large'; + /** + * Label for the control. If this prop is provided, it will be rendered + * above the control interface. + */ + label?: string; + /** + * Help text to be displayed below the control. If a function is provided, it will + * receive the current font size value as an argument and should return a string. + */ + help?: string | ( ( value: number | string | undefined ) => string ); }; export type FontSize = {