From 055ac64d8945b88bc99c53e90a7724e42c9f2f14 Mon Sep 17 00:00:00 2001 From: chenyu <63953834+chenyu-01@users.noreply.github.com> Date: Fri, 27 Dec 2024 10:44:15 +0800 Subject: [PATCH] feat: add search box and title above model list --- app/components/ui-lib.module.scss | 31 ++++++++- app/components/ui-lib.tsx | 103 ++++++++++++++++++++---------- app/locales/cn.ts | 3 + app/locales/en.ts | 3 + 4 files changed, 103 insertions(+), 37 deletions(-) diff --git a/app/components/ui-lib.module.scss b/app/components/ui-lib.module.scss index 56aeac311..f71ce0034 100644 --- a/app/components/ui-lib.module.scss +++ b/app/components/ui-lib.module.scss @@ -78,7 +78,7 @@ .list { border: var(--border-in-light); - border-radius: 10px; + border-radius: 0 0 10px 10px; box-shadow: var(--card-shadow); margin-bottom: 20px; animation: slide-in ease 0.3s; @@ -313,11 +313,37 @@ .selector-item-disabled { 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 { min-width: 300px; .list { - max-height: 90vh; + max-height: 50vh; overflow-x: hidden; overflow-y: auto; @@ -336,4 +362,3 @@ } } } - diff --git a/app/components/ui-lib.tsx b/app/components/ui-lib.tsx index a64265235..bc7128fe7 100644 --- a/app/components/ui-lib.tsx +++ b/app/components/ui-lib.tsx @@ -507,44 +507,79 @@ export function Selector(props: { 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 (
props.onClose?.()}>
+ {/* todo: add searchbox */} +
+
+ {Locale.UI.SelectorTitle} +
+
+ onSearch(e.currentTarget.value)} + /> +
+
- {props.items.map((item, i) => { - const selected = selectedValues.includes(item.value); - return ( - { - if (item.disable) { - e.stopPropagation(); - } else { - handleSelection(e, item.value); - } - }} - > - {selected ? ( -
- ) : ( - <> - )} -
- ); - })} + {filteredItems.length ? ( + filteredItems.map((item, i) => { + const selected = selectedValues.includes(item.value); + return ( + { + if (item.disable) { + e.stopPropagation(); + } else { + handleSelection(e, item.value); + } + }} + > + {selected ? ( +
+ ) : ( + <> + )} +
+ ); + }) + ) : ( + + )}
diff --git a/app/locales/cn.ts b/app/locales/cn.ts index 47be019a8..fd40c175b 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -758,6 +758,9 @@ const cn = { Import: "导入", Sync: "同步", Config: "配置", + Search: "搜索", + SelectorTitle: "选择model", + NoResults: "没有结果", }, Exporter: { Description: { diff --git a/app/locales/en.ts b/app/locales/en.ts index fddb6f091..fb80ca4b4 100644 --- a/app/locales/en.ts +++ b/app/locales/en.ts @@ -764,6 +764,9 @@ const en: LocaleType = { Import: "Import", Sync: "Sync", Config: "Config", + Search: "Search", + SelectorTitle: "Choose Model", + NoResults: "No Results", }, Exporter: { Description: {