Update WBBR frontend template collection
This commit is contained in:
199
app/icons/IconLibrary.module.css
Normal file
199
app/icons/IconLibrary.module.css
Normal file
@@ -0,0 +1,199 @@
|
||||
@keyframes toastIn { from { opacity: 0; transform: translate(-50%,10px); } to { opacity: 1; transform: translate(-50%,0); } }
|
||||
|
||||
.page {
|
||||
--ink: #222a3c;
|
||||
--muted: #8e96a5;
|
||||
--line: #e6e8ed;
|
||||
--blue: #4169e1;
|
||||
min-height: 100vh;
|
||||
background: #f7f8fa;
|
||||
color: var(--ink);
|
||||
font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
|
||||
}
|
||||
.page * { box-sizing: border-box; }
|
||||
.page button, .page input { font: inherit; }
|
||||
.topbar { position: sticky; top: 0; z-index: 30; height: 62px; display: flex; align-items: center; padding: 0 20px; border-bottom: 1px solid #e4e6eb; background: rgba(255,255,255,.96); backdrop-filter: blur(12px); }
|
||||
.brand { display: grid; grid-template-columns: 31px auto; align-items: center; column-gap: 9px; color: #252d40; text-decoration: none; }
|
||||
.brand > span { grid-row: 1/3; width: 31px; height: 31px; display: grid; place-items: center; border-radius: 9px; background: #292f42; color: #fff; font-family: Georgia,serif; font-size: 15px; }
|
||||
.brand strong { align-self: end; font-size: 12px; line-height: 1; }
|
||||
.brand small { align-self: start; margin-top: 3px; color: #a0a5af; font-size: 5px; letter-spacing: 1px; }
|
||||
.topbar nav { height: 100%; display: flex; align-items: stretch; gap: 3px; margin-left: 39px; }
|
||||
.topbar nav a { position: relative; display: flex; align-items: center; padding: 0 13px; color: #8b92a0; text-decoration: none; font-size: 9px; }
|
||||
.topbar nav a:hover, .topbar nav .activeNav { color: #343d52; }
|
||||
.topbar nav .activeNav::after { content: ""; position: absolute; inset: auto 12px -1px; height: 2px; background: var(--blue); }
|
||||
.headerActions { display: flex; align-items: center; gap: 7px; margin-left: auto; }
|
||||
.headerActions button { height: 30px; padding: 0 10px; border: 1px solid #e0e3e9; border-radius: 6px; background: #fff; color: #687285; cursor: pointer; font-size: 8px; }
|
||||
.headerActions button:hover:not(:disabled), .headerActions .favoriteFilterActive { border-color: #b4c4ec; background: #f2f5ff; color: #3d60c1; }
|
||||
.headerActions button:disabled { opacity: .45; cursor: not-allowed; }
|
||||
.headerActions > span { width: 29px; height: 29px; display: grid; place-items: center; margin-left: 4px; border-radius: 50%; background: #e1e8fb; color: #4163ac; font-size: 8px; font-weight: 700; }
|
||||
|
||||
.workspace { display: grid; grid-template-columns: 194px minmax(0,1fr) 308px; align-items: start; min-height: calc(100vh - 62px); }
|
||||
.sidebar { position: sticky; top: 62px; height: calc(100vh - 62px); display: flex; flex-direction: column; border-right: 1px solid #e3e6eb; background: #fff; }
|
||||
.sidebarTitle { padding: 27px 18px 17px; }
|
||||
.sidebarTitle > span { display: block; margin-bottom: 4px; color: #6880bd; font-size: 6px; font-weight: 800; letter-spacing: 1.4px; }
|
||||
.sidebarTitle strong { display: block; font-size: 14px; }
|
||||
.sidebarTitle small { display: block; margin-top: 5px; color: #a0a6b0; font-size: 7px; }
|
||||
.categories { padding: 4px 9px; }
|
||||
.categories button { width: 100%; height: 38px; display: flex; align-items: center; gap: 9px; padding: 0 10px; border: 0; border-radius: 7px; background: transparent; color: #737d8f; cursor: pointer; font-size: 8px; text-align: left; }
|
||||
.categories button:hover { background: #f5f6f9; }
|
||||
.categories .categoryActive { background: #edf2ff; color: #385fc5; font-weight: 700; }
|
||||
.categories button > span { width: 20px; color: #929bac; font-family: "Segoe UI Symbol",sans-serif; font-size: 12px; text-align: center; }
|
||||
.categories .categoryActive > span { color: #4169d3; }
|
||||
.categories button > b { margin-left: auto; padding: 2px 5px; border-radius: 8px; background: #f0f1f4; color: #9ca3ae; font-size: 6px; }
|
||||
.categories .categoryActive > b { background: #dce6ff; color: #4770d2; }
|
||||
.sidebarHelp { display: flex; gap: 9px; margin: auto 12px 14px; padding: 12px; border: 1px solid #e5e8ef; border-radius: 9px; background: #f8f9fb; }
|
||||
.sidebarHelp > span { width: 21px; height: 21px; display: grid; place-items: center; flex: 0 0 auto; border-radius: 50%; background: #e5ecfd; color: #4a6fca; font-family: Georgia,serif; font-size: 9px; font-style: italic; }
|
||||
.sidebarHelp p { display: flex; flex-direction: column; gap: 4px; margin: 0; }
|
||||
.sidebarHelp strong { font-size: 7px; }
|
||||
.sidebarHelp small { color: #9da4b0; font-size: 6px; line-height: 1.6; }
|
||||
|
||||
.main { min-width: 0; padding: 23px 25px 70px; }
|
||||
.hero { position: relative; min-height: 145px; display: flex; align-items: center; justify-content: space-between; overflow: hidden; margin-bottom: 15px; padding: 26px 31px; border-radius: 13px; background: radial-gradient(circle at 79% 14%,rgba(124,145,255,.2),transparent 28%),linear-gradient(120deg,#242a3e,#333c59); color: #fff; }
|
||||
.hero > div:first-child { position: relative; z-index: 2; }
|
||||
.hero p { margin: 0 0 6px; color: #aebcff; font-size: 6px; font-weight: 800; letter-spacing: 1.8px; }
|
||||
.hero h1 { margin: 0 0 8px; font-size: 21px; letter-spacing: -.4px; }
|
||||
.hero div > span { color: rgba(255,255,255,.52); font-size: 8px; }
|
||||
.heroSamples { display: flex; align-items: center; gap: 8px; margin-right: 4px; }
|
||||
.heroSamples span { width: 47px; height: 54px; display: grid; place-items: center; border: 1px solid rgba(255,255,255,.14); border-radius: 10px; background: rgba(255,255,255,.08); color: rgba(255,255,255,.8)!important; font-family: "Segoe UI Symbol",sans-serif; font-size: 22px!important; box-shadow: 0 9px 22px rgba(5,8,20,.14); backdrop-filter: blur(5px); }
|
||||
.toolbar { min-height: 58px; display: flex; align-items: center; gap: 14px; padding: 11px 13px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
|
||||
.search { height: 35px; display: flex; align-items: center; gap: 7px; flex: 1; padding: 0 9px; border: 1px solid #e1e4ea; border-radius: 7px; background: #f9fafb; color: #959da9; }
|
||||
.search:focus-within { border-color: #a5b8e9; background: #fff; box-shadow: 0 0 0 3px rgba(65,105,225,.07); }
|
||||
.search input { min-width: 0; flex: 1; border: 0; outline: 0; background: transparent; color: #475369; font-size: 8px; }
|
||||
.search button { border: 0; background: none; color: #9ca3ae; cursor: pointer; }
|
||||
.search kbd { padding: 3px 5px; border: 1px solid #dfe2e8; border-radius: 4px; background: #fff; color: #a0a5ae; font-family: inherit; font-size: 6px; }
|
||||
.sizeControl { display: flex; align-items: center; gap: 8px; padding-left: 2px; color: #7d8695; font-size: 7px; }
|
||||
.sizeControl input { width: 78px; accent-color: var(--blue); }
|
||||
.sizeControl b { width: 27px; color: #5f697c; font-size: 7px; }
|
||||
.viewSwitch { display: flex; padding: 3px; border-radius: 6px; background: #f1f2f5; }
|
||||
.viewSwitch button { width: 27px; height: 26px; border: 0; border-radius: 4px; background: transparent; color: #9aa1ad; cursor: pointer; }
|
||||
.viewSwitch .viewActive { background: #fff; color: #4667bf; box-shadow: 0 2px 6px rgba(34,39,55,.08); }
|
||||
.resultHeading { min-height: 55px; display: flex; align-items: center; justify-content: space-between; }
|
||||
.resultHeading > div { display: flex; align-items: center; gap: 8px; }
|
||||
.resultHeading strong { font-size: 10px; }
|
||||
.resultHeading span { padding: 3px 6px; border-radius: 8px; background: #e9ecf2; color: #8d95a2; font-size: 6px; }
|
||||
.resultHeading button { border: 0; background: none; color: #5c75bb; cursor: pointer; font-size: 7px; }
|
||||
.iconCollection { --preview-size: 28px; --preview-color: #27324a; display: grid; grid-template-columns: repeat(5,minmax(0,1fr)); gap: 8px; }
|
||||
.iconCollection article { position: relative; min-width: 0; height: 126px; overflow: hidden; border: 1px solid #e2e5eb; border-radius: 9px; background: #fff; transition: transform .16s,border .16s,box-shadow .16s; }
|
||||
.iconCollection article:hover { transform: translateY(-2px); border-color: #b8c6e9; box-shadow: 0 8px 22px rgba(39,50,77,.07); }
|
||||
.iconCollection .selectedCard { border-color: #708ee0; box-shadow: inset 0 0 0 1px #708ee0,0 8px 22px rgba(65,105,225,.08); }
|
||||
.selectIcon { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; flex-direction: column; gap: 12px; padding: 14px 9px 12px; border: 0; background: transparent; cursor: pointer; }
|
||||
.iconSymbol { min-height: 38px; display: grid; place-items: center; color: var(--preview-color); font-family: "Segoe UI Symbol","Arial Unicode MS",sans-serif; font-size: var(--preview-size); line-height: 1; white-space: nowrap; }
|
||||
.iconLabel { min-width: 0; width: 100%; display: flex; flex-direction: column; gap: 3px; }
|
||||
.iconLabel strong { overflow: hidden; color: #505a6c; font-size: 8px; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.iconLabel small { overflow: hidden; color: #a0a6b1; font-size: 6px; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.favoriteButton { position: absolute; right: 6px; top: 6px; width: 24px; height: 24px; border: 0; border-radius: 5px; background: transparent; color: #c1c5cc; cursor: pointer; font-size: 12px; opacity: 0; }
|
||||
.iconCollection article:hover .favoriteButton, .favoriteButton.isFavorite { opacity: 1; }
|
||||
.favoriteButton:hover { background: #fff7df; color: #dda632; }
|
||||
.favoriteButton.isFavorite { color: #e3a930; }
|
||||
.quickCopy { position: absolute; right: 6px; bottom: 6px; padding: 3px 5px; border: 0; border-radius: 4px; background: #edf2ff; color: #4b6abe; cursor: pointer; font-size: 6px; opacity: 0; }
|
||||
.iconCollection article:hover .quickCopy { opacity: 1; }
|
||||
.listView { grid-template-columns: 1fr; }
|
||||
.listView article { height: 58px; }
|
||||
.listView .selectIcon { align-items: center; justify-content: flex-start; flex-direction: row; gap: 15px; padding: 7px 45px 7px 13px; text-align: left; }
|
||||
.listView .iconSymbol { width: 42px; min-height: 42px; }
|
||||
.listView .iconLabel { width: auto; }
|
||||
.listView .iconLabel strong { font-size: 9px; }
|
||||
.listView .quickCopy { right: 10px; top: 50%; bottom: auto; transform: translateY(-50%); opacity: 1; }
|
||||
.listView .favoriteButton { right: 54px; top: 50%; transform: translateY(-50%); opacity: 1; }
|
||||
.empty { grid-column: 1/-1; min-height: 360px; display: flex; align-items: center; justify-content: center; flex-direction: column; color: #9ba3af; text-align: center; }
|
||||
.empty > span { width: 52px; height: 52px; display: grid; place-items: center; border-radius: 50%; background: #edf0f5; font-size: 23px; }
|
||||
.empty h3 { margin: 12px 0 4px; color: #596476; font-size: 11px; }
|
||||
.empty p { margin: 0 0 14px; font-size: 8px; }
|
||||
.empty button { height: 30px; padding: 0 11px; border: 1px solid #d9deea; border-radius: 6px; background: #fff; color: #4866b6; cursor: pointer; font-size: 7px; }
|
||||
|
||||
.inspector { position: sticky; top: 62px; height: calc(100vh - 62px); overflow-y: auto; padding: 19px; border-left: 1px solid #e2e5eb; background: #fff; }
|
||||
.inspectorHeader { display: flex; justify-content: space-between; align-items: flex-start; }
|
||||
.inspectorHeader span { display: block; margin-bottom: 3px; color: #7288be; font-size: 6px; font-weight: 800; letter-spacing: 1.2px; }
|
||||
.inspectorHeader strong { font-size: 12px; }
|
||||
.inspectorHeader > button { width: 29px; height: 29px; border: 1px solid #e1e4e9; border-radius: 7px; background: #fff; color: #b1b6bf; cursor: pointer; font-size: 14px; }
|
||||
.inspectorHeader > .inspectorFavorite { border-color: #eed9a2; background: #fff9e9; color: #dfa932; }
|
||||
.largePreview { --preview-size: 28px; --preview-color: #27324a; position: relative; height: 150px; display: grid; place-items: center; margin: 17px 0 15px; overflow: hidden; border: 1px solid #e1e4ea; border-radius: 11px; }
|
||||
.largePreview::before { content: ""; position: absolute; inset: 0; opacity: .28; background-image: linear-gradient(#d9dee7 1px,transparent 1px),linear-gradient(90deg,#d9dee7 1px,transparent 1px); background-size: 16px 16px; }
|
||||
.largePreview > span { position: relative; z-index: 1; color: var(--preview-color); font-family: "Segoe UI Symbol","Arial Unicode MS",sans-serif; font-size: calc(var(--preview-size) * 2.2); line-height: 1; white-space: nowrap; }
|
||||
.largePreview > small { position: absolute; right: 9px; bottom: 8px; z-index: 1; padding: 3px 5px; border-radius: 4px; background: rgba(255,255,255,.75); color: #8d95a3; font-size: 6px; }
|
||||
.preview_light { background: #fff; }
|
||||
.preview_soft { background: #f0f3f8; }
|
||||
.preview_dark { background: #242b3c; }
|
||||
.preview_dark::before { background-image: linear-gradient(#455066 1px,transparent 1px),linear-gradient(90deg,#455066 1px,transparent 1px); }
|
||||
.preview_dark > small { background: rgba(14,18,29,.65); color: #adb5c5; }
|
||||
.iconMeta { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding-bottom: 14px; border-bottom: 1px solid #eceef2; }
|
||||
.iconMeta h2 { margin: 0 0 3px; font-size: 15px; }
|
||||
.iconMeta p { margin: 0; color: #999faa; font-size: 7px; }
|
||||
.iconMeta button { height: 29px; padding: 0 9px; border: 1px solid #ced9f2; border-radius: 6px; background: #f5f8ff; color: #4565b8; cursor: pointer; font-size: 7px; }
|
||||
.details { margin: 8px 0 0; }
|
||||
.details > div { display: flex; justify-content: space-between; gap: 15px; padding: 7px 0; font-size: 7px; }
|
||||
.details dt { color: #9ba1ac; }
|
||||
.details dd { margin: 0; color: #566175; font-family: "Cascadia Code",Consolas,monospace; }
|
||||
.appearance, .codeSection { margin-top: 13px; padding-top: 14px; border-top: 1px solid #eceef2; }
|
||||
.appearance h3, .codeSection h3 { margin: 0 0 12px; font-size: 9px; }
|
||||
.appearance > label { display: grid; grid-template-columns: 31px 1fr 30px; align-items: center; gap: 8px; color: #7f8795; font-size: 7px; }
|
||||
.appearance > label input { width: 100%; accent-color: var(--blue); }
|
||||
.appearance > label b { font-size: 7px; }
|
||||
.colorRow { display: flex; align-items: center; gap: 6px; margin-top: 12px; }
|
||||
.colorRow > span { width: 31px; color: #7f8795; font-size: 7px; }
|
||||
.colorRow button, .colorRow input { width: 19px; height: 19px; padding: 0; border: 2px solid #fff; border-radius: 50%; cursor: pointer; box-shadow: 0 0 0 1px #d7dbe3; }
|
||||
.colorRow .colorActive { box-shadow: 0 0 0 2px #6f89cf; }
|
||||
.colorRow input { overflow: hidden; }
|
||||
.backgroundSwitch { display: grid; grid-template-columns: repeat(3,1fr); gap: 4px; margin-top: 12px; padding: 3px; border-radius: 6px; background: #f1f2f5; }
|
||||
.backgroundSwitch button { height: 25px; border: 0; border-radius: 4px; background: transparent; color: #8f96a2; cursor: pointer; font-size: 7px; }
|
||||
.backgroundSwitch .backgroundActive { background: #fff; color: #405fae; box-shadow: 0 2px 6px rgba(34,39,55,.08); }
|
||||
.codeTabs { display: flex; margin-bottom: 7px; border-bottom: 1px solid #e6e8ed; }
|
||||
.codeTabs button { padding: 6px 8px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: #9299a5; cursor: pointer; font-size: 6px; }
|
||||
.codeTabs .codeTabActive { border-bottom-color: var(--blue); color: #3d5fbc; font-weight: 700; }
|
||||
.codeSection pre { min-height: 71px; overflow-x: auto; margin: 0; padding: 10px; border-radius: 7px; background: #252a39; color: #d8deec; font-family: "Cascadia Code",Consolas,monospace; font-size: 7px; line-height: 1.65; white-space: pre-wrap; word-break: break-all; }
|
||||
.copyCode { width: 100%; height: 31px; margin-top: 7px; border: 0; border-radius: 6px; background: #3e66d2; color: #fff; cursor: pointer; font-size: 7px; }
|
||||
.compatibility { display: grid; grid-template-columns: 23px 1fr; gap: 2px 8px; margin: 14px 0 0; padding: 10px; border-radius: 7px; background: #edf8f3; }
|
||||
.compatibility > span { grid-row: 1/3; width: 23px; height: 23px; display: grid; place-items: center; border-radius: 50%; background: #d9f1e5; color: #28845a; font-size: 8px; }
|
||||
.compatibility strong { color: #36765b; font-size: 7px; }
|
||||
.compatibility small { color: #759487; font-size: 6px; line-height: 1.5; }
|
||||
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 70; padding: 10px 16px; border-radius: 20px; background: rgba(30,36,51,.96); color: #fff; box-shadow: 0 12px 30px rgba(22,27,40,.23); font-size: 8px; animation: toastIn .2s ease both; }
|
||||
|
||||
@media (max-width: 1120px) {
|
||||
.workspace { grid-template-columns: 180px minmax(0,1fr) 280px; }
|
||||
.iconCollection { grid-template-columns: repeat(4,minmax(0,1fr)); }
|
||||
.main { padding: 20px 18px 60px; }
|
||||
.heroSamples span:nth-last-child(-n+2) { display: none; }
|
||||
.sizeControl { display: none; }
|
||||
}
|
||||
|
||||
@media (max-width: 860px) {
|
||||
.topbar nav { display: none; }
|
||||
.workspace { grid-template-columns: 165px minmax(0,1fr); }
|
||||
.inspector { grid-column: 2; position: relative; top: auto; height: auto; border-top: 1px solid #e2e5eb; border-left: 0; }
|
||||
.sidebar { grid-row: 1/3; }
|
||||
.inspector { display: grid; grid-template-columns: 210px 1fr; gap: 0 18px; }
|
||||
.inspectorHeader { grid-column: 1/-1; }
|
||||
.largePreview { grid-row: 2/7; }
|
||||
.appearance, .codeSection { margin-top: 10px; }
|
||||
.compatibility { grid-column: 2; }
|
||||
.iconCollection { grid-template-columns: repeat(3,minmax(0,1fr)); }
|
||||
}
|
||||
|
||||
@media (max-width: 620px) {
|
||||
.topbar { padding: 0 12px; }
|
||||
.headerActions button { display: none; }
|
||||
.workspace { display: block; }
|
||||
.sidebar { position: relative; top: auto; width: 100%; height: auto; border-right: 0; border-bottom: 1px solid #e3e6eb; }
|
||||
.sidebarTitle { padding: 18px 15px 8px; }
|
||||
.categories { display: flex; gap: 4px; overflow-x: auto; padding: 8px 12px 13px; }
|
||||
.categories button { width: auto; flex: 0 0 auto; padding: 0 11px; }
|
||||
.categories button > span, .categories button > b { display: none; }
|
||||
.sidebarHelp { display: none; }
|
||||
.main { padding: 13px 12px 45px; }
|
||||
.hero { min-height: 132px; padding: 22px; }
|
||||
.hero h1 { max-width: 260px; font-size: 18px; }
|
||||
.hero div > span { display: block; max-width: 270px; line-height: 1.6; }
|
||||
.heroSamples { display: none; }
|
||||
.toolbar { gap: 8px; }
|
||||
.search kbd { display: none; }
|
||||
.iconCollection { grid-template-columns: repeat(3,minmax(0,1fr)); }
|
||||
.iconCollection article { height: 112px; }
|
||||
.favoriteButton, .quickCopy { opacity: 1; }
|
||||
.quickCopy { display: none; }
|
||||
.inspector { display: block; padding: 18px 15px 35px; }
|
||||
.largePreview { height: 170px; }
|
||||
}
|
||||
|
||||
@media (max-width: 390px) {
|
||||
.iconCollection { grid-template-columns: repeat(2,minmax(0,1fr)); }
|
||||
}
|
||||
173
app/icons/page.tsx
Normal file
173
app/icons/page.tsx
Normal file
@@ -0,0 +1,173 @@
|
||||
"use client";
|
||||
|
||||
import Link from "next/link";
|
||||
import { CSSProperties, useEffect, useMemo, useState } from "react";
|
||||
import iconData from "../data/web-icons.json";
|
||||
import styles from "./IconLibrary.module.css";
|
||||
|
||||
type IconItem = (typeof iconData.icons)[number];
|
||||
type CodeMode = "character" | "html" | "react" | "css";
|
||||
type PreviewBackground = "light" | "soft" | "dark";
|
||||
|
||||
export default function IconLibraryPage() {
|
||||
const [query, setQuery] = useState("");
|
||||
const [category, setCategory] = useState("all");
|
||||
const [selectedId, setSelectedId] = useState("home");
|
||||
const [favorites, setFavorites] = useState<string[]>([]);
|
||||
const [view, setView] = useState<"grid" | "list">("grid");
|
||||
const [size, setSize] = useState(28);
|
||||
const [color, setColor] = useState("#27324a");
|
||||
const [background, setBackground] = useState<PreviewBackground>("soft");
|
||||
const [codeMode, setCodeMode] = useState<CodeMode>("html");
|
||||
const [onlyFavorites, setOnlyFavorites] = useState(false);
|
||||
const [toast, setToast] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
try {
|
||||
const saved = window.localStorage.getItem("orbit-icon-favorites");
|
||||
if (saved) setFavorites(JSON.parse(saved));
|
||||
} catch { /* use an empty favorite list */ }
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
window.localStorage.setItem("orbit-icon-favorites", JSON.stringify(favorites));
|
||||
}, [favorites]);
|
||||
|
||||
const selected = iconData.icons.find((icon) => icon.id === selectedId) ?? iconData.icons[0];
|
||||
const filteredIcons = useMemo(() => iconData.icons.filter((icon) => {
|
||||
const text = `${icon.name}${icon.cn}${icon.id}${icon.keywords.join("")}`.toLowerCase();
|
||||
const matchesQuery = text.includes(query.toLowerCase());
|
||||
const matchesCategory = category === "all" || icon.category === category;
|
||||
const matchesFavorite = !onlyFavorites || favorites.includes(icon.id);
|
||||
return matchesQuery && matchesCategory && matchesFavorite;
|
||||
}), [query, category, onlyFavorites, favorites]);
|
||||
|
||||
const categoryName = iconData.categories.find((item) => item.id === selected.category)?.name ?? "通用";
|
||||
const code = getIconCode(selected, codeMode, size, color);
|
||||
const previewStyle = { "--preview-size": `${size}px`, "--preview-color": color } as CSSProperties;
|
||||
|
||||
const notify = (message: string) => {
|
||||
setToast(message);
|
||||
window.setTimeout(() => setToast(""), 1800);
|
||||
};
|
||||
|
||||
const copy = async (value: string, label: string) => {
|
||||
try {
|
||||
await navigator.clipboard.writeText(value);
|
||||
} catch {
|
||||
const input = document.createElement("textarea");
|
||||
input.value = value;
|
||||
input.style.position = "fixed";
|
||||
input.style.opacity = "0";
|
||||
document.body.appendChild(input);
|
||||
input.select();
|
||||
document.execCommand("copy");
|
||||
input.remove();
|
||||
}
|
||||
notify(`${label}已复制`);
|
||||
};
|
||||
|
||||
const toggleFavorite = (id: string) => setFavorites((current) => current.includes(id) ? current.filter((item) => item !== id) : [...current, id]);
|
||||
|
||||
const exportFavorites = () => {
|
||||
const items = iconData.icons.filter((icon) => favorites.includes(icon.id));
|
||||
const blob = new Blob([JSON.stringify(items, null, 2)], { type: "application/json;charset=utf-8" });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const link = document.createElement("a");
|
||||
link.href = url;
|
||||
link.download = "web-icons-favorites.json";
|
||||
link.click();
|
||||
URL.revokeObjectURL(url);
|
||||
notify("收藏图标已导出");
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={styles.page}>
|
||||
<header className={styles.topbar}>
|
||||
<Link href="/" className={styles.brand}><span>G</span><strong>GlyphKit</strong><small>WEB ICON LIBRARY</small></Link>
|
||||
<nav><Link href="/simple-list">列表模板</Link><Link href="/repeatable-form">可重复表单</Link><Link className={styles.activeNav} href="/icons">图标库</Link><Link href="/markdown">文档编辑</Link></nav>
|
||||
<div className={styles.headerActions}><button onClick={() => setOnlyFavorites((value) => !value)} className={onlyFavorites ? styles.favoriteFilterActive : ""}>☆ 收藏 {favorites.length}</button><button onClick={exportFavorites} disabled={favorites.length === 0}>导出收藏</button><span>林</span></div>
|
||||
</header>
|
||||
|
||||
<div className={styles.workspace}>
|
||||
<aside className={styles.sidebar}>
|
||||
<div className={styles.sidebarTitle}><span>ICON SET</span><strong>网页图标</strong><small>{iconData.icons.length} 个原生符号</small></div>
|
||||
<nav className={styles.categories} aria-label="图标分类">
|
||||
{iconData.categories.map((item) => {
|
||||
const count = item.id === "all" ? iconData.icons.length : iconData.icons.filter((icon) => icon.category === item.id).length;
|
||||
return <button key={item.id} className={category === item.id ? styles.categoryActive : ""} onClick={() => { setCategory(item.id); setOnlyFavorites(false); }}><span>{categorySymbol(item.id)}</span>{item.name}<b>{count}</b></button>;
|
||||
})}
|
||||
</nav>
|
||||
<div className={styles.sidebarHelp}><span>i</span><p><strong>零依赖图标</strong><small>复制后可直接用于 HTML、CSS 和 React 页面。</small></p></div>
|
||||
</aside>
|
||||
|
||||
<main className={styles.main}>
|
||||
<section className={styles.hero}>
|
||||
<div><p>SYMBOL PICKER</p><h1>为界面选择一个合适的图标</h1><span>搜索、预览并复制。全部图标使用系统字体,不需要安装额外资源。</span></div>
|
||||
<div className={styles.heroSamples}>{["⌂","✓","⌕","✎","▦"].map((symbol,index) => <span key={symbol} style={{transform:`translateY(${index % 2 ? 7 : -2}px)`}}>{symbol}</span>)}</div>
|
||||
</section>
|
||||
|
||||
<div className={styles.toolbar}>
|
||||
<label className={styles.search}><span>⌕</span><input value={query} onChange={(event) => setQuery(event.target.value)} placeholder="搜索图标名称、功能或关键词,例如:编辑、upload" />{query && <button onClick={() => setQuery("")}>×</button>}<kbd>⌘ K</kbd></label>
|
||||
<div className={styles.sizeControl}><span>预览大小</span><input type="range" min="18" max="42" value={size} onChange={(event) => setSize(Number(event.target.value))} /><b>{size}px</b></div>
|
||||
<div className={styles.viewSwitch}><button className={view === "grid" ? styles.viewActive : ""} onClick={() => setView("grid")} aria-label="网格视图">▦</button><button className={view === "list" ? styles.viewActive : ""} onClick={() => setView("list")} aria-label="列表视图">☷</button></div>
|
||||
</div>
|
||||
|
||||
<div className={styles.resultHeading}><div><strong>{onlyFavorites ? "我的收藏" : iconData.categories.find((item) => item.id === category)?.name}</strong><span>{filteredIcons.length} 个结果</span></div>{(query || onlyFavorites || category !== "all") && <button onClick={() => { setQuery(""); setCategory("all"); setOnlyFavorites(false); }}>清除筛选</button>}</div>
|
||||
|
||||
<div className={`${styles.iconCollection} ${view === "list" ? styles.listView : ""}`} style={previewStyle}>
|
||||
{filteredIcons.map((icon) => {
|
||||
const favorite = favorites.includes(icon.id);
|
||||
return <article key={icon.id} className={selected.id === icon.id ? styles.selectedCard : ""}>
|
||||
<button className={styles.selectIcon} onClick={() => setSelectedId(icon.id)}>
|
||||
<span className={styles.iconSymbol}>{icon.symbol}</span>
|
||||
<span className={styles.iconLabel}><strong>{icon.cn}</strong><small>{icon.name}</small></span>
|
||||
</button>
|
||||
<button className={`${styles.favoriteButton} ${favorite ? styles.isFavorite : ""}`} onClick={() => toggleFavorite(icon.id)} aria-label={favorite ? `取消收藏 ${icon.cn}` : `收藏 ${icon.cn}`}>{favorite ? "★" : "☆"}</button>
|
||||
<button className={styles.quickCopy} onClick={() => copy(icon.symbol, "图标字符")} aria-label={`复制 ${icon.cn}`}>复制</button>
|
||||
</article>;
|
||||
})}
|
||||
{filteredIcons.length === 0 && <div className={styles.empty}><span>⌕</span><h3>没有找到匹配图标</h3><p>尝试搜索“首页”“编辑”“文件”或英文关键词。</p><button onClick={() => { setQuery(""); setCategory("all"); setOnlyFavorites(false); }}>查看全部图标</button></div>}
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<aside className={styles.inspector}>
|
||||
<div className={styles.inspectorHeader}><div><span>SELECTED ICON</span><strong>图标详情</strong></div><button className={favorites.includes(selected.id) ? styles.inspectorFavorite : ""} onClick={() => toggleFavorite(selected.id)}>{favorites.includes(selected.id) ? "★" : "☆"}</button></div>
|
||||
<div className={`${styles.largePreview} ${styles[`preview_${background}`]}`} style={previewStyle}><span>{selected.symbol}</span><small>{size}px</small></div>
|
||||
<div className={styles.iconMeta}><div><h2>{selected.cn}</h2><p>{selected.name}</p></div><button onClick={() => copy(selected.symbol, "图标字符")}>复制字符</button></div>
|
||||
<dl className={styles.details}><div><dt>图标 ID</dt><dd>{selected.id}</dd></div><div><dt>分类</dt><dd>{categoryName}</dd></div><div><dt>Unicode</dt><dd>U+{unicodeValue(selected.symbol)}</dd></div></dl>
|
||||
|
||||
<section className={styles.appearance}><h3>预览样式</h3><label><span>大小</span><input type="range" min="14" max="64" value={size} onChange={(event) => setSize(Number(event.target.value))} /><b>{size}px</b></label><div className={styles.colorRow}><span>颜色</span>{["#27324a","#3d6fe8","#20a26a","#e45252","#8a5bd1"].map((value) => <button key={value} className={color === value ? styles.colorActive : ""} style={{background:value}} onClick={() => setColor(value)} aria-label={`颜色 ${value}`} />)}<input type="color" value={color} onChange={(event) => setColor(event.target.value)} aria-label="自定义颜色" /></div><div className={styles.backgroundSwitch}>{(["light","soft","dark"] as PreviewBackground[]).map((value) => <button key={value} className={background === value ? styles.backgroundActive : ""} onClick={() => setBackground(value)}>{value === "light" ? "白色" : value === "soft" ? "浅色" : "深色"}</button>)}</div></section>
|
||||
|
||||
<section className={styles.codeSection}>
|
||||
<h3>使用代码</h3>
|
||||
<div className={styles.codeTabs}>{(["character","html","react","css"] as CodeMode[]).map((mode) => <button key={mode} className={codeMode === mode ? styles.codeTabActive : ""} onClick={() => setCodeMode(mode)}>{mode === "character" ? "字符" : mode.toUpperCase()}</button>)}</div>
|
||||
<pre><code>{code}</code></pre>
|
||||
<button className={styles.copyCode} onClick={() => copy(code, `${codeMode.toUpperCase()} 代码`)}>▣ 复制代码</button>
|
||||
</section>
|
||||
<p className={styles.compatibility}><span>✓</span><strong>浏览器原生支持</strong><small>建议使用 Segoe UI Symbol、Arial Unicode MS 或系统无衬线字体。</small></p>
|
||||
</aside>
|
||||
</div>
|
||||
{toast && <div className={styles.toast}>✓ {toast}</div>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function categorySymbol(id: string) {
|
||||
return ({ all: "✣", navigation: "⌖", actions: "✎", status: "◉", media: "▶", files: "▤", business: "▦", communication: "✉", identity: "⚥", biology: "⚛", breeding: "♂♀", pets: "🐾︎" } as Record<string,string>)[id] ?? "◇";
|
||||
}
|
||||
|
||||
function unicodeValue(symbol: string) {
|
||||
return Array.from(symbol).map((char) => char.codePointAt(0)?.toString(16).toUpperCase().padStart(4, "0")).join(" ");
|
||||
}
|
||||
|
||||
function cssEscaped(symbol: string) {
|
||||
return Array.from(symbol).map((char) => `\\${char.codePointAt(0)?.toString(16).toUpperCase()} `).join("");
|
||||
}
|
||||
|
||||
function getIconCode(icon: IconItem, mode: CodeMode, size: number, color: string) {
|
||||
if (mode === "character") return icon.symbol;
|
||||
if (mode === "html") return `<span class="web-icon" aria-hidden="true">${icon.symbol}</span>`;
|
||||
if (mode === "react") return `<span className="web-icon" aria-hidden>${icon.symbol}</span>`;
|
||||
return `.web-icon::before {\n content: "${cssEscaped(icon.symbol)}";\n color: ${color};\n font: ${size}px/1 "Segoe UI Symbol", sans-serif;\n}`;
|
||||
}
|
||||
Reference in New Issue
Block a user