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

Convert a range of EuiRange* components to TypeScript #2124

Merged
merged 8 commits into from
Jul 16, 2019
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ exports[`EuiDualRange props ticks should render 1`] = `
class="euiRangeTick"
style="width:16.666666666666664%"
tabindex="-1"
title="0"
type="button"
value="0"
>
Expand All @@ -437,7 +436,6 @@ exports[`EuiDualRange props ticks should render 1`] = `
class="euiRangeTick"
style="width:16.666666666666664%"
tabindex="-1"
title="20"
type="button"
value="20"
>
Expand All @@ -447,7 +445,6 @@ exports[`EuiDualRange props ticks should render 1`] = `
class="euiRangeTick"
style="width:16.666666666666664%"
tabindex="-1"
title="40"
type="button"
value="40"
>
Expand All @@ -457,7 +454,6 @@ exports[`EuiDualRange props ticks should render 1`] = `
class="euiRangeTick"
style="width:16.666666666666664%"
tabindex="-1"
title="60"
type="button"
value="60"
>
Expand All @@ -467,7 +463,6 @@ exports[`EuiDualRange props ticks should render 1`] = `
class="euiRangeTick"
style="width:16.666666666666664%"
tabindex="-1"
title="80"
type="button"
value="80"
>
Expand All @@ -477,7 +472,6 @@ exports[`EuiDualRange props ticks should render 1`] = `
class="euiRangeTick"
style="width:16.666666666666664%"
tabindex="-1"
title="100"
type="button"
value="100"
>
Expand Down
6 changes: 0 additions & 6 deletions src/components/form/range/__snapshots__/range.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,6 @@ exports[`EuiRange props ticks should render 1`] = `
class="euiRangeTick"
style="width:16.666666666666664%"
tabindex="-1"
title="0"
type="button"
value="0"
>
Expand All @@ -331,7 +330,6 @@ exports[`EuiRange props ticks should render 1`] = `
class="euiRangeTick"
style="width:16.666666666666664%"
tabindex="-1"
title="20"
type="button"
value="20"
>
Expand All @@ -341,7 +339,6 @@ exports[`EuiRange props ticks should render 1`] = `
class="euiRangeTick"
style="width:16.666666666666664%"
tabindex="-1"
title="40"
type="button"
value="40"
>
Expand All @@ -351,7 +348,6 @@ exports[`EuiRange props ticks should render 1`] = `
class="euiRangeTick"
style="width:16.666666666666664%"
tabindex="-1"
title="60"
type="button"
value="60"
>
Expand All @@ -361,7 +357,6 @@ exports[`EuiRange props ticks should render 1`] = `
class="euiRangeTick"
style="width:16.666666666666664%"
tabindex="-1"
title="80"
type="button"
value="80"
>
Expand All @@ -371,7 +366,6 @@ exports[`EuiRange props ticks should render 1`] = `
class="euiRangeTick"
style="width:16.666666666666664%"
tabindex="-1"
title="100"
type="button"
value="100"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ exports[`EuiRangeTrack is rendered 1`] = `
class="euiRangeTick"
style="width:9.090909090909092%"
tabindex="-1"
title="0"
type="button"
value="0"
>
Expand All @@ -23,7 +22,6 @@ exports[`EuiRangeTrack is rendered 1`] = `
class="euiRangeTick"
style="width:9.090909090909092%"
tabindex="-1"
title="10"
type="button"
value="10"
>
Expand All @@ -33,7 +31,6 @@ exports[`EuiRangeTrack is rendered 1`] = `
class="euiRangeTick"
style="width:9.090909090909092%"
tabindex="-1"
title="20"
type="button"
value="20"
>
Expand All @@ -43,7 +40,6 @@ exports[`EuiRangeTrack is rendered 1`] = `
class="euiRangeTick"
style="width:9.090909090909092%"
tabindex="-1"
title="30"
type="button"
value="30"
>
Expand All @@ -53,7 +49,6 @@ exports[`EuiRangeTrack is rendered 1`] = `
class="euiRangeTick"
style="width:9.090909090909092%"
tabindex="-1"
title="40"
type="button"
value="40"
>
Expand All @@ -63,7 +58,6 @@ exports[`EuiRangeTrack is rendered 1`] = `
class="euiRangeTick"
style="width:9.090909090909092%"
tabindex="-1"
title="50"
type="button"
value="50"
>
Expand All @@ -73,7 +67,6 @@ exports[`EuiRangeTrack is rendered 1`] = `
class="euiRangeTick"
style="width:9.090909090909092%"
tabindex="-1"
title="60"
type="button"
value="60"
>
Expand All @@ -83,7 +76,6 @@ exports[`EuiRangeTrack is rendered 1`] = `
class="euiRangeTick"
style="width:9.090909090909092%"
tabindex="-1"
title="70"
type="button"
value="70"
>
Expand All @@ -93,7 +85,6 @@ exports[`EuiRangeTrack is rendered 1`] = `
class="euiRangeTick"
style="width:9.090909090909092%"
tabindex="-1"
title="80"
type="button"
value="80"
>
Expand All @@ -103,7 +94,6 @@ exports[`EuiRangeTrack is rendered 1`] = `
class="euiRangeTick"
style="width:9.090909090909092%"
tabindex="-1"
title="90"
type="button"
value="90"
>
Expand All @@ -113,7 +103,6 @@ exports[`EuiRangeTrack is rendered 1`] = `
class="euiRangeTick"
style="width:9.090909090909092%"
tabindex="-1"
title="100"
type="button"
value="100"
>
Expand Down
2 changes: 1 addition & 1 deletion src/components/form/range/dual_range.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ export class EuiDualRange extends Component {
showTicks={showTicks}
hasFocus={this.state.hasFocus}
aria-hidden={true}
tabIndex={'-1'}
tabIndex={-1}
showRange={showRange}
{...rest}
/>
Expand Down
22 changes: 21 additions & 1 deletion src/components/form/range/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,29 @@ import { CommonProps, Omit } from '../../common';

import { ReactNode, FunctionComponent, InputHTMLAttributes } from 'react';

import { EuiRangeHighlightProps } from './range_highlight';
import { EuiRangeLabelProps } from './range_label';
import { EuiRangeLevelsProps, EuiRangeLevel } from './range_levels';
import { EuiRangeSliderProps } from './range_slider';
import { EuiRangeThumbProps } from './range_thumb';
import { EuiRangeTicksProps } from './range_ticks';
import { EuiRangeTooltipProps } from './range_tooltip';
import { EuiRangeTrackProps } from './range_track';
import { EuiRangeWrapperProps } from './range_wrapper';

declare module '@elastic/eui' {
export type EuiRangeLevelColor = 'primary' | 'success' | 'warning' | 'danger';

export const EuiRangeHighlight: FunctionComponent<EuiRangeHighlightProps>;
export const EuiRangeLabel: FunctionComponent<EuiRangeLabelProps>;
export const EuiRangeLevels: FunctionComponent<EuiRangeLevelsProps>;
export const EuiRangeSlider: FunctionComponent<EuiRangeSliderProps>;
export const EuiRangeThumb: FunctionComponent<EuiRangeThumbProps>;
export const EuiRangeTicks: FunctionComponent<EuiRangeTicksProps>;
export const EuiRangeTooltip: FunctionComponent<EuiRangeTooltipProps>;
export const EuiRangeTrack: FunctionComponent<EuiRangeTrackProps>;
export const EuiRangeWrapper: FunctionComponent<EuiRangeWrapperProps>;

/**
* single range type def
*
Expand All @@ -15,7 +35,7 @@ declare module '@elastic/eui' {
compressed?: boolean;
fullWidth?: boolean;
id?: string;
levels?: Array<{ min?: number; max?: number; color?: EuiRangeLevelColor }>;
levels?: EuiRangeLevel[];
// `min` and `max` are optional in HTML but required for our component,
// so we override them.
max: number;
Expand Down
2 changes: 1 addition & 1 deletion src/components/form/range/range.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export class EuiRange extends Component {
style={style}
showTicks={showTicks}
showRange={showRange}
tabIndex={showInput ? '-1' : tabIndex || null}
tabIndex={showInput ? -1 : tabIndex || null}
{...rest}
/>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import React from 'react';
import PropTypes from 'prop-types';
import React, { FunctionComponent } from 'react';
import classNames from 'classnames';

export const EuiRangeHighlight = ({
export interface EuiRangeHighlightProps {
hasFocus?: boolean;
showTicks?: boolean;
lowerValue: number;
upperValue: number;
max: number;
min: number;
}

export const EuiRangeHighlight: FunctionComponent<EuiRangeHighlightProps> = ({
hasFocus,
showTicks,
lowerValue,
Expand Down Expand Up @@ -33,12 +41,3 @@ export const EuiRangeHighlight = ({
</div>
);
};

EuiRangeHighlight.propTypes = {
hasFocus: PropTypes.bool,
showTicks: PropTypes.bool,
lowerValue: PropTypes.number.isRequired,
upperValue: PropTypes.number.isRequired,
max: PropTypes.number.isRequired,
min: PropTypes.number.isRequired,
};
17 changes: 0 additions & 17 deletions src/components/form/range/range_label.js

This file was deleted.

19 changes: 19 additions & 0 deletions src/components/form/range/range_label.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React, { FunctionComponent } from 'react';
import classNames from 'classnames';

export interface EuiRangeLabelProps {
children: string | number;
disabled?: boolean;
side?: 'min' | 'max';
}

export const EuiRangeLabel: FunctionComponent<EuiRangeLabelProps> = ({
children,
disabled,
side = 'max',
}) => {
const classes = classNames('euiRangeLabel', `euiRangeLabel--${side}`, {
'euiRangeLabel--isDisabled': disabled,
});
return <label className={classes}>{children}</label>;
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,35 @@
import React from 'react';
import PropTypes from 'prop-types';
import React, { FunctionComponent } from 'react';
import classNames from 'classnames';

export const LEVEL_COLORS = ['primary', 'success', 'warning', 'danger'];
export type EuiRangeLevelColor = 'primary' | 'success' | 'warning' | 'danger';

export const EuiRangeLevels = ({ levels, max, min, showTicks }) => {
const validateLevelIsInRange = level => {
export const LEVEL_COLORS: EuiRangeLevelColor[] = [
'primary',
'success',
'warning',
'danger',
];

export interface EuiRangeLevel {
min: number;
max: number;
color: EuiRangeLevelColor;
}

export interface EuiRangeLevelsProps {
levels?: EuiRangeLevel[];
max: number;
min: number;
showTicks?: boolean;
}

export const EuiRangeLevels: FunctionComponent<EuiRangeLevelsProps> = ({
levels = [],
max,
min,
showTicks,
}) => {
const validateLevelIsInRange = (level: EuiRangeLevel) => {
if (level.min < min) {
throw new Error(
`The level min of ${level.min} is lower than the min value of ${min}.`
Expand Down Expand Up @@ -40,16 +64,3 @@ export const EuiRangeLevels = ({ levels, max, min, showTicks }) => {
</div>
);
};

EuiRangeLevels.propTypes = {
levels: PropTypes.arrayOf(
PropTypes.shape({
min: PropTypes.number.isRequired,
max: PropTypes.number.isRequired,
color: PropTypes.oneOf(LEVEL_COLORS).isRequired,
})
),
max: PropTypes.number.isRequired,
min: PropTypes.number.isRequired,
showTicks: PropTypes.bool,
};
Loading