Skip to content
Merged
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
11 changes: 7 additions & 4 deletions src/Truncate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import styled from 'styled-components'
import {maxWidth, MaxWidthProps} from 'styled-system'
import sx, {SxProp} from './sx'
import {ForwardRefComponent as PolymorphicForwardRefComponent} from './utils/polymorphic'
import {ComponentProps} from './utils/types'

type StyledTruncateProps = {
Expand All @@ -22,9 +23,11 @@ const StyledTruncate = styled.div<StyledTruncateProps>`
${sx};
`

export type TruncateProps = ComponentProps<typeof StyledTruncate>
const Truncate = ({expandable = false, inline = false, maxWidth = 125, ...rest}: TruncateProps) => (
<StyledTruncate maxWidth={maxWidth} expandable={expandable} inline={inline} {...rest} />
)
const Truncate = React.forwardRef(({expandable = false, inline = false, maxWidth = 125, ...rest}, ref) => (
<StyledTruncate ref={ref} maxWidth={maxWidth} expandable={expandable} inline={inline} {...rest} />
)) as PolymorphicForwardRefComponent<'div', StyledTruncateProps>

Truncate.displayName = 'Truncate'

export type TruncateProps = ComponentProps<typeof Truncate>
export default Truncate