-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #127 from nkbt/more-defauls-values
More default values
- Loading branch information
Showing
5 changed files
with
134 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import React, {useState, useCallback} from 'react'; | ||
import {DebounceInput} from '../src'; | ||
|
||
|
||
export const DefaultValue = () => { | ||
const [type, setType] = useState('number'); | ||
const [value, setValue] = useState(0); | ||
|
||
const onChange = useCallback(e => setValue(e.target.value), [setValue]); | ||
|
||
const onEmptyNumber = useCallback(() => { | ||
setType(undefined); | ||
setValue(undefined); | ||
setTimeout(() => { | ||
setType('number'); | ||
}); | ||
}, [setValue, setType]); | ||
|
||
const onNumberZero = useCallback(() => { | ||
setType(undefined); | ||
setValue(undefined); | ||
setTimeout(() => { | ||
setValue(0); | ||
setType('number'); | ||
}); | ||
}, [setValue, setType]); | ||
|
||
const onNumber = useCallback(() => { | ||
setType(undefined); | ||
setValue(undefined); | ||
setTimeout(() => { | ||
setValue(5); | ||
setType('number'); | ||
}); | ||
}, [setValue, setType]); | ||
|
||
const onEmptyText = useCallback(() => { | ||
setType(undefined); | ||
setValue(undefined); | ||
setTimeout(() => { | ||
setType('text'); | ||
}); | ||
}, [setValue, setType]); | ||
|
||
const onText = useCallback(() => { | ||
setType(undefined); | ||
setValue(undefined); | ||
setTimeout(() => { | ||
setValue('some text'); | ||
setType('text'); | ||
}); | ||
}, [setValue, setType]); | ||
|
||
const onDestroy = useCallback(() => { | ||
setValue(undefined); | ||
setType(undefined); | ||
}, [setValue, setType]); | ||
|
||
|
||
return ( | ||
<> | ||
<div className="config"> | ||
<label className="label"> | ||
<button | ||
type="button" | ||
className="input" | ||
onClick={onNumberZero}> | ||
Number with value 0 | ||
</button> | ||
</label> | ||
<label className="label"> | ||
<button | ||
type="button" | ||
className="input" | ||
onClick={onEmptyNumber}> | ||
Number with no value | ||
</button> | ||
</label> | ||
<label className="label"> | ||
<button | ||
type="button" | ||
className="input" | ||
onClick={onNumber}> | ||
Number with some value | ||
</button> | ||
</label> | ||
<label className="label"> | ||
<button | ||
type="button" | ||
className="input" | ||
onClick={onEmptyText}> | ||
Text with no value | ||
</button> | ||
</label> | ||
<label className="label"> | ||
<button | ||
type="button" | ||
className="input" | ||
onClick={onText}> | ||
Text with some value | ||
</button> | ||
</label> | ||
<label className="label"> | ||
<button | ||
type="button" | ||
className="input" | ||
onClick={onDestroy}> | ||
Destroy | ||
</button> | ||
</label> | ||
</div> | ||
|
||
{type && ( | ||
<DebounceInput | ||
type={type} | ||
value={value} | ||
debounceTimeout={500} | ||
onChange={onChange} /> | ||
)} | ||
|
||
<p>Type: {JSON.stringify(type)}</p> | ||
<p>Value: {JSON.stringify(value)}</p> | ||
</> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -11,6 +11,10 @@ | |
padding-bottom: 20px; | ||
} | ||
|
||
.config button { | ||
margin: 5px 0; | ||
} | ||
|
||
.label { | ||
padding-right: 20px; | ||
} | ||
|
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