Skip to content

Commit

Permalink
FontSizePicker: Deprecate bottom margin (#43870)
Browse files Browse the repository at this point in the history
* FontSizePicker: Deprecate bottom margin

* Add changelog
  • Loading branch information
mirka committed Sep 6, 2022
1 parent 2d1e007 commit c645690
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 7 deletions.
4 changes: 4 additions & 0 deletions packages/block-editor/CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Breaking change

- `FontSizePicker`: Deprecate bottom margin style. Add a `__nextHasNoMarginBottom` prop to start opting into the margin-free styles that will become the default in a future version, currently scheduled to be WordPress 6.4 ([#43870](https://github.com/WordPress/gutenberg/pull/43870)).

## 9.8.0 (2022-08-24)

## 9.7.0 (2022-08-10)
Expand Down
9 changes: 9 additions & 0 deletions packages/block-editor/src/components/font-sizes/README.MD
Expand Up @@ -31,6 +31,7 @@ const MyFontSizePicker = () => {

return (
<FontSizePicker
__nextHasNoMarginBottom
value={ fontSize }
fallbackFontSize={ fallbackFontSize }
onChange={ ( newFontSize ) => {
Expand Down Expand Up @@ -79,3 +80,11 @@ If `true`, the UI will contain a slider, instead of a numeric text input field.
- Type: `Boolean`
- Required: no
- Default: `false`

### __nextHasNoMarginBottom

Start opting into the new margin-free styles that will become the default in a future version, currently scheduled to be WordPress 6.4. (The prop can be safely removed once this happens.)

- Type: `Boolean`
- Required: no
- Default: `false`
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Expand Up @@ -4,6 +4,7 @@

### Breaking Changes

- `FontSizePicker`: Deprecate bottom margin style. Add a `__nextHasNoMarginBottom` prop to start opting into the margin-free styles that will become the default in a future version, currently scheduled to be WordPress 6.4 ([#43870](https://github.com/WordPress/gutenberg/pull/43870)).
- `AnglePickerControl`: Deprecate bottom margin style. Add a `__nextHasNoMarginBottom` prop to start opting into the margin-free styles that will become the default in a future version, currently scheduled to be WordPress 6.4 ([#43867](https://github.com/WordPress/gutenberg/pull/43867)).

### Bug Fix
Expand Down
9 changes: 9 additions & 0 deletions packages/components/src/font-size-picker/README.md
Expand Up @@ -29,6 +29,7 @@ const MyFontSizePicker = () => {

return (
<FontSizePicker
__nextHasNoMarginBottom
fontSizes={ fontSizes }
value={ fontSize }
fallbackFontSize={ fallbackFontSize }
Expand Down Expand Up @@ -105,3 +106,11 @@ If `true`, a reset button will be displayed alongside the input field when a cus
- Type: `Boolean`
- Required: no
- Default: `true`

### __nextHasNoMarginBottom

Start opting into the new margin-free styles that will become the default in a future version, currently scheduled to be WordPress 6.4. (The prop can be safely removed once this happens.)

- Type: `Boolean`
- Required: no
- Default: `false`
9 changes: 9 additions & 0 deletions packages/components/src/font-size-picker/index.js
Expand Up @@ -6,6 +6,7 @@ import classNames from 'classnames';
/**
* WordPress dependencies
*/
import deprecated from '@wordpress/deprecated';
import { __, sprintf } from '@wordpress/i18n';
import { settings } from '@wordpress/icons';
import { useState, useMemo, forwardRef } from '@wordpress/element';
Expand Down Expand Up @@ -58,6 +59,14 @@ function FontSizePicker(
},
ref
) {
if ( ! __nextHasNoMarginBottom ) {
deprecated( 'Bottom margin styles for wp.components.FontSizePicker', {
since: '6.1',
version: '6.4',
hint: 'Set the `__nextHasNoMarginBottom` prop to true to start opting into the new styles, which will become the default in a future version.',
} );
}

const hasUnits = [ typeof value, typeof fontSizes?.[ 0 ]?.size ].includes(
'string'
);
Expand Down
8 changes: 3 additions & 5 deletions packages/components/src/font-size-picker/stories/index.js
Expand Up @@ -12,17 +12,14 @@ export default {
title: 'Components/FontSizePicker',
component: FontSizePicker,
argTypes: {
__nextHasNoMarginBottom: { control: { type: 'boolean' } },
initialValue: { table: { disable: true } }, // hide prop because it's not actually part of FontSizePicker
fallbackFontSize: {
description:
'If no value exists, this prop defines the starting position for the font size picker slider. Only relevant if `withSlider` is `true`.',
},
size: {
control: {
type: 'radio',
options: [ 'default', '__unstable-large' ],
},
control: { type: 'radio' },
options: [ 'default', '__unstable-large' ],
},
withReset: {
description:
Expand Down Expand Up @@ -68,6 +65,7 @@ const TwoFontSizePickersWithState = ( { fontSizes, ...props } ) => {

export const Default = FontSizePickerWithState.bind( {} );
Default.args = {
__nextHasNoMarginBottom: true,
disableCustomFontSizes: false,
fontSizes: [
{
Expand Down
17 changes: 15 additions & 2 deletions packages/components/src/font-size-picker/test/index.js
Expand Up @@ -28,7 +28,11 @@ describe( 'FontSizePicker', () => {
);

render(
<FontSizePicker value={ fontSize } onChange={ setFontSize } />
<FontSizePicker
value={ fontSize }
onChange={ setFontSize }
__nextHasNoMarginBottom
/>
);

const unitSelect = getUnitSelect();
Expand All @@ -52,7 +56,11 @@ describe( 'FontSizePicker', () => {
);

render(
<FontSizePicker value={ fontSize } onChange={ setFontSize } />
<FontSizePicker
value={ fontSize }
onChange={ setFontSize }
__nextHasNoMarginBottom
/>
);

const unitSelect = getUnitSelect();
Expand Down Expand Up @@ -87,6 +95,7 @@ describe( 'FontSizePicker', () => {
fontSizes={ fontSizes }
value={ fontSize }
onChange={ setFontSize }
__nextHasNoMarginBottom
/>
);

Expand Down Expand Up @@ -123,6 +132,7 @@ describe( 'FontSizePicker', () => {
fontSizes={ fontSizes }
value={ fontSize }
onChange={ setFontSize }
__nextHasNoMarginBottom
/>
);

Expand Down Expand Up @@ -182,6 +192,7 @@ describe( 'FontSizePicker', () => {
<FontSizePicker
fontSizes={ fontSizes }
value={ fontSizes[ 0 ].size }
__nextHasNoMarginBottom
/>
);
// Trigger click to open the select menu and take into account
Expand All @@ -199,6 +210,7 @@ describe( 'FontSizePicker', () => {
<FontSizePicker
fontSizes={ fontSizes }
value={ fontSizes[ 0 ].size }
__nextHasNoMarginBottom
/>
);
const element = screen.getByLabelText( 'Large' );
Expand All @@ -218,6 +230,7 @@ describe( 'FontSizePicker', () => {
<FontSizePicker
fontSizes={ fontSizes }
value={ fontSizes[ 0 ].size }
__nextHasNoMarginBottom
/>
);
const largeElement = screen.getByLabelText( 'Large' );
Expand Down

0 comments on commit c645690

Please sign in to comment.