Skip to content

Commit

Permalink
feat: add keyboard hint
Browse files Browse the repository at this point in the history
Resolves: #7
  • Loading branch information
quantum-ernest committed Aug 16, 2024
1 parent 3f907b3 commit c75d60d
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/streamlit_shortcuts/streamlit_shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit c75d60d

Please sign in to comment.