-
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.
- Loading branch information
1 parent
fdde94b
commit f3a3911
Showing
5 changed files
with
160 additions
and
131 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,58 +1,68 @@ | ||
import { ReactNode } from "react"; | ||
import { createContext, ReactNode, useContext, useState } from "react"; | ||
import { | ||
Badge, | ||
Button, | ||
Card, | ||
CardBody, | ||
CardHeader, | ||
CardTitle, | ||
Split, | ||
SplitItem, | ||
Switch, | ||
} from "@patternfly/react-core"; | ||
import { PencilAltIcon } from "@patternfly/react-icons"; | ||
|
||
const SectionContext = createContext<{ | ||
view: "viewer" | "designer"; | ||
toggleView: () => void; | ||
}>({ | ||
view: "viewer", | ||
toggleView: () => {}, | ||
}); | ||
|
||
export function useSection() { | ||
return useContext(SectionContext).view; | ||
} | ||
|
||
export function Section({ | ||
title, | ||
count, | ||
id, | ||
children, | ||
onEdit, | ||
}: { | ||
title: ReactNode; | ||
count?: number; | ||
id: string; | ||
children: ReactNode; | ||
onEdit?: () => void; | ||
}) { | ||
const [view, setView] = useState<"viewer" | "designer">("viewer"); | ||
const toggleView = () => | ||
setView((v) => (v === "viewer" ? "designer" : "viewer")); | ||
return ( | ||
<Card isPlain={true} isLarge={true} id={id}> | ||
<CardHeader | ||
actions={{ | ||
actions: ( | ||
<> | ||
{onEdit && ( | ||
<Button | ||
variant={"control"} | ||
icon={<PencilAltIcon />} | ||
onClick={onEdit} | ||
/> | ||
<SectionContext.Provider value={{ view, toggleView }}> | ||
<Card isPlain={true} isLarge={true} id={id}> | ||
<CardHeader | ||
actions={{ | ||
actions: ( | ||
<Switch | ||
isChecked={view === "designer"} | ||
onChange={toggleView} | ||
label={"Design"} | ||
/> | ||
), | ||
}} | ||
> | ||
<CardTitle> | ||
<Split hasGutter={true}> | ||
<SplitItem>{title}</SplitItem> | ||
{count !== undefined && ( | ||
<SplitItem> | ||
<Badge>{count}</Badge> | ||
</SplitItem> | ||
)} | ||
</> | ||
), | ||
}} | ||
> | ||
<CardTitle> | ||
<Split hasGutter={true}> | ||
<SplitItem>{title}</SplitItem> | ||
{count !== undefined && ( | ||
<SplitItem> | ||
<Badge>{count}</Badge> | ||
</SplitItem> | ||
)} | ||
</Split> | ||
</CardTitle> | ||
</CardHeader> | ||
<CardBody>{children}</CardBody> | ||
</Card> | ||
</Split> | ||
</CardTitle> | ||
</CardHeader> | ||
<CardBody>{children}</CardBody> | ||
</Card> | ||
</SectionContext.Provider> | ||
); | ||
} |
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 @@ | ||
import { useSection } from "../components/Section.tsx"; | ||
import { useMachineSelector } from "./DocumentDesignerMachineContext.ts"; | ||
import { PathsTree } from "./PathsTree.tsx"; | ||
import { PathsExplorer } from "./PathsExplorer.tsx"; | ||
|
||
export function Paths() { | ||
const { editable } = useMachineSelector(({ context }) => ({ | ||
editable: context.editable, | ||
})); | ||
const view = useSection(); | ||
const isEditable = view === "designer" || editable; | ||
return isEditable ? <PathsTree /> : <PathsExplorer />; | ||
} |
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