From c75d60de015dbf0537ed765e0901a0cec9d8abb3 Mon Sep 17 00:00:00 2001 From: quantum-ernest Date: Mon, 29 Apr 2024 15:43:04 +0000 Subject: [PATCH] feat: add keyboard hint Resolves: #7 --- .../streamlit_shortcuts.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/streamlit_shortcuts/streamlit_shortcuts.py b/src/streamlit_shortcuts/streamlit_shortcuts.py index 6eaadb8..7e11b48 100644 --- a/src/streamlit_shortcuts/streamlit_shortcuts.py +++ b/src/streamlit_shortcuts/streamlit_shortcuts.py @@ -41,7 +41,18 @@ def add_keyboard_shortcuts(key_combinations: Dict[str, str]): components.html(js_code, height=0, width=0) -def button(label: str, shortcut: str, on_click: Callable[..., None], *args, **kwargs): - shortcut = {shortcut: label} - add_keyboard_shortcuts(shortcut) - return st.button(label=label, on_click=on_click, args=args, **kwargs) +def button( + label: str, + shortcut: str, + on_click: Callable[..., None], + hint=False, + *args, + **kwargs, +): + key_combination = {shortcut: label} + add_keyboard_shortcuts(key_combination) + if hint is False: + return st.button(label=label, on_click=on_click, args=args, **kwargs) + return st.button( + label=label + f"`{shortcut}`", on_click=on_click, args=args, **kwargs + )