Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ export default function TypographyPanel( {
settings,
panelId,
defaultControls = DEFAULT_CONTROLS,
fitText = false,
Copy link
Member Author

Choose a reason for hiding this comment

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

An alternative solution to avoid passing a new prop here, would be to on the typography hook packages/block-editor/src/hooks/typography.js change the settings passed when fit text is on. But will add more code without any specific advantage. I'm happy to change if someone prefers the other approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

My only hesitation here is what to do about the Site Editor screens: ScreenBlock and ScreenTypographyElement. Will we support fit-text for site-wide elements? What about when setting typography styles for all Paragraphs?

That said, for the purpose of releasing this in 6.9, I'm good.

Copy link
Member Author

Choose a reason for hiding this comment

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

My only hesitation here is what to do about the Site Editor screens: ScreenBlock and ScreenTypographyElement. Will we support fit-text for site-wide elements?

There are no plans to support fit-text in global styles, I don't think it makes sense to globally target elements with fit text from global styles (it is not even a css property so technically it would be complex). I expect fit text to be enabled per block when needed.
This component is also used by global styles but the property has a default so it should have no impact for the global styles use case.

} ) {
const decodeValue = ( rawValue ) =>
getValueFromVariable( { settings }, '', rawValue );
Expand Down Expand Up @@ -439,6 +440,7 @@ export default function TypographyPanel( {
withReset={ false }
withSlider
size="__unstable-large"
disabled={ fitText }
/>
</ToolsPanelItem>
) }
Expand Down
9 changes: 6 additions & 3 deletions packages/block-editor/src/hooks/typography.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,13 @@ function TypographyInspectorControl( { children, resetAllFilter } ) {

export function TypographyPanel( { clientId, name, setAttributes, settings } ) {
function selector( select ) {
const { style, fontFamily, fontSize } =
const { style, fontFamily, fontSize, fitText } =
select( blockEditorStore ).getBlockAttributes( clientId ) || {};
return { style, fontFamily, fontSize };
return { style, fontFamily, fontSize, fitText };
}
const { style, fontFamily, fontSize } = useSelect( selector, [ clientId ] );
const { style, fontFamily, fontSize, fitText } = useSelect( selector, [
clientId,
] );
const isEnabled = useHasTypographyPanel( settings );
const value = useMemo(
() => attributesToStyle( { style, fontFamily, fontSize } ),
Expand Down Expand Up @@ -148,6 +150,7 @@ export function TypographyPanel( { clientId, name, setAttributes, settings } ) {
value={ value }
onChange={ onChange }
defaultControls={ defaultControls }
fitText={ fitText }
/>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ function _CustomSelect(
) {
const {
children,
disabled = false,
hideLabelFromVision = false,
label,
size,
Expand Down Expand Up @@ -135,11 +136,13 @@ function _CustomSelect(
__next40pxDefaultSize
size={ size }
suffix={ <SelectControlChevronDown /> }
disabled={ disabled }
>
<CustomSelectButton
{ ...restProps }
size={ size }
store={ store }
disabled={ disabled }
// Match legacy behavior (move selection rather than open the popover)
showOnKeyDown={ ! isLegacy }
/>
Expand Down
6 changes: 6 additions & 0 deletions packages/components/src/custom-select-control-v2/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ export type _CustomSelectProps = CustomSelectButtonProps & {
* The child elements. This should be composed of `CustomSelectItem` components.
*/
children: React.ReactNode;
/**
* If true, the control will be disabled and the user will not be able to interact with it.
*
* @default false
*/
disabled?: boolean;
/**
* Used to visually hide the label. It will always be visible to screen readers.
*
Expand Down
2 changes: 2 additions & 0 deletions packages/components/src/custom-select-control/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function CustomSelectControl< T extends CustomSelectOption >(
__next40pxDefaultSize = false,
__shouldNotWarnDeprecated36pxSize,
describedBy,
disabled = false,
options,
onChange,
size = 'default',
Expand Down Expand Up @@ -188,6 +189,7 @@ function CustomSelectControl< T extends CustomSelectOption >(
<>
<_CustomSelect
aria-describedby={ descriptionId }
disabled={ disabled }
renderSelectedValue={
showSelectedHint ? renderSelectedValueHint : undefined
}
Expand Down
6 changes: 6 additions & 0 deletions packages/components/src/custom-select-control/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ export type CustomSelectProps< T extends CustomSelectOption > = {
* Optional classname for the component.
*/
className?: string;
/**
* If true, the control will be disabled and the user will not be able to interact with it.
*
* @default false
*/
disabled?: boolean;
/**
* Hide the label visually, while keeping available to assistive technology.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,14 @@ const DEFAULT_OPTION: FontSizePickerSelectOption = {
};

const FontSizePickerSelect = ( props: FontSizePickerSelectProps ) => {
const { __next40pxDefaultSize, fontSizes, value, size, onChange } = props;
const {
__next40pxDefaultSize,
fontSizes,
value,
size,
disabled,
onChange,
} = props;

const options: FontSizePickerSelectOption[] = [
DEFAULT_OPTION,
Expand Down Expand Up @@ -56,6 +63,7 @@ const FontSizePickerSelect = ( props: FontSizePickerSelectProps ) => {
options={ options }
value={ selectedOption }
showSelectedHint
disabled={ disabled }
onChange={ ( {
selectedItem,
}: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ import { T_SHIRT_ABBREVIATIONS, T_SHIRT_NAMES } from './constants';
import type { FontSizePickerToggleGroupProps } from './types';

const FontSizePickerToggleGroup = ( props: FontSizePickerToggleGroupProps ) => {
const { fontSizes, value, __next40pxDefaultSize, size, onChange } = props;
const {
fontSizes,
value,
__next40pxDefaultSize,
size,
disabled,
onChange,
} = props;
return (
<ToggleGroupControl
__nextHasNoMarginBottom
Expand All @@ -26,6 +33,7 @@ const FontSizePickerToggleGroup = ( props: FontSizePickerToggleGroupProps ) => {
onChange={ onChange }
isBlock
size={ size }
disabled={ disabled }
>
{ fontSizes.map( ( fontSize, index ) => (
<ToggleGroupControlOption
Expand All @@ -34,6 +42,7 @@ const FontSizePickerToggleGroup = ( props: FontSizePickerToggleGroupProps ) => {
label={ T_SHIRT_ABBREVIATIONS[ index ] }
aria-label={ fontSize.name || T_SHIRT_NAMES[ index ] }
showTooltip
disabled={ disabled }
/>
) ) }
</ToggleGroupControl>
Expand Down
9 changes: 8 additions & 1 deletion packages/components/src/font-size-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const UnforwardedFontSizePicker = (
fallbackFontSize,
fontSizes = [],
disableCustomFontSizes = false,
disabled = false,
onChange,
size = 'default',
units: unitsProp = DEFAULT_UNITS,
Expand Down Expand Up @@ -96,7 +97,7 @@ const UnforwardedFontSizePicker = (
);
const isValueUnitRelative =
!! valueUnit && [ 'em', 'rem', 'vw', 'vh' ].includes( valueUnit );
const isDisabled = value === undefined;
const isDisabled = disabled || value === undefined;

maybeWarnDeprecated36pxSize( {
componentName: 'FontSizePicker',
Expand All @@ -110,6 +111,7 @@ const UnforwardedFontSizePicker = (
className="components-font-size-picker"
// This Container component renders a fieldset element that needs to be labeled.
aria-labelledby={ labelId }
disabled={ disabled }
>
<Spacer>
<Header className="components-font-size-picker__header">
Expand All @@ -129,6 +131,7 @@ const UnforwardedFontSizePicker = (
}
isPressed={ currentPickerType === 'custom' }
size="small"
disabled={ disabled }
/>
) }
</Header>
Expand All @@ -141,6 +144,7 @@ const UnforwardedFontSizePicker = (
value={ value }
disableCustomFontSizes={ disableCustomFontSizes }
size={ size }
disabled={ disabled }
onChange={ ( newValue ) => {
if ( newValue === undefined ) {
onChange?.( undefined );
Expand All @@ -163,6 +167,7 @@ const UnforwardedFontSizePicker = (
value={ value }
__next40pxDefaultSize={ __next40pxDefaultSize }
size={ size }
disabled={ disabled }
onChange={ ( newValue ) => {
if ( newValue === undefined ) {
onChange?.( undefined );
Expand All @@ -188,6 +193,7 @@ const UnforwardedFontSizePicker = (
labelPosition="top"
hideLabelFromVision
value={ value }
disabled={ disabled }
onChange={ ( newValue ) => {
setUserRequestedCustom( true );

Expand Down Expand Up @@ -221,6 +227,7 @@ const UnforwardedFontSizePicker = (
value={ valueQuantity }
initialPosition={ fallbackFontSize }
withInputField={ false }
disabled={ disabled }
onChange={ ( newValue ) => {
setUserRequestedCustom( true );

Expand Down
11 changes: 9 additions & 2 deletions packages/components/src/font-size-picker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ export type FontSizePickerProps = {
* @default false
*/
disableCustomFontSizes?: boolean;
/**
* If `true`, the font size picker will be disabled and the user will not
* be able to change the font size.
*
* @default false
*/
disabled?: boolean;
/**
* If no value exists, this prop defines the starting position for the font
* size picker slider. Only relevant if `withSlider` is `true`.
Expand Down Expand Up @@ -100,7 +107,7 @@ export type FontSize = {

export type FontSizePickerSelectProps = Pick<
FontSizePickerProps,
'value' | 'size'
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you intend to propagate the prop?

Copy link
Member Author

Choose a reason for hiding this comment

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

Exactly the idea was to propagate the disable to the components bellow.

'value' | 'size' | 'disabled'
> & {
fontSizes: NonNullable< FontSizePickerProps[ 'fontSizes' ] >;
disableCustomFontSizes: NonNullable<
Expand All @@ -120,7 +127,7 @@ export type FontSizePickerSelectOption = {

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