💄 redesigned combobox

This commit is contained in:
Nate Sesti 2023-12-05 17:31:33 -08:00
parent 9157ad0d05
commit 60a3cbd9bf

View file

@ -38,7 +38,6 @@ import {
PlusIcon,
SparklesIcon,
TrashIcon,
XMarkIcon,
ExclamationCircleIcon,
} from "@heroicons/react/24/outline";
import { postToIde } from "../../util/ide";
@ -47,7 +46,6 @@ import { MeiliSearch } from "meilisearch";
import { setBottomMessage } from "../../redux/slices/uiStateSlice";
import { useDispatch, useSelector } from "react-redux";
import { RootStore } from "../../redux/store";
import ContinueButton from "./ContinueButton";
import {
getFontSize,
getMarkdownLanguageTagForFile,
@ -204,6 +202,59 @@ const MainTextInput = styled.textarea<{
&::placeholder {
color: ${lightGray}cc;
}
position: relative;
`;
const InputToolbar = styled.div`
position: absolute;
display: flex;
gap: 4px;
right: 12px;
bottom: 4px;
width: calc(100% - 28px);
align-items: center;
z-index: 100;
font-size: 10px;
cursor: text;
`;
const EnterButton = styled.div<{ offFocus: boolean }>`
padding: 2px 4px;
display: flex;
align-items: center;
background-color: ${(props) =>
props.offFocus ? undefined : lightGray + "33"};
border-radius: ${defaultBorderRadius};
color: #fff8;
&:hover {
background-color: #cf313199;
color: white;
}
cursor: pointer;
`;
const StopButton = styled.div`
width: fit-content;
margin-right: auto;
margin-left: auto;
font-size: 12px;
border: 0.5px solid ${lightGray};
border-radius: ${defaultBorderRadius};
padding: 4px 8px;
color: ${lightGray};
&:hover {
}
cursor: pointer;
`;
const DeleteButtonDiv = styled.div`
@ -855,6 +906,16 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
backgroundColor: vscBackground,
}}
>
{active && props.isMainInput && (
<StopButton
onClick={() => {
client?.stopSession();
dispatch(setActive(false));
}}
>
⌘ ⌫ Cancel
</StopButton>
)}
{selectedContextItems.length === 0 && props.isMainInput && (
<div
style={{
@ -866,15 +927,6 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
width: "calc(100% - 24px)",
}}
>
<span
onClick={() => {
downshiftProps.setInputValue("@");
inputRef.current?.focus();
}}
className="hover:underline cursor-pointer"
>
+ Add Context
</span>
{downshiftProps.inputValue?.startsWith("/edit") && (
<span className="float-right">Inserting at cursor</span>
)}
@ -1360,6 +1412,72 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
ref: inputRef,
})}
/>
{(inputFocused || props.isMainInput) && (
<InputToolbar>
<span
style={{
color: lightGray,
}}
onClick={() => {
downshiftProps.setInputValue("@");
inputRef.current?.focus();
}}
className="hover:underline cursor-pointer mr-auto"
>
+ Add Context
</span>
<span
style={{
color: downshiftProps.inputValue?.startsWith("/codebase")
? "#fff8"
: lightGray,
backgroundColor: downshiftProps.inputValue?.startsWith(
"/codebase"
)
? lightGray + "33"
: undefined,
borderRadius: defaultBorderRadius,
padding: "2px 4px",
}}
onClick={() => {
const inputValue = downshiftProps.inputValue;
if (inputValue?.startsWith("/codebase")) {
downshiftProps.setInputValue(
inputValue.replace("/codebase ", "")
);
} else {
downshiftProps.setInputValue("/codebase " + inputValue);
}
inputRef.current?.focus();
}}
className={"hover:underline cursor-pointer float-right"}
>
{downshiftProps.inputValue?.startsWith("/codebase")
? "Using codebase"
: `${getMetaKeyLabel()} ⏎ Use codebase`}
</span>
<EnterButton
offFocus={downshiftProps.inputValue?.startsWith("/codebase")}
// disabled={
// !active &&
// (!(inputRef.current as any)?.value ||
// typeof client === "undefined")
// }
onClick={() => {
if (active) {
client?.stopSession();
dispatch(setActive(false));
} else {
props.onEnter?.(undefined);
}
}}
>
⏎ Enter
</EnterButton>
</InputToolbar>
)}
{props.isMainInput || (
<DeleteButtonDiv ref={deleteButtonDivRef}>
{isHovered && (
@ -1394,7 +1512,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
<ArrowUpLeftIcon width="1.3em" height="1.3em" />
</HeaderButtonWithText>
)}
<HeaderButtonWithText
{/* <HeaderButtonWithText
onClick={(e) => {
e.stopPropagation();
if (props.active && props.groupIndices) {
@ -1411,7 +1529,7 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
// <StopCircleIcon width="1.4em" height="1.4em" />
<XMarkIcon width="1.4em" height="1.4em" />
)}
</HeaderButtonWithText>
</HeaderButtonWithText> */}
</>
</div>
)}
@ -1554,59 +1672,12 @@ const ComboBox = React.forwardRef((props: ComboBoxProps, ref) => {
</div>
</Ul>
</div>
{props.isMainInput && (
<>
<div
style={{
color: lightGray,
fontSize: "10px",
backgroundColor: vscBackground,
width: "calc(100% - 16px)",
height: "0",
marginTop: "4px",
}}
>
<span
onClick={() => {
const inputValue = downshiftProps.inputValue;
if (inputValue?.startsWith("/codebase")) {
downshiftProps.setInputValue(
inputValue.replace("/codebase ", "")
);
} else {
downshiftProps.setInputValue("/codebase " + inputValue);
}
inputRef.current?.focus();
}}
className={"hover:underline cursor-pointer float-right"}
>
{downshiftProps.inputValue?.startsWith("/codebase")
? "Using codebase"
: `${getMetaKeyLabel()} ⏎ Use codebase`}
</span>
</div>
<br />
<br />
</>
)}
{props.isMainInput && (
<ContinueButton
disabled={
!active &&
(!(inputRef.current as any)?.value || typeof client === "undefined")
}
onClick={() => {
if (active) {
client?.stopSession();
dispatch(setActive(false));
} else {
props.onEnter?.(undefined);
}
}}
showStop={active}
/>
)}
</div>
);
});