-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Fixed bugs with localStorage initialization.
Added basic tests
- Loading branch information
1 parent
d9f2b32
commit 9953a91
Showing
11 changed files
with
4,432 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
module.exports = { | ||
"env": { | ||
"test": { | ||
"presets": ['@babel/preset-env', '@babel/preset-react'] | ||
} | ||
} | ||
}; |
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
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
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,94 @@ | ||
import React from 'react' | ||
import { useLocalStorage, useKeyboardShortcut, useOnClickOutside, useFiler } from '../src/main' | ||
|
||
export const LocalStorageTest = () => { | ||
const [state, setState] = useLocalStorage("FRUIT", "apple") | ||
|
||
const update = () => { | ||
setState('pear') | ||
} | ||
|
||
const updateCallback = () => { | ||
setState(fruit => fruit + 'pear') | ||
} | ||
|
||
return ( | ||
<div> | ||
<div>{state}</div> | ||
<button onClick={update}>UPDATE</button> | ||
<button onClick={updateCallback}>UPDATECALLBACK</button> | ||
</div> | ||
) | ||
} | ||
|
||
export const FilerTest = ({getState}) => { | ||
const [files, {add, remove, update, clear}] = useFiler('FILES') | ||
|
||
const addFile = () => { | ||
add('apple') | ||
} | ||
|
||
const addFileWithID = () => { | ||
add('apple', 'fruit_id') | ||
} | ||
|
||
const removeFile = () => { | ||
const id = Object.keys(files)[0] | ||
remove(id) | ||
} | ||
|
||
const updateFile = () => { | ||
const id = Object.keys(files)[0] | ||
update(id, 'pear') | ||
} | ||
|
||
const clearFiles = () => { | ||
clear() | ||
} | ||
getState(files) | ||
return ( | ||
<div> | ||
<button onClick={addFile}>ADD</button> | ||
<button onClick={addFileWithID}>ADDID</button> | ||
<button onClick={removeFile}>REMOVE</button> | ||
<button onClick={updateFile}>UPDATE</button> | ||
<button onClick={clearFiles}>CLEAR</button> | ||
</div> | ||
) | ||
} | ||
|
||
export const OnClickOutside = ({disabled}) => { | ||
const [fruit, setFruit] = React.useState('apple') | ||
|
||
const handleClickOutside = () => setFruit('pear') | ||
|
||
const outsideRef = useOnClickOutside(handleClickOutside, disabled) | ||
|
||
return ( | ||
<div> | ||
<div ref={outsideRef} style={{padding: 10}}> | ||
<div>MODAL</div> | ||
</div> | ||
<div>OUTSIDE</div> | ||
<div>{fruit}</div> | ||
</div> | ||
) | ||
} | ||
|
||
export const KeyboardShortcut = ({disabled}) => { | ||
const [fruit, setFruit] = React.useState('apple') | ||
|
||
const onKey = () => setFruit('pear') | ||
|
||
const { enable, disable } = useKeyboardShortcut({ | ||
keyCode: 65, | ||
action: onKey, | ||
disabled | ||
}) | ||
return ( | ||
<div> | ||
<div>KEYDOWN</div> | ||
<div>{fruit}</div> | ||
</div> | ||
) | ||
} |
Oops, something went wrong.