This commit is contained in:
Chen Yu 2025-02-05 10:54:03 +08:00 committed by GitHub
commit 1ad58f1c4b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 111 additions and 40 deletions

View File

@ -78,10 +78,10 @@
.list { .list {
border: var(--border-in-light); border: var(--border-in-light);
border-radius: 10px; border-radius: 0 0 10px 10px;
box-shadow: var(--card-shadow); box-shadow: var(--card-shadow);
margin-bottom: 20px; margin-bottom: 20px;
animation: slide-in ease 0.3s;
background: var(--white); background: var(--white);
} }
@ -313,11 +313,38 @@
.selector-item-disabled { .selector-item-disabled {
opacity: 0.6; opacity: 0.6;
} }
.selector-bar {
background-color: var(--white);
border: solid var(--border-in-light);
border-top-left-radius: 10px;
border-top-right-radius: 10px;
min-height: 40px;
width: 100%;
}
.selector-title {
font-size: large;
font-weight: bold;
padding: 10px;
}
.selector-search-container {
display: flex;
align-items: center;
justify-content: space-between;
padding: 10px;
border-bottom: solid var(--border-in-light);
}
.selector-search-input {
padding: 5px;
margin-right: 5px;
flex-grow: 1;
max-width: none;
}
&-content { &-content {
min-width: 300px; animation: slide-in ease 0.3s;
width: 30rem;
height: 60vh;
.list { .list {
max-height: 90vh;
overflow-x: hidden; overflow-x: hidden;
overflow-y: auto; overflow-y: auto;
@ -336,4 +363,3 @@
} }
} }
} }

View File

@ -507,44 +507,83 @@ export function Selector<T>(props: {
props.onClose?.(); props.onClose?.();
} }
}; };
const [searchText, setSearchText] = useState("");
const [filteredItems, setFilteredItems] = useState([...props.items]);
function onSearch(text: string) {
setSearchText(text);
if (text === "") {
setFilteredItems([...props.items]);
return;
}
// filter by items title
const newItems = props.items.filter((item) =>
item.title.toLowerCase().includes(text.toLowerCase()),
);
setFilteredItems([...newItems]);
}
return ( return (
<div className={styles["selector"]} onClick={() => props.onClose?.()}> <div className={styles["selector"]} onClick={() => props.onClose?.()}>
<div className={styles["selector-content"]}> <div
className={styles["selector-content"]}
onClick={(e) => e.stopPropagation()}
>
{/* title and search box */}
<div className={styles["selector-bar"]}>
<div className={styles["selector-title"]}>
{Locale.UI.SelectorTitle}
</div>
<div className={styles["selector-search-container"]}>
<input
type="text"
className={styles["selector-search-input"]}
placeholder={Locale.UI.Search}
autoFocus
onInput={(e) => onSearch(e.currentTarget.value)}
/>
</div>
</div>
{/* list content */}
<List> <List>
{props.items.map((item, i) => { {filteredItems.length ? (
const selected = selectedValues.includes(item.value); filteredItems.map((item, i) => {
return ( const selected = selectedValues.includes(item.value);
<ListItem return (
className={clsx(styles["selector-item"], { <ListItem
[styles["selector-item-disabled"]]: item.disable, className={clsx(styles["selector-item"], {
})} [styles["selector-item-disabled"]]: item.disable,
key={i} })}
title={item.title} key={i}
subTitle={item.subTitle} title={item.title}
onClick={(e) => { subTitle={item.subTitle}
if (item.disable) { onClick={(e) => {
e.stopPropagation(); if (item.disable) {
} else { e.stopPropagation();
handleSelection(e, item.value); } else {
} handleSelection(e, item.value);
}} }
> }}
{selected ? ( >
<div {selected ? (
style={{ <div
height: 10, style={{
width: 10, height: 10,
backgroundColor: "var(--primary)", width: 10,
borderRadius: 10, backgroundColor: "var(--primary)",
}} borderRadius: 10,
></div> }}
) : ( ></div>
<></> ) : (
)} <></>
</ListItem> )}
); </ListItem>
})} );
})
) : (
<ListItem
title={Locale.UI.NoResults}
className={styles["selector-item"]}
></ListItem>
)}
</List> </List>
</div> </div>
</div> </div>

View File

@ -784,6 +784,9 @@ const cn = {
Import: "导入", Import: "导入",
Sync: "同步", Sync: "同步",
Config: "配置", Config: "配置",
Search: "搜索",
SelectorTitle: "选择",
NoResults: "没有结果",
}, },
Exporter: { Exporter: {
Description: { Description: {

View File

@ -790,6 +790,9 @@ const en: LocaleType = {
Import: "Import", Import: "Import",
Sync: "Sync", Sync: "Sync",
Config: "Config", Config: "Config",
Search: "Search",
SelectorTitle: "Select",
NoResults: "No Results",
}, },
Exporter: { Exporter: {
Description: { Description: {