|
1 | 1 | import { useEffect, useState } from "react";
|
2 |
| -import { A, Div, Strong } from "@cloudflare/elements"; |
| 2 | +import { A, Div, Form, Span, Strong } from "@cloudflare/elements"; |
3 | 3 | import { createComponent } from "@cloudflare/style-container";
|
4 | 4 | import { Button } from "@cloudflare/component-button";
|
5 | 5 | import { Icon } from "@cloudflare/component-icon";
|
@@ -64,68 +64,86 @@ export function TopBar() {
|
64 | 64 | }
|
65 | 65 | }, [hasCopied]);
|
66 | 66 | return (
|
67 |
| - <> |
68 |
| - <Wrapper> |
69 |
| - <A href="/" color="inherit"> |
70 |
| - <WorkersLogo /> |
71 |
| - </A> |
72 |
| - <A target="_blank" href="/playground"> |
73 |
| - <Button ml={2} type="primary" inverted={true}> |
74 |
| - <Icon label="Add" type="plus" mr={1} /> |
75 |
| - New |
76 |
| - </Button> |
77 |
| - </A> |
78 |
| - <Div ml="auto" mr="auto" display="flex" gap={1} alignItems="center"> |
79 |
| - {isEditing ? ( |
80 |
| - <Input |
81 |
| - name="path" |
82 |
| - value={value} |
83 |
| - autoComplete="off" |
84 |
| - spellCheck={false} |
85 |
| - onChange={(e) => setValue(e.target.value)} |
86 |
| - mb={0} |
87 |
| - /> |
88 |
| - ) : ( |
89 |
| - <Strong>{value}</Strong> |
90 |
| - )} |
91 |
| - <Button |
92 |
| - type="plain" |
93 |
| - p={2} |
94 |
| - ml={1} |
95 |
| - onClick={() => { |
96 |
| - if (isEditing) { |
97 |
| - persistValue(); |
98 |
| - } |
99 |
| - setIsEditing(!isEditing); |
100 |
| - }} |
101 |
| - > |
102 |
| - <Icon type={isEditing ? "ok" : "edit"} /> |
103 |
| - </Button> |
104 |
| - </Div> |
| 67 | + <Wrapper> |
| 68 | + <A href="/" color="inherit"> |
| 69 | + <WorkersLogo /> |
| 70 | + </A> |
| 71 | + <A target="_blank" href="/playground"> |
| 72 | + <Button ml={2} type="primary" inverted={true}> |
| 73 | + <Icon label="Add" type="plus" mr={1} /> |
| 74 | + New |
| 75 | + </Button> |
| 76 | + </A> |
| 77 | + <Form |
| 78 | + ml="auto" |
| 79 | + mr="auto" |
| 80 | + display="flex" |
| 81 | + gap={1} |
| 82 | + alignItems="center" |
| 83 | + onSubmit={(e) => { |
| 84 | + e.preventDefault(); |
| 85 | + if (isEditing) { |
| 86 | + persistValue(); |
| 87 | + } |
| 88 | + }} |
| 89 | + > |
| 90 | + {isEditing ? ( |
| 91 | + <Input |
| 92 | + name="path" |
| 93 | + value={value} |
| 94 | + autoComplete="off" |
| 95 | + spellCheck={false} |
| 96 | + onChange={(e) => setValue(e.target.value)} |
| 97 | + mb={0} |
| 98 | + /> |
| 99 | + ) : ( |
| 100 | + <Strong>{value}</Strong> |
| 101 | + )} |
105 | 102 | <Button
|
106 |
| - type="primary" |
107 |
| - inverted={true} |
| 103 | + type="plain" |
| 104 | + p={2} |
| 105 | + ml={1} |
| 106 | + submit={isEditing} |
108 | 107 | onClick={() => {
|
109 |
| - void navigator.clipboard.writeText(location.href); |
110 |
| - setHasCopied(!hasCopied); |
| 108 | + setIsEditing(!isEditing); |
111 | 109 | }}
|
112 | 110 | >
|
113 |
| - <Icon label="Add" type="link" mr={1} /> |
114 |
| - Copy Link |
| 111 | + <Icon type={isEditing ? "ok" : "edit"} /> |
115 | 112 | </Button>
|
116 |
| - <A |
117 |
| - target="_blank" |
118 |
| - href={`https://dash.cloudflare.com/workers-and-pages/deploy/playground/${value}${location.hash}`} |
119 |
| - > |
120 |
| - <Button type="primary">Deploy</Button> |
121 |
| - </A> |
122 |
| - </Wrapper> |
| 113 | + </Form> |
123 | 114 | {hasCopied && (
|
124 |
| - <AnimatedToast type="success"> |
125 |
| - <Icon type="ok-sign"></Icon> |
126 |
| - Copied Playground link to clipboard |
127 |
| - </AnimatedToast> |
| 115 | + <Div position="relative"> |
| 116 | + <Span |
| 117 | + height="100%" |
| 118 | + display="flex" |
| 119 | + gap={1} |
| 120 | + alignItems="center" |
| 121 | + mr={2} |
| 122 | + position={"absolute"} |
| 123 | + right={0} |
| 124 | + > |
| 125 | + <Icon type="ok" color={"green"} size={20}></Icon> |
| 126 | + Copied! |
| 127 | + </Span> |
| 128 | + </Div> |
128 | 129 | )}
|
129 |
| - </> |
| 130 | + <Button |
| 131 | + type="primary" |
| 132 | + inverted={true} |
| 133 | + onClick={() => { |
| 134 | + void navigator.clipboard.writeText(location.href); |
| 135 | + setHasCopied(!hasCopied); |
| 136 | + }} |
| 137 | + > |
| 138 | + <Icon label="Add" type="link" mr={1} /> |
| 139 | + Copy Link |
| 140 | + </Button> |
| 141 | + <A |
| 142 | + target="_blank" |
| 143 | + href={`https://dash.cloudflare.com/workers-and-pages/deploy/playground/${value}${location.hash}`} |
| 144 | + > |
| 145 | + <Button type="primary">Deploy</Button> |
| 146 | + </A> |
| 147 | + </Wrapper> |
130 | 148 | );
|
131 | 149 | }
|
0 commit comments