Skip to content

Commit

Permalink
Blank stepped range
Browse files Browse the repository at this point in the history
  • Loading branch information
cchaos committed Jun 19, 2018
1 parent 16189ca commit 2cfbb8a
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 8 deletions.
18 changes: 18 additions & 0 deletions src-docs/src/views/form_controls/form_controls_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
EuiLink,
EuiRadio,
EuiRange,
EuiRangeStepped,
EuiSelect,
EuiSwitch,
EuiTextArea,
Expand Down Expand Up @@ -73,6 +74,10 @@ import RangeExample from './range';
const rangeSource = require('!!raw-loader!./range');
const rangeHtml = renderToHtml(RangeExample);

import RangeStepped from './range_stepped';
const rangeSteppedSource = require('!!raw-loader!./range_stepped');
const rangeSteppedHtml = renderToHtml(RangeStepped);

import Switch from './switch';
const switchSource = require('!!raw-loader!./switch');
const switchHtml = renderToHtml(Switch);
Expand Down Expand Up @@ -266,6 +271,19 @@ export const FormControlsExample = {
EuiRange,
},
demo: <RangeExample />,
}, {
title: 'Stepped range',
source: [{
type: GuideSectionTypes.JS,
code: rangeSteppedSource,
}, {
type: GuideSectionTypes.HTML,
code: rangeSteppedHtml,
}],
props: {
EuiRangeStepped,
},
demo: <RangeStepped />,
}, {
title: 'Switch',
source: [{
Expand Down
54 changes: 54 additions & 0 deletions src-docs/src/views/form_controls/range_stepped.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React, { Component, Fragment } from 'react';

import {
EuiRangeStepped,
} from '../../../../src/components';

import makeId from '../../../../src/components/form/form_row/make_id';


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

const idPrefix = makeId();

this.options = [{
id: `${idPrefix}0`,
value: 0,
label: 'Option one',
}, {
id: `${idPrefix}1`,
value: 1,
label: 'Option two is checked by default',
}, {
id: `${idPrefix}2`,
value: 2,
label: 'Option three',
}];

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

onChange = e => {
this.setState({
value: e.currentTarget.value,
});
};

render() {
return (
<Fragment>
<EuiRangeStepped
options={this.options}
onChange={this.onChange}
value={this.state.value}
/>

{this.state.value}
</Fragment>
);
}
}
5 changes: 4 additions & 1 deletion src/components/form/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export {
EuiRadio,
EuiRadioGroup,
} from './radio';
export { EuiRange } from './range';
export {
EuiRange,
EuiRangeStepped,
} from './range';
export { EuiSelect } from './select';
export { EuiSwitch } from './switch';
export { EuiTextArea } from './text_area';
Expand Down
17 changes: 13 additions & 4 deletions src/components/form/range/__snapshots__/range.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports[`EuiRange is rendered 1`] = `
min="1"
name="name"
type="range"
value="value"
value="8"
/>
</div>
`;
Expand All @@ -36,19 +36,28 @@ exports[`EuiRange props extra input should render 1`] = `
class="euiRange__wrapper"
>
<input
class="euiRange"
max="100"
aria-label="aria-label"
class="euiRange testClass1 testClass2"
data-test-subj="test subject string"
id="id"
max="10"
min="1"
name="name"
type="range"
value="8"
/>
<div
class="euiFormControlLayout"
>
<input
aria-label="aria-label"
class="euiFieldNumber euiRange__extraInput"
max="100"
data-test-subj="test subject string"
max="10"
min="1"
name="name"
type="number"
value="8"
/>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`EuiRangeStepped is rendered 1`] = `
<div
aria-label="aria-label"
class="testClass1 testClass2"
data-test-subj="test subject string"
/>
`;
2 changes: 2 additions & 0 deletions src/components/form/range/_index.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import 'variables';
@import 'mixins';

@import 'range';
@import 'range_stepped';
3 changes: 3 additions & 0 deletions src/components/form/range/_range_stepped.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.euiRangeStepped {

}
1 change: 1 addition & 0 deletions src/components/form/range/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export { EuiRange } from './range';
export { EuiRangeStepped } from './range_stepped';
2 changes: 1 addition & 1 deletion src/components/form/range/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const EuiRange = ({
className="euiRange__extraInput"
min={min}
max={max}
value={value}
value={Number(value)}
disabled={disabled}
compressed={compressed}
{...rest}
Expand Down
13 changes: 11 additions & 2 deletions src/components/form/range/range.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('EuiRange', () => {
id="id"
min={1}
max={10}
value="value"
value="8"
onChange={() => {}}
{...requiredProps}
/>
Expand Down Expand Up @@ -52,7 +52,16 @@ describe('EuiRange', () => {

test('extra input should render', () => {
const component = render(
<EuiRange showInput/>
<EuiRange
name="name"
id="id"
min={1}
max={10}
value="8"
onChange={() => {}}
showInput
{...requiredProps}
/>
);

expect(component)
Expand Down
19 changes: 19 additions & 0 deletions src/components/form/range/range_stepped.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import PropTypes from 'prop-types';

export const EuiRangeStepped = ({
className,
children,
...rest
}) => (
<div className={className} {...rest}>
{children}
</div>
);

EuiRangeStepped.propTypes = {
children: PropTypes.node,
};

EuiRangeStepped.defaultProps = {
};
16 changes: 16 additions & 0 deletions src/components/form/range/range_stepped.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react';
import { render } from 'enzyme';
import { requiredProps } from '../../../test';

import { EuiRangeStepped } from './range_stepped';

describe('EuiRangeStepped', () => {
test('is rendered', () => {
const component = render(
<EuiRangeStepped {...requiredProps} />
);

expect(component)
.toMatchSnapshot();
});
});
1 change: 1 addition & 0 deletions src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export {
EuiRadio,
EuiRadioGroup,
EuiRange,
EuiRangeStepped,
EuiSelect,
EuiSwitch,
EuiTextArea,
Expand Down

0 comments on commit 2cfbb8a

Please sign in to comment.