Skip to content

Commit

Permalink
Add: modal
Browse files Browse the repository at this point in the history
  • Loading branch information
Hayao0819 committed Dec 9, 2024
1 parent ee70957 commit c0ccea9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
15 changes: 15 additions & 0 deletions src/components/elements/Modal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { PrimitiveAtom, useAtom } from "jotai";

export type DetailModal<T> = [data: T, setData: (data: T) => void];

export const useDetailModal = <T>(atom: PrimitiveAtom<T>): DetailModal<T> => {
const [internalData, setInternalData] = useAtom<T>(atom);
const setData = (data: T): void => setInternalData(data);
return [internalData, setData];
};

export type SimpleModal = [isOpen: boolean, setOpen: (open: boolean) => void, toggle: () => void];
export const useSimpleModal = (atom: PrimitiveAtom<boolean>): SimpleModal => {
const [isOpen, setOpen] = useDetailModal(atom);
return [isOpen, setOpen, (): void => setOpen(!isOpen)];
};
7 changes: 6 additions & 1 deletion src/components/elements/Toc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ const RenderHeadingTree = ({ tree, indent }: { tree: HeadingTree[]; indent: numb

return (
<>
<ul className={clsx("ml-8", { "marker:text-accent marker:content-['-']": isTopLevel })}>
<ul
className={clsx("ml-8", {
"marker:text-accent marker:content-['-']": isTopLevel,
"marker:content-none": !isTopLevel,
})}
>
{tree.map((e) => (
<li key={e.id} className={clsx(levelClassNames[e.level], { "pl-2": isTopLevel }, "py-1")}>
<NextLink href={`#${e.id}`} scroll={true}>
Expand Down

0 comments on commit c0ccea9

Please sign in to comment.