@moises.ai/design-system 4.21.16 → 4.21.18

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.21.16",
3
+ "version": "4.21.18",
4
4
  "description": "Design System package based on @radix-ui/themes with custom defaults",
5
5
  "private": false,
6
6
  "type": "module",
@@ -1,4 +1,4 @@
1
- import { forwardRef, useMemo } from 'react'
1
+ import { forwardRef, useLayoutEffect, useMemo, useRef, useState } from 'react'
2
2
  import classNames from 'classnames'
3
3
  import { Text } from '../Text/Text'
4
4
  import { Tooltip } from '../Tooltip/Tooltip'
@@ -33,7 +33,7 @@ import styles from './InstrumentSelect.module.css'
33
33
  * @property {InstrumentSelectValue} [selectedValue] - Alias for `value` (backwards-compat with `InstrumentSelector`).
34
34
  * @property {(item: InstrumentSelectItem) => void} [onSelect] - Fires for every card click, including locked items. The parent decides whether to update `value`, open a paywall, etc.
35
35
  * @property {'horizontal' | 'vertical'} [orientation='horizontal'] - `horizontal` fills each row left to right, then wraps. `vertical` fills each column top to bottom, for `rows` rows, then starts the next column.
36
- * @property {number | { initial?: string | number, sm?: string | number, md?: string | number, lg?: string | number }} [columns=2] - Horizontal only. Maximum items per row. If the container cannot fit that many at the card's minimum width, the extras wrap onto the next row.
36
+ * @property {number | { initial?: string | number, sm?: string | number, md?: string | number, lg?: string | number }} [columns=2] - Horizontal only. Number of column tracks in the row. A short row stretches so its items split those tracks: 2 items in 4 columns means each item spans 2. If the container cannot fit that many tracks at the card's minimum width, the row uses fewer tracks and wraps.
37
37
  * @property {number} [rows] - Vertical only. How many rows to fill before starting another column. Defaults to one column (every item on its own row).
38
38
  * @property {'neutral' | 'cyan'} [variant='neutral'] - Visual variant. `neutral` is the default bordered card. `cyan` uses the accent-tinted background and selection border.
39
39
  * @property {'small' | 'medium' | 'large'} [size='small'] - Card size. `small` is the compact horizontal card. `medium` is the 64px vertical card (min 150px). `large` is the 160×80 vertical card.
@@ -70,6 +70,27 @@ const TRACK_MAX = {
70
70
  large: 160,
71
71
  }
72
72
 
