Skip to content

Commit

Permalink
feat(@captn/joy): add run and save buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelass committed May 6, 2024
1 parent 1b6aded commit 7731dc1
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 0 deletions.
48 changes: 48 additions & 0 deletions packages/joy/src/run-button/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import PlayIcon from "@mui/icons-material/PlayArrow";
import StopIcon from "@mui/icons-material/Stop";
import Button from "@mui/joy/Button";
import CircularProgress from "@mui/joy/CircularProgress";

export interface RunButtonProperties {
disabled?: boolean;
isLoading?: boolean;
isRunning?: boolean;
labels?: { start?: string; stop?: string };
onStop(): void;
onStart(): void;
}

export function RunButton({
disabled,
isLoading,
isRunning,
onStart,
onStop,
labels: { start = "Start", stop = "Stop" } = {},
}: RunButtonProperties) {
return isRunning ? (
<Button
disabled={disabled}
color="danger"
variant="soft"
startDecorator={isLoading ? <CircularProgress /> : <StopIcon />}
onClick={() => {
onStop();
}}
>
{stop}
</Button>
) : (
<Button
disabled={disabled}
color="success"
variant="soft"
startDecorator={isLoading ? <CircularProgress /> : <PlayIcon />}
onClick={() => {
onStart();
}}
>
{start}
</Button>
);
}
29 changes: 29 additions & 0 deletions packages/joy/src/save-button/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { useSaveImage } from "@captn/react/use-save-image";
import CheckIcon from "@mui/icons-material/Check";
import SaveIcon from "@mui/icons-material/Save";
import Button from "@mui/joy/Button";

export function SaveButton({
image,
prompt,
appId,
labels: { save: saveLabel = "Save", saved: savedLabel = "Saved" } = {},
}: {
image: string;
prompt: string;
appId: string;
labels?: { save?: string; saved?: string };
}) {
const { saved, save } = useSaveImage({ image, prompt, appId });

return (
<Button
color={saved ? "success" : "neutral"}
variant="soft"
startDecorator={saved ? <CheckIcon /> : <SaveIcon />}
onClick={save}
>
{saved ? savedLabel : saveLabel}
</Button>
);
}

0 comments on commit 7731dc1

Please sign in to comment.