2021-05-08 02:35:11 +03:00
|
|
|
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) => {
|
2021-06-02 19:28:39 +03:00
|
|
|
const { as, maxLines, className, children } = props
|
|
|
|
const Component = as || 'div'
|
2021-05-08 02:35:11 +03:00
|
|
|
return (
|
2021-06-02 19:28:39 +03:00
|
|
|
<Component className={cx('root', className)}>
|
|
|
|
{children}
|
2021-05-08 02:35:11 +03:00
|
|
|
<style jsx>{`
|
|
|
|
.root {
|
|
|
|
display: -webkit-box;
|
2021-06-02 19:28:39 +03:00
|
|
|
-webkit-line-clamp: ${maxLines};
|
2021-05-08 02:35:11 +03:00
|
|
|
-webkit-box-orient: vertical;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
`}</style>
|
|
|
|
</Component>
|
|
|
|
)
|
|
|
|
}
|