|
| 1 | +import reflex as rx |
| 2 | +from typing import Any, Literal, Optional, Union |
| 3 | + |
| 4 | + |
| 5 | +lib_deps: list = ["@heroui/theme", "@heroui/system", "framer-motion"] |
| 6 | + |
| 7 | + |
| 8 | +# Type aliases for component props |
| 9 | +TooltipProps = dict[str, Any] |
| 10 | +"""Type for tooltip component properties.""" |
| 11 | + |
| 12 | +ButtonProps = dict[str, Any] |
| 13 | +"""Type for button component properties.""" |
| 14 | + |
| 15 | + |
| 16 | +class Snippet(rx.Component): |
| 17 | + """A code snippet component with copy functionality and customizable appearance. |
| 18 | +
|
| 19 | + Attributes: |
| 20 | + library: The library the component belongs to. |
| 21 | + lib_dependencies: Dependencies required by the component. |
| 22 | + tag: The tag name for the component. |
| 23 | + size: The size of the snippet component. |
| 24 | + radius: The border radius of the snippet. |
| 25 | + symbol: The symbol to display before the code (string or ReactNode). |
| 26 | + timeout: The timeout duration for copy feedback in milliseconds. |
| 27 | + code_string: The code string to be copied to clipboard. |
| 28 | + tooltip_props: Additional props for the tooltip component. |
| 29 | + copy_icon: Custom icon for the copy button. |
| 30 | + check_icon: Custom icon shown after successful copy. |
| 31 | + disable_tooltip: Whether to disable the tooltip. |
| 32 | + disable_copy: Whether to disable copy functionality. |
| 33 | + hide_copy_button: Whether to hide the copy button. |
| 34 | + hide_symbol: Whether to hide the symbol. |
| 35 | + copy_button_props: Additional props for the copy button. |
| 36 | + disable_animation: Whether to disable animations. |
| 37 | + """ |
| 38 | + |
| 39 | + library = "@heroui/snippet" |
| 40 | + lib_dependencies: list = lib_deps |
| 41 | + tag = "Snippet" |
| 42 | + |
| 43 | + # Props |
| 44 | + size: rx.Var[Literal["sm", "md", "lg"]] = "md" |
| 45 | + radius: rx.Var[Literal["none", "sm", "md", "lg"]] = "lg" |
| 46 | + symbol: rx.Var[Union[str, Any]] = "$" |
| 47 | + timeout: rx.Var[int] = 2000 |
| 48 | + code_string: rx.Var[Optional[str]] |
| 49 | + tooltip_props: rx.Var[Optional[TooltipProps]] |
| 50 | + copy_icon: rx.Var[Optional[Any]] |
| 51 | + check_icon: rx.Var[Optional[Any]] |
| 52 | + disable_tooltip: rx.Var[bool] = False |
| 53 | + disable_copy: rx.Var[bool] = False |
| 54 | + hide_copy_button: rx.Var[bool] = False |
| 55 | + hide_symbol: rx.Var[bool] = False |
| 56 | + copy_button_props: rx.Var[Optional[ButtonProps]] |
| 57 | + disable_animation: rx.Var[bool] = False |
| 58 | + |
| 59 | + # Events |
| 60 | + on_copy: rx.EventHandler[lambda e: [e]] |
0 commit comments