generated from react-component/footer
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathshow-count.tsx
68 lines (64 loc) · 1.76 KB
/
show-count.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import Input from '@rc-component/input';
import type { FC } from 'react';
import React from 'react';
import '../../assets/index.less';
const sharedHeadStyle: React.CSSProperties = {
margin: 0,
padding: 0,
};
const Demo: FC = () => {
return (
<div
style={{
display: 'flex',
flexDirection: 'column',
gap: 16,
alignItems: 'start',
}}
>
<h3 style={sharedHeadStyle}>Native</h3>
<Input prefixCls="rc-input" showCount defaultValue="👨👩👧👦" />
<Input prefixCls="rc-input" showCount defaultValue="👨👩👧👦" maxLength={20} />
<h3 style={sharedHeadStyle}>Count</h3>
<h4 style={sharedHeadStyle}>Only Max</h4>
<Input
placeholder="count.max"
prefixCls="rc-input"
defaultValue="🔥"
count={{
show: true,
max: 5,
}}
/>
<h4 style={sharedHeadStyle}>Customize strategy</h4>
<Input
placeholder="Emoji count 1"
prefixCls="rc-input"
defaultValue="🔥"
count={{
show: true,
max: 5,
strategy: (val) => [...new Intl.Segmenter().segment(val)].length,
}}
/>
<h4 style={sharedHeadStyle}>Customize exceedFormatter</h4>
<Input
placeholder="Emoji count 1"
prefixCls="rc-input"
defaultValue="🔥"
count={{
show: true,
max: 5,
exceedFormatter: (val, { max }) => {
const segments = [...new Intl.Segmenter().segment(val)];
return segments
.filter((seg) => seg.index + seg.segment.length <= max)
.map((seg) => seg.segment)
.join('');
},
}}
/>
</div>
);
};
export default Demo;