diff options
author | 2022-11-20 17:35:21 +0530 | |
---|---|---|
committer | 2022-11-20 17:35:21 +0530 | |
commit | 86f9ab693dcad951271f727046214b03d91ebd69 (patch) | |
tree | 3d32ff4814b5484495b811c5fe0ebea4805f4e55 /src/components/ui/Slider.tsx | |
parent | 6.2.1-nightly.47 [skip ci] (diff) | |
download | ferdium-app-86f9ab693dcad951271f727046214b03d91ebd69.tar.gz ferdium-app-86f9ab693dcad951271f727046214b03d91ebd69.tar.zst ferdium-app-86f9ab693dcad951271f727046214b03d91ebd69.zip |
Transform Todo feature, ServiceBarTargetUrl, ServiceIcon, TeamDashboard, Slider, Loader & WorkspaceSwitchningIndicator into ts (#782)
Diffstat (limited to 'src/components/ui/Slider.tsx')
-rw-r--r-- | src/components/ui/Slider.tsx | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/src/components/ui/Slider.tsx b/src/components/ui/Slider.tsx new file mode 100644 index 000000000..ed9fe9073 --- /dev/null +++ b/src/components/ui/Slider.tsx | |||
@@ -0,0 +1,69 @@ | |||
1 | import { ChangeEvent, Component, ReactElement } from 'react'; | ||
2 | import { observer } from 'mobx-react'; | ||
3 | import classnames from 'classnames'; | ||
4 | import { noop } from 'lodash'; | ||
5 | |||
6 | interface IProps { | ||
7 | field: any; | ||
8 | className?: string; | ||
9 | showLabel?: boolean; | ||
10 | disabled?: boolean; | ||
11 | type?: 'range' | 'number'; | ||
12 | onSliderChange?: (e: ChangeEvent) => void; | ||
13 | } | ||
14 | |||
15 | // TODO - [TS DEBT] Should this file be converted into the coding style similar to './toggle/index.tsx'? | ||
16 | @observer | ||
17 | class Slider extends Component<IProps> { | ||
18 | onChange(e: ChangeEvent<HTMLInputElement>): void { | ||
19 | const { field, onSliderChange = noop } = this.props; | ||
20 | field.onChange(e); | ||
21 | onSliderChange(e); | ||
22 | } | ||
23 | |||
24 | render(): ReactElement { | ||
25 | const { | ||
26 | field, | ||
27 | className = '', | ||
28 | showLabel = true, | ||
29 | disabled = false, | ||
30 | type = 'range', | ||
31 | } = this.props; | ||
32 | |||
33 | if (field.value === '' && field.default !== '') { | ||
34 | field.value = field.default; | ||
35 | } | ||
36 | |||
37 | return ( | ||
38 | <div | ||
39 | className={classnames([ | ||
40 | 'franz-form__field', | ||
41 | 'franz-form__slider-wrapper', | ||
42 | className, | ||
43 | ])} | ||
44 | > | ||
45 | <div className="slider-container"> | ||
46 | <input | ||
47 | className="slider" | ||
48 | type={type} | ||
49 | id={field.id} | ||
50 | name={field.name} | ||
51 | value={field.value} | ||
52 | min="1" | ||
53 | max="100" | ||
54 | onChange={e => (!disabled ? this.onChange(e) : null)} | ||
55 | /> | ||
56 | </div> | ||
57 | |||
58 | {field.error && <div className={field.error}>{field.error}</div>} | ||
59 | {field.label && showLabel && ( | ||
60 | <label className="franz-form__label" htmlFor={field.id}> | ||
61 | {field.label} | ||
62 | </label> | ||
63 | )} | ||
64 | </div> | ||
65 | ); | ||
66 | } | ||
67 | } | ||
68 | |||
69 | export default Slider; | ||