-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
370 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// This is a draft version. | ||
// It doesn't seem to be a good idea to compare using two inputs with different units by composition on parent. | ||
import DynamicUnitInputNumberWithSlider from './DynamicUnitInputNumberWithSlider'; | ||
import InputNumberWithSlider, { | ||
InputNumberWithSliderProps, | ||
} from './InputNumberWithSlider'; | ||
import { useControllableValue } from 'ahooks'; | ||
import React from 'react'; | ||
|
||
interface MultipleTypeInputWithSliderProps | ||
extends Omit<InputNumberWithSliderProps, 'min' | 'max' | 'step'> { | ||
type: 'number' | 'bytes'; | ||
min?: number; | ||
max?: number; | ||
} | ||
|
||
const MultipleTypeInputWithSlider: React.FC< | ||
MultipleTypeInputWithSliderProps | ||
> = ({ | ||
type, | ||
inputNumberProps, | ||
sliderProps, | ||
min, | ||
max, | ||
value: _valueFromProps, | ||
onChange: _onChangeFromProps, | ||
...props | ||
}) => { | ||
const [value, setValue] = useControllableValue({ | ||
value: _valueFromProps, | ||
onChange: _onChangeFromProps, | ||
}); | ||
return type === 'bytes' ? ( | ||
<DynamicUnitInputNumberWithSlider | ||
{...props} | ||
value={value} | ||
onChange={setValue} | ||
extraMarks={sliderProps?.marks} | ||
/> | ||
) : ( | ||
<InputNumberWithSlider | ||
{...props} | ||
min={min} | ||
max={max} | ||
inputNumberProps={inputNumberProps} | ||
sliderProps={sliderProps} | ||
value={value} | ||
onChange={setValue} | ||
/> | ||
); | ||
}; | ||
|
||
export default MultipleTypeInputWithSlider; |
Oops, something went wrong.