|
1 |
| -import { styled, keyframes } from "stitches.config"; |
2 |
| -import { createToast } from "vercel-toast"; |
3 |
| -import * as ContextMenu from "@radix-ui/react-context-menu"; |
| 1 | +import { styled, keyframes } from 'stitches.config'; |
| 2 | +import { createToast } from 'vercel-toast'; |
| 3 | +import * as RadixContextMenu from '@radix-ui/react-context-menu'; |
4 | 4 |
|
5 |
| -export default ({ children, stitchesStyling, cssStyling, scssStyling }) => { |
6 |
| - const copyToClipboard = async (styling) => { |
7 |
| - try { |
8 |
| - await navigator.clipboard.writeText(styling); |
| 5 | +const ContextMenu = ({ children, stitchesStyling, cssStyling, scssStyling }) => { |
| 6 | + const copyToClipboard = async (styling) => { |
| 7 | + try { |
| 8 | + await navigator.clipboard.writeText(styling); |
9 | 9 |
|
10 |
| - createToast("Copied styles to clipboard", { |
11 |
| - timeout: 3000, |
12 |
| - }); |
13 |
| - } catch { |
14 |
| - createToast("Failed to copy", { |
15 |
| - timeout: 3000, |
16 |
| - type: "error", |
17 |
| - }); |
18 |
| - } |
19 |
| - }; |
| 10 | + createToast('Copied styles to clipboard', { |
| 11 | + timeout: 3000 |
| 12 | + }); |
| 13 | + } catch { |
| 14 | + createToast('Failed to copy', { |
| 15 | + timeout: 3000, |
| 16 | + type: 'error' |
| 17 | + }); |
| 18 | + } |
| 19 | + }; |
20 | 20 |
|
21 |
| - return ( |
22 |
| - <ContextMenu.Root> |
23 |
| - <ContextMenu.Trigger>{children}</ContextMenu.Trigger> |
24 |
| - <Content> |
25 |
| - <Item onSelect={() => copyToClipboard(cssStyling)}>CSS</Item> |
26 |
| - <Item onSelect={() => copyToClipboard(scssStyling)}>SCSS</Item> |
27 |
| - <Item onSelect={() => copyToClipboard(stitchesStyling)}>Stitches</Item> |
28 |
| - </Content> |
29 |
| - </ContextMenu.Root> |
30 |
| - ); |
| 21 | + return ( |
| 22 | + <RadixContextMenu.Root> |
| 23 | + <RadixContextMenu.Trigger>{children}</RadixContextMenu.Trigger> |
| 24 | + <Content> |
| 25 | + <Item onSelect={() => copyToClipboard(cssStyling)}>CSS</Item> |
| 26 | + <Item onSelect={() => copyToClipboard(scssStyling)}>SCSS</Item> |
| 27 | + <Item onSelect={() => copyToClipboard(stitchesStyling)}>Stitches</Item> |
| 28 | + </Content> |
| 29 | + </RadixContextMenu.Root> |
| 30 | + ); |
31 | 31 | };
|
32 | 32 |
|
| 33 | +export default ContextMenu; |
| 34 | + |
33 | 35 | const reveal = keyframes({
|
34 |
| - "0%": { transform: "scale(0.9)", opacity: 0 }, |
35 |
| - "100%": { transform: "scale(1)", opacity: 1 }, |
| 36 | + '0%': { transform: 'scale(0.9)', opacity: 0 }, |
| 37 | + '100%': { transform: 'scale(1)', opacity: 1 } |
36 | 38 | });
|
37 | 39 |
|
38 |
| -const Content = styled(ContextMenu.Content, { |
39 |
| - minWidth: 160, |
40 |
| - backgroundColor: "white", |
41 |
| - borderRadius: 6, |
42 |
| - padding: 5, |
43 |
| - boxShadow: "0px 5px 15px -5px hsla(206,22%,7%,.15)", |
44 |
| - transformOrigin: "var(--radix-context-menu-content-transform-origin)", |
45 |
| - animation: `${reveal} 0.1s ease`, |
| 40 | +const Content = styled(RadixContextMenu.Content, { |
| 41 | + minWidth: 160, |
| 42 | + backgroundColor: 'white', |
| 43 | + borderRadius: 6, |
| 44 | + padding: 5, |
| 45 | + boxShadow: '0px 5px 15px -5px hsla(206,22%,7%,.15)', |
| 46 | + transformOrigin: 'var(--radix-context-menu-content-transform-origin)', |
| 47 | + animation: `${reveal} 0.1s ease` |
46 | 48 | });
|
47 | 49 |
|
48 |
| -const Separator = styled(ContextMenu.Separator, { |
49 |
| - height: 1, |
50 |
| - background: "hsl(208, 18%, 92%)", |
51 |
| - margin: 4, |
| 50 | +const Separator = styled(RadixContextMenu.Separator, { |
| 51 | + height: 1, |
| 52 | + background: 'hsl(208, 18%, 92%)', |
| 53 | + margin: 4 |
52 | 54 | });
|
53 | 55 |
|
54 |
| -const Wrapper = styled(ContextMenu.Root, { |
55 |
| - minWidth: 160, |
56 |
| - background: "$white", |
57 |
| - borderRadius: "$1", |
58 |
| - padding: 4, |
| 56 | +const Wrapper = styled(RadixContextMenu.Root, { |
| 57 | + minWidth: 160, |
| 58 | + background: '$white', |
| 59 | + borderRadius: '$1', |
| 60 | + padding: 4 |
59 | 61 | });
|
60 | 62 |
|
61 |
| -const Item = styled(ContextMenu.Item, { |
62 |
| - fontSize: 13, |
63 |
| - padding: "5px 10px", |
64 |
| - borderRadius: "$1", |
65 |
| - cursor: "default", |
66 |
| - height: 28, |
67 |
| - padding: "4px 8px", |
68 |
| - color: "$gray", |
| 63 | +const Item = styled(RadixContextMenu.Item, { |
| 64 | + fontSize: 13, |
| 65 | + padding: '5px 10px', |
| 66 | + borderRadius: '$1', |
| 67 | + cursor: 'default', |
| 68 | + height: 28, |
| 69 | + padding: '4px 8px', |
| 70 | + color: '$gray', |
69 | 71 |
|
70 |
| - "&:focus": { |
71 |
| - outline: "none", |
72 |
| - backgroundColor: "hsl(207, 11%, 96%)", |
73 |
| - color: "$darkGray", |
74 |
| - }, |
| 72 | + '&:focus': { |
| 73 | + outline: 'none', |
| 74 | + backgroundColor: 'hsl(207, 11%, 96%)', |
| 75 | + color: '$darkGray' |
| 76 | + } |
75 | 77 | });
|
0 commit comments