-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Borrow slider from patternfly, and adapt for vertical display
- Loading branch information
Showing
5 changed files
with
131 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#scope-slider { | ||
position: relative; | ||
width: 300px; | ||
height: 0; | ||
top: 150px; | ||
left: -100px; | ||
z-index: 2; | ||
} |
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,36 @@ | ||
import * as React from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { MetricScope } from '../../model/flow-query'; | ||
import { Slider } from '../slider/Slider'; | ||
|
||
import './scope-slider.css'; | ||
|
||
export interface ScopeSliderProps { | ||
metricScope: MetricScope; | ||
setMetricScope: (ms: MetricScope) => void; | ||
} | ||
|
||
export const ScopeSlider: React.FC<ScopeSliderProps> = ({ metricScope, setMetricScope }) => { | ||
const { t } = useTranslation('plugin__netobserv-plugin'); | ||
|
||
const scopes: [MetricScope, string][] = [ | ||
['resource', t('Resource')], | ||
['owner', t('Owner')], | ||
['namespace', t('Namespace')], | ||
['host', t('Node')] | ||
]; | ||
const index = scopes.findIndex(s => s[0] === metricScope); | ||
|
||
return ( | ||
<div id={'scope-slider'}> | ||
<Slider | ||
value={index < 0 ? 2 : index} | ||
showTicks | ||
max={3} | ||
customSteps={scopes.map((s, idx) => ({ value: idx, label: s[1] }))} | ||
onChange={(value: number) => setMetricScope(scopes[value][0])} | ||
vertical | ||
/> | ||
</div> | ||
); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import * as React from 'react'; | ||
import styles from '@patternfly/react-styles/css/components/Slider/slider'; | ||
import { css } from '@patternfly/react-styles'; | ||
|
||
export interface SliderStepProps extends Omit<React.HTMLProps<HTMLDivElement>, 'label'> { | ||
/** Additional classes added to the slider step. */ | ||
className?: string; | ||
/** Flag indicating the step is active. */ | ||
isActive?: boolean; | ||
/** Flag indicating that the label should be hidden. */ | ||
isLabelHidden?: boolean; | ||
/** Flag indicating that the tick should be hidden. */ | ||
isTickHidden?: boolean; | ||
/** Step label. **/ | ||
label?: string; | ||
/** Step value. **/ | ||
value?: number; | ||
} | ||
|
||
export const SliderStep: React.FunctionComponent<SliderStepProps> = ({ | ||
className, | ||
label, | ||
value, | ||
isTickHidden = false, | ||
isLabelHidden = false, | ||
isActive = false, | ||
...props | ||
}: SliderStepProps) => { | ||
const style = { '--pf-c-slider__step--Left': `${value}%` } as React.CSSProperties; | ||
return ( | ||
<div className={css(styles.sliderStep, isActive && styles.modifiers.active, className)} style={style} {...props}> | ||
{!isTickHidden && <div className={css(styles.sliderStepTick)} />} | ||
{!isLabelHidden && label && <div className={css(styles.sliderStepLabel)}>{label}</div>} | ||
</div> | ||
); | ||
}; | ||
SliderStep.displayName = 'SliderStep'; |