Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add select field component #62

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ linkPrefix = "/react-mdc-web"
[[components]]
name = "Menu"
path = "/components/menu/"
[[components]]
name = "Select Field"
path = "/components/select_field/"
[[components]]
name = "Radio"
path = "/components/radio/"
Expand Down
47 changes: 47 additions & 0 deletions docs/pages/components/select_field/_template.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React, {PropTypes} from 'react';
import ReactDOM from 'react-dom';
import {Option, SelectField} from '../../../../src/SelectField';

class Template extends React.Component {
static propTypes = {
children: PropTypes.node,
};

constructor(props) {
super(props);
this.state = {
selected: ''
};
}

componentDidMount() {
const container = document.getElementById('select_field');
ReactDOM.render(this.renderSelectField(), container);
}

onChange({ target }) {
this.setState({ selected: target.value });
}

renderSelectField() {
return (
<SelectField
onChange={this.onChange.bind(this)}
value={this.state.selected}
>
<Option value="first">First select field </Option>
<Option value="second">Second select field</Option>
<Option value="third">Third select field </Option>
</SelectField>
);
}

render() {
return (
<div>
{this.props.children}
</div>
);
}
}
export default Template;
21 changes: 21 additions & 0 deletions docs/pages/components/select_field/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
title: "Select Field"
---

```react-snippet
select_field
```
```jsx
onChange({ target }) {
this.setState({ selected: target.value });
}

<SelectField
onChange={this.onChange.bind(this)}
value={this.state.selected}
>
<Option value="first">First select field </Option>
<Option value="second">Second select field</Option>
<Option value="third">Third select field </Option>
</SelectField>
```
11 changes: 11 additions & 0 deletions src/SelectField/Option.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';

const Option = props =>
<option
onClick={props.onClick}
value={props.value}
>
{props.children}
</option>;

export default Option;
11 changes: 11 additions & 0 deletions src/SelectField/SelectField.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';

const SelectField = props => <select
onChange={props.onChange}
className='mdc-select'
style={{ marginTop: '20px' }}
>
{props.children}
</select>;

export default SelectField;
2 changes: 2 additions & 0 deletions src/SelectField/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { default as Option } from './Option';
export { default as SelectField } from './SelectField';