@moises.ai/design-system 4.21.23 → 4.22.1
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/dist/index.js +2078 -2043
- package/package.json +1 -1
- package/src/components/ToolsDropdown/ToolsDropdown.jsx +26 -2
- package/src/components/ToolsDropdown/ToolsDropdown.stories.jsx +18 -0
- package/src/components/ToolsPopover/ToolsPopover.jsx +32 -1
- package/src/components/ToolsPopover/ToolsPopover.stories.jsx +18 -0
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,
|
|
@@ -18,6 +18,7 @@ export const ToolsPopover = memo(
|
|
|
18
18
|
matchTriggerWidth = false,
|
|
19
19
|
wrapCloseMenu,
|
|
20
20
|
modal = false,
|
|
21
|
+
closeOnTriggerClick = true,
|
|
21
22
|
...props
|
|
22
23
|
}) => {
|
|
23
24
|
const isControlled = props.open !== undefined
|
|
@@ -55,6 +56,27 @@ export const ToolsPopover = memo(
|
|
|
55
56
|
panel?.focus({ preventScroll: true })
|
|
56
57
|
}, [])
|
|
57
58
|
|
|
59
|
+
const keepOpenOnTrigger = open && !closeOnTriggerClick
|
|
60
|
+
|
|
61
|
+
const handleTriggerClick = (event) => {
|
|
62
|
+
if (!keepOpenOnTrigger) return
|
|
63
|
+
// Radix toggles on click and skips that when default is prevented.
|
|
64
|
+
event.preventDefault()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const handleTriggerKeyDown = (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
|
+
const target = event.target
|
|
75
|
+
if (target instanceof Element && target.closest('[data-tools-popover-trigger]')) {
|
|
76
|
+
event.preventDefault()
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
58
80
|
const renderPanel = () => (
|
|
59
81
|
<div
|
|
60
82
|
className={styles.contentPanel}
|
|
@@ -76,6 +98,7 @@ export const ToolsPopover = memo(
|
|
|
76
98
|
sideOffset={sideOffset}
|
|
77
99
|
alignOffset={0}
|
|
78
100
|
onOpenAutoFocus={handleOpenAutoFocus}
|
|
101
|
+
onPointerDownOutside={handlePointerDownOutside}
|
|
79
102
|
onCloseAutoFocus={(event) => {
|
|
80
103
|
event.preventDefault()
|
|
81
104
|
}}
|
|
@@ -99,7 +122,15 @@ export const ToolsPopover = memo(
|
|
|
99
122
|
open={disabled ? false : open}
|
|
100
123
|
onOpenChange={disabled ? undefined : onOpenChange}
|
|
101
124
|
>
|
|
102
|
-
<PopoverRadix.Trigger
|
|
125
|
+
<PopoverRadix.Trigger
|
|
126
|
+
asChild
|
|
127
|
+
className={triggerClassName}
|
|
128
|
+
disabled={disabled}
|
|
129
|
+
data-tools-popover-trigger=""
|
|
130
|
+
style={keepOpenOnTrigger ? { pointerEvents: 'auto' } : undefined}
|
|
131
|
+
onClick={handleTriggerClick}
|
|
132
|
+
onKeyDown={handleTriggerKeyDown}
|
|
133
|
+
>
|
|
103
134
|
{trigger}
|
|
104
135
|
</PopoverRadix.Trigger>
|
|
105
136
|
|
|
@@ -18,6 +18,8 @@ ToolsPopover is a Popover wrapper with controlled open state, styled panel conte
|
|
|
18
18
|
Pass any single React element as \`trigger\` — it is forwarded to \`Popover.Trigger\` via \`asChild\`.
|
|
19
19
|
|
|
20
20
|
Use this instead of \`ToolsDropdown\` when the panel contains interactive content (forms, switches, sliders) that should stay open while the user interacts with it.
|
|
21
|
+
|
|
22
|
+
Set \`closeOnTriggerClick\` to \`false\` to keep the popover open when the trigger is clicked again.
|
|
21
23
|
`,
|
|
22
24
|
},
|
|
23
25
|
},
|
|
@@ -32,6 +34,11 @@ Use this instead of \`ToolsDropdown\` when the panel contains interactive conten
|
|
|
32
34
|
control: 'boolean',
|
|
33
35
|
table: { type: { summary: 'boolean' }, defaultValue: { summary: false } },
|
|
34
36
|
},
|
|
37
|
+
closeOnTriggerClick: {
|
|
38
|
+
control: 'boolean',
|
|
39
|
+
description: 'Closes the popover when the trigger is clicked while it is already open',
|
|
40
|
+
table: { type: { summary: 'boolean' }, defaultValue: { summary: true } },
|
|
41
|
+
},
|
|
35
42
|
children: {
|
|
36
43
|
description: 'Popover content or render prop receiving closePopover',
|
|
37
44
|
table: { type: { summary: 'React.ReactNode | (closePopover) => React.ReactNode' } },
|
|
@@ -115,6 +122,17 @@ export const ControlledOpen = {
|
|
|
115
122
|
},
|
|
116
123
|
}
|
|
117
124
|
|
|
125
|
+
export const KeepOpenOnTriggerClick = {
|
|
126
|
+
args: {
|
|
127
|
+
closeOnTriggerClick: false,
|
|
128
|
+
},
|
|
129
|
+
render: (args) => (
|
|
130
|
+
<ToolsPopover {...args} trigger={<Button variant="soft">Settings</Button>}>
|
|
131
|
+
<Text size="2">Stays open if the trigger is clicked again</Text>
|
|
132
|
+
</ToolsPopover>
|
|
133
|
+
),
|
|
134
|
+
}
|
|
135
|
+
|
|
118
136
|
export const CustomElement = {
|
|
119
137
|
render: () => (
|
|
120
138
|
<ToolsPopover
|