|
1 | 1 | import {type ComponentChildren} from 'preact'; |
2 | 2 | import {forwardRef} from 'preact/compat'; |
3 | | -import {useRef, useImperativeHandle, useEffect} from 'preact/hooks'; |
| 3 | +import { |
| 4 | + useRef, |
| 5 | + useImperativeHandle, |
| 6 | + useEffect, |
| 7 | + useLayoutEffect, |
| 8 | + useState, |
| 9 | + useMemo, |
| 10 | +} from 'preact/hooks'; |
| 11 | +import {createContext, useContext} from 'preact/compat'; |
4 | 12 |
|
5 | 13 | import type { |
6 | 14 | ButtonProperties, |
@@ -31,15 +39,14 @@ export function Button({ |
31 | 39 | children?: ComponentChildren; |
32 | 40 | modal?: ComponentChildren; |
33 | 41 | } & ButtonProperties) { |
34 | | - console.log('#modal', modal); |
35 | 42 | return ( |
36 | 43 | <> |
37 | 44 | <button |
38 | 45 | class="Button" |
39 | 46 | type="button" |
40 | | - onClick={() => |
41 | | - onPress?.() ?? document.querySelector('dialog')?.showModal() |
42 | | - } |
| 47 | + onClick={() => { |
| 48 | + onPress?.(); |
| 49 | + }} |
43 | 50 | > |
44 | 51 | {children} |
45 | 52 | </button> |
@@ -67,30 +74,11 @@ export const Modal = forwardRef< |
67 | 74 | children?: ComponentChildren; |
68 | 75 | primaryAction?: ComponentChildren; |
69 | 76 | } & ModalProperties |
70 | | ->(function Modal({children, primaryAction, onClose}, ref) { |
71 | | - const dialogRef = useRef<HTMLDialogElement>(null); |
72 | | - |
73 | | - useImperativeHandle(ref, () => ({ |
74 | | - open() { |
75 | | - dialogRef.current?.showModal(); |
76 | | - }, |
77 | | - close() { |
78 | | - dialogRef.current?.close(); |
79 | | - }, |
80 | | - })); |
81 | | - |
82 | | - useEffect(() => { |
83 | | - dialogRef.current?.showModal(); |
84 | | - |
85 | | - return () => { |
86 | | - dialogRef.current?.close(); |
87 | | - }; |
88 | | - }, [dialogRef.current]); |
89 | | - |
| 77 | +>(function Modal({children, primaryAction}) { |
90 | 78 | return ( |
91 | | - <dialog ref={dialogRef} class="Modal" onClose={() => onClose?.()}> |
| 79 | + <div class="Modal"> |
92 | 80 | <div class="Modal-Content">{children}</div> |
93 | 81 | {primaryAction && <div class="Modal-Actions">{primaryAction}</div>} |
94 | | - </dialog> |
| 82 | + </div> |
95 | 83 | ); |
96 | 84 | }); |
0 commit comments