Преглед на файлове

Add copy to clipboard component (#380)

Dong-hyeon Shin преди 2 години
родител
ревизия
526e417e8f
променени са 3 файла, в които са добавени 28 реда и са изтрити 0 реда
  1. 1 0
      pynecone/.templates/web/package.json
  2. 1 0
      pynecone/components/forms/__init__.py
  3. 26 0
      pynecone/components/forms/copytoclipboard.py

+ 1 - 0
pynecone/.templates/web/package.json

@@ -20,6 +20,7 @@
     "plotly.js": "2.6.4",
     "plotly.js": "2.6.4",
     "prettier": "^2.8.1",
     "prettier": "^2.8.1",
     "react": "^17.0.2",
     "react": "^17.0.2",
+    "react-copy-to-clipboard": "^5.1.0",
     "react-dom": "^17.0.2",
     "react-dom": "^17.0.2",
     "react-markdown": "^8.0.3",
     "react-markdown": "^8.0.3",
     "react-plotly.js": "^2.6.0",
     "react-plotly.js": "^2.6.0",

+ 1 - 0
pynecone/components/forms/__init__.py

@@ -2,6 +2,7 @@
 
 
 from .button import Button, ButtonGroup
 from .button import Button, ButtonGroup
 from .checkbox import Checkbox, CheckboxGroup
 from .checkbox import Checkbox, CheckboxGroup
+from .copytoclipboard import CopyToClipboard
 from .editable import Editable, EditableInput, EditablePreview, EditableTextarea
 from .editable import Editable, EditableInput, EditablePreview, EditableTextarea
 from .formcontrol import FormControl, FormErrorMessage, FormHelperText, FormLabel
 from .formcontrol import FormControl, FormErrorMessage, FormHelperText, FormLabel
 from .iconbutton import IconButton
 from .iconbutton import IconButton

+ 26 - 0
pynecone/components/forms/copytoclipboard.py

@@ -0,0 +1,26 @@
+"""A copy to clipboard component."""
+
+from typing import Set
+
+from pynecone.components import Component
+from pynecone.var import Var
+
+
+class CopyToClipboard(Component):
+    """Component to copy text to clipboard."""
+
+    library = "react-copy-to-clipboard"
+
+    tag = "CopyToClipboard"
+
+    # The text to copy when clicked.
+    text: Var[str]
+
+    @classmethod
+    def get_controlled_triggers(cls) -> Set[str]:
+        """Get the event triggers that pass the component's value to the handler.
+
+        Returns:
+            The controlled event triggers.
+        """
+        return {"on_copy"}