-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathFieldSlider.tsx
More file actions
38 lines (33 loc) · 995 Bytes
/
FieldSlider.tsx
File metadata and controls
38 lines (33 loc) · 995 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { useMemo } from 'react'
import type { FieldSliderProps } from './types'
import { FormErrorMessage, FormLabel, Box, Slider } from '@/design-system/components'
import { getLayoutProps } from '@/design-system/utils/getLayoutProps'
export const FieldSlider = ({
errorMessage,
isInvalid,
isRequired,
label,
labelStyle,
testID,
onChangeValue,
value,
...props
}: FieldSliderProps) => {
const { layoutProps, restProps: sliderProps } = useMemo(() => getLayoutProps(props), [props])
return (
<Box width="100%" gap={1} mb={2} {...layoutProps}>
<FormLabel
{...{ isRequired, label, labelStyle }}
label={`${label}: ${value ? Math.round(value * 10) / 10 : 0}`}
testID={testID + ':label'}
/>
<Slider
{...sliderProps}
value={value}
onChangeValue={onChangeValue}
testID={testID + ':input'}
/>
<FormErrorMessage {...{ errorMessage }} testId={testID + ':error_message'} />
</Box>
)
}