-
Notifications
You must be signed in to change notification settings - Fork 390
feat(Slider): add support for custom tooltip content #12531
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { useState } from 'react'; | ||
| import { Slider, SliderOnChangeEvent } from '@patternfly/react-core'; | ||
|
|
||
| export const SliderCustomTooltip: React.FunctionComponent = () => { | ||
| const [value, setValue] = useState(50); | ||
| const steps = [ | ||
| { value: 0, label: '0' }, | ||
| { value: 12.5, label: '1', isLabelHidden: true }, | ||
| { value: 25, label: '2' }, | ||
| { value: 37.5, label: '3', isLabelHidden: true }, | ||
| { value: 50, label: '4' }, | ||
| { value: 62.5, label: '5', isLabelHidden: true }, | ||
| { value: 75, label: '6' }, | ||
| { value: 87.5, label: '7', isLabelHidden: true }, | ||
| { value: 100, label: '8' } | ||
| ]; | ||
|
|
||
| const displayValue = () => { | ||
| const step = steps.find((step) => step.value === value); | ||
| return step ? step.label : 0; | ||
| }; | ||
|
|
||
| const customTooltipContent = () => <div>Custom tooltip content for step: {displayValue()}</div>; | ||
|
|
||
| return ( | ||
| <Slider | ||
| hasTooltipOverThumb | ||
| tooltipContent={customTooltipContent()} | ||
| value={value} | ||
| onChange={(_event: SliderOnChangeEvent, value: number) => setValue(value)} | ||
| customSteps={steps} | ||
| /> | ||
|
Comment on lines
+26
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. May not be absolutely necessary with the above example verbiage added in, but we could add a second slider tothis example showing an implementation more similar to the original issue, where each step is a date timestamp. If we do, maybe we have the slider steps min and max values be 1-10 with whole number intervals |
||
| ); | ||
| }; | ||
Uh oh!
There was an error while loading. Please reload this page.