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

Truncate: Convert component to TypeScript #41697

Merged
merged 17 commits into from
Jun 23, 2022
Prev Previous commit
Next Next commit
Use truncateProps
Petter Walbø Johnsgård committed Jun 21, 2022
commit bcd56757972292d940d398fc6ef977074031b2d5
15 changes: 11 additions & 4 deletions packages/components/src/truncate/utils.ts
Original file line number Diff line number Diff line change
@@ -2,9 +2,16 @@
* Internal dependencies
*/
import { isValueDefined } from '../utils/values';
import type { TruncateProps } from './types';

export const TRUNCATE_ELLIPSIS = '…';
export const TRUNCATE_TYPE = {
export const TRUNCATE_TYPE: {
auto: 'auto';
head: 'head';
middle: 'middle';
tail: 'tail';
none: 'none';
} = {
auto: 'auto',
head: 'head',
middle: 'middle',
@@ -60,7 +67,7 @@ export function truncateMiddle(

export function truncateContent(
words: string = '',
props: typeof TRUNCATE_DEFAULT_PROPS
props: Omit< TruncateProps, 'children' >
) {
const mergedProps = { ...TRUNCATE_DEFAULT_PROPS, ...props };
const { ellipsis, ellipsizeMode, limit } = mergedProps;
@@ -69,8 +76,8 @@ export function truncateContent(
return words;
}

let truncateHead;
let truncateTail;
let truncateHead: number;
let truncateTail: number;

switch ( ellipsizeMode ) {
case TRUNCATE_TYPE.head: