From e7aaa14dc2f3628caab9ea142258c4af7d45b19a Mon Sep 17 00:00:00 2001 From: Tobias Date: Thu, 25 Aug 2022 11:49:09 +0200 Subject: [PATCH] feat(Slider): add tooltip on active thumb button --- .../docs/uilib/components/slider/Examples.tsx | 9 +- .../src/components/slider/SliderHelpers.tsx | 11 +- .../src/components/slider/SliderInstance.tsx | 16 +- .../src/components/slider/SliderThumb.tsx | 140 +++++++++++------- .../__tests__/Slider.screenshot.test.js | 6 +- .../__snapshots__/Slider.test.tsx.snap | 9 +- ...to-match-the-active-state-1-f1077.snap.png | Bin 2358 -> 5303 bytes ...-to-match-the-focus-state-1-1e3c0.snap.png | Bin 2974 -> 5718 bytes ...-to-match-the-hover-state-1-40b49.snap.png | Bin 2974 -> 5718 bytes .../slider/stories/Slider.stories.tsx | 4 +- .../src/components/slider/style/_slider.scss | 13 +- 11 files changed, 133 insertions(+), 75 deletions(-) diff --git a/packages/dnb-design-system-portal/src/docs/uilib/components/slider/Examples.tsx b/packages/dnb-design-system-portal/src/docs/uilib/components/slider/Examples.tsx index 29b2861a203..e5f8fb4040f 100644 --- a/packages/dnb-design-system-portal/src/docs/uilib/components/slider/Examples.tsx +++ b/packages/dnb-design-system-portal/src/docs/uilib/components/slider/Examples.tsx @@ -15,6 +15,7 @@ export const SliderExampleDefault = () => ( max={100} value={70} label="Default Slider:" + numberFormat={{ currency: 'EUR' }} onChange={({ value }) => console.log('onChange:', value)} /> ` @@ -33,6 +34,7 @@ export const SliderExampleMultiButtons = () => ( value={[30, 70]} step={5} label="Range with steps:" + numberFormat={{ currency: 'EUR' }} onChange={({ value }) => console.log('onChange:', value)} bottom /> @@ -41,7 +43,7 @@ export const SliderExampleMultiButtons = () => ( max={100} value={[10, 30, 50, 70]} label="Multi thumbs:" - numberFormat={{ decimals: 2, currency: true }} + numberFormat={{ currency: true }} onChange={({ value, number }) => console.log('onChange:', value, number)} /> @@ -59,6 +61,7 @@ export const SliderExampleMultiButtonsThumbBehavior = () => ( multiThumbBehavior="omit" value={[30, 70]} label="Omit behavior:" + numberFormat={{ currency: 'EUR' }} onChange={({ value }) => console.log('onChange:', value)} bottom /> @@ -67,7 +70,7 @@ export const SliderExampleMultiButtonsThumbBehavior = () => ( value={[10, 50, 70]} step={1} label="Push behavior:" - numberFormat={{ decimals: 2, currency: true }} + numberFormat={{ currency: true }} onChange={({ value, number }) => console.log('onChange:', value, number)} /> @@ -88,6 +91,7 @@ const Component = () => { step={10} hideButtons label="Slider A:" + numberFormat={{ currency: 'EUR' }} onChange={({ value }) => setValue(value)} /> @@ -98,6 +102,7 @@ const Component = () => { step={1} label="Slider B:" labelDirection="vertical" + numberFormat={{ currency: 'NOK' }} onChange={({ value }) => setValue(value)} /> { - 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 004ff781f38..0642665b89b 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) @@ -164,7 +164,7 @@ function SubtractButton() { subtractParams['aria-hidden'] = attributes['aria-hidden'] } - const humanNumber = getHumanNumber(value as number, numberFormat) + const humanNumber = getFormattedNumber(value as number, numberFormat) return (