@moises.ai/design-system 4.16.7 → 4.16.9

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
  {
2
2
  "name": "@moises.ai/design-system",
3
- "version": "4.16.7",
3
+ "version": "4.16.9",
4
4
  "description": "Design System package based on @radix-ui/themes with custom defaults",
5
5
  "private": false,
6
6
  "type": "module",
@@ -0,0 +1,162 @@
1
+
2
+ import classNames from 'classnames'
3
+ import { DropdownMenu as DropdownMenuRadix } from 'radix-ui'
4
+ import { memo, useCallback, useState } from 'react'
5
+ import { ChevronDownIcon } from '../../icons/ChevronDownIcon'
6
+ import { styles as menuStyles } from '../../lib/menu'
7
+ import { Theme } from '../theme/Theme'
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"])'
13
+
14
+ export const ToolsDropdown = memo(
15
+ ({
16
+ trigger,
17
+ children,
18
+ className,
19
+ contentClassName,
20
+ showActiveTrigger,
21
+ size = '2',
22
+ disabled = false,
23
+ maxHeight,
24
+ sideOffset = 5,
25
+ matchTriggerWidth = false,
26
+ onTriggerClick,
27
+ showSeparator = true,
28
+ withIconTrigger = true,
29
+ wrapCloseMenu,
30
+ ...props
31
+ }) => {
32
+ const isControlled = props.open !== undefined
33
+ const [internalOpen, setInternalOpen] = useState(false)
34
+
35
+ const open = isControlled ? props.open : internalOpen
36
+ const onOpenChange = useCallback(
37
+ (value) => {
38
+ if (!isControlled) setInternalOpen(value)
39
+ props?.onOpenChange?.(value)
40
+ },
41
+ [isControlled, props?.onOpenChange],
42
+ )
43
+
44
+ const baseClose = useCallback(() => onOpenChange(false), [onOpenChange])
45
+ const closeMenu = wrapCloseMenu ? wrapCloseMenu(baseClose) : baseClose
46
+
47
+ const contentStyle = {
48
+ ...(matchTriggerWidth && {
49
+ width: 'var(--radix-dropdown-menu-trigger-width)',
50
+ boxSizing: 'border-box',
51
+ }),
52
+ ...(maxHeight && { height: maxHeight }),
53
+ }
54
+
55
+ const handleTriggerClick = (event) => {
56
+ if (!onTriggerClick) return
57
+ event.preventDefault()
58
+ event.stopPropagation()
59
+ onTriggerClick(event)
60
+ }
61
+
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
+ )
87
+
88
+ const menuContent = (
89
+ <Theme asChild>
90
+ <DropdownMenuRadix.Content
91
+ className={classNames(menuStyles.menuContent, contentClassName, styles.customContentClassName)}
92
+ size={size}
93
+ side={props.side}
94
+ align={props.align}
95
+ style={contentStyle}
96
+ sideOffset={sideOffset}
97
+ alignOffset={0}
98
+ onOpenAutoFocus={handleOpenAutoFocus}
99
+ onCloseAutoFocus={(event) => {
100
+ event.preventDefault()
101
+ }}
102
+ onClick={(event) => event.stopPropagation()}
103
+ >
104
+ {maxHeight ? (
105
+ <ScrollArea scrollbars="vertical" style={{ height: maxHeight }}>
106
+ {renderPanel()}
107
+ </ScrollArea>
108
+ ) : (
109
+ renderPanel()
110
+ )}
111
+ </DropdownMenuRadix.Content>
112
+ </Theme>
113
+ )
114
+
115
+ return (
116
+ <Flex className={classNames(styles.container, className)}>
117
+ <DropdownMenuRadix.Root
118
+ {...props}
119
+ open={disabled ? false : open}
120
+ onOpenChange={disabled ? undefined : onOpenChange}
121
+ >
122
+ {onTriggerClick && (
123
+ <button
124
+ type="button"
125
+ onClick={handleTriggerClick}
126
+ className={classNames(styles.triggerWithClick)}
127
+ >
128
+ {trigger}
129
+ </button>
130
+ )}
131
+
132
+ <DropdownMenuRadix.Trigger
133
+ disabled={disabled}
134
+ className={classNames(styles.menuTrigger)}
135
+ >
136
+ {!onTriggerClick && (
137
+ <Flex className={styles.triggerWithoutClick}>
138
+ {trigger}
139
+ </Flex>
140
+ )}
141
+
142
+ {showSeparator && <Separator orientation="vertical" className={styles.separator} />}
143
+
144
+ <ChevronDownIcon
145
+ width={8}
146
+ height={8}
147
+ className={classNames(styles.chevron, {
148
+ [styles.chevronWithoutSeparator]: !showSeparator,
149
+ })}
150
+ />
151
+ </DropdownMenuRadix.Trigger>
152
+
153
+ <DropdownMenuRadix.Portal className={menuStyles.menuPortal}>
154
+ {menuContent}
155
+ </DropdownMenuRadix.Portal>
156
+ </DropdownMenuRadix.Root>
157
+ </Flex>
158
+ )
159
+ },
160
+ )
161
+
162
+ ToolsDropdown.displayName = 'ToolsDropdown'
@@ -0,0 +1,140 @@
1
+ .container {
2
+ display: flex;
3
+ align-items: center;
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;
10
+ }
11
+
12
+ .triggerWithClick {
13
+ cursor: pointer;
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;
65
+ }
66
+
67
+ .menuTrigger {
68
+ display: flex;
69
+ align-items: center;
70
+ cursor: pointer;
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
+ }
107
+ }
108
+
109
+ .menuPortal {
110
+ border-radius: 8px;
111
+ border: 1px solid var(--neutral-alpha-3);
112
+ background: #18191b;
113
+ box-shadow: 0 12px 32px -16px rgba(0, 0, 0, 0.3),
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
+ }
@@ -0,0 +1,145 @@
1
+ import { Flex, Switch, Text } from '@radix-ui/themes'
2
+ import { useState } from 'react'
3
+ import { MetronomeIcon } from '../../icons/MetronomeIcon'
4
+ import { ToolsDropdown } from './ToolsDropdown'
5
+ export default {
6
+ title: 'Components/ToolsDropdown',
7
+ component: ToolsDropdown,
8
+ parameters: {
9
+ layout: 'centered',
10
+ docs: {
11
+ description: {
12
+ component: `
13
+ ToolsDropdown combines a tool action trigger with a dropdown menu built on Radix DropdownMenu.
14
+
15
+ - Pass \`onTriggerClick\` to run a primary action without opening the menu. The chevron opens the menu.
16
+ - Omit \`onTriggerClick\` to open the menu from the full trigger.
17
+ - Use \`children\` or \`children(closeMenu)\` for custom panel content.
18
+ `,
19
+ },
20
+ },
21
+ },
22
+ tags: ['autodocs'],
23
+ argTypes: {
24
+ trigger: {
25
+ description: 'Trigger content shown on the main button area',
26
+ table: { type: { summary: 'React.ReactNode' } },
27
+ },
28
+ onTriggerClick: {
29
+ description: 'Primary action executed when the main trigger is clicked',
30
+ table: { type: { summary: 'function' } },
31
+ },
32
+ showSeparator: {
33
+ control: 'boolean',
34
+ table: { type: { summary: 'boolean' }, defaultValue: { summary: true } },
35
+ },
36
+ children: {
37
+ description: 'Dropdown content or render prop receiving closeMenu',
38
+ table: { type: { summary: 'React.ReactNode | (closeMenu) => React.ReactNode' } },
39
+ },
40
+ },
41
+ }
42
+
43
+ export const Default = {
44
+ args: {
45
+ trigger: <Text>Tools</Text>,
46
+ showSeparator: true,
47
+ },
48
+ render: (args) => (
49
+ <ToolsDropdown {...args}>
50
+ <Text size="2">Tool settings panel</Text>
51
+ </ToolsDropdown>
52
+ ),
53
+ }
54
+
55
+ export const WithCustomAction = {
56
+ args: {
57
+ trigger: <MetronomeIcon width={16} height={16} />,
58
+ onTriggerClick: () => alert('Metronome toggled'),
59
+ },
60
+ render: (args) => (
61
+ <ToolsDropdown {...args}>
62
+ <Flex direction="column" gap="2">
63
+ <Text size="2">BPM: 120</Text>
64
+ <Text size="2">Time signature: 4/4</Text>
65
+ </Flex>
66
+ </ToolsDropdown>
67
+ ),
68
+ }
69
+
70
+ export const WithRenderProp = {
71
+ render: () => {
72
+ const [enabled, setEnabled] = useState(false)
73
+
74
+ return (
75
+ <ToolsDropdown
76
+ trigger={<Text>Chords</Text>}
77
+ onTriggerClick={() => alert('Chords toggled')}
78
+ >
79
+ {(closeMenu) => (
80
+ <>
81
+ <Flex direction="column" gap="3" width="220px">
82
+ <Text size="2">Show chord diagrams</Text>
83
+ <Switch
84
+ size="2"
85
+ checked={enabled}
86
+ onCheckedChange={setEnabled}
87
+ />
88
+ <button
89
+ type="button"
90
+ onClick={() => {
91
+ closeMenu()
92
+ alert('Saved')
93
+ }}
94
+ >
95
+ Save
96
+ </button>
97
+ </Flex>
98
+ </>
99
+ )}
100
+ </ToolsDropdown>
101
+ )
102
+ },
103
+ }
104
+
105
+ export const ControlledOpen = {
106
+ render: () => {
107
+ const [isOpen, setIsOpen] = useState(false)
108
+
109
+ return (
110
+ <Flex direction="column" gap="4" align="center">
111
+ <Flex gap="2">
112
+ <button type="button" onClick={() => setIsOpen(true)}>
113
+ Open
114
+ </button>
115
+ <button type="button" onClick={() => setIsOpen(false)}>
116
+ Close
117
+ </button>
118
+ </Flex>
119
+
120
+ <ToolsDropdown
121
+ open={isOpen}
122
+ onOpenChange={setIsOpen}
123
+ trigger={<Text color='blue'>Controlled</Text>}
124
+ >
125
+ <Text size="2">Controlled menu content</Text>
126
+ </ToolsDropdown>
127
+
128
+ <Text size="1" >
129
+ Status: <strong>{isOpen ? 'Open' : 'Closed'}</strong>
130
+ </Text>
131
+ </Flex>
132
+ )
133
+ },
134
+ }
135
+
136
+ export const WithoutSeparator = {
137
+ args: {
138
+ showSeparator: false,
139
+ },
140
+ render: (args) => (
141
+ <ToolsDropdown {...args} trigger={<MetronomeIcon width={16} height={16} />}>
142
+ <Text size="2">Tool settings panel</Text>
143
+ </ToolsDropdown>
144
+ ),
145
+ }
package/src/index.jsx CHANGED
@@ -53,6 +53,7 @@ export { Countdown } from './components/Countdown/Countdown'
53
53
  export { DataTable } from './components/DataTable/DataTable'
54
54
  export { DropdownButton } from './components/DropdownButton/DropdownButton'
55
55
  export { DropdownMenu } from './components/DropdownMenu/DropdownMenu'
56
+ export { ToolsDropdown } from './components/ToolsDropdown/ToolsDropdown'
56
57
  export { EmptyState } from './components/EmptyState/EmptyState'
57
58
  export {
58
59
  Extension,