tdesign-react
Version:
TDesign Component for React
74 lines (72 loc) • 3.05 kB
TypeScript
/**
* LICENSE
* https://github.com/pablosichert/react-truncate/blob/master/LICENSE.md
*
* ISC License
*
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is
hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE
FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
import React from 'react';
import PropTypes from 'prop-types';
export type TruncateProps = {
children: React.ReactNode;
ellipsis: React.ReactNode;
onTruncate: (truncated: boolean) => void;
lines: number;
trimWhitespace: boolean;
width: number;
className: string;
lineClassName: string;
};
export type TruncateState = {
targetWidth?: number;
};
export default class Truncate extends React.Component<TruncateProps, TruncateState> {
static propTypes: {
children: PropTypes.Requireable<PropTypes.ReactNodeLike>;
ellipsis: PropTypes.Requireable<PropTypes.ReactNodeLike>;
lines: PropTypes.Requireable<NonNullable<number | boolean>>;
trimWhitespace: PropTypes.Requireable<boolean>;
width: PropTypes.Requireable<number>;
onTruncate: PropTypes.Requireable<(...args: any[]) => any>;
className: PropTypes.Requireable<string>;
lineClassName: PropTypes.Requireable<string>;
};
static defaultProps: {
children: string;
ellipsis: string;
lines: number;
trimWhitespace: boolean;
width: number;
lineClassName: string;
};
elements: Record<string, HTMLElement>;
replacedLinks: Array<Record<string, string>>;
calculatedEllipsisWidth: boolean;
canvasContext: CanvasRenderingContext2D;
timeout: number;
state: TruncateState;
constructor(props: TruncateProps);
componentDidMount(): void;
componentDidUpdate(prevProps: TruncateProps): void;
componentWillUnmount(): void;
extractReplaceLinksKeys: (content: any) => any;
restoreReplacedLinks: (content: string) => string;
innerText: (node: HTMLElement) => string;
onResize: () => void;
onTruncate: (didTruncate: boolean) => void;
calcTargetWidth: (callback?: () => void) => number;
measureWidth: (text: string) => number;
ellipsisWidth: (node: HTMLElement) => number;
trimRight: (text: string) => string;
createMarkup: (str: string) => React.JSX.Element;
getLines: () => (React.JSX.Element | React.JSX.Element[])[];
renderLine: (line: React.ReactNode, i: number, arr: Array<string>) => React.JSX.Element | React.JSX.Element[];
render(): React.JSX.Element;
}