feat: multiple selected notes panel

This commit is contained in:
Baptiste Grob
2021-04-08 11:30:56 +02:00
parent 0f53361689
commit abfc588368
36 changed files with 542 additions and 128 deletions

View File

@@ -1,16 +1,31 @@
import { autorun } from 'mobx';
import { FunctionComponent, h, render } from 'preact';
import { Inputs, useEffect, useState } from 'preact/hooks';
import { StateUpdater, useCallback, useState } from 'preact/hooks';
import { FocusEvent, EventHandler, FocusEventHandler } from 'react';
export function useAutorunValue<T>(query: () => T, inputs: Inputs): T {
const [value, setValue] = useState(query);
useEffect(() => {
return autorun(() => {
setValue(query());
});
// eslint-disable-next-line react-hooks/exhaustive-deps
}, inputs);
return value;
/**
* @returns a callback that will close a dropdown if none of its children has
* focus. Must be set as the onBlur callback of children that need to be
* monitored.
*/
export function useCloseOnBlur(
container: { current: HTMLDivElement },
setOpen: (open: boolean) => void
): [(event: { relatedTarget: EventTarget | null }) => void, StateUpdater<boolean>] {
const [locked, setLocked] = useState(false);
return [
useCallback(
function onBlur(event: { relatedTarget: EventTarget | null }) {
if (
!locked &&
!container.current.contains(event.relatedTarget as Node)
) {
setOpen(false);
}
},
[container, setOpen, locked]
),
setLocked,
];
}
export function toDirective<Props>(