Skip to content

Commit

Permalink
Inline getPickerType utility
Browse files Browse the repository at this point in the history
  • Loading branch information
ciampo committed Jul 16, 2024
1 parent 0a50988 commit 41deb9f
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions packages/components/src/font-size-picker/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,19 +45,6 @@ const DEFAULT_UNITS = [ 'px', 'em', 'rem', 'vw', 'vh' ];
const shouldUseSelectOverToggle = ( howManyfontSizes: number ) =>
howManyfontSizes > 5;

const getPickerType = (
showCustomValuePicker: boolean,
fontSizes: FontSize[]
): FontSizePickerType => {
if ( showCustomValuePicker ) {
return 'custom';
}

return shouldUseSelectOverToggle( fontSizes.length )
? 'select'
: 'togglegroup';
};

const getHeaderHint = (
currentPickerType: FontSizePickerType,
selectedFontSize: FontSize | undefined,
Expand Down Expand Up @@ -117,14 +104,17 @@ const UnforwardedFontSizePicker = (

if ( fontSizes.length === 0 && disableCustomFontSizes ) {
return null;
let currentPickerType;
if ( ! disableCustomFontSizes && userRequestedCustom ) {
// While showing the custom value picker, switch back to predef only if
// `disableCustomFontSizes` is set to `true`.
currentPickerType = 'custom' as const;
} else {
currentPickerType = shouldUseSelectOverToggle( fontSizes.length )
? ( 'select' as const )
: ( 'togglegroup' as const );
}

const currentPickerType = getPickerType(
// If showing the custom value picker, switch back to predef only
// if `disableCustomFontSizes` is set to `true`.
! disableCustomFontSizes && userRequestedCustom,
fontSizes
);

const headerHint = getHeaderHint(
currentPickerType,
Expand Down

0 comments on commit 41deb9f

Please sign in to comment.