Skip to content

πŸ™Œ OpenHands: AI-Driven Development

refactor: use cn utility for className composition in 21 components (#544)

Hiep Le13164d477fa1
diff --git a/src/components/features/automations/create-instructions.tsx b/src/components/features/automations/create-instructions.tsx
index a19685d040..25ca5d42ec 100644
--- a/src/components/features/automations/create-instructions.tsx
+++ b/src/components/features/automations/create-instructions.tsx
@@ -4,6 +4,7 @@ import { I18nKey } from "#/i18n/declaration";
import TerminalIcon from "#/icons/terminal.svg?react";
import SparkleIcon from "#/icons/sparkle.svg?react";
import ChevronDownIcon from "#/icons/chevron-down.svg?react";
+import { cn } from "#/utils/utils";
import { NavigationLink } from "#/components/shared/navigation-link";
const DOCS_URL =
@@ -99,9 +100,10 @@ export function CreateInstructions({
{t(I18nKey.AUTOMATIONS$EMPTY_HOW_TO_CREATE_TITLE)}
</span>
<ChevronDownIcon
- className={`size-5 text-muted transition-transform ${
- isExpanded ? "rotate-180" : ""
- }`}
+ className={cn(
+ "size-5 text-muted transition-transform",
+ isExpanded && "rotate-180",
+ )}
/>
</button>
{isExpanded && <div className="px-4 pb-4">{content}</div>}
diff --git a/src/components/features/automations/detail/active-status-badge.tsx b/src/components/features/automations/detail/active-status-badge.tsx
index a1e1df6883..1d7ebbb886 100644
--- a/src/components/features/automations/detail/active-status-badge.tsx
+++ b/src/components/features/automations/detail/active-status-badge.tsx
@@ -1,5 +1,6 @@
import { useTranslation } from "react-i18next";
import { I18nKey } from "#/i18n/declaration";
+import { cn } from "#/utils/utils";
interface ActiveStatusBadgeProps {
active: boolean;
@@ -13,11 +14,12 @@ export function ActiveStatusBadge({ active }: ActiveStatusBadgeProps) {
data-testid={
active ? "active-status-badge-active" : "active-status-badge-inactive"
}
- className={`inline-flex items-center rounded-full px-3 py-1 text-xs font-medium ${
+ className={cn(
+ "inline-flex items-center rounded-full px-3 py-1 text-xs font-medium",
active
? "bg-[var(--oh-success)]/15 text-[var(--oh-success)]"
- : "bg-surface-raised text-muted"
- }`}
+ : "bg-surface-raised text-muted",
+ )}
>
{active
? t(I18nKey.AUTOMATIONS$DETAIL$ACTIVE)
diff --git a/src/components/features/automations/detail/detail-skeleton.tsx b/src/components/features/automations/detail/detail-skeleton.tsx
index 641332520d..36f7b2f426 100644
--- a/src/components/features/automations/detail/detail-skeleton.tsx
+++ b/src/components/features/automations/detail/detail-skeleton.tsx
@@ -1,6 +1,8 @@
+import { cn } from "#/utils/utils";
+
function SkeletonBlock({ className }: { className: string }) {
return (
- <div className={`animate-pulse rounded bg-surface-raised ${className}`} />
+ <div className={cn("animate-pulse rounded bg-surface-raised", className)} />
);
}
diff --git a/src/components/features/automations/detail/run-status-badge.tsx b/src/components/features/automations/detail/run-status-badge.tsx
index a109f3ff1f..1685729265 100644
--- a/src/components/features/automations/detail/run-status-badge.tsx
+++ b/src/components/features/automations/detail/run-status-badge.tsx
@@ -4,6 +4,7 @@ import CheckCircleIcon from "#/icons/check-circle.svg?react";
import XCircleIcon from "#/icons/x-circle.svg?react";
import ClockIcon from "#/icons/clock.svg?react";
import { AutomationRunStatus } from "#/types/automation";
+import { cn } from "#/utils/utils";
interface RunStatusBadgeProps {
status: AutomationRunStatus;
@@ -61,7 +62,10 @@ export function RunStatusBadge({ status }: RunStatusBadgeProps) {
return (
<span
- className={`inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-xs font-medium ${config.style}`}
+ className={cn(
+ "inline-flex items-center gap-1.5 rounded-full border px-2.5 py-1 text-xs font-medium",
+ config.style,
+ )}
>
<StatusIcon status={status} />
{t(config.label)}
diff --git a/src/components/features/automations/kebab-menu.tsx b/src/components/features/automations/kebab-menu.tsx
index d21f7bf3bc..06ebd4f575 100644
--- a/src/components/features/automations/kebab-menu.tsx
+++ b/src/components/features/automations/kebab-menu.tsx
@@ -1,5 +1,6 @@
import { useState, useEffect, useRef } from "react";
import KebabVerticalIcon from "#/icons/kebab-vertical.svg?react";
+import { cn } from "#/utils/utils";
export interface KebabMenuItem {
label: string;
@@ -54,9 +55,10 @@ export function KebabMenu({ items }: KebabMenuProps) {
item.onClick();
setOpen(false);
}}
- className={`flex w-full cursor-pointer items-center gap-2 px-4 py-2 text-sm hover:bg-surface-raised ${
- item.variant === "danger" ? "text-danger" : "text-white"
- }`}
+ className={cn(
+ "flex w-full cursor-pointer items-center gap-2 px-4 py-2 text-sm hover:bg-surface-raised",
+ item.variant === "danger" ? "text-danger" : "text-white",
+ )}
>
{item.icon}
{item.label}
diff --git a/src/components/features/automations/toggle-switch.tsx b/src/components/features/automations/toggle-switch.tsx
index 99cb05e859..5b2b1dabe3 100644
--- a/src/components/features/automations/toggle-switch.tsx
+++ b/src/components/features/automations/toggle-switch.tsx
@@ -1,3 +1,5 @@
+import { cn } from "#/utils/utils";
+
interface ToggleSwitchProps {
enabled: boolean;
label: string;
@@ -15,18 +17,20 @@ export function ToggleSwitch({ enabled, label, onToggle }: ToggleSwitchProps) {
e.stopPropagation();
onToggle();
}}
- className={`relative inline-flex h-[22px] w-[40px] shrink-0 cursor-pointer items-center rounded-full border transition-colors ${
+ className={cn(
+ "relative inline-flex h-[22px] w-[40px] shrink-0 cursor-pointer items-center rounded-full border transition-colors",
enabled
? "border-[var(--oh-success)] bg-[var(--oh-success)]/15"
- : "border-[var(--oh-border)] bg-surface-raised"
- }`}
+ : "border-[var(--oh-border)] bg-surface-raised",
+ )}
>
<span
- className={`inline-block size-4 rounded-full transition-transform ${
+ className={cn(
+ "inline-block size-4 rounded-full transition-transform",
enabled
? "translate-x-[20px] bg-[var(--oh-success)]"
- : "translate-x-[3px] bg-[var(--oh-muted)]"
- }`}
+ : "translate-x-[3px] bg-[var(--oh-muted)]",
+ )}
/>
</button>
);
diff --git a/src/components/features/chat/chat-messages-skeleton.tsx b/src/components/features/chat/chat-messages-skeleton.tsx
index c5adc8109f..4012d68fc1 100644
--- a/src/components/features/chat/chat-messages-skeleton.tsx
+++ b/src/components/features/chat/chat-messages-skeleton.tsx
@@ -1,4 +1,5 @@
import React from "react";
+import { cn } from "#/utils/utils";
const SKELETON_PATTERN = [
{ width: "w-[25%]", height: "h-4", align: "justify-end" },
@@ -15,7 +16,7 @@ const SKELETON_PATTERN = [
function SkeletonBlock({ width, height }: { width: string; height: string }) {
return (
<div
- className={`rounded-md bg-foreground/5 animate-pulse ${width} ${height}`}
+ className={cn("rounded-md bg-foreground/5 animate-pulse", width, height)}
/>
);
}
@@ -28,7 +29,7 @@ export function ChatMessagesSkeleton() {
aria-label="Loading conversation"
>
{SKELETON_PATTERN.map((item, i) => (
- <div key={i} className={`flex w-full ${item.align}`}>
+ <div key={i} className={cn("flex w-full", item.align)}>
<SkeletonBlock width={item.width} height={item.height} />
</div>
))}
diff --git a/src/components/features/chat/custom-chat-input.tsx b/src/components/features/chat/custom-chat-input.tsx
index 4f5f6a49ec..d0e41e28db 100644
--- a/src/components/features/chat/custom-chat-input.tsx
+++ b/src/components/features/chat/custom-chat-input.tsx
@@ -9,6 +9,7 @@ import { ChatInputGrip } from "./components/chat-input-grip";
import { ChatInputContainer } from "./components/chat-input-container";
import { HiddenFileInput } from "./components/hidden-file-input";
import { useConversationStore } from "#/stores/conversation-store";
+import { cn } from "#/utils/utils";
export interface CustomChatInputProps {
disabled?: boolean;
@@ -154,7 +155,7 @@ export function CustomChatInput({
syncCanSubmit();
}, [syncCanSubmit]);
return (
- <div className={`w-full ${className}`}>
+ <div className={cn("w-full", className)}>
{/* Hidden file input */}
<HiddenFileInput
fileInputRef={fileInputRef}
diff --git a/src/components/features/chat/generic-event-message.tsx b/src/components/features/chat/generic-event-message.tsx
index 841b5e79ab..9fecfe91cc 100644
--- a/src/components/features/chat/generic-event-message.tsx
+++ b/src/components/features/chat/generic-event-message.tsx
@@ -4,6 +4,7 @@ import ArrowUp from "#/icons/angle-up-solid.svg?react";
import { SuccessIndicator } from "./success-indicator";
import { ObservationResultStatus } from "#/components/conversation-events/chat/event-content-helpers/get-observation-result";
import { MarkdownRenderer } from "../markdown/markdown-renderer";
+import { cn } from "#/utils/utils";
interface GenericEventMessageProps {
title: React.ReactNode;
@@ -35,15 +36,17 @@ export function GenericEventMessage({
>
{showDetails ? (
<ArrowUp
- className={`h-4 w-4 inline fill-[var(--oh-muted)] ${
- chevronPosition === "after" ? "ml-2" : "mr-2"
- }`}
+ className={cn(
+ "h-4 w-4 inline fill-[var(--oh-muted)]",
+ chevronPosition === "after" ? "ml-2" : "mr-2",
+ )}
/>
) : (
<ArrowDown
- className={`h-4 w-4 inline fill-[var(--oh-muted)] ${
- chevronPosition === "after" ? "ml-2" : "mr-2"
- }`}
+ className={cn(
+ "h-4 w-4 inline fill-[var(--oh-muted)]",
+ chevronPosition === "after" ? "ml-2" : "mr-2",
+ )}
/>
)}
</button>
diff --git a/src/components/features/chat/task-tracking/status-badge.tsx b/src/components/features/chat/task-tracking/status-badge.tsx
index d6428f1967..6ed812187b 100644
--- a/src/components/features/chat/task-tracking/status-badge.tsx
+++ b/src/components/features/chat/task-tracking/status-badge.tsx
@@ -1,4 +1,4 @@
-import { getStatusClassName } from "#/utils/utils";
+import { cn, getStatusClassName } from "#/utils/utils";
interface StatusBadgeProps {
status: string;
@@ -7,9 +7,10 @@ interface StatusBadgeProps {
export function StatusBadge({ status }: StatusBadgeProps) {
return (
<span
- className={`text-xs px-2 py-1 rounded uppercase font-semibold ${getStatusClassName(
- status,
- )}`}
+ className={cn(
+ "text-xs px-2 py-1 rounded uppercase font-semibold",
+ getStatusClassName(status),
+ )}
>
{status.replace("_", " ")}
</span>
diff --git a/src/components/features/conversation-panel/budget-progress-bar.tsx b/src/components/features/conversation-panel/budget-progress-bar.tsx
index 16b5272453..2f1994780f 100644
--- a/src/components/features/conversation-panel/budget-progress-bar.tsx
+++ b/src/components/features/conversation-panel/budget-progress-bar.tsx
@@ -1,4 +1,4 @@
-import React from "react";
+import { cn } from "#/utils/utils";
interface BudgetProgressBarProps {
currentCost: number;
@@ -15,9 +15,10 @@ export function BudgetProgressBar({
return (
<div className="w-full h-1.5 bg-tertiary rounded-full overflow-hidden mt-1">
<div
- className={`h-full transition-all duration-300 ${
- isNearLimit ? "bg-red-500" : "bg-blue-500"
- }`}
+ className={cn(
+ "h-full transition-all duration-300",
+ isNearLimit ? "bg-red-500" : "bg-blue-500",
+ )}
// runtime usage-percentage width
style={{
width: `${Math.min(100, usagePercentage)}%`,
diff --git a/src/components/features/conversation-panel/hooks-modal-header.tsx b/src/components/features/conversation-panel/hooks-modal-header.tsx
index 2c29fa7eed..76c648d683 100644
--- a/src/components/features/conversation-panel/hooks-modal-header.tsx
+++ b/src/components/features/conversation-panel/hooks-modal-header.tsx
@@ -3,6 +3,7 @@ import { RefreshCw } from "lucide-react";
import { BaseModalTitle } from "#/components/shared/modals/confirmation-modals/base-modal";
import { I18nKey } from "#/i18n/declaration";
import { BrandButton } from "../settings/brand-button";
+import { cn } from "#/utils/utils";
interface HooksModalHeaderProps {
isAgentReady: boolean;
@@ -34,7 +35,7 @@ export function HooksModalHeader({
>
<RefreshCw
size={16}
- className={`${isRefetching ? "animate-spin" : ""}`}
+ className={cn(isRefetching && "animate-spin")}
/>
{t(I18nKey.BUTTON$REFRESH)}
</BrandButton>
diff --git a/src/components/features/conversation-panel/skills-modal-header.tsx b/src/components/features/conversation-panel/skills-modal-header.tsx
index b5d8393973..39dfbfe0b0 100644
--- a/src/components/features/conversation-panel/skills-modal-header.tsx
+++ b/src/components/features/conversation-panel/skills-modal-header.tsx
@@ -3,6 +3,7 @@ import { RefreshCw } from "lucide-react";
import { BaseModalTitle } from "#/components/shared/modals/confirmation-modals/base-modal";
import { I18nKey } from "#/i18n/declaration";
import { BrandButton } from "../settings/brand-button";
+import { cn } from "#/utils/utils";
interface SkillsModalHeaderProps {
isAgentReady: boolean;
@@ -34,7 +35,7 @@ export function SkillsModalHeader({
>
<RefreshCw
size={16}
- className={`${isRefetching ? "animate-spin" : ""}`}
+ className={cn(isRefetching && "animate-spin")}
/>
{t(I18nKey.BUTTON$REFRESH)}
</BrandButton>
diff --git a/src/components/features/conversation-panel/system-message-modal/toggle-button.tsx b/src/components/features/conversation-panel/system-message-modal/toggle-button.tsx
index b9ba89234f..8679090253 100644
--- a/src/components/features/conversation-panel/system-message-modal/toggle-button.tsx
+++ b/src/components/features/conversation-panel/system-message-modal/toggle-button.tsx
@@ -1,5 +1,6 @@
import { ChevronDown, ChevronRight } from "lucide-react";
import { Typography } from "#/ui/typography";
+import { cn } from "#/utils/utils";
interface ToggleButtonProps {
title: string;
@@ -19,7 +20,10 @@ export function ToggleButton({
type="button"
data-testid="toggle-button"
onClick={onClick}
- className={`w-full py-3 px-2 text-left flex items-center justify-between hover:bg-tertiary transition-colors ${className || ""}`}
+ className={cn(
+ "w-full py-3 px-2 text-left flex items-center justify-between hover:bg-tertiary transition-colors",
+ className,
+ )}
>
<div className="flex items-center">
<Typography.Text className="font-bold text-content-2">
diff --git a/src/components/features/markdown/blockquote.tsx b/src/components/features/markdown/blockquote.tsx
index 5c611fd0c3..39d0214272 100644
--- a/src/components/features/markdown/blockquote.tsx
+++ b/src/components/features/markdown/blockquote.tsx
@@ -9,6 +9,7 @@ import {
} from "react-icons/fa6";
import type { IconType } from "react-icons";
import type { AlertType } from "./remark-github-alerts";
+import { cn } from "#/utils/utils";
interface AlertConfig {
label: string;
@@ -89,12 +90,18 @@ export function blockquote({
return (
<div
data-testid={`markdown-alert-${alertType}`}
- className={`my-3 rounded-r-sm border-l-4 px-3 py-2 ${config.containerClass}`}
+ className={cn(
+ "my-3 rounded-r-sm border-l-4 px-3 py-2",
+ config.containerClass,
+ )}
>
<p
- className={`flex items-center gap-2 font-semibold ${config.titleClass}`}
+ className={cn(
+ "flex items-center gap-2 font-semibold",
+ config.titleClass,
+ )}
>
- <Icon aria-hidden className={`shrink-0 ${config.iconClass}`} />
+ <Icon aria-hidden className={cn("shrink-0", config.iconClass)} />
<span>{config.label}</span>
</p>
<div className="text-content">{children}</div>
diff --git a/src/components/features/settings/llm-profiles/profile-name-input.tsx b/src/components/features/settings/llm-profiles/profile-name-input.tsx
index 050cf74720..5430e8a840 100644
--- a/src/components/features/settings/llm-profiles/profile-name-input.tsx
+++ b/src/components/features/settings/llm-profiles/profile-name-input.tsx
@@ -3,6 +3,7 @@ import { useTranslation } from "react-i18next";
import { SettingsInput } from "#/components/features/settings/settings-input";
import { isProfileNameValid } from "#/utils/derive-profile-name";
import { I18nKey } from "#/i18n/declaration";
+import { cn } from "#/utils/utils";
interface ProfileNameInputProps {
testId?: string;
@@ -66,7 +67,10 @@ export const ProfileNameInput = forwardRef<
<p
id={describedById}
data-testid={ruleTestId}
- className={`text-xs ${isValid ? "text-[var(--oh-muted)]" : "text-red-400"}`}
+ className={cn(
+ "text-xs",
+ isValid ? "text-[var(--oh-muted)]" : "text-red-400",
+ )}
>
{t(I18nKey.SETTINGS$PROFILE_NAME_RULE)}
</p>
diff --git a/src/components/shared/git-provider-icon.tsx b/src/components/shared/git-provider-icon.tsx
index ee8c869595..b0f7765366 100644
--- a/src/components/shared/git-provider-icon.tsx
+++ b/src/components/shared/git-provider-icon.tsx
@@ -1,6 +1,7 @@
import { FaBitbucket, FaGithub, FaGitlab } from "react-icons/fa6";
import { Provider } from "#/types/settings";
import AzureDevOpsLogo from "#/assets/branding/azure-devops-logo.svg?react";
+import { cn } from "#/utils/utils";
interface GitProviderIconProps {
gitProvider: Provider;
@@ -22,7 +23,7 @@ export function GitProviderIcon({
<FaBitbucket size={14} className={className} />
)}
{gitProvider === "azure_devops" && (
- <AzureDevOpsLogo className={`${className} w-[14px] h-[14px]`} />
+ <AzureDevOpsLogo className={cn(className, "w-[14px] h-[14px]")} />
)}
</>
);
diff --git a/src/components/shared/hook-execution-event-message.tsx b/src/components/shared/hook-execution-event-message.tsx
index 17446d2d33..6b4793e02f 100644
--- a/src/components/shared/hook-execution-event-message.tsx
+++ b/src/components/shared/hook-execution-event-message.tsx
@@ -3,6 +3,7 @@ import { useTranslation } from "react-i18next";
import { isHookExecutionEvent } from "#/types/agent-server/type-guards";
import { OpenHandsEvent } from "#/types/agent-server/core";
import { GenericEventMessage } from "#/components/features/chat/generic-event-message";
+import { cn } from "#/utils/utils";
interface HookExecutionEventMessageProps {
event: OpenHandsEvent;
@@ -79,7 +80,7 @@ export function HookExecutionEventMessage({
{event.tool_name && (
<span className="text-[var(--oh-muted)] ml-2">({event.tool_name})</span>
)}
- <span className={`ml-2 px-1 py-0.5 rounded text-xs ${statusClassName}`}>
+ <span className={cn("ml-2 px-1 py-0.5 rounded text-xs", statusClassName)}>
{statusText}
</span>
</span>
diff --git a/src/routes/device-verify.tsx b/src/routes/device-verify.tsx
index 4b2f8fc9b4..34b0030099 100644
--- a/src/routes/device-verify.tsx
+++ b/src/routes/device-verify.tsx
@@ -4,6 +4,7 @@ import { useTranslation } from "react-i18next";
import { useIsAuthed } from "#/hooks/query/use-is-authed";
import { I18nKey } from "#/i18n/declaration";
import { H1 } from "#/ui/typography";
+import { cn } from "#/utils/utils";
export default function DeviceVerify() {
const { t } = useTranslation("openhands");
@@ -66,7 +67,10 @@ export default function DeviceVerify() {
<div className="max-w-md w-full mx-auto p-6 bg-card rounded-lg shadow-lg">
<div className="text-center">
<div
- className={`mb-4 ${verificationResult.success ? "text-green-600" : "text-red-600"}`}
+ className={cn(
+ "mb-4",
+ verificationResult.success ? "text-green-600" : "text-red-600",
+ )}
>
{verificationResult.success ? (
<svg