Skip to content

Commit b03a7ef

Browse files
authored
feat(Select): add custom style
close #227
1 parent dc37f94 commit b03a7ef

File tree

6 files changed

+157
-19
lines changed

6 files changed

+157
-19
lines changed

src/components/Select/Select.jsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,19 @@ class Select extends Component {
105105
/** @ignore */
106106
onVisibleChange: PropTypes.func,
107107
/** @ignore */
108-
locale: PropTypes.object
108+
locale: PropTypes.object,
109+
/**
110+
* 可修改自定义样式集中营
111+
*/
112+
customStyle: PropTypes.shape({
113+
optionListMaxHeight: PropTypes.number
114+
})
109115
};
110116
static defaultProps = {
111117
onChange: () => {},
112118
size: 'md',
113-
onVisibleChange: () => {}
119+
onVisibleChange: () => {},
120+
customStyle: {}
114121
};
115122
componentWillReceiveProps(nextProps) {
116123
const { children, options } = nextProps;
@@ -196,7 +203,7 @@ class Select extends Component {
196203
}
197204
};
198205
renderPopup = () => {
199-
const { search, children, onChange, multiple, showSelectAll, value, options, extra } = this.props;
206+
const { search, children, onChange, multiple, showSelectAll, value, options, extra, customStyle } = this.props;
200207
const { searchValue, itemTree } = this.state;
201208
const Options = this.renderOptions(options);
202209
const Extra = this.renderExtra(extra);
@@ -222,6 +229,7 @@ class Select extends Component {
222229
onChange(value);
223230
}
224231
}}
232+
customStyle={customStyle}
225233
itemTree={itemTree}
226234
multiple={multiple}
227235
showSelectAll={showSelectAll}
@@ -292,6 +300,7 @@ class Select extends Component {
292300
renderSelector,
293301
popover,
294302
popoverProps,
303+
customStyle,
295304
...rest
296305
} = this.props;
297306
/* eslint-enable no-unused-vars */

src/components/Select/Select.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,8 @@
5858

5959
```js {"codepath": "popoverProps.jsx"}
6060
```
61+
62+
* customStyle - 可自定义样式
63+
64+
```js {"codepath": "customStyle.jsx"}
65+
```
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from 'react';
2+
3+
import Select from 'src/components/Select';
4+
5+
// demo start
6+
const { Option } = Select;
7+
8+
class Demo extends React.Component {
9+
render() {
10+
return (
11+
<div>
12+
<h3>optionListMaxHeight</h3>
13+
<div className="demo-wrap">
14+
<Select
15+
multiple
16+
showSelectAll
17+
search
18+
onChange={console.log}
19+
customStyle={{ optionListMaxHeight: 100 }}
20+
>
21+
{new Array(100).fill(null).map((v, i) => (
22+
<Option key={i} value={`v_${i}`}>
23+
option{i}
24+
</Option>
25+
))}
26+
</Select>
27+
</div>
28+
</div>
29+
);
30+
}
31+
}
32+
// demo end
33+
34+
export default Demo;

src/components/Select/__demo__/extra.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React from 'react';
2+
23
import Select from 'src/components/Select';
34
import Button from 'src/components/Button';
45

src/components/Select/__tests__/__snapshots__/demo.test.js.snap

Lines changed: 98 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`Select demo -- disabled 1`] = `
3+
exports[`Select demo -- customStyle 1`] = `
44
.c4 {
55
vertical-align: baseline;
66
}
@@ -35,14 +35,59 @@ exports[`Select demo -- disabled 1`] = `
3535
box-shadow: 0 0 1px 0 rgba(0,0,0,0.12),0 8px 12px -4px rgba(0,0,0,0.12),0 2px 1px -1px rgba(0,0,0,0.05);
3636
}
3737
38-
.c2.c2 {
39-
border-color: #d9d9d9;
40-
background: #f7f7f7;
41-
color: #cccccc;
42-
cursor: not-allowed;
43-
border-width: 1px;
44-
border-style: solid;
45-
box-shadow: none;
38+
.c1 {
39+
padding-right: 28px;
40+
width: 100%;
41+
text-align: left;
42+
}
43+
44+
.c3 {
45+
position: absolute;
46+
right: 8px;
47+
top: 50%;
48+
margin-top: -6px;
49+
}
50+
51+
.c0 {
52+
box-sizing: border-box;
53+
position: relative;
54+
display: inline-block;
55+
vertical-align: middle;
56+
font-size: 12px;
57+
color: #0a1633;
58+
}
59+
60+
<div>
61+
<h3>
62+
optionListMaxHeight
63+
</h3>
64+
<div
65+
class="demo-wrap"
66+
>
67+
<div
68+
class="c0"
69+
>
70+
<div>
71+
<button
72+
class="c1 uc-fe-button uc-fe-button-size-md uc-fe-button-styletype-border c2"
73+
type="button"
74+
>
75+
<div>
76+
请选择
77+
</div>
78+
<i
79+
class="uc-fe-icon icon__down c3 c4"
80+
/>
81+
</button>
82+
</div>
83+
</div>
84+
</div>
85+
</div>
86+
`;
87+
88+
exports[`Select demo -- disabled 1`] = `
89+
.c4 {
90+
vertical-align: baseline;
4691
}
4792
4893
.c6 {
@@ -75,6 +120,46 @@ exports[`Select demo -- disabled 1`] = `
75120
box-shadow: 0 0 1px 0 rgba(0,0,0,0.12),0 8px 12px -4px rgba(0,0,0,0.12),0 2px 1px -1px rgba(0,0,0,0.05);
76121
}
77122
123+
.c2 {
124+
margin: 0;
125+
box-sizing: border-box;
126+
border-radius: 2px;
127+
border-width: 1px;
128+
border-style: solid;
129+
text-align: center;
130+
-webkit-text-decoration: none;
131+
text-decoration: none;
132+
cursor: pointer;
133+
outline: none;
134+
font-size: 12px;
135+
display: inline-block;
136+
vertical-align: middle;
137+
height: 28px;
138+
padding: 0 8px;
139+
color: #0a1633;
140+
background: #ffffff;
141+
border: none;
142+
box-shadow: 0 1px 2px 0 rgba(0,0,0,0.08),0 1px 1px -1px rgba(0,0,0,0.30),0 1px 3px -1px rgba(0,0,0,0.12),inset 0 1px 0 0 rgba(0,0,0,0.05);
143+
-webkit-transition: all .22s cubic-bezier(.4,0,.2,1);
144+
transition: all .22s cubic-bezier(.4,0,.2,1);
145+
}
146+
147+
.c2:hover {
148+
color: #3860f4;
149+
background: #ffffff;
150+
box-shadow: 0 0 1px 0 rgba(0,0,0,0.12),0 8px 12px -4px rgba(0,0,0,0.12),0 2px 1px -1px rgba(0,0,0,0.05);
151+
}
152+
153+
.c2.c2 {
154+
border-color: #d9d9d9;
155+
background: #f7f7f7;
156+
color: #cccccc;
157+
cursor: not-allowed;
158+
border-width: 1px;
159+
border-style: solid;
160+
box-shadow: none;
161+
}
162+
78163
.c1 {
79164
padding-right: 28px;
80165
width: 100%;
@@ -88,24 +173,24 @@ exports[`Select demo -- disabled 1`] = `
88173
margin-top: -6px;
89174
}
90175
91-
.c0 {
176+
.c5 {
92177
box-sizing: border-box;
93178
position: relative;
94179
display: inline-block;
95180
vertical-align: middle;
96181
font-size: 12px;
97182
color: #0a1633;
98-
color: #cccccc;
99-
pointer-events: none;
100183
}
101184
102-
.c5 {
185+
.c0 {
103186
box-sizing: border-box;
104187
position: relative;
105188
display: inline-block;
106189
vertical-align: middle;
107190
font-size: 12px;
108191
color: #0a1633;
192+
color: #cccccc;
193+
pointer-events: none;
109194
}
110195
111196
<div>

src/components/Select/style/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import React from 'react';
12
import styled, { css } from 'styled-components';
23

34
import addDefaultThemeProps from 'src/components/ThemeProvider/addDefaultThemeProps';
@@ -50,12 +51,15 @@ export const MenuWrap = styled.div(
5051
`
5152
);
5253

53-
export const BlockMenu = styled(Menu)(
54-
() => css`
54+
// eslint-disable-next-line react/prop-types,no-unused-vars
55+
const CustomMenu = ({ customStyle, ...rest }) => <Menu {...rest} />;
56+
57+
export const BlockMenu = styled(CustomMenu)(
58+
({ customStyle }) => css`
5559
display: block;
5660
border: none;
5761
box-shadow: none;
58-
max-height: 380px;
62+
max-height: ${customStyle.optionListMaxHeight || 380}px;
5963
max-width: unset;
6064
`
6165
);

0 commit comments

Comments
 (0)