-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
feat(slider): add getTooltipValue prop for custom tooltip value #5384
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
Merged
wingkwong
merged 10 commits into
heroui-inc:beta/release-next
from
ararTP:feat/slider-custom-tooltip-value
Jul 14, 2025
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6b4a1bf
feat(slider): add getTooltipValue prop for custom tooltip value
andartadev1 cbe2ce7
feat(slider): fix coderabbit highlights
andartadev1 5d65d2b
feat(slider): fixed wingkwong highlights
andartadev1 238abfd
feat(slider): added custom-tooltip.raw.tsx?raw
andartadev1 c95ca6c
feat(slider): improved custom-tooltip.raw.tsx
andartadev1 d3c9d04
Merge branch 'beta/release-next' into pr/5384
wingkwong 7c1b637
chore: undo README.md
wingkwong c9be936
chore(slider): use normal $ sign
wingkwong 861e47a
chore(changeset): add changeset
wingkwong d3f5d08
chore(docs): formatting
wingkwong File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| --- | ||
| "@heroui/slider": patch | ||
| --- | ||
|
|
||
| introduce `getTooltipValue` prop for custom tooltip value (#4741) |
42 changes: 42 additions & 0 deletions
42
apps/docs/content/components/slider/custom-tooltip.raw.jsx
This file contains hidden or 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,42 @@ | ||
| import {Slider} from "@heroui/react"; | ||
|
|
||
| export default function App() { | ||
| const formatMillisecondsToHHMMSS = (milliseconds) => { | ||
| if (typeof milliseconds !== "number") { | ||
| // Handle cases where value might be an array for multi-thumb | ||
| milliseconds = Array.isArray(milliseconds) ? milliseconds[0] : milliseconds; | ||
| } | ||
| if (isNaN(milliseconds) || milliseconds < 0) { | ||
| // Default for invalid input | ||
| return "00:00:00"; | ||
| } | ||
|
|
||
| let totalSeconds = Math.floor(milliseconds / 1000); | ||
| let hours = Math.floor(totalSeconds / 3600); | ||
|
|
||
| totalSeconds %= 3600; | ||
| let minutes = Math.floor(totalSeconds / 60); | ||
| let seconds = totalSeconds % 60; | ||
|
|
||
| const pad = (num) => String(num).padStart(2, "0"); | ||
|
|
||
| return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`; | ||
| }; | ||
|
|
||
| return ( | ||
| // The slider's main value will be formatted using default or formatOptions | ||
| // The tooltip will use the hh:mm:ss format from | ||
| <Slider | ||
| showTooltip | ||
| // Example: 1 hour, 1 minute, 5 seconds in ms | ||
| defaultValue={3665000} | ||
| // Single thumb, SliderValue is a number. | ||
| getTooltipValuegetTooltipValue={(value) => formatMillisecondsToHHMMSS(value)} | ||
| label="Video Duration (Tooltip: hh:mm:ss)" | ||
| // Example: 2 hours in ms | ||
| maxValue={7200000} | ||
| // 1-second steps | ||
| step={1000} | ||
| /> | ||
| ); | ||
| } |
40 changes: 40 additions & 0 deletions
40
apps/docs/content/components/slider/custom-tooltip.raw.tsx
This file contains hidden or 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,40 @@ | ||
| import type {SliderValue} from "@heroui/react"; | ||
|
|
||
| import {Slider} from "@heroui/react"; | ||
|
|
||
| export default function App() { | ||
| const formatMillisecondsToHHMMSS = (milliseconds: number) => { | ||
| if (isNaN(milliseconds) || milliseconds < 0) { | ||
| // Default for invalid input | ||
| return "00:00:00"; | ||
| } | ||
|
|
||
| let totalSeconds = Math.floor(milliseconds / 1000); | ||
| let hours = Math.floor(totalSeconds / 3600); | ||
|
|
||
| totalSeconds %= 3600; | ||
| let minutes = Math.floor(totalSeconds / 60); | ||
| let seconds = totalSeconds % 60; | ||
|
|
||
| const pad = (num: number) => String(num).padStart(2, "0"); | ||
|
|
||
| return `${pad(hours)}:${pad(minutes)}:${pad(seconds)}`; | ||
| }; | ||
|
|
||
| return ( | ||
| // The slider's main value will be formatted using default or formatOptions | ||
| // The tooltip will use the hh:mm:ss format from getTooltipValue | ||
| <Slider | ||
| showTooltip | ||
| // Example: 1 hour, 1 minute, 5 seconds in ms | ||
| defaultValue={3665000} | ||
| // Single thumb, SliderValue is a number. | ||
| getTooltipValue={(value: SliderValue) => formatMillisecondsToHHMMSS(value as number)} | ||
| label="Video Duration (Tooltip: hh:mm:ss)" | ||
| // Example: 2 hours in ms | ||
| maxValue={7200000} | ||
| // 1-second steps | ||
| step={1000} | ||
| /> | ||
| ); | ||
| } |
This file contains hidden or 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,15 @@ | ||
| import App from "./custom-tooltip.raw.jsx?raw"; | ||
| import AppTs from "./custom-tooltip.raw.tsx?raw"; | ||
|
ararTP marked this conversation as resolved.
|
||
|
|
||
| const react = { | ||
| "/App.jsx": App, | ||
| }; | ||
|
|
||
| const reactTs = { | ||
| "/App.tsx": AppTs, | ||
| }; | ||
|
|
||
| export default { | ||
| ...react, | ||
| ...reactTs, | ||
| }; | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.