@moises.ai/design-system 3.6.23 → 3.6.25

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.6.23",
3
+ "version": "3.6.25",
4
4
  "description": "Design System package based on @radix-ui/themes with custom defaults",
5
5
  "private": false,
6
6
  "type": "module",
@@ -1,36 +1,44 @@
1
1
  import { Flex, Text, Separator } from '@radix-ui/themes'
2
2
  import styles from './ProjectsList.module.css'
3
- import { useState, createContext, useContext } from 'react'
3
+ import { useState, createContext, useContext, useCallback } from 'react'
4
4
  import { ArrowLeftIcon, NoMusicIcon, ChevronDownIcon, ChevronUpIcon } from '../../icons'
5
5
  import { getIconFromTrackId } from './utils'
6
6
  import { Button } from '../Button/Button'
7
7
  import { ProductsBrandPattern } from '../ProductsBrandPattern/ProductsBrandPattern'
8
8
 
9
9
  const ProjectsListContext = createContext({
10
+ projects: [],
10
11
  onClickTrack: null,
11
12
  onInsertAllTracks: null,
13
+ onProjectClick: null,
12
14
  openedItem: null,
13
15
  setOpenedItem: () => { },
14
16
  })
15
17
 
16
18
  export const ProjectsList = ({
17
19
  children,
20
+ projects = [],
18
21
  onClickTrack,
19
22
  onInsertAllTracks,
23
+ onProjectClick
20
24
  }) => {
21
25
  const [openedItem, setOpenedItem] = useState(null)
22
26
 
27
+ const content = typeof children === 'function' ? children(projects) : children
28
+
23
29
  return (
24
30
  <ProjectsListContext.Provider
25
31
  value={{
32
+ projects,
26
33
  onClickTrack,
27
34
  onInsertAllTracks,
35
+ onProjectClick,
28
36
  openedItem,
29
37
  setOpenedItem,
30
38
  }}
31
39
  >
32
40
  <Flex direction="column" width="100%">
33
- {children}
41
+ {content}
34
42
  </Flex>
35
43
  </ProjectsListContext.Provider>
36
44
  )
@@ -45,24 +53,27 @@ const ProjectsListItem = ({
45
53
  tracks = [],
46
54
  ...props
47
55
  }) => {
48
- const { onClickTrack, onInsertAllTracks, openedItem, setOpenedItem } = useContext(ProjectsListContext)
56
+ const { projects, onClickTrack, onInsertAllTracks, onProjectClick, openedItem, setOpenedItem } = useContext(ProjectsListContext)
49
57
  const [showAllTracks, setShowAllTracks] = useState(false)
50
58
 
51
- const handleClickProject = () => {
59
+ const handleClickProject = useCallback(() => {
52
60
  setShowAllTracks(false)
61
+ const project = projects.find((p) => p.id === id)
53
62
 
54
63
  if (openedItem === id) {
55
64
  setOpenedItem(null)
65
+ onProjectClick?.(project, false)
56
66
  } else {
57
67
  setOpenedItem(id)
68
+ onProjectClick?.(project, true)
58
69
  }
59
- }
70
+ }, [id, openedItem, setOpenedItem, onProjectClick, projects])
60
71
 
61
- const handleClickShowAllTracks = (e) => {
72
+ const handleClickShowAllTracks = useCallback((e) => {
62
73
  e.preventDefault()
63
74
  e.stopPropagation()
64
75
  setShowAllTracks(!showAllTracks)
65
- }
76
+ }, [showAllTracks])
66
77
 
67
78
 
68
79
  return (
@@ -6,21 +6,39 @@ export default {
6
6
  component: ProjectsList,
7
7
  tags: ['autodocs'],
8
8
  argTypes: {
9
+ projects: { control: false },
9
10
  onClickTrack: { action: 'track-clicked' },
10
11
  onInsertAllTracks: { action: 'insert-all-tracks' },
11
12
  },
12
13
  }
13
14
 
14
15
  export const Default = {
16
+ args: {
17
+ projects,
18
+ onProjectClick: (project, opened) => {
19
+ console.log('project', project)
20
+ console.log('opened', opened)
21
+ },
22
+ onClickTrack: (track) => {
23
+ console.log('track', track)
24
+ },
25
+ onInsertAllTracks: (tracks) => {
26
+ console.log('insert-all-tracks', tracks)
27
+ },
28
+ },
15
29
  render: (args) => {
16
30
  return (
17
31
  <ProjectsList
32
+ projects={args.projects}
18
33
  onClickTrack={args.onClickTrack}
19
34
  onInsertAllTracks={args.onInsertAllTracks}
35
+ onProjectClick={args.onProjectClick}
20
36
  >
21
- {projects.map((project) => (
22
- <ProjectsList.Item key={project.id} {...project} />
23
- ))}
37
+ {(projects) =>
38
+ projects.map((project) => (
39
+ <ProjectsList.Item key={project.id} {...project} />
40
+ ))
41
+ }
24
42
  </ProjectsList>
25
43
  )
26
44
  },