Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/components/icon-select.tsx
Views: 687
/* Search through and select icons12See frontend/components/iconfont.cn/README.md for how to add anything from3the massive https://www.iconfont.cn/?lang=us4*/56import { Input } from "antd";7import { Icon, iconNames, IconName } from "./icon";8import { CSSProperties, useEffect, useState } from "react";9const { Search } = Input;1011interface Props {12onSelect?: (name: IconName) => void;13onChange?: (search: string) => void;14defaultSearch?: string;15search?: string;16style?: CSSProperties;17fontSize?: string;18disabled?: boolean;19}2021export default function IconSelect({22onSelect,23onChange,24defaultSearch,25search: search0,26style,27fontSize,28disabled,29}: Props) {30const [search, setSearch] = useState<string>(search0 ?? defaultSearch ?? "");3132useEffect(() => {33if (search0 != null) {34setSearch(search0);35}36}, [search0]);3738return (39<div style={{ fontSize: "24pt", ...style }}>40<Search41disabled={disabled}42placeholder="Search..."43value={search}44allowClear45onChange={(e) => {46setSearch(e.target.value);47onChange?.(e.target.value);48}}49style={{ maxWidth: "400px" }}50onPressEnter={() => {51// if there are any results, choose the first one52const search0 = search.trim().toLowerCase();53for (const name of iconNames) {54if (name.includes(search0)) {55setSearch(name);56onChange?.(name);57onSelect?.(name);58return;59}60}61}}62/>63<div64style={{65marginTop: "10px",66overflowY: "scroll",67border: "1px solid lightgrey",68}}69>70{icons(search, fontSize, (name) => {71setSearch(name);72onSelect?.(name);73})}74</div>75</div>76);77}7879function icons(search, fontSize, onClick) {80search = search.trim().toLowerCase();81const v: JSX.Element[] = [];82for (const name of iconNames) {83if (!name.includes(search)) continue;84v.push(85<Match fontSize={fontSize} key={name} name={name} onClick={onClick} />86);87}88return v;89}9091function Match({92name,93onClick,94fontSize = "11pt",95}: {96name: IconName;97onClick: (name: IconName) => void;98fontSize?;99}) {100return (101<div102style={{103display: "inline-block",104width: "100px",105cursor: "pointer",106whiteSpace: "nowrap",107overflow: "hidden",108textOverflow: "ellipsis",109textAlign: "center",110}}111onClick={() => onClick(name)}112>113<div style={{ margin: "0 10px" }}>114<Icon name={name} />115</div>116<div style={{ fontSize }}>{name}</div>117</div>118);119}120121122