-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathfill-width.tsx
More file actions
151 lines (139 loc) · 3.58 KB
/
fill-width.tsx
File metadata and controls
151 lines (139 loc) · 3.58 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import React from 'react';
import useLayoutEffect from "@rc-component/util/lib/hooks/useLayoutEffect";
import Overflow from '../src';
import '../assets/index.less';
import './common.less';
interface ItemType {
value: string | number;
label: string;
}
function createData(count: number): ItemType[] {
const data: ItemType[] = new Array(count).fill(undefined).map((_, index) => ({
value: index,
label: `Label ${index}`,
}));
return data;
}
function renderItem(item: ItemType) {
return (
<div
style={{
margin: '0 16px 0 8px',
padding: '4px 8px',
background: 'rgba(255, 0, 0, 0.2)',
}}
>
{item.label}
</div>
);
}
function renderRest(items: ItemType[]) {
return (
<div
style={{
margin: '0 16px 0 8px',
padding: '4px 8px',
background: 'rgba(255, 0, 0, 0.2)',
}}
>
+{items.length}...
</div>
);
}
const inputStyle: React.CSSProperties = {
border: 'none',
fontSize: 12,
margin: 0,
outline: 'none',
lineHeight: '20px',
fontFamily: '-apple-system',
padding: '0 4px',
};
const Demo = () => {
const [responsive, setResponsive] = React.useState(true);
const [inputValue, setInputValue] = React.useState('');
const [inputWidth, setInputWidth] = React.useState(0);
const [data, setData] = React.useState(createData(3));
const inputRef = React.useRef<HTMLInputElement>();
const measureRef = React.useRef<HTMLDivElement>();
useLayoutEffect(() => {
setInputWidth(measureRef.current.offsetWidth);
}, [inputValue]);
React.useEffect(() => {
inputRef.current.focus();
}, []);
return (
<div style={{ padding: 32 }}>
<button
type="button"
onClick={() => {
setResponsive(!responsive);
}}
>
{responsive ? 'Responsive' : 'MaxCount: 6'}
</button>
<select
style={{ width: 200, height: 32 }}
value={data.length}
onChange={({ target: { value } }) => {
setData(createData(Number(value)));
}}
>
<option value={0}>0</option>
<option value={1}>1</option>
<option value={2}>2</option>
<option value={3}>3</option>
<option value={5}>5</option>
<option value={10}>10</option>
<option value={20}>20</option>
<option value={200}>200</option>
</select>
<div
style={{
border: '5px solid green',
padding: 8,
maxWidth: 300,
marginTop: 32,
}}
>
<Overflow<ItemType>
data={data}
renderItem={renderItem}
renderRest={renderRest}
maxCount={responsive ? 'responsive' : 6}
suffix={
<div style={{ position: 'relative', maxWidth: '100%' }}>
<input
style={{
...inputStyle,
background: 'rgba(0, 0, 0, 0.1)',
width: inputWidth,
minWidth: 10,
maxWidth: '100%',
}}
value={inputValue}
onChange={e => {
setInputValue(e.target.value);
}}
ref={inputRef}
/>
<div
style={{
...inputStyle,
pointerEvents: 'none',
position: 'absolute',
left: 0,
top: `200%`,
}}
ref={measureRef}
>
{inputValue}
</div>
</div>
}
/>
</div>
</div>
);
};
export default Demo;