1.0.4 • Published 1 year ago

water-design-ellipsis v1.0.4

Weekly downloads
-
License
ISC
Repository
-
Last release
1 year ago

综述

该组件适用于 web 环境下的文本溢出,支持:

  • 单行溢出隐藏(设置 width & height 即可)
    • 支持溢出尾部省略隐藏
    • 支持溢出中间部分省略隐藏
  • 多行溢出隐藏(设置 width & height & line 即可)
  • 单行或多行溢出直接截断(设置 defaultDirectCuttrue 即可)
  • 支持溢出时 hover 有 tooltip 提示,移动端不支持 tooltip 提示,默认enableTooltip开启,请合理设置宽高和字体行高。

使用

import React from 'react';
import { createRoot } from 'react-dom/client';
import Ellipsis from 'water-design-ellipsis';
import './index.css';

function App() {
  return (
    <Ellipsis
      className="title"
      tooltipProps={{ textColor: 'pink', className: 'tool-tip' }}
    >
      看花不是花,看雾亦非雾,是宿命还是我糊涂;看岁月晃晃悠悠,不紧不慢拉着我走
    </Ellipsis>
  );
}

const root = createRoot(document.getElementById('root'));
root.render(<App />);
.title {
  width: 300px;
  height: 30px;
  font-size: 24px;
  line-height: 30px;
  background-color: skyblue;
}

.tool-tip {
  width: 260px;
}

API

参数说明类型默认值版本
className自定义类名string-
style自定义样式对象CSSProperties-
defaultDirectCut选择文本溢出直接截断,无省略号booleanfalse
middleOverflow是否选择中间位置省略boolean-
endCharCount当一行溢出时,且选择中间省略时,文本尾部字符数number4
line选择文本多少行溢出隐藏, 仅在尾部省略生效number1
prevTextClassName单行溢出省略前文本自定义类名string-
nextTextClassName单行溢出省略后文本自定义类名string-
wordClassName直接截断每个字符自定义类名string-
prevTextStyle单行溢出省略前文本自定义样式对象CSSProperties-
nextTextStyle单行溢出省略后文本自定义样式对象CSSProperties-
wordStyle直接截断每个字符自定义样式对象CSSProperties-
enableTooltip是否开启 tooltip 提示,仅在 PC 端生效booleantrue
tooltipProps提示传入的属性,继承库react-tooltip中的TooltipPropsTooltipProps-
children文本string-

注:单行溢出外层会嵌套一层盒子,可通过prevTextClassName,prevTextStyle修改内层盒子样式。

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago