@moises.ai/design-system 4.20.4 → 4.20.6

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.20.4",
3
+ "version": "4.20.6",
4
4
  "description": "Design System package based on @radix-ui/themes with custom defaults",
5
5
  "private": false,
6
6
  "type": "module",
@@ -1,5 +1,7 @@
1
- import { useMemo } from 'react'
1
+ import { useState, useMemo, useRef, useEffect, useCallback } from 'react'
2
2
  import { Box, Flex, Heading, Text, Grid, Card } from '@radix-ui/themes'
3
+ import { CheckCircledIcon, CopyIcon, CheckIcon } from '@radix-ui/react-icons'
4
+ import { Callout } from '../components/Callout/Callout'
3
5
  import cssSource from './custom-styles.css?raw'
4
6
 
5
7
  function isColorValue(value) {
@@ -7,84 +9,26 @@ function isColorValue(value) {
7
9
  return v.startsWith('#') || /^rgba?\(/i.test(v)
8
10
  }
9
11
 
10
- function clampByte(n) {
11
- return Math.round(Math.min(255, Math.max(0, n)))
12
- }
13
-
14
- function rgbaToHex(r, g, b, a = 1) {
15
- const toHex = (n) => clampByte(n).toString(16).padStart(2, '0').toUpperCase()
16
- let hex = `#${toHex(r)}${toHex(g)}${toHex(b)}`
17
- if (a < 1) {
18
- hex += toHex(a * 255)
12
+ function getNeutralSection(name) {
13
+ if (name.startsWith('--neutral-alpha-0')) {
14
+ return 'Neutral Extras'
19
15
  }
20
- return hex
21
- }
22
-
23
- function parseColorFormats(cssValue) {
24
- const v = cssValue.trim()
25
- if (v.startsWith('#')) {
26
- let h = v.slice(1)
27
- if (h.length === 3) {
28
- h = h
29
- .split('')
30
- .map((c) => c + c)
31
- .join('')
32
- }
33
- if (h.length === 6) {
34
- const r = parseInt(h.slice(0, 2), 16)
35
- const g = parseInt(h.slice(2, 4), 16)
36
- const b = parseInt(h.slice(4, 6), 16)
37
- return {
38
- rgba: `rgba(${r}, ${g}, ${b}, 1)`,
39
- hex: `#${h.toUpperCase()}`,
40
- }
41
- }
42
- if (h.length === 8) {
43
- const r = parseInt(h.slice(0, 2), 16)
44
- const g = parseInt(h.slice(2, 4), 16)
45
- const b = parseInt(h.slice(4, 6), 16)
46
- const alpha = parseInt(h.slice(6, 8), 16) / 255
47
- const aRounded = Math.round(alpha * 1000) / 1000
48
- return {
49
- rgba: `rgba(${r}, ${g}, ${b}, ${aRounded})`,
50
- hex: `#${h.toUpperCase()}`,
51
- }
52
- }
53
- return { rgba: v, hex: v }
16
+ if (name.startsWith('--neutral-alpha-')) {
17
+ return 'Neutral Alpha'
54
18
  }
55
-
56
- const m = v.match(
57
- /^rgba?\(\s*([\d.]+)\s*,\s*([\d.]+)\s*,\s*([\d.]+)(?:\s*,\s*([\d.]+))?\s*\)$/i,
58
- )
59
- if (m) {
60
- const r = Number(m[1])
61
- const g = Number(m[2])
62
- const b = Number(m[3])
63
- const a = m[4] !== undefined ? Number(m[4]) : 1
64
- const aRounded = Math.round(a * 1000) / 1000
65
- return {
66
- rgba: `rgba(${r}, ${g}, ${b}, ${aRounded})`,
67
- hex: rgbaToHex(r, g, b, a),
68
- }
19
+ if (name.startsWith('--neutral-')) {
20
+ return 'Neutral (Solid)'
69
21
  }
70
-
71
- return { rgba: v, hex: '—' }
22
+ return null
72
23
  }
73
24
 
74
- function parseColorTokens(css) {
25
+ function parseNeutralColorTokens(css) {
75
26
  const lines = css.split('\n')
76
27
  /** @type {{ section: string; name: string; value: string }[]} */
77
28
  const tokens = []
78
- let section = 'Cores'
79
29
 
80
30
  for (const line of lines) {
81
31
  const trimmed = line.trim()
82
- const sectionMatch = trimmed.match(/^\/\*\s*([^*]+?)\s*\*\/$/)
83
- if (sectionMatch && !trimmed.includes('--')) {
84
- section = sectionMatch[1].trim()
85
- continue
86
- }
87
-
88
32
  const varMatch = trimmed.match(/^--([\w-]+)\s*:\s*([^;]+);/)
89
33
  if (!varMatch) continue
90
34
 
@@ -92,6 +36,10 @@ function parseColorTokens(css) {
92
36
  const value = varMatch[2].trim()
93
37
  if (value.startsWith('var(')) continue
94
38
  if (!isColorValue(value)) continue
39
+ if (!name.startsWith('--neutral-')) continue
40
+
41
+ const section = getNeutralSection(name)
42
+ if (!section) continue
95
43
 
96
44
  tokens.push({ section, name, value })
97
45
  }
@@ -117,18 +65,64 @@ export default {
117
65
  }
118
66
 
119
67
  export const Colors = () => {
68
+ const [copiedVar, setCopiedVar] = useState(null)
69
+ const timeoutRef = useRef(null)
70
+
120
71
  const sections = useMemo(() => {
121
- const tokens = parseColorTokens(cssSource)
72
+ const tokens = parseNeutralColorTokens(cssSource)
122
73
  return groupBySection(tokens)
123
74
  }, [])
124
75
 
76
+ const handleCopy = useCallback((name) => {
77
+ const textToCopy = `var(${name})`
78
+ navigator.clipboard.writeText(textToCopy)
79
+ setCopiedVar(textToCopy)
80
+
81
+ if (timeoutRef.current) {
82
+ clearTimeout(timeoutRef.current)
83
+ }
84
+
85
+ timeoutRef.current = setTimeout(() => {
86
+ setCopiedVar(null)
87
+ }, 3000)
88
+ }, [])
89
+
90
+ useEffect(() => {
91
+ return () => {
92
+ if (timeoutRef.current) {
93
+ clearTimeout(timeoutRef.current)
94
+ }
95
+ }
96
+ }, [])
97
+
125
98
  return (
126
- <Box p="6" style={{ maxWidth: 1200, margin: '0 auto' }}>
99
+ <Box p="6" style={{ maxWidth: 1200, margin: '0 auto', position: 'relative' }}>
100
+ {copiedVar && (
101
+ <Box
102
+ style={{
103
+ position: 'fixed',
104
+ top: 24,
105
+ right: 24,
106
+ zIndex: 9999,
107
+ maxWidth: 420,
108
+ boxShadow: '0 8px 24px rgba(0, 0, 0, 0.4)',
109
+ }}
110
+ >
111
+ <Callout
112
+ color="success"
113
+ size="2"
114
+ Icon={CheckCircledIcon}
115
+ title="Copied to clipboard"
116
+ text={copiedVar}
117
+ />
118
+ </Box>
119
+ )}
120
+
127
121
  <Flex direction="column" gap="6">
128
122
  <Flex direction="column" gap="2">
129
- <Heading size="8">Cores</Heading>
123
+ <Heading size="8">Neutral Colors</Heading>
130
124
  <Text size="3" color="gray">
131
- Variáveis CSS do design system com rgba e hex.
125
+ Design system neutral color CSS variables. Click any card to copy its CSS variable.
132
126
  </Text>
133
127
  </Flex>
134
128
 
@@ -137,9 +131,29 @@ export const Colors = () => {
137
131
  <Heading size="5">{section}</Heading>
138
132
  <Grid columns="1" gap="2">
139
133
  {tokens.map(({ name, value }) => {
140
- const { rgba, hex } = parseColorFormats(value)
134
+ const varText = `var(${name})`
135
+ const isCopied = copiedVar === varText
136
+
141
137
  return (
142
- <Card key={name} size="1">
138
+ <Card
139
+ key={name}
140
+ size="1"
141
+ onClick={() => handleCopy(name)}
142
+ onKeyDown={(e) => {
143
+ if (e.key === 'Enter' || e.key === ' ') {
144
+ e.preventDefault()
145
+ handleCopy(name)
146
+ }
147
+ }}
148
+ tabIndex={0}
149
+ role="button"
150
+ aria-label={`Copy ${varText}`}
151
+ style={{
152
+ cursor: 'pointer',
153
+ transition: 'border-color 0.15s ease, background-color 0.15s ease',
154
+ outline: 'none',
155
+ }}
156
+ >
143
157
  <Grid
144
158
  columns={{ initial: '1', sm: 'auto 1fr' }}
145
159
  gap="3"
@@ -159,9 +173,10 @@ export const Colors = () => {
159
173
  aria-hidden
160
174
  />
161
175
  <Grid
162
- columns={{ initial: '1', xs: '1fr 1fr' }}
176
+ columns={{ initial: '1', xs: '1fr 1fr auto' }}
163
177
  gap="2"
164
178
  width="100%"
179
+ align="center"
165
180
  >
166
181
  <Flex direction="column" gap="1" minWidth="0">
167
182
  <Text
@@ -174,22 +189,28 @@ export const Colors = () => {
174
189
  >
175
190
  {name}
176
191
  </Text>
177
- <Text
178
- size="1"
179
- color="gray"
180
- style={{ fontFamily: 'ui-monospace, monospace' }}
181
- >
182
- {rgba}
183
- </Text>
184
192
  </Flex>
185
193
  <Flex align="center">
186
194
  <Text
187
195
  size="2"
196
+ color="gray"
188
197
  style={{ fontFamily: 'ui-monospace, monospace' }}
189
198
  >
190
- {hex}
199
+ {value}
191
200
  </Text>
192
201
  </Flex>
202
+ <Flex align="center" justify="end" pr="2">
203
+ {isCopied ? (
204
+ <Flex align="center" gap="1">
205
+ <CheckIcon color="var(--mint-9)" width={16} height={16} />
206
+ <Text size="1" color="green" style={{ fontFamily: 'ui-monospace, monospace' }}>
207
+ Copied
208
+ </Text>
209
+ </Flex>
210
+ ) : (
211
+ <CopyIcon color="var(--neutral-9)" width={16} height={16} />
212
+ )}
213
+ </Flex>
193
214
  </Grid>
194
215
  </Grid>
195
216
  </Card>
@@ -1,4 +1,5 @@
1
1
  import { Flex, Text, Separator, Spinner, Button } from '@radix-ui/themes'
2
+ import { Collapsible } from 'radix-ui'
2
3
  import { useState, useContext, useCallback, useMemo } from 'react'
3
4
  import { ArrowLeftIcon, NoMusicIcon, ChevronDownIcon, ChevronUpIcon, InfoIcon } from '../../../icons'
4
5
  import { ProjectsListContext } from '../context'
@@ -27,19 +28,18 @@ const ProjectItem = ({
27
28
  } = useContext(ProjectsListContext)
28
29
  const [showAllTracks, setShowAllTracks] = useState(false)
29
30
 
30
- const tracks = useMemo(() => {
31
- return showAllTracks ? allTracks : allTracks.slice(0, 6)
32
- }, [allTracks, showAllTracks])
31
+ const visibleTracks = useMemo(() => allTracks.slice(0, 6), [allTracks])
32
+ const extraTracks = useMemo(() => allTracks.slice(6), [allTracks])
33
33
 
34
34
  const handleClickProject = useCallback(() => {
35
35
  if (failed) return
36
- setShowAllTracks(false)
37
36
  const project = projects.find((p) => p.id === id)
38
37
 
39
38
  if (openedItem === id) {
40
39
  setOpenedItem(null)
41
40
  onProjectClick?.(project, false)
42
41
  } else {
42
+ setShowAllTracks(false)
43
43
  setOpenedItem(id)
44
44
  onProjectClick?.(project, true)
45
45
  }
@@ -65,7 +65,6 @@ const ProjectItem = ({
65
65
  return (
66
66
  <Flex
67
67
  direction="column"
68
- gap="2"
69
68
  p="1"
70
69
  className={`${styles.item} ${openedItem === id ? styles.opened : ''} ${failed ? styles.failed : ''}`}
71
70
  onClick={handleClickProject}
@@ -104,48 +103,63 @@ const ProjectItem = ({
104
103
  </Flex>
105
104
  </Flex>
106
105
 
107
- {openedItem === id && (
108
- <Flex direction="column">
109
- {type !== 'voice' && allTracks.length === 0 && !loading && (
110
- <Flex direction="row" gap="3" p="5" pt="2" align="center" justify="center">
111
- <NoMusicIcon width={16} height={16} style={{ color: 'var(--neutral-alpha-10)' }} />
112
- <Text size="2" style={{ color: 'var(--neutral-alpha-10)' }}>{labels.noTracks || 'This file has no tracks'}</Text>
113
- </Flex>
114
- )}
115
-
116
- {loading && (
117
- <Flex direction="row" gap="3" p="5" align="center" justify="center">
118
- <Spinner width={16} height={16} style={{ color: 'var(--neutral-alpha-10)' }} />
119
- <Text size="2" style={{ color: 'var(--neutral-alpha-10)' }}>{labels.loading || 'Loading tracks...'}</Text>
120
- </Flex>
121
- )}
122
-
123
- {allTracks.length > 0 && (
124
- <Flex direction="column" gap="1">
125
- {typeof children === 'function' ? children({ projectId: id, tracks }) : children}
106
+ <Collapsible.Root open={openedItem === id} className={styles.tracksCollapsible}>
107
+ <Collapsible.Content className={styles.tracksContent}>
108
+ <Flex direction="column" pt="2" style={{ border: '1px solid green' }}>
109
+ {type !== 'voice' && allTracks.length === 0 && !loading && (
110
+ <Flex direction="row" gap="3" p="5" pt="2" align="center" justify="center">
111
+ <NoMusicIcon width={16} height={16} style={{ color: 'var(--neutral-alpha-10)' }} />
112
+ <Text size="2" style={{ color: 'var(--neutral-alpha-10)' }}>{labels.noTracks || 'This file has no tracks'}</Text>
113
+ </Flex>
114
+ )}
126
115
 
127
- <Flex direction="row" gap="3" p="2" align="center" justify="center">
128
- <Button variant="ghost" color="gray" style={{ flex: '1' }}
129
- onClick={handleInsertAllTracks}
130
- >
131
- <ArrowLeftIcon width={16} height={16} /> {labels.insertAll || 'Insert all'}
132
- </Button>
116
+ {loading && (
117
+ <Flex direction="row" gap="3" p="5" align="center" justify="center">
118
+ <Spinner width={16} height={16} style={{ color: 'var(--neutral-alpha-10)' }} />
119
+ <Text size="2" style={{ color: 'var(--neutral-alpha-10)' }}>{labels.loading || 'Loading tracks...'}</Text>
120
+ </Flex>
121
+ )}
133
122
 
134
- {allTracks.length > 6 && (
123
+ {allTracks.length > 0 && (
124
+ <Flex direction="column" gap="1">
125
+ {typeof children === 'function' ? (
135
126
  <>
136
- <Separator orientation="vertical" />
137
-
138
- <Button variant="ghost" color="gray" style={{ flex: '1' }} onClick={handleClickShowAllTracks}>
139
- {showAllTracks ? labels.showLess || 'Show less' : labels.showMore || 'Show more'}
140
- {showAllTracks ? <ChevronUpIcon width={16} height={16} /> : <ChevronDownIcon width={16} height={16} />}
141
- </Button>
127
+ {children({ projectId: id, tracks: visibleTracks })}
128
+ {extraTracks.length > 0 && (
129
+ <Collapsible.Root open={showAllTracks} className={styles.extraTracksCollapsible}>
130
+ <Collapsible.Content className={styles.tracksContent}>
131
+ <Flex direction="column" gap="1" className={styles.extraTracksInner}>
132
+ {children({ projectId: id, tracks: extraTracks })}
133
+ </Flex>
134
+ </Collapsible.Content>
135
+ </Collapsible.Root>
136
+ )}
142
137
  </>
143
- )}
138
+ ) : children}
139
+
140
+ <Flex direction="row" gap="3" p="2" align="center" justify="center">
141
+ <Button variant="ghost" color="gray" style={{ flex: '1' }}
142
+ onClick={handleInsertAllTracks}
143
+ >
144
+ <ArrowLeftIcon width={16} height={16} /> {labels.insertAll || 'Insert all'}
145
+ </Button>
146
+
147
+ {allTracks.length > 6 && (
148
+ <>
149
+ <Separator orientation="vertical" />
150
+
151
+ <Button variant="ghost" color="gray" style={{ flex: '1' }} onClick={handleClickShowAllTracks}>
152
+ {showAllTracks ? labels.showLess || 'Show less' : labels.showMore || 'Show more'}
153
+ {showAllTracks ? <ChevronUpIcon width={16} height={16} /> : <ChevronDownIcon width={16} height={16} />}
154
+ </Button>
155
+ </>
156
+ )}
157
+ </Flex>
144
158
  </Flex>
145
- </Flex>
146
- )}
147
- </Flex>
148
- )}
159
+ )}
160
+ </Flex>
161
+ </Collapsible.Content>
162
+ </Collapsible.Root>
149
163
  </Flex>
150
164
  )
151
165
  }
@@ -51,3 +51,47 @@
51
51
  background: rgba(216, 244, 246, 0.04);
52
52
  }
53
53
  }
54
+
55
+ .tracksCollapsible {
56
+ width: 100%;
57
+ }
58
+
59
+ .extraTracksCollapsible {
60
+ width: 100%;
61
+ margin-top: calc(-1 * var(--space-1));
62
+ }
63
+
64
+ .extraTracksInner {
65
+ padding-top: var(--space-1);
66
+ }
67
+
68
+ .tracksContent {
69
+ overflow: hidden;
70
+ width: 100%;
71
+ }
72
+
73
+ .tracksContent[data-state='open'] {
74
+ animation: projectItemSlideDown 0.3s ease;
75
+ }
76
+
77
+ .tracksContent[data-state='closed'] {
78
+ animation: projectItemSlideUp 0.3s ease;
79
+ }
80
+
81
+ @keyframes projectItemSlideDown {
82
+ from {
83
+ height: 0;
84
+ }
85
+ to {
86
+ height: var(--radix-collapsible-content-height);
87
+ }
88
+ }
89
+
90
+ @keyframes projectItemSlideUp {
91
+ from {
92
+ height: var(--radix-collapsible-content-height);
93
+ }
94
+ to {
95
+ height: 0;
96
+ }
97
+ }
@@ -1,7 +1,11 @@
1
1
  export const AssistSectionsIcon = ({ width = 16, height = 16, className, ...props }) => (
2
2
  <svg xmlns="http://www.w3.org/2000/svg" width={width} height={height} viewBox="0 0 24 24" fill="none" className={className} {...props} aria-label="AssistSectionsIcon">
3
- <path d="M3.38 20H20.63M7.73841 4H16.2617C17.2704 4 18.0881 4.78208 18.0881 5.74683V11.0284C18.0881 11.9932 17.2704 12.7753 16.2617 12.7753H9.86027C8.97862 12.7753 7.94436 13.2318 7.41791 14.5874C7.31105 14.8625 7.16461 15.1239 6.95128 15.328C6.56776 15.6948 5.91199 15.435 5.91199 14.9162V5.74683C5.91199 4.78208 6.7297 4 7.73841 4Z" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"/>
4
- </svg>
3
+ <path fillRule="evenodd" clipRule="evenodd" d="M5.64697 5.06836C6.49071 5.06836 6.93604 5.44339 7.2583 6.39844L9.02197 11.584C9.12744 11.9121 9.18018 12.1465 9.18018 12.3516C9.18018 12.8613 8.81689 13.1895 8.26025 13.1895C7.7447 13.1894 7.44579 12.9082 7.25244 12.2461L6.94775 11.291H4.2583L3.94775 12.2461C3.7544 12.9258 3.479 13.1895 2.96338 13.1895C2.4361 13.1894 2.07275 12.8613 2.07275 12.3926C2.07275 12.1992 2.1255 11.9765 2.26025 11.584L4.02979 6.39844C4.34618 5.44926 4.8033 5.0684 5.64697 5.06836ZM4.65674 9.89062H6.55518L5.65869 6.86133H5.56494L4.65674 9.89062Z"
4
+ fill="currentColor"/>
5
+ <path fillRule="evenodd" clipRule="evenodd" d="M18.9478 5.12695C20.4595 5.12695 21.4087 5.88281 21.4087 7.08984C21.4087 8.00391 20.8579 8.67188 19.979 8.83594V8.92383C21.0513 8.99414 21.7896 9.7793 21.7896 10.8574C21.7896 12.2168 20.6763 13.125 19.0063 13.125H16.5278C15.7955 13.125 15.4028 12.7382 15.4028 12.0176V6.23438C15.4028 5.51957 15.7955 5.127 16.5278 5.12695H18.9478ZM17.3188 11.7539H18.356C19.3931 11.7539 19.8208 11.3496 19.8208 10.6992C19.8208 10.0488 19.3931 9.62109 18.5493 9.62109H17.3188V11.7539ZM17.3188 8.37891H18.2505C19.1353 8.37891 19.5161 7.99219 19.5161 7.42383C19.5161 6.86133 19.1294 6.49805 18.4556 6.49805H17.3188V8.37891Z"
6
+ fill="currentColor"/>
7
+ <path d="M11.9945 15.25L12.0045 3M3.37952 20H20.6295" stroke="currentColor" strokeWidth="1.8" strokeLinecap="round" strokeLinejoin="round"/>
8
+ </svg>
5
9
  )
6
10
 
7
11
  AssistSectionsIcon.displayName = 'AssistSectionsIcon'