Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update plugin components #4927

Merged
merged 43 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
741ace3
add spinner variant
Br2850 Sep 30, 2024
5d45615
allow to only show icon in dropdownview
lanzhenw Oct 3, 2024
8a36c84
update type and minor tweak
lanzhenw Oct 7, 2024
5bea4b7
style tweak and clean up
lanzhenw Oct 7, 2024
71bd61a
improved sliderview
manivoxel51 Oct 3, 2024
ab131b3
progress
manivoxel51 Oct 4, 2024
b589949
complete slider
manivoxel51 Oct 7, 2024
9c1a519
pillBadge outline
Br2850 Oct 8, 2024
9b02e46
coloring
Br2850 Oct 8, 2024
162f883
base Chip
Br2850 Oct 8, 2024
4827e44
add PillBadgeView to Python Panel types
Br2850 Oct 9, 2024
da99e2d
colored badges
Br2850 Oct 10, 2024
930acd6
badge with circle and color
Br2850 Oct 10, 2024
2f1bf5e
extend badge to include dropdowns
Br2850 Oct 10, 2024
e56ecc2
show/hide icon
Br2850 Oct 10, 2024
c3c70dc
final color changes and select
Br2850 Oct 10, 2024
d24a5ac
color matching on selection
Br2850 Oct 10, 2024
aacf655
make use state vars more readable
Br2850 Oct 10, 2024
62de88e
Update app/packages/components/src/components/PillBadge/PillBadge.tsx
Br2850 Oct 10, 2024
e3448f1
add debouncing and throttle to slider onchange event
lanzhenw Oct 11, 2024
6404f05
use onChangeComitted instead
lanzhenw Oct 14, 2024
81fe8f8
cleanup
lanzhenw Oct 14, 2024
fa57350
modify icon only dropdownview style
lanzhenw Oct 16, 2024
f377f13
gridView change
lanzhenw Oct 17, 2024
5894643
Update PillBadge.tsx
Br2850 Oct 15, 2024
ca1bccd
adds disabled state for various variants of the button view
manivoxel51 Oct 16, 2024
7771d0a
hook up .btn to new disabled state
Br2850 Oct 16, 2024
d1f0541
docstring additions for LoadingView
Br2850 Oct 16, 2024
0c8a8a6
refactor and fix disabled color when no color code provided
manivoxel51 Oct 16, 2024
3fd5ba8
Adds a customizable TextView component (#4942)
manivoxel51 Oct 18, 2024
ea56505
snake_case the TextView component
manivoxel51 Oct 18, 2024
b095575
Merge pull request #4948 from voxel51/bug/fix-casing-textview
manivoxel51 Oct 18, 2024
66daf79
minor improvements
Br2850 Oct 18, 2024
d1260b7
cherry-pick ModalView and relevant changes from tag-modal branch
Br2850 Oct 20, 2024
af9f0f7
Merge pull request #4951 from voxel51/patch/panel-tag-modal
Br2850 Oct 20, 2024
947731c
pill badge onChange patch
Br2850 Oct 22, 2024
cb7dfec
ModalView enhancement
Br2850 Oct 22, 2024
4972cbc
Merge branch 'develop' into panel
lanzhenw Oct 22, 2024
3d67489
review changes 1
Br2850 Oct 22, 2024
6f81d66
review changes 2
Br2850 Oct 22, 2024
dfb8681
Merge branch 'panel' of github.com:voxel51/fiftyone into panel
Br2850 Oct 22, 2024
c2c3fcc
testing
manivoxel51 Oct 22, 2024
a9fde0a
infinite loop fix
Br2850 Oct 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions app/packages/components/src/components/Loading/LoadingSpinner.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React from "react";

import { CircularProgress } from "@mui/material";

const LoadingSpinner = ({
color = "base",
size = "medium",
}: {
color?: string;
size?: string;
}) => {
const COLORS: { [key: string]: string } = {
base: "#FFC59B",
primary: "primary",
secondary: "secondary",
error: "error",
warning: "warning",
info: "info",
success: "success",
};
const SIZES: { [key: string]: string } = {
small: "1rem",
medium: "2rem",
large: "3rem",
};
return <CircularProgress sx={{ color: COLORS[color] }} size={SIZES[size]} />;
};

export default LoadingSpinner;
150 changes: 150 additions & 0 deletions app/packages/components/src/components/PillBadge/PillBadge.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import React, { useState } from "react";
import CircleIcon from "@mui/icons-material/Circle";
import { Chip, FormControl, MenuItem, Select } from "@mui/material";

const PillBadge = ({
text,
color = "default",
variant = "filled",
showIcon = true,
}: {
text: string | string[] | [string, string][];
color?: string;
variant?: "filled" | "outlined";
showIcon?: boolean;
}) => {
const getInitialChipSelection = (
text: string | string[] | [string, string][]
) => {
if (typeof text === "string") return text;
if (Array.isArray(text)) {
if (Array.isArray(text[0])) return text[0][0];
return text[0];
}
return "";
};
Br2850 marked this conversation as resolved.
Show resolved Hide resolved

const getInitialChipColor = (
text: string | string[] | [string, string][],
color?: string
) => {
if (typeof text === "string") return color;
if (Array.isArray(text)) {
if (Array.isArray(text[0])) return text[0][1];
return color || "default";
}
return "default";
};
Br2850 marked this conversation as resolved.
Show resolved Hide resolved

const [chipSelection, setChipSelection] = useState(
getInitialChipSelection(text)
);
const [chipColor, setChipColor] = useState(getInitialChipColor(text, color));

const COLORS: { [key: string]: string } = {
default: "#999999",
primary: "#FFB682",
error: "error",
warning: "warning",
info: "info",
success: "#8BC18D",
};

const chipStyle: { [key: string]: string | number } = {
color: COLORS[chipColor || "default"] || COLORS.default,
fontSize: 14,
fontWeight: 500,
paddingLeft: 1,
};
Br2850 marked this conversation as resolved.
Show resolved Hide resolved

return (
<span>
{typeof text === "string" ? (
<Chip
icon={
showIcon ? (
<CircleIcon color={"inherit"} sx={{ fontSize: 10 }} />
) : undefined
}
label={text}
sx={{
...chipStyle,
"& .MuiChip-icon": {
marginRight: "-7px",
},
"& .MuiChip-label": {
marginBottom: "1px",
},
}}
variant={variant as "filled" | "outlined" | undefined}
/>
) : (
<FormControl fullWidth>
<Chip
icon={
showIcon ? (
<CircleIcon color={"inherit"} sx={{ fontSize: 10 }} />
) : undefined
}
label={
Array.isArray(text) && text.length > 0 && Array.isArray(text[0]) ? (
<Select
value={chipSelection}
variant={"standard"}
disableUnderline={true}
onChange={(event) => {
const selectedText = text.find(
(t) => t[0] === event.target.value
);
setChipSelection(event.target.value);
setChipColor(selectedText?.[1] ?? "default");
}}
Br2850 marked this conversation as resolved.
Show resolved Hide resolved
sx={{
color: "inherit",
}}
>
{text.map((t, index) => (
<MenuItem key={index} value={t[0]}>
{t[0]}
</MenuItem>
))}
</Select>
) : (
<Select
value={chipSelection}
variant={"standard"}
disableUnderline={true}
onChange={(event) => setChipSelection(event.target.value)}
sx={{
color: "inherit",
}}
>
{text.map((t, index) => (
<MenuItem key={index} value={t}>
{t}
</MenuItem>
))}
</Select>
)
}
sx={{
...chipStyle,
"& .MuiChip-icon": {
marginRight: "-7px",
},
"& .MuiChip-label": {
marginBottom: "1px",
},
"& .MuiInput-input:focus": {
backgroundColor: "inherit",
},
}}
variant={variant as "filled" | "outlined" | undefined}
></Chip>
</FormControl>
)}
</span>
);
Br2850 marked this conversation as resolved.
Show resolved Hide resolved
};

export default PillBadge;
1 change: 1 addition & 0 deletions app/packages/components/src/components/PillBadge/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as PillBadge } from "./PillBadge";
37 changes: 32 additions & 5 deletions app/packages/core/src/plugins/SchemaIO/components/ButtonView.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react";
import { MuiIconFont } from "@fiftyone/components";
import { usePanelEvent } from "@fiftyone/operators";
import { usePanelId } from "@fiftyone/spaces";
import { isNullish } from "@fiftyone/utilities";
import { Box, ButtonProps, Typography } from "@mui/material";
import React from "react";
import { getColorByCode, getComponentProps } from "../utils";
import { getColorByCode, getComponentProps, getDisabledColors } from "../utils";
import { ViewPropsType } from "../utils/types";
import Button from "./Button";
import TooltipProvider from "./TooltipProvider";
Expand All @@ -22,6 +22,7 @@ export default function ButtonView(props: ViewPropsType) {
params = {},
prompt,
title,
disabled = false,
} = view;
const panelId = usePanelId();
const handleClick = usePanelEvent();
Expand All @@ -37,8 +38,12 @@ export default function ButtonView(props: ViewPropsType) {

return (
<Box {...getComponentProps(props, "container")}>
<TooltipProvider title={title} {...getComponentProps(props, "tooltip")}>
<TooltipProvider
title={disabled ? "" : title}
{...getComponentProps(props, "tooltip")}
>
<Button
disabled={disabled}
variant={variant}
href={href}
onClick={(e) => {
Expand Down Expand Up @@ -66,7 +71,7 @@ export default function ButtonView(props: ViewPropsType) {
}

function getButtonProps(props: ViewPropsType): ButtonProps {
const { label, variant, color } = props.schema.view;
const { label, variant, color, disabled } = props.schema.view;
const baseProps: ButtonProps = getCommonProps(props);
if (isNullish(label)) {
baseProps.sx["& .MuiButton-startIcon"] = { mr: 0, ml: 0 };
Expand Down Expand Up @@ -101,6 +106,18 @@ function getButtonProps(props: ViewPropsType): ButtonProps {
};
}

if (disabled) {
const [bgColor, textColor] = getDisabledColors();
baseProps.sx["&.Mui-disabled"] = {
backgroundColor: variant === "outlined" ? "inherit" : bgColor,
color: textColor,
};
if (["square", "outlined"].includes(variant)) {
baseProps.sx["&.Mui-disabled"].backgroundColor = (theme) =>
theme.palette.background.field;
}
}

return baseProps;
}

Expand All @@ -110,6 +127,8 @@ function getIconProps(props: ViewPropsType): ButtonProps {

function getCommonProps(props: ViewPropsType): ButtonProps {
const color = getColor(props);
const disabled = props.schema.view?.disabled || false;

return {
sx: {
color,
Expand All @@ -119,12 +138,20 @@ function getCommonProps(props: ViewPropsType): ButtonProps {
"&:hover": {
borderColor: color,
},
...(disabled
? {
opacity: 0.5,
}
: {}),
},
};
}

function getColor(props: ViewPropsType) {
const color = props.schema.view.color;
const {
schema: { view = {} },
} = props;
const { color } = view;
if (color) {
return getColorByCode(color);
}
Expand Down
Loading
Loading