Skip to content

Commit

Permalink
[DOCS] Changed ranged component docs to functional components (elasti…
Browse files Browse the repository at this point in the history
  • Loading branch information
anishagg17 authored and Marvin9 committed Apr 2, 2020
1 parent d48f15d commit e9a673b
Show file tree
Hide file tree
Showing 10 changed files with 489 additions and 626 deletions.
48 changes: 19 additions & 29 deletions src-docs/src/views/range/dual_range.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,26 @@
import React, { Component } from 'react';
import React, { useState } from 'react';

import { EuiDualRange } from '../../../../src/components';

import makeId from '../../../../src/components/form/form_row/make_id';
import { htmlIdGenerator } from '../../../../src/services';

export default class extends Component {
constructor(props) {
super(props);
export default () => {
const [value, setValue] = useState(['', '']);

this.state = {
value: ['', ''],
};
}

onChange = value => {
this.setState({
value,
});
const onChange = value => {
setValue(value);
};

render() {
return (
<EuiDualRange
id={makeId()}
min={-100}
max={200}
step={10}
value={this.state.value}
onChange={this.onChange}
showLabels
aria-label="An example of EuiDualRange"
/>
);
}
}
return (
<EuiDualRange
id={htmlIdGenerator()()}
min={-100}
max={200}
step={10}
value={value}
onChange={onChange}
showLabels
aria-label="An example of EuiDualRange"
/>
);
};
78 changes: 33 additions & 45 deletions src-docs/src/views/range/input.js
Original file line number Diff line number Diff line change
@@ -1,54 +1,42 @@
import React, { Component, Fragment } from 'react';
import React, { useState, Fragment } from 'react';

import { EuiRange, EuiSpacer, EuiDualRange } from '../../../../src/components';

import makeId from '../../../../src/components/form/form_row/make_id';
import { htmlIdGenerator } from '../../../../src/services';

export default class extends Component {
constructor(props) {
super(props);
export default () => {
const [value, setValue] = useState('20');
const [dualValue, setDualValue] = useState([20, 100]);

this.state = {
value: '20',
dualValue: [20, 100],
};
}

onChange = e => {
this.setState({
value: e.target.value,
});
const onChange = e => {
setValue(e.target.value);
};

onDualChange = value => {
this.setState({
dualValue: value,
});
const onDualChange = value => {
setDualValue(value);
};

render() {
return (
<Fragment>
<EuiRange
id={makeId()}
value={this.state.value}
onChange={this.onChange}
showInput
aria-label="An example of EuiRange"
/>

<EuiSpacer size="xl" />

<EuiDualRange
id={makeId()}
value={this.state.dualValue}
onChange={this.onDualChange}
showInput
minInputProps={{ 'aria-label': 'Min value' }}
maxInputProps={{ 'aria-label': 'Max value' }}
aria-label="An example of EuiDualRange with inputs"
/>
</Fragment>
);
}
}
return (
<Fragment>
<EuiRange
id={htmlIdGenerator()()}
value={value}
onChange={onChange}
showInput
aria-label="An example of EuiRange"
/>

<EuiSpacer size="xl" />

<EuiDualRange
id={htmlIdGenerator()()}
value={dualValue}
onChange={onDualChange}
showInput
minInputProps={{ 'aria-label': 'Min value' }}
maxInputProps={{ 'aria-label': 'Max value' }}
aria-label="An example of EuiDualRange with inputs"
/>
</Fragment>
);
};
115 changes: 51 additions & 64 deletions src-docs/src/views/range/input_only.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,61 @@
import React, { Component, Fragment } from 'react';
import React, { useState, Fragment } from 'react';

import { EuiRange, EuiSpacer, EuiDualRange } from '../../../../src/components';

import { DisplayToggles } from '../form_controls/display_toggles';
import { htmlIdGenerator } from '../../../../src/services';

import makeId from '../../../../src/components/form/form_row/make_id';
export default () => {
const [value, setValue] = useState('20');
const [dualValue, setDualValue] = useState([20, 100]);

export default class extends Component {
constructor(props) {
super(props);

this.levels = [
{
min: 0,
max: 20,
color: 'danger',
},
{
min: 20,
max: 100,
color: 'success',
},
];

this.state = {
value: '20',
dualValue: [20, 100],
};
}

onChange = e => {
this.setState({
value: e.target.value,
});
const onChange = e => {
setValue(e.target.value);
};

onDualChange = value => {
this.setState({
dualValue: value,
});
const onDualChange = value => {
setDualValue(value);
};

render() {
return (
<Fragment>
<DisplayToggles canAppend canPrepend>
<EuiRange
id={makeId()}
value={this.state.value}
onChange={this.onChange}
showInput="inputWithPopover"
showLabels
aria-label="An example of EuiRange with showInput prop"
/>
</DisplayToggles>

<EuiSpacer size="xl" />

<DisplayToggles canAppend canPrepend canLoading={false}>
<EuiDualRange
id={makeId()}
value={this.state.dualValue}
onChange={this.onDualChange}
showInput="inputWithPopover"
showLabels
levels={this.levels}
aria-label="An example of EuiDualRange with showInput prop"
/>
</DisplayToggles>
</Fragment>
);
}
}
const levels = [
{
min: 0,
max: 20,
color: 'danger',
},
{
min: 20,
max: 100,
color: 'success',
},
];

return (
<Fragment>
<DisplayToggles canAppend canPrepend>
<EuiRange
id={htmlIdGenerator()()}
value={value}
onChange={onChange}
showInput="inputWithPopover"
showLabels
aria-label="An example of EuiRange with showInput prop"
/>
</DisplayToggles>

<EuiSpacer size="xl" />

<DisplayToggles canAppend canPrepend canLoading={false}>
<EuiDualRange
id={htmlIdGenerator()()}
value={dualValue}
onChange={onDualChange}
showInput="inputWithPopover"
showLabels
levels={levels}
aria-label="An example of EuiDualRange with showInput prop"
/>
</DisplayToggles>
</Fragment>
);
};
108 changes: 49 additions & 59 deletions src-docs/src/views/range/range.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,56 @@
import React, { Component, Fragment } from 'react';
import React, { useState, Fragment } from 'react';

import { EuiRange, EuiSpacer } from '../../../../src/components';

import makeId from '../../../../src/components/form/form_row/make_id';
import { htmlIdGenerator } from '../../../../src/services';

export default class extends Component {
constructor(props) {
super(props);
export default () => {
const [value, setValue] = useState('120');

this.state = {
value: '120',
};
}

onChange = e => {
this.setState({
value: e.target.value,
});
const onChange = e => {
setValue(e.target.value);
};

render() {
return (
<Fragment>
<EuiRange
id={makeId()}
min={100}
max={200}
step={0.05}
value={this.state.value}
onChange={this.onChange}
showLabels
aria-label="An example of EuiRange with showLabels prop"
/>

<EuiSpacer size="xl" />

<EuiRange
id={makeId()}
min={100}
max={200}
value={this.state.value}
onChange={this.onChange}
showLabels
showValue
aria-label="An example of EuiRange with showValue prop"
/>

<EuiSpacer size="xl" />

<EuiRange
id={makeId()}
min={100}
max={200}
value={this.state.value}
onChange={this.onChange}
showLabels
showRange
showValue
valuePrepend="100 - "
aria-label="An example of EuiRange with valuePrepend prop"
/>
</Fragment>
);
}
}
return (
<Fragment>
<EuiRange
id={htmlIdGenerator()()}
min={100}
max={200}
step={0.05}
value={value}
onChange={onChange}
showLabels
aria-label="An example of EuiRange with showLabels prop"
/>

<EuiSpacer size="xl" />

<EuiRange
id={htmlIdGenerator()()}
min={100}
max={200}
value={value}
onChange={onChange}
showLabels
showValue
aria-label="An example of EuiRange with showValue prop"
/>

<EuiSpacer size="xl" />

<EuiRange
id={htmlIdGenerator()()}
min={100}
max={200}
value={value}
onChange={onChange}
showLabels
showRange
showValue
valuePrepend="100 - "
aria-label="An example of EuiRange with valuePrepend prop"
/>
</Fragment>
);
};
Loading

0 comments on commit e9a673b

Please sign in to comment.