Created
June 13, 2026 05:06
-
-
Save hansthen/928a43a6db80a6781527c7bf2bec70b1 to your computer and use it in GitHub Desktop.
drag and drop
This file contains hidden or 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
| import streamlit as st | |
| button = st.html("<span id='button' draggable='true' style='border: 1px solid red;'>hello world</span>") | |
| with st.container(key="board") as cont: | |
| left, right = st.columns(2) | |
| with left: | |
| st.markdown('<div data-column="left" class="column-marker"/>', unsafe_allow_html=True) | |
| st.write("left") | |
| with right: | |
| st.markdown('<div data-column="right" class="column-marker"/>', unsafe_allow_html=True) | |
| st.write("right") | |
| draggable = st.components.v2.component( | |
| name="hello_world", | |
| js=""" | |
| export default function(component) { | |
| const { setTriggerValue } = component; | |
| const button = document.getElementById("button"); | |
| const zeno = document.querySelector('.st-key-board'); | |
| const columns = zeno.querySelectorAll('.stColumn:has(.column-marker)'); | |
| zeno.ondragover = (e) => { | |
| e.preventDefault(); | |
| setTriggerValue('over', "zeno"); | |
| }; | |
| for (const column of columns) { | |
| const marker = column.querySelector('[data-column]'); | |
| console.log(marker); | |
| column.ondrop = (e) => { | |
| e.preventDefault(); | |
| setTriggerValue('drop', marker.dataset.column); | |
| } | |
| }; | |
| console.log("ramen"); | |
| } | |
| """ | |
| ) | |
| x = draggable() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment