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

enhance: add icon color choices #1781

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
110 changes: 107 additions & 3 deletions ui/admin/app/components/agent/icon/AgentIcon.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
import { EraserIcon, LinkIcon, PaintbrushIcon, PencilIcon } from "lucide-react";
import {
EraserIcon,
LinkIcon,
PaintbrushIcon,
PaletteIcon,
PencilIcon,
SlashIcon,
} from "lucide-react";
import { useState } from "react";

import { AgentIcons } from "~/lib/model/agents";
Expand Down Expand Up @@ -38,6 +45,37 @@ const iconOptions = [
"obot_alt_10",
];

const colors = [
{
name: "purple",
value: "#380067",
},
{
name: "blue",
value: "#4f73f3",
},
{
name: "teal",
value: "#2ddcec",
},
{
name: "green",
value: "#06eaa7",
},
{
name: "red",
value: "#ff4044",
},
{
name: "yellow",
value: "#fdcc11",
},
{
name: "orange",
value: "#ff7240",
},
];

type AgentIconProps = {
icons: AgentIcons | null;
onChange: (icons: AgentIcons | null) => void;
Expand All @@ -50,6 +88,9 @@ export function AgentIcon({ icons, onChange, name }: AgentIconProps) {

const { icon = "", iconDark = "" } = icons ?? {};
const isDarkMode = theme === AppTheme.Dark;
const obotIconIndex = iconOptions.findIndex((option) =>
icon.includes(option)
);
return (
<>
<DropdownMenu>
Expand Down Expand Up @@ -82,6 +123,18 @@ export function AgentIcon({ icons, onChange, name }: AgentIconProps) {
</DropdownMenuSubContent>
</DropdownMenuPortal>
</DropdownMenuSub>
{obotIconIndex !== -1 && (
<DropdownMenuSub>
<DropdownMenuSubTrigger className="flex items-center gap-2">
<PaletteIcon size={16} /> Choose Color
</DropdownMenuSubTrigger>
<DropdownMenuPortal>
<DropdownMenuSubContent>
{renderColorOptions()}
</DropdownMenuSubContent>
</DropdownMenuPortal>
</DropdownMenuSub>
)}
<DropdownMenuItem
className="flex items-center gap-2"
onClick={() => setImageUrlDialogOpen(true)}
Expand Down Expand Up @@ -135,7 +188,58 @@ export function AgentIcon({ icons, onChange, name }: AgentIconProps) {
);
}

function generateIconUrl(icon: string, dark = false) {
return `/agent/images/${icon}${dark ? "_dark" : ""}.svg`;
function renderColorOptions() {
return (
<div className="grid grid-cols-4 gap-2 p-2">
{colors.map((color) => (
<DropdownMenuItem
key={color.name}
onClick={() => {
onChange({
icon: generateIconUrl(
iconOptions[obotIconIndex],
false,
color.name
),
iconDark: generateIconUrl(
iconOptions[obotIconIndex],
false,
color.name
),
collapsed: "",
collapsedDark: "",
});
}}
>
<div
className={cn("h-8 w-8 rounded-sm")}
style={{ backgroundColor: color.value }}
/>
</DropdownMenuItem>
))}
<DropdownMenuItem
onClick={() => {
onChange({
icon: generateIconUrl(iconOptions[obotIconIndex], false),
iconDark: generateIconUrl(iconOptions[obotIconIndex], true),
collapsed: "",
collapsedDark: "",
});
}}
>
<div
className={cn(
"flex h-8 w-8 items-center justify-center rounded-sm border border-foreground"
)}
>
<SlashIcon />
</div>
</DropdownMenuItem>
</div>
);
}

function generateIconUrl(icon: string, dark = false, color = "") {
return `/agent/images/${icon}${dark ? "_dark" : ""}${color ? `_${color}` : ""}.svg`;
}
}
2 changes: 1 addition & 1 deletion ui/admin/app/components/agent/icon/AgentImageUrl.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export function AgentImageUrl({
function getDefaultUrl(url?: string) {
if (!url) return "";

const isDefaultAsset = url.toLowerCase().startsWith("/admin/assets/agent/");
const isDefaultAsset = url.toLowerCase().startsWith("/agent/images/obot_");
return isDefaultAsset ? "" : url;
}
}
Expand Down
33 changes: 33 additions & 0 deletions ui/user/static/agent/images/obot_alt_10_blue.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions ui/user/static/agent/images/obot_alt_10_green.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions ui/user/static/agent/images/obot_alt_10_orange.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions ui/user/static/agent/images/obot_alt_10_purple.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading