diff --git a/app/components/ui-lib.module.scss b/app/components/ui-lib.module.scss index 56aeac311ae..403653b0032 100644 --- a/app/components/ui-lib.module.scss +++ b/app/components/ui-lib.module.scss @@ -78,10 +78,10 @@ .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; + background: var(--white); } @@ -313,11 +313,38 @@ .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; + animation: slide-in ease 0.3s; + width: 30rem; + height: 60vh; .list { - max-height: 90vh; overflow-x: hidden; overflow-y: auto; @@ -336,4 +363,3 @@ } } } - diff --git a/app/components/ui-lib.tsx b/app/components/ui-lib.tsx index a642652358f..1fa614f3b4e 100644 --- a/app/components/ui-lib.tsx +++ b/app/components/ui-lib.tsx @@ -507,44 +507,83 @@ 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?.()}> -
+
e.stopPropagation()} + > + {/* title and search box */} +
+
+ {Locale.UI.SelectorTitle} +
+
+ onSearch(e.currentTarget.value)} + /> +
+
+ {/* list content */} - {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 47be019a809..f483be804bb 100644 --- a/app/locales/cn.ts +++ b/app/locales/cn.ts @@ -758,6 +758,9 @@ const cn = { Import: "导入", Sync: "同步", Config: "配置", + Search: "搜索", + SelectorTitle: "选择", + NoResults: "没有结果", }, Exporter: { Description: { diff --git a/app/locales/en.ts b/app/locales/en.ts index fddb6f09153..0a1d0edd2ee 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: "Select", + NoResults: "No Results", }, Exporter: { Description: {