adriangalilea / streamlit-shortcuts

Streamlit keyboard shortcuts for your buttons.
MIT License
17 stars 4 forks source link

add keyboard hint to button (streamlit-extras) #7

Open github-actions[bot] opened 2 months ago

github-actions[bot] commented 2 months ago

https://arnaudmiribel\.github\.io/streamlit\-extras/extras/keyboard\_text/

https://github.com/adriangalilea/streamlit-shortcuts/blob/eb0ca95d8a776f76b5e1f8db2f2879f418264474/src/streamlit_shortcuts/streamlit_shortcuts.py#L7


import streamlit as st

# TODO add keyboard hint to button (streamlit-extras)
# https://arnaudmiribel.github.io/streamlit-extras/extras/keyboard_text/

def add_keyboard_shortcuts(key_combinations: dict[str, str]):
quantum-ernest commented 2 months ago

Add a little explanation.

adriangalilea commented 2 months ago

Ah, yeah, I did, but the action closed the issue when I changed the wording, here it was. Let me past it here for reference:

https://arnaudmiribel.github.io/streamlit-extras/extras/keyboard_text/

It'd be great if button showed this kind of hint inside, not sure how feasible is it, but it would greatly improve UX, should probably be optional.

streamlit_shortcuts.button("delete", on_click=delete_callback, shortcut="Ctrl+Shift+X", hint=True)
adriangalilea commented 2 months ago
image

A bit like this, but inside the button that get's the keybinding. So discoverability is built-in and there's no need to create an info pane explaining shortcuts.

quantum-ernest commented 2 months ago

So the shortcut key binding should show on the button if hint is set to true right?

adriangalilea commented 2 months ago

So the shortcut key binding should show on the button if hint is set to true right?

Yes

quantum-ernest commented 2 months ago

The st.button() doesn't evaluate html, when you pass the key() as the label. I can put it on the side using st.columns() if that's ok/

adriangalilea commented 2 months ago

Hey @quantum-ernest, that could def work, maybe under would be better instead on the side, care to share a screenshot?

quantum-ernest commented 2 months ago

Screenshot from 2024-04-29 17-06-54

adriangalilea commented 2 months ago

Nice! Looks a bit rough since it's non responsive(white on dark theme) and the lack of alignment with the button. But could work as a bare implementation, well done!

Perhaps scrapping streamlit extras and adding some styled text inside the button would work better. (not sure if possible, just thinking out loud, can't dedicate time atm sadly)

Feel free to PR if you think it's good ;)

Thank you so much @quantum-ernest