Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FontSizePicker: Replace SCSS with Emotion + components #44483

Merged
merged 5 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
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
1 change: 1 addition & 0 deletions packages/components/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- `Popover`: refactor unit tests to TypeScript and modern RTL assertions ([#44373](https://github.com/WordPress/gutenberg/pull/44373)).
- `Sandbox`: updated to satisfy `react/exhaustive-deps` eslint rule ([#44378](https://github.com/WordPress/gutenberg/pull/44378))
- `FontSizePicker`: Convert to TypeScript ([#44449](https://github.com/WordPress/gutenberg/pull/44449)).
- `FontSizePicker`: Replace SCSS with Emotion + components ([#44483](https://github.com/WordPress/gutenberg/pull/44483)).

## 21.1.0 (2022-09-21)

Expand Down
90 changes: 48 additions & 42 deletions packages/components/src/font-size-picker/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/**
* External dependencies
*/
import classNames from 'classnames';
import type { ReactNode, ForwardedRef } from 'react';

/**
Expand All @@ -15,7 +14,6 @@ import { useState, useMemo, forwardRef } from '@wordpress/element';
/**
* Internal dependencies
*/
import { BaseControl } from '../base-control';
import Button from '../button';
import RangeControl from '../range-control';
import { Flex, FlexItem } from '../flex';
Expand All @@ -40,6 +38,14 @@ import type {
FontSizeSelectOption,
FontSizeToggleGroupOption,
} from './types';
import {
Container,
HeaderHint,
HeaderLabel,
Controls,
ResetButton,
} from './styles';
import { Spacer } from '../spacer';

// This conditional is needed to maintain the spacing before the slider in the `withSlider` case.
const MaybeVStack = ( {
Expand Down Expand Up @@ -163,49 +169,49 @@ const UnforwardedFontSizePicker = (
__( 'Currently selected font size: %s' ),
selectedOption.name
);
const baseClassName = 'components-font-size-picker';
return (
<fieldset className={ baseClassName } { ...( ref ? {} : { ref } ) }>
<Container ref={ ref } className="components-font-size-picker">
<VisuallyHidden as="legend">{ __( 'Font size' ) }</VisuallyHidden>
<HStack className={ `${ baseClassName }__header` }>
<BaseControl.VisualLabel>
{ __( 'Size' ) }
{ headerHint && (
<span className={ `${ baseClassName }__header__hint` }>
{ headerHint }
</span>
<Spacer>
<HStack className="components-font-size-picker__header">
<HeaderLabel>
{ __( 'Size' ) }
{ headerHint && (
<HeaderHint className="components-font-size-picker__header__hint">
{ headerHint }
</HeaderHint>
) }
</HeaderLabel>
{ ! disableCustomFontSizes && (
<Button
label={
showCustomValueControl
? __( 'Use size preset' )
: __( 'Set custom size' )
}
icon={ settings }
onClick={ () => {
setShowCustomValueControl(
! showCustomValueControl
);
} }
isPressed={ showCustomValueControl }
isSmall
/>
) }
</BaseControl.VisualLabel>
{ ! disableCustomFontSizes && (
<Button
label={
showCustomValueControl
? __( 'Use size preset' )
: __( 'Set custom size' )
}
icon={ settings }
onClick={ () => {
setShowCustomValueControl(
! showCustomValueControl
);
} }
isPressed={ showCustomValueControl }
isSmall
/>
) }
</HStack>
</HStack>
</Spacer>
<MaybeVStack __nextHasNoMarginBottom={ __nextHasNoMarginBottom }>
<div
className={ classNames( `${ baseClassName }__controls`, {
'is-next-has-no-margin-bottom': __nextHasNoMarginBottom,
} ) }
<Controls
className="components-font-size-picker__controls"
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
>
{ !! fontSizes.length &&
shouldUseSelectControl &&
! showCustomValueControl && (
<CustomSelectControl
__nextUnconstrainedWidth
className={ `${ baseClassName }__select` }
className="components-font-size-picker__select"
label={ __( 'Font size' ) }
hideLabelFromVision
describedBy={ currentFontSizeSR }
Expand Down Expand Up @@ -267,7 +273,7 @@ const UnforwardedFontSizePicker = (
showCustomValueControl && (
<Flex
justify="space-between"
className={ `${ baseClassName }__custom-size-control` }
className="components-font-size-picker__custom-size-control"
>
<FlexItem isBlock>
<UnitControl
Expand Down Expand Up @@ -298,26 +304,26 @@ const UnforwardedFontSizePicker = (
</FlexItem>
{ withReset && (
<FlexItem isBlock>
<Button
className="components-color-palette__clear"
<ResetButton
disabled={ value === undefined }
onClick={ () => {
onChange?.( undefined );
} }
isSmall
variant="secondary"
size={ size }
>
{ __( 'Reset' ) }
</Button>
</ResetButton>
</FlexItem>
) }
</Flex>
) }
</div>
</Controls>
{ withSlider && (
<RangeControl
__nextHasNoMarginBottom={ __nextHasNoMarginBottom }
className={ `${ baseClassName }__custom-input` }
className="components-font-size-picker__custom-input"
label={ __( 'Custom Size' ) }
value={
isPixelValue && noUnitsValue
Expand All @@ -333,7 +339,7 @@ const UnforwardedFontSizePicker = (
/>
) }
</MaybeVStack>
</fieldset>
</Container>
);
};

Expand Down
78 changes: 0 additions & 78 deletions packages/components/src/font-size-picker/style.scss

This file was deleted.

48 changes: 48 additions & 0 deletions packages/components/src/font-size-picker/styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* External dependencies
*/
import styled from '@emotion/styled';

/**
* Internal dependencies
*/
import BaseControl from '../base-control';
import Button from '../button';
import { space } from '../ui/utils/space';
import { COLORS } from '../utils';
import type { FontSizePickerProps } from './types';

export const Container = styled.fieldset`
border: 0;
margin: 0;
padding: 0;
`;

export const HeaderLabel = styled( BaseControl.VisualLabel )`
margin-bottom: 0;
`;

export const HeaderHint = styled.span`
color: ${ COLORS.gray[ 700 ] };
margin-left: ${ space( 1 ) };
`;

// 280px is the sidebar width.
// TODO: Remove this, @wordpress/components shouldn't care what a "sidebar" is.
Copy link
Member Author

Choose a reason for hiding this comment

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

Didn't want to change the UI in this PR so will do this later.

export const Controls = styled.div< {
__nextHasNoMarginBottom: boolean;
} >`
max-width: calc( 280px - ${ space( 4 ) } * 2 );

${ ( props ) =>
! props.__nextHasNoMarginBottom && `margin-bottom: ${ space( 6 ) };` }
`;

export const ResetButton = styled( Button )< {
size: FontSizePickerProps[ 'size' ];
} >`
&&& {
height: ${ ( props ) =>
props.size === '__unstable-large' ? '40px' : '30px' };
}
`;
1 change: 0 additions & 1 deletion packages/components/src/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
@import "./dropdown/style.scss";
@import "./dropdown-menu/style.scss";
@import "./duotone-picker/style.scss";
@import "./font-size-picker/style.scss";
@import "./form-toggle/style.scss";
@import "./form-token-field/style.scss";
@import "./guide/style.scss";
Expand Down