Py.Cafe

dash.mantine.components/

dmc-custom-copybutton-textarea

Demo of CustomCopyButton in Textarea

DocsPricing
  • assets/
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import dash_mantine_components as dmc
from dash import Dash, Input, Output
from dash_iconify import DashIconify  # Required for chatCopyIcon

app = Dash()

app.layout = dmc.MantineProvider([         
            
    dmc.Title("Demo of CustomCopyButton in a Textarea", order=3),
    dmc.Paper(
        [
            dmc.Box(
                [                    
                    dmc.Textarea(
                        id="chat-textarea",
                        value="This could be a chat message or generated text.",
                        autosize=True,
                        minRows=4,
                        variant="unstyled",
                    ),
                    dmc.CustomCopyButton(
                        value="",
                        children={"function": "chatCopyIcon"},
                        id="copy-icon"
                    ),
                ],
                style={"position": "relative"},
            )
        ],
        shadow="lg",
        radius="xl",
        m="xl",
        p="sm",
        withBorder=True,
        style={
            "position": "relative",
            "maxWidth": 600,
        },
    )
])


@app.callback(
    Output("copy-icon", "value"),
    Input("chat-textarea", "value"),
)
def update(v):
    return v

if __name__ == "__main__":
    app.run(debug=True)