Skip to content

Commit

Permalink
refactor: give the content component as children and not as prop
Browse files Browse the repository at this point in the history
…to the Modal
  • Loading branch information
orlinmalkja committed Feb 7, 2025
1 parent 4ccf7f6 commit 23eca7f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
17 changes: 7 additions & 10 deletions src/components/Modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,14 @@ import { FC, ReactNode, useEffect, useState } from 'react'
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'

interface ModalProps {
TriggerButton?: ReactNode,
showPopover?: boolean,
Content?: ReactNode,
position?: Position
children: ReactNode,
TriggerButton?: ReactNode,
showPopover?: boolean,
position?: Position
}

const Modal: FC<ModalProps> = ({
TriggerButton,
showPopover,
Content,
position
children, TriggerButton, showPopover, position
}) => {

const [isOpen, setIsOpen] = useState(false)
Expand All @@ -25,7 +22,7 @@ const Modal: FC<ModalProps> = ({
useEffect(() => {
if (showPopover) setIsOpen(true)
}, [position])

Check warning on line 24 in src/components/Modal.tsx

View workflow job for this annotation

GitHub Actions / build (18)

React Hook useEffect has a missing dependency: 'showPopover'. Either include it or remove the dependency array

Check warning on line 24 in src/components/Modal.tsx

View workflow job for this annotation

GitHub Actions / build (20)

React Hook useEffect has a missing dependency: 'showPopover'. Either include it or remove the dependency array

return <div className="local-tree-modal">
<Popover open={isOpen} onOpenChange={handleOpenChange}>
<PopoverTrigger asChild>
Expand All @@ -36,7 +33,7 @@ const Modal: FC<ModalProps> = ({
top: `${position?.y + 40}px`,
left: `${position?.x}px`,
}}>
{Content}
{children}
</PopoverContent>
</Popover>
</div>
Expand Down
5 changes: 3 additions & 2 deletions src/components/tree/GlobalTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ const GlobalTree: FC = () => {
return <div className="t-mt-24 t-ml-10 t-w-96">
<Tree nodes={treeNodes} onSelect={onSelectNode} getChildren={getChildren}/>
<Modal showPopover={showSelectionModal}
Content={<GlobalTreeSelectionModalContent selectedItemIndices={selectedItemIndices.current}/>}
position={positionSelectedItem}/>
position={positionSelectedItem}>
<GlobalTreeSelectionModalContent selectedItemIndices={selectedItemIndices.current}/>
</Modal>
</div>
}

Expand Down

0 comments on commit 23eca7f

Please sign in to comment.