update from cdrl

This commit is contained in:
2026-07-15 11:20:47 -04:00
parent 0f9f42be5a
commit f1745b8a1b
8 changed files with 195 additions and 353 deletions

View File

@@ -65,16 +65,16 @@ function resolveFAIcon(name: string, prefix: string): FAEntry | undefined {
return FA_ICONS[prefix + ":" + name];
}
export function Icon(props: IconProps) {
const size = () => props.size ?? 16;
export function Icon(props: IconProps): JSXElement {
const size = props.size ?? 16;
const custom = () => customIcons[props.icon];
const custom = customIcons[props.icon];
// Style resolution: an explicit `prefix` wins; then a per-icon `solid`
// override (true→solid, false→regular); otherwise the app-wide default set
// by FA_DEFAULT_SOLID. The fallback chain lets any icon resolve regardless
// of which style it actually ships in, so opting into solid never blanks.
const faDef = (): FAEntry | undefined => {
if (custom()) return undefined;
if (custom) return undefined;
let want: string;
if (props.prefix) want = props.prefix;
else if (props.solid === true) want = FA_PREFIX_SOLID;
@@ -88,7 +88,7 @@ export function Icon(props: IconProps) {
// viewBox as [minX, minY, width, height]: custom icons are 0-origin; FA icons
// carry a viewBox cropped to the glyph so they render at their intended size.
const box = (): [number, number, number, number] => {
const c = custom();
const c = custom;
if (c) return [0, 0, c.viewBox[0], c.viewBox[1]];
const fa = faDef();
return fa ? [fa[0], fa[1], fa[2], fa[3]] : [0, 0, 512, 512];
@@ -96,18 +96,18 @@ export function Icon(props: IconProps) {
const vw = () => box()[2];
const vh = () => box()[3];
const svgContent = () => {
const c = custom();
const c = custom;
if (c) return c.content;
const fa = faDef();
return fa ? '<path d="' + fa[4] + '"/>' : "";
};
const h = (): number => {
const s = size();
const s = size;
return Array.isArray(s) ? (s[1] ?? s[0]) : s;
};
const w = (): number => {
const s = size();
const s = size;
return Array.isArray(s) ? s[0] : Math.round(h() * (vw() / vh()));
};
@@ -116,22 +116,18 @@ export function Icon(props: IconProps) {
);
}
export function IconInline(props: IconProps) {
export function IconInline(props: IconProps): JSXElement {
return <Icon icon={props.icon} size={props.size} prefix={props.prefix} solid={props.solid} class={ICON_INLINE + " " + (props.class || "")}/>;
}
export function IconSuccess(props: IconProps) {
export function IconSuccess(props: IconProps): JSXElement {
return <Icon icon={props.icon} size={props.size} prefix={props.prefix} solid={props.solid} class={ICON_INLINE + " text-green-600 dark:text-green-400 " + (props.class || "")}/>;
}
export function IconError(props: IconProps) {
export function IconError(props: IconProps): JSXElement {
return <Icon icon={props.icon} size={props.size} prefix={props.prefix} solid={props.solid} class={ICON_INLINE + " text-red-600 dark:text-red-400 " + (props.class || "")}/>;
}
interface IconContainerProps {
children?: JSXElement;
}
export function IconContainer(props: IconContainerProps) {
export function IconContainer(props: {children?: JSXElement}): JSXElement {
return <span class="flex flex-row items-center gap-2">{props.children}</span>;
}