@moises.ai/design-system 4.16.8 → 4.16.10
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,12 +1,15 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
2
|
import classNames from 'classnames'
|
|
3
3
|
import { DropdownMenu as DropdownMenuRadix } from 'radix-ui'
|
|
4
4
|
import { memo, useCallback, useState } from 'react'
|
|
5
5
|
import { ChevronDownIcon } from '../../icons/ChevronDownIcon'
|
|
6
6
|
import { styles as menuStyles } from '../../lib/menu'
|
|
7
|
-
import { Button } from '../Button/Button'
|
|
8
7
|
import { Theme } from '../theme/Theme'
|
|
9
8
|
import styles from './ToolsDropdown.module.css'
|
|
9
|
+
import { Flex, ScrollArea, Separator } from '../../index'
|
|
10
|
+
|
|
11
|
+
const FOCUSABLE_SELECTOR =
|
|
12
|
+
'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [role="switch"]:not([disabled]), [tabindex]:not([tabindex="-1"])'
|
|
10
13
|
|
|
11
14
|
export const ToolsDropdown = memo(
|
|
12
15
|
({
|
|
@@ -28,9 +31,6 @@ export const ToolsDropdown = memo(
|
|
|
28
31
|
}) => {
|
|
29
32
|
const isControlled = props.open !== undefined
|
|
30
33
|
const [internalOpen, setInternalOpen] = useState(false)
|
|
31
|
-
const [hover, setHover] = useState(false)
|
|
32
|
-
const [isActionFocused, setIsActionFocused] = useState(false)
|
|
33
|
-
const [isMenuTriggerFocused, setIsMenuTriggerFocused] = useState(false)
|
|
34
34
|
|
|
35
35
|
const open = isControlled ? props.open : internalOpen
|
|
36
36
|
const onOpenChange = useCallback(
|
|
@@ -59,22 +59,43 @@ export const ToolsDropdown = memo(
|
|
|
59
59
|
onTriggerClick(event)
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
62
|
+
const handlePanelKeyDown = useCallback((event) => {
|
|
63
|
+
if (event.key === 'Tab') {
|
|
64
|
+
event.stopPropagation()
|
|
65
|
+
}
|
|
66
|
+
}, [])
|
|
67
|
+
|
|
68
|
+
const handleOpenAutoFocus = useCallback((event) => {
|
|
69
|
+
const panel = event.currentTarget.querySelector('[data-tools-dropdown-panel]')
|
|
70
|
+
const focusable = panel?.querySelector(FOCUSABLE_SELECTOR)
|
|
71
|
+
|
|
72
|
+
if (!focusable) return
|
|
73
|
+
|
|
74
|
+
event.preventDefault()
|
|
75
|
+
focusable.focus({ preventScroll: true })
|
|
76
|
+
}, [])
|
|
77
|
+
|
|
78
|
+
const renderPanel = () => (
|
|
79
|
+
<div
|
|
80
|
+
className={styles.contentPanel}
|
|
81
|
+
data-tools-dropdown-panel
|
|
82
|
+
onKeyDown={handlePanelKeyDown}
|
|
83
|
+
>
|
|
84
|
+
{typeof children === 'function' ? children(closeMenu) : children}
|
|
85
|
+
</div>
|
|
86
|
+
)
|
|
67
87
|
|
|
68
88
|
const menuContent = (
|
|
69
89
|
<Theme asChild>
|
|
70
90
|
<DropdownMenuRadix.Content
|
|
71
|
-
className={classNames(menuStyles.menuContent, contentClassName)}
|
|
91
|
+
className={classNames(menuStyles.menuContent, contentClassName, styles.customContentClassName)}
|
|
72
92
|
size={size}
|
|
73
93
|
side={props.side}
|
|
74
94
|
align={props.align}
|
|
75
95
|
style={contentStyle}
|
|
76
96
|
sideOffset={sideOffset}
|
|
77
97
|
alignOffset={0}
|
|
98
|
+
onOpenAutoFocus={handleOpenAutoFocus}
|
|
78
99
|
onCloseAutoFocus={(event) => {
|
|
79
100
|
event.preventDefault()
|
|
80
101
|
}}
|
|
@@ -82,14 +103,10 @@ export const ToolsDropdown = memo(
|
|
|
82
103
|
>
|
|
83
104
|
{maxHeight ? (
|
|
84
105
|
<ScrollArea scrollbars="vertical" style={{ height: maxHeight }}>
|
|
85
|
-
|
|
86
|
-
{typeof children === 'function' ? children(closeMenu) : children}
|
|
87
|
-
</div>
|
|
106
|
+
{renderPanel()}
|
|
88
107
|
</ScrollArea>
|
|
89
108
|
) : (
|
|
90
|
-
|
|
91
|
-
{typeof children === 'function' ? children(closeMenu) : children}
|
|
92
|
-
</div>
|
|
109
|
+
renderPanel()
|
|
93
110
|
)}
|
|
94
111
|
</DropdownMenuRadix.Content>
|
|
95
112
|
</Theme>
|
|
@@ -108,31 +125,29 @@ export const ToolsDropdown = memo(
|
|
|
108
125
|
onClick={handleTriggerClick}
|
|
109
126
|
className={classNames(styles.triggerWithClick)}
|
|
110
127
|
>
|
|
111
|
-
|
|
128
|
+
{trigger}
|
|
112
129
|
</button>
|
|
113
130
|
)}
|
|
114
131
|
|
|
115
132
|
<DropdownMenuRadix.Trigger
|
|
116
|
-
asChild
|
|
117
133
|
disabled={disabled}
|
|
134
|
+
className={classNames(styles.menuTrigger)}
|
|
118
135
|
>
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
136
|
+
{!onTriggerClick && (
|
|
137
|
+
<Flex className={styles.triggerWithoutClick}>
|
|
138
|
+
{trigger}
|
|
139
|
+
</Flex>
|
|
140
|
+
)}
|
|
122
141
|
|
|
123
|
-
|
|
124
|
-
{trigger}
|
|
142
|
+
{showSeparator && <Separator orientation="vertical" className={styles.separator} />}
|
|
125
143
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
})}
|
|
134
|
-
/>
|
|
135
|
-
</button>
|
|
144
|
+
<ChevronDownIcon
|
|
145
|
+
width={8}
|
|
146
|
+
height={8}
|
|
147
|
+
className={classNames(styles.chevron, {
|
|
148
|
+
[styles.chevronWithoutSeparator]: !showSeparator,
|
|
149
|
+
})}
|
|
150
|
+
/>
|
|
136
151
|
</DropdownMenuRadix.Trigger>
|
|
137
152
|
|
|
138
153
|
<DropdownMenuRadix.Portal className={menuStyles.menuPortal}>
|
|
@@ -2,16 +2,108 @@
|
|
|
2
2
|
display: flex;
|
|
3
3
|
align-items: center;
|
|
4
4
|
justify-content: center;
|
|
5
|
+
border: 1px solid var(--neutral-alpha-3);
|
|
6
|
+
border-radius: 4px;
|
|
7
|
+
display: flex;
|
|
8
|
+
align-items: center;
|
|
9
|
+
justify-content: center;
|
|
5
10
|
}
|
|
6
11
|
|
|
7
12
|
.triggerWithClick {
|
|
8
13
|
cursor: pointer;
|
|
9
14
|
height: 32px;
|
|
15
|
+
margin: 0;
|
|
16
|
+
border: 0;
|
|
17
|
+
padding: 8px;
|
|
18
|
+
background: transparent;
|
|
19
|
+
outline: none;
|
|
20
|
+
|
|
21
|
+
line-height: 0;
|
|
22
|
+
|
|
23
|
+
color: var(--neutral-alpha-11);
|
|
24
|
+
|
|
25
|
+
span {
|
|
26
|
+
font-family: "Articulat CF";
|
|
27
|
+
font-size: 14px;
|
|
28
|
+
font-style: normal;
|
|
29
|
+
font-weight: 400;
|
|
30
|
+
line-height: 17px;
|
|
31
|
+
letter-spacing: 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.container:has(.triggerWithClick) .triggerWithClick {
|
|
37
|
+
border-radius: 4px 0 0 4px;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.triggerWithClick:focus-visible {
|
|
41
|
+
outline: 2px solid var(--neutral-alpha-8);
|
|
42
|
+
outline-offset: 2px;
|
|
43
|
+
position: relative;
|
|
44
|
+
z-index: 1;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.triggerWithClick:hover {
|
|
48
|
+
color: var(--neutral-alpha-12);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.triggerWithClick:active {
|
|
52
|
+
color: var(--neutral-alpha-11);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.container:has(.triggerWithClick:hover) .chevron {
|
|
56
|
+
color: var(--neutral-alpha-12) !important;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.container:has(.triggerWithClick:active) .chevron {
|
|
60
|
+
color: var(--neutral-alpha-11) !important;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.triggerWithoutClick {
|
|
64
|
+
padding: 8px;
|
|
10
65
|
}
|
|
11
66
|
|
|
12
67
|
.menuTrigger {
|
|
68
|
+
display: flex;
|
|
69
|
+
align-items: center;
|
|
13
70
|
cursor: pointer;
|
|
14
71
|
height: 32px;
|
|
72
|
+
margin: 0;
|
|
73
|
+
border: 0;
|
|
74
|
+
padding: 0;
|
|
75
|
+
background: transparent;
|
|
76
|
+
font: inherit;
|
|
77
|
+
color: inherit;
|
|
78
|
+
outline: none;
|
|
79
|
+
border-radius: 4px;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.container:has(.triggerWithClick) .menuTrigger {
|
|
83
|
+
border-radius: 0 4px 4px 0;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.menuTrigger:focus-visible {
|
|
87
|
+
outline: 2px solid var(--neutral-alpha-8);
|
|
88
|
+
outline-offset: 2px;
|
|
89
|
+
position: relative;
|
|
90
|
+
z-index: 1;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
.menuTrigger:hover {
|
|
94
|
+
color: var(--neutral-12);
|
|
95
|
+
|
|
96
|
+
.chevron {
|
|
97
|
+
color: var(--neutral-12);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.menuTrigger:active {
|
|
102
|
+
color: var(--neutral-11);
|
|
103
|
+
|
|
104
|
+
.chevron {
|
|
105
|
+
color: var(--neutral-11);
|
|
106
|
+
}
|
|
15
107
|
}
|
|
16
108
|
|
|
17
109
|
.menuPortal {
|
|
@@ -20,4 +112,41 @@
|
|
|
20
112
|
background: #18191b;
|
|
21
113
|
box-shadow: 0 12px 32px -16px rgba(0, 0, 0, 0.3),
|
|
22
114
|
0 12px 60px 0 rgba(0, 0, 0, 0.15);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
.chevron {
|
|
118
|
+
padding: 4px;
|
|
119
|
+
color: var(--neutral-alpha-7);
|
|
120
|
+
|
|
121
|
+
&:hover {
|
|
122
|
+
color: var(--neutral-alpha-11);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
&:active {
|
|
126
|
+
color: var(--neutral-alpha-11);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
.chevronWithoutSeparator {
|
|
131
|
+
padding: 4px 4px 4px 0 !important;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
.customContentClassName {
|
|
135
|
+
padding: 12px 16px 16px 16px;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
.contentPanel {
|
|
139
|
+
outline: none;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.triggerWithoutClick {
|
|
143
|
+
color: var(--neutral-alpha-11);
|
|
144
|
+
|
|
145
|
+
&:hover {
|
|
146
|
+
color: var(--neutral-alpha-12);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
&:active {
|
|
150
|
+
color: var(--neutral-alpha-11);
|
|
151
|
+
}
|
|
23
152
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import { Flex, Switch, Text } from '@radix-ui/themes'
|
|
2
2
|
import { useState } from 'react'
|
|
3
|
-
import { DropdownMenu as DropdownMenuRadix } from 'radix-ui'
|
|
4
3
|
import { MetronomeIcon } from '../../icons/MetronomeIcon'
|
|
5
4
|
import { ToolsDropdown } from './ToolsDropdown'
|
|
6
|
-
|
|
7
5
|
export default {
|
|
8
6
|
title: 'Components/ToolsDropdown',
|
|
9
7
|
component: ToolsDropdown,
|
|
@@ -123,14 +121,26 @@ export const ControlledOpen = {
|
|
|
123
121
|
open={isOpen}
|
|
124
122
|
onOpenChange={setIsOpen}
|
|
125
123
|
trigger={<Text>Controlled</Text>}
|
|
124
|
+
showSeparator={false}
|
|
126
125
|
>
|
|
127
126
|
<Text size="2">Controlled menu content</Text>
|
|
128
127
|
</ToolsDropdown>
|
|
129
128
|
|
|
130
|
-
<Text size="1">
|
|
129
|
+
<Text size="1" >
|
|
131
130
|
Status: <strong>{isOpen ? 'Open' : 'Closed'}</strong>
|
|
132
131
|
</Text>
|
|
133
132
|
</Flex>
|
|
134
133
|
)
|
|
135
134
|
},
|
|
136
135
|
}
|
|
136
|
+
|
|
137
|
+
export const WithoutSeparator = {
|
|
138
|
+
args: {
|
|
139
|
+
showSeparator: false,
|
|
140
|
+
},
|
|
141
|
+
render: (args) => (
|
|
142
|
+
<ToolsDropdown {...args} trigger={<MetronomeIcon width={16} height={16} />}>
|
|
143
|
+
<Text size="2">Tool settings panel</Text>
|
|
144
|
+
</ToolsDropdown>
|
|
145
|
+
),
|
|
146
|
+
}
|