diff options
author | sanine-a <sanine.not@pm.me> | 2021-04-13 11:37:51 -0500 |
---|---|---|
committer | sanine-a <sanine.not@pm.me> | 2021-04-13 11:37:51 -0500 |
commit | c9c1b78ed805371615d3ca8b54c86da9a35db8ce (patch) | |
tree | 1af9063f2e30392fc039738105f86461dddec576 /App.js | |
parent | bc594a2d3839d1d0a3cc76eed23ec8535c72f6bf (diff) |
implement basic user input and button styling
Diffstat (limited to 'App.js')
-rw-r--r-- | App.js | 49 |
1 files changed, 40 insertions, 9 deletions
@@ -1,6 +1,8 @@ let state = {}; let internalState = {}; +const KEY_ENTER = 13; + state.currentChar = '你'; function setState(key, value) @@ -18,19 +20,48 @@ const CurrentCharacter = function({character}) character ); } - + +function shakeInputBox() +{ + setState('inputShaking', true); + setTimeout(() => setState('inputShaking', false), 300); +} + const App = function() { - const { currentChar } = state; + const { currentChar, inputValue, inputShaking } = state; return h( 'div', {}, [ - h( - CurrentCharacter, - {character: currentChar} - ), - ] - ); -} + h(CurrentCharacter, + { character: currentChar + }), + + h(InputBox, + { value: inputValue, + shouldGrabFocus: true, + shaking: inputShaking, + handleKeyDown: (e) => + { + if (e.keyCode == KEY_ENTER) { + console.log(inputValue); + } + else { + setTimeout(() => setState('inputValue', e.target.value), 0); + } + } + }), + + h(StyleButton, + { + text: 'hello, world', + enabled: true, + handleClick: () => { + console.log('hi there'); + }, + }), + ] + ); + } |