adriangalilea / streamlit-shortcuts

Streamlit keyboard shortcuts for your buttons.
https://shortcuts.streamlit.app/
MIT License
28 stars 5 forks source link

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

Closed github-actions[bot] closed 3 months ago

github-actions[bot] commented 7 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 7 months ago

Add a little explanation.

adriangalilea commented 7 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 7 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 7 months ago

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

adriangalilea commented 7 months ago

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

Yes

quantum-ernest commented 7 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 7 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 7 months ago

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

adriangalilea commented 7 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

github-actions[bot] commented 4 months ago

Closed in 04cf3021fe4758dcdce474233ec7f246c72cd24c