st-copy-button 0.0.7__py3-none-any.whl
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.
- st_copy_button/__init__.py +53 -0
- st_copy_button/example.py +35 -0
- st_copy_button/frontend/.env +6 -0
- st_copy_button/frontend/.prettierrc +5 -0
- st_copy_button/frontend/build/asset-manifest.json +10 -0
- st_copy_button/frontend/build/bootstrap.min.css +9500 -0
- st_copy_button/frontend/build/index.html +1 -0
- st_copy_button/frontend/build/static/js/main.105053e0.js +2 -0
- st_copy_button/frontend/build/static/js/main.105053e0.js.map +1 -0
- st_copy_button/frontend/build/style.css +29 -0
- st_copy_button/frontend/package-lock.json +21642 -0
- st_copy_button/frontend/package.json +34 -0
- st_copy_button/frontend/public/bootstrap.min.css +9500 -0
- st_copy_button/frontend/public/index.html +16 -0
- st_copy_button/frontend/public/style.css +29 -0
- st_copy_button/frontend/src/index.tsx +83 -0
- st_copy_button/frontend/src/react-app-env.d.ts +1 -0
- st_copy_button/frontend/tsconfig.json +25 -0
- st_copy_button/package-lock.json +6 -0
- st_copy_button-0.0.7.dist-info/LICENSE +25 -0
- st_copy_button-0.0.7.dist-info/METADATA +56 -0
- st_copy_button-0.0.7.dist-info/RECORD +23 -0
- st_copy_button-0.0.7.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import streamlit.components.v1 as components
|
|
3
|
+
|
|
4
|
+
_RELEASE = True
|
|
5
|
+
|
|
6
|
+
if not _RELEASE:
|
|
7
|
+
_component_func = components.declare_component(
|
|
8
|
+
"st_copy_button",
|
|
9
|
+
url="http://localhost:3001",
|
|
10
|
+
)
|
|
11
|
+
else:
|
|
12
|
+
parent_dir = os.path.dirname(os.path.abspath(__file__))
|
|
13
|
+
build_dir = os.path.join(parent_dir, "frontend/build")
|
|
14
|
+
_component_func = components.declare_component(
|
|
15
|
+
"st_copy_button", path=build_dir
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def st_copy_button(
|
|
20
|
+
text: str,
|
|
21
|
+
before_copy_label: str = "📋",
|
|
22
|
+
after_copy_label: str = "✅",
|
|
23
|
+
show_text: bool = False,
|
|
24
|
+
key=None
|
|
25
|
+
):
|
|
26
|
+
"""Create a button that copies text to the user's clipboard when clicked.
|
|
27
|
+
|
|
28
|
+
Parameters
|
|
29
|
+
----------
|
|
30
|
+
text: str
|
|
31
|
+
The text to be copied to the clipboard.
|
|
32
|
+
before_copy_label: str
|
|
33
|
+
The button label before copying occurs. Defaults to "📋".
|
|
34
|
+
after_copy_label: str
|
|
35
|
+
The button label after copying occurs. Defaults to "✅".
|
|
36
|
+
show_text: bool
|
|
37
|
+
If True, displays the text to be copied as a second, also clickable
|
|
38
|
+
button, to the left of the first.
|
|
39
|
+
key: str or None
|
|
40
|
+
An optional key that uniquely identifies this component.
|
|
41
|
+
|
|
42
|
+
Returns
|
|
43
|
+
-------
|
|
44
|
+
component_value
|
|
45
|
+
"""
|
|
46
|
+
component_value = _component_func(
|
|
47
|
+
text=text,
|
|
48
|
+
before_copy_label=before_copy_label,
|
|
49
|
+
after_copy_label=after_copy_label,
|
|
50
|
+
show_text=show_text,
|
|
51
|
+
key=key,
|
|
52
|
+
)
|
|
53
|
+
return component_value
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import streamlit as st
|
|
2
|
+
from st_copy_button import st_copy_button
|
|
3
|
+
|
|
4
|
+
st.subheader("Copy to Clipboard Component Demo")
|
|
5
|
+
|
|
6
|
+
# Basic Example
|
|
7
|
+
st.write("### Basic Example")
|
|
8
|
+
text = st.text_input("Enter text to copy", value="Hello World")
|
|
9
|
+
copied = st_copy_button(text, key="basic")
|
|
10
|
+
if copied is None: # Convert None to False initially
|
|
11
|
+
copied = False
|
|
12
|
+
st.write(f"Text copied: {copied}")
|
|
13
|
+
|
|
14
|
+
# Custom Labels
|
|
15
|
+
st.write("### Custom Labels")
|
|
16
|
+
copied_custom = st_copy_button(
|
|
17
|
+
text,
|
|
18
|
+
before_copy_label="📋 Push to copy",
|
|
19
|
+
after_copy_label="✅ Text copied!",
|
|
20
|
+
key="custom"
|
|
21
|
+
)
|
|
22
|
+
if copied_custom is None:
|
|
23
|
+
copied_custom = False
|
|
24
|
+
st.write(f"Text copied: {copied_custom}")
|
|
25
|
+
|
|
26
|
+
# With Visible Text
|
|
27
|
+
st.write("### With Visible Text")
|
|
28
|
+
copied_visible = st_copy_button(
|
|
29
|
+
text,
|
|
30
|
+
show_text=True,
|
|
31
|
+
key="visible"
|
|
32
|
+
)
|
|
33
|
+
if copied_visible is None:
|
|
34
|
+
copied_visible = False
|
|
35
|
+
st.write(f"Text copied: {copied_visible}")
|