hyperlink-button 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hyperlink_button-0.1.0/LICENSE +21 -0
- hyperlink_button-0.1.0/MANIFEST.in +1 -0
- hyperlink_button-0.1.0/PKG-INFO +60 -0
- hyperlink_button-0.1.0/README.md +35 -0
- hyperlink_button-0.1.0/hyperlink_button/__init__.py +5 -0
- hyperlink_button-0.1.0/hyperlink_button/_component.py +106 -0
- hyperlink_button-0.1.0/hyperlink_button/frontend/build/assets/index-Cg1LCKIs.css +1 -0
- hyperlink_button-0.1.0/hyperlink_button/frontend/build/assets/index-DTJxcZAl.js +63 -0
- hyperlink_button-0.1.0/hyperlink_button/frontend/build/index.html +13 -0
- hyperlink_button-0.1.0/hyperlink_button.egg-info/PKG-INFO +60 -0
- hyperlink_button-0.1.0/hyperlink_button.egg-info/SOURCES.txt +14 -0
- hyperlink_button-0.1.0/hyperlink_button.egg-info/dependency_links.txt +1 -0
- hyperlink_button-0.1.0/hyperlink_button.egg-info/requires.txt +10 -0
- hyperlink_button-0.1.0/hyperlink_button.egg-info/top_level.txt +1 -0
- hyperlink_button-0.1.0/pyproject.toml +48 -0
- hyperlink_button-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Maxim Saplin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
recursive-include hyperlink_button/frontend/build *
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
|
+
Name: hyperlink_button
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Streamlit custom component: hyperlink-like button with stock button API
|
|
5
|
+
Author: OpenCode
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/your-org/hyperlink_button
|
|
8
|
+
Project-URL: Source, https://github.com/your-org/hyperlink_button
|
|
9
|
+
Project-URL: Issues, https://github.com/your-org/hyperlink_button/issues
|
|
10
|
+
Keywords: streamlit,component,ui,web,python
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
13
|
+
Requires-Python: >=3.13
|
|
14
|
+
Description-Content-Type: text/markdown
|
|
15
|
+
License-File: LICENSE
|
|
16
|
+
Requires-Dist: streamlit
|
|
17
|
+
Provides-Extra: dev
|
|
18
|
+
Requires-Dist: pytest; extra == "dev"
|
|
19
|
+
Requires-Dist: pytest-xdist; extra == "dev"
|
|
20
|
+
Requires-Dist: requests; extra == "dev"
|
|
21
|
+
Requires-Dist: playwright; extra == "dev"
|
|
22
|
+
Requires-Dist: build; extra == "dev"
|
|
23
|
+
Requires-Dist: twine; extra == "dev"
|
|
24
|
+
Requires-Dist: ruff; extra == "dev"
|
|
25
|
+
|
|
26
|
+
# hyperlink_button
|
|
27
|
+
|
|
28
|
+
`hyperlink_button` is a Streamlit custom component that looks like a hoverable text link, but behaves like `st.button`.
|
|
29
|
+
|
|
30
|
+
<img width="650" alt="image" src="https://github.com/user-attachments/assets/32e07e55-a575-4c6d-aa87-30da35915d11" />
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
From source (dev):
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
python -m pip install -e ".[dev]"
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Usage
|
|
41
|
+
|
|
42
|
+
```python
|
|
43
|
+
import streamlit as st
|
|
44
|
+
from hyperlink_button import hyperlink_button
|
|
45
|
+
|
|
46
|
+
clicked = hyperlink_button(
|
|
47
|
+
"Open details",
|
|
48
|
+
help="Does a normal Streamlit rerun",
|
|
49
|
+
type="secondary",
|
|
50
|
+
)
|
|
51
|
+
|
|
52
|
+
st.write("clicked", clicked)
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Development
|
|
56
|
+
|
|
57
|
+
- Build frontend: `cd hyperlink_button/frontend && npm install && npm run build`
|
|
58
|
+
- Run demo: `streamlit run examples/demo_app.py`
|
|
59
|
+
|
|
60
|
+
Streamlit reference docs are available via the local `st_docs/` symlink.
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# hyperlink_button
|
|
2
|
+
|
|
3
|
+
`hyperlink_button` is a Streamlit custom component that looks like a hoverable text link, but behaves like `st.button`.
|
|
4
|
+
|
|
5
|
+
<img width="650" alt="image" src="https://github.com/user-attachments/assets/32e07e55-a575-4c6d-aa87-30da35915d11" />
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
From source (dev):
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
python -m pip install -e ".[dev]"
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
import streamlit as st
|
|
19
|
+
from hyperlink_button import hyperlink_button
|
|
20
|
+
|
|
21
|
+
clicked = hyperlink_button(
|
|
22
|
+
"Open details",
|
|
23
|
+
help="Does a normal Streamlit rerun",
|
|
24
|
+
type="secondary",
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
st.write("clicked", clicked)
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Development
|
|
31
|
+
|
|
32
|
+
- Build frontend: `cd hyperlink_button/frontend && npm install && npm run build`
|
|
33
|
+
- Run demo: `streamlit run examples/demo_app.py`
|
|
34
|
+
|
|
35
|
+
Streamlit reference docs are available via the local `st_docs/` symlink.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import inspect
|
|
5
|
+
import os
|
|
6
|
+
import re
|
|
7
|
+
|
|
8
|
+
import streamlit as st
|
|
9
|
+
import streamlit.components.v1 as components
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
_BUILD_DIR = os.path.join(os.path.dirname(__file__), "frontend", "build")
|
|
13
|
+
_DEV_URL = os.environ.get("HYPERLINK_BUTTON_DEV_SERVER_URL")
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _declare_component():
|
|
17
|
+
# components.declare_component expects exactly one of url/path.
|
|
18
|
+
if _DEV_URL:
|
|
19
|
+
return components.declare_component("hyperlink_button", url=_DEV_URL)
|
|
20
|
+
return components.declare_component("hyperlink_button", path=_BUILD_DIR)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
_HB_COMPONENT = _declare_component()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def _safe_id(value: str) -> str:
|
|
27
|
+
# For DOM/test ids.
|
|
28
|
+
value = re.sub(r"[^a-zA-Z0-9_-]+", "_", value)
|
|
29
|
+
return value[:64] if value else "anon"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def _instance_id(label: str, user_key: str | None) -> str:
|
|
33
|
+
# If user provided an explicit key, Streamlit already enforces uniqueness;
|
|
34
|
+
# use it to make Playwright selectors stable.
|
|
35
|
+
if user_key:
|
|
36
|
+
return _safe_id(user_key)
|
|
37
|
+
|
|
38
|
+
# Otherwise derive a stable id for a given callsite + label.
|
|
39
|
+
# stack[0] = _instance_id, stack[1] = hyperlink_button, stack[2] = caller
|
|
40
|
+
frame = inspect.stack()[2]
|
|
41
|
+
payload = f"{frame.filename}:{frame.lineno}:{frame.function}:{label}"
|
|
42
|
+
return hashlib.sha256(payload.encode("utf-8")).hexdigest()[:16]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def hyperlink_button(
|
|
46
|
+
label: str,
|
|
47
|
+
key: str | None = None,
|
|
48
|
+
help: str | None = None,
|
|
49
|
+
on_click=None,
|
|
50
|
+
args=None,
|
|
51
|
+
kwargs=None,
|
|
52
|
+
*,
|
|
53
|
+
type: str = "secondary",
|
|
54
|
+
icon: str | None = None,
|
|
55
|
+
icon_position: str = "left",
|
|
56
|
+
disabled: bool = False,
|
|
57
|
+
use_container_width: bool | None = None,
|
|
58
|
+
width="content",
|
|
59
|
+
shortcut: str | None = None,
|
|
60
|
+
) -> bool:
|
|
61
|
+
"""Hyperlink-styled Streamlit button.
|
|
62
|
+
|
|
63
|
+
Mirrors the current `st.button` API but renders as hyperlink-like text.
|
|
64
|
+
"""
|
|
65
|
+
|
|
66
|
+
instance_id = _instance_id(label, key)
|
|
67
|
+
component_key = (
|
|
68
|
+
f"_hyperlink_button:{key}" if key else f"_hyperlink_button:{instance_id}"
|
|
69
|
+
)
|
|
70
|
+
state_key = f"_hyperlink_button_last_click:{component_key}"
|
|
71
|
+
last_seen = int(st.session_state.get(state_key, 0) or 0)
|
|
72
|
+
|
|
73
|
+
click_count = _HB_COMPONENT(
|
|
74
|
+
key=component_key,
|
|
75
|
+
label=label,
|
|
76
|
+
instance_id=instance_id,
|
|
77
|
+
testid=f"hyperlink-button-{instance_id}",
|
|
78
|
+
help=help,
|
|
79
|
+
disabled=disabled,
|
|
80
|
+
type=type,
|
|
81
|
+
icon=icon,
|
|
82
|
+
icon_position=icon_position,
|
|
83
|
+
use_container_width=use_container_width,
|
|
84
|
+
width=width,
|
|
85
|
+
shortcut=shortcut,
|
|
86
|
+
default=0,
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
# Component returns an int counter; convert to ephemeral bool.
|
|
90
|
+
try:
|
|
91
|
+
click_count_int = int(click_count or 0)
|
|
92
|
+
except Exception:
|
|
93
|
+
click_count_int = 0
|
|
94
|
+
|
|
95
|
+
clicked = click_count_int > last_seen
|
|
96
|
+
# Mirror st.button's "trigger-like" behavior for users who rely on session_state.
|
|
97
|
+
if key:
|
|
98
|
+
st.session_state[key] = clicked
|
|
99
|
+
|
|
100
|
+
if clicked:
|
|
101
|
+
st.session_state[state_key] = click_count_int
|
|
102
|
+
if on_click is not None:
|
|
103
|
+
cb_args = args or ()
|
|
104
|
+
cb_kwargs = kwargs or {}
|
|
105
|
+
on_click(*cb_args, **cb_kwargs)
|
|
106
|
+
return clicked
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
:root{color-scheme:light}.hb-root{display:inline-flex;align-items:center;justify-content:flex-start}.hb-button{font-family:"Source Serif 4",Georgia,Times New Roman,serif;font-size:.98rem;color:var(--hb-color, #1a73e8);background:transparent;border:none;padding:0;margin:0;cursor:pointer;text-decoration:none;display:inline-flex;align-items:center;gap:.35rem}.hb-button:hover{text-decoration:underline}.hb-button:focus-visible{outline:2px solid color-mix(in srgb,var(--hb-color, #1a73e8) 70%,transparent);outline-offset:2px;border-radius:2px}.hb-button:disabled{color:#7a7a7a;cursor:not-allowed;text-decoration:none}.hb-button:disabled .hb-label{text-decoration:line-through}.hb-icon{font-size:.95em;line-height:1}.hb-label{line-height:1.2}
|