@moises.ai/design-system 4.22.0 → 4.22.2

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.22.0",
3
+ "version": "4.22.2",
4
4
  "description": "Design System package based on @radix-ui/themes with custom defaults",
5
5
  "private": false,
6
6
  "type": "module",
@@ -158,7 +158,12 @@
158
158
  opacity: 0;
159
159
  }
160
160
 
161
- .DataTable :global(.rt-TableRow:hover) .checkboxCell,
161
+ @media (hover: hover) and (pointer: fine) {
162
+ .DataTable :global(.rt-TableRow:hover) .checkboxCell {
163
+ opacity: 1;
164
+ }
165
+ }
166
+
162
167
  .selectColumn:focus-within .checkboxCell,
163
168
  .rowSelected .checkboxCell {
164
169
  opacity: 1;
@@ -276,8 +281,10 @@
276
281
  --row-bg: transparent;
277
282
  }
278
283
 
279
- .DataTable :global(.rt-TableRow:hover) {
280
- --row-bg: var(--neutral-alpha-2);
284
+ @media (hover: hover) and (pointer: fine) {
285
+ .DataTable :global(.rt-TableRow:hover) {
286
+ --row-bg: var(--neutral-alpha-2);
287
+ }
281
288
  }
282
289
 
283
290
  .DataTable :global(.rt-TableRow:focus-within) {
@@ -315,6 +322,9 @@
315
322
  color: inherit;
316
323
  text-align: left;
317
324
  cursor: pointer;
325
+ -webkit-touch-callout: none;
326
+ -webkit-user-select: none;
327
+ user-select: none;
318
328
  }
319
329
 
320
330
  .rowActionButton > * {
@@ -327,8 +337,13 @@
327
337
  outline-offset: 2px;
328
338
  }
329
339
 
330
- .DataTable :global(.rt-TableRow:hover) .projectCell:not(.dropdownColumn) :not(.artistText) {
331
- color: var(--neutral-12);
340
+ @media (hover: hover) and (pointer: fine) {
341
+ .DataTable
342
+ :global(.rt-TableRow:hover)
343
+ .projectCell:not(.dropdownColumn)
344
+ :not(.artistText) {
345
+ color: var(--neutral-12);
346
+ }
332
347
  }
333
348
 
334
349
  .DataTable
@@ -524,12 +539,23 @@
524
539
  min-width: 100%;
525
540
  }
526
541
 
527
- .DataTable :global(.rt-TableRow:hover) .dropdownTriggerWrapperIcon,
542
+ @media (hover: hover) and (pointer: fine) {
543
+ .DataTable :global(.rt-TableRow:hover) .dropdownTriggerWrapperIcon {
544
+ opacity: 1;
545
+ }
546
+ }
547
+
528
548
  .dropdownColumn:focus-within .dropdownTriggerWrapperIcon,
529
549
  .showDropdownOnSelect .dropdownTriggerWrapperIcon {
530
550
  opacity: 1;
531
551
  }
532
552
 
553
+ @media (pointer: coarse) {
554
+ .dropdownTriggerWrapperIcon {
555
+ opacity: 1;
556
+ }
557
+ }
558
+
533
559
 
534
560
  .headerActions {
535
561
  width: max-content;
@@ -1,11 +1,37 @@
1
- import React, { useRef } from 'react'
1
+ import React, { useEffect, useRef, useState } from 'react'
2
2
  import { useSortable } from '@dnd-kit/sortable'
3
3
  import { CSS } from '@dnd-kit/utilities'
4
4
  import classNames from 'classnames'
5
5
  import { Flex, Table, Checkbox, DropdownMenu } from '../../../index'
6
6
  import { MoreButton } from '../../MoreButton/MoreButton'
7
7
  import styles from '../DataTable.module.css'
8
- import { resolveRowDraggable } from './dataTableDnd.utils'
8
+ import { isTouchTap, resolveRowDraggable } from './dataTableDnd.utils'
9
+
10
+ let lastScroll = null
11
+ let scrollListenerAttached = false
12
+
13
+ const recordScroll = (e) => {
14
+ lastScroll = { target: e.target, time: performance.now() }
15
+ }
16
+
17
+ const listenForScroll = () => {
18
+ if (scrollListenerAttached) return
19
+ scrollListenerAttached = true
20
+ document.addEventListener('scroll', recordScroll, {
21
+ capture: true,
22
+ passive: true,
23
+ })
24
+ }
25
+
26
+ const toPoint = (e) => ({
27
+ pointerId: e.pointerId,
28
+ x: e.clientX,
29
+ y: e.clientY,
30
+ time: performance.now(),
31
+ })
32
+
33
+ // Keeps a press on a cell control from arming the row's drag sensor.
34
+ const stopDragActivation = (e) => e.stopPropagation()
9
35
 
10
36
  export const DataTableRowSortable = React.memo(function DataTableRowSortable({
11
37
  row,
@@ -32,6 +58,9 @@ export const DataTableRowSortable = React.memo(function DataTableRowSortable({
32
58
  const touchHandledRef = useRef(false)
33
59
  const checkboxTouchHandledRef = useRef(false)
34
60
  const checkboxKeyboardHandledRef = useRef(false)
61
+ const pointerStartRef = useRef(null)
62
+ const gestureDraggedRef = useRef(false)
63
+ const [menuOpen, setMenuOpen] = useState(false)
35
64
  const { listeners, setNodeRef, transform, transition, isDragging } =
36
65
  useSortable({
37
66
  id: rowId,
@@ -45,6 +74,30 @@ export const DataTableRowSortable = React.memo(function DataTableRowSortable({
45
74
  },
46
75
  })
47
76
 
77
+ useEffect(() => {
78
+ if (isDragging) gestureDraggedRef.current = true
79
+ }, [isDragging])
80
+
81
+ const handleRowPointerDownCapture = (e) => {
82
+ if (e.pointerType === 'touch') listenForScroll()
83
+ pointerStartRef.current = toPoint(e)
84
+ gestureDraggedRef.current = false
85
+ touchHandledRef.current = false
86
+ checkboxTouchHandledRef.current = false
87
+ }
88
+
89
+ const handleRowPointerCancel = () => {
90
+ pointerStartRef.current = null
91
+ }
92
+
93
+ const isTap = (e) => {
94
+ if (gestureDraggedRef.current) return false
95
+ const scroll = lastScroll?.target?.contains?.(e.currentTarget)
96
+ ? lastScroll
97
+ : null
98
+ return isTouchTap(pointerStartRef.current, toPoint(e), scroll)
99
+ }
100
+
48
101
  const sortableStyle = {
49
102
  ...(transform ? { transform: CSS.Transform.toString(transform) } : {}),
50
103
  ...(transition ? { transition } : {}),
@@ -69,6 +122,7 @@ export const DataTableRowSortable = React.memo(function DataTableRowSortable({
69
122
  const handleRowPointerUp = (e) => {
70
123
  if (e.pointerType !== 'touch') return
71
124
  touchHandledRef.current = true
125
+ if (!isTap(e)) return
72
126
  if (e.shiftKey) {
73
127
  onShiftClickRow?.(row, rowIndex)
74
128
  } else {
@@ -126,6 +180,7 @@ export const DataTableRowSortable = React.memo(function DataTableRowSortable({
126
180
  if (e.pointerType !== 'touch') return
127
181
  e.stopPropagation()
128
182
  checkboxTouchHandledRef.current = true
183
+ if (!isTap(e)) return
129
184
  if (e.shiftKey) {
130
185
  onShiftClickRow?.(row, rowIndex)
131
186
  } else if (rowId != null) {
@@ -133,6 +188,16 @@ export const DataTableRowSortable = React.memo(function DataTableRowSortable({
133
188
  }
134
189
  }
135
190
 
191
+ // Radix opens the menu on pointerdown, which would open it at the start of
192
+ // a scroll. On touch the row opens it on a tap instead.
193
+ const handleMenuPointerDown = (e) => {
194
+ if (e.pointerType === 'touch') e.preventDefault()
195
+ }
196
+
197
+ const handleMenuPointerUp = (e) => {
198
+ if (e.pointerType === 'touch' && isTap(e)) setMenuOpen(true)
199
+ }
200
+
136
201
  const handleCheckedChange = (value) => {
137
202
  if (shiftClickRef.current) {
138
203
  shiftClickRef.current = false
@@ -166,12 +231,17 @@ export const DataTableRowSortable = React.memo(function DataTableRowSortable({
166
231
  })}
167
232
  style={rowStyle}
168
233
  {...(isDraggable ? listeners : {})}
234
+ onPointerDownCapture={handleRowPointerDownCapture}
235
+ onPointerCancel={handleRowPointerCancel}
169
236
  >
170
237
  <Table.Cell
171
238
  className={styles.selectColumn}
172
239
  data-column-id="select"
173
240
  data-sorted="false"
174
241
  onClick={handleCheckboxCellClick}
242
+ onPointerDown={stopDragActivation}
243
+ onMouseDown={stopDragActivation}
244
+ onTouchStart={stopDragActivation}
175
245
  onPointerUp={handleCheckboxCellPointerUp}
176
246
  >
177
247
  <Checkbox
@@ -226,11 +296,20 @@ export const DataTableRowSortable = React.memo(function DataTableRowSortable({
226
296
  styles.dropdownColumnCell,
227
297
  )}
228
298
  data-column-id="actions"
299
+ onPointerDown={stopDragActivation}
300
+ onMouseDown={stopDragActivation}
301
+ onTouchStart={stopDragActivation}
229
302
  >
230
303
  {row.dropdownOptions?.length ? (
231
304
  <DropdownMenu
305
+ open={menuOpen}
306
+ onOpenChange={setMenuOpen}
232
307
  trigger={
233
- <Flex className={styles.dropdownTriggerWrapper}>
308
+ <Flex
309
+ className={styles.dropdownTriggerWrapper}
310
+ onPointerDown={handleMenuPointerDown}
311
+ onPointerUp={handleMenuPointerUp}
312
+ >
234
313
  <MoreButton
235
314
  aria-label={`More options for ${row.title ?? ''}`}
236
315
  className={classNames(
@@ -14,6 +14,23 @@ export const resolveRowId = (row, fallbackIndex = null) => {
14
14
  export const DATA_TABLE_DROP_TOP_ID = 'data-table-drop-top'
15
15
  export const DATA_TABLE_DROP_BOTTOM_ID = 'data-table-drop-bottom'
16
16
 
17
+ // Mouse drags after a short move; a finger has to hold still first, so a
18
+ // swipe stays a scroll. The touch tolerance sits under the tap slop.
19
+ export const DATA_TABLE_MOUSE_ACTIVATION = { distance: 6 }
20
+ export const DATA_TABLE_TOUCH_ACTIVATION = { delay: 250, tolerance: 8 }
21
+
22
+ export const TOUCH_TAP_SLOP_PX = 10
23
+ export const TOUCH_TAP_SCROLL_GRACE_MS = 100
24
+
25
+ // start/end: { pointerId, x, y, time }; lastScroll: { time } or null.
26
+ export const isTouchTap = (start, end, lastScroll) => {
27
+ if (!start || !end || start.pointerId !== end.pointerId) return false
28
+ if (Math.hypot(end.x - start.x, end.y - start.y) >= TOUCH_TAP_SLOP_PX) {
29
+ return false
30
+ }
31
+ return !lastScroll || lastScroll.time < start.time - TOUCH_TAP_SCROLL_GRACE_MS
32
+ }
33
+
17
34
  export const resolveRowType = (row) => {
18
35
  return (
19
36
  row?.type ??
@@ -1,7 +1,8 @@
1
1
  import { useCallback, useMemo, useState } from 'react'
2
2
  import {
3
+ MouseSensor,
3
4
  pointerWithin,
4
- PointerSensor,
5
+ TouchSensor,
5
6
  useDndMonitor,
6
7
  useSensor,
7
8
  useSensors,
@@ -10,6 +11,8 @@ import {
10
11
  buildReorderPayload,
11
12
  DATA_TABLE_DROP_TOP_ID,
12
13
  DATA_TABLE_DROP_BOTTOM_ID,
14
+ DATA_TABLE_MOUSE_ACTIVATION,
15
+ DATA_TABLE_TOUCH_ACTIVATION,
13
16
  } from './dataTableDnd.utils'
14
17
 
15
18
  const isDataTableDrag = (event, dndScopeId) => {
@@ -72,8 +75,11 @@ export const useDataTableDnd = ({
72
75
  const [activeDragContext, setActiveDragContext] = useState(null)
73
76
 
74
77
  const sensors = useSensors(
75
- useSensor(PointerSensor, {
76
- activationConstraint: { distance: 6 },
78
+ useSensor(MouseSensor, {
79
+ activationConstraint: DATA_TABLE_MOUSE_ACTIVATION,
80
+ }),
81
+ useSensor(TouchSensor, {
82
+ activationConstraint: DATA_TABLE_TOUCH_ACTIVATION,
77
83
  }),
78
84
  )
79
85
 
@@ -1,13 +1,18 @@
1
1
  import { useState, useCallback } from 'react'
2
2
  import {
3
3
  DndContext,
4
- PointerSensor,
4
+ MouseSensor,
5
+ TouchSensor,
5
6
  useSensor,
6
7
  useSensors,
7
8
  pointerWithin,
8
9
  } from '@dnd-kit/core'
9
10
  import { SetlistList } from './SetlistList'
10
11
  import { DataTable } from '../DataTable/DataTable'
12
+ import {
13
+ DATA_TABLE_MOUSE_ACTIVATION,
14
+ DATA_TABLE_TOUCH_ACTIVATION,
15
+ } from '../DataTable/dnd/dataTableDnd.utils'
11
16
 
12
17
  const defaultSetlists = [
13
18
  {
@@ -331,7 +336,12 @@ export const DragFromDataTable = {
331
336
  const [dropLog, setDropLog] = useState([])
332
337
 
333
338
  const sensors = useSensors(
334
- useSensor(PointerSensor, { activationConstraint: { distance: 6 } }),
339
+ useSensor(MouseSensor, {
340
+ activationConstraint: DATA_TABLE_MOUSE_ACTIVATION,
341
+ }),
342
+ useSensor(TouchSensor, {
343
+ activationConstraint: DATA_TABLE_TOUCH_ACTIVATION,
344
+ }),
335
345
  )
336
346
 
337
347
  const handleDragEnd = useCallback(
@@ -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 asChild className={triggerClassName} disabled={disabled}>
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