@ohkit/text-ellipsis 0.0.2-alpha.2 → 0.0.2-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -6
- package/src/__test__/data.tsx +0 -42
- package/src/index.stories.tsx +0 -149
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohkit/text-ellipsis",
|
|
3
|
-
"version": "0.0.2-alpha.
|
|
3
|
+
"version": "0.0.2-alpha.4",
|
|
4
4
|
"description": "text ellipsis for react",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"text ellipsis"
|
|
@@ -17,10 +17,6 @@
|
|
|
17
17
|
"dist": "dist",
|
|
18
18
|
"test": "__tests__"
|
|
19
19
|
},
|
|
20
|
-
"files": [
|
|
21
|
-
"dist",
|
|
22
|
-
"src"
|
|
23
|
-
],
|
|
24
20
|
"publishConfig": {
|
|
25
21
|
"registry": "https://registry.npmjs.org/",
|
|
26
22
|
"access": "public"
|
|
@@ -47,5 +43,5 @@
|
|
|
47
43
|
"react": ">=16.8.0",
|
|
48
44
|
"react-dom": ">=16.8.0"
|
|
49
45
|
},
|
|
50
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "8ac135fcd546178414824efd94cf46eb961fb065"
|
|
51
47
|
}
|
package/src/__test__/data.tsx
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @description: 测试数据
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export const text =
|
|
6
|
-
"改变文本容器宽度看看效果\n" +
|
|
7
|
-
"测试文本也可以是reactDom测试文本也可以是reactDom测试文本也可以是reactDom\n" +
|
|
8
|
-
"测试文本也可以是reactDom测试文本也可以是reactDom测试文本也可以是reactDom\n" +
|
|
9
|
-
"测试文本也可以是reactDom测试文本也可以是reactDom测试文本也可以是reactDom\n" +
|
|
10
|
-
"测试文本也可以是reactDom测试文本也可以是reactDom测试文本也可以是reactDom";
|
|
11
|
-
|
|
12
|
-
export const element = (
|
|
13
|
-
<article>
|
|
14
|
-
<aside>一篇富文本文章 导航</aside>
|
|
15
|
-
<h1>大标题</h1>
|
|
16
|
-
<p>{text}</p>
|
|
17
|
-
<div>
|
|
18
|
-
<img width="160" src="//www.baidu.com/img/PCtm_d9c8750bed0b3c7d089fa7d55720d6cf.png" />
|
|
19
|
-
</div>
|
|
20
|
-
<div>
|
|
21
|
-
<table>
|
|
22
|
-
<tbody>
|
|
23
|
-
<tr>
|
|
24
|
-
<td>1</td>
|
|
25
|
-
<td>2</td>
|
|
26
|
-
</tr>
|
|
27
|
-
<tr>
|
|
28
|
-
<td>3</td>
|
|
29
|
-
<td>4</td>
|
|
30
|
-
</tr>
|
|
31
|
-
</tbody>
|
|
32
|
-
</table>
|
|
33
|
-
</div>
|
|
34
|
-
<h3>三级标题</h3>
|
|
35
|
-
<ul>
|
|
36
|
-
<li>12 <a href="https://www.baidu.com">百度一下</a></li>
|
|
37
|
-
<li>34</li>
|
|
38
|
-
<li>56</li>
|
|
39
|
-
<li>78</li>
|
|
40
|
-
</ul>
|
|
41
|
-
</article>
|
|
42
|
-
);
|
package/src/index.stories.tsx
DELETED
|
@@ -1,149 +0,0 @@
|
|
|
1
|
-
import {useState, useCallback} from 'react';
|
|
2
|
-
import type { Meta, StoryObj } from '@storybook/react';
|
|
3
|
-
import { Button, Tooltip, Popover } from 'antd';
|
|
4
|
-
import { DownOutlined, UpOutlined } from '@ant-design/icons';
|
|
5
|
-
|
|
6
|
-
import { TextEllipsis, TextEllipsisProps } from '.';
|
|
7
|
-
import { text, element } from './__test__/data';
|
|
8
|
-
|
|
9
|
-
const meta = {
|
|
10
|
-
// title: 'Components/TextEllipsis',
|
|
11
|
-
component: TextEllipsis,
|
|
12
|
-
tags: ['autodocs'],
|
|
13
|
-
} satisfies Meta<typeof TextEllipsis>;
|
|
14
|
-
|
|
15
|
-
export default meta;
|
|
16
|
-
|
|
17
|
-
type Story = StoryObj<typeof meta>;
|
|
18
|
-
|
|
19
|
-
export const Right: Story = {
|
|
20
|
-
args: {
|
|
21
|
-
lines: 2,
|
|
22
|
-
content: text,
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
export const RightCustom: Story = {
|
|
26
|
-
args: {
|
|
27
|
-
lines: 2,
|
|
28
|
-
content: text,
|
|
29
|
-
showTitleWhenFold: true,
|
|
30
|
-
renderFoldButton: (fold) => {
|
|
31
|
-
return <Button
|
|
32
|
-
size='small'
|
|
33
|
-
type='link'
|
|
34
|
-
color='primary'
|
|
35
|
-
iconPosition='end'
|
|
36
|
-
icon={fold ? <DownOutlined /> : <UpOutlined />}
|
|
37
|
-
>
|
|
38
|
-
自定义{fold ? '展开' : '收起'}
|
|
39
|
-
</Button>;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const Bottom: Story = {
|
|
45
|
-
args: {
|
|
46
|
-
lines: 2,
|
|
47
|
-
uiType: 'bottom',
|
|
48
|
-
showTitleWhenFold: true,
|
|
49
|
-
titleWhenFold: '如果太长了hover我也就不展示全了,可自定义title文案',
|
|
50
|
-
content: text,
|
|
51
|
-
lineHeight: '22px',
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const RichText: Story = {
|
|
56
|
-
args: {
|
|
57
|
-
lines: 7,
|
|
58
|
-
uiType: 'bottom',
|
|
59
|
-
content: element,
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
|
|
63
|
-
export const CustomWithTooltip: Story = {
|
|
64
|
-
render: (args) => {
|
|
65
|
-
const [visible, setVisible] = useState(false);
|
|
66
|
-
const [title, setTitle] = useState('');
|
|
67
|
-
const handleVisibleChange = useCallback((newVisible: boolean) => {
|
|
68
|
-
console.log('handleVisibleChange newVisible', newVisible);
|
|
69
|
-
setVisible(newVisible);
|
|
70
|
-
}, []);
|
|
71
|
-
const handleStatusChange = useCallback<NonNullable<TextEllipsisProps['onStatusChange']>>((status) => {
|
|
72
|
-
console.log('触发了 onStatusChange 回调', status);
|
|
73
|
-
const {ellipsis, fold, title} = status;
|
|
74
|
-
if (ellipsis && fold && title) {
|
|
75
|
-
setTitle(title);
|
|
76
|
-
} else {
|
|
77
|
-
setTitle('');
|
|
78
|
-
setVisible(false);
|
|
79
|
-
}
|
|
80
|
-
}, []);
|
|
81
|
-
return (
|
|
82
|
-
<Tooltip
|
|
83
|
-
title={<div style={{maxHeight: 350, overflowY: 'auto'}}>{title}</div>}
|
|
84
|
-
open={visible}
|
|
85
|
-
onOpenChange={title ? handleVisibleChange : undefined}
|
|
86
|
-
placement='bottomRight'
|
|
87
|
-
mouseEnterDelay={0.3}
|
|
88
|
-
>
|
|
89
|
-
<TextEllipsis {...args} onStatusChange={handleStatusChange} />
|
|
90
|
-
</Tooltip>
|
|
91
|
-
)
|
|
92
|
-
},
|
|
93
|
-
args: {
|
|
94
|
-
lines: 2,
|
|
95
|
-
uiType: 'right',
|
|
96
|
-
content: '适合不是特别长的文本,太长出滚动条比较丑:\n' + text,
|
|
97
|
-
lineHeight: '22px',
|
|
98
|
-
onFoldChange: (fold) => {
|
|
99
|
-
console.log('触发了 onFoldChange 回调 fold', fold);
|
|
100
|
-
},
|
|
101
|
-
onEllipsisChange: (ellipsis) => {
|
|
102
|
-
console.log('触发了 onEllipsisChange 回调 ellipsis', ellipsis);
|
|
103
|
-
},
|
|
104
|
-
}
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
export const CustomWithPopover: Story = {
|
|
108
|
-
render: (args) => {
|
|
109
|
-
const [visible, setVisible] = useState(false);
|
|
110
|
-
const [title, setTitle] = useState('');
|
|
111
|
-
const handleVisibleChange = useCallback((newVisible: boolean) => {
|
|
112
|
-
setVisible(newVisible);
|
|
113
|
-
}, []);
|
|
114
|
-
const handleStatusChange = useCallback<NonNullable<TextEllipsisProps['onStatusChange']>>((status) => {
|
|
115
|
-
console.log('触发了 onStatusChange 回调', status);
|
|
116
|
-
const {ellipsis, fold, title} = status;
|
|
117
|
-
if (ellipsis && fold && title) {
|
|
118
|
-
setTitle(title);
|
|
119
|
-
} else {
|
|
120
|
-
setTitle('');
|
|
121
|
-
setVisible(false);
|
|
122
|
-
}
|
|
123
|
-
}, []);
|
|
124
|
-
return (
|
|
125
|
-
<Popover
|
|
126
|
-
title={<div style={{maxHeight: 300, maxWidth: 400, overflowY: 'auto'}}>{title}</div>}
|
|
127
|
-
open={visible}
|
|
128
|
-
onOpenChange={title ? handleVisibleChange : undefined}
|
|
129
|
-
placement='bottomRight'
|
|
130
|
-
mouseEnterDelay={0.3}
|
|
131
|
-
>
|
|
132
|
-
<TextEllipsis {...args} onStatusChange={handleStatusChange} />
|
|
133
|
-
</Popover>
|
|
134
|
-
)
|
|
135
|
-
},
|
|
136
|
-
args: {
|
|
137
|
-
lines: 2,
|
|
138
|
-
uiType: 'right',
|
|
139
|
-
showFoldControl: false,
|
|
140
|
-
content: '适合超长文本,出滚动条:\n' + text + text + text,
|
|
141
|
-
lineHeight: '22px',
|
|
142
|
-
onFoldChange: (fold) => {
|
|
143
|
-
console.log('触发了 onFoldChange 回调 fold', fold);
|
|
144
|
-
},
|
|
145
|
-
onEllipsisChange: (ellipsis) => {
|
|
146
|
-
console.log('触发了 onEllipsisChange 回调 ellipsis', ellipsis);
|
|
147
|
-
},
|
|
148
|
-
}
|
|
149
|
-
};
|