-
Notifications
You must be signed in to change notification settings - Fork 23
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 #6 from blackary/vanilla2
Simplify to vanilla js
- Loading branch information
Showing
16 changed files
with
291 additions
and
338 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
recursive-include src/st_keyup/frontend/build * | ||
recursive-include src/st_keyup/frontend * | ||
include README.md | ||
include LICENSE |
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 |
---|---|---|
|
@@ -7,14 +7,13 @@ | |
|
||
setuptools.setup( | ||
name="streamlit-keyup", | ||
version="0.1.6", | ||
version="0.1.7", | ||
author="Zachary Blackwood", | ||
author_email="[email protected]", | ||
description="Text input that renders on keyup", | ||
long_description=long_description, | ||
long_description_content_type="text/markdown", | ||
url="https://github.com/blackary/streamlit-keyup", | ||
# packages=setuptools.find_packages(), | ||
packages=setuptools.find_packages(where="src"), | ||
package_dir={"": "src"}, | ||
include_package_data=True, | ||
|
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Streamlit Keyup</title> | ||
<script src="./streamlit-component-lib.js"></script> | ||
<script src="./main.js"></script> | ||
<link rel="stylesheet" href="./style.css" /> | ||
</head> | ||
<body> | ||
<div id="root"> | ||
<label id="label" for="text_input">This is a label</label> | ||
<div class="input"> | ||
<input type="text" name="text_input" id="input_box" /> | ||
</div> | ||
</div> | ||
</body> | ||
</html> |
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,49 @@ | ||
function onKeyUp(event) { | ||
Streamlit.setComponentValue(event.target.value) | ||
} | ||
|
||
const debounce = (callback, wait) => { | ||
let timeoutId = null; | ||
return (...args) => { | ||
window.clearTimeout(timeoutId); | ||
timeoutId = window.setTimeout(() => { | ||
callback.apply(null, args); | ||
}, wait); | ||
}; | ||
} | ||
|
||
/** | ||
* The component's render function. This will be called immediately after | ||
* the component is initially loaded, and then again every time the | ||
* component gets new data from Python. | ||
*/ | ||
function onRender(event) { | ||
// Get the RenderData from the event | ||
if (!window.rendered) { | ||
const {label, value, debounce: debounce_time } = event.detail.args; | ||
const input = document.getElementById("input_box"); | ||
const label_el = document.getElementById("label") | ||
|
||
if (label_el) { | ||
label_el.innerText = label | ||
} | ||
|
||
if (value && !input.value) { | ||
input.value = value | ||
} | ||
|
||
if (debounce_time > 0) { | ||
input.onkeyup = debounce(onKeyUp, debounce_time) | ||
} | ||
else { | ||
input.onkeyup = onKeyUp | ||
} | ||
|
||
window.rendered = true | ||
} | ||
} | ||
|
||
Streamlit.events.addEventListener(Streamlit.RENDER_EVENT, onRender) | ||
Streamlit.setComponentReady() | ||
// Render with the correct height | ||
Streamlit.setFrameHeight(85) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.