@moises.ai/design-system 3.5.3 → 3.5.4

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": "3.5.3",
3
+ "version": "3.5.4",
4
4
  "description": "Design System package based on @radix-ui/themes with custom defaults",
5
5
  "private": false,
6
6
  "type": "module",
@@ -1,25 +1,59 @@
1
1
  import { Flex, Text, Separator } from '@radix-ui/themes'
2
2
  import styles from './ProjectsList.module.css'
3
- import { useState } from 'react'
3
+ import { useState, createContext, useContext } from 'react'
4
4
  import { ArrowLeftIcon, NoMusicIcon, ChevronDownIcon, ChevronUpIcon } from '../../icons'
5
- import { getIconFromTrackId } from './utils'
5
+ import { getIconFromTrackId, getProjectCover } from './utils'
6
6
  import { Button } from '../Button/Button'
7
7
 
8
+ const ProjectsListContext = createContext({
9
+ onClickTrack: null,
10
+ onInsertAllTracks: null,
11
+ openedItem: null,
12
+ setOpenedItem: () => { },
13
+ })
14
+
8
15
  export const ProjectsList = ({
9
- projects = [],
16
+ children,
10
17
  onClickTrack,
11
18
  onInsertAllTracks,
12
19
  }) => {
13
20
  const [openedItem, setOpenedItem] = useState(null)
21
+
22
+ return (
23
+ <ProjectsListContext.Provider
24
+ value={{
25
+ onClickTrack,
26
+ onInsertAllTracks,
27
+ openedItem,
28
+ setOpenedItem,
29
+ }}
30
+ >
31
+ <Flex direction="column" width="100%">
32
+ {children}
33
+ </Flex>
34
+ </ProjectsListContext.Provider>
35
+ )
36
+ }
37
+
38
+ const ProjectsListItem = ({
39
+ id,
40
+ title,
41
+ artist,
42
+ cover,
43
+ type,
44
+ tracks = [],
45
+ ...props
46
+ }) => {
47
+ const { onClickTrack, onInsertAllTracks, openedItem, setOpenedItem } = useContext(ProjectsListContext)
14
48
  const [showAllTracks, setShowAllTracks] = useState(false)
15
49
 
16
- const handleClickProject = (projectId) => {
50
+ const handleClickProject = () => {
17
51
  setShowAllTracks(false)
18
52
 
19
- if (openedItem === projectId) {
53
+ if (openedItem === id) {
20
54
  setOpenedItem(null)
21
55
  } else {
22
- setOpenedItem(projectId)
56
+ setOpenedItem(id)
23
57
  }
24
58
  }
25
59
 
@@ -29,105 +63,104 @@ export const ProjectsList = ({
29
63
  setShowAllTracks(!showAllTracks)
30
64
  }
31
65
 
66
+ const project = { id, title, artist, cover, type, tracks }
67
+
32
68
  return (
33
- <Flex direction="column" width="100%">
34
- {projects.map((project, index) => (
35
- <Flex
36
- key={project.id}
37
- direction="column"
38
- gap="2"
39
- p="1"
40
- className={`${styles.item} ${openedItem === project.id ? styles.opened : ''}`}
41
- onClick={() => handleClickProject(project.id)}
42
- >
43
- <Flex direction="row" gap="3">
44
- <Flex className={styles.projectCover}>
45
- <img
46
- src={project.cover || `https://picsum.photos/48?random=${index}`}
47
- alt={project.title}
48
- draggable={false}
49
- className={styles.projectCoverImage}
50
- />
51
- </Flex>
69
+ <Flex
70
+ direction="column"
71
+ gap="2"
72
+ p="1"
73
+ className={`${styles.item} ${openedItem === id ? styles.opened : ''}`}
74
+ onClick={handleClickProject}
75
+ {...props}
76
+ >
77
+ <Flex direction="row" gap="3">
78
+ <Flex className={styles.projectCover}>
79
+ <img
80
+ src={getProjectCover(project)}
81
+ alt={title}
82
+ draggable={false}
83
+ className={styles.projectCoverImage}
84
+ />
85
+ </Flex>
52
86
 
53
- <Flex direction="column" gap="1" align="start" justify="center">
54
- <Text size="2" className={styles.projectTitle}>
55
- {project.title}
56
- </Text>
87
+ <Flex direction="column" gap="1" align="start" justify="center">
88
+ <Text size="2" className={styles.projectTitle}>
89
+ {title}
90
+ </Text>
57
91
 
58
- {project.artist && (
59
- <Text size="1" className={styles.projectArtist}>
60
- {project.artist}
61
- </Text>
62
- )}
92
+ {artist && (
93
+ <Text size="1" className={styles.projectArtist}>
94
+ {artist}
95
+ </Text>
96
+ )}
97
+ </Flex>
98
+ </Flex>
99
+
100
+ {openedItem === id && (
101
+ <Flex direction="column">
102
+ {tracks.length === 0 && (
103
+ <Flex direction="row" gap="3" p="5" pt="2" align="center" justify="center">
104
+ <NoMusicIcon width={16} height={16} style={{ color: 'var(--neutral-alpha-10)' }} />
105
+ <Text size="2" style={{ color: 'var(--neutral-alpha-10)' }}>This file has no tracks</Text>
63
106
  </Flex>
64
- </Flex>
65
-
66
- {openedItem === project.id && (
67
- <Flex direction="column">
68
- {project.tracks.length === 0 && (
69
- <Flex direction="row" gap="3" p="5" pt="2" align="center" justify="center">
70
- <NoMusicIcon width={16} height={16} style={{ color: 'var(--neutral-alpha-10)' }} />
71
- <Text size="2" style={{ color: 'var(--neutral-alpha-10)' }}>This file has no tracks</Text>
72
- </Flex>
73
- )}
74
-
75
- {project.tracks.length > 0 && (
76
- <Flex direction="column" gap="1">
77
- {project.tracks.slice(0, showAllTracks ? project.tracks.length : 6).map((track) => (
78
- <Flex
79
- key={track.id}
80
- direction="row"
81
- gap="3"
82
- className={styles.itemTrack}
83
- onClick={(e) => {
84
- e.stopPropagation()
85
- onClickTrack?.(track)
86
- }}
87
- >
88
- <div className={styles.icon}>
89
- <Flex className={styles.iconTrack}>
90
- {getIconFromTrackId(track.id)}
91
- </Flex>
92
- <ArrowLeftIcon width={16} height={16} className={styles.iconArrowLeft} />
93
- </div>
94
-
95
- <Flex direction="column" gap="1" align="start" justify="center">
96
- <Text size="2" className={styles.trackTitle}>
97
- {track.title}
98
- </Text>
99
- </Flex>
100
- </Flex>
101
- ))}
102
-
103
- <Flex direction="row" gap="3" p="2" align="center" justify="center">
104
- <Button variant="ghost" color="neutral" style={{ flex: '1' }}
105
- onClick={(e) => {
106
- e.stopPropagation()
107
- onInsertAllTracks?.(project.tracks)
108
- }}
109
- >
110
- <ArrowLeftIcon width={16} height={16} /> Insert all
111
- </Button>
107
+ )}
112
108
 
113
- {project.tracks.length > 6 && (
114
- <>
115
- <Separator orientation="vertical" />
109
+ {tracks.length > 0 && (
110
+ <Flex direction="column" gap="1">
111
+ {tracks.slice(0, showAllTracks ? tracks.length : 6).map((track) => (
112
+ <Flex
113
+ key={track.id}
114
+ direction="row"
115
+ gap="3"
116
+ className={styles.itemTrack}
117
+ onClick={(e) => {
118
+ e.stopPropagation()
119
+ onClickTrack?.(track)
120
+ }}
121
+ >
122
+ <div className={styles.icon}>
123
+ <Flex className={styles.iconTrack}>
124
+ {getIconFromTrackId(track.id)}
125
+ </Flex>
126
+ <ArrowLeftIcon width={16} height={16} className={styles.iconArrowLeft} />
127
+ </div>
116
128
 
117
- <Button variant="ghost" color="gray" style={{ flex: '1' }} onClick={handleClickShowAllTracks}>
118
- {showAllTracks ? 'Show less' : 'Show more'}
119
- {showAllTracks ? <ChevronUpIcon width={16} height={16} /> : <ChevronDownIcon width={16} height={16} />}
120
- </Button>
121
- </>
122
- )}
129
+ <Flex direction="column" gap="1" align="start" justify="center">
130
+ <Text size="2" className={styles.trackTitle}>
131
+ {track.title}
132
+ </Text>
123
133
  </Flex>
124
134
  </Flex>
125
- )}
135
+ ))}
136
+
137
+ <Flex direction="row" gap="3" p="2" align="center" justify="center">
138
+ <Button variant="ghost" color="neutral" style={{ flex: '1' }}
139
+ onClick={(e) => {
140
+ e.stopPropagation()
141
+ onInsertAllTracks?.(tracks)
142
+ }}
143
+ >
144
+ <ArrowLeftIcon width={16} height={16} /> Insert all
145
+ </Button>
146
+
147
+ {tracks.length > 6 && (
148
+ <>
149
+ <Separator orientation="vertical" />
150
+
151
+ <Button variant="ghost" color="gray" style={{ flex: '1' }} onClick={handleClickShowAllTracks}>
152
+ {showAllTracks ? 'Show less' : 'Show more'}
153
+ {showAllTracks ? <ChevronUpIcon width={16} height={16} /> : <ChevronDownIcon width={16} height={16} />}
154
+ </Button>
155
+ </>
156
+ )}
157
+ </Flex>
126
158
  </Flex>
127
159
  )}
128
160
  </Flex>
129
- ))
130
- }
131
- </Flex >
161
+ )}
162
+ </Flex>
132
163
  )
133
164
  }
165
+
166
+ ProjectsList.Item = ProjectsListItem
@@ -15,11 +15,13 @@ export const Default = {
15
15
  render: (args) => {
16
16
  return (
17
17
  <ProjectsList
18
- {...args}
19
- />
18
+ onClickTrack={args.onClickTrack}
19
+ onInsertAllTracks={args.onInsertAllTracks}
20
+ >
21
+ {projects.map((project) => (
22
+ <ProjectsList.Item key={project.id} {...project} />
23
+ ))}
24
+ </ProjectsList>
20
25
  )
21
26
  },
22
- args: {
23
- projects: projects,
24
- },
25
27
  }
@@ -5,6 +5,7 @@ export const projects = [
5
5
  "artist": "NPR Music: Tiny Desk Concert",
6
6
  "cover": null,
7
7
  "duration": 30.72,
8
+ "type": "studio",
8
9
  "tracks": [
9
10
  {
10
11
  "id": "q8pzli0h38ptcxq09h2al",
@@ -29,6 +30,7 @@ export const projects = [
29
30
  "artist": null,
30
31
  "cover": null,
31
32
  "duration": 19.924,
33
+ "type": "stems",
32
34
  "tracks": [
33
35
  {
34
36
  "id": "original",
@@ -143,6 +145,7 @@ export const projects = [
143
145
  "artist": null,
144
146
  "cover": null,
145
147
  "duration": 1062.0343,
148
+ "type": "master",
146
149
  "tracks": []
147
150
  },
148
151
  {
@@ -151,6 +154,7 @@ export const projects = [
151
154
  "artist": null,
152
155
  "cover": null,
153
156
  "duration": 227.0215,
157
+ "type": "voice",
154
158
  "tracks": [
155
159
  {
156
160
  "id": "bass",
@@ -170,6 +174,7 @@ export const projects = [
170
174
  "artist": "Led Zeppelin",
171
175
  "cover": "https://d1-stage.moises.ai/v3/download/moises-stage--tasks2/operations/FILEMETADATA_A/76477978-88b0-4dd1-b729-ad760b9f1b9c/cover.jpeg",
172
176
  "duration": 296.8065,
177
+ "type": "lyrics",
173
178
  "tracks": [
174
179
  {
175
180
  "id": "bass",
@@ -182,5 +187,24 @@ export const projects = [
182
187
  "audioUrl": "https://d2-stage.moises.ai/v3/download/moises-stage--tasks2/operations/SEPARATE_CUSTOM/e4325003-662f-4aeb-b75a-14797654828a/other.m4a"
183
188
  }
184
189
  ]
190
+ },
191
+ {
192
+ "id": "3612a6132234-b86c-408e-b23296-b9f0f22dbeb108",
193
+ "title": "Project without cover and type",
194
+ "artist": null,
195
+ "cover": null,
196
+ "duration": 227.0215,
197
+ "tracks": [
198
+ {
199
+ "id": "bass",
200
+ "title": "bass",
201
+ "audioUrl": "https://d2-stage.moises.ai/v3/download/moises-stage--tasks2/operations/SEPARATE_CUSTOM/09239f2d-f93f-4924-86a0-2277e5ba35ea/bass.m4a"
202
+ },
203
+ {
204
+ "id": "other",
205
+ "title": "other",
206
+ "audioUrl": "https://d3-stage.moises.ai/v3/download/moises-stage--tasks2/operations/SEPARATE_CUSTOM/09239f2d-f93f-4924-86a0-2277e5ba35ea/other.m4a"
207
+ }
208
+ ]
185
209
  }
186
210
  ]
@@ -19,6 +19,11 @@ import {
19
19
  MusicIcon,
20
20
  SparkBarsIcon,
21
21
  } from '../../icons'
22
+ import thumbCoverLyrics from './assets/images/thumb-song-lyrics.jpg'
23
+ import thumbCoverMaster from './assets/images/thumb-song-master.jpg'
24
+ import thumbCoverStems from './assets/images/thumb-song-stems.jpg'
25
+ import thumbCoverStudio from './assets/images/thumb-song-studio.jpg'
26
+ import thumbCoverVoice from './assets/images/thumb-song-voice.jpg'
22
27
 
23
28
  export const getIconFromTrackId = (trackId) => {
24
29
  switch (trackId) {
@@ -68,3 +73,24 @@ export const getIconFromTrackId = (trackId) => {
68
73
  return <SparkBarsIcon width={16} height={16} />
69
74
  }
70
75
  }
76
+
77
+ export const getProjectCover = (project) => {
78
+ if (project?.cover) {
79
+ return project.cover
80
+ }
81
+
82
+ switch (project?.type) {
83
+ case 'studio':
84
+ return thumbCoverStudio
85
+ case 'stems':
86
+ return thumbCoverStems
87
+ case 'voice':
88
+ return thumbCoverVoice
89
+ case 'master':
90
+ return thumbCoverMaster
91
+ case 'lyrics':
92
+ return thumbCoverLyrics
93
+ default:
94
+ return thumbCoverLyrics
95
+ }
96
+ }