Skip to content

Commit c2e956b

Browse files
committed
Add copy to clipboard functionality + refinements
1 parent ea1a824 commit c2e956b

File tree

5 files changed

+51
-22
lines changed

5 files changed

+51
-22
lines changed

components/ContextMenu/ContextMenu.js

+17-14
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,23 @@ import { styled } from "stitches.config";
22
import { keyframes } from "@stitches/react";
33
import * as ContextMenu from "@radix-ui/react-context-menu";
44

5-
export default ({ children }) => (
6-
<ContextMenu.Root>
7-
<ContextMenu.Trigger>{children}</ContextMenu.Trigger>
8-
<Content>
9-
<Item onSelect={() => console.log("cut")}>CSS</Item>
10-
<Item onSelect={() => console.log("cut")}>SCSS</Item>
11-
<Item onSelect={() => console.log("copy")}>Stitches</Item>
12-
<Item onSelect={() => console.log("paste")}>Styled Components</Item>
13-
<Separator />
14-
<Item onSelect={() => console.log("paste")}>JSX</Item>
15-
<Item onSelect={() => console.log("paste")}>HTML</Item>
16-
</Content>
17-
</ContextMenu.Root>
18-
);
5+
export default ({ children, stitchesStyling }) => {
6+
const copyToClipboard = async (value) => {
7+
await navigator.clipboard.writeText(location.href);
8+
console.log("Page URL copied to clipboard");
9+
};
10+
return (
11+
<ContextMenu.Root>
12+
<ContextMenu.Trigger>{children}</ContextMenu.Trigger>
13+
<Content>
14+
<Item onSelect={() => copyToClipboard(stitchesStyling)}>CSS</Item>
15+
<Item onSelect={() => console.log("cut")}>SCSS</Item>
16+
<Item onSelect={() => console.log("copy")}>Stitches</Item>
17+
<Item onSelect={() => console.log("paste")}>Styled Components</Item>
18+
</Content>
19+
</ContextMenu.Root>
20+
);
21+
};
1922

2023
const reveal = keyframes({
2124
"0%": { transform: "scale(0.9)", opacity: 0 },

components/Grid/Grid.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@ import { styled } from "stitches.config";
55
import snippets from "@components/Snippets";
66

77
const Grid = ({ children }) => {
8+
console.log(snippets);
89
return (
910
<Wrapper>
10-
{snippets.map((Snippet) => (
11-
<GridItem>
12-
<Snippet>Hover me</Snippet>
11+
{snippets.map(({ component: Component, stitches }) => (
12+
<GridItem stitchesStyling={stitches}>
13+
<Component />
1314
</GridItem>
1415
))}
1516
</Wrapper>

components/Grid/components/GridItem.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ import { styled } from "stitches.config";
22

33
import ContextMenu from "@components/ContextMenu";
44

5-
const GridItem = ({ children }) => {
5+
const GridItem = ({ children, stitchesStyling }) => {
66
return (
7-
<ContextMenu>
7+
<ContextMenu stitchesStyling={stitchesStyling}>
88
<Wrapper>{children}</Wrapper>
99
</ContextMenu>
1010
);

components/Snippets/UnderlineLeftRight.js

+26-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ const UnderlineLeftRight = () => {
44
return <Wrapper>Hover me</Wrapper>;
55
};
66

7+
export default UnderlineLeftRight;
8+
79
const Wrapper = styled("a", {
810
display: "inline-block",
911
position: "relative",
@@ -28,4 +30,27 @@ const Wrapper = styled("a", {
2830
},
2931
});
3032

31-
export default UnderlineLeftRight;
33+
export const stitchesStyling = `
34+
const Wrapper = styled("a", {
35+
display: "inline-block",
36+
position: "relative",
37+
cursor: "pointer",
38+
39+
"&:after": {
40+
content: "",
41+
position: "absolute",
42+
width: "100%",
43+
transform: "scaleX(0)",
44+
height: "1px",
45+
top: "110%",
46+
left: "0",
47+
backgroundColor: "hsl(193, 95%, 71%)",
48+
transformOrigin: "bottom right",
49+
transition: "transform .4s cubic-bezier(.86,0,.07,1)",
50+
},
51+
52+
"&:hover::after": {
53+
transform: "scaleX(1)",
54+
transformOrigin: "bottom left",
55+
},
56+
});`;

components/Snippets/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import UnderlineLeftRight from "./UnderlineLeftRight";
1+
import UnderlineLeftRight, { stitchesStyling } from "./UnderlineLeftRight";
22

3-
const allSnippets = [UnderlineLeftRight];
3+
const allSnippets = [{ component: UnderlineLeftRight, stitches: stitchesStyling }];
44

55
export default allSnippets;

0 commit comments

Comments
 (0)