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.
@@ -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}")
@@ -0,0 +1,6 @@
1
+ # Run the component's dev server on :3001
2
+ # (The Streamlit dev server already runs on :3000)
3
+ PORT=3001
4
+
5
+ # Don't automatically open the web browser on `npm run start`.
6
+ BROWSER=none
@@ -0,0 +1,5 @@
1
+ {
2
+ "endOfLine": "lf",
3
+ "semi": false,
4
+ "trailingComma": "es5"
5
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "files": {
3
+ "main.js": "./static/js/main.105053e0.js",
4
+ "index.html": "./index.html",
5
+ "main.105053e0.js.map": "./static/js/main.105053e0.js.map"
6
+ },
7
+ "entrypoints": [
8
+ "static/js/main.105053e0.js"
9
+ ]
10
+ }