Skip to content

Commit

Permalink
feat: move level selection to the floating toolbar (#933)
Browse files Browse the repository at this point in the history
  • Loading branch information
dhess authored Jun 1, 2023
2 parents 4ed8edb + 02dce26 commit 889579a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 20 deletions.
17 changes: 15 additions & 2 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,19 @@ const AppNoError = ({
redoAvailable: boolean;
}): JSX.Element => {
const [level, setLevel] = useState<Level>(initialLevel);
const toggleLevel = (): void => {
switch (level) {
case "Beginner":
setLevel("Intermediate");
break;
case "Intermediate":
setLevel("Expert");
break;
case "Expert":
setLevel("Beginner");
break;
}
};
const [showCreateDefModal, setShowCreateDefModal] = useState<boolean>(false);
const [showCreateTypeDefModal, setShowCreateTypeDefModal] =
useState<boolean>(false);
Expand Down Expand Up @@ -274,6 +287,8 @@ const AppNoError = ({
onModeChange={() => {
console.log("Toggle mode");
}}
level={level}
onLevelChange={toggleLevel}
undoAvailable={p.undoAvailable}
onClickUndo={() => {
undo
Expand Down Expand Up @@ -327,7 +342,6 @@ const AppNoError = ({
{selection ? (
<ActionsListSelection
level={level}
onChangeLevel={setLevel}
selection={selection}
sessionId={p.sessionId}
onAction={(action) => {
Expand Down Expand Up @@ -407,7 +421,6 @@ const ActionsListSelection = (p: {
selection: Selection;
sessionId: string;
level: Level;
onChangeLevel: (level: Level) => void;
onAction: (action: NoInputAction) => void;
onInputAction: (action: InputAction, option: Option) => void;
onRequestOpts: (acrion: InputAction) => Promise<Options>;
Expand Down
19 changes: 1 addition & 18 deletions src/components/ActionPanel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import classNames from "classnames";
export interface ActionPanelProps {
actions: Action[];
level: Level;
onChangeLevel: (level: Level) => void;
onAction: (action: NoInputAction) => void;
onInputAction: (action: InputAction, option: Option) => void;
onRequestOpts: (action: InputAction) => Promise<Options>;
Expand All @@ -32,31 +31,15 @@ type State =
export const ActionPanel = ({
actions,
level,
onChangeLevel,
onAction,
onInputAction,
onRequestOpts,
}: ActionPanelProps): JSX.Element => {
const [state, setState] = useState<State>({ state: "ActionList" });
return (
<div className="h-full overflow-scroll bg-grey-primary p-4 pt-2">
<div className="flex flex-row flex-wrap items-center justify-between text-base font-bold text-blue-primary">
<div className="flex flex-row py-4 font-bold text-blue-primary lg:text-lg">
{"Actions"}
<select
value={level}
onChange={(e) =>
onChangeLevel(
// This type assertion is safe, since all `option`s in this `select` come from `Object.values(Level)`.
e.target.value as Level
)
}
>
{Object.values(Level).map((level) => (
<option key={level} value={level}>
{level}
</option>
))}
</select>
</div>
{(() => {
switch (state.state) {
Expand Down
5 changes: 5 additions & 0 deletions src/components/FloatingToolbar/FloatingToolbar.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ export default {
description: 'The event handler for the "Mode" button.',
action: "mode",
},
onLevelChange: {
description: 'The event handler for the "Level" button.',
action: "level",
},
redoAvailable: {
description: "Whether redo is available.",
control: "boolean",
Expand Down Expand Up @@ -49,4 +53,5 @@ export const Default = Template.bind({});
Default.args = {
initialMode: "tree",
initialPosition: { x: 100, y: 50 },
level: "Beginner",
};
37 changes: 37 additions & 0 deletions src/components/FloatingToolbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,24 @@ import {
ArrowUturnLeftIcon,
ChevronDownIcon,
EllipsisHorizontalIcon,
BeakerIcon,
AcademicCapIcon,
RocketLaunchIcon,
} from "@heroicons/react/24/outline";
import classNames from "classnames";
import { MouseEventHandler, useRef, useState } from "react";
import { useDraggable, DragOptions } from "@neodrag/react";
import { Level } from "@/primer-api";

export type FloatingToolbarProps = {
initialPosition: { x: number; y: number };
initialMode: Mode;
level: Level;
onModeChange: (
mode: Mode,
event: React.MouseEvent<HTMLButtonElement>
) => void;
onLevelChange: () => void;
redoAvailable: boolean;
onClickRedo: MouseEventHandler<HTMLButtonElement>;
undoAvailable: boolean;
Expand All @@ -41,6 +47,28 @@ const nextMode = (m: Mode): Mode => {
}
};

const levelSvg = (level: Level) => {
switch (level) {
case "Beginner":
return <BeakerIcon />;
case "Intermediate":
return <AcademicCapIcon />;
case "Expert":
return <RocketLaunchIcon />;
}
};

const levelButtonTitle = (level: Level) => {
switch (level) {
case "Beginner":
return "Beginner";
case "Intermediate":
return "Intermediate";
case "Expert":
return "Expert";
}
};

// https://github.com/francoismassart/eslint-plugin-tailwindcss/issues/130
// eslint-disable-next-line tailwindcss/no-custom-classname
const arrow = <ArrowUturnLeftIcon className="w-6 stroke-[3]" />;
Expand Down Expand Up @@ -110,6 +138,15 @@ export const FloatingToolbar = (p: FloatingToolbarProps): JSX.Element => {
{arrow}
undo
</button>
<button
title={levelButtonTitle(p.level)}
type="button"
onClick={p.onLevelChange}
className="flex h-12 w-12 flex-col items-center rounded text-blue-primary hover:bg-blue-primary hover:text-white-primary disabled:cursor-not-allowed disabled:opacity-50"
>
{levelSvg(p.level)}
level
</button>
<button type="button" onClick={p.onClickChevron}>
<ChevronDownIcon className="w-6" />
</button>
Expand Down
1 change: 1 addition & 0 deletions src/primer-api/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './primer-api';
export * from './model';

0 comments on commit 889579a

Please sign in to comment.