From 4a3dbb47e16d30fe0f618738e9ac6f22a011f9f6 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Mon, 24 Mar 2025 12:56:52 -0700 Subject: [PATCH 01/12] headless update --- gui/package-lock.json | 177 ++++++++++++++++-- gui/package.json | 4 +- .../CodeToEditCard/AddFileButton.tsx | 23 ++- .../CodeToEditCard/AddFileCombobox.tsx | 20 +- gui/src/components/mainInput/InputToolbar.tsx | 3 + .../components/modelSelection/ModeSelect.tsx | 13 +- .../modelSelection/ModelSelectionListbox.tsx | 14 +- .../platform/AssistantSelect.tsx | 10 +- gui/src/components/ui/Listbox.tsx | 106 +++++++++++ gui/src/components/ui/Listbox2.tsx | 169 +++++++++++++++++ gui/src/pages/config/AccountButton.tsx | 15 +- gui/src/pages/config/ScopeSelect.tsx | 23 ++- gui/src/pages/gui/index.tsx | 2 +- gui/src/util/cn.ts | 6 + 14 files changed, 524 insertions(+), 61 deletions(-) create mode 100644 gui/src/components/ui/Listbox.tsx create mode 100644 gui/src/components/ui/Listbox2.tsx create mode 100644 gui/src/util/cn.ts diff --git a/gui/package-lock.json b/gui/package-lock.json index b0918360d..16c04c5d1 100644 --- a/gui/package-lock.json +++ b/gui/package-lock.json @@ -8,7 +8,7 @@ "license": "Apache-2.0", "dependencies": { "@continuedev/config-yaml": "^1.0.63", - "@headlessui/react": "^1.7.17", + "@headlessui/react": "^2.2.0", "@heroicons/react": "^2.0.18", "@reduxjs/toolkit": "^2.3.0", "@tiptap/core": "^2.3.2", @@ -26,6 +26,7 @@ "@tiptap/suggestion": "^2.1.13", "@types/uuid": "^10.0.0", "@types/vscode-webview": "^1.57.1", + "clsx": "^2.1.1", "core": "file:../core", "dompurify": "^3.0.6", "downshift": "^7.6.0", @@ -59,6 +60,7 @@ "socket.io-client": "^4.7.2", "styled-components": "^5.3.6", "table": "^6.8.1", + "tailwind-merge": "^3.0.2", "tippy.js": "^6.3.7", "unist-util-visit": "^5.0.0", "uuid": "^9.0.1", @@ -1098,25 +1100,53 @@ "@floating-ui/utils": "^0.2.8" } }, + "node_modules/@floating-ui/react": { + "version": "0.26.28", + "resolved": "https://registry.npmjs.org/@floating-ui/react/-/react-0.26.28.tgz", + "integrity": "sha512-yORQuuAtVpiRjpMhdc0wJj06b9JFjrYF4qp96j++v2NBpbi6SEGF7donUJ3TMieerQ6qVkAv1tgr7L4r5roTqw==", + "dependencies": { + "@floating-ui/react-dom": "^2.1.2", + "@floating-ui/utils": "^0.2.8", + "tabbable": "^6.0.0" + }, + "peerDependencies": { + "react": ">=16.8.0", + "react-dom": ">=16.8.0" + } + }, + "node_modules/@floating-ui/react-dom": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/@floating-ui/react-dom/-/react-dom-2.1.2.tgz", + "integrity": "sha512-06okr5cgPzMNBy+Ycse2A6udMi4bqwW/zgBF/rwjcNqWkyr82Mcg8b0vjX8OJpZFy/FKjJmw6wV7t44kK6kW7A==", + "dependencies": { + "@floating-ui/dom": "^1.0.0" + }, + "peerDependencies": { + "react": ">=16.8.0", + "react-dom": ">=16.8.0" + } + }, "node_modules/@floating-ui/utils": { "version": "0.2.8", "resolved": "https://registry.npmjs.org/@floating-ui/utils/-/utils-0.2.8.tgz", "integrity": "sha512-kym7SodPp8/wloecOpcmSnWJsK7M0E5Wg8UcFA+uO4B9s5d0ywXOEro/8HM9x0rW+TljRzul/14UYz3TleT3ig==" }, "node_modules/@headlessui/react": { - "version": "1.7.19", - "resolved": "https://registry.npmjs.org/@headlessui/react/-/react-1.7.19.tgz", - "integrity": "sha512-Ll+8q3OlMJfJbAKM/+/Y2q6PPYbryqNTXDbryx7SXLIDamkF6iQFbriYHga0dY44PvDhvvBWCx1Xj4U5+G4hOw==", + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/@headlessui/react/-/react-2.2.0.tgz", + "integrity": "sha512-RzCEg+LXsuI7mHiSomsu/gBJSjpupm6A1qIZ5sWjd7JhARNlMiSA4kKfJpCKwU9tE+zMRterhhrP74PvfJrpXQ==", "dependencies": { - "@tanstack/react-virtual": "^3.0.0-beta.60", - "client-only": "^0.0.1" + "@floating-ui/react": "^0.26.16", + "@react-aria/focus": "^3.17.1", + "@react-aria/interactions": "^3.21.3", + "@tanstack/react-virtual": "^3.8.1" }, "engines": { "node": ">=10" }, "peerDependencies": { - "react": "^16 || ^17 || ^18", - "react-dom": "^16 || ^17 || ^18" + "react": "^18 || ^19 || ^19.0.0-rc", + "react-dom": "^18 || ^19 || ^19.0.0-rc" } }, "node_modules/@heroicons/react": { @@ -1702,6 +1732,96 @@ "url": "https://opencollective.com/popperjs" } }, + "node_modules/@react-aria/focus": { + "version": "3.20.1", + "resolved": "https://registry.npmjs.org/@react-aria/focus/-/focus-3.20.1.tgz", + "integrity": "sha512-lgYs+sQ1TtBrAXnAdRBQrBo0/7o5H6IrfDxec1j+VRpcXL0xyk0xPq+m3lZp8typzIghqDgpnKkJ5Jf4OrzPIw==", + "dependencies": { + "@react-aria/interactions": "^3.24.1", + "@react-aria/utils": "^3.28.1", + "@react-types/shared": "^3.28.0", + "@swc/helpers": "^0.5.0", + "clsx": "^2.0.0" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1", + "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1" + } + }, + "node_modules/@react-aria/interactions": { + "version": "3.24.1", + "resolved": "https://registry.npmjs.org/@react-aria/interactions/-/interactions-3.24.1.tgz", + "integrity": "sha512-OWEcIC6UQfWq4Td5Ptuh4PZQ4LHLJr/JL2jGYvuNL6EgL3bWvzPrRYIF/R64YbfVxIC7FeZpPSkS07sZ93/NoA==", + "dependencies": { + "@react-aria/ssr": "^3.9.7", + "@react-aria/utils": "^3.28.1", + "@react-stately/flags": "^3.1.0", + "@react-types/shared": "^3.28.0", + "@swc/helpers": "^0.5.0" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1", + "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1" + } + }, + "node_modules/@react-aria/ssr": { + "version": "3.9.7", + "resolved": "https://registry.npmjs.org/@react-aria/ssr/-/ssr-3.9.7.tgz", + "integrity": "sha512-GQygZaGlmYjmYM+tiNBA5C6acmiDWF52Nqd40bBp0Znk4M4hP+LTmI0lpI1BuKMw45T8RIhrAsICIfKwZvi2Gg==", + "dependencies": { + "@swc/helpers": "^0.5.0" + }, + "engines": { + "node": ">= 12" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1" + } + }, + "node_modules/@react-aria/utils": { + "version": "3.28.1", + "resolved": "https://registry.npmjs.org/@react-aria/utils/-/utils-3.28.1.tgz", + "integrity": "sha512-mnHFF4YOVu9BRFQ1SZSKfPhg3z+lBRYoW5mLcYTQihbKhz48+I1sqRkP7ahMITr8ANH3nb34YaMME4XWmK2Mgg==", + "dependencies": { + "@react-aria/ssr": "^3.9.7", + "@react-stately/flags": "^3.1.0", + "@react-stately/utils": "^3.10.5", + "@react-types/shared": "^3.28.0", + "@swc/helpers": "^0.5.0", + "clsx": "^2.0.0" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1", + "react-dom": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1" + } + }, + "node_modules/@react-stately/flags": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/@react-stately/flags/-/flags-3.1.0.tgz", + "integrity": "sha512-KSHOCxTFpBtxhIRcKwsD1YDTaNxFtCYuAUb0KEihc16QwqZViq4hasgPBs2gYm7fHRbw7WYzWKf6ZSo/+YsFlg==", + "dependencies": { + "@swc/helpers": "^0.5.0" + } + }, + "node_modules/@react-stately/utils": { + "version": "3.10.5", + "resolved": "https://registry.npmjs.org/@react-stately/utils/-/utils-3.10.5.tgz", + "integrity": "sha512-iMQSGcpaecghDIh3mZEpZfoFH3ExBwTtuBEcvZ2XnGzCgQjeYXcMdIUwAfVQLXFTdHUHGF6Gu6/dFrYsCzySBQ==", + "dependencies": { + "@swc/helpers": "^0.5.0" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1" + } + }, + "node_modules/@react-types/shared": { + "version": "3.28.0", + "resolved": "https://registry.npmjs.org/@react-types/shared/-/shared-3.28.0.tgz", + "integrity": "sha512-9oMEYIDc3sk0G5rysnYvdNrkSg7B04yTKl50HHSZVbokeHpnU0yRmsDaWb9B/5RprcKj8XszEk5guBO8Sa/Q+Q==", + "peerDependencies": { + "react": "^16.8.0 || ^17.0.0-rc.1 || ^18.0.0 || ^19.0.0-rc.1" + } + }, "node_modules/@reduxjs/toolkit": { "version": "2.3.0", "resolved": "https://registry.npmjs.org/@reduxjs/toolkit/-/toolkit-2.3.0.tgz", @@ -2201,6 +2321,14 @@ "integrity": "sha512-e2BR4lsJkkRlKZ/qCHPw9ZaSxc0MVUd7gtbtaB7aMvHeJVYe8sOB8DBZkP2DtISHGSku9sCK6T6cnY0CtXrOCQ==", "dev": true }, + "node_modules/@swc/helpers": { + "version": "0.5.15", + "resolved": "https://registry.npmjs.org/@swc/helpers/-/helpers-0.5.15.tgz", + "integrity": "sha512-JQ5TuMi45Owi4/BIMAJBoSQoOJu12oOk/gADqlcUL9JEdHB8vyjUSsxqeNXnmXHjYKMi2WcYtezGEEhqUI/E2g==", + "dependencies": { + "tslib": "^2.8.0" + } + }, "node_modules/@swc/types": { "version": "0.1.12", "resolved": "https://registry.npmjs.org/@swc/types/-/types-0.1.12.tgz", @@ -4265,11 +4393,6 @@ "resolved": "https://registry.npmjs.org/classnames/-/classnames-2.5.1.tgz", "integrity": "sha512-saHYOzhIQs6wy2sVxTM6bUDsQO4F50V9RQ22qBpEdCW+I+/Wmke2HOl6lS6dTpdxVhb88/I6+Hs+438c3lfUow==" }, - "node_modules/client-only": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/client-only/-/client-only-0.0.1.tgz", - "integrity": "sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==" - }, "node_modules/clone-response": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/clone-response/-/clone-response-1.0.3.tgz", @@ -4282,6 +4405,14 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/clsx": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/clsx/-/clsx-2.1.1.tgz", + "integrity": "sha512-eYm0QWBtUrBWZWG0d386OGAw16Z995PiOVo2B7bjWSbHedGl5e0ZWaq65kOGgUSNesEIDkB9ISbTg/JK9dhCZA==", + "engines": { + "node": ">=6" + } + }, "node_modules/combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -11398,6 +11529,11 @@ "integrity": "sha512-9QNk5KwDF+Bvz+PyObkmSYjI5ksVUYtjW7AU22r2NKcfLJcXp96hkDWU3+XndOsUb+AQ9QhfzfCT2O+CNWT5Tw==", "dev": true }, + "node_modules/tabbable": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/tabbable/-/tabbable-6.2.0.tgz", + "integrity": "sha512-Cat63mxsVJlzYvN51JmVXIgNoUokrIaT2zLclCXjRd8boZ0004U4KCs/sToJ75C6sdlByWxpYnb5Boif1VSFew==" + }, "node_modules/table": { "version": "6.8.2", "resolved": "https://registry.npmjs.org/table/-/table-6.8.2.tgz", @@ -11413,6 +11549,15 @@ "node": ">=10.0.0" } }, + "node_modules/tailwind-merge": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-3.0.2.tgz", + "integrity": "sha512-l7z+OYZ7mu3DTqrL88RiKrKIqO3NcpEO8V/Od04bNpvk0kiIFndGEoqfuzvj4yuhRkHKjRkII2z+KS2HfPcSxw==", + "funding": { + "type": "github", + "url": "https://github.com/sponsors/dcastil" + } + }, "node_modules/tailwindcss": { "version": "3.4.12", "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-3.4.12.tgz", @@ -11730,9 +11875,9 @@ "dev": true }, "node_modules/tslib": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", - "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==" + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", + "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==" }, "node_modules/type-check": { "version": "0.4.0", diff --git a/gui/package.json b/gui/package.json index 6724bd757..6efdffbf7 100644 --- a/gui/package.json +++ b/gui/package.json @@ -16,7 +16,7 @@ }, "dependencies": { "@continuedev/config-yaml": "^1.0.63", - "@headlessui/react": "^1.7.17", + "@headlessui/react": "^2.2.0", "@heroicons/react": "^2.0.18", "@reduxjs/toolkit": "^2.3.0", "@tiptap/core": "^2.3.2", @@ -34,6 +34,7 @@ "@tiptap/suggestion": "^2.1.13", "@types/uuid": "^10.0.0", "@types/vscode-webview": "^1.57.1", + "clsx": "^2.1.1", "core": "file:../core", "dompurify": "^3.0.6", "downshift": "^7.6.0", @@ -67,6 +68,7 @@ "socket.io-client": "^4.7.2", "styled-components": "^5.3.6", "table": "^6.8.1", + "tailwind-merge": "^3.0.2", "tippy.js": "^6.3.7", "unist-util-visit": "^5.0.0", "uuid": "^9.0.1", diff --git a/gui/src/components/CodeToEditCard/AddFileButton.tsx b/gui/src/components/CodeToEditCard/AddFileButton.tsx index b1e1966fe..a8c70d3c1 100644 --- a/gui/src/components/CodeToEditCard/AddFileButton.tsx +++ b/gui/src/components/CodeToEditCard/AddFileButton.tsx @@ -1,9 +1,14 @@ +import { + Listbox, + ListboxButton, + ListboxOption, + ListboxOptions, +} from "@headlessui/react"; +import { ChevronDownIcon, PlusIcon } from "@heroicons/react/24/outline"; import { useContext, useRef } from "react"; import { IdeMessengerContext } from "../../context/IdeMessenger"; -import { ChevronDownIcon, PlusIcon } from "@heroicons/react/24/outline"; -import { Listbox } from "@headlessui/react"; -import { addCodeToEdit } from "../../redux/slices/sessionSlice"; import { useAppDispatch } from "../../redux/hooks"; +import { addCodeToEdit } from "../../redux/slices/sessionSlice"; export interface AddFileButtonProps { onClick: () => void; @@ -29,7 +34,7 @@ export default function AddFileButton({ onClick }: AddFileButtonProps) { return (
- @@ -50,16 +55,16 @@ export default function AddFileButton({ onClick }: AddFileButtonProps) {
- + - - + Add all open files - - + +
); diff --git a/gui/src/components/CodeToEditCard/AddFileCombobox.tsx b/gui/src/components/CodeToEditCard/AddFileCombobox.tsx index 9450ba480..af19fbf80 100644 --- a/gui/src/components/CodeToEditCard/AddFileCombobox.tsx +++ b/gui/src/components/CodeToEditCard/AddFileCombobox.tsx @@ -1,4 +1,10 @@ -import { Combobox } from "@headlessui/react"; +import { + Combobox, + ComboboxButton, + ComboboxInput, + ComboboxOption, + ComboboxOptions, +} from "@headlessui/react"; import { ContextSubmenuItemWithProvider } from "core"; import { useEffect, useRef, useState } from "react"; import { useSubmenuContextProviders } from "../../context/SubmenuContextProviders"; @@ -54,8 +60,8 @@ export default function AddFileCombobox({ > {({ open }) => (
- - + { if (!open) { @@ -75,10 +81,10 @@ export default function AddFileCombobox({ }} /> - + {filteredFiles.length > 0 ? ( filteredFiles.map((file) => ( - @@ -109,14 +115,14 @@ export default function AddFileCombobox({
)} - + )) ) : (
No results
)} - +
)} diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index f3a8b975f..9e3c7238a 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -30,6 +30,8 @@ import { import { ToolTip } from "../gui/Tooltip"; import ModelSelect from "../modelSelection/ModelSelect"; import ModeSelect from "../modelSelection/ModeSelect"; +// import { ExampleListbox } from "../ui/Listbox2"; +import { ExampleListbox } from "../ui/Listbox"; import HoverItem from "./InputToolbar/bottom/HoverItem"; const StyledDiv = styled.div<{ isHidden?: boolean }>` @@ -116,6 +118,7 @@ function InputToolbar(props: InputToolbarProps) { >
+
{props.toolbarOptions?.hideImageUpload || diff --git a/gui/src/components/modelSelection/ModeSelect.tsx b/gui/src/components/modelSelection/ModeSelect.tsx index afc0588fa..29f30e212 100644 --- a/gui/src/components/modelSelection/ModeSelect.tsx +++ b/gui/src/components/modelSelection/ModeSelect.tsx @@ -1,5 +1,10 @@ // A dropdown menu for selecting between Chat, Edit, and Agent modes with keyboard shortcuts -import { Listbox } from "@headlessui/react"; +import { + Listbox, + ListboxButton, + ListboxOption, + ListboxOptions, +} from "@headlessui/react"; import { ChatBubbleLeftIcon, CheckIcon, @@ -26,7 +31,7 @@ import { isJetBrains, } from "../../util"; -const StyledListboxButton = styled(Listbox.Button)` +const StyledListboxButton = styled(ListboxButton)` font-family: inherit; display: flex; align-items: center; @@ -41,7 +46,7 @@ const StyledListboxButton = styled(Listbox.Button)` } `; -const StyledListboxOptions = styled(Listbox.Options)` +const StyledListboxOptions = styled(ListboxOptions)` margin-top: 4px; position: absolute; list-style: none; @@ -55,7 +60,7 @@ const StyledListboxOptions = styled(Listbox.Options)` background-color: ${vscInputBackground}; `; -const StyledListboxOption = styled(Listbox.Option)` +const StyledListboxOption = styled(ListboxOption)` border-radius: ${defaultBorderRadius}; padding: 6px 12px; cursor: ${(props) => (props.disabled ? "not-allowed" : "pointer")}; diff --git a/gui/src/components/modelSelection/ModelSelectionListbox.tsx b/gui/src/components/modelSelection/ModelSelectionListbox.tsx index 596cddb9b..bf8f5b1fc 100644 --- a/gui/src/components/modelSelection/ModelSelectionListbox.tsx +++ b/gui/src/components/modelSelection/ModelSelectionListbox.tsx @@ -1,4 +1,10 @@ -import { Listbox, Transition } from "@headlessui/react"; +import { + Listbox, + ListboxButton, + ListboxOption, + ListboxOptions, + Transition, +} from "@headlessui/react"; import { CheckIcon, ChevronUpDownIcon, @@ -21,7 +27,7 @@ export const StyledListbox = styled(Listbox)` background-color: ${vscBackground}; `; -export const StyledListboxButton = styled(Listbox.Button)` +export const StyledListboxButton = styled(ListboxButton)` cursor: pointer; background-color: ${vscBackground}; text-align: left; @@ -55,7 +61,7 @@ export const StyledListboxButton = styled(Listbox.Button)` } `; -export const StyledListboxOptions = styled(Listbox.Options)` +export const StyledListboxOptions = styled(ListboxOptions)` background-color: ${vscInputBackground}; padding: 0; @@ -78,7 +84,7 @@ export const StyledListboxOptions = styled(Listbox.Options)` } `; -export const StyledListboxOption = styled(Listbox.Option)<{ +export const StyledListboxOption = styled(ListboxOption)<{ selected: boolean; }>` background-color: ${({ selected }) => diff --git a/gui/src/components/modelSelection/platform/AssistantSelect.tsx b/gui/src/components/modelSelection/platform/AssistantSelect.tsx index 43caa02a9..a842069e0 100644 --- a/gui/src/components/modelSelection/platform/AssistantSelect.tsx +++ b/gui/src/components/modelSelection/platform/AssistantSelect.tsx @@ -1,4 +1,4 @@ -import { Popover } from "@headlessui/react"; +import { Popover, PopoverButton, PopoverPanel } from "@headlessui/react"; import { ChevronDownIcon, PlusIcon } from "@heroicons/react/24/outline"; import { ProfileDescription } from "core/config/ConfigHandler"; import { useContext, useEffect, useRef } from "react"; @@ -79,17 +79,17 @@ export default function AssistantSelect() { return (
- - + - + { if (buttonRef.current) { @@ -97,7 +97,7 @@ export default function AssistantSelect() { } }} /> - +
diff --git a/gui/src/components/ui/Listbox.tsx b/gui/src/components/ui/Listbox.tsx new file mode 100644 index 000000000..91d22551b --- /dev/null +++ b/gui/src/components/ui/Listbox.tsx @@ -0,0 +1,106 @@ +import { + ListboxButton as HLButton, + ListboxOption as HLOption, + ListboxOptions as HLOptions, + Listbox, + Transition, +} from "@headlessui/react"; +import * as React from "react"; +import { useState } from "react"; +import { cn } from "../../util/cn"; + +type ListboxButtonProps = React.ComponentProps; +const ListboxButton = React.forwardRef( + ({ className, ...props }, ref) => ( + + ), +); + +type ListboxOptionsProps = React.ComponentProps; +const ListboxOptions = React.forwardRef( + ({ className, ...props }, ref) => ( + + ), +); + +type ListboxOptionProps = React.ComponentProps; +const ListboxOption = React.forwardRef( + ({ className, ...props }, ref) => ( + + ), +); + +type ListboxTransitionProps = React.ComponentProps; +function ListboxTransition(props: ListboxTransitionProps) { + return ( + + ); +} + +const people = [ + { id: 1, name: "Durward Reynolds" }, + { id: 2, name: "Kenton Towne" }, + { id: 3, name: "Therese Wunsch" }, + { id: 4, name: "Benedict Kessler" }, + { id: 5, name: "Katelyn Rohan" }, +]; + +function ExampleListbox() { + const [selectedPerson, setSelectedPerson] = useState(people[0]); + + return ( + + {selectedPerson.name} + + + {people.map((person) => ( + + {person.name} + + ))} + + + + ); +} + +export { + ExampleListbox, + Listbox, + ListboxButton, + ListboxOption, + ListboxOptions, +}; diff --git a/gui/src/components/ui/Listbox2.tsx b/gui/src/components/ui/Listbox2.tsx new file mode 100644 index 000000000..2267fe61a --- /dev/null +++ b/gui/src/components/ui/Listbox2.tsx @@ -0,0 +1,169 @@ +// import { ChevronDownIcon } from "@heroicons/react/24/outline"; +// import React, { +// ButtonHTMLAttributes, +// LiHTMLAttributes, +// useEffect, +// useRef, +// useState, +// } from "react"; + +// import { cn } from "../../util/cn"; + +// import { createContext, useContext } from 'react'; + +// interface ListboxContextType { + +// }; + +// const defaultListboxContext: ListboxContextType = { + +// } + +// export const ListboxContext = createContext(defaultListboxContext); + +// const useListbox = () => { +// const context = useContext(ThemeContext); +// if (context === undefined) { +// throw new Error('useTheme must be used within a ThemeProvider'); +// } +// return context; +// }; + +// interface ListboxItemProps extends LiHTMLAttributes { +// isOpen: boolean; +// // selected: boolean +// } + +// export const ListboxItem: React.FC = (props) => { +// return
  • ; +// }; + +// interface ListboxButtonProps extends ButtonHTMLAttributes { +// isOpen: boolean; +// showChevron: boolean; +// } + +// export const ListboxButton: React.FC = (props) => { +// return ( +// +// ); +// }; + +// export const ContinueListbox: React.FC = ({ +// options, +// value, +// onChange, +// placeholder, +// }) => { +// const containerRef = useRef(null); +// const listRef = useRef(null); + +// return ( +//
    +//
      +// {options.map((option) => ( +//
    • { +// onChange?.(option); +// setIsOpen(false); +// }} +// className={`cursor-pointer list-none px-3 py-2 hover:bg-gray-100 ${option === value ? "bg-gray-200" : ""}`} +// > +// {option} +//
    • +// ))} +//
    +//
    +// ); +// }; + +// // interface UseListboxProps +// function useListbox() { +// const listRef = useRef(null); +// const containerRef = useRef(null); +// const buttonRef = useRef(null); + +// const [isOpen, setIsOpen] = useState(false); +// const [popupDirection, setPopupDirection] = useState<"down" | "up">("down"); + +// useEffect(() => { +// if (isOpen && containerRef.current && listRef.current) { +// const rect = containerRef.current.getBoundingClientRect(); +// const listHeight = listRef.current.offsetHeight; +// const viewportHeight = window.innerHeight; +// const spaceBelow = viewportHeight - rect.bottom; +// const spaceAbove = rect.top; +// setPopupDirection( +// spaceBelow >= listHeight || spaceBelow >= spaceAbove ? "down" : "up", +// ); +// } +// }, [isOpen]); + +// // Handle blurring/clicking outside the list + +// useEffect(() => { +// if (!listRef.current) return; +// const ref = listRef.current; +// const handleBlur = () => setIsOpen(false); +// ref.addEventListener("blur", handleBlur); +// return () => ref.removeEventListener("blur", handleBlur); +// }, [listRef]); + +// function closeList() { +// setIsOpen(false); +// } + +// function openList() { +// setIsOpen(true); +// listRef.current?.focus(); +// } + +// function toggleList() { +// if (isOpen) { +// closeList(); +// } else { +// openList(); +// } +// } + +// return { +// listRef, +// containerRef, +// buttonRef, +// isOpen, +// closeList, +// openList, +// toggleList, +// }; +// } + +// const options = ["Apple", "Banana", "Orange", "Mango", "Pineapple"]; +// export const ExampleListbox = () => { +// return ( +// console.log("Selected:", value)} +// /> +// ); +// }; diff --git a/gui/src/pages/config/AccountButton.tsx b/gui/src/pages/config/AccountButton.tsx index 0eaf4e471..ce09c1621 100644 --- a/gui/src/pages/config/AccountButton.tsx +++ b/gui/src/pages/config/AccountButton.tsx @@ -1,4 +1,9 @@ -import { Popover, Transition } from "@headlessui/react"; +import { + Popover, + PopoverButton, + PopoverPanel, + Transition, +} from "@headlessui/react"; import { UserCircleIcon } from "@heroicons/react/24/outline"; import { Fragment } from "react"; @@ -17,9 +22,9 @@ export function AccountButton() { return ( - + - + - +
    {session.account.label} @@ -50,7 +55,7 @@ export function AccountButton() { Sign out
    - + ); diff --git a/gui/src/pages/config/ScopeSelect.tsx b/gui/src/pages/config/ScopeSelect.tsx index 51538d784..7658ee8bd 100644 --- a/gui/src/pages/config/ScopeSelect.tsx +++ b/gui/src/pages/config/ScopeSelect.tsx @@ -1,4 +1,9 @@ -import { Listbox } from "@headlessui/react"; +import { + Listbox, + ListboxButton, + ListboxOption, + ListboxOptions, +} from "@headlessui/react"; import { BuildingOfficeIcon, ChevronUpDownIcon, @@ -36,7 +41,7 @@ export function ScopeSelect() { return (
    - +
    {selectedDisplay?.iconUrl ? ( @@ -50,16 +55,16 @@ export function ScopeSelect() {
    -
    + - + {organizations.length > 0 && ( <>
    Organizations
    {organizations.map((org) => ( - {org.name}
    - + ))}
    )} - @@ -87,8 +92,8 @@ export function ScopeSelect() { Personal
    - - + +
    ); diff --git a/gui/src/pages/gui/index.tsx b/gui/src/pages/gui/index.tsx index 31784a358..788d88b23 100644 --- a/gui/src/pages/gui/index.tsx +++ b/gui/src/pages/gui/index.tsx @@ -3,7 +3,7 @@ import { Chat } from "./Chat"; export default function GUI() { return ( -
    +
    diff --git a/gui/src/util/cn.ts b/gui/src/util/cn.ts new file mode 100644 index 000000000..a5ef19350 --- /dev/null +++ b/gui/src/util/cn.ts @@ -0,0 +1,6 @@ +import { clsx, type ClassValue } from "clsx"; +import { twMerge } from "tailwind-merge"; + +export function cn(...inputs: ClassValue[]) { + return twMerge(clsx(inputs)); +} From da2109152414c08aa4847066ee8fecce88c5a049 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Mon, 24 Mar 2025 15:34:30 -0700 Subject: [PATCH 02/12] unified listbox p1 --- .../CodeToEditCard/AddFileButton.tsx | 12 +- .../CodeToEditCard/AddFileCombobox.tsx | 7 +- gui/src/components/Layout.tsx | 83 +++++---- gui/src/components/mainInput/InputToolbar.tsx | 3 - .../InputToolbar/bottom/PopoverTransition.tsx | 26 --- gui/src/components/mainInput/Lump/index.tsx | 6 +- .../components/modelSelection/ModeSelect.tsx | 101 ++++------- .../components/modelSelection/ModelSelect.tsx | 99 ++++------ .../modelSelection/ModelSelectionListbox.tsx | 15 +- .../platform/AssistantSelect.tsx | 8 +- gui/src/components/ui/Combobox.tsx | 15 ++ gui/src/components/ui/Listbox.tsx | 171 ++++++++---------- gui/src/components/ui/Listbox2.tsx | 169 ----------------- gui/src/components/ui/Popover.tsx | 3 + gui/src/components/ui/Transition.tsx | 20 ++ gui/src/components/ui/font.ts | 15 ++ gui/src/components/ui/index.tsx | 4 + gui/src/context/LocalStorage.tsx | 41 +++++ gui/src/pages/config/AccountButton.tsx | 21 +-- gui/src/pages/config/ModelRoleSelector.tsx | 40 ++-- gui/src/pages/config/ScopeSelect.tsx | 12 +- gui/tsconfig.json | 6 +- 22 files changed, 344 insertions(+), 533 deletions(-) delete mode 100644 gui/src/components/mainInput/InputToolbar/bottom/PopoverTransition.tsx create mode 100644 gui/src/components/ui/Combobox.tsx delete mode 100644 gui/src/components/ui/Listbox2.tsx create mode 100644 gui/src/components/ui/Popover.tsx create mode 100644 gui/src/components/ui/Transition.tsx create mode 100644 gui/src/components/ui/font.ts create mode 100644 gui/src/components/ui/index.tsx create mode 100644 gui/src/context/LocalStorage.tsx diff --git a/gui/src/components/CodeToEditCard/AddFileButton.tsx b/gui/src/components/CodeToEditCard/AddFileButton.tsx index a8c70d3c1..a5b9364b7 100644 --- a/gui/src/components/CodeToEditCard/AddFileButton.tsx +++ b/gui/src/components/CodeToEditCard/AddFileButton.tsx @@ -1,14 +1,14 @@ -import { - Listbox, - ListboxButton, - ListboxOption, - ListboxOptions, -} from "@headlessui/react"; import { ChevronDownIcon, PlusIcon } from "@heroicons/react/24/outline"; import { useContext, useRef } from "react"; import { IdeMessengerContext } from "../../context/IdeMessenger"; import { useAppDispatch } from "../../redux/hooks"; import { addCodeToEdit } from "../../redux/slices/sessionSlice"; +import { + Listbox, + ListboxButton, + ListboxOption, + ListboxOptions, +} from "../ui/Listbox"; export interface AddFileButtonProps { onClick: () => void; diff --git a/gui/src/components/CodeToEditCard/AddFileCombobox.tsx b/gui/src/components/CodeToEditCard/AddFileCombobox.tsx index af19fbf80..5d8f92559 100644 --- a/gui/src/components/CodeToEditCard/AddFileCombobox.tsx +++ b/gui/src/components/CodeToEditCard/AddFileCombobox.tsx @@ -1,16 +1,15 @@ +import { ContextSubmenuItemWithProvider } from "core"; +import { useEffect, useRef, useState } from "react"; import { Combobox, ComboboxButton, ComboboxInput, ComboboxOption, ComboboxOptions, -} from "@headlessui/react"; -import { ContextSubmenuItemWithProvider } from "core"; -import { useEffect, useRef, useState } from "react"; +} from "../../components/ui/Combobox"; import { useSubmenuContextProviders } from "../../context/SubmenuContextProviders"; import { useAppSelector } from "../../redux/hooks"; import FileIcon from "../FileIcon"; - export interface AddFileComboboxProps { onSelect: (filepaths: string[]) => void | Promise; onEscape: () => void | Promise; diff --git a/gui/src/components/Layout.tsx b/gui/src/components/Layout.tsx index 20ecc7761..d2d91f1ea 100644 --- a/gui/src/components/Layout.tsx +++ b/gui/src/components/Layout.tsx @@ -3,6 +3,7 @@ import { Outlet, useLocation, useNavigate } from "react-router-dom"; import styled from "styled-components"; import { CustomScrollbarDiv, defaultBorderRadius } from "."; import { AuthProvider } from "../context/Auth"; +import { LocalStorageProvider } from "../context/LocalStorage"; import { useWebviewListener } from "../hooks/useWebviewListener"; import { useAppDispatch, useAppSelector } from "../redux/hooks"; import { selectUseHub } from "../redux/selectors"; @@ -265,49 +266,51 @@ const Layout = () => { // }, [onboardingCard.show, useHub]); return ( - - - -
    - { - dispatch(setShowDialog(false)); + + + + +
    { - dispatch(setShowDialog(false)); - }} - message={dialogMessage} - /> + > + { + dispatch(setShowDialog(false)); + }} + onClose={() => { + dispatch(setShowDialog(false)); + }} + message={dialogMessage} + /> - - - + + + - {hasFatalErrors && pathname !== ROUTES.CONFIG_ERROR && ( -
    navigate(ROUTES.CONFIG_ERROR)} - > - Error!{" "} - Could not load config -
    Learn More
    -
    - )} -
    - -
    -
    - - + {hasFatalErrors && pathname !== ROUTES.CONFIG_ERROR && ( +
    navigate(ROUTES.CONFIG_ERROR)} + > + Error!{" "} + Could not load config +
    Learn More
    +
    + )} +
    + +
    +
    + + + ); }; diff --git a/gui/src/components/mainInput/InputToolbar.tsx b/gui/src/components/mainInput/InputToolbar.tsx index 9e3c7238a..f3a8b975f 100644 --- a/gui/src/components/mainInput/InputToolbar.tsx +++ b/gui/src/components/mainInput/InputToolbar.tsx @@ -30,8 +30,6 @@ import { import { ToolTip } from "../gui/Tooltip"; import ModelSelect from "../modelSelection/ModelSelect"; import ModeSelect from "../modelSelection/ModeSelect"; -// import { ExampleListbox } from "../ui/Listbox2"; -import { ExampleListbox } from "../ui/Listbox"; import HoverItem from "./InputToolbar/bottom/HoverItem"; const StyledDiv = styled.div<{ isHidden?: boolean }>` @@ -118,7 +116,6 @@ function InputToolbar(props: InputToolbarProps) { >
    -
    {props.toolbarOptions?.hideImageUpload || diff --git a/gui/src/components/mainInput/InputToolbar/bottom/PopoverTransition.tsx b/gui/src/components/mainInput/InputToolbar/bottom/PopoverTransition.tsx deleted file mode 100644 index 24b64c27b..000000000 --- a/gui/src/components/mainInput/InputToolbar/bottom/PopoverTransition.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import { Transition } from "@headlessui/react"; - -export default function PopoverTransition({ - children, - show, - afterLeave, -}: { - children: React.ReactNode; - show?: boolean; - afterLeave?: () => void; -}) { - return ( - - {children} - - ); -} diff --git a/gui/src/components/mainInput/Lump/index.tsx b/gui/src/components/mainInput/Lump/index.tsx index f46f432d0..f12e35c4d 100644 --- a/gui/src/components/mainInput/Lump/index.tsx +++ b/gui/src/components/mainInput/Lump/index.tsx @@ -66,7 +66,11 @@ export function Lump(props: LumpProps) { setSelectedSection={setSelectedSection} /> - +
    diff --git a/gui/src/components/modelSelection/ModeSelect.tsx b/gui/src/components/modelSelection/ModeSelect.tsx index 29f30e212..b2bb16410 100644 --- a/gui/src/components/modelSelection/ModeSelect.tsx +++ b/gui/src/components/modelSelection/ModeSelect.tsx @@ -1,10 +1,4 @@ // A dropdown menu for selecting between Chat, Edit, and Agent modes with keyboard shortcuts -import { - Listbox, - ListboxButton, - ListboxOption, - ListboxOptions, -} from "@headlessui/react"; import { ChatBubbleLeftIcon, CheckIcon, @@ -24,12 +18,13 @@ import { selectCurrentMode, setMode, } from "../../redux/slices/sessionSlice"; +import { getFontSize, getMetaKeyLabel, isJetBrains } from "../../util"; import { - fontSize, - getFontSize, - getMetaKeyLabel, - isJetBrains, -} from "../../util"; + Listbox, + ListboxButton, + ListboxOption, + ListboxOptions, +} from "../ui/Listbox"; const StyledListboxButton = styled(ListboxButton)` font-family: inherit; @@ -60,21 +55,6 @@ const StyledListboxOptions = styled(ListboxOptions)` background-color: ${vscInputBackground}; `; -const StyledListboxOption = styled(ListboxOption)` - border-radius: ${defaultBorderRadius}; - padding: 6px 12px; - cursor: ${(props) => (props.disabled ? "not-allowed" : "pointer")}; - display: flex; - align-items: center; - gap: 8px; - opacity: ${(props) => (props.disabled ? 0.5 : 1)}; - - &:hover { - background: ${(props) => - props.disabled ? "transparent" : `${lightGray}33`}; - } -`; - const ShortcutText = styled.span` color: ${lightGray}; font-size: ${getFontSize() - 3}px; @@ -126,60 +106,55 @@ function ModeSelect() { }} >
    - -
    - {getModeIcon(mode)} - {mode.charAt(0).toUpperCase() + mode.slice(1)} -
    -
    - - - - Agent - {/* */} + {getModeIcon(mode)} + {mode.charAt(0).toUpperCase() + mode.slice(1)} + + - - - Chat - {getMetaKeyLabel()}L + +
    + + Chat + {getMetaKeyLabel()}L +
    {mode === "chat" && } -
    + {!jetbrains && ( - - - Edit - {getMetaKeyLabel()}I + +
    + + Edit + {getMetaKeyLabel()}I +
    {mode === "edit" && } -
    + )}
    {getMetaKeyLabel()} . for next mode
    -
    +
    ); diff --git a/gui/src/components/modelSelection/ModelSelect.tsx b/gui/src/components/modelSelection/ModelSelect.tsx index 437e2304f..f3edc6937 100644 --- a/gui/src/components/modelSelection/ModelSelect.tsx +++ b/gui/src/components/modelSelection/ModelSelect.tsx @@ -1,4 +1,3 @@ -import { Listbox } from "@headlessui/react"; import { CheckIcon, ChevronDownIcon, @@ -21,6 +20,7 @@ import { import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; import { fontSize, isMetaEquivalentKeyPressed } from "../../util"; import Shortcut from "../gui/Shortcut"; +import { Listbox, ListboxButton, ListboxOption, ListboxOptions } from "../ui"; import { Divider } from "./platform/shared"; interface ModelOptionProps { @@ -36,8 +36,6 @@ interface Option { apiKey?: string; } -const MAX_HEIGHT_PX = 300; - const StyledListboxButton = styled(Listbox.Button)` font-family: inherit; display: flex; @@ -68,35 +66,28 @@ const StyledListboxOptions = styled(Listbox.Options)<{ $showabove: boolean }>` border-radius: ${defaultBorderRadius}; border: 0.5px solid ${lightGray}; background-color: ${vscInputBackground}; - - max-height: ${MAX_HEIGHT_PX}px; - overflow-y: scroll; - - scrollbar-width: none; - - ${(props) => (props.$showabove ? "bottom: 100%;" : "top: 100%;")} `; -const StyledListboxOption = styled(Listbox.Option)<{ isDisabled?: boolean }>` - border-radius: ${defaultBorderRadius}; - padding: 4px 12px; +// const StyledListboxOption = styled(Listbox.Option)<{ isDisabled?: boolean }>` +// border-radius: ${defaultBorderRadius}; +// padding: 4px 12px; - ${({ isDisabled }) => - !isDisabled && - ` - cursor: pointer; +// ${({ isDisabled }) => +// !isDisabled && +// ` +// cursor: pointer; - &:hover { - background: ${lightGray}33; - } - `} +// &:hover { +// background: ${lightGray}33; +// } +// `} - ${({ isDisabled }) => - isDisabled && - ` - opacity: 0.5; - `} -`; +// ${({ isDisabled }) => +// isDisabled && +// ` +// opacity: 0.5; +// `} +// `; const IconBase = styled.div<{ $hovered: boolean }>` width: 1.2em; @@ -151,16 +142,16 @@ function ModelOption({ } return ( - setHovered(true)} onMouseLeave={() => setHovered(false)} onClick={handleOptionClick} > -
    -
    +
    +
    @@ -178,7 +169,7 @@ function ModelOption({
    - + ); } @@ -186,7 +177,6 @@ function ModelSelect() { const dispatch = useDispatch(); const defaultModel = useAppSelector(selectDefaultModel); const allModels = useAppSelector((state) => state.config.config.models); - const [showAbove, setShowAbove] = useState(false); const buttonRef = useRef(null); const [options, setOptions] = useState([]); const [sortedOptions, setSortedOptions] = useState([]); @@ -216,12 +206,6 @@ function ModelSelect() { ); }, [allModels]); - useEffect(() => { - const handleResize = () => calculatePosition(); - window.addEventListener("resize", handleResize); - return () => window.removeEventListener("resize", handleResize); - }, []); - useEffect(() => { const handleKeyDown = (event: KeyboardEvent) => { if (event.key === "'" && isMetaEquivalentKeyPressed(event as any)) { @@ -242,18 +226,6 @@ function ModelSelect() { }; }, [options, defaultModel]); - function calculatePosition() { - if (!buttonRef.current) { - return; - } - const rect = buttonRef.current.getBoundingClientRect(); - const spaceBelow = window.innerHeight - rect.bottom; - const spaceAbove = rect.top; - const dropdownHeight = MAX_HEIGHT_PX; - - setShowAbove(spaceBelow < dropdownHeight && spaceAbove > spaceBelow); - } - function onClickAddModel(e: MouseEvent) { e.stopPropagation(); e.preventDefault(); @@ -282,30 +254,23 @@ function ModelSelect() { }} >
    - -
    +
    {modelSelectTitle(defaultModel) || "Select model"}{" "}
    - - -
    + + +
    {sortedOptions.map((option, idx) => ( - Add Chat model
    - + )} @@ -341,7 +306,7 @@ function ModelSelect() { meta ' to toggle model
    -
    +
    ); diff --git a/gui/src/components/modelSelection/ModelSelectionListbox.tsx b/gui/src/components/modelSelection/ModelSelectionListbox.tsx index bf8f5b1fc..5111a1bcc 100644 --- a/gui/src/components/modelSelection/ModelSelectionListbox.tsx +++ b/gui/src/components/modelSelection/ModelSelectionListbox.tsx @@ -1,10 +1,3 @@ -import { - Listbox, - ListboxButton, - ListboxOption, - ListboxOptions, - Transition, -} from "@headlessui/react"; import { CheckIcon, ChevronUpDownIcon, @@ -21,8 +14,14 @@ import { vscListActiveBackground, vscListActiveForeground, } from ".."; +import { + Listbox, + ListboxButton, + ListboxOption, + ListboxOptions, + Transition, +} from "../../components/ui"; import { DisplayInfo } from "../../pages/AddNewModel/configs/models"; - export const StyledListbox = styled(Listbox)` background-color: ${vscBackground}; `; diff --git a/gui/src/components/modelSelection/platform/AssistantSelect.tsx b/gui/src/components/modelSelection/platform/AssistantSelect.tsx index a842069e0..26b19e0d4 100644 --- a/gui/src/components/modelSelection/platform/AssistantSelect.tsx +++ b/gui/src/components/modelSelection/platform/AssistantSelect.tsx @@ -1,4 +1,3 @@ -import { Popover, PopoverButton, PopoverPanel } from "@headlessui/react"; import { ChevronDownIcon, PlusIcon } from "@heroicons/react/24/outline"; import { ProfileDescription } from "core/config/ConfigHandler"; import { useContext, useEffect, useRef } from "react"; @@ -7,7 +6,8 @@ import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { cycleProfile } from "../../../redux"; import { useAppDispatch } from "../../../redux/hooks"; import { fontSize, isMetaEquivalentKeyPressed } from "../../../util"; -import PopoverTransition from "../../mainInput/InputToolbar/bottom/PopoverTransition"; +import { Popover, PopoverButton, PopoverPanel, Transition } from "../../ui"; + import AssistantIcon from "./AssistantIcon"; import { AssistantSelectOptions } from "./AssistantSelectOptions"; @@ -88,7 +88,7 @@ export default function AssistantSelect() { - + { @@ -98,7 +98,7 @@ export default function AssistantSelect() { }} /> - +
    ); diff --git a/gui/src/components/ui/Combobox.tsx b/gui/src/components/ui/Combobox.tsx new file mode 100644 index 000000000..8ba9e51ff --- /dev/null +++ b/gui/src/components/ui/Combobox.tsx @@ -0,0 +1,15 @@ +import { + Combobox, + ComboboxButton, + ComboboxInput, + ComboboxOption, + ComboboxOptions, +} from "@headlessui/react"; + +export { + Combobox, + ComboboxButton, + ComboboxInput, + ComboboxOption, + ComboboxOptions, +}; diff --git a/gui/src/components/ui/Listbox.tsx b/gui/src/components/ui/Listbox.tsx index 91d22551b..a63f5eef0 100644 --- a/gui/src/components/ui/Listbox.tsx +++ b/gui/src/components/ui/Listbox.tsx @@ -3,104 +3,83 @@ import { ListboxOption as HLOption, ListboxOptions as HLOptions, Listbox, - Transition, } from "@headlessui/react"; import * as React from "react"; -import { useState } from "react"; import { cn } from "../../util/cn"; +import { FontSizeModifier, useFontSize } from "./font"; -type ListboxButtonProps = React.ComponentProps; -const ListboxButton = React.forwardRef( - ({ className, ...props }, ref) => ( - - ), -); - -type ListboxOptionsProps = React.ComponentProps; -const ListboxOptions = React.forwardRef( - ({ className, ...props }, ref) => ( - - ), -); - -type ListboxOptionProps = React.ComponentProps; -const ListboxOption = React.forwardRef( - ({ className, ...props }, ref) => ( - - ), -); - -type ListboxTransitionProps = React.ComponentProps; -function ListboxTransition(props: ListboxTransitionProps) { - return ( - - ); -} - -const people = [ - { id: 1, name: "Durward Reynolds" }, - { id: 2, name: "Kenton Towne" }, - { id: 3, name: "Therese Wunsch" }, - { id: 4, name: "Benedict Kessler" }, - { id: 5, name: "Katelyn Rohan" }, -]; - -function ExampleListbox() { - const [selectedPerson, setSelectedPerson] = useState(people[0]); - - return ( - - {selectedPerson.name} - - - {people.map((person) => ( - - {person.name} - - ))} - - - - ); -} - -export { - ExampleListbox, - Listbox, - ListboxButton, - ListboxOption, - ListboxOptions, +type ListboxButtonProps = React.ComponentProps & { + fontSizeModifier?: FontSizeModifier; }; + +const ListboxButton = React.forwardRef( + ({ fontSizeModifier = -3, ...props }, ref) => { + const fontSize = useFontSize(fontSizeModifier); + return ( + + ); + }, +); + +type ListboxOptionsProps = React.ComponentProps & { + fontSizeModifier?: FontSizeModifier; +}; +const ListboxOptions = React.forwardRef( + ({ fontSizeModifier = -3, ...props }, ref) => { + const fontSize = useFontSize(fontSizeModifier); + return ( + + ); + }, +); + +type ListboxOptionProps = React.ComponentProps & { + fontSizeModifier?: FontSizeModifier; +}; +const ListboxOption = React.forwardRef( + ({ fontSizeModifier = -3, ...props }, ref) => { + const fontSize = useFontSize(fontSizeModifier); + return ( + + ); + }, +); + +export { Listbox, ListboxButton, ListboxOption, ListboxOptions }; diff --git a/gui/src/components/ui/Listbox2.tsx b/gui/src/components/ui/Listbox2.tsx deleted file mode 100644 index 2267fe61a..000000000 --- a/gui/src/components/ui/Listbox2.tsx +++ /dev/null @@ -1,169 +0,0 @@ -// import { ChevronDownIcon } from "@heroicons/react/24/outline"; -// import React, { -// ButtonHTMLAttributes, -// LiHTMLAttributes, -// useEffect, -// useRef, -// useState, -// } from "react"; - -// import { cn } from "../../util/cn"; - -// import { createContext, useContext } from 'react'; - -// interface ListboxContextType { - -// }; - -// const defaultListboxContext: ListboxContextType = { - -// } - -// export const ListboxContext = createContext(defaultListboxContext); - -// const useListbox = () => { -// const context = useContext(ThemeContext); -// if (context === undefined) { -// throw new Error('useTheme must be used within a ThemeProvider'); -// } -// return context; -// }; - -// interface ListboxItemProps extends LiHTMLAttributes { -// isOpen: boolean; -// // selected: boolean -// } - -// export const ListboxItem: React.FC = (props) => { -// return
  • ; -// }; - -// interface ListboxButtonProps extends ButtonHTMLAttributes { -// isOpen: boolean; -// showChevron: boolean; -// } - -// export const ListboxButton: React.FC = (props) => { -// return ( -// -// ); -// }; - -// export const ContinueListbox: React.FC = ({ -// options, -// value, -// onChange, -// placeholder, -// }) => { -// const containerRef = useRef(null); -// const listRef = useRef(null); - -// return ( -//
    -//
      -// {options.map((option) => ( -//
    • { -// onChange?.(option); -// setIsOpen(false); -// }} -// className={`cursor-pointer list-none px-3 py-2 hover:bg-gray-100 ${option === value ? "bg-gray-200" : ""}`} -// > -// {option} -//
    • -// ))} -//
    -//
    -// ); -// }; - -// // interface UseListboxProps -// function useListbox() { -// const listRef = useRef(null); -// const containerRef = useRef(null); -// const buttonRef = useRef(null); - -// const [isOpen, setIsOpen] = useState(false); -// const [popupDirection, setPopupDirection] = useState<"down" | "up">("down"); - -// useEffect(() => { -// if (isOpen && containerRef.current && listRef.current) { -// const rect = containerRef.current.getBoundingClientRect(); -// const listHeight = listRef.current.offsetHeight; -// const viewportHeight = window.innerHeight; -// const spaceBelow = viewportHeight - rect.bottom; -// const spaceAbove = rect.top; -// setPopupDirection( -// spaceBelow >= listHeight || spaceBelow >= spaceAbove ? "down" : "up", -// ); -// } -// }, [isOpen]); - -// // Handle blurring/clicking outside the list - -// useEffect(() => { -// if (!listRef.current) return; -// const ref = listRef.current; -// const handleBlur = () => setIsOpen(false); -// ref.addEventListener("blur", handleBlur); -// return () => ref.removeEventListener("blur", handleBlur); -// }, [listRef]); - -// function closeList() { -// setIsOpen(false); -// } - -// function openList() { -// setIsOpen(true); -// listRef.current?.focus(); -// } - -// function toggleList() { -// if (isOpen) { -// closeList(); -// } else { -// openList(); -// } -// } - -// return { -// listRef, -// containerRef, -// buttonRef, -// isOpen, -// closeList, -// openList, -// toggleList, -// }; -// } - -// const options = ["Apple", "Banana", "Orange", "Mango", "Pineapple"]; -// export const ExampleListbox = () => { -// return ( -// console.log("Selected:", value)} -// /> -// ); -// }; diff --git a/gui/src/components/ui/Popover.tsx b/gui/src/components/ui/Popover.tsx new file mode 100644 index 000000000..4d6c03f89 --- /dev/null +++ b/gui/src/components/ui/Popover.tsx @@ -0,0 +1,3 @@ +import { Popover, PopoverButton, PopoverPanel } from "@headlessui/react"; + +export { Popover, PopoverButton, PopoverPanel }; diff --git a/gui/src/components/ui/Transition.tsx b/gui/src/components/ui/Transition.tsx new file mode 100644 index 000000000..34cc7e706 --- /dev/null +++ b/gui/src/components/ui/Transition.tsx @@ -0,0 +1,20 @@ +import { Transition as HLTransition } from "@headlessui/react"; +import { cn } from "../../util/cn"; + +type TransitionProps = React.ComponentProps; +function Transition(props: TransitionProps) { + return ( + + ); +} + +export { Transition }; diff --git a/gui/src/components/ui/font.ts b/gui/src/components/ui/font.ts new file mode 100644 index 000000000..67f44b03b --- /dev/null +++ b/gui/src/components/ui/font.ts @@ -0,0 +1,15 @@ +import { useMemo } from "react"; +import { useLocalStorage } from "../../context/LocalStorage"; + +export type FontSizeModifier = number | ((fontSize: number) => number); + +export const useFontSize = (modifier?: FontSizeModifier) => { + const { fontSize } = useLocalStorage(); + return useMemo(() => { + return !modifier + ? fontSize + : typeof modifier === "number" + ? fontSize + modifier + : modifier(fontSize); + }, [fontSize]); +}; diff --git a/gui/src/components/ui/index.tsx b/gui/src/components/ui/index.tsx new file mode 100644 index 000000000..e8f087bb1 --- /dev/null +++ b/gui/src/components/ui/index.tsx @@ -0,0 +1,4 @@ +export * from "./Combobox"; +export * from "./Listbox"; +export * from "./Popover"; +export * from "./Transition"; diff --git a/gui/src/context/LocalStorage.tsx b/gui/src/context/LocalStorage.tsx new file mode 100644 index 000000000..8c6d56b3a --- /dev/null +++ b/gui/src/context/LocalStorage.tsx @@ -0,0 +1,41 @@ +import React, { createContext, useContext, useEffect, useState } from "react"; +import { getLocalStorage } from "../util/localStorage"; + +interface LocalStorageType { + fontSize: number; +} + +const DEFAULT_LOCAL_STORAGE: LocalStorageType = { + fontSize: 14, +}; + +const LocalStorageContext = createContext( + DEFAULT_LOCAL_STORAGE, +); + +export const LocalStorageProvider: React.FC<{ children: React.ReactNode }> = ({ + children, +}) => { + const [values, setValues] = useState(DEFAULT_LOCAL_STORAGE); + + // TODO setvalue + + useEffect(() => { + const isJetbrains = getLocalStorage("ide") === "jetbrains"; + let fontSize = getLocalStorage("fontSize") ?? (isJetbrains ? 15 : 14); + setValues({ + fontSize, + }); + }, []); + + return ( + + {children} + + ); +}; + +export const useLocalStorage = () => { + const context = useContext(LocalStorageContext); + return context; +}; diff --git a/gui/src/pages/config/AccountButton.tsx b/gui/src/pages/config/AccountButton.tsx index ce09c1621..f09965dfe 100644 --- a/gui/src/pages/config/AccountButton.tsx +++ b/gui/src/pages/config/AccountButton.tsx @@ -1,13 +1,12 @@ +import { UserCircleIcon } from "@heroicons/react/24/outline"; + +import { SecondaryButton } from "../../components"; import { Popover, PopoverButton, PopoverPanel, Transition, -} from "@headlessui/react"; -import { UserCircleIcon } from "@heroicons/react/24/outline"; -import { Fragment } from "react"; - -import { SecondaryButton } from "../../components"; +} from "../../components/ui"; import { useAuth } from "../../context/Auth"; import { ScopeSelect } from "./ScopeSelect"; @@ -26,16 +25,8 @@ export function AccountButton() { - - + +
    {session.account.label} diff --git a/gui/src/pages/config/ModelRoleSelector.tsx b/gui/src/pages/config/ModelRoleSelector.tsx index bd777c44b..e8461a060 100644 --- a/gui/src/pages/config/ModelRoleSelector.tsx +++ b/gui/src/pages/config/ModelRoleSelector.tsx @@ -1,10 +1,15 @@ -import { Listbox, Transition } from "@headlessui/react"; import { CheckIcon, ChevronUpDownIcon } from "@heroicons/react/24/outline"; import { type ModelDescription } from "core"; -import { Fragment } from "react"; import { defaultBorderRadius } from "../../components"; import { ToolTip } from "../../components/gui/Tooltip"; import InfoHover from "../../components/InfoHover"; +import { + Listbox, + ListboxButton, + ListboxOption, + ListboxOptions, + Transition, +} from "../../components/ui"; import { fontSize } from "../../util"; interface ModelRoleSelectorProps { @@ -44,9 +49,9 @@ const ModelRoleSelector = ({ {({ open }) => (
    - 0 ? "hover:bg-vsc-input-background cursor-pointer" : "cursor-not-allowed opacity-50"} text-vsc-foreground relative m-0 flex w-full items-center justify-between rounded-md border border-solid px-1.5 py-0.5 text-left text-sm`} + className={`${models.length === 0 ? "cursor-not-allowed opacity-50" : ""} `} > {models.length === 0 ? (
    ) : null} - + - - + {models.map((option, idx) => ( - + + ))} - +
    )} diff --git a/gui/src/pages/config/ScopeSelect.tsx b/gui/src/pages/config/ScopeSelect.tsx index 7658ee8bd..8b0949fdb 100644 --- a/gui/src/pages/config/ScopeSelect.tsx +++ b/gui/src/pages/config/ScopeSelect.tsx @@ -1,14 +1,14 @@ -import { - Listbox, - ListboxButton, - ListboxOption, - ListboxOptions, -} from "@headlessui/react"; import { BuildingOfficeIcon, ChevronUpDownIcon, UserCircleIcon, } from "@heroicons/react/24/outline"; +import { + Listbox, + ListboxButton, + ListboxOption, + ListboxOptions, +} from "../../components/ui/Listbox"; import { useAuth } from "../../context/Auth"; import { useWebviewListener } from "../../hooks/useWebviewListener"; import { selectOrgThunk } from "../../redux"; diff --git a/gui/tsconfig.json b/gui/tsconfig.json index d41a6b9c3..d4f020465 100644 --- a/gui/tsconfig.json +++ b/gui/tsconfig.json @@ -19,6 +19,10 @@ "types": ["vitest/globals"] // Disabled for now since it's causing too many errors }, - "include": ["src", "../src/util/messenger.ts"], + "include": [ + "src", + "../src/util/messenger.ts", + "src/components/ui/DELETE_ME/.tsx" + ], "references": [{ "path": "./tsconfig.node.json" }] } From 3bf2d301d9da910f5462bfcb4ab1b7e5962f32bd Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Mon, 24 Mar 2025 17:51:27 -0700 Subject: [PATCH 03/12] styling tweaks --- extensions/vscode/package-lock.json | 4 +- .../components/OllamaStatus.tsx | 8 +- gui/src/components/dialogs/AddDocsDialog.tsx | 2 +- .../InputToolbar/bottom/ToolDropdownItem.tsx | 2 +- .../Lump/sections/docs/DocsDetailsDialog.tsx | 2 +- .../Lump/sections/docs/DocsIndexingStatus.tsx | 2 +- .../components/modelSelection/ModeSelect.tsx | 41 +-- .../components/modelSelection/ModelSelect.tsx | 41 +-- .../platform/AssistantSelect.tsx | 262 +++++++++++++++--- .../platform/AssistantSelectOptions.tsx | 202 -------------- gui/src/components/ui/Listbox.tsx | 8 +- gui/src/components/ui/Transition.tsx | 2 +- gui/src/index.css | 20 -- gui/src/pages/config/ModelRoleSelector.tsx | 12 +- gui/src/pages/config/UserSettingsForm.tsx | 4 +- gui/src/pages/gui/ToolCallDiv/ToolCall.tsx | 2 +- 16 files changed, 273 insertions(+), 341 deletions(-) delete mode 100644 gui/src/components/modelSelection/platform/AssistantSelectOptions.tsx diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index e8f7b966b..f1b847bfa 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "1.1.13", + "version": "1.1.14", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "1.1.13", + "version": "1.1.14", "license": "Apache-2.0", "dependencies": { "@continuedev/fetch": "^1.0.3", diff --git a/gui/src/components/OnboardingCard/components/OllamaStatus.tsx b/gui/src/components/OnboardingCard/components/OllamaStatus.tsx index 515958503..3839ba6ad 100644 --- a/gui/src/components/OnboardingCard/components/OllamaStatus.tsx +++ b/gui/src/components/OnboardingCard/components/OllamaStatus.tsx @@ -2,12 +2,12 @@ import { ArrowPathIcon, ArrowTopRightOnSquareIcon, } from "@heroicons/react/24/outline"; -import { useState, useContext, useEffect } from "react"; +import { useContext, useEffect, useState } from "react"; +import { StyledActionButton } from "../.."; import { IdeMessengerContext } from "../../../context/IdeMessenger"; import { providers } from "../../../pages/AddNewModel/configs/providers"; -import { StyledActionButton } from "../.."; -import OllamaCompletedStep from "./OllamaCompletedStep"; import { OllamaConnectionStatuses } from "../utils"; +import OllamaCompletedStep from "./OllamaCompletedStep"; interface OllamaStatusProps { isOllamaConnected: boolean; @@ -38,7 +38,7 @@ export function OllamaStatus({ isOllamaConnected }: OllamaStatusProps) { case OllamaConnectionStatuses.WaitingToDownload: return ( -

    {downloadUrl}

    +

    {downloadUrl}

    ); diff --git a/gui/src/components/dialogs/AddDocsDialog.tsx b/gui/src/components/dialogs/AddDocsDialog.tsx index f8006cee7..0221d112c 100644 --- a/gui/src/components/dialogs/AddDocsDialog.tsx +++ b/gui/src/components/dialogs/AddDocsDialog.tsx @@ -116,7 +116,7 @@ function AddDocsDialog() {