Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Make FontSizePicker component generic again
  • Loading branch information
luminuu committed Oct 17, 2025
commit d51729df48527fbc8f329d1ab1f31a8dcd393445
9 changes: 1 addition & 8 deletions packages/components/src/font-size-picker/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,10 @@ export type FontSize = {
* size. Used for the class generation process.
*/
slug: string;
/**
* The `fluid` property is an optional object specifying min and max values for
* fluid font sizes.
*/
fluid?: {
min?: string | number;
max?: string | number;
};
/**
* The `hint` property is an optional string that provides additional information
* about the font size, such as fluid typography ranges or custom descriptions.
* Consumers can use this to provide their own preferred hints.
*/
hint?: string;
};
Expand Down
40 changes: 4 additions & 36 deletions packages/components/src/font-size-picker/utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
/**
* WordPress dependencies
*/
import { __, sprintf } from '@wordpress/i18n';

/**
* Internal dependencies
*/
Expand All @@ -24,46 +19,19 @@ export function isSimpleCssValue(
}

/**
* Generates hint text for a font size based on its fluid typography properties.
* This function can be used by consumers to generate hint text for font sizes
* that have fluid typography properties.
* Generates hint text for a font size.
* This function returns the hint provided by the consumer, if any.
* If no hint is provided, it falls back to showing the size value for simple CSS values.
*
* @param fontSize The font size object to generate hint text for.
* @return The generated hint text, or undefined if no hint should be shown.
* @return The hint text provided by the consumer, or the size value for simple CSS values, or undefined.
*/
export function generateFontSizeHint( fontSize: FontSize ): string | undefined {
// If the font size already has a hint, use it
if ( fontSize.hint ) {
return fontSize.hint;
}

// Generate hint from fluid typography properties
if ( fontSize.fluid ) {
const hasMin = isSimpleCssValue( fontSize.fluid.min ?? '' );
const hasMax = isSimpleCssValue( fontSize.fluid.max ?? '' );

if ( hasMin && hasMax ) {
return sprintf(
// translators: 1: the minimum fluid font size value, 2: the maximum fluid font size value.
__( '%1$s - %2$s' ),
String( fontSize.fluid.min! ),
String( fontSize.fluid.max! )
);
} else if ( hasMin ) {
return sprintf(
// translators: %s: the minimum fluid font size value.
__( '>= %s' ),
String( fontSize.fluid.min! )
);
} else if ( hasMax ) {
return sprintf(
// translators: %s: the maximum fluid font size value.
__( '<= %s' ),
String( fontSize.fluid.max! )
);
}
}

// Fallback to showing the size value if it's a simple CSS value
if ( isSimpleCssValue( fontSize.size ) ) {
return String( fontSize.size );
Expand Down
Loading