@@ -12,80 +12,57 @@ import {
12
12
Trigger ,
13
13
TriggerItem ,
14
14
} from '@radix-ui/react-context-menu'
15
- import React , { ComponentProps , ElementRef , FC , forwardRef } from 'react'
16
- import type { CSSProps } from '../../stitches.config'
15
+ import React , { ComponentProps , ElementRef , forwardRef } from 'react'
16
+ import type { CSSProps , VariantProps } from '../../stitches.config'
17
17
import { styled } from '../../stitches.config'
18
- import { Check , ChevronRight } from '../Icons'
19
-
20
- const StyledContent = styled ( Content , {
21
- minWidth : '$10' ,
22
- backgroundColor : '$background' ,
23
- borderRadius : '$default' ,
24
- padding : '$1' ,
25
- boxShadow : '$1' ,
26
- } )
27
-
28
- const itemStyles = {
29
- fontSize : '$-1' ,
30
- padding : '$1 $3' ,
31
- borderRadius : '$default' ,
32
- cursor : 'default' ,
33
- transition : 'all 50ms' ,
34
- display : 'flex' ,
35
- alignItems : 'center' ,
36
- justifyContent : 'space-between' ,
37
-
38
- '&:focus' : {
39
- outline : 'none' ,
40
- backgroundColor : '$selection' ,
41
- color : '$text' ,
42
- } ,
43
-
44
- '&[data-disabled]' : {
45
- color : '$grey9' ,
46
- } ,
47
- }
48
-
49
- const StyledItem = styled ( Item , itemStyles )
18
+ import {
19
+ checkboxItemStyles ,
20
+ contentStyles ,
21
+ groupStyles ,
22
+ itemIndicatorStyles ,
23
+ itemShortcutStyles ,
24
+ itemStyles ,
25
+ labelStyles ,
26
+ separatorStyles ,
27
+ StyledCheckIndicator ,
28
+ StyledTriggerItemIndicator ,
29
+ triggerItemStyles ,
30
+ } from '../../utils/menuStyles'
31
+ import { paperStyles } from '../Paper'
50
32
51
- const StyledSeparator = styled ( Separator , {
52
- height : 1 ,
53
- backgroundColor : '$grey8' ,
33
+ /**
34
+ * ContextMenu component
35
+ *
36
+ * Displays a pop up menu when right clicking the `ContextMenuTrigger`.
37
+ *
38
+ * The content should be wrapped in a `ContextMenuContent` and should be made up of the other `ContextMenuXxxx` components.
39
+ *
40
+ * Based on [Radix Context Menu](https://radix-ui.com/primitives/docs/components/context-menu).
41
+ */
42
+ export const ContextMenu = Root
43
+ export const ContextMenuTrigger = Trigger
44
+ export const ContextMenuItem = styled ( Item , itemStyles )
45
+ export const ContextMenuItemShortcut = styled ( 'span' , itemShortcutStyles )
46
+ export const ContextMenuSeparator = styled ( Separator , separatorStyles )
47
+ export const ContextMenuLabel = styled ( Label , labelStyles )
48
+ export const ContextMenuItemGroup = styled ( Group , groupStyles ( ContextMenuItem ) )
49
+ export const ContextMenuRadioGroup = RadioGroup
54
50
55
- variants : {
56
- orientation : {
57
- horizontal : {
58
- height : 1 ,
59
- margin : '$1 0' ,
60
- } ,
61
- vertical : {
62
- width : 1 ,
63
- height : 'auto' ,
64
- margin : '0 $1' ,
65
- flex : '1 1 100%' ,
66
- } ,
67
- } ,
68
- } ,
69
- defaultVariants : {
70
- orientation : 'horizontal' ,
71
- } ,
72
- } )
51
+ export const ContextMenuContent = styled ( Content , paperStyles , contentStyles )
73
52
74
- const StyledLabel = styled ( Label , {
75
- color : '$grey10' ,
76
- fontSize : '$-1' ,
77
- padding : '$1 $3' ,
78
- cursor : 'default' ,
79
- } )
53
+ const StyledItemIndicator = styled ( ItemIndicator , itemIndicatorStyles )
54
+ const StyledCheckboxItem = styled ( CheckboxItem , itemStyles , checkboxItemStyles )
55
+ const StyledRadioItem = styled ( RadioItem , itemStyles , checkboxItemStyles )
80
56
81
- const StyledContextMenuTriggerItem = styled ( TriggerItem , {
82
- ...itemStyles ,
83
- '&[data-state="open"]' : {
84
- background : '$selection' ,
85
- } ,
86
- } )
57
+ const StyledContextMenuTriggerItem = styled (
58
+ TriggerItem ,
59
+ itemStyles ,
60
+ triggerItemStyles
61
+ )
87
62
88
- type ContextMenuTriggerItemProps = ComponentProps < typeof TriggerItem > & CSSProps
63
+ type ContextMenuTriggerItemProps = ComponentProps <
64
+ typeof StyledContextMenuTriggerItem
65
+ >
89
66
90
67
export const ContextMenuTriggerItem = forwardRef <
91
68
ElementRef < typeof StyledContextMenuTriggerItem > ,
@@ -94,93 +71,47 @@ export const ContextMenuTriggerItem = forwardRef<
94
71
return (
95
72
< StyledContextMenuTriggerItem { ...props } ref = { forwardedRef } >
96
73
{ children }
97
- < ChevronRight css = { { size : '$4' } } />
74
+ < StyledTriggerItemIndicator />
98
75
</ StyledContextMenuTriggerItem >
99
76
)
100
77
} )
101
78
ContextMenuTriggerItem . toString = ( ) =>
102
79
`.${ StyledContextMenuTriggerItem . className } `
103
80
104
- export const ContextMenuItemGroup = styled ( Group , {
105
- display : 'flex' ,
106
- marginLeft : '$3' ,
107
- marginRight : '$1' ,
108
-
109
- [ `& ${ StyledItem } ` ] : {
110
- paddingLeft : '$2' ,
111
- } ,
112
- } )
113
-
114
- export const ContextMenuItemShortcut = styled ( 'span' , {
115
- fontFamily : '$monospace' ,
116
- lineHeight : '$body' ,
117
- color : '$textSecondary' ,
118
- marginLeft : '$3' ,
119
- } )
120
-
121
- /**
122
- * The `ContextMenu` displays a pop up menu when right clicking the `ContextMenuTrigger`.
123
- */
124
- export const ContextMenu = Root
125
- export const ContextMenuTrigger = Trigger
126
- export const ContextMenuItem : FC < ComponentProps < typeof Item > > = StyledItem
127
- export const ContextMenuContent : FC <
128
- ComponentProps < typeof Content >
129
- > = StyledContent
130
- export const ContextMenuSeparator : FC <
131
- ComponentProps < typeof StyledSeparator >
132
- > = StyledSeparator
133
- export const ContextMenuLabel : FC < ComponentProps < typeof Label > > = StyledLabel
134
-
135
- const StyledItemIndicator = styled ( ItemIndicator , {
136
- position : 'absolute' ,
137
- left : '$2' ,
138
- } )
139
-
140
- const StyledContextMenuCheckboxItem = styled ( CheckboxItem , {
141
- ...itemStyles ,
142
- padding : '$1 $2 $1 $5' ,
143
- } )
144
-
145
81
type ContextMenuCheckboxItemProps = ComponentProps < typeof CheckboxItem > &
146
82
CSSProps
147
83
148
84
export const ContextMenuCheckboxItem = forwardRef <
149
- ElementRef < typeof StyledContextMenuCheckboxItem > ,
85
+ ElementRef < typeof StyledCheckboxItem > ,
150
86
ContextMenuCheckboxItemProps
151
87
> ( ( { children, ...props } , forwardedRef ) => {
152
88
return (
153
- < StyledContextMenuCheckboxItem { ...props } ref = { forwardedRef } >
89
+ < StyledCheckboxItem { ...props } ref = { forwardedRef } >
154
90
< StyledItemIndicator >
155
- < Check css = { { height : 16 , width : 16 } } />
91
+ < StyledCheckIndicator />
156
92
</ StyledItemIndicator >
157
93
{ children }
158
- </ StyledContextMenuCheckboxItem >
94
+ </ StyledCheckboxItem >
159
95
)
160
96
} )
161
- ContextMenuCheckboxItem . toString = ( ) =>
162
- `.${ StyledContextMenuCheckboxItem . className } `
163
-
164
- const StyledContextMenuRadioItem = styled ( RadioItem , {
165
- ...itemStyles ,
166
- padding : '$1 $2 $1 $5' ,
167
- } )
97
+ ContextMenuCheckboxItem . toString = ( ) => `.${ StyledCheckboxItem . className } `
168
98
169
- type ContextMenuRadioItemProps = ComponentProps < typeof RadioItem > & CSSProps
99
+ type RadioItemVariants = VariantProps < typeof StyledRadioItem >
100
+ type ContextMenuRadioItemProps = ComponentProps < typeof RadioItem > &
101
+ RadioItemVariants &
102
+ CSSProps
170
103
171
104
export const ContextMenuRadioItem = forwardRef <
172
- ElementRef < typeof StyledContextMenuRadioItem > ,
105
+ ElementRef < typeof StyledRadioItem > ,
173
106
ContextMenuRadioItemProps
174
107
> ( ( { children, ...props } , forwardedRef ) => {
175
108
return (
176
- < StyledContextMenuRadioItem { ...props } ref = { forwardedRef } >
109
+ < StyledRadioItem { ...props } ref = { forwardedRef } >
177
110
< StyledItemIndicator >
178
- < Check css = { { height : 16 , width : 16 } } />
111
+ < StyledCheckIndicator />
179
112
</ StyledItemIndicator >
180
113
{ children }
181
- </ StyledContextMenuRadioItem >
114
+ </ StyledRadioItem >
182
115
)
183
116
} )
184
- ContextMenuRadioItem . toString = ( ) => `.${ StyledContextMenuRadioItem . className } `
185
-
186
- export const ContextMenuRadioGroup = RadioGroup
117
+ ContextMenuRadioItem . toString = ( ) => `.${ StyledRadioItem . className } `
0 commit comments