Skip to content

Commit

Permalink
feat: add keyboard hint
Browse files Browse the repository at this point in the history
Resolves: adriangalilea#7
  • Loading branch information
quantum-ernest committed Aug 16, 2024
1 parent c75d60d commit c423da0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import streamlit_shortcuts
def delete_callback():
st.write("DELETED!")

streamlit_shortcuts.button("delete", on_click=delete_callback, shortcut="Ctrl+Shift+X")
streamlit_shortcuts.button("delete", on_click=delete_callback, shortcut="Ctrl+Shift+X", hint=True)
```

⭐ NEW in v0.1.5: Support for args and kwargs
Expand All @@ -33,6 +33,7 @@ streamlit_shortcuts.button(
"Delete",
shortcut="Ctrl+Shift+X",
on_click=delete_callback,
hint=True,
args=(42,),
kwargs={"user": "admin"},
type="primary"
Expand Down
18 changes: 18 additions & 0 deletions src/streamlit_shortcuts/streamlit_shortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ def button(
*args,
**kwargs,
):
"""
Creates a button with an optional keyboard shortcut and hint.
Args:
label (str): The text to display on the button.
shortcut (str): The keyboard shortcut associated with the button.
on_click (Callable[..., None]): The function to call when the button is clicked.
hint (bool, optional): Whether to show the keyboard shortcut as a hint on the button label. Defaults to False.
*args: Additional positional arguments passed to the button function.
**kwargs: Additional keyword arguments passed to the button function.
Returns:
The result of the Streamlit button function.
Notes:
This function integrates with Streamlit's `st.button` to display a button with an optional hint showing the associated
keyboard shortcut.
"""
key_combination = {shortcut: label}
add_keyboard_shortcuts(key_combination)
if hint is False:
Expand Down

0 comments on commit c423da0

Please sign in to comment.