-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: improve highlighting and pulling * fix: keys with namespaces bug * feat: preserve scrolling state * chore: fix e2e tests * feat: remove unnecessary package * fix: improve window size management * fix: improve window size management * fix: improve window size management
- Loading branch information
Showing
23 changed files
with
351 additions
and
181 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
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,9 @@ | ||
.dialogBody { | ||
z-index: 1300; | ||
position: fixed; | ||
top: 0px; | ||
left: 0px; | ||
right: 0px; | ||
bottom: 0px; | ||
background: var(--figma-color-bg); | ||
} |
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,5 @@ | ||
declare const styles: { | ||
readonly "dialogBody": string; | ||
}; | ||
export = styles; | ||
|
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,29 @@ | ||
import { ComponentChildren, h } from "preact"; | ||
import { useEffect, useRef } from "preact/hooks"; | ||
import styles from "./Dialog.css"; | ||
import { useWindowSize } from "@/ui/hooks/useWindowSize"; | ||
import { DEFAULT_SIZE } from "@/ui/state/sizes"; | ||
|
||
type Props = { | ||
onClose: () => void; | ||
children: ComponentChildren; | ||
}; | ||
|
||
export const Dialog = ({ children, onClose }: Props) => { | ||
const ref = useRef<HTMLDivElement>(null); | ||
|
||
useWindowSize(DEFAULT_SIZE); | ||
|
||
useEffect(() => { | ||
const handler = () => onClose(); | ||
ref.current?.focus(); | ||
ref.current?.addEventListener("keydown", handler); | ||
return () => ref.current?.removeEventListener("keydown", handler); | ||
}, []); | ||
|
||
return ( | ||
<div ref={ref} tabIndex={0} data-cy="dialog"> | ||
<div className={styles.dialogBody}>{children}</div> | ||
</div> | ||
); | ||
}; |
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
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,18 +1,36 @@ | ||
import { emit } from "@/utilities"; | ||
import { useEffect } from "preact/hooks"; | ||
import { useEffect, useRef } from "preact/hooks"; | ||
|
||
import { ResizeHandler } from "@/types"; | ||
export const DEFAULT_SIZE = { width: 500, height: 400 }; | ||
export const COMPACT_SIZE = { width: 500, height: 160 }; | ||
import { useGlobalActions, useGlobalState } from "../state/GlobalState"; | ||
|
||
type WindowSize = { | ||
width: number; | ||
height: number; | ||
}; | ||
|
||
export const useWindowSize = (size: WindowSize) => { | ||
export const useWindowSize = (newSize: WindowSize) => { | ||
const lastSize = useRef<WindowSize>(); | ||
const { setSizeStack } = useGlobalActions(); | ||
const sizeStack = useGlobalState((c) => c.sizeStack); | ||
useEffect(() => { | ||
emit<ResizeHandler>("RESIZE", size); | ||
return () => emit<ResizeHandler>("RESIZE", DEFAULT_SIZE); | ||
}, [size]); | ||
const addedSize = { ...newSize }; | ||
if (sizeStack.includes(lastSize.current!)) { | ||
setSizeStack((stack) => | ||
stack.map((i) => { | ||
if (i === lastSize.current) { | ||
return addedSize; | ||
} | ||
return i; | ||
}) | ||
); | ||
} else { | ||
setSizeStack((stack) => [...stack, addedSize]); | ||
} | ||
lastSize.current = addedSize; | ||
}, [newSize.width, newSize.height]); | ||
|
||
useEffect(() => { | ||
return () => { | ||
setSizeStack((stack) => stack.filter((i) => i !== lastSize.current)); | ||
}; | ||
}, []); | ||
}; |
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,2 @@ | ||
export const DEFAULT_SIZE = { width: 500, height: 400 }; | ||
export const COMPACT_SIZE = { width: 500, height: 160 }; |
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
Oops, something went wrong.