Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions packages/ui-truncate-text/src/TruncateText/v2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@ class TruncateText extends Component<TruncateTextProps, TruncateTextState> {
if (canUseDOM) {
const result = truncate(this._stage!, {
...this.props,
parent: this.ref ? this.ref : undefined,
lineHeight: this.props.styles?.lineHeight as number
parent: this.ref ? this.ref : undefined
})
if (result) {
const element = this.renderChildren(
Expand Down
4 changes: 1 addition & 3 deletions packages/ui-truncate-text/src/TruncateText/v2/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ type TruncateTextProps = TruncateTextOwnProps &
TruncateTextStyle
>

type TruncateTextStyle = ComponentStyle<
'truncateText' | 'auto' | 'spacer' | 'lineHeight'
>
type TruncateTextStyle = ComponentStyle<'truncateText' | 'auto' | 'spacer'>

type TruncateTextState = {
isTruncated: boolean
Expand Down
3 changes: 1 addition & 2 deletions packages/ui-truncate-text/src/TruncateText/v2/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ const generateStyle = (
visibility: 'hidden',
maxHeight: '0',
display: 'block'
},
lineHeight: componentTheme.lineHeight
}
}
}
export default generateStyle
12 changes: 6 additions & 6 deletions packages/ui-truncate-text/src/TruncateText/v2/utils/truncate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@ import { TruncateTextCommonProps } from '../props.js'

export type TruncatorOptions = {
parent?: Node
lineHeight?: number
} & TruncateTextCommonProps

type NodeMapData = {
node: Node
data: string[]
}
const DEFAULT_LINE_HEIGHT = 1.5

/**
* ---
Expand Down Expand Up @@ -89,14 +89,14 @@ class Truncator {
const parentElement = element?.parentElement
? element?.parentElement
: undefined

this._options = {
parent: options.parent || parentElement,
maxLines: options.maxLines || 1,
position: options.position || 'end',
truncate: options.truncate || 'character',
ellipsis: options.ellipsis || '\u2026',
ignore: options.ignore || [' ', '.', ','],
lineHeight: options.lineHeight || 1.2,
shouldTruncateWhenInvisible: !!options.shouldTruncateWhenInvisible
}

Expand Down Expand Up @@ -128,11 +128,11 @@ class Truncator {
return
}

const { maxLines, truncate, lineHeight } = this._options
const { maxLines, truncate } = this._options
// if no explicit lineHeight is inherited, use lineHeight multiplier for calculations
const actualLineHeight =
style.lineHeight === 'normal'
? lineHeight * parseFloat(style.fontSize)
? DEFAULT_LINE_HEIGHT * parseFloat(style.fontSize)
: parseFloat(style.lineHeight)
const node = (this._stage.firstChild as Element).children
? this._stage.firstChild!
Expand Down Expand Up @@ -192,8 +192,8 @@ class Truncator {
textContent.match(/.*?[\.\s\/]+?/g)!
: ['']
: shouldTruncate
? node.textContent!.split('')
: []
? node.textContent!.split('')
: []
})
}
})
Expand Down
Loading