forked from grafana/grafana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
yaml --- r: 170359 b: refs/heads/chore/arve-oauth-orgs c: 85a0479 h: refs/heads/master i: 170357: d8f1fff 170355: d85872f 170351: 5b1d635
- Loading branch information
1 parent
68251fe
commit c46bb81
Showing
20 changed files
with
424 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
branches/chore/arve-oauth-orgs/packages/grafana-ui/src/components/OptionsUI/slider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React, { useCallback } from 'react'; | ||
import { FieldConfigEditorProps, SliderFieldConfigSettings } from '@grafana/data'; | ||
import { Slider } from '../Slider/Slider'; | ||
|
||
export const SliderValueEditor: React.FC<FieldConfigEditorProps<number, SliderFieldConfigSettings>> = ({ | ||
value, | ||
onChange, | ||
item, | ||
}) => { | ||
const { settings } = item; | ||
const onValueAfterChange = useCallback( | ||
(value?: number) => { | ||
onChange(value); | ||
}, | ||
[onChange] | ||
); | ||
const initialValue = typeof value === 'number' ? value : typeof value === 'string' ? +value : 0; | ||
return ( | ||
<Slider | ||
value={initialValue} | ||
min={settings?.min || 0} | ||
max={settings?.max || 100} | ||
step={settings?.step} | ||
onAfterChange={onValueAfterChange} | ||
/> | ||
); | ||
}; |
12 changes: 12 additions & 0 deletions
12
...chore/arve-oauth-orgs/packages/grafana-ui/src/components/Slider/RangeSlider.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { Meta, Props } from '@storybook/addon-docs/blocks'; | ||
import { RangeSliderProps } from './types'; | ||
|
||
<Meta title="MDX|RangeSlider" /> | ||
|
||
# Range-slider | ||
|
||
The `Range-slider` component is an input element where users can manipulate two values on a one-dimensional axis. | ||
|
||
`Range-slider` can be implemented in horizontal or vertical orientation. You can set the default starting values for the slider with the `value` prop. | ||
|
||
<Props of={RangeSliderProps} /> |
30 changes: 30 additions & 0 deletions
30
...hes/chore/arve-oauth-orgs/packages/grafana-ui/src/components/Slider/RangeSlider.story.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import { RangeSlider } from '@grafana/ui'; | ||
import { select, number, boolean } from '@storybook/addon-knobs'; | ||
|
||
export default { | ||
title: 'Forms/Slider/Range', | ||
component: RangeSlider, | ||
}; | ||
|
||
const getKnobs = () => { | ||
return { | ||
min: number('min', 0), | ||
max: number('max', 100), | ||
step: boolean('enable step', false), | ||
orientation: select('orientation', ['horizontal', 'vertical'], 'horizontal'), | ||
reverse: boolean('reverse', false), | ||
}; | ||
}; | ||
|
||
const SliderWrapper = () => { | ||
const { min, max, orientation, reverse, step } = getKnobs(); | ||
const stepValue = step ? 10 : undefined; | ||
return ( | ||
<div style={{ width: '200px', height: '200px' }}> | ||
<RangeSlider min={min} max={max} step={stepValue} orientation={orientation} value={[10, 20]} reverse={reverse} /> | ||
</div> | ||
); | ||
}; | ||
|
||
export const basic = () => <SliderWrapper />; |
17 changes: 17 additions & 0 deletions
17
...ches/chore/arve-oauth-orgs/packages/grafana-ui/src/components/Slider/RangeSlider.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react'; | ||
import { RangeSlider } from './RangeSlider'; | ||
import { RangeSliderProps } from './types'; | ||
import { render } from '@testing-library/react'; | ||
|
||
const sliderProps: RangeSliderProps = { | ||
min: 10, | ||
max: 20, | ||
}; | ||
|
||
describe('RangeSlider', () => { | ||
it('renders without error', () => { | ||
expect(() => { | ||
render(<RangeSlider {...sliderProps} />); | ||
}); | ||
}); | ||
}); |
53 changes: 53 additions & 0 deletions
53
branches/chore/arve-oauth-orgs/packages/grafana-ui/src/components/Slider/RangeSlider.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import React, { FunctionComponent } from 'react'; | ||
import { Range as RangeComponent, createSliderWithTooltip } from 'rc-slider'; | ||
import { cx } from 'emotion'; | ||
import { Global } from '@emotion/core'; | ||
import { useTheme } from '../../themes/ThemeContext'; | ||
import { getStyles } from './styles'; | ||
import { RangeSliderProps } from './types'; | ||
|
||
/** | ||
* @public | ||
* | ||
* RichHistoryQueriesTab uses this Range Component | ||
*/ | ||
export const RangeSlider: FunctionComponent<RangeSliderProps> = ({ | ||
min, | ||
max, | ||
onChange, | ||
onAfterChange, | ||
orientation = 'horizontal', | ||
reverse, | ||
step, | ||
formatTooltipResult, | ||
value, | ||
tooltipAlwaysVisible = true, | ||
}) => { | ||
const isHorizontal = orientation === 'horizontal'; | ||
const theme = useTheme(); | ||
const styles = getStyles(theme, isHorizontal); | ||
const RangeWithTooltip = createSliderWithTooltip(RangeComponent); | ||
return ( | ||
<div className={cx(styles.container, styles.slider)}> | ||
{/** Slider tooltip's parent component is body and therefore we need Global component to do css overrides for it. */} | ||
<Global styles={styles.tooltip} /> | ||
<RangeWithTooltip | ||
tipProps={{ | ||
visible: tooltipAlwaysVisible, | ||
placement: isHorizontal ? 'top' : 'right', | ||
}} | ||
min={min} | ||
max={max} | ||
step={step} | ||
defaultValue={value} | ||
tipFormatter={(value: number) => (formatTooltipResult ? formatTooltipResult(value) : value)} | ||
onChange={onChange} | ||
onAfterChange={onAfterChange} | ||
vertical={!isHorizontal} | ||
reverse={reverse} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
RangeSlider.displayName = 'Range'; |
8 changes: 4 additions & 4 deletions
8
...ches/chore/arve-oauth-orgs/packages/grafana-ui/src/components/Slider/Slider.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { Meta, Props } from '@storybook/addon-docs/blocks'; | ||
import { Slider } from './Slider'; | ||
import { SliderProps } from './types'; | ||
|
||
<Meta title="MDX|Slider" /> | ||
|
||
# Slider | ||
|
||
The `Slider` component is an input element where users can manipulate one or two values on a one-dimensional axis. | ||
The `Slider` component is an input element where users can manipulate one value on a one-dimensional axis. | ||
|
||
`Slider` can be implemented in horizontal or vertical orientation. You can set the default starting value(s) for the slider with the `value` prop. | ||
`Slider` can be implemented in horizontal or vertical orientation. You can set the default starting value(s) for the slider with the `value` prop. | ||
|
||
<Props of={Slider} /> | ||
<Props of={SliderProps} /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.