给所有select元素添加一个右侧下拉按钮

This commit is contained in:
PaRaD1SE98 2023-05-10 07:14:49 +00:00
parent 0ad91101a4
commit 96e3d3a22c
6 changed files with 70 additions and 15 deletions

View File

@ -14,7 +14,7 @@ import CopyIcon from "../icons/copy.svg";
import { DEFAULT_MASK_AVATAR, Mask, useMaskStore } from "../store/mask";
import { Message, ModelConfig, ROLES, useChatStore } from "../store";
import { Input, List, ListItem, Modal, Popover } from "./ui-lib";
import { Input, List, ListItem, Modal, Popover, Select } from "./ui-lib";
import { Avatar, AvatarPicker } from "./emoji";
import Locale, { AllLangs, Lang } from "../locales";
import { useNavigate } from "react-router-dom";
@ -116,7 +116,7 @@ function ContextPromptItem(props: {
return (
<div className={chatStyle["context-prompt-row"]}>
{!focusingInput && (
<select
<Select
value={props.prompt.role}
className={chatStyle["context-role"]}
onChange={(e) =>
@ -131,7 +131,7 @@ function ContextPromptItem(props: {
{r}
</option>
))}
</select>
</Select>
)}
<Input
value={props.prompt.content}
@ -307,7 +307,7 @@ export function MaskPage() {
autoFocus
onInput={(e) => onSearch(e.currentTarget.value)}
/>
<select
<Select
className={styles["mask-filter-lang"]}
value={filterLang ?? Locale.Settings.Lang.All}
onChange={(e) => {
@ -327,7 +327,7 @@ export function MaskPage() {
{Locale.Settings.Lang.Options[lang]}
</option>
))}
</select>
</Select>
<IconButton
className={styles["mask-create"]}

View File

@ -2,7 +2,7 @@ import { ALL_MODELS, ModalConfigValidator, ModelConfig } from "../store";
import Locale from "../locales";
import { InputRange } from "./input-range";
import { List, ListItem } from "./ui-lib";
import { List, ListItem, Select } from "./ui-lib";
export function ModelConfigList(props: {
modelConfig: ModelConfig;
@ -11,7 +11,7 @@ export function ModelConfigList(props: {
return (
<>
<ListItem title={Locale.Settings.Model}>
<select
<Select
value={props.modelConfig.model}
onChange={(e) => {
props.updateConfig(
@ -27,7 +27,7 @@ export function ModelConfigList(props: {
{v.name}
</option>
))}
</select>
</Select>
</ListItem>
<ListItem
title={Locale.Settings.Temperature.Title}

View File

@ -10,7 +10,15 @@ import ClearIcon from "../icons/clear.svg";
import LoadingIcon from "../icons/three-dots.svg";
import EditIcon from "../icons/edit.svg";
import EyeIcon from "../icons/eye.svg";
import { Input, List, ListItem, Modal, PasswordInput, Popover } from "./ui-lib";
import {
Input,
List,
ListItem,
Modal,
PasswordInput,
Popover,
Select,
} from "./ui-lib";
import { ModelConfigList } from "./model-config";
import { IconButton } from "./button";
@ -368,7 +376,7 @@ export function Settings() {
</ListItem>
<ListItem title={Locale.Settings.SendKey}>
<select
<Select
value={config.submitKey}
onChange={(e) => {
updateConfig(
@ -382,11 +390,11 @@ export function Settings() {
{v}
</option>
))}
</select>
</Select>
</ListItem>
<ListItem title={Locale.Settings.Theme}>
<select
<Select
value={config.theme}
onChange={(e) => {
updateConfig(
@ -399,11 +407,11 @@ export function Settings() {
{v}
</option>
))}
</select>
</Select>
</ListItem>
<ListItem title={Locale.Settings.Lang.Name}>
<select
<Select
value={getLang()}
onChange={(e) => {
changeLang(e.target.value as any);
@ -414,7 +422,7 @@ export function Settings() {
{Locale.Settings.Lang.Options[lang]}
</option>
))}
</select>
</Select>
</ListItem>
<ListItem

View File

@ -203,3 +203,28 @@
resize: none;
min-width: 50px;
}
.select-with-icon {
position: relative;
max-width: fit-content;
.select-with-icon-select {
border: var(--border-in-light);
padding: 10px 25px 10px 10px;
border-radius: 10px;
appearance: none;
cursor: pointer;
background-color: var(--white);
color: var(--black);
text-align: center;
position: relative;
}
.select-with-icon-icon {
position: absolute;
top: 50%;
right: 10px;
transform: translateY(-50%);
pointer-events: none;
}
}

View File

@ -3,6 +3,7 @@ import LoadingIcon from "../icons/three-dots.svg";
import CloseIcon from "../icons/close.svg";
import EyeIcon from "../icons/eye.svg";
import EyeOffIcon from "../icons/eye-off.svg";
import DownIcon from "../icons/down.svg";
import { createRoot } from "react-dom/client";
import React, { HTMLProps, useEffect, useState } from "react";
@ -244,3 +245,23 @@ export function PasswordInput(props: HTMLProps<HTMLInputElement>) {
</div>
);
}
export function Select(
props: React.DetailedHTMLProps<
React.SelectHTMLAttributes<HTMLSelectElement>,
HTMLSelectElement
>,
) {
const { className, children, ...otherProps } = props;
return (
<div className={styles["select-with-icon"]}>
<select
className={`${styles["select-with-icon-select"]} ${className}`}
{...otherProps}
>
{children}
</select>
<DownIcon className={styles["select-with-icon-icon"]} />
</div>
);
}

1
app/icons/down.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="16" height="16" viewBox="0 0 16 16" fill="none"><defs><rect id="path_0" x="0" y="0" width="16" height="16" /></defs><g opacity="1" transform="translate(0 0) rotate(-90 8 8)"><mask id="bg-mask-0" fill="white"><use xlink:href="#path_0"></use></mask><g mask="url(#bg-mask-0)" ><path id="路径 1" style="stroke:#333333; stroke-width:1.3333333333333333; stroke-opacity:1; stroke-dasharray:0 0" transform="translate(6.333333333333333 4) rotate(0 2 4)" d="M4,8L0,4L4,0 " /></g></g></svg>

After

Width:  |  Height:  |  Size: 575 B