diff --git a/.changeset/sour-apes-switch.md b/.changeset/sour-apes-switch.md new file mode 100644 index 00000000..b101f97a --- /dev/null +++ b/.changeset/sour-apes-switch.md @@ -0,0 +1,5 @@ +--- +"claude-dev": patch +--- + +Add tooltips and improve contrast diff --git a/webview-ui/src/components/chat/AutoApproveMenu.tsx b/webview-ui/src/components/chat/AutoApproveMenu.tsx index d1178bdf..aebd9fd8 100644 --- a/webview-ui/src/components/chat/AutoApproveMenu.tsx +++ b/webview-ui/src/components/chat/AutoApproveMenu.tsx @@ -1,10 +1,12 @@ import { VSCodeCheckbox, VSCodeTextField } from "@vscode/webview-ui-toolkit/react" -import { useCallback, useMemo, useState } from "react" +import { useCallback, useMemo, useRef, useState } from "react" import styled from "styled-components" import { useExtensionState } from "@/context/ExtensionStateContext" import { AutoApprovalSettings } from "@shared/AutoApprovalSettings" +import { CODE_BLOCK_BG_COLOR } from "@/components/common/CodeBlock" import { vscode } from "@/utils/vscode" import { getAsVar, VSC_FOREGROUND, VSC_TITLEBAR_INACTIVE_FOREGROUND, VSC_DESCRIPTION_FOREGROUND } from "@/utils/vscStyles" +import { useClickAway } from "react-use" interface AutoApproveMenuProps { style?: React.CSSProperties @@ -80,6 +82,7 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => { const { autoApprovalSettings } = useExtensionState() const [isExpanded, setIsExpanded] = useState(false) const [isHoveringCollapsibleSection, setIsHoveringCollapsibleSection] = useState(false) + const menuRef = useRef(null) // Careful not to use partials to mutate since spread operator only does shallow copy const enabledActions = ACTION_METADATA.filter((action) => autoApprovalSettings.actions[action.id]) @@ -227,8 +230,16 @@ const AutoApproveMenu = ({ style }: AutoApproveMenuProps) => { [extensionState.autoApprovalSettings], ) + // Handle clicks outside the menu to close it + useClickAway(menuRef, () => { + if (isExpanded) { + setIsExpanded(false) + } + }) + return (
{ ? `0.5px solid color-mix(in srgb, ${getAsVar(VSC_TITLEBAR_INACTIVE_FOREGROUND)} 20%, transparent)` : "none", overflowY: "auto", + backgroundColor: isExpanded ? CODE_BLOCK_BG_COLOR : "transparent", ...style, }}>
( - - - - @ - - {/* {showButtonText && Context} */} - - + + + + + @ + + {/* {showButtonText && Context} */} + + + - { - if (!shouldDisableImages) { - onSelectImages() - } - }} - style={{ padding: "0px 0px", height: "20px" }}> - - - {/* {showButtonText && Images} */} - - + + { + if (!shouldDisableImages) { + onSelectImages() + } + }} + style={{ padding: "0px 0px", height: "20px" }}> + + + {/* {showButtonText && Images} */} + + + - { // if (e.key === "Enter" || e.key === " ") { diff --git a/webview-ui/src/components/chat/ServersToggleModal.tsx b/webview-ui/src/components/chat/ServersToggleModal.tsx index 086506fa..b353d8b1 100644 --- a/webview-ui/src/components/chat/ServersToggleModal.tsx +++ b/webview-ui/src/components/chat/ServersToggleModal.tsx @@ -5,6 +5,7 @@ import { CODE_BLOCK_BG_COLOR } from "@/components/common/CodeBlock" import ServersToggleList from "@/components/mcp/configuration/tabs/installed/ServersToggleList" import { vscode } from "@/utils/vscode" import { VSCodeButton } from "@vscode/webview-ui-toolkit/react" +import Tooltip from "@/components/common/Tooltip" const ServersToggleModal: React.FC = () => { const { mcpServers } = useExtensionState() @@ -41,18 +42,20 @@ const ServersToggleModal: React.FC = () => { return (
- setIsVisible(!isVisible)} - style={{ padding: "0px 0px", height: "20px" }}> -
- -
-
+ + setIsVisible(!isVisible)} + style={{ padding: "0px 0px", height: "20px" }}> +
+ +
+
+
{isVisible && ( diff --git a/webview-ui/src/components/cline-rules/ClineRulesToggleModal.tsx b/webview-ui/src/components/cline-rules/ClineRulesToggleModal.tsx index 423ff6b9..8318034a 100644 --- a/webview-ui/src/components/cline-rules/ClineRulesToggleModal.tsx +++ b/webview-ui/src/components/cline-rules/ClineRulesToggleModal.tsx @@ -5,6 +5,7 @@ import { CODE_BLOCK_BG_COLOR } from "@/components/common/CodeBlock" import { vscode } from "@/utils/vscode" import { VSCodeButton } from "@vscode/webview-ui-toolkit/react" import RulesToggleList from "./RulesToggleList" +import Tooltip from "@/components/common/Tooltip" const ClineRulesToggleModal: React.FC = () => { const { globalClineRulesToggles = {}, localClineRulesToggles = {} } = useExtensionState() @@ -61,15 +62,20 @@ const ClineRulesToggleModal: React.FC = () => { return (
- setIsVisible(!isVisible)} - style={{ padding: "0px 0px", height: "20px" }}> -
- -
-
+ + setIsVisible(!isVisible)} + style={{ padding: "0px 0px", height: "20px" }}> +
+ +
+
+
{isVisible && ( diff --git a/webview-ui/src/components/common/Tooltip.tsx b/webview-ui/src/components/common/Tooltip.tsx index 4c4a94b8..6f2a5145 100644 --- a/webview-ui/src/components/common/Tooltip.tsx +++ b/webview-ui/src/components/common/Tooltip.tsx @@ -9,8 +9,8 @@ import { } from "@/utils/vscStyles" interface TooltipProps { - visible: boolean - hintText: string + visible?: boolean + hintText?: string tipText: string children: React.ReactNode style?: React.CSSProperties @@ -24,8 +24,8 @@ const TooltipBody = styled.div>` padding: 5px; border-radius: 5px; bottom: 100%; - left: -180%; - z-index: ${(props) => props.style?.zIndex ?? 10}; + left: ${(props) => props.style?.left ?? -180}%; + z-index: ${(props) => props.style?.zIndex ?? 1000}; white-space: wrap; max-width: 200px; border: 1px solid ${getAsVar(VSC_INPUT_BORDER)}; @@ -41,10 +41,18 @@ const Hint = styled.div` ` const Tooltip: React.FC = ({ visible, tipText, hintText, children, style }) => { + const [isHovered, setIsHovered] = useState(false) + + // Determine final visibility based on prop or internal state + const shouldShow = visible !== undefined ? visible : isHovered + return ( -
+
setIsHovered(true)} + onMouseLeave={() => setIsHovered(false)}> {children} - {visible && ( + {shouldShow && ( {tipText} {hintText && {hintText}} diff --git a/webview-ui/src/components/settings/OpenAiModelPicker.tsx b/webview-ui/src/components/settings/OpenAiModelPicker.tsx deleted file mode 100644 index 6f2fe718..00000000 --- a/webview-ui/src/components/settings/OpenAiModelPicker.tsx +++ /dev/null @@ -1,360 +0,0 @@ -import { VSCodeLink, VSCodeTextField } from "@vscode/webview-ui-toolkit/react" -import Fuse from "fuse.js" -import React, { KeyboardEvent, memo, useEffect, useMemo, useRef, useState } from "react" -import { useRemark } from "react-remark" -import styled from "styled-components" -import { useExtensionState } from "@/context/ExtensionStateContext" -import { vscode } from "@/utils/vscode" -import { highlight } from "../history/HistoryView" - -const OpenAiModelPicker: React.FC = () => { - const { apiConfiguration, setApiConfiguration, openAiModels } = useExtensionState() - const [searchTerm, setSearchTerm] = useState(apiConfiguration?.openAiModelId || "") - const [isDropdownVisible, setIsDropdownVisible] = useState(false) - const [selectedIndex, setSelectedIndex] = useState(-1) - const dropdownRef = useRef(null) - const itemRefs = useRef<(HTMLDivElement | null)[]>([]) - const dropdownListRef = useRef(null) - - const handleModelChange = (newModelId: string) => { - // could be setting invalid model id/undefined info but validation will catch it - setApiConfiguration({ - ...apiConfiguration, - openAiModelId: newModelId, - }) - setSearchTerm(newModelId) - } - - useEffect(() => { - vscode.postMessage({ type: "refreshOpenAiModels" }) - }, [apiConfiguration?.openAiBaseUrl, apiConfiguration?.openAiApiKey]) - - useEffect(() => { - const handleClickOutside = (event: MouseEvent) => { - if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) { - setIsDropdownVisible(false) - } - } - - document.addEventListener("mousedown", handleClickOutside) - return () => { - document.removeEventListener("mousedown", handleClickOutside) - } - }, []) - - const modelIds = useMemo(() => { - return openAiModels.sort((a, b) => a.localeCompare(b)) - }, [openAiModels]) - - const searchableItems = useMemo(() => { - return modelIds.map((id) => ({ - id, - html: id, - })) - }, [modelIds]) - - const fuse = useMemo(() => { - return new Fuse(searchableItems, { - keys: ["html"], // highlight function will update this - threshold: 0.6, - shouldSort: true, - isCaseSensitive: false, - ignoreLocation: false, - includeMatches: true, - minMatchCharLength: 1, - }) - }, [searchableItems]) - - const modelSearchResults = useMemo(() => { - const results: { id: string; html: string }[] = searchTerm - ? highlight(fuse.search(searchTerm), "model-item-highlight") - : searchableItems - // results.sort((a, b) => a.id.localeCompare(b.id)) NOTE: sorting like this causes ids in objects to be reordered and mismatched - return results - }, [searchableItems, searchTerm, fuse]) - - const handleKeyDown = (event: KeyboardEvent) => { - if (!isDropdownVisible) return - - switch (event.key) { - case "ArrowDown": - event.preventDefault() - setSelectedIndex((prev) => (prev < modelSearchResults.length - 1 ? prev + 1 : prev)) - break - case "ArrowUp": - event.preventDefault() - setSelectedIndex((prev) => (prev > 0 ? prev - 1 : prev)) - break - case "Enter": - event.preventDefault() - if (selectedIndex >= 0 && selectedIndex < modelSearchResults.length) { - handleModelChange(modelSearchResults[selectedIndex].id) - setIsDropdownVisible(false) - } - break - case "Escape": - setIsDropdownVisible(false) - setSelectedIndex(-1) - break - } - } - - useEffect(() => { - setSelectedIndex(-1) - if (dropdownListRef.current) { - dropdownListRef.current.scrollTop = 0 - } - }, [searchTerm]) - - useEffect(() => { - if (selectedIndex >= 0 && itemRefs.current[selectedIndex]) { - itemRefs.current[selectedIndex]?.scrollIntoView({ - block: "nearest", - behavior: "smooth", - }) - } - }, [selectedIndex]) - - return ( - <> - -
- - { - handleModelChange((e.target as HTMLInputElement)?.value?.toLowerCase()) - setIsDropdownVisible(true) - }} - onFocus={() => setIsDropdownVisible(true)} - onKeyDown={handleKeyDown} - style={{ width: "100%", zIndex: OPENAI_MODEL_PICKER_Z_INDEX, position: "relative" }}> - {searchTerm && ( -
{ - handleModelChange("") - setIsDropdownVisible(true) - }} - slot="end" - style={{ - display: "flex", - justifyContent: "center", - alignItems: "center", - height: "100%", - }} - /> - )} - - {isDropdownVisible && ( - - {modelSearchResults.map((item, index) => ( - (itemRefs.current[index] = el)} - isSelected={index === selectedIndex} - onMouseEnter={() => setSelectedIndex(index)} - onClick={() => { - handleModelChange(item.id) - setIsDropdownVisible(false) - }} - dangerouslySetInnerHTML={{ - __html: item.html, - }} - /> - ))} - - )} - -
- - ) -} - -export default OpenAiModelPicker - -// Dropdown - -const DropdownWrapper = styled.div` - position: relative; - width: 100%; -` - -export const OPENAI_MODEL_PICKER_Z_INDEX = 1_000 - -const DropdownList = styled.div` - position: absolute; - top: calc(100% - 3px); - left: 0; - width: calc(100% - 2px); - max-height: 200px; - overflow-y: auto; - background-color: var(--vscode-dropdown-background); - border: 1px solid var(--vscode-list-activeSelectionBackground); - z-index: ${OPENAI_MODEL_PICKER_Z_INDEX - 1}; - border-bottom-left-radius: 3px; - border-bottom-right-radius: 3px; -` - -const DropdownItem = styled.div<{ isSelected: boolean }>` - padding: 5px 10px; - cursor: pointer; - word-break: break-all; - white-space: normal; - - background-color: ${({ isSelected }) => (isSelected ? "var(--vscode-list-activeSelectionBackground)" : "inherit")}; - - &:hover { - background-color: var(--vscode-list-activeSelectionBackground); - } -` - -// Markdown - -const StyledMarkdown = styled.div` - font-family: - var(--vscode-font-family), - system-ui, - -apple-system, - BlinkMacSystemFont, - "Segoe UI", - Roboto, - Oxygen, - Ubuntu, - Cantarell, - "Open Sans", - "Helvetica Neue", - sans-serif; - font-size: 12px; - color: var(--vscode-descriptionForeground); - - p, - li, - ol, - ul { - line-height: 1.25; - margin: 0; - } - - ol, - ul { - padding-left: 1.5em; - margin-left: 0; - } - - p { - white-space: pre-wrap; - } - - a { - text-decoration: none; - } - a { - &:hover { - text-decoration: underline; - } - } -` - -export const ModelDescriptionMarkdown = memo( - ({ - markdown, - key, - isExpanded, - setIsExpanded, - }: { - markdown?: string - key: string - isExpanded: boolean - setIsExpanded: (isExpanded: boolean) => void - }) => { - const [reactContent, setMarkdown] = useRemark() - // const [isExpanded, setIsExpanded] = useState(false) - const [showSeeMore, setShowSeeMore] = useState(false) - const textContainerRef = useRef(null) - const textRef = useRef(null) - - useEffect(() => { - setMarkdown(markdown || "") - }, [markdown, setMarkdown]) - - useEffect(() => { - if (textRef.current && textContainerRef.current) { - const { scrollHeight } = textRef.current - const { clientHeight } = textContainerRef.current - const isOverflowing = scrollHeight > clientHeight - setShowSeeMore(isOverflowing) - // if (!isOverflowing) { - // setIsExpanded(false) - // } - } - }, [reactContent, setIsExpanded]) - - return ( - -
-
- {reactContent} -
- {!isExpanded && showSeeMore && ( -
-
- setIsExpanded(true)}> - See more - -
- )} -
- - ) - }, -)