From 9cd17213a07fb263902ca779eb96febbe09a2dba Mon Sep 17 00:00:00 2001 From: Tobias Date: Thu, 25 Aug 2022 11:49:30 +0200 Subject: [PATCH] feat(Slider): add toolbar on active thumb button --- .../src/components/slider/SliderHelpers.tsx | 11 +- .../src/components/slider/SliderInstance.tsx | 16 +- .../src/components/slider/SliderThumb.tsx | 141 +++++++++++------- .../__tests__/Slider.screenshot.test.js | 6 +- .../__snapshots__/Slider.test.tsx.snap | 9 +- ...to-match-the-active-state-1-f1077.snap.png | Bin 2358 -> 5352 bytes ...-to-match-the-focus-state-1-1e3c0.snap.png | Bin 2974 -> 5007 bytes ...-to-match-the-hover-state-1-40b49.snap.png | Bin 2974 -> 5007 bytes .../slider/stories/Slider.stories.tsx | 18 +-- .../src/components/slider/style/_slider.scss | 13 +- 10 files changed, 128 insertions(+), 86 deletions(-) diff --git a/packages/dnb-eufemia/src/components/slider/SliderHelpers.tsx b/packages/dnb-eufemia/src/components/slider/SliderHelpers.tsx index e08d55cc084..12e66d1d0a4 100644 --- a/packages/dnb-eufemia/src/components/slider/SliderHelpers.tsx +++ b/packages/dnb-eufemia/src/components/slider/SliderHelpers.tsx @@ -126,19 +126,16 @@ export const formatNumber = ( return value } -export const getHumanNumber = ( +export const getFormattedNumber = ( value: number, numberFormat: formatOptionParams ) => { - const num = value as number - const { aria: humanNumber } = ( + return ( numberFormat - ? formatNumber(num, { + ? formatNumber(value as number, { ...(numberFormat || {}), returnAria: true, }) - : { aria: null } + : { aria: null, number: null } ) as formatReturnValue - - return String(humanNumber || value) } diff --git a/packages/dnb-eufemia/src/components/slider/SliderInstance.tsx b/packages/dnb-eufemia/src/components/slider/SliderInstance.tsx index 14d395140ab..c7006bc3e4f 100644 --- a/packages/dnb-eufemia/src/components/slider/SliderInstance.tsx +++ b/packages/dnb-eufemia/src/components/slider/SliderInstance.tsx @@ -26,7 +26,7 @@ import { } from './SliderTrack' import { SliderThumb } from './SliderThumb' import { useSliderProps } from './hooks/useSliderProps' -import { clamp, getHumanNumber } from './SliderHelpers' +import { clamp, getFormattedNumber } from './SliderHelpers' export function SliderInstance() { const context = React.useContext(Context) @@ -158,7 +158,7 @@ function SubtractButton() { subtractParams['aria-hidden'] = attributes['aria-hidden'] } - const humanNumber = getHumanNumber(value as number, numberFormat) + const humanNumber = getFormattedNumber(value as number, numberFormat) return (