-
Notifications
You must be signed in to change notification settings - Fork 590
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
Showing
78 changed files
with
2,675 additions
and
344 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React, { useState } from "react"; | ||
import { Snackbar, Button, SnackbarContent } from "@mui/material"; | ||
import Box from '@mui/material/Box'; | ||
import Typography from '@mui/material/Typography'; | ||
import BoltIcon from '@mui/icons-material/Bolt'; // Icon for the lightning bolt | ||
|
||
// Define types for the props | ||
interface ToastProps { | ||
action: React.ReactNode; // Accepts any valid React component, element, or JSX | ||
message: React.ReactNode; // Accepts any valid React component, element, or JSX | ||
duration?: number; // Optional duration, with a default value | ||
} | ||
|
||
const Toast: React.FC<ToastProps> = ({ action, message, duration = 5000 }) => { | ||
const [open, setOpen] = useState(true); | ||
|
||
const handleClose = (event, reason) => { | ||
if (reason === "clickaway") { | ||
return; | ||
} | ||
setOpen(false); | ||
}; | ||
|
||
return ( | ||
<Snackbar | ||
anchorOrigin={{ vertical: "bottom", horizontal: "center" }} | ||
open={open} | ||
onClose={handleClose} | ||
autoHideDuration={duration} | ||
sx={{ height: 5 }} | ||
> | ||
<SnackbarContent | ||
message={message} | ||
action={action} | ||
style={{ backgroundColor: "#333", color: "#fff" }} | ||
/> | ||
</Snackbar> | ||
); | ||
} | ||
|
||
export default Toast; |
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 @@ | ||
export {default as Toast} from "./Toast"; |
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
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
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,12 @@ | ||
import { describe, expect, it } from "vitest"; | ||
import { shortcutToHelpItems } from "./utils"; | ||
|
||
describe("shortcut processing test", () => { | ||
it("parses unique shortcuts", () => { | ||
const results = shortcutToHelpItems({ | ||
one: { shortcut: "test" }, | ||
two: { shortcut: "test" }, | ||
}); | ||
expect(results).toStrictEqual([{ shortcut: "test" }]); | ||
}); | ||
}); |
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,7 +1,13 @@ | ||
export function shortcutToHelpItems(SHORTCUTS) { | ||
const result = {}; | ||
for (const k of SHORTCUTS) { | ||
result[SHORTCUTS[k].shortcut] = SHORTCUTS[k]; | ||
interface ShortcutItem { | ||
shortcut: string; | ||
} | ||
|
||
type Shortcuts = { [key: string]: ShortcutItem }; | ||
|
||
export function shortcutToHelpItems(SHORTCUTS: Shortcuts) { | ||
const uniqueItems = {}; | ||
for (const item of Object.values(SHORTCUTS)) { | ||
uniqueItems[item.shortcut] = item; | ||
} | ||
return Object.values(result); | ||
return Object.values(uniqueItems); | ||
} |
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
108 changes: 108 additions & 0 deletions
108
app/packages/core/src/plugins/SchemaIO/components/ActionsMenu.tsx
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,108 @@ | ||
import { MuiIconFont } from "@fiftyone/components"; | ||
import { MoreVert } from "@mui/icons-material"; | ||
import { | ||
Box, | ||
Button, | ||
IconButton, | ||
ListItemIcon, | ||
ListItemText, | ||
Menu, | ||
MenuItem, | ||
Stack, | ||
} from "@mui/material"; | ||
import React, { useCallback } from "react"; | ||
|
||
const DEFAULT_MAX_INLINE = 1; | ||
|
||
export default function ActionsMenu(props: ActionsPropsType) { | ||
const { actions, maxInline = DEFAULT_MAX_INLINE } = props; | ||
|
||
if (actions.length === maxInline) { | ||
return ( | ||
<Stack direction="row" spacing={0.5} justifyContent="flex-end"> | ||
{actions.map((action) => ( | ||
<Action {...action} key={action.name} mode="inline" /> | ||
))} | ||
</Stack> | ||
); | ||
} | ||
|
||
return <ActionsOverflowMenu actions={actions} />; | ||
} | ||
|
||
function ActionsOverflowMenu(props: ActionsPropsType) { | ||
const { actions } = props; | ||
const [open, setOpen] = React.useState(false); | ||
const anchorRef = React.useRef(null); | ||
|
||
const handleClose = useCallback(() => { | ||
setOpen(false); | ||
}, []); | ||
|
||
return ( | ||
<Box> | ||
<IconButton | ||
onClick={() => { | ||
setOpen(!open); | ||
}} | ||
ref={anchorRef} | ||
> | ||
<MoreVert /> | ||
</IconButton> | ||
<Menu open={open} onClose={handleClose} anchorEl={anchorRef.current}> | ||
{actions.map((action) => { | ||
const { name, onClick } = action; | ||
return ( | ||
<Action | ||
key={name} | ||
{...action} | ||
mode="menu" | ||
onClick={(action, e) => { | ||
handleClose(); | ||
onClick?.(action, e); | ||
}} | ||
/> | ||
); | ||
})} | ||
</Menu> | ||
</Box> | ||
); | ||
} | ||
|
||
function Action(props: ActionPropsType) { | ||
const { label, name, onClick, icon, variant, mode } = props; | ||
|
||
const Icon = icon ? <MuiIconFont name={icon} /> : null; | ||
|
||
const handleClick = useCallback( | ||
(e: React.MouseEvent) => { | ||
onClick?.(props, e); | ||
}, | ||
[onClick, props] | ||
); | ||
|
||
return mode === "inline" ? ( | ||
<Button variant={variant} startIcon={Icon} onClick={handleClick}> | ||
{label} | ||
</Button> | ||
) : ( | ||
<MenuItem onClick={handleClick}> | ||
{Icon && <ListItemIcon>{Icon}</ListItemIcon>} | ||
<ListItemText>{label || name}</ListItemText> | ||
</MenuItem> | ||
); | ||
} | ||
|
||
type ActionsPropsType = { | ||
actions: Array<ActionPropsType>; | ||
maxInline?: number; | ||
}; | ||
|
||
type ActionPropsType = { | ||
name: string; | ||
label: string; | ||
onClick: (action: ActionPropsType, e: React.MouseEvent) => void; | ||
icon: string; | ||
variant: string; | ||
mode: "inline" | "menu"; | ||
}; |
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
Oops, something went wrong.