1
0
mirror of synced 2025-12-21 10:57:10 -05:00
Files
docs/components/TruncateLines.tsx
2021-05-07 16:35:11 -07:00

26 lines
595 B
TypeScript

import React, { ReactNode, ReactHTML } from 'react'
import cx from 'classnames'
type Props = {
as?: keyof ReactHTML
maxLines: number
children: ReactNode
className?: string
}
export const TruncateLines = (props: Props) => {
const Component = props.as || 'div'
return (
<Component className={cx('root', props.className)}>
{props.children}
<style jsx>{`
.root {
display: -webkit-box;
-webkit-line-clamp: ${props.maxLines};
-webkit-box-orient: vertical;
overflow: hidden;
}
`}</style>
</Component>
)
}