Skip to content

Commit

Permalink
FontSizePicker: Add opt-in prop for 40px default size (#56804)
Browse files Browse the repository at this point in the history
* `FontSizePicker`: Add opt-in prop for 40px default size

* Update button when __next40pxDefaultSize is true

* Update changelog
  • Loading branch information
brookewp authored Dec 7, 2023
1 parent 6a42225 commit f6adf1e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- `PaletteEdit`: Gradient pickers to use same width as color pickers ([#56801](https://github.com/WordPress/gutenberg/pull/56801)).
- `FocalPointPicker`: Add opt-in prop for 40px default size ([#56021](https://github.com/WordPress/gutenberg/pull/56021)).
- `DimensionControl`: Add opt-in prop for 40px default size ([#56805](https://github.com/WordPress/gutenberg/pull/56805)).
- `FontSizePicker`: Add opt-in prop for 40px default size ([#56804](https://github.com/WordPress/gutenberg/pull/56804)).

### Bug Fix

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const CUSTOM_OPTION: FontSizePickerSelectOption = {

const FontSizePickerSelect = ( props: FontSizePickerSelectProps ) => {
const {
__next40pxDefaultSize,
fontSizes,
value,
disableCustomFontSizes,
Expand Down Expand Up @@ -67,6 +68,7 @@ const FontSizePickerSelect = ( props: FontSizePickerSelectProps ) => {

return (
<CustomSelectControl
__next40pxDefaultSize={ __next40pxDefaultSize }
__nextUnconstrainedWidth
className="components-font-size-picker__select"
label={ __( 'Font size' ) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,18 @@ import { T_SHIRT_ABBREVIATIONS, T_SHIRT_NAMES } from './constants';
import type { FontSizePickerToggleGroupProps } from './types';

const FontSizePickerToggleGroup = ( props: FontSizePickerToggleGroupProps ) => {
const { fontSizes, value, __nextHasNoMarginBottom, size, onChange } = props;
const {
fontSizes,
value,
__nextHasNoMarginBottom,
__next40pxDefaultSize,
size,
onChange,
} = props;
return (
<ToggleGroupControl
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
__next40pxDefaultSize={ __next40pxDefaultSize }
label={ __( 'Font size' ) }
hideLabelFromVision
value={ value }
Expand Down
14 changes: 11 additions & 3 deletions packages/components/src/font-size-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const UnforwardedFontSizePicker = (
const {
/** Start opting into the new margin-free styles that will become the default in a future version. */
__nextHasNoMarginBottom = false,
__next40pxDefaultSize = false,
fallbackFontSize,
fontSizes = [],
disableCustomFontSizes = false,
Expand Down Expand Up @@ -165,6 +166,7 @@ const UnforwardedFontSizePicker = (
shouldUseSelectControl &&
! showCustomValueControl && (
<FontSizePickerSelect
__next40pxDefaultSize={ __next40pxDefaultSize }
fontSizes={ fontSizes }
value={ value }
disableCustomFontSizes={ disableCustomFontSizes }
Expand Down Expand Up @@ -194,6 +196,7 @@ const UnforwardedFontSizePicker = (
fontSizes={ fontSizes }
value={ value }
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
__next40pxDefaultSize={ __next40pxDefaultSize }
size={ size }
onChange={ ( newValue ) => {
if ( newValue === undefined ) {
Expand All @@ -214,6 +217,7 @@ const UnforwardedFontSizePicker = (
<Flex className="components-font-size-picker__custom-size-control">
<FlexItem isBlock>
<UnitControl
__next40pxDefaultSize={ __next40pxDefaultSize }
label={ __( 'Custom' ) }
labelPosition="top"
hideLabelFromVision
Expand Down Expand Up @@ -241,6 +245,9 @@ const UnforwardedFontSizePicker = (
__nextHasNoMarginBottom={
__nextHasNoMarginBottom
}
__next40pxDefaultSize={
__next40pxDefaultSize
}
className="components-font-size-picker__custom-input"
label={ __( 'Custom Size' ) }
hideLabelFromVision
Expand Down Expand Up @@ -276,9 +283,10 @@ const UnforwardedFontSizePicker = (
variant="secondary"
__next40pxDefaultSize
size={
size !== '__unstable-large'
? 'small'
: 'default'
size === '__unstable-large' ||
props.__next40pxDefaultSize
? 'default'
: 'small'
}
>
{ __( 'Reset' ) }
Expand Down
9 changes: 8 additions & 1 deletion packages/components/src/font-size-picker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ export type FontSizePickerProps = {
* @default false
*/
__nextHasNoMarginBottom?: boolean;
/**
* Start opting into the larger default height that will become the default size in a future version.
*
* @default false
*/
__next40pxDefaultSize?: boolean;
/**
* Size of the control.
*
Expand Down Expand Up @@ -93,6 +99,7 @@ export type FontSizePickerSelectProps = Pick<
>;
onChange: NonNullable< FontSizePickerProps[ 'onChange' ] >;
onSelectCustom: () => void;
__next40pxDefaultSize: boolean;
};

export type FontSizePickerSelectOption = {
Expand All @@ -104,7 +111,7 @@ export type FontSizePickerSelectOption = {

export type FontSizePickerToggleGroupProps = Pick<
FontSizePickerProps,
'value' | 'size' | '__nextHasNoMarginBottom'
'value' | 'size' | '__nextHasNoMarginBottom' | '__next40pxDefaultSize'
> & {
fontSizes: NonNullable< FontSizePickerProps[ 'fontSizes' ] >;
onChange: NonNullable< FontSizePickerProps[ 'onChange' ] >;
Expand Down

1 comment on commit f6adf1e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in f6adf1e.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7134075091
📝 Reported issues:

Please sign in to comment.