Skip to content

Commit

Permalink
feature: begin creating modal component
Browse files Browse the repository at this point in the history
-  fix bug in NewWindow comp
  • Loading branch information
ZanzyTHEbar committed Jan 25, 2023
1 parent 4728ea1 commit 1577b29
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 4 deletions.
48 changes: 48 additions & 0 deletions GUI/ETVR/src/components/Modal/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Button, HStack, Modal, Text } from '@hope-ui/core'
import { children, createSignal, createEffect, Show, onMount } from 'solid-js'
import { openModalStatus } from '@src/store/ui/selectors'
import { setOpenModal, type IModalMenu } from '@src/store/ui/ui'
import './styles.css'

const ModalMenu = (props: IModalMenu) => {
const [ref, setRef] = createSignal<HTMLElement>()
const Children = children(() => props.children)
const clickOutside = (e: MouseEvent) => {
if (e.target instanceof HTMLElement) {
if (ref() && (ref()?.contains(e.target) || ref()?.isSameNode(e.target))) return
console.log('clicked outside')
setOpenModal(false)
}
}
createEffect(() => {
if (openModalStatus()) {
document.addEventListener('click', clickOutside)
return
}
document.removeEventListener('click', clickOutside)
})
return (
<>
<Modal
isOpen={openModalStatus() ?? false}
onClose={() => setOpenModal(false)}
initialFocusSelector="#initial-focus">
<Modal.Overlay />
<Modal.Content p={4}>
<HStack justifyContent="space-between" mb={4}>
<Modal.Heading fontWeight="semibold">Title</Modal.Heading>
<Modal.CloseButton />
</HStack>
<Text mb={4}>The content of the Modal.</Text>
<HStack justifyContent="flex-end" spacing={4}>
<Button id="initial-focus" _focus={{ color: 'red' }}>
Action
</Button>
</HStack>
</Modal.Content>
</Modal>
</>
)
}

export default ModalMenu
Empty file.
4 changes: 1 addition & 3 deletions GUI/ETVR/src/components/NewWindow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,10 @@ const NewMenu = (props: INewMenu) => {
if (e.target instanceof HTMLElement) {
if (ref() && (ref()?.contains(e.target) || ref()?.isSameNode(e.target))) return
console.log('clicked outside')
document.documentElement.style.setProperty(props.cssVariable, 'hidden')
setMenu(null)
}
}
onMount(() => {
document.documentElement.style.setProperty(props.cssVariable, 'hidden')
if (props.ref) {
props.ref.addEventListener('contextmenu', (e) => {
e.preventDefault()
Expand All @@ -35,7 +33,7 @@ const NewMenu = (props: INewMenu) => {
})
return (
<div>
<Show when={menuOpenStatus}>
<Show when={menuOpenStatus() ?? false}>
<Portal mount={props?.ref as HTMLElement}>
<div
ref={setRef}
Expand Down
1 change: 0 additions & 1 deletion GUI/ETVR/src/components/NewWindow/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
width: fit-content;
border-radius: 3px;
z-index: 999;
visibility: var(--menu-visibility);
}

.context-menu button {
Expand Down
5 changes: 5 additions & 0 deletions GUI/ETVR/src/store/ui/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ export interface INewMenu {
cssVariable: string
}

export interface IModalMenu {
children: JSXElement
ref: HTMLElement | null
}

interface IUiStore {
loader?: { [key in loaderType]: boolean }
connecting?: boolean
Expand Down

0 comments on commit 1577b29

Please sign in to comment.