mirror of
https://github.com/profullstack/logicsrc.git
synced 2026-12-01 09:24:46 +00:00
OpenIcon gallery: all 370 icons on /openicon, with search, filters and terminal glyphs (#199)
Replaces the 47-icon sample with the whole reference set: search by name,
alias or keyword; category chips with counts; UI/brand filter; SVG,
Nerd Font, Unicode or ASCII view (the Nerd Font view uses the official
symbols subset to the set's 349 glyphs, 38 KB woff2, MIT); size and
colour; a detail panel with all three glyphs and codepoints, trademark
notes, copy SVG / <img> / icon("key"), and downloads. Ready for the
optional HQ (full-colour) style: a Simple/HQ toggle appears once icons
carry an hq field. Filters live in the URL.
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
3883ee7a2c
commit
3e8d3098ba
377 changed files with 8248 additions and 33 deletions
407
apps/logicsrc-web/src/app/openicon/gallery.module.css
Normal file
407
apps/logicsrc-web/src/app/openicon/gallery.module.css
Normal file
|
|
@ -0,0 +1,407 @@
|
|||
/* Nerd Font symbols, subset to the glyphs OpenIcon uses (38 KB; MIT, see nerd-fonts-LICENSE.txt). */
|
||||
@font-face {
|
||||
font-family: "OpenIcon Nerd Symbols";
|
||||
src: url("/openicon/set/nerd-openicon.woff2") format("woff2");
|
||||
font-display: block;
|
||||
}
|
||||
|
||||
.gallery {
|
||||
--line: #e3e6e0;
|
||||
--muted: #5b6b7a;
|
||||
--accent: #0a7d59;
|
||||
--tile: 32px;
|
||||
}
|
||||
|
||||
.notice {
|
||||
color: var(--muted);
|
||||
padding: 2rem 0;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 3;
|
||||
display: grid;
|
||||
gap: 0.6rem;
|
||||
padding: 0.75rem 0 0.8rem;
|
||||
background: #f6f7f4;
|
||||
border-bottom: 1px solid var(--line);
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.search {
|
||||
width: 100%;
|
||||
font: inherit;
|
||||
font-size: 1rem;
|
||||
padding: 0.7rem 0.95rem;
|
||||
border: 1px solid #cfd5cc;
|
||||
border-radius: 0.6rem;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.search:focus,
|
||||
.tile:focus-visible,
|
||||
.seg:focus-visible,
|
||||
.chip:focus-visible {
|
||||
outline: 2px solid var(--accent);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
|
||||
.controls {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 0.6rem 0.9rem;
|
||||
}
|
||||
|
||||
.segmented {
|
||||
display: inline-flex;
|
||||
border: 1px solid #cfd5cc;
|
||||
border-radius: 0.55rem;
|
||||
overflow: hidden;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.seg,
|
||||
.segOn {
|
||||
padding: 0.4rem 0.75rem;
|
||||
font-size: 0.86rem;
|
||||
background: #fff;
|
||||
color: #101418;
|
||||
border-right: 1px solid #e3e6e0;
|
||||
}
|
||||
|
||||
.segmented > :last-child {
|
||||
border-right: 0;
|
||||
}
|
||||
|
||||
.segOn {
|
||||
background: var(--accent);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.control {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.45rem;
|
||||
font-size: 0.8rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.control input[type="range"] {
|
||||
width: 8rem;
|
||||
accent-color: var(--accent);
|
||||
}
|
||||
|
||||
.control input[type="color"] {
|
||||
width: 2rem;
|
||||
height: 1.8rem;
|
||||
padding: 0;
|
||||
border: 1px solid #cfd5cc;
|
||||
border-radius: 0.35rem;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.count {
|
||||
margin-left: auto;
|
||||
font-size: 0.85rem;
|
||||
color: var(--muted);
|
||||
display: inline-flex;
|
||||
gap: 0.5rem;
|
||||
}
|
||||
|
||||
.reset {
|
||||
background: none;
|
||||
padding: 0;
|
||||
color: var(--accent);
|
||||
font-size: 0.85rem;
|
||||
}
|
||||
|
||||
.chips {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.35rem;
|
||||
}
|
||||
|
||||
.chip,
|
||||
.chipOn {
|
||||
padding: 0.28rem 0.68rem;
|
||||
border-radius: 999px;
|
||||
font-size: 0.83rem;
|
||||
border: 1px solid #cfd5cc;
|
||||
background: #fff;
|
||||
color: #101418;
|
||||
}
|
||||
|
||||
.chip small,
|
||||
.chipOn small {
|
||||
color: var(--muted);
|
||||
margin-left: 0.15rem;
|
||||
}
|
||||
|
||||
.chipOn {
|
||||
background: var(--accent);
|
||||
border-color: var(--accent);
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.chipOn small {
|
||||
color: #d7f3e8;
|
||||
}
|
||||
|
||||
.hint {
|
||||
margin: -0.3rem 0 0.8rem;
|
||||
font-size: 0.84rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.grid {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(calc(var(--tile) + 4.2rem), 1fr));
|
||||
gap: 0.45rem;
|
||||
}
|
||||
|
||||
.tile {
|
||||
width: 100%;
|
||||
display: grid;
|
||||
justify-items: center;
|
||||
align-content: center;
|
||||
gap: 0.45rem;
|
||||
min-height: calc(var(--tile) + 3.2rem);
|
||||
padding: 0.7rem 0.3rem 0.5rem;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 0.7rem;
|
||||
background: #fff;
|
||||
color: #101418;
|
||||
transition:
|
||||
transform 0.12s ease,
|
||||
box-shadow 0.12s ease,
|
||||
border-color 0.12s ease;
|
||||
}
|
||||
|
||||
.tile:hover {
|
||||
transform: translateY(-2px);
|
||||
border-color: #b9c9bf;
|
||||
box-shadow: 0 6px 16px rgb(16 20 24 / 8%);
|
||||
}
|
||||
|
||||
.tileOn {
|
||||
border-color: var(--accent);
|
||||
box-shadow: 0 0 0 2px var(--accent);
|
||||
}
|
||||
|
||||
.gridTerminal .tile {
|
||||
background: #11161b;
|
||||
border-color: #232b33;
|
||||
color: #d8e3dc;
|
||||
}
|
||||
|
||||
.gridTerminal .tile:hover {
|
||||
border-color: #3a4a55;
|
||||
}
|
||||
|
||||
.gridTerminal .label {
|
||||
color: #7f909c;
|
||||
}
|
||||
|
||||
.glyph,
|
||||
.glyphNerd {
|
||||
font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Segoe UI Symbol", "Noto Sans Symbols 2", "Apple Symbols",
|
||||
system-ui, monospace;
|
||||
line-height: 1;
|
||||
min-height: 1em;
|
||||
white-space: pre;
|
||||
}
|
||||
|
||||
.glyphNerd {
|
||||
font-family: "OpenIcon Nerd Symbols", ui-monospace, SFMono-Regular, Menlo, "Segoe UI Symbol", "Noto Sans Symbols 2",
|
||||
"Apple Symbols", system-ui, monospace;
|
||||
}
|
||||
|
||||
.fallback {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.fallback::after {
|
||||
content: "";
|
||||
position: absolute;
|
||||
top: 0.45rem;
|
||||
right: 0.45rem;
|
||||
width: 0.4rem;
|
||||
height: 0.4rem;
|
||||
border-radius: 999px;
|
||||
background: #d9a441;
|
||||
}
|
||||
|
||||
.label {
|
||||
max-width: 100%;
|
||||
font-size: 0.68rem;
|
||||
color: var(--muted);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.detail {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
z-index: 20;
|
||||
width: min(24rem, 100vw);
|
||||
overflow-y: auto;
|
||||
padding: 1.4rem 1.3rem 2rem;
|
||||
background: #fff;
|
||||
border-left: 1px solid var(--line);
|
||||
box-shadow: -18px 0 40px rgb(16 20 24 / 12%);
|
||||
}
|
||||
|
||||
.close {
|
||||
position: absolute;
|
||||
top: 0.6rem;
|
||||
right: 0.8rem;
|
||||
width: 2rem;
|
||||
height: 2rem;
|
||||
border-radius: 999px;
|
||||
background: #f1f3ef;
|
||||
font-size: 1.3rem;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.hero {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1.4rem;
|
||||
padding: 1.2rem;
|
||||
border-radius: 0.9rem;
|
||||
background: radial-gradient(circle at 30% 20%, #ffffff, #eef1ec);
|
||||
}
|
||||
|
||||
.heroSmall {
|
||||
display: flex;
|
||||
align-items: flex-end;
|
||||
gap: 0.8rem;
|
||||
}
|
||||
|
||||
.detail h3 {
|
||||
margin: 1rem 0 0.4rem;
|
||||
font-size: 1.25rem;
|
||||
}
|
||||
|
||||
.facts {
|
||||
display: grid;
|
||||
grid-template-columns: auto 1fr;
|
||||
gap: 0.3rem 0.9rem;
|
||||
margin: 0.6rem 0;
|
||||
font-size: 0.86rem;
|
||||
}
|
||||
|
||||
.facts dt {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.facts dd {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.trademark {
|
||||
font-size: 0.8rem;
|
||||
color: #8a5a00;
|
||||
background: #fdf6e8;
|
||||
border-radius: 0.5rem;
|
||||
padding: 0.5rem 0.65rem;
|
||||
}
|
||||
|
||||
.tui {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
font-size: 0.85rem;
|
||||
margin: 0.8rem 0;
|
||||
}
|
||||
|
||||
.tui caption {
|
||||
text-align: left;
|
||||
color: var(--muted);
|
||||
font-size: 0.78rem;
|
||||
margin-bottom: 0.3rem;
|
||||
}
|
||||
|
||||
.tui th {
|
||||
text-align: left;
|
||||
font-weight: 600;
|
||||
padding: 0.35rem 0.5rem 0.35rem 0;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.tui td {
|
||||
padding: 0.35rem 0.5rem 0.35rem 0;
|
||||
border-top: 1px solid #f0f2ee;
|
||||
}
|
||||
|
||||
.tui .glyph,
|
||||
.tui .glyphNerd {
|
||||
font-size: 1.3rem;
|
||||
}
|
||||
|
||||
.actions,
|
||||
.downloads {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: 0.4rem 0.8rem;
|
||||
margin-bottom: 0.8rem;
|
||||
font-size: 0.86rem;
|
||||
}
|
||||
|
||||
.downloads span {
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
.copy {
|
||||
padding: 0.35rem 0.7rem;
|
||||
border-radius: 0.45rem;
|
||||
border: 1px solid #cfd5cc;
|
||||
background: #fff;
|
||||
color: #101418;
|
||||
font-size: 0.82rem;
|
||||
}
|
||||
|
||||
.copy:hover {
|
||||
border-color: var(--accent);
|
||||
color: var(--accent);
|
||||
}
|
||||
|
||||
.keywords {
|
||||
font-size: 0.8rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.toolbar {
|
||||
position: static;
|
||||
}
|
||||
.chips {
|
||||
flex-wrap: nowrap;
|
||||
overflow-x: auto;
|
||||
padding-bottom: 0.2rem;
|
||||
}
|
||||
.chips > * {
|
||||
flex: none;
|
||||
}
|
||||
.count {
|
||||
margin-left: 0;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.heroHq {
|
||||
display: grid;
|
||||
justify-items: center;
|
||||
gap: 0.2rem;
|
||||
margin-left: auto;
|
||||
font-size: 0.7rem;
|
||||
color: var(--muted);
|
||||
}
|
||||
528
apps/logicsrc-web/src/app/openicon/gallery.tsx
Normal file
528
apps/logicsrc-web/src/app/openicon/gallery.tsx
Normal file
|
|
@ -0,0 +1,528 @@
|
|||
"use client";
|
||||
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import type { CSSProperties, ReactNode } from "react";
|
||||
import styles from "./gallery.module.css";
|
||||
import { GALLERY_SET, OPENICON_RAW } from "./set";
|
||||
|
||||
/**
|
||||
* The OpenIcon reference set, filterable, with the terminal view beside the
|
||||
* vector one: every icon can be shown as its SVG or as the glyph hqtui's
|
||||
* icon() would print (Nerd Font, Unicode or ASCII), which is the point of
|
||||
* the spec's tui block.
|
||||
*
|
||||
* Icons are drawn as CSS masks over the chosen colour, the same way
|
||||
* currentColor would colour them inline, without 370 inline SVGs.
|
||||
* Filters live in the query string.
|
||||
*/
|
||||
|
||||
type Icon = {
|
||||
key: string;
|
||||
name: string;
|
||||
category: string;
|
||||
aliases?: string[];
|
||||
keywords?: string[];
|
||||
brand?: boolean;
|
||||
trademark?: string;
|
||||
source?: string;
|
||||
license?: string;
|
||||
made_by?: string;
|
||||
svg: string;
|
||||
png?: string;
|
||||
/** The optional full-colour style; simple (the line icon) is canonical. */
|
||||
hq?: { png?: string; webp?: string; svg?: string; made_by?: string; hex?: string };
|
||||
tui?: { nerd?: string; nerd_code?: string; nerd_name?: string; unicode?: string; ascii?: string };
|
||||
};
|
||||
|
||||
type IconSet = {
|
||||
name: string;
|
||||
version: string;
|
||||
license: string;
|
||||
sizes: number[];
|
||||
categories: Record<string, string>;
|
||||
icons: Icon[];
|
||||
};
|
||||
|
||||
type View = "svg" | "nerd" | "unicode" | "ascii";
|
||||
|
||||
const VIEWS: Array<[View, string]> = [
|
||||
["svg", "SVG"],
|
||||
["nerd", "Nerd Font"],
|
||||
["unicode", "Unicode"],
|
||||
["ascii", "ASCII"]
|
||||
];
|
||||
|
||||
type Filters = {
|
||||
q: string;
|
||||
/** simple: the line icon in the chosen colour; hq: the full-colour style. */
|
||||
style: "simple" | "hq";
|
||||
category: string;
|
||||
kind: "" | "ui" | "brand";
|
||||
view: View;
|
||||
size: number;
|
||||
color: string;
|
||||
};
|
||||
|
||||
const DEFAULTS: Filters = { q: "", style: "simple", category: "", kind: "", view: "svg", size: 32, color: "#101418" };
|
||||
|
||||
function readFilters(): Filters {
|
||||
const p = new URLSearchParams(window.location.search);
|
||||
const view = p.get("view") as View | null;
|
||||
const kind = p.get("kind");
|
||||
const size = Number(p.get("size"));
|
||||
const color = p.get("color");
|
||||
return {
|
||||
q: p.get("q") ?? "",
|
||||
style: p.get("style") === "hq" ? "hq" : "simple",
|
||||
category: p.get("category") ?? "",
|
||||
kind: kind === "ui" || kind === "brand" ? kind : "",
|
||||
view: view && VIEWS.some(([v]) => v === view) ? view : "svg",
|
||||
size: size >= 16 && size <= 96 ? size : DEFAULTS.size,
|
||||
color: color && /^#[0-9a-f]{6}$/i.test(color) ? color : DEFAULTS.color
|
||||
};
|
||||
}
|
||||
|
||||
function writeFilters(f: Filters, selected: string | null): void {
|
||||
const p = new URLSearchParams(window.location.search);
|
||||
for (const key of ["q", "style", "category", "kind", "view", "size", "color", "icon"]) p.delete(key);
|
||||
if (f.q) p.set("q", f.q);
|
||||
if (f.style === "hq") p.set("style", "hq");
|
||||
if (f.category) p.set("category", f.category);
|
||||
if (f.kind) p.set("kind", f.kind);
|
||||
if (f.view !== "svg") p.set("view", f.view);
|
||||
if (f.size !== DEFAULTS.size) p.set("size", String(f.size));
|
||||
if (f.color !== DEFAULTS.color) p.set("color", f.color);
|
||||
if (selected) p.set("icon", selected);
|
||||
const query = p.toString();
|
||||
window.history.replaceState(null, "", `${query ? `?${query}` : window.location.pathname}${window.location.hash}`);
|
||||
}
|
||||
|
||||
const glyphOf = (icon: Icon, view: View): string => {
|
||||
const t = icon.tui ?? {};
|
||||
if (view === "nerd") return t.nerd ?? t.unicode ?? t.ascii ?? "";
|
||||
if (view === "unicode") return t.unicode ?? t.ascii ?? "";
|
||||
return t.ascii ?? "";
|
||||
};
|
||||
|
||||
const maskStyle = (icon: Icon, color: string, size: number): CSSProperties => {
|
||||
const url = `url("${GALLERY_SET}/${icon.svg}")`;
|
||||
return {
|
||||
width: size,
|
||||
height: size,
|
||||
background: color,
|
||||
WebkitMaskImage: url,
|
||||
maskImage: url,
|
||||
WebkitMaskRepeat: "no-repeat",
|
||||
maskRepeat: "no-repeat",
|
||||
WebkitMaskSize: "contain",
|
||||
maskSize: "contain",
|
||||
WebkitMaskPosition: "center",
|
||||
maskPosition: "center"
|
||||
};
|
||||
};
|
||||
|
||||
/** The HQ artwork for an icon at a size, or null when it has none. */
|
||||
const hqSrc = (icon: Icon, size: number): string | null => {
|
||||
const hq = icon.hq;
|
||||
if (!hq) return null;
|
||||
if (hq.svg) return `${GALLERY_SET}/${hq.svg}`;
|
||||
const template = hq.webp ?? hq.png;
|
||||
return template ? `${GALLERY_SET}/${template.replace("{size}", String(size > 64 ? 128 : 64))}` : null;
|
||||
};
|
||||
|
||||
function Art({ icon, style, color, size }: { icon: Icon; style: Filters["style"]; color: string; size: number }): ReactNode {
|
||||
const src = style === "hq" ? hqSrc(icon, size * 2) : null;
|
||||
if (src) {
|
||||
// eslint-disable-next-line @next/next/no-img-element
|
||||
return <img src={src} alt={icon.name} width={size} height={size} loading="lazy" decoding="async" />;
|
||||
}
|
||||
return <span role="img" aria-label={icon.name} style={maskStyle(icon, color, size)} />;
|
||||
}
|
||||
|
||||
export function Gallery(): ReactNode {
|
||||
const [set, setSet] = useState<IconSet | null>(null);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [filters, setFilters] = useState<Filters>(DEFAULTS);
|
||||
const [query, setQuery] = useState("");
|
||||
const [selected, setSelected] = useState<string | null>(null);
|
||||
const [ready, setReady] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const initial = readFilters();
|
||||
setFilters(initial);
|
||||
setQuery(initial.q);
|
||||
setSelected(new URLSearchParams(window.location.search).get("icon"));
|
||||
setReady(true);
|
||||
fetch(`${GALLERY_SET}/openicon.json`)
|
||||
.then((r) => {
|
||||
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
||||
return r.json() as Promise<IconSet>;
|
||||
})
|
||||
.then(setSet)
|
||||
.catch((reason: Error) => setError(reason.message));
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const timer = window.setTimeout(() => setFilters((f) => (f.q === query ? f : { ...f, q: query })), 120);
|
||||
return () => window.clearTimeout(timer);
|
||||
}, [query]);
|
||||
|
||||
useEffect(() => {
|
||||
if (ready) writeFilters(filters, selected);
|
||||
}, [filters, selected, ready]);
|
||||
|
||||
const update = useCallback(<K extends keyof Filters>(key: K, value: Filters[K]) => {
|
||||
setFilters((f) => ({ ...f, [key]: value }));
|
||||
}, []);
|
||||
|
||||
const hay = useMemo(
|
||||
() =>
|
||||
new Map(
|
||||
(set?.icons ?? []).map((i) => [
|
||||
i.key,
|
||||
[i.key, i.name, i.category, ...(i.aliases ?? []), ...(i.keywords ?? []), i.tui?.nerd_name ?? ""]
|
||||
.join(" ")
|
||||
.toLowerCase()
|
||||
])
|
||||
),
|
||||
[set]
|
||||
);
|
||||
|
||||
const matches = useCallback(
|
||||
(i: Icon, skipCategory = false): boolean => {
|
||||
if (!skipCategory && filters.category && i.category !== filters.category) return false;
|
||||
if (filters.kind === "brand" && !i.brand) return false;
|
||||
if (filters.kind === "ui" && i.brand) return false;
|
||||
if (filters.q) {
|
||||
const h = hay.get(i.key) ?? "";
|
||||
for (const word of filters.q.toLowerCase().split(/\s+/).filter(Boolean)) if (!h.includes(word)) return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
[filters, hay]
|
||||
);
|
||||
|
||||
const results = useMemo(() => (set ? set.icons.filter((i) => matches(i)) : []), [set, matches]);
|
||||
const counts = useMemo(() => {
|
||||
const c = new Map<string, number>();
|
||||
for (const i of set?.icons ?? []) if (matches(i, true)) c.set(i.category, (c.get(i.category) ?? 0) + 1);
|
||||
return c;
|
||||
}, [set, matches]);
|
||||
|
||||
const current = selected && set ? (set.icons.find((i) => i.key === selected) ?? null) : null;
|
||||
|
||||
useEffect(() => {
|
||||
if (!current) return;
|
||||
const onKey = (event: KeyboardEvent): void => {
|
||||
if (event.key === "Escape") setSelected(null);
|
||||
if (event.key !== "ArrowRight" && event.key !== "ArrowLeft") return;
|
||||
const at = results.findIndex((i) => i.key === current.key);
|
||||
const next = results[at + (event.key === "ArrowRight" ? 1 : -1)];
|
||||
if (at !== -1 && next) {
|
||||
event.preventDefault();
|
||||
setSelected(next.key);
|
||||
}
|
||||
};
|
||||
window.addEventListener("keydown", onKey);
|
||||
return () => window.removeEventListener("keydown", onKey);
|
||||
}, [current, results]);
|
||||
|
||||
if (error) return <p className={styles.notice}>The set could not be loaded ({error}).</p>;
|
||||
if (!set) return <p className={styles.notice}>Loading the set…</p>;
|
||||
|
||||
const brands = set.icons.filter((i) => i.brand).length;
|
||||
const hqCount = set.icons.filter((i) => i.hq).length;
|
||||
const terminal = filters.view !== "svg";
|
||||
const active = filters.q || filters.category || filters.kind;
|
||||
|
||||
return (
|
||||
<div className={styles.gallery}>
|
||||
<div className={styles.toolbar}>
|
||||
<input
|
||||
className={styles.search}
|
||||
type="search"
|
||||
placeholder={`Search ${set.icons.length} icons: mail, email, github, arrow…`}
|
||||
value={query}
|
||||
onChange={(e) => setQuery(e.target.value)}
|
||||
aria-label="Search icons"
|
||||
/>
|
||||
|
||||
<div className={styles.controls}>
|
||||
{hqCount ? (
|
||||
<div className={styles.segmented} role="group" aria-label="Style">
|
||||
{(
|
||||
[
|
||||
["simple", "Simple"],
|
||||
["hq", `HQ ${hqCount}`]
|
||||
] as const
|
||||
).map(([v, label]) => (
|
||||
<button
|
||||
type="button"
|
||||
key={v}
|
||||
className={filters.style === v && filters.view === "svg" ? styles.segOn : styles.seg}
|
||||
onClick={() => setFilters((f) => ({ ...f, style: v, view: "svg" }))}
|
||||
title={v === "hq" ? "The full-colour style" : "The line icon, in any colour"}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
<div className={styles.segmented} role="group" aria-label="Show as">
|
||||
{VIEWS.map(([v, label]) => (
|
||||
<button
|
||||
type="button"
|
||||
key={v}
|
||||
className={filters.view === v ? styles.segOn : styles.seg}
|
||||
onClick={() => update("view", v)}
|
||||
title={v === "svg" ? "The vector icon" : `The ${label} glyph hqtui's icon() prints`}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<div className={styles.segmented} role="group" aria-label="Kind">
|
||||
{(
|
||||
[
|
||||
["", `All ${set.icons.length}`],
|
||||
["ui", `UI ${set.icons.length - brands}`],
|
||||
["brand", `Brands ${brands}`]
|
||||
] as const
|
||||
).map(([k, label]) => (
|
||||
<button
|
||||
type="button"
|
||||
key={k || "all"}
|
||||
className={filters.kind === k ? styles.segOn : styles.seg}
|
||||
onClick={() => update("kind", k)}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<label className={styles.control}>
|
||||
<span>Size {filters.size}px</span>
|
||||
<input
|
||||
type="range"
|
||||
min={16}
|
||||
max={96}
|
||||
step={4}
|
||||
value={filters.size}
|
||||
onChange={(e) => update("size", Number(e.target.value))}
|
||||
/>
|
||||
</label>
|
||||
{!terminal && filters.style === "simple" ? (
|
||||
<label className={styles.control}>
|
||||
<span>Colour</span>
|
||||
<input type="color" value={filters.color} onChange={(e) => update("color", e.target.value)} />
|
||||
</label>
|
||||
) : null}
|
||||
<span className={styles.count}>
|
||||
{results.length} {results.length === 1 ? "icon" : "icons"}
|
||||
{active ? (
|
||||
<button
|
||||
type="button"
|
||||
className={styles.reset}
|
||||
onClick={() => {
|
||||
setQuery("");
|
||||
setFilters((f) => ({ ...DEFAULTS, view: f.view, size: f.size, color: f.color }));
|
||||
}}
|
||||
>
|
||||
Reset
|
||||
</button>
|
||||
) : null}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className={styles.chips} role="group" aria-label="Category">
|
||||
<button
|
||||
type="button"
|
||||
className={!filters.category ? styles.chipOn : styles.chip}
|
||||
onClick={() => update("category", "")}
|
||||
>
|
||||
All categories
|
||||
</button>
|
||||
{Object.entries(set.categories).map(([key, label]) => (
|
||||
<button
|
||||
type="button"
|
||||
key={key}
|
||||
className={filters.category === key ? styles.chipOn : styles.chip}
|
||||
onClick={() => update("category", filters.category === key ? "" : key)}
|
||||
>
|
||||
{label} <small>{counts.get(key) ?? 0}</small>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{terminal ? (
|
||||
<p className={styles.hint}>
|
||||
What <code>icon("{current?.key ?? "mail"}")</code> prints in hqtui with the glyph mode set to{" "}
|
||||
<strong>{filters.view}</strong>
|
||||
{filters.view === "nerd" ? " (Nerd Font symbols served subset from this page)" : ""}.
|
||||
</p>
|
||||
) : null}
|
||||
|
||||
{results.length === 0 ? (
|
||||
<p className={styles.notice}>Nothing matches. Try an alias (email, trash) or fewer words.</p>
|
||||
) : (
|
||||
<ul className={`${styles.grid} ${terminal ? styles.gridTerminal : ""}`} style={{ ["--tile" as string]: `${filters.size}px` }}>
|
||||
{results.map((i) => (
|
||||
<li key={i.key}>
|
||||
<button
|
||||
type="button"
|
||||
className={`${styles.tile} ${selected === i.key ? styles.tileOn : ""} ${
|
||||
filters.view === "nerd" && !i.tui?.nerd ? styles.fallback : ""
|
||||
}`}
|
||||
onClick={() => setSelected(i.key)}
|
||||
title={filters.view === "nerd" && !i.tui?.nerd ? `${i.name}: no Nerd Font glyph, Unicode shown` : i.name}
|
||||
>
|
||||
{terminal ? (
|
||||
<span
|
||||
className={filters.view === "nerd" ? styles.glyphNerd : styles.glyph}
|
||||
style={{ fontSize: filters.size * 0.8 }}
|
||||
>
|
||||
{glyphOf(i, filters.view)}
|
||||
</span>
|
||||
) : (
|
||||
<Art icon={i} style={filters.style} color={filters.color} size={filters.size} />
|
||||
)}
|
||||
<span className={styles.label}>{i.key}</span>
|
||||
</button>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
|
||||
{current ? (
|
||||
<Detail icon={current} set={set} color={filters.color} onClose={() => setSelected(null)} />
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function Detail({ icon, set, color, onClose }: { icon: Icon; set: IconSet; color: string; onClose: () => void }): ReactNode {
|
||||
const [svgText, setSvgText] = useState("");
|
||||
useEffect(() => {
|
||||
setSvgText("");
|
||||
fetch(`${GALLERY_SET}/${icon.svg}`)
|
||||
.then((r) => (r.ok ? r.text() : ""))
|
||||
.then((t) => setSvgText(t.trim()))
|
||||
.catch(() => setSvgText(""));
|
||||
}, [icon.svg]);
|
||||
|
||||
const t = icon.tui ?? {};
|
||||
const img = `<img src="${OPENICON_RAW}/${icon.svg}" alt="${icon.name}" width="24" height="24">`;
|
||||
return (
|
||||
<aside className={styles.detail} aria-label={`${icon.name} details`}>
|
||||
<button type="button" className={styles.close} onClick={onClose} aria-label="Close">
|
||||
×
|
||||
</button>
|
||||
<div className={styles.hero}>
|
||||
<span role="img" aria-label={icon.name} style={maskStyle(icon, color, 96)} />
|
||||
<div className={styles.heroSmall}>
|
||||
{[16, 24, 32].map((size) => (
|
||||
<span key={size} style={maskStyle(icon, color, size)} />
|
||||
))}
|
||||
</div>
|
||||
{icon.hq ? (
|
||||
<div className={styles.heroHq}>
|
||||
<Art icon={icon} style="hq" color={color} size={72} />
|
||||
<span>HQ</span>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
<h3>{icon.name}</h3>
|
||||
<dl className={styles.facts}>
|
||||
<dt>Key</dt>
|
||||
<dd>
|
||||
<code>{icon.key}</code>
|
||||
</dd>
|
||||
{icon.aliases?.length ? (
|
||||
<>
|
||||
<dt>Aliases</dt>
|
||||
<dd>{icon.aliases.join(", ")}</dd>
|
||||
</>
|
||||
) : null}
|
||||
<dt>Category</dt>
|
||||
<dd>{set.categories[icon.category] ?? icon.category}</dd>
|
||||
{icon.brand ? (
|
||||
<>
|
||||
<dt>Source</dt>
|
||||
<dd>
|
||||
{icon.source} · {icon.license}
|
||||
</dd>
|
||||
</>
|
||||
) : null}
|
||||
</dl>
|
||||
{icon.trademark ? <p className={styles.trademark}>{icon.trademark}</p> : null}
|
||||
|
||||
<table className={styles.tui}>
|
||||
<caption>In a terminal (hqtui icon())</caption>
|
||||
<tbody>
|
||||
<tr>
|
||||
<th>Nerd Font</th>
|
||||
<td className={styles.glyphNerd}>{t.nerd ?? "none"}</td>
|
||||
<td>{t.nerd_code ? <code>U+{t.nerd_code.toUpperCase()}</code> : null}</td>
|
||||
<td>{t.nerd ? <button type="button" className={styles.copy} data-copy={t.nerd}>Copy</button> : null}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Unicode</th>
|
||||
<td className={styles.glyph}>{t.unicode}</td>
|
||||
<td>
|
||||
{t.unicode ? (
|
||||
<code>
|
||||
{[...t.unicode].map((c) => `U+${c.codePointAt(0)!.toString(16).toUpperCase()}`).join(" ")}
|
||||
</code>
|
||||
) : null}
|
||||
</td>
|
||||
<td>{t.unicode ? <button type="button" className={styles.copy} data-copy={t.unicode}>Copy</button> : null}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>ASCII</th>
|
||||
<td className={styles.glyph}>{t.ascii}</td>
|
||||
<td />
|
||||
<td>{t.ascii ? <button type="button" className={styles.copy} data-copy={t.ascii}>Copy</button> : null}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div className={styles.actions}>
|
||||
{svgText ? (
|
||||
<button type="button" className={styles.copy} data-copy={svgText}>
|
||||
Copy SVG
|
||||
</button>
|
||||
) : null}
|
||||
<button type="button" className={styles.copy} data-copy={img}>
|
||||
Copy <img>
|
||||
</button>
|
||||
<button type="button" className={styles.copy} data-copy={`icon("${icon.key}")`}>
|
||||
Copy icon("{icon.key}")
|
||||
</button>
|
||||
</div>
|
||||
<div className={styles.downloads}>
|
||||
<span>Download</span>
|
||||
<a href={`${OPENICON_RAW}/${icon.svg}`} download>
|
||||
SVG
|
||||
</a>
|
||||
{icon.hq?.png
|
||||
? [128, 256]
|
||||
.map((s) => (
|
||||
<a key={`hq${s}`} href={`${OPENICON_RAW}/${icon.hq!.png!.replace("{size}", String(s))}`} download>
|
||||
HQ PNG {s}
|
||||
</a>
|
||||
))
|
||||
: null}
|
||||
{icon.png
|
||||
? [24, 64, 128, 256]
|
||||
.filter((s) => set.sizes.includes(s))
|
||||
.map((s) => (
|
||||
<a key={s} href={`${OPENICON_RAW}/${icon.png!.replace("{size}", String(s))}`} download>
|
||||
PNG {s}
|
||||
</a>
|
||||
))
|
||||
: null}
|
||||
</div>
|
||||
{icon.keywords?.length ? <p className={styles.keywords}>{icon.keywords.join(" · ")}</p> : null}
|
||||
</aside>
|
||||
);
|
||||
}
|
||||
|
|
@ -3,6 +3,8 @@ import type { ReactNode } from "react";
|
|||
import type { Metadata } from "next";
|
||||
import { SiteShell } from "@/components/site-shell";
|
||||
import { mono, pre, table, td, th } from "../openontology/ui";
|
||||
import { Gallery } from "./gallery";
|
||||
import { OPENICON_REPO } from "./set";
|
||||
|
||||
export const metadata: Metadata = {
|
||||
title: "OpenIcon · LogicSRC",
|
||||
|
|
@ -11,14 +13,6 @@ export const metadata: Metadata = {
|
|||
alternates: { canonical: "/openicon" }
|
||||
};
|
||||
|
||||
/** From the reference set, profullstack/openicon; copied into public/openicon. */
|
||||
const SAMPLE = [
|
||||
"mail", "phone", "chat", "at", "link", "search", "settings", "filter", "menu", "add", "edit", "delete",
|
||||
"copy", "share", "download", "upload", "refresh", "bell", "calendar", "user", "users", "lock", "key", "eye",
|
||||
"home", "map-pin", "globe", "cloud", "database", "package", "terminal", "code", "git-branch", "git-pull-request",
|
||||
"rocket", "sparkles", "rss", "github", "x", "bluesky", "mastodon", "discord", "slack", "signal", "whatsapp",
|
||||
"youtube", "npm"
|
||||
];
|
||||
|
||||
/** key, Nerd Font codepoint, Unicode, ASCII: straight from openicon.json. */
|
||||
const GLYPHS: Array<[string, string, string, string]> = [
|
||||
|
|
@ -95,33 +89,17 @@ export default function OpenIconPage(): ReactNode {
|
|||
</p>
|
||||
</div>
|
||||
|
||||
<div className="band">
|
||||
<div className="section-head">
|
||||
<h2>The reference set</h2>
|
||||
<p>
|
||||
370 icons: 259 drawn on a 24x24 grid with 2px strokes, 111 brand logos from Simple Icons and Font Awesome
|
||||
Free. <a href="https://github.com/profullstack/openicon">profullstack/openicon</a>.
|
||||
<div className="band" id="gallery">
|
||||
<div style={{ maxWidth: "52rem", marginBottom: "0.4rem" }}>
|
||||
<h2 style={{ margin: "0 0 0.4rem" }}>The reference set: all 370</h2>
|
||||
<p style={{ color: "#41505d", margin: 0, lineHeight: 1.6 }}>
|
||||
259 icons drawn on a 24x24 grid with 2px strokes, and 111 brand logos from Simple Icons and Font Awesome
|
||||
Free. Search by name, alias or keyword, filter by category or brand, and switch between the SVG and the
|
||||
glyph a terminal gets (Nerd Font, Unicode, ASCII). Click one for its glyphs, SVG and downloads. The files
|
||||
are in <a href={OPENICON_REPO}>profullstack/openicon</a>.
|
||||
</p>
|
||||
</div>
|
||||
<div style={{ display: "grid", gridTemplateColumns: "repeat(auto-fill, minmax(76px, 1fr))", gap: "0.45rem" }}>
|
||||
{SAMPLE.map((key) => (
|
||||
<figure
|
||||
key={key}
|
||||
style={{
|
||||
margin: 0,
|
||||
padding: "0.75rem 0.25rem 0.5rem",
|
||||
border: "1px solid #e3e6e0",
|
||||
borderRadius: "0.6rem",
|
||||
background: "#fff",
|
||||
textAlign: "center"
|
||||
}}
|
||||
>
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img src={`/openicon/${key}.svg`} alt="" width={28} height={28} />
|
||||
<figcaption style={{ fontSize: "0.7rem", color: "#5b6b7a", marginTop: "0.35rem" }}>{key}</figcaption>
|
||||
</figure>
|
||||
))}
|
||||
</div>
|
||||
<Gallery />
|
||||
</div>
|
||||
|
||||
<div className="band">
|
||||
|
|
|
|||
11
apps/logicsrc-web/src/app/openicon/set.ts
Normal file
11
apps/logicsrc-web/src/app/openicon/set.ts
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/**
|
||||
* Where the OpenIcon reference set lives. A plain module so a server
|
||||
* component can import the strings (from a "use client" file it would get
|
||||
* client references instead).
|
||||
*/
|
||||
|
||||
/** openicon.json, the SVGs and the subset Nerd Font, served by this site. */
|
||||
export const GALLERY_SET = "/openicon/set";
|
||||
/** PNGs at every size and the sprite live in the set's repository. */
|
||||
export const OPENICON_RAW = "https://raw.githubusercontent.com/profullstack/openicon/main";
|
||||
export const OPENICON_REPO = "https://github.com/profullstack/openicon";
|
||||
Loading…
Add table
Add a link
Reference in a new issue