Skip to content

Commit

Permalink
给所有select元素添加一个右侧下拉按钮
Browse files Browse the repository at this point in the history
  • Loading branch information
PaRaD1SE98 committed May 10, 2023
1 parent 0ad9110 commit 96e3d3a
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 15 deletions.
10 changes: 5 additions & 5 deletions app/components/mask.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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) =>
Expand All @@ -131,7 +131,7 @@ function ContextPromptItem(props: {
{r}
</option>
))}
</select>
</Select>
)}
<Input
value={props.prompt.content}
Expand Down Expand Up @@ -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) => {
Expand All @@ -327,7 +327,7 @@ export function MaskPage() {
{Locale.Settings.Lang.Options[lang]}
</option>
))}
</select>
</Select>

<IconButton
className={styles["mask-create"]}
Expand Down
6 changes: 3 additions & 3 deletions app/components/model-config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -11,7 +11,7 @@ export function ModelConfigList(props: {
return (
<>
<ListItem title={Locale.Settings.Model}>
<select
<Select
value={props.modelConfig.model}
onChange={(e) => {
props.updateConfig(
Expand All @@ -27,7 +27,7 @@ export function ModelConfigList(props: {
{v.name}
</option>
))}
</select>
</Select>
</ListItem>
<ListItem
title={Locale.Settings.Temperature.Title}
Expand Down
22 changes: 15 additions & 7 deletions app/components/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -368,7 +376,7 @@ export function Settings() {
</ListItem>

<ListItem title={Locale.Settings.SendKey}>
<select
<Select
value={config.submitKey}
onChange={(e) => {
updateConfig(
Expand All @@ -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(
Expand All @@ -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);
Expand All @@ -414,7 +422,7 @@ export function Settings() {
{Locale.Settings.Lang.Options[lang]}
</option>
))}
</select>
</Select>
</ListItem>

<ListItem
Expand Down
25 changes: 25 additions & 0 deletions app/components/ui-lib.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
21 changes: 21 additions & 0 deletions app/components/ui-lib.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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 change: 1 addition & 0 deletions app/icons/down.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 96e3d3a

Please sign in to comment.