/
RangeControl.tsx
71 lines (67 loc) · 1.95 KB
/
RangeControl.tsx
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import React, { memo, useCallback } from 'react'
import styled from 'styled-components'
import pick from 'lodash/pick'
import { Control } from './Control'
import { TextInput } from './TextInput'
import { PropertyHeader } from './PropertyHeader'
import { Help } from './Help'
import { Flavor } from '../../types'
import { RangeControlConfig } from './types'
interface RangeControlProps {
id: string
property: any
flavors: Flavor[]
currentFlavor: Flavor
value: number
onChange: (value: number) => void
config: RangeControlConfig
context?: any
}
export const RangeControl = memo(
({
id,
property,
flavors,
currentFlavor,
config,
value,
onChange,
context,
}: RangeControlProps) => {
const handleChange = useCallback(event => onChange(Number(event.target.value)), [onChange])
return (
<Control
id={id}
description={property.description}
flavors={flavors}
currentFlavor={currentFlavor}
supportedFlavors={property.flavors}
>
<PropertyHeader id={id} {...property} context={context} />
<Row>
<TextInput
id={id}
value={value}
unit={config.unit}
isNumber={true}
onChange={handleChange}
/>
<input
type="range"
value={value}
onChange={handleChange}
{...pick(config, ['min', 'max', 'step'])}
/>
</Row>
<Help>{property.help}</Help>
</Control>
)
}
)
const Row = styled.div`
display: grid;
grid-template-columns: 60px auto;
grid-column-gap: 9px;
max-width: 240px;
margin-bottom: 5px;
`