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

[Feature Branch] Add support for EuiRange in a dropdown with input #2179

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
66b3378
[Feature branch] Updated form control border color (#2114)
cchaos Jul 12, 2019
eb5297a
[Feature branch] Added EuiFormControlLayoutDelimited component (#2117)
cchaos Jul 23, 2019
89c9966
[Feature branch] Compressed EuiSuperSelect dropdown (#2155)
cchaos Jul 25, 2019
87c3df7
[Feature Branch] Update compressed form control styles (#2174)
cchaos Jul 30, 2019
f917029
[Feature branch] Compressed form rows (#2181)
cchaos Aug 13, 2019
8d3ae71
Fix snap
Aug 29, 2019
f5d9981
Compressed EuiRange step 1
Jul 10, 2019
dd80c95
Compressed EuiRange step 2
Jul 10, 2019
d1dc24b
Compressed EuiRange step 2 (cont)
Jul 11, 2019
a791585
Compressed EuiRange step 3
Jul 11, 2019
732ffc6
Fix for delimited
Jul 29, 2019
db0e016
Fix full-width delimited
Aug 14, 2019
b29fe1d
Added `controlOnly` prop to EuiFieldNumber
Aug 14, 2019
e8a6d82
Finalize styles of input only ranges
Aug 14, 2019
7e73d80
Some cleanup
Aug 19, 2019
8ded06a
Use tooltip background variable
Aug 29, 2019
b9937a5
Open popover on focus
Aug 29, 2019
cff7eac
Merge branch 'feature/compressed-editor-controls' into into-feature/r…
cchaos Sep 4, 2019
536b9b9
focus direction
thompsongl Sep 4, 2019
d1bf98a
Merge pull request #25 from thompsongl/into-feature/range-dropdowns
cchaos Sep 4, 2019
ac95317
dual range respond to resize events when in showInputOnly mode
thompsongl Sep 5, 2019
1b58cdf
clean up
thompsongl Sep 5, 2019
9a6d9de
Merge pull request #26 from thompsongl/into-feature/range-dropdowns
cchaos Sep 5, 2019
e132f7e
PR Feedback
Sep 6, 2019
019e139
Merge branch 'into-feature/range-dropdowns' of https://github.com/cch…
Sep 6, 2019
161ae26
Merge branch 'feature/compressed-editor-controls' into into-feature/r…
cchaos Sep 6, 2019
2fd14f4
use callback instead of resizeObserver
thompsongl Sep 5, 2019
657e3d8
ie11 focus fix
thompsongl Sep 9, 2019
418e4e1
use focusout instead of blur
thompsongl Sep 9, 2019
5d169d0
Merge pull request #27 from thompsongl/into-feature/range-dropdowns
cchaos Sep 9, 2019
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
90 changes: 90 additions & 0 deletions src-docs/src/views/range/input_only.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import React, { Component, Fragment } from 'react';

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

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

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,
});
};

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

render() {
return (
<Fragment>
<EuiRange
id={makeId()}
value={this.state.value}
onChange={this.onChange}
showInput="inputWithPopover"
showLabels
/>

<EuiSpacer size="xl" />

<EuiDualRange
id={makeId()}
value={this.state.dualValue}
onChange={this.onDualChange}
showInput="inputWithPopover"
showLabels
levels={this.levels}
/>

<EuiSpacer size="xl" />

<EuiRange
id={makeId()}
value={this.state.value}
onChange={this.onChange}
compressed
showInput="inputWithPopover"
showLabels
/>

<EuiSpacer size="xl" />

<EuiDualRange
id={makeId()}
value={this.state.dualValue}
onChange={this.onDualChange}
compressed
showInput="inputWithPopover"
showLabels
levels={this.levels}
readOnly
/>
</Fragment>
);
}
}
93 changes: 66 additions & 27 deletions src-docs/src/views/range/range_example.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ import StatesExample from './states';
const statesSource = require('!!raw-loader!./states');
const statesHtml = renderToHtml(StatesExample);

import InputOnlyExample from './input_only';
const inputOnlySource = require('!!raw-loader!./input_only');
const inputOnlyHtml = renderToHtml(InputOnlyExample);

export const RangeControlExample = {
title: 'Range sliders',
intro: (
Expand Down Expand Up @@ -112,26 +116,25 @@ export const RangeControlExample = {
EuiRange,
},
demo: <RangeExample />,
snippet: `<EuiRange
snippet: [
`<EuiRange
min={100}
max={200}
step={0.05}
value={this.state.value}
onChange={this.onChange}
showLabels
/>

// Show tooltip
/>`,
`// Show tooltip
<EuiRange
min={100}
max={200}
value={this.state.value}
onChange={this.onChange}
showLabels
showValue
/>

// Show thickened range and prepend a string to the tooltip
/>`,
`// Show thickened range and prepend a string to the tooltip
<EuiRange
min={100}
max={200}
Expand All @@ -142,6 +145,7 @@ export const RangeControlExample = {
showValue
valuePrepend="100 - "
/>`,
],
},
{
title: 'Dual range',
Expand Down Expand Up @@ -224,9 +228,7 @@ export const RangeControlExample = {
],
demo: <InputExample />,
props: { EuiRangeInput },
snippet: `<EuiRange showInput />

<EuiDualRange showInput />`,
snippet: ['<EuiRange showInput />', '<EuiDualRange showInput />'],
},
{
title: 'Tick marks',
Expand Down Expand Up @@ -265,17 +267,17 @@ export const RangeControlExample = {
],
demo: <TicksExample />,
props: { EuiRangeTicks },
snippet: `<EuiRange step={10} showTicks />

<EuiRange showTicks tickInterval={20} />

<EuiDualRange
snippet: [
'<EuiRange step={10} showTicks />',
'<EuiRange showTicks tickInterval={20} />',
`<EuiDualRange
showTicks
ticks={[
{ label: '20kb', value: 20 },
{ label: '100kb', value: 100 }
]}
/>`,
],
},
{
title: 'Levels',
Expand Down Expand Up @@ -305,30 +307,68 @@ export const RangeControlExample = {
],
demo: <LevelsExample />,
props: { EuiRangeLevels },
snippet: `<EuiRange
snippet: [
`<EuiRange
levels={[
{min: 0, max: 20, color: 'danger'},
{min: 20, max: 100, color: 'success'}
]}
aria-describedBy={replaceWithID}
/>

<EuiDualRange
/>`,
`<EuiDualRange
levels={[
{min: 0, max: 20, color: 'danger'},
{min: 20, max: 100, color: 'success'}
]}
aria-describedBy={replaceWithID}
/>`,
],
},
{
title: 'Inputs with range in a dropdown',
text: (
<Fragment>
<p>
Passing <EuiCode>showInput=&quot;inputWithPopover&quot;</EuiCode>{' '}
instead of a boolean will only display the inputs until the input is
interacted with in which case a dropdown will appear displaying the
actual slider.
</p>
</Fragment>
),
source: [
{
type: GuideSectionTypes.JS,
code: inputOnlySource,
},
{
type: GuideSectionTypes.HTML,
code: inputOnlyHtml,
},
],
demo: <InputOnlyExample />,
snippet: [
`<EuiRange
id=""
value={}
onChange={() => {}}
showInput="inputWithPopover"
/>`,
`<EuiDualRange
id=""
value={}
onChange={() => {}}
showInput="inputWithPopover"
/>`,
],
},
{
title: 'Kitchen sink',
text: (
<Fragment>
<p>
Other alterations you can add to the range are{' '}
<EuiCode>compressed</EuiCode>, <EuiCode>fullWidth</EuiCode>, and{' '}
<EuiCode>disabled</EuiCode>.
<EuiCode>fullWidth</EuiCode>, and <EuiCode>disabled</EuiCode>.
</p>
</Fragment>
),
Expand All @@ -343,11 +383,11 @@ export const RangeControlExample = {
},
],
demo: <StatesExample />,
snippet: `<EuiRange
snippet: [
`<EuiRange
id=""
value={}
onChange={() => {}}
compressed
fullWidth
disabled
showTicks
Expand All @@ -358,13 +398,11 @@ export const RangeControlExample = {
tickInterval={}
levels={[]}
aria-describedBy={replaceWithID}
/>

<EuiDualRange
/>`,
`<EuiDualRange
id=""
value={}
onChange={() => {}}
compressed
fullWidth
disabled
showLabels
Expand All @@ -374,6 +412,7 @@ export const RangeControlExample = {
levels={[]}
aria-describedBy={replaceWithID}
/>`,
],
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ exports[`EuiFieldNumber is rendered 1`] = `
</eui-form-control-layout>
`;

exports[`EuiFieldNumber props controlOnly is rendered 1`] = `
<eui-validatable-control>
<input
class="euiFieldNumber"
type="number"
/>
</eui-validatable-control>
`;

exports[`EuiFieldNumber props fullWidth is rendered 1`] = `
<eui-form-control-layout
compressed="false"
Expand Down
44 changes: 29 additions & 15 deletions src/components/form/field_number/field_number.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const EuiFieldNumber = ({
append,
inputRef,
readOnly,
controlOnly,
...rest
}) => {
const classes = classNames('euiFieldNumber', className, {
Expand All @@ -33,6 +34,28 @@ export const EuiFieldNumber = ({
'euiFieldNumber-isLoading': isLoading,
});

const control = (
<EuiValidatableControl isInvalid={isInvalid}>
<input
type="number"
id={id}
min={min}
max={max}
name={name}
value={value}
placeholder={placeholder}
readOnly={readOnly}
className={classes}
ref={inputRef}
{...rest}
/>
</EuiValidatableControl>
);

if (controlOnly) {
return control;
}

return (
<EuiFormControlLayout
icon={icon}
Expand All @@ -43,21 +66,7 @@ export const EuiFieldNumber = ({
prepend={prepend}
append={append}
inputId={id}>
<EuiValidatableControl isInvalid={isInvalid}>
<input
type="number"
id={id}
min={min}
max={max}
name={name}
value={value}
placeholder={placeholder}
readOnly={readOnly}
className={classes}
ref={inputRef}
{...rest}
/>
</EuiValidatableControl>
{control}
</EuiFormControlLayout>
);
};
Expand Down Expand Up @@ -114,6 +123,11 @@ EuiFieldNumber.propTypes = {
PropTypes.node,
PropTypes.arrayOf(PropTypes.node),
]),
/**
* Completely removes form control layout wrapper and ignores
* icon, prepend, and append. Best used inside EuiFormControlLayoutDelimited.
*/
controlOnly: PropTypes.bool,
};

EuiFieldNumber.defaultProps = {
Expand Down
6 changes: 6 additions & 0 deletions src/components/form/field_number/field_number.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ describe('EuiFieldNumber', () => {
expect(component).toMatchSnapshot();
});

test('controlOnly is rendered', () => {
const component = render(<EuiFieldNumber controlOnly />);

expect(component).toMatchSnapshot();
});

describe('value', () => {
test('value is number', () => {
const component = render(
Expand Down
Loading