-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
509 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,67 @@ | ||
import { HTMLProps, forwardRef, useImperativeHandle, useRef } from "react"; | ||
import { | ||
DialogHTMLAttributes, | ||
MutableRefObject, | ||
forwardRef, | ||
useEffect, | ||
useImperativeHandle, | ||
useRef, | ||
useState, | ||
} from "react"; | ||
import cx from "classix"; | ||
|
||
import { Button } from "../button"; | ||
|
||
import classes from "./index.module.css"; | ||
|
||
export const Dialog = forwardRef< | ||
HTMLDialogElement, | ||
HTMLProps<HTMLDialogElement> | ||
>(function Dialog( | ||
{ children, ...props }: HTMLProps<HTMLDialogElement>, | ||
outerRef | ||
) { | ||
const ref = useRef<HTMLDialogElement | null>(null); | ||
useImperativeHandle(outerRef, () => ref.current!); | ||
export interface DialogProps extends DialogHTMLAttributes<HTMLDialogElement> { | ||
closeable?: boolean; | ||
} | ||
|
||
return ( | ||
<dialog | ||
ref={ref} | ||
{...props} | ||
className={cx(classes.dialog, props.className)} | ||
> | ||
<Button | ||
className={classes.close} | ||
onClick={() => ref.current?.close()} | ||
export const Dialog = forwardRef<HTMLDialogElement, DialogProps>( | ||
function Dialog({ closeable = true, children, ...props }, outerRef) { | ||
const ref = useRef<HTMLDialogElement | null>(null); | ||
useImperativeHandle(outerRef, () => ref.current!); | ||
|
||
const mutRef = ref as MutableRefObject<HTMLDialogElement>; | ||
const [open, setOpen] = useState(false); | ||
|
||
/** | ||
* Control open state by using `showModal` and `close` methods due to | ||
* preferred behavior versus manipulating the `open` attribute directly. | ||
*/ | ||
useEffect(() => { | ||
if (props.open && !open) { | ||
mutRef.current.showModal(); | ||
setOpen(true); | ||
} else if (!props.open && open) { | ||
mutRef.current.close(); | ||
setOpen(false); | ||
} | ||
}, [mutRef, props.open, open]); | ||
|
||
return ( | ||
<dialog | ||
ref={ref} | ||
{...props} | ||
open={open} | ||
className={cx(classes.dialog, props.className)} | ||
onCancel={e => { | ||
if (!closeable) e.preventDefault(); | ||
props.onCancel?.(e); | ||
}} | ||
> | ||
✖ | ||
</Button> | ||
{children} | ||
</dialog> | ||
); | ||
}); | ||
{closeable && ( | ||
<Button | ||
className={classes.close} | ||
onClick={() => { | ||
mutRef.current.close(); | ||
}} | ||
> | ||
✖ | ||
</Button> | ||
)} | ||
{children} | ||
</dialog> | ||
); | ||
} | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.ending { | ||
margin-top: auto; | ||
width: 30%; | ||
|
||
& > h1 { | ||
margin-bottom: 1rem; | ||
padding: 0 0.5rem; | ||
} | ||
|
||
& > a > img { | ||
width: 100%; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Dialog } from "@/components/dialog"; | ||
import { useGameStore } from "@/stores/game"; | ||
import { useState } from "react"; | ||
import image from "@/assets/images/ending.png"; | ||
|
||
import classes from "./index.module.css"; | ||
|
||
export function Ending() { | ||
const ending = useGameStore(state => state.popups.ending); | ||
const [open, setOpen] = useState<boolean | null>(null); | ||
|
||
if (!ending.reached) return; | ||
|
||
return ( | ||
<Dialog | ||
className={classes.ending} | ||
open={ending.reached ?? open} | ||
onCancel={() => setOpen(false)} | ||
> | ||
<h1>Happy Anniversary Fuyo!</h1> | ||
<a href={image} target="_blank" rel="noreferrer"> | ||
<img src={image} /> | ||
</a> | ||
</Dialog> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { HTMLProps, RefObject } from "react"; | ||
|
||
import { Tutorial } from "./tutorial"; | ||
import { Ending } from "./ending"; | ||
|
||
export interface PopupsRefs { | ||
clicker: RefObject<HTMLDivElement>; | ||
repro: RefObject<HTMLDivElement>; | ||
shop: RefObject<HTMLDivElement>; | ||
} | ||
|
||
export interface PopupsProps extends HTMLProps<HTMLDivElement> { | ||
refs: PopupsRefs; | ||
} | ||
|
||
export function Popups({ refs, ...props }: PopupsProps) { | ||
return ( | ||
<div {...props}> | ||
<Tutorial refs={refs} /> | ||
<Ending /> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.