@moises.ai/design-system 4.21.23 → 4.22.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import classNames from 'classnames'
|
|
2
2
|
import { DropdownMenu as DropdownMenuRadix } from 'radix-ui'
|
|
3
|
-
import { memo, useCallback, useState } from 'react'
|
|
3
|
+
import { memo, useCallback, useRef, useState } from 'react'
|
|
4
4
|
import { ChevronDownIcon } from '../../icons/ChevronDownIcon'
|
|
5
5
|
import { styles as menuStyles } from '../../lib/menu'
|
|
6
6
|
import { Theme } from '../theme/Theme'
|
|
@@ -23,10 +23,12 @@ export const ToolsDropdown = memo(
|
|
|
23
23
|
showSeparator = true,
|
|
24
24
|
withIconTrigger = true,
|
|
25
25
|
wrapCloseMenu,
|
|
26
|
+
closeOnTriggerClick = true,
|
|
26
27
|
...props
|
|
27
28
|
}) => {
|
|
28
29
|
const isControlled = props.open !== undefined
|
|
29
30
|
const [internalOpen, setInternalOpen] = useState(false)
|
|
31
|
+
const triggerRef = useRef(null)
|
|
30
32
|
|
|
31
33
|
const open = isControlled ? props.open : internalOpen
|
|
32
34
|
const onOpenChange = useCallback(
|
|
@@ -55,6 +57,23 @@ export const ToolsDropdown = memo(
|
|
|
55
57
|
onTriggerClick(event)
|
|
56
58
|
}
|
|
57
59
|
|
|
60
|
+
const keepOpenOnTrigger = open && !closeOnTriggerClick
|
|
61
|
+
|
|
62
|
+
const handleMenuTriggerPointerDown = (event) => {
|
|
63
|
+
if (!keepOpenOnTrigger) return
|
|
64
|
+
event.preventDefault()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const handleMenuTriggerKeyDown = (event) => {
|
|
68
|
+
if (!keepOpenOnTrigger) return
|
|
69
|
+
if (event.key === 'Enter' || event.key === ' ') event.preventDefault()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const handlePointerDownOutside = (event) => {
|
|
73
|
+
if (closeOnTriggerClick) return
|
|
74
|
+
if (triggerRef.current?.contains(event.target)) event.preventDefault()
|
|
75
|
+
}
|
|
76
|
+
|
|
58
77
|
const handlePanelKeyDown = useCallback((event) => {
|
|
59
78
|
if (event.key === 'Tab') {
|
|
60
79
|
event.stopPropagation()
|
|
@@ -89,6 +108,7 @@ export const ToolsDropdown = memo(
|
|
|
89
108
|
sideOffset={sideOffset}
|
|
90
109
|
alignOffset={0}
|
|
91
110
|
onOpenAutoFocus={handleOpenAutoFocus}
|
|
111
|
+
onPointerDownOutside={handlePointerDownOutside}
|
|
92
112
|
onCloseAutoFocus={(event) => {
|
|
93
113
|
event.preventDefault()
|
|
94
114
|
}}
|
|
@@ -123,8 +143,12 @@ export const ToolsDropdown = memo(
|
|
|
123
143
|
)}
|
|
124
144
|
|
|
125
145
|
<DropdownMenuRadix.Trigger
|
|
146
|
+
ref={triggerRef}
|
|
126
147
|
disabled={disabled}
|
|
127
148
|
className={classNames(styles.menuTrigger)}
|
|
149
|
+
style={keepOpenOnTrigger ? { pointerEvents: 'auto' } : undefined}
|
|
150
|
+
onPointerDown={handleMenuTriggerPointerDown}
|
|
151
|
+
onKeyDown={handleMenuTriggerKeyDown}
|
|
128
152
|
>
|
|
129
153
|
{!onTriggerClick && (
|
|
130
154
|
<Flex className={styles.triggerWithoutClick}>
|
|
@@ -132,7 +156,7 @@ export const ToolsDropdown = memo(
|
|
|
132
156
|
</Flex>
|
|
133
157
|
)}
|
|
134
158
|
|
|
135
|
-
{showSeparator && <Separator orientation="vertical" className={styles.separator} size="2"/>}
|
|
159
|
+
{showSeparator && <Separator orientation="vertical" className={styles.separator} size="2" />}
|
|
136
160
|
|
|
137
161
|
<ChevronDownIcon
|
|
138
162
|
width={14.4}
|
|
@@ -16,6 +16,7 @@ ToolsDropdown combines a tool action trigger with a dropdown menu built on Radix
|
|
|
16
16
|
- Pass \`onTriggerClick\` to run a primary action without opening the menu. The chevron opens the menu.
|
|
17
17
|
- Omit \`onTriggerClick\` to open the menu from the full trigger.
|
|
18
18
|
- Use \`children\` or \`children(closeMenu)\` for custom panel content.
|
|
19
|
+
- Set \`closeOnTriggerClick\` to \`false\` to keep the menu open when the trigger is clicked again.
|
|
19
20
|
`,
|
|
20
21
|
},
|
|
21
22
|
},
|
|
@@ -34,6 +35,11 @@ ToolsDropdown combines a tool action trigger with a dropdown menu built on Radix
|
|
|
34
35
|
control: 'boolean',
|
|
35
36
|
table: { type: { summary: 'boolean' }, defaultValue: { summary: true } },
|
|
36
37
|
},
|
|
38
|
+
closeOnTriggerClick: {
|
|
39
|
+
control: 'boolean',
|
|
40
|
+
description: 'Closes the menu when the trigger is clicked while it is already open',
|
|
41
|
+
table: { type: { summary: 'boolean' }, defaultValue: { summary: true } },
|
|
42
|
+
},
|
|
37
43
|
children: {
|
|
38
44
|
description: 'Dropdown content or render prop receiving closeMenu',
|
|
39
45
|
table: { type: { summary: 'React.ReactNode | (closeMenu) => React.ReactNode' } },
|
|
@@ -138,6 +144,18 @@ export const ControlledOpen = {
|
|
|
138
144
|
},
|
|
139
145
|
}
|
|
140
146
|
|
|
147
|
+
export const KeepOpenOnTriggerClick = {
|
|
148
|
+
args: {
|
|
149
|
+
trigger: <Text>Tools</Text>,
|
|
150
|
+
closeOnTriggerClick: false,
|
|
151
|
+
},
|
|
152
|
+
render: (args) => (
|
|
153
|
+
<ToolsDropdown {...args}>
|
|
154
|
+
<Text size="2">Stays open if the trigger is clicked again</Text>
|
|
155
|
+
</ToolsDropdown>
|
|
156
|
+
),
|
|
157
|
+
}
|
|
158
|
+
|
|
141
159
|
export const WithoutSeparator = {
|
|
142
160
|
args: {
|
|
143
161
|
showSeparator: false,
|