@moises.ai/design-system 4.16.7 → 4.16.8

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