73
+ function columnsThatFit(width, columns, min, gap) {
74
+ if (!width) return columns
75
+ const count = Math.floor((width + gap) / (min + gap))
76
+ return Math.max(1, Math.min(columns, count))
77
+ }
78
+
79
+ /**
80
+ * How many of `columnCount` tracks this item spans. A row with fewer items than
81
+ * tracks splits the tracks across those items (2 items in 4 columns span 2 each).
82
+ */
83
+ function itemColumnSpan(index, itemCount, columnCount) {
84
+ const rowStart = Math.floor(index / columnCount) * columnCount
85
+ const remaining = itemCount - rowStart
86
+ const inRow = Math.min(columnCount, remaining)
87
+ if (inRow >= columnCount) return 1
88
+ const base = Math.floor(columnCount / inRow)
89
+ const extra = columnCount % inRow
90
+ const indexInRow = index - rowStart
91
+ return base + (indexInRow >= inRow - extra ? 1 : 0)
92
+ }
93
+
73
94
  function resolveColumns(columns) {
74
95
  if (typeof columns === 'number' && Number.isFinite(columns)) return Math.max(1, columns)
75
96
  if (columns && typeof columns === 'object') {
@@ -87,13 +108,12 @@ function resolveColumns(columns) {
87
108
  *
88
109
  * Vertical fills `rows` rows top to bottom, then starts the next column.
89
110
  */
90
- function getGridStyle(orientation, size, columns, rows, itemCount, fit) {
111
+ function getGridStyle(orientation, size, columns, rows, itemCount, fit, trackCount) {
91
112
  const min = TRACK_MIN[size] ?? TRACK_MIN.small
92
113
  const fill = fit === 'fill' || size === 'small'
93
114
  const max = fill ? undefined : TRACK_MAX[size]
94
115
  const gap = gridGap(size)
95
116
  const gaps = Math.max(columns - 1, 0)
96
- const share = `calc((100% - ${gap}px * ${gaps}) / ${columns})`
97
117
 
98
118
  if (orientation === 'vertical') {
99
119
  const rowCount = Math.max(rows ?? itemCount, 1)
@@ -114,8 +134,7 @@ function getGridStyle(orientation, size, columns, rows, itemCount, fit) {
114
134
  return {
115
135
  display: 'grid',
116
136
  gap,
117
- gridTemplateColumns: `repeat(auto-fit, minmax(max(${min}px, ${share}), 1fr))`,
118
- justifyContent: 'stretch',
137
+ gridTemplateColumns: `repeat(${trackCount}, minmax(0, 1fr))`,
119
138
  width: '100%',
120
139
  }
121
140
  }
@@ -194,14 +213,32 @@ export const InstrumentSelect = forwardRef(function InstrumentSelect(
194
213
  ref,
195
214
  ) {
196
215
  const resolvedValue = value ?? selectedValue
216
+ const gridRef = useRef(null)
217
+ const [gridWidth, setGridWidth] = useState(0)
197
218
 
198
219
  const cols = useMemo(() => resolveColumns(columns), [columns])
199
220
 
200
221
  const fill = fit === 'fill' || size === 'small'
222
+ const minTrack = TRACK_MIN[size] ?? TRACK_MIN.small
223
+ const gap = gridGap(size)
224
+ const trackCount =
225
+ fill && orientation === 'horizontal'
226
+ ? columnsThatFit(gridWidth, cols, minTrack, gap)
227
+ : cols
228
+
229
+ useLayoutEffect(() => {
230
+ const element = gridRef.current
231
+ if (!element || !fill || orientation !== 'horizontal') return undefined
232
+ const update = () => setGridWidth(element.clientWidth)
233
+ update()
234
+ const observer = new ResizeObserver(update)
235
+ observer.observe(element)
236
+ return () => observer.disconnect()
237
+ }, [fill, orientation, cols, size, items.length])
201
238
 
202
239
  const gridStyle = useMemo(
203
- () => getGridStyle(orientation, size, cols, rows, items.length, fit),
204
- [orientation, size, cols, rows, items.length, fit],
240
+ () => getGridStyle(orientation, size, cols, rows, items.length, fit, trackCount),
241
+ [orientation, size, cols, rows, items.length, fit, trackCount],
205
242
  )
206
243
 
207
244
  return (
@@ -220,6 +257,7 @@ export const InstrumentSelect = forwardRef(function InstrumentSelect(
220
257
  )}
221
258
 
222
259
  <div
260
+ ref={gridRef}
223
261
  className={styles.grid}
224
262
  data-orientation={orientation}
225
263
  data-fit={fill ? 'fill' : 'fixed'}
@@ -227,11 +265,15 @@ export const InstrumentSelect = forwardRef(function InstrumentSelect(
227
265
  role="group"
228
266
  aria-label={title}
229
267
  >
230
- {items.map((item) => {
268
+ {items.map((item, index) => {
231
269
  const itemText = item.text ?? item.label ?? item.name
232
270
  const ItemIcon = item.Icon ?? item.icon
233
271
  const itemLocked = item.locked ?? item.isLocked ?? false
234
272
  const itemDisabled = item.disabled ?? false
273
+ const span =
274
+ fill && orientation === 'horizontal'
275
+ ? itemColumnSpan(index, items.length, trackCount)
276
+ : 1
235
277
 
236
278
  return (
237
279
  <InstrumentSelectCard
@@ -245,6 +287,7 @@ export const InstrumentSelect = forwardRef(function InstrumentSelect(
245
287
  disabled={itemDisabled}
246
288
  variant={variant}
247
289
  size={size}
290
+ style={span > 1 ? { gridColumn: `span ${span}` } : undefined}
248
291
  onClick={() => onSelect?.(item)}
249
292
  />
250
293
  )
@@ -252,6 +252,7 @@
252
252
  max-width: 100%;
253
253
  margin-right: 0;
254
254
  font-weight: 500;
255
+ line-height: 18px;
255
256
  }
256
257
 
257
258
  .card[data-size="large"] .cardText {
@@ -267,6 +268,9 @@
267
268
  }
268
269
 
269
270
  .cardBadge {
271
+ position: absolute;
272
+ right: 6px;
273
+ top: 6px;
270
274
  display: flex;
271
275
  flex-shrink: 0;
272
276
  padding: 2px 6px;
@@ -307,6 +307,20 @@ export const Large = {
307
307
  },
308
308
  }
309
309
 
310
+ export const TwoItemsFourColumns = {
311
+ render: verticalStory(['vocals']),
312
+ args: {
313
+ variant: 'cyan',
314
+ size: 'medium',
315
+ fit: 'fill',
316
+ columns: 4,
317
+ items: INSTRUMENTS.slice(0, 2),
318
+ },
319
+ parameters: {
320
+ containerWidth: 640,
321
+ },
322
+ }
323
+
310
324
  export const MediumFill = {
311
325
  render: verticalStory(['vocals']),
312
326
  args: {
@@ -8,16 +8,16 @@ export const KeyboardIcon = ({
8
8
  xmlns="http://www.w3.org/2000/svg"
9
9
  width={width}
10
10
  height={height}
11
- viewBox="0 0 24 16"
11
+ viewBox="0 0 24 24"
12
12
  fill="none"
13
13
  className={className}
14
14
  {...props}
15
- >
15
+ aria-label="Keyboard icon">
16
16
  <path
17
- d="M6.75 11.25H16.75M4.25 8.25H4.26M4.25 4.25H4.26M9.25 8.25H9.26M9.26001 4.25H9.27001M14.25 8.25H14.26M14.25 4.25H14.26M19.25 8.25H19.26M19.25 4.25H19.26M1.85 14.75C1.24249 14.75 0.75 14.2678 0.75 13.6731V1.82692C0.75 1.23215 1.24249 0.75 1.85 0.75H21.65C22.2575 0.75 22.75 1.23215 22.75 1.82692V13.6731C22.75 14.2678 22.2575 14.75 21.65 14.75H1.85Z"
18
- stroke="currentColor"
17
+ d="M7 15.5H17M4.5 12.5H4.51M4.5 8.5H4.51M9.5 12.5H9.51M9.51001 8.5H9.52001M14.5 12.5H14.51M14.5 8.5H14.51M19.5 12.5H19.51M19.5 8.5H19.51M2.1 19C1.49249 19 1 18.5178 1 17.9231V6.07692C1 5.48215 1.49249 5 2.1 5H21.9C22.5075 5 23 5.48215 23 6.07692V17.9231C23 18.5178 22.5075 19 21.9 19H2.1Z"
19
18
  strokeWidth="1.5"
20
19
  strokeLinecap="square"
20
+ stroke="currentColor"
21
21
  />
22
22
  </svg>
23
23
  )