Skip to content

Commit

Permalink
Add Truncate helper to @wordpress/components
Browse files Browse the repository at this point in the history
Use to truncate text contents to a particular length or number of lines.

Available as of Gutenberg 9.9

https://make.wordpress.org/core/2021/02/05/whats-new-in-gutenberg-9-9-5-february/

WordPress/gutenberg#28176
  • Loading branch information
lipemat committed Feb 15, 2021
1 parent 441d012 commit 02f310a
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions wordpress__components/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,23 @@ declare module '@wordpress/components' {
type?: string;
}

/**
* Truncate is a typography primitive that trims text content.
* For almost all cases, it is recommended that Text, Heading, or Subheading is used to render text content.
*
* However, Truncate is available for custom implementations.
*/
interface Truncate {
// The ellipsis string when truncate is set.
ellipsis?: string;
// Determines where to truncate. For example, we can truncate text right in the middle. To do this, we need to set ellipsizeMode to middle and a text limit.
ellipsizeMode?: 'auto' | 'head' | 'middle' | 'tail';
// Determines the max characters when truncate is set.
limit?: number;
// Clamps the text content to the specifiec numberOfLines, adding the ellipsis at the end.
numberOfLines?: number;
}

export interface withSpokenMessages {
speak?: ( message: string, ariaLive?: 'polite' | 'assertive' ) => void;
debouncedSpeak?: ( message: string, ariaLive?: 'polite' | 'assertive' ) => void;
Expand All @@ -510,6 +527,7 @@ declare module '@wordpress/components' {
export const Spinner: ComponentType<{}>;
export const TextControl: ComponentType<TextControl>;
export const Tooltip: Tooltip;
export const Truncate: Truncate;

export default interface Components {
Button: ComponentType<ButtonLink | ButtonButton>;
Expand All @@ -527,6 +545,7 @@ declare module '@wordpress/components' {
Spinner: ComponentType<{}>;
TextControl: ComponentType<TextControl>;
Tooltip: ComponentType<Tooltip>;
Truncate: Truncate;
}
}

0 comments on commit 02f310a

Please sign in to comment.