Skip to content

Commit 31e3a93

Browse files
committed
Add ContextMenu component
1 parent d14cce3 commit 31e3a93

File tree

10 files changed

+424
-9
lines changed

10 files changed

+424
-9
lines changed

components/ContextMenu/ContextMenu.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { styled } from "stitches.config";
2+
import { keyframes } from "@stitches/react";
3+
import * as ContextMenu from "@radix-ui/react-context-menu";
4+
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+
);
19+
20+
const reveal = keyframes({
21+
"0%": { transform: "scale(0.9)", opacity: 0 },
22+
"100%": { transform: "scale(1)", opacity: 1 },
23+
});
24+
25+
const Content = styled(ContextMenu.Content, {
26+
minWidth: 160,
27+
backgroundColor: "white",
28+
borderRadius: 6,
29+
padding: 5,
30+
boxShadow: "0px 5px 15px -5px hsla(206,22%,7%,.15)",
31+
transformOrigin: "var(--radix-context-menu-content-transform-origin)",
32+
animation: `${reveal} 0.1s ease`,
33+
});
34+
35+
const Separator = styled(ContextMenu.Separator, {
36+
height: 1,
37+
background: "hsl(208, 18%, 92%)",
38+
margin: 4,
39+
});
40+
41+
const Wrapper = styled(ContextMenu.Root, {
42+
minWidth: 160,
43+
background: "$white",
44+
borderRadius: "$1",
45+
padding: 4,
46+
});
47+
48+
const Item = styled(ContextMenu.Item, {
49+
fontSize: 13,
50+
padding: "5px 10px",
51+
borderRadius: "$1",
52+
cursor: "default",
53+
height: 28,
54+
padding: "4px 8px",
55+
color: "$gray",
56+
57+
"&:focus": {
58+
outline: "none",
59+
backgroundColor: "hsl(207, 11%, 96%)",
60+
color: "$darkGray",
61+
},
62+
});

components/ContextMenu/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from "./ContextMenu";

components/Grid/Grid.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
import GridItem from "./components/GridItem";
33

44
import { styled } from "stitches.config";
5-
import UnderlineLeftRight from "@styles/underlineLeftRight";
5+
import snippets from "@components/Snippets";
66

77
const Grid = ({ children }) => {
88
return (
99
<Wrapper>
10-
<GridItem>
11-
<UnderlineLeftRight>Hover me</UnderlineLeftRight>
12-
</GridItem>
10+
{snippets.map((Snippet) => (
11+
<GridItem>
12+
<Snippet>Hover me</Snippet>
13+
</GridItem>
14+
))}
1315
</Wrapper>
1416
);
1517
};

components/Grid/components/GridItem.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
import { styled } from "stitches.config";
22

3+
import ContextMenu from "@components/ContextMenu";
4+
35
const GridItem = ({ children }) => {
4-
return <Wrapper>{children}</Wrapper>;
6+
return (
7+
<ContextMenu>
8+
<Wrapper>{children}</Wrapper>
9+
</ContextMenu>
10+
);
511
};
612

713
const Wrapper = styled("div", {
8-
height: "120px",
14+
height: 120,
915
backgroundColor: "$darkGray",
10-
borderRadius: "$1",
16+
borderRadius: "$2",
1117
display: "flex",
1218
justifyContent: "center",
1319
alignItems: "center",

styles/underlineLeftRight.js renamed to components/Snippets/UnderlineLeftRight.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { styled } from "stitches.config.js";
22

3-
const UnderlineLeftRight = styled("a", {
3+
const UnderlineLeftRight = () => {
4+
return <Wrapper>Hover me</Wrapper>;
5+
};
6+
7+
const Wrapper = styled("a", {
48
display: "inline-block",
59
position: "relative",
610
cursor: "pointer",

components/Snippets/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import UnderlineLeftRight from "./UnderlineLeftRight";
2+
3+
const allSnippets = [UnderlineLeftRight];
4+
5+
export default allSnippets;

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"start": "next start"
99
},
1010
"dependencies": {
11+
"@radix-ui/react-context-menu": "^0.0.19",
1112
"@stitches/react": "^0.2.0-canary.5",
1213
"next": "10.2.3",
1314
"react": "17.0.2",

pages/_app.js

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { globalStyles } from "@styles/global";
2+
import "@styles/animations.css";
23

34
import Header from "@components/Header";
45

stitches.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const { styled, getCssString, global } = createCss({
2727
},
2828
radii: {
2929
1: "7px",
30+
2: "7px",
3031
},
3132
},
3233
});

0 commit comments

Comments
 (0)