Skip to content

Commit 8ae8912

Browse files
committed
Select react component changes (change component properties)
1 parent 4ce4753 commit 8ae8912

5 files changed

Lines changed: 69 additions & 97 deletions

File tree

index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ReactComponents extends React.Component {
4444
playground: {
4545
codeText: EmptyStateExample,
4646
scope: { React, EmptyState },
47-
docClass: EmptyStateExample
47+
docClass: EmptyState
4848
}
4949
}
5050
];

landing/styles/main.styl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
.auth0-styleguide
2-
// display: none
3-
// &.loaded
4-
// display: block
52

63
@import '../../lib/vars/index'
74
@import '../../lib/mixins/index'

lib/react/select/example.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Select
22
options={[ 'Name', 'Company', 'Location' ]}
3+
selected={0}
4+
handleChange={(e) => {console.log('Selected value: ' + e.target.value);}}
35
label="Search users by"
4-
color="#000"
5-
afterSelect={(selected) => { console.log(selected); }}
66
/>

lib/react/select/index.js

Lines changed: 36 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,36 @@
1-
import React, {Component} from "react";
2-
import styles from "./index.styl";
3-
4-
export default class select extends Component {
5-
static defaultProps = {
6-
options: ["None"],
7-
label: "",
8-
color: "#0a86b1",
9-
width: 100,
10-
afterSelect: () => {}
11-
12-
};
13-
14-
static propTypes = {
15-
options: React.PropTypes.array.isRequired,
16-
label: React.PropTypes.string,
17-
color: React.PropTypes.string,
18-
width: React.PropTypes.number,
19-
afterSelect: React.PropTypes.func
20-
};
21-
22-
state = {
23-
selected: 0
24-
};
25-
26-
showLabel() {
27-
if(this.props.label.length) {
28-
return (<span>{this.props.label} </span>);
29-
}
30-
}
31-
32-
handleChange(e) {
33-
this.setState({
34-
selected: e.target.value
35-
})
36-
37-
return this.props.afterSelect(this.props.options[e.target.value])
38-
}
39-
40-
render() {
41-
var options = this.props.options;
42-
var linkCSS = {
43-
maxWidth: this.props.width,
44-
color: this.props.color
45-
};
46-
47-
return (
48-
<div className={styles.select} onChange={this.handleChange.bind(this)}>
49-
{this.showLabel()}
50-
<span className={styles.value + ' text-truncate'} style={linkCSS}>{options[this.state.selected]}</span>
51-
<i className="icon-budicon-460"></i>
52-
<select>
53-
{
54-
options.map((name, index) => {
55-
return (
56-
<option key={index} value={index}>{name}</option>
57-
);
58-
})
59-
}
60-
</select>
61-
</div>
62-
);
63-
}
64-
}
1+
import React, { Component, PropTypes } from 'react';
2+
import styles from './index.styl';
3+
4+
const Select = (props) => {
5+
const { options, selected, label, color, handleChange } = props;
6+
7+
return (
8+
<div className={styles.select}>
9+
{ label && <span>{label}</span> }
10+
<span className={`${styles.value} text-truncate`} style={{ color }}>{options[selected]}</span>
11+
<i className="icon-budicon-460" />
12+
<select onChange={handleChange} {...props}>
13+
{
14+
options.map((name, index) => <option key={index} value={index}>{name}</option>)
15+
}
16+
</select>
17+
</div>
18+
);
19+
};
20+
21+
Select.defaultProps = {
22+
options: [ 'Default' ],
23+
selected: 0,
24+
label: '',
25+
handleChange: () => {}
26+
};
27+
28+
Select.propTypes = {
29+
options: PropTypes.arrayOf(PropTypes.string).isRequired,
30+
selected: PropTypes.number.isRequired,
31+
handleChange: PropTypes.func.isRequired,
32+
label: PropTypes.string,
33+
color: PropTypes.string
34+
};
35+
36+
export default Select;

lib/react/select/index.styl

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,39 @@
1+
@import '../../vars/index'
2+
13
.select
2-
display: inline-block;
3-
vertical-align: top;
4-
position: relative;
5-
cursor: pointer;
6-
height: 35px;
7-
line-height: 35px;
8-
padding: 0 15px;
9-
padding-right: 25px;
10-
cursor: pointer;
11-
background: #e6e6e6;
12-
border-radius: 3px;
4+
display inline-block
5+
vertical-align top
6+
position relative
7+
cursor pointer
8+
height 35px
9+
line-height 35px
10+
padding 0 15px
11+
padding-right 25px
12+
cursor pointer
13+
background $bg-color-gray
14+
border-radius $border-radius-base
1315

1416
> span
15-
display: inline-block;
16-
overflow: hidden;
17+
display inline-block
18+
overflow hidden
1719

1820
.value
19-
max-width: 110px;
20-
margin-left: 4px;
21+
max-width 110px
22+
margin-left 4px
23+
color $color-blue-medium
2124

2225
i
23-
position: absolute;
24-
right: 8px;
25-
top: 14px;
26-
font-size: 12px;
27-
opacity: 0.7;
26+
position absolute
27+
right 8px
28+
top 14px
29+
font-size 12px
30+
opacity 0.7
2831

2932
select
30-
position: absolute;
31-
top: 0;
32-
left: 0;
33-
width: 100%;
34-
height: 100%;
35-
opacity: 0;
36-
-webkit-appearance: none;
33+
position absolute
34+
top 0
35+
left 0
36+
width 100%
37+
height 100%
38+
opacity 0
39+
-webkit-appearance none

0 commit comments

Comments
 (0)