Skip to content

Commit

Permalink
migrate select-field docs to the new standard
Browse files Browse the repository at this point in the history
  • Loading branch information
alitaheri committed Dec 29, 2015
1 parent 7355635 commit 12e27ec
Show file tree
Hide file tree
Showing 14 changed files with 474 additions and 540 deletions.
4 changes: 2 additions & 2 deletions docs/src/app/app-routes.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import Paper from './components/pages/components/paper';
import Popover from './components/pages/components/popover';
import Progress from './components/pages/components/progress';
import RefreshIndicator from './components/pages/components/refresh-indicator';
import SelectFields from './components/pages/components/select-fields';
import SelectField from './components/pages/components/SelectField/Page';
import Sliders from './components/pages/components/sliders';
import SnackbarPage from './components/pages/components/Snackbar/Page';
import Switches from './components/pages/components/switches';
Expand Down Expand Up @@ -104,7 +104,7 @@ const AppRoutes = (
<Route path="popover" component={Popover} />
<Route path="progress" component={Progress} />
<Route path="refresh-indicator" component={RefreshIndicator} />
<Route path="select-fields" component={SelectFields} />
<Route path="select-field" component={SelectField} />
<Route path="sliders" component={Sliders} />
<Route path="switches" component={Switches} />
<Route path="snackbar" component={SnackbarPage} />
Expand Down
2 changes: 1 addition & 1 deletion docs/src/app/components/pages/components.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const menuItems = [
{route: '/components/popover', text: 'Popover'},
{route: '/components/progress', text: 'Progress'},
{route: '/components/refresh-indicator', text: 'Refresh Indicator'},
{route: '/components/select-fields', text: 'Select Fields'},
{route: '/components/select-field', text: 'Select Field'},
{route: '/components/sliders', text: 'Sliders'},
{route: '/components/switches', text: 'Switches'},
{route: '/components/snackbar', text: 'Snackbar'},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import SelectField from 'material-ui/lib/SelectField';
import MenuItem from 'material-ui/lib/menus/menu-item';

export default class SelectFieldCustomLabelExample extends React.Component {

constructor(props) {
super(props);
this.state = {value: 1};
}

handleChange = (e, index, value) => this.setState({value});

render() {
return (
<SelectField value={this.state.value} onChange={this.handleChange}>
<MenuItem value={1} label="5 am - 12 pm" primaryText="Morning"/>
<MenuItem value={2} label="12 pm - 5 pm" primaryText="Afternoon"/>
<MenuItem value={3} label="5 pm to 9 pm" primaryText="Evening"/>
<MenuItem value={4} label="9 pm to 4 am" primaryText="Night"/>
</SelectField>
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import SelectField from 'material-ui/lib/SelectField';
import MenuItem from 'material-ui/lib/menus/menu-item';

const SelectFieldDisabledExample = () => (
<SelectField value={1} disabled={true}>
<MenuItem value={1} primaryText="Never"/>
<MenuItem value={2} primaryText="Every Night"/>
</SelectField>
);

export default SelectFieldDisabledExample;
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import React from 'react';
import SelectField from 'material-ui/lib/SelectField';
import MenuItem from 'material-ui/lib/menus/menu-item';

export default class SelectFieldErrorExample extends React.Component {

constructor(props) {
super(props);
this.state = {value: null};
}

handleChange = (e, index, value) => this.setState({value});

render() {
const {value} = this.state;

const items = [
<MenuItem key={1} value={1} primaryText="Never"/>,
<MenuItem key={2} value={2} primaryText="Every Night"/>,
<MenuItem key={3} value={3} primaryText="Weeknights"/>,
<MenuItem key={4} value={4} primaryText="Weekends"/>,
<MenuItem key={5} value={5} primaryText="Weekly"/>,
];

const night = value === 2 || value === 3;

return (
<div>
<SelectField
value={value}
onChange={this.handleChange}
errorText={!night && "Should be Night"}
>
{items}
</SelectField>
<br/>
<SelectField
value={value}
onChange={this.handleChange}
errorText={night && "Should not be Night (Custom error style)"}
errorStyle={{color: 'orange'}}
>
{items}
</SelectField>
</div>
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import React from 'react';
import SelectField from 'material-ui/lib/SelectField';
import MenuItem from 'material-ui/lib/menus/menu-item';

export default class SelectFieldFloatingLabelExample extends React.Component {

constructor(props) {
super(props);
this.state = {value: null};
}

handleChange = (e, index, value) => this.setState({value});

render() {

const items = [
<MenuItem key={1} value={1} primaryText="Never"/>,
<MenuItem key={2} value={2} primaryText="Every Night"/>,
<MenuItem key={3} value={3} primaryText="Weeknights"/>,
<MenuItem key={4} value={4} primaryText="Weekends"/>,
<MenuItem key={5} value={5} primaryText="Weekly"/>,
];

return (
<div>
<SelectField
value={this.state.value}
onChange={this.handleChange}
floatingLabelText="Float Label Text"
>
{items}
</SelectField>
<br/>
<SelectField
value={this.state.value}
onChange={this.handleChange}
floatingLabelText="Custom Float Label Text"
floatingLabelStyle={{color: 'red'}}
>
{items}
</SelectField>
</div>
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import React from 'react';
import SelectField from 'material-ui/lib/SelectField';
import MenuItem from 'material-ui/lib/menus/menu-item';

export default class SelectFieldSimpleExample extends React.Component {

constructor(props) {
super(props);
this.state = {value: 2};
}

handleChange = (e, index, value) => this.setState({value});

render() {
return (
<SelectField value={this.state.value} onChange={this.handleChange}>
<MenuItem value={1} primaryText="Never"/>
<MenuItem value={2} primaryText="Every Night"/>
<MenuItem value={3} primaryText="Weeknights"/>
<MenuItem value={4} primaryText="Weekends"/>
<MenuItem value={5} primaryText="Weekly"/>
</SelectField>
);
}
}
41 changes: 41 additions & 0 deletions docs/src/app/components/pages/components/SelectField/Page.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import CodeExample from '../../../CodeExample';
import PropTypeDescription from '../../../PropTypeDescription';
import MarkdownElement from '../../../MarkdownElement';

import selectFieldReadmeText from './README';
import SelectFieldSimpleExample from './ExampleSimple';
import selectFieldSimpleExampleCode from '!raw!./ExampleSimple';
import SelectFieldDisabledExample from './ExampleDisabled';
import selectFieldDisabledExampleCode from '!raw!./ExampleDisabled';
import SelectFieldCustomLabelExample from './ExampleCustomLabel';
import selectFieldCustomLabelExampleCode from '!raw!./ExampleCustomLabel';
import SelectFieldFloatingLabelExample from './ExampleFloatingLabel';
import selectFieldFloatingLabelExampleCode from '!raw!./ExampleFloatingLabel';
import SelectFieldErrorExample from './ExampleError';
import selectFieldErrorExampleCode from '!raw!./ExampleError';
import selectFieldCode from '!raw!material-ui/lib/SelectField/SelectField';

const SelectFieldPage = () => (
<div>
<MarkdownElement text={selectFieldReadmeText} />
<CodeExample code={selectFieldSimpleExampleCode}>
<SelectFieldSimpleExample />
</CodeExample>
<CodeExample code={selectFieldDisabledExampleCode}>
<SelectFieldDisabledExample />
</CodeExample>
<CodeExample code={selectFieldCustomLabelExampleCode}>
<SelectFieldCustomLabelExample />
</CodeExample>
<CodeExample code={selectFieldFloatingLabelExampleCode}>
<SelectFieldFloatingLabelExample />
</CodeExample>
<CodeExample code={selectFieldErrorExampleCode}>
<SelectFieldErrorExample />
</CodeExample>
<PropTypeDescription code={selectFieldCode}/>
</div>
);

export default SelectFieldPage;
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Select Field

To learn more about `SelectField` please visit the specifications
[here](https://www.google.com/design/spec/components/menus.html#menus-usage).

### Examples
Loading

0 comments on commit 12e27ec

Please sign in to comment.