slate/pages/system/dropdowns.js

193 lines
4.7 KiB
JavaScript
Raw Normal View History

import * as React from "react";
import * as System from "~/components/system";
import SystemPage from "~/components/system/SystemPage";
import ViewSourceLink from "~/components/system/ViewSourceLink";
const SELECT_MENU_OPTIONS = [
{ value: "1", name: "Capricorn" },
{ value: "2", name: "Aquarius" },
{ value: "3", name: "Pisces" },
{ value: "4", name: "Aries" },
{ value: "5", name: "Taurus" },
{ value: "6", name: "Gemini" },
{ value: "7", name: "Cancer" },
{ value: "8", name: "Leo" },
{ value: "9", name: "Virgo" },
{ value: "10", name: "Libra" },
{ value: "11", name: "Scorpio" },
{ value: "12", name: "Sagittarus" },
];
export default class SystemPageDropdowns extends React.Component {
state = {
2020-07-05 08:20:57 +03:00
exampleOne: "1",
exampleTwo: "3",
exampleThree: "United States of America",
};
_handleChange = (e) => {
this.setState({ [e.target.name]: e.target.value });
};
render() {
return (
<SystemPage
2020-07-05 08:20:57 +03:00
title="SDS: Dropdowns"
description="..."
url="https://fps.onrender.com/system/dropdowns"
>
<System.H1>
Dropdowns <ViewSourceLink file="system/dropdowns.js" />
</System.H1>
<br />
<br />
<System.P>
2020-07-05 08:20:57 +03:00
The Dropdown component is used to present the user a list of values
where they can select a single option.
</System.P>
<br />
<br />
<br />
<System.H2>Imports</System.H2>
<hr />
<br />
<System.P>
Import React and the SelectMenu and/or the SelectMenuFull Components.
</System.P>
<br />
<br />
<System.CodeBlock>
2020-07-05 08:20:57 +03:00
{`import * as React from 'react';
import { SelectMenu, SelectCountryMenu } from 'slate-react-system';`}
</System.CodeBlock>
<br />
<br />
2020-06-24 05:02:55 +03:00
<System.H2>Usage</System.H2>
<hr />
<br />
<System.P>Define the dropdown menu options.</System.P>
<br />
<System.CodeBlock>
{`const SELECT_MENU_OPTIONS = [
2020-06-24 05:02:55 +03:00
{ value: '1', name: 'Capricorn' },
{ value: '2', name: 'Aquarius' },
{ value: '3', name: 'Pisces' },
{ value: '4', name: 'Aries' },
{ value: '5', name: 'Taurus' },
{ value: '6', name: 'Gemini' },
{ value: '7', name: 'Cancer' },
{ value: '8', name: 'Leo' },
{ value: '9', name: 'Virgo' },
{ value: '10', name: 'Libra' },
{ value: '11', name: 'Scorpio' },
{ value: '12', name: 'Sagittarus' },
];`}
2020-06-24 05:02:55 +03:00
</System.CodeBlock>
<br />
<System.P>Declare the Dropdown component.</System.P>
<br />
<System.CodeBlock>
{`class ExampleOne extends React.Component {
state = { exampleOne: '1' }
_handleChange = e => this.setState(
{ [e.target.name]: e.target.value }
);
render() {
return(
<SelectMenu
name="exampleOne"
value={this.state.exampleOne}
category="horoscope"
onChange={this._handleChange}
2020-07-05 08:20:57 +03:00
options={SELECT_MENU_OPTIONS}
/>
)
}
}
2020-06-24 05:02:55 +03:00
class ExampleTwo extends React.Component {
state = { exampleTwo: '3' }
_handleChange = e => this.setState(
{ [e.target.name]: e.target.value }
);
render() {
return(
2020-07-05 08:20:57 +03:00
<SelectMenu
label="Pick a horoscope"
name="exampleTwo"
2020-07-05 08:20:57 +03:00
full
value={this.state.exampleTwo}
category="horoscope"
onChange={this._handleChange}
2020-07-05 08:20:57 +03:00
options={SELECT_MENU_OPTIONS}
/>
)
}
2020-07-05 08:20:57 +03:00
}
2020-07-05 08:20:57 +03:00
class ExampleThree extends React.Component {
state = { exampleThree: "United States of America" }
2020-07-05 08:20:57 +03:00
_handleChange = e => this.setState(
{ [e.target.name]: e.target.value }
);
render() {
return(
<SelectCountryMenu
label="Pick your country"
name="countryMenu"
full
value={this.state.countryMenu}
category="country"
onChange={this._handleChange}
/>
)
}
}`}
2020-06-24 05:02:55 +03:00
</System.CodeBlock>
<br />
<br />
<System.H2>Output</System.H2>
<hr />
<br />
<System.SelectMenu
name="exampleOne"
value={this.state.exampleOne}
category="horoscope"
onChange={this._handleChange}
options={SELECT_MENU_OPTIONS}
/>
<br />
<br />
<System.SelectMenu
label="Pick a horoscope"
name="exampleTwo"
full
2020-07-05 08:20:57 +03:00
value={this.state.exampleTwo}
category="horoscope"
onChange={this._handleChange}
options={SELECT_MENU_OPTIONS}
/>
<br />
<br />
<System.SelectCountryMenu
label="Pick your country"
name="exampleThree"
full
value={this.state.exampleThree}
category="country"
onChange={this._handleChange}
/>
</SystemPage>
);
}
}