From 3baaa5c8b46742d67be25f3fc88879174dd49664 Mon Sep 17 00:00:00 2001 From: Bee <68532117+abeatrix@users.noreply.github.com> Date: Tue, 18 Nov 2025 12:39:50 -0800 Subject: [PATCH] refactor: replace custom UI toggle with shadcn Switch component (#7308) * refactor(webview-ui): replace custom UI toggle with shadcn Switch component - Add @radix-ui/react-switch dependency (v1.2.6) https://ui.shadcn.com/docs/components/switch - Refactor ClineRulesToggleModal to use Radix Switch instead of VSCode buttons - Improve button styling with reduced padding and adjusted icon sizes - Enhance form layout with conditional rendering based on expansion state - Update input field styling with better focus states and border handling This change provides a more consistent UI experience by leveraging Radix UI's accessible Switch component while maintaining the same functionality. * clean up * clean up * update switch color * adjust * revert unrelated changes * size * toggle * Update webview-ui/src/components/cline-rules/RuleRow.tsx Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> --------- Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com> --- .../models/refreshRequestyModels.ts | 2 +- webview-ui/package-lock.json | 45 ++++++ webview-ui/package.json | 1 + .../cline-rules/ClineRulesToggleModal.tsx | 40 ++--- .../src/components/cline-rules/NewRuleRow.tsx | 109 +++++++------ .../src/components/cline-rules/RuleRow.tsx | 90 +++++------ .../tabs/installed/server-row/ServerRow.tsx | 152 +++++------------- webview-ui/src/components/ui/switch.tsx | 26 +++ webview-ui/src/theme.css | 2 + 9 files changed, 231 insertions(+), 236 deletions(-) create mode 100644 webview-ui/src/components/ui/switch.tsx diff --git a/src/core/controller/models/refreshRequestyModels.ts b/src/core/controller/models/refreshRequestyModels.ts index 79842377..8125b5ba 100644 --- a/src/core/controller/models/refreshRequestyModels.ts +++ b/src/core/controller/models/refreshRequestyModels.ts @@ -59,4 +59,4 @@ export async function refreshRequestyModels(controller: Controller, _: EmptyRequ } return OpenRouterCompatibleModelInfo.create({ models }) -} +} \ No newline at end of file diff --git a/webview-ui/package-lock.json b/webview-ui/package-lock.json index 6160767b..f6bf1c0f 100644 --- a/webview-ui/package-lock.json +++ b/webview-ui/package-lock.json @@ -17,6 +17,7 @@ "@radix-ui/react-progress": "^1.1.7", "@radix-ui/react-separator": "^1.1.7", "@radix-ui/react-slot": "^1.2.3", + "@radix-ui/react-switch": "^1.2.6", "@radix-ui/react-tooltip": "^1.2.8", "@vscode/webview-ui-toolkit": "^1.4.0", "class-variance-authority": "^0.7.1", @@ -4132,6 +4133,35 @@ } } }, + "node_modules/@radix-ui/react-switch": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/@radix-ui/react-switch/-/react-switch-1.2.6.tgz", + "integrity": "sha512-bByzr1+ep1zk4VubeEVViV592vu2lHE2BZY5OnzehZqOOgogN80+mNtCqPkhn2gklJqOpxWgPoYTSnhBCqpOXQ==", + "license": "MIT", + "dependencies": { + "@radix-ui/primitive": "1.1.3", + "@radix-ui/react-compose-refs": "1.1.2", + "@radix-ui/react-context": "1.1.2", + "@radix-ui/react-primitive": "2.1.3", + "@radix-ui/react-use-controllable-state": "1.2.2", + "@radix-ui/react-use-previous": "1.1.1", + "@radix-ui/react-use-size": "1.1.1" + }, + "peerDependencies": { + "@types/react": "*", + "@types/react-dom": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc", + "react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + }, + "@types/react-dom": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-tooltip": { "version": "1.2.8", "resolved": "https://registry.npmjs.org/@radix-ui/react-tooltip/-/react-tooltip-1.2.8.tgz", @@ -4251,6 +4281,21 @@ } } }, + "node_modules/@radix-ui/react-use-previous": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@radix-ui/react-use-previous/-/react-use-previous-1.1.1.tgz", + "integrity": "sha512-2dHfToCj/pzca2Ck724OZ5L0EVrr3eHRNsG/b3xQJLA2hZpVCS99bLAX+hm1IHXDEnzU6by5z/5MIY794/a8NQ==", + "license": "MIT", + "peerDependencies": { + "@types/react": "*", + "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc" + }, + "peerDependenciesMeta": { + "@types/react": { + "optional": true + } + } + }, "node_modules/@radix-ui/react-use-rect": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/@radix-ui/react-use-rect/-/react-use-rect-1.1.1.tgz", diff --git a/webview-ui/package.json b/webview-ui/package.json index 6d27e1a9..375cdb64 100644 --- a/webview-ui/package.json +++ b/webview-ui/package.json @@ -25,6 +25,7 @@ "@radix-ui/react-progress": "^1.1.7", "@radix-ui/react-separator": "^1.1.7", "@radix-ui/react-slot": "^1.2.3", + "@radix-ui/react-switch": "^1.2.6", "@radix-ui/react-tooltip": "^1.2.8", "@vscode/webview-ui-toolkit": "^1.4.0", "class-variance-authority": "^0.7.1", diff --git a/webview-ui/src/components/cline-rules/ClineRulesToggleModal.tsx b/webview-ui/src/components/cline-rules/ClineRulesToggleModal.tsx index 69117497..1bddbcca 100644 --- a/webview-ui/src/components/cline-rules/ClineRulesToggleModal.tsx +++ b/webview-ui/src/components/cline-rules/ClineRulesToggleModal.tsx @@ -81,7 +81,15 @@ const ClineRulesToggleModal: React.FC = () => { console.error("Failed to refresh rules:", error) }) } - }, [isVisible]) + }, [ + isVisible, + setGlobalClineRulesToggles, + setLocalClineRulesToggles, + setGlobalWorkflowToggles, + setLocalCursorRulesToggles, + setLocalWindsurfRulesToggles, + setLocalWorkflowToggles, + ]) // Format global rules for display with proper typing const globalRules = Object.entries(globalClineRulesToggles || {}) @@ -286,11 +294,9 @@ const ClineRulesToggleModal: React.FC = () => { setIsVisible(!isVisible)}> -
- -
+
@@ -298,7 +304,7 @@ const ClineRulesToggleModal: React.FC = () => { {isVisible && (
{ overscrollBehavior: "contain", }}>
{
{/* Remote config banner */} - {((currentView === "rules" && hasRemoteRules) || (currentView === "workflows" && hasRemoteWorkflows)) && ( + {(currentView === "rules" && hasRemoteRules) || (currentView === "workflows" && hasRemoteWorkflows) ? (
- + {currentView === "rules" ? "Your organization manages some rules" : "Your organization manages some workflows"}
- )} + ) : null} {/* Description text */} -
+
{currentView === "rules" ? (

Rules allow you to provide Cline with system-level guidance. Think of them as a persistent way to @@ -365,16 +371,10 @@ const ClineRulesToggleModal: React.FC = () => {

Workflows allow you to define a series of steps to guide Cline through a repetitive set of tasks, such as deploying a service or submitting a PR. To invoke a workflow, type{" "} - - /workflow-name - {" "} - in the chat.{" "} + /workflow-name in the chat.{" "} + className="text-xs inline" + href="https://docs.cline.bot/features/slash-commands/workflows"> Docs

diff --git a/webview-ui/src/components/cline-rules/NewRuleRow.tsx b/webview-ui/src/components/cline-rules/NewRuleRow.tsx index 7f3bf193..1185a848 100644 --- a/webview-ui/src/components/cline-rules/NewRuleRow.tsx +++ b/webview-ui/src/components/cline-rules/NewRuleRow.tsx @@ -1,7 +1,9 @@ import { RuleFileRequest } from "@shared/proto/index.cline" -import { VSCodeButton } from "@vscode/webview-ui-toolkit/react" +import { PlusIcon } from "lucide-react" import { useEffect, useRef, useState } from "react" import { useClickAway } from "react-use" +import { Button } from "@/components/ui/button" +import { cn } from "@/lib/utils" import { FileServiceClient } from "@/services/grpc-client" interface NewRuleRowProps { @@ -88,65 +90,66 @@ const NewRuleRow: React.FC = ({ isGlobal, ruleType }) => { return (
!isExpanded && setIsExpanded(true)} ref={componentRef}>
- {isExpanded ? ( -
- setFilename(e.target.value)} - onKeyDown={handleKeyDown} - placeholder={ - ruleType === "workflow" + className={cn( + "flex items-center px-2 py-4 rounded bg-input-background transition-all duration-300 ease-in-out h-5", + { + "shadow-sm": isExpanded, + }, + )}> + + setFilename(e.target.value)} + placeholder={ + isExpanded + ? ruleType === "workflow" ? "workflow-name (.md, .txt, or no extension)" : "rule-name (.md, .txt, or no extension)" - } - ref={inputRef} - style={{ - outline: "none", - }} - type="text" - value={filename} - /> + : ruleType === "workflow" + ? "New workflow file..." + : "New rule file..." + } + ref={inputRef} + type="text" + value={isExpanded ? filename : ""} + /> -
- - - -
-
- ) : ( - <> - - {ruleType === "workflow" ? "New workflow file..." : "New rule file..."} - -
- { - e.stopPropagation() - setIsExpanded(true) - }} - style={{ padding: "0px" }} - title="New rule file"> - - -
- - )} + +
- {isExpanded && error &&
{error}
} + {isExpanded && error &&
{error}
}
) } diff --git a/webview-ui/src/components/cline-rules/RuleRow.tsx b/webview-ui/src/components/cline-rules/RuleRow.tsx index c085e1b2..6c71d06c 100644 --- a/webview-ui/src/components/cline-rules/RuleRow.tsx +++ b/webview-ui/src/components/cline-rules/RuleRow.tsx @@ -1,7 +1,10 @@ import { StringRequest } from "@shared/proto/cline/common" import { RuleFileRequest } from "@shared/proto/index.cline" -import { VSCodeButton } from "@vscode/webview-ui-toolkit/react" +import { InfoIcon, PenIcon, Trash2Icon } from "lucide-react" +import { Button } from "@/components/ui/button" +import { Switch } from "@/components/ui/switch" import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip" +import { cn } from "@/lib/utils" import { FileServiceClient } from "@/services/grpc-client" const RuleRow: React.FC<{ @@ -96,18 +99,16 @@ const RuleRow: React.FC<{ return (
+ className={cn("flex items-center px-2 py-4 rounded bg-text-block-background max-h-4", { + 'opacity-60': isDisabled, + })}> {getRuleTypeIcon() && {getRuleTypeIcon()}} {finalDisplayName} {ruleType === "agents" && ( - - - - + + Searches recursively for all AGENTS.md files in the workspace when a top-level AGENTS.md exists @@ -117,52 +118,33 @@ const RuleRow: React.FC<{ {/* Toggle Switch */} -
-
!isDisabled && toggleRule(rulePath, !enabled)} - onKeyDown={(e) => { - if (!isDisabled && (e.key === "Enter" || e.key === " ")) { - e.preventDefault() - toggleRule(rulePath, !enabled) - } - }} - role="switch" - tabIndex={isDisabled ? -1 : 0} - title={isDisabled ? "This rule is required and cannot be disabled" : undefined}> -
-
- {!isRemote && ( - <> - - - - - - - - )} +
+ toggleRule(rulePath, !enabled)} + title={isDisabled ? "This rule is required and cannot be disabled" : undefined} + /> + +
diff --git a/webview-ui/src/components/mcp/configuration/tabs/installed/server-row/ServerRow.tsx b/webview-ui/src/components/mcp/configuration/tabs/installed/server-row/ServerRow.tsx index 8f0574e3..5fb41160 100644 --- a/webview-ui/src/components/mcp/configuration/tabs/installed/server-row/ServerRow.tsx +++ b/webview-ui/src/components/mcp/configuration/tabs/installed/server-row/ServerRow.tsx @@ -16,9 +16,13 @@ import { VSCodePanelTab, VSCodePanelView, } from "@vscode/webview-ui-toolkit/react" -import { useCallback, useState } from "react" +import { RefreshCcwIcon, Trash2Icon } from "lucide-react" +import { useState } from "react" import DangerButton from "@/components/common/DangerButton" +import { Button } from "@/components/ui/button" +import { Switch } from "@/components/ui/switch" import { useExtensionState } from "@/context/ExtensionStateContext" +import { cn } from "@/lib/utils" import { McpServiceClient } from "@/services/grpc-client" import { getMcpServerDisplayName } from "@/utils/mcp" import McpResourceRow from "./McpResourceRow" @@ -53,17 +57,6 @@ const ServerRow = ({ const [isDeleting, setIsDeleting] = useState(false) const [isRestarting, setIsRestarting] = useState(false) - const getStatusColor = useCallback((status: McpServer["status"]) => { - switch (status) { - case "connected": - return "var(--vscode-testing-iconPassed)" - case "connecting": - return "var(--vscode-charts-yellow)" - case "disconnected": - return "var(--vscode-testing-iconFailed)" - } - }, []) - const handleRowClick = () => { if (!server.error && isExpandable) { setIsExpanded(!isExpanded) @@ -173,111 +166,54 @@ const ServerRow = ({ } return ( -
-
+
+
{!server.error && isExpandable && ( - + )} - + {getMcpServerDisplayName(server.name, mcpMarketplaceCatalog)} {/* Collapsed view controls */} {!server.error && ( -
- { - e.stopPropagation() - handleRestart() - }} - title="Restart Server"> - - - {hasTrashIcon && ( - { - e.stopPropagation() - handleDelete() - }} - title="Delete Server"> - - - )} -
+ + )} + {!server.error && hasTrashIcon && ( + )} {/* Toggle Switch */} -
e.stopPropagation()} style={{ display: "flex", alignItems: "center", marginLeft: "8px" }}> -
{ - handleToggleMcpServer() - }} - onKeyDown={(e) => { - if (e.key === "Enter" || e.key === " ") { - e.preventDefault() - handleToggleMcpServer() - } - }} - role="switch" - style={{ - width: "20px", - height: "10px", - backgroundColor: server.disabled - ? "var(--vscode-titleBar-inactiveForeground)" - : "var(--vscode-testing-iconPassed)", - borderRadius: "5px", - position: "relative", - cursor: "pointer", - transition: "background-color 0.2s", - opacity: server.disabled ? 0.5 : 0.9, - }} - tabIndex={0}> -
-
-
+
diff --git a/webview-ui/src/components/ui/switch.tsx b/webview-ui/src/components/ui/switch.tsx new file mode 100644 index 00000000..06c4bb99 --- /dev/null +++ b/webview-ui/src/components/ui/switch.tsx @@ -0,0 +1,26 @@ +import * as SwitchPrimitives from "@radix-ui/react-switch" +import * as React from "react" + +import { cn } from "@/lib/utils" + +const Switch = React.forwardRef< + React.ElementRef, + React.ComponentPropsWithoutRef +>(({ className, ...props }, ref) => ( + + + +)) +Switch.displayName = SwitchPrimitives.Root.displayName + +export { Switch } diff --git a/webview-ui/src/theme.css b/webview-ui/src/theme.css index 6e38f6fe..56809d96 100644 --- a/webview-ui/src/theme.css +++ b/webview-ui/src/theme.css @@ -9,6 +9,8 @@ --color-code-foreground: var(--vscode-editor-foreground); --color-code-border: var(--vscode-editor-border); --color-code-block-background: var(--vscode-editor-background, --vscode-sideBar-background, rgb(30 30 30)); + --color-text-block-background: var(--vscode-textCodeBlock-background); + --color-editor-group-border: var(--vscode-editorGroup-border); --color-sidebar-background: var(--vscode-sideBar-background); --color-sidebar-foreground: var(--vscode-sideBar-foreground); --color-input-foreground: var(--vscode-input-foreground);