@tonycodes-ui/mortar 0.15.0 → 0.16.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -7
- package/catalog.json +360 -360
- package/cli/audit.mjs +98 -6
- package/cli/data.mjs +5 -0
- package/cli/mcp.mjs +1 -1
- package/cli/packet.mjs +17 -0
- package/dist/agent-data.json +1 -1
- package/dist/display.d.ts +3 -1
- package/dist/display.js +5 -2
- package/dist/ecommerce.d.ts +2 -1
- package/dist/ecommerce.js +5 -4
- package/dist/icons.d.ts +4 -0
- package/dist/icons.js +4 -0
- package/dist/image.d.ts +32 -0
- package/dist/image.js +42 -0
- package/dist/marketing.js +7 -1
- package/docs/agents.md +4 -2
- package/docs/email.md +10 -0
- package/package.json +1 -1
- package/skills/mortar/SKILL.md +3 -2
- package/src/display.tsx +13 -4
- package/src/ecommerce.tsx +8 -15
- package/src/foundation.css +16 -0
- package/src/icons.tsx +11 -0
- package/src/image.tsx +79 -0
- package/src/marketing.tsx +11 -5
package/dist/display.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type ImageFallback } from "./image.js";
|
|
1
2
|
import { type ReactNode } from "react";
|
|
2
3
|
import type { Tone } from "./primitives.js";
|
|
3
4
|
import { type HeadingLevel } from "./heading.js";
|
|
@@ -88,10 +89,11 @@ export interface GridListItem {
|
|
|
88
89
|
/** Avatar or icon shown beside the title. */
|
|
89
90
|
media?: ReactNode;
|
|
90
91
|
/** Image across the top of the card. Use alt="" when the title already describes it. */
|
|
92
|
+
/** A cover image. `fallbackSrc` and `fallback` cover a missing or broken image. */
|
|
91
93
|
cover?: {
|
|
92
94
|
src: string;
|
|
93
95
|
alt: string;
|
|
94
|
-
};
|
|
96
|
+
} & ImageFallback;
|
|
95
97
|
/** Badges, dates or counts under the description. */
|
|
96
98
|
meta?: ReactNode;
|
|
97
99
|
/** Term/value pairs under the body, e.g. a client card's last invoice and amount. */
|
package/dist/display.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { KitImage, useImageFallback } from "./image.js";
|
|
2
3
|
import { useId } from "react";
|
|
3
4
|
import { KitLink } from "./navigation.js";
|
|
4
5
|
import { Check, Close, Paperclip, Person } from "./icons.js";
|
|
@@ -13,12 +14,14 @@ function initials(name) {
|
|
|
13
14
|
.join("");
|
|
14
15
|
}
|
|
15
16
|
export function Avatar({ name, src, size = "md", shape = "circle", status, statusPosition = "bottom", placeholder = "initials", decorative = false, className, }) {
|
|
17
|
+
// A broken or expired photo falls back to the placeholder.
|
|
18
|
+
const image = useImageFallback(src ?? "");
|
|
16
19
|
return (_jsxs("span", { ...componentRoot("Avatar"), className: cx(`m-avatar m-avatar-${size}`, className), "data-shape": shape === "circle" ? undefined : shape, ...(decorative
|
|
17
20
|
? { "aria-hidden": true }
|
|
18
21
|
: {
|
|
19
22
|
role: "img",
|
|
20
23
|
"aria-label": status ? `${name}, ${status}` : name,
|
|
21
|
-
}), children: [
|
|
24
|
+
}), children: [image.current ? (_jsx("img", { ref: image.ref, src: image.current, alt: "", onError: image.onError })) : placeholder === "icon" ? (_jsx(Person, { className: "m-avatar-placeholder" })) : (_jsx("span", { "aria-hidden": "true", children: initials(name) })), status && (_jsx("span", { className: "m-avatar-status", "data-status": status, "data-position": statusPosition === "top" ? "top" : undefined, "aria-hidden": "true" }))] }));
|
|
22
25
|
}
|
|
23
26
|
export function AvatarGroup({ label, people, max = 4, className, }) {
|
|
24
27
|
const shown = people.slice(0, max), rest = people.length - shown.length;
|
|
@@ -67,7 +70,7 @@ export function DescriptionList({ title, description, headingLevel = 2, items, l
|
|
|
67
70
|
*/
|
|
68
71
|
export function GridList({ label, items, columns = 3, itemHeadingLevel = 3, actionsLayout = "inline", className, }) {
|
|
69
72
|
const Heading = headingTag(itemHeadingLevel);
|
|
70
|
-
return (_jsx("ul", { ...componentRoot("GridList"), className: cx("m-grid-list", className), "aria-label": label, "data-columns": columns === 3 ? undefined : columns, "data-actions": actionsLayout === "split" ? "split" : undefined, children: items.map((item) => (_jsxs("li", { children: [item.cover && (_jsx("div", { className: "m-grid-list-cover", children: _jsx(
|
|
73
|
+
return (_jsx("ul", { ...componentRoot("GridList"), className: cx("m-grid-list", className), "aria-label": label, "data-columns": columns === 3 ? undefined : columns, "data-actions": actionsLayout === "split" ? "split" : undefined, children: items.map((item) => (_jsxs("li", { children: [item.cover && (_jsx("div", { className: "m-grid-list-cover", children: _jsx(KitImage, { ...item.cover, loading: "lazy" }) })), _jsxs("div", { className: "m-grid-list-body", children: [item.media && (_jsx("span", { className: "m-grid-list-media", children: item.media })), _jsxs("div", { className: "m-grid-list-text", children: [_jsx(Heading, { className: "m-grid-list-title", children: item.href ? (_jsx(KitLink, { href: item.href, children: item.title })) : (item.title) }), item.description && _jsx("p", { children: item.description }), item.meta && _jsx("div", { className: "m-grid-list-meta", children: item.meta })] })] }), item.details && item.details.length > 0 && (_jsx(TermList, { className: "m-grid-list-details", items: item.details })), item.actions && (_jsx("div", { className: "m-grid-list-actions", children: item.actions }))] }, item.id))) }));
|
|
71
74
|
}
|
|
72
75
|
/** Files attached to a record, each with a size and a named download link. */
|
|
73
76
|
export function AttachmentList({ files, label = "Attachments", className, }) {
|
package/dist/ecommerce.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { type ImageFallback } from "./image.js";
|
|
1
2
|
import { type ReactNode } from "react";
|
|
2
3
|
import { type ProgressStep } from "./application.js";
|
|
3
4
|
import { type HeadingLevel } from "./heading.js";
|
|
4
|
-
export interface ProductImage {
|
|
5
|
+
export interface ProductImage extends ImageFallback {
|
|
5
6
|
src: string;
|
|
6
7
|
/** Describe the product shown; images are the main product information. */
|
|
7
8
|
alt: string;
|
package/dist/ecommerce.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { KitImage } from "./image.js";
|
|
2
3
|
import { useEffect, useId, useRef, useState, } from "react";
|
|
3
4
|
import { KitLink } from "./navigation.js";
|
|
4
5
|
import { ActionLink, Button, Checkbox, EmptyState, Modal, } from "./primitives.js";
|
|
@@ -13,7 +14,7 @@ export function ProductList({ label, products, columns = 4, itemHeadingLevel = 3
|
|
|
13
14
|
const overlay = variant === "overlay";
|
|
14
15
|
return (_jsx("ul", { id: id, ...componentRoot("ProductList"), className: cx("m-product-list", className), "aria-label": label, "data-columns": columns, "data-variant": variant === "plain" ? undefined : variant, children: products.map((product) => {
|
|
15
16
|
const text = (_jsxs(_Fragment, { children: [_jsxs("div", { className: "m-product-info", children: [_jsx(Heading, { className: "m-product-name", children: _jsx(KitLink, { href: product.href, children: product.name }) }), product.meta && _jsx("p", { className: "m-product-meta", children: product.meta }), product.description && (_jsx("p", { className: "m-product-summary", children: product.description }))] }), _jsx("p", { className: "m-product-price", children: product.price })] }));
|
|
16
|
-
return (_jsxs("li", { children: [_jsxs("div", { className: "m-product-image", children: [_jsx(
|
|
17
|
+
return (_jsxs("li", { children: [_jsxs("div", { className: "m-product-image", children: [_jsx(KitImage, { ...product.image, loading: "lazy" }), product.badge && (_jsx("span", { className: "m-product-badge", children: product.badge })), overlay && _jsx("div", { className: "m-product-overlay", children: text })] }), !overlay && text, product.swatches && product.swatches.length > 0 && (_jsx("ul", { className: "m-product-swatches", "aria-label": `${product.name} colours`, children: product.swatches.map((colour) => (_jsx("li", { children: _jsx(Swatch, { color: colour.swatch, label: colour.label }) }, colour.label))) })), product.action && (_jsx("div", { className: "m-product-card-action", children: product.action }))] }, product.id));
|
|
17
18
|
}) }));
|
|
18
19
|
}
|
|
19
20
|
/** Product page body: gallery, price, rating, option pickers, add to bag and details. */
|
|
@@ -29,7 +30,7 @@ export function ProductOverview({ name, price, description, images, rating, opti
|
|
|
29
30
|
const group = useId();
|
|
30
31
|
const Heading = headingTag(headingLevel);
|
|
31
32
|
const shown = images[current] ?? images[0];
|
|
32
|
-
return (_jsxs("div", { id: id, ...componentRoot("ProductOverview"), className: cx("m-product-overview", className), children: [gallery === "grid" ? (_jsx("div", { className: "m-product-gallery", "data-gallery": "grid", children: images.map((image) => (_jsx("div", { className: "m-product-image", children: _jsx(
|
|
33
|
+
return (_jsxs("div", { id: id, ...componentRoot("ProductOverview"), className: cx("m-product-overview", className), children: [gallery === "grid" ? (_jsx("div", { className: "m-product-gallery", "data-gallery": "grid", children: images.map((image) => (_jsx("div", { className: "m-product-image", children: _jsx(KitImage, { ...image }) }, image.src))) })) : (_jsxs("div", { className: "m-product-gallery", children: [shown && (_jsx("div", { className: "m-product-image", children: _jsx(KitImage, { ...shown }) })), images.length > 1 && (_jsx("div", { className: "m-product-thumbs", role: "group", "aria-label": "Product images", children: images.map((image, index) => (_jsx("button", { type: "button", "aria-pressed": index === current, "aria-label": `Show image ${index + 1} of ${images.length}: ${image.alt}`, onClick: () => setCurrent(index), children: _jsx(KitImage, { ...image, alt: "" }) }, image.src))) }))] })), _jsxs("div", { className: "m-product-details", children: [!hideName && _jsx(Heading, { className: "m-product-name", children: name }), _jsx("p", { className: "m-product-price", children: price }), rating && (_jsxs("div", { className: "m-rating", children: [_jsx(Stars, { value: rating.value, label: `Rated ${rating.value} out of 5 from ${rating.count} reviews` }), rating.href ? (_jsxs(KitLink, { href: rating.href, children: [rating.count, " reviews"] })) : (_jsxs("span", { "aria-hidden": "true", children: [rating.count, " reviews"] }))] })), description && (_jsx("div", { className: "m-product-description", children: description })), _jsxs("form", { className: "m-product-form", onSubmit: (event) => {
|
|
33
34
|
event.preventDefault();
|
|
34
35
|
if (!loading)
|
|
35
36
|
onAdd?.();
|
|
@@ -75,7 +76,7 @@ function CartLines({ items, onQuantityChange, onRemove, label = "Items in your b
|
|
|
75
76
|
return (_jsx("ul", { id: id, ...componentRoot("ShoppingCart", isRoot), className: cx("m-cart", className), "aria-label": label, ref: root, children: items.map((item, index) => {
|
|
76
77
|
const quantityId = `${base}-${item.id}`;
|
|
77
78
|
const choices = Array.from({ length: Math.max(maxQuantity, item.quantity) }, (_, i) => i + 1);
|
|
78
|
-
return (_jsxs("li", { children: [_jsx("div", { className: "m-product-image", children: _jsx(
|
|
79
|
+
return (_jsxs("li", { children: [_jsx("div", { className: "m-product-image", children: _jsx(KitImage, { ...item.image, loading: "lazy" }) }), _jsxs("div", { className: "m-cart-info", children: [_jsx(Heading, { className: "m-cart-item-title", children: _jsx(KitLink, { href: item.href, children: item.name }) }), item.meta && _jsx("p", { className: "m-product-meta", children: item.meta }), _jsx("p", { className: "m-product-price", children: item.price }), item.stock && _jsx("p", { className: "m-cart-stock", children: item.stock })] }), _jsxs("div", { className: "m-cart-controls", children: [_jsxs("label", { className: "m-sr-only", htmlFor: quantityId, children: ["Quantity, ", item.name] }), _jsxs("div", { className: "m-select-control", children: [_jsx("select", { id: quantityId, value: item.quantity, onChange: (event) => onQuantityChange(item.id, Number(event.target.value)), children: choices.map((n) => (_jsx("option", { value: n, children: n }, n))) }), _jsx(ChevronDown, {})] }), _jsxs("button", { type: "button", className: "m-cart-remove", onClick: () => {
|
|
79
80
|
removing.current = { index, id: item.id };
|
|
80
81
|
onRemove(item.id);
|
|
81
82
|
}, children: ["Remove", _jsxs("span", { className: "m-sr-only", children: [" ", item.name] })] })] })] }, item.id));
|
|
@@ -172,6 +173,6 @@ export function OrderHistory({ orders, headingLevel = 2, empty = {
|
|
|
172
173
|
return (_jsxs("section", { className: "m-order", "aria-labelledby": titleId, children: [_jsxs("header", { className: "m-order-header", children: [_jsxs(Heading, { id: titleId, className: "m-order-title", children: ["Order ", order.number] }), _jsx(TermList, { items: [
|
|
173
174
|
{ term: "Date placed", details: order.date },
|
|
174
175
|
{ term: "Total", details: order.total },
|
|
175
|
-
] }), _jsxs(KitLink, { href: order.href, children: ["View order", _jsxs("span", { className: "m-sr-only", children: [" ", order.number] })] }), order.actions && (_jsx("div", { className: "m-order-actions", children: order.actions }))] }), _jsx("p", { className: "m-order-status", children: order.status }), order.progress && order.progress.length > 0 && (_jsx(ProgressSteps, { className: "m-order-progress", steps: order.progress, variant: "bar", navigation: false, label: `Order ${order.number} progress` })), _jsx("ul", { className: "m-order-items", children: order.items.map((item) => (_jsxs("li", { children: [_jsx("div", { className: "m-product-image", children: _jsx(
|
|
176
|
+
] }), _jsxs(KitLink, { href: order.href, children: ["View order", _jsxs("span", { className: "m-sr-only", children: [" ", order.number] })] }), order.actions && (_jsx("div", { className: "m-order-actions", children: order.actions }))] }), _jsx("p", { className: "m-order-status", children: order.status }), order.progress && order.progress.length > 0 && (_jsx(ProgressSteps, { className: "m-order-progress", steps: order.progress, variant: "bar", navigation: false, label: `Order ${order.number} progress` })), _jsx("ul", { className: "m-order-items", children: order.items.map((item) => (_jsxs("li", { children: [_jsx("div", { className: "m-product-image", children: _jsx(KitImage, { ...item.image, loading: "lazy" }) }), _jsxs("div", { children: [_jsx("p", { className: "m-order-item-name", children: item.href ? (_jsx(KitLink, { href: item.href, children: item.name })) : (item.name) }), _jsxs("p", { className: "m-product-meta", children: ["Qty ", item.quantity] })] }), _jsx("p", { className: "m-product-price", children: item.price }), item.actions && (_jsx("div", { className: "m-order-item-actions", children: item.actions }))] }, item.id))) })] }, order.id));
|
|
176
177
|
}) }));
|
|
177
178
|
}
|
package/dist/icons.d.ts
CHANGED
|
@@ -48,3 +48,7 @@ export declare function Eye(): import("react").JSX.Element;
|
|
|
48
48
|
export declare function EyeOff(): import("react").JSX.Element;
|
|
49
49
|
/** Hollow circle: a requirement that is not met yet. */
|
|
50
50
|
export declare function Circle(): import("react").JSX.Element;
|
|
51
|
+
/** A picture frame, for an image that failed to load. */
|
|
52
|
+
export declare function ImageMissing({ className }: {
|
|
53
|
+
className?: string;
|
|
54
|
+
}): import("react").JSX.Element;
|
package/dist/icons.js
CHANGED
|
@@ -68,3 +68,7 @@ export function EyeOff() {
|
|
|
68
68
|
export function Circle() {
|
|
69
69
|
return (_jsx(Icon, { children: _jsx(Stroke, { d: "M10 15a5 5 0 1 0 0-10 5 5 0 0 0 0 10z", width: "1.5" }) }));
|
|
70
70
|
}
|
|
71
|
+
/** A picture frame, for an image that failed to load. */
|
|
72
|
+
export function ImageMissing({ className }) {
|
|
73
|
+
return (_jsxs(Icon, { className: className, stroke: "currentColor", strokeWidth: "1.5", children: [_jsx("rect", { x: "2.75", y: "3.75", width: "14.5", height: "12.5", rx: "2" }), _jsx("circle", { cx: "7.25", cy: "8", r: "1.5" }), _jsx("path", { d: "m3 14.5 4.25-4 3 2.75 2.5-2.25 4.25 3.75" })] }));
|
|
74
|
+
}
|
package/dist/image.d.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
/** Optional fallbacks on an image a component renders from data. */
|
|
3
|
+
export interface ImageFallback {
|
|
4
|
+
/** Shown once if `src` fails or is empty. Not retried if it fails too. */
|
|
5
|
+
fallbackSrc?: string;
|
|
6
|
+
/**
|
|
7
|
+
* Shown when every image fails, in the image's reserved box, instead of the
|
|
8
|
+
* default placeholder icon. It is visual only: the image's `alt` names it.
|
|
9
|
+
*/
|
|
10
|
+
fallback?: ReactNode;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Which source to show: `src`, then `fallbackSrc` once, then none. Each step
|
|
14
|
+
* happens at most once per `src`, so a failing fallback can't loop, and a new
|
|
15
|
+
* `src` starts over. An error that fired before hydration attached `onError`
|
|
16
|
+
* is caught on mount from the image's own state.
|
|
17
|
+
*/
|
|
18
|
+
export declare function useImageFallback(src: string, fallbackSrc?: string): {
|
|
19
|
+
current: string | undefined;
|
|
20
|
+
ref: import("react").RefObject<HTMLImageElement | null>;
|
|
21
|
+
onError: () => void;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* An image with the kit's fallback: `fallbackSrc` once, then `fallback` or a
|
|
25
|
+
* placeholder icon in the same reserved box (the container sets the size), so
|
|
26
|
+
* nothing shifts. The placeholder carries the image's accessible name.
|
|
27
|
+
*/
|
|
28
|
+
export declare function KitImage({ src, alt, fallbackSrc, fallback, loading, }: ImageFallback & {
|
|
29
|
+
src: string;
|
|
30
|
+
alt: string;
|
|
31
|
+
loading?: "lazy";
|
|
32
|
+
}): import("react").JSX.Element;
|
package/dist/image.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
// Images the kit renders from data (covers, product photos, avatars, logos),
|
|
3
|
+
// with a one-shot fallback when the image fails. Internal: not exported.
|
|
4
|
+
import { useLayoutEffect, useRef, useState } from "react";
|
|
5
|
+
import { ImageMissing } from "./icons.js";
|
|
6
|
+
/**
|
|
7
|
+
* Which source to show: `src`, then `fallbackSrc` once, then none. Each step
|
|
8
|
+
* happens at most once per `src`, so a failing fallback can't loop, and a new
|
|
9
|
+
* `src` starts over. An error that fired before hydration attached `onError`
|
|
10
|
+
* is caught on mount from the image's own state.
|
|
11
|
+
*/
|
|
12
|
+
export function useImageFallback(src, fallbackSrc) {
|
|
13
|
+
const [failed, setFailed] = useState(null);
|
|
14
|
+
const second = fallbackSrc && fallbackSrc !== src ? fallbackSrc : undefined;
|
|
15
|
+
let stage = failed?.src === src ? failed.stage : 0;
|
|
16
|
+
if (stage === 0 && !src)
|
|
17
|
+
stage = second ? 1 : 2;
|
|
18
|
+
if (stage === 1 && !second)
|
|
19
|
+
stage = 2;
|
|
20
|
+
const current = stage === 0 ? src : stage === 1 ? second : undefined;
|
|
21
|
+
const fail = () => setFailed({ src, stage: stage === 0 && second ? 1 : 2 });
|
|
22
|
+
const ref = useRef(null);
|
|
23
|
+
useLayoutEffect(() => {
|
|
24
|
+
const img = ref.current;
|
|
25
|
+
if (img?.complete && img.naturalWidth === 0 && img.getAttribute("src"))
|
|
26
|
+
fail();
|
|
27
|
+
// `fail` reads this render's stage; re-run only when the source changes.
|
|
28
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
29
|
+
}, [current]);
|
|
30
|
+
return { current, ref, onError: fail };
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* An image with the kit's fallback: `fallbackSrc` once, then `fallback` or a
|
|
34
|
+
* placeholder icon in the same reserved box (the container sets the size), so
|
|
35
|
+
* nothing shifts. The placeholder carries the image's accessible name.
|
|
36
|
+
*/
|
|
37
|
+
export function KitImage({ src, alt, fallbackSrc, fallback, loading, }) {
|
|
38
|
+
const image = useImageFallback(src, fallbackSrc);
|
|
39
|
+
if (image.current)
|
|
40
|
+
return (_jsx("img", { ref: image.ref, src: image.current, alt: alt, loading: loading, onError: image.onError }));
|
|
41
|
+
return (_jsx("span", { className: "m-image-fallback", ...(alt ? { role: "img", "aria-label": alt } : { "aria-hidden": true }), children: fallback ? _jsx("span", { "aria-hidden": "true", children: fallback }) : _jsx(ImageMissing, {}) }));
|
|
42
|
+
}
|
package/dist/marketing.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useImageFallback } from "./image.js";
|
|
2
3
|
import { IconLinks, KitLink, } from "./navigation.js";
|
|
3
4
|
import { useId, useState } from "react";
|
|
4
5
|
import { DialogPanel, DialogTitle } from "@headlessui/react";
|
|
@@ -71,9 +72,14 @@ export function Testimonial({ id, className, quote, name, role, logo, avatar, })
|
|
|
71
72
|
const person = (_jsxs(_Fragment, { children: [_jsx("strong", { children: name }), role && _jsx("span", { children: role })] }));
|
|
72
73
|
return (_jsxs("figure", { id: id, className: cx("m-testimonial", className), ...componentRoot("Testimonial"), children: [logo && _jsx("div", { className: "m-testimonial-logo", children: logo }), _jsx("blockquote", { children: quote }), _jsx("figcaption", { children: avatar ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "m-testimonial-avatar", "aria-hidden": "true", children: avatar }), _jsx("span", { className: "m-testimonial-person", children: person })] })) : (person) })] }));
|
|
73
74
|
}
|
|
75
|
+
/** A logo, or its name as text when there is no image or it fails to load. */
|
|
76
|
+
function Logo({ name, image }) {
|
|
77
|
+
const logo = useImageFallback(image ?? "");
|
|
78
|
+
return logo.current ? (_jsx("img", { ref: logo.ref, src: logo.current, alt: name, onError: logo.onError })) : (_jsx("span", { children: name }));
|
|
79
|
+
}
|
|
74
80
|
export function LogoCloud({ id, className, label, items, layout = "inline", title, description, actions = [], headingLevel = 2, }) {
|
|
75
81
|
const Heading = headingTag(headingLevel);
|
|
76
|
-
const list = (_jsx("ul", { children: items.map((item) => (_jsx("li", { children:
|
|
82
|
+
const list = (_jsx("ul", { children: items.map((item) => (_jsx("li", { children: _jsx(Logo, { name: item.name, image: item.image }) }, item.name))) }));
|
|
77
83
|
if (layout === "split") {
|
|
78
84
|
return (_jsxs("section", { id: id, className: cx("m-logo-cloud", className), "aria-label": label, ...componentRoot("LogoCloud"), "data-layout": "split", children: [_jsxs("div", { className: "m-logo-cloud-copy", children: [title ? (_jsx(Heading, { className: "m-section-title", children: title })) : (_jsx("p", { children: label })), description && (_jsx("p", { className: "m-section-description", children: description })), actions.length > 0 && _jsx(ActionLinks, { actions: actions })] }), list] }));
|
|
79
85
|
}
|
package/docs/agents.md
CHANGED
|
@@ -63,7 +63,7 @@ In a project without Mortar installed, `npx -y @tonycodes-ui/mortar mcp` downloa
|
|
|
63
63
|
| `search_components` | `query`, optional `kit`, `category`, `limit` | Ranked components: name, kit, category, description, capabilities. |
|
|
64
64
|
| `get_component` | `name` | The full contract: props with types, required flags and defaults; usage, avoid and accessibility notes; the components it renders; its `data-m-component` marker; tested states; page templates; a JSX example; the import line. |
|
|
65
65
|
| `get_build_packet` | `components` and/or `brief` | The chosen components (for a brief, with the reason for each, starting from the purpose shell), their dependency closure, install, CSS and ThemeProvider setup, the import line, the design principles and API conventions, and matching page templates. |
|
|
66
|
-
| `get_guide` | `topic` | A guide as markdown: `design`, `conventions`, `theming`, `auth-flows`, `migrating-0.6`, `contributing`, `testing` or `agents`.
|
|
66
|
+
| `get_guide` | `topic` | A guide as markdown: `design`, `conventions`, `theming`, `auth-flows`, `email`, `migrating-0.6`, `contributing`, `testing` or `agents`. |
|
|
67
67
|
| `list_kits` | none | Kits → categories → components, and the page templates. |
|
|
68
68
|
| `audit_app` | `path` | A read-only audit of an application: findings with file, line, rule, message and a suggested fix. |
|
|
69
69
|
|
|
@@ -100,13 +100,15 @@ Add `--json` for machine-readable output. `mortar audit` exits with status 1 whe
|
|
|
100
100
|
| `not-installed` | error | Mortar imported but not in node_modules |
|
|
101
101
|
| `version-mismatch` | error | The installed version does not satisfy the package.json range |
|
|
102
102
|
| `unknown-export` | error | A named import the installed version does not export, with the replacement for names removed in 0.6 |
|
|
103
|
-
| `deep-import` | error | Imports or aliases into the package's `src` or `dist`
|
|
103
|
+
| `deep-import` | error | Imports or aliases into the package's `src` or `dist`, or an entry other than the package, `/styles.css`, `/brand` and `/email` |
|
|
104
104
|
| `unknown-prop` | error | A prop the component's contract does not declare, with the 0.6 rename where there is one |
|
|
105
105
|
| `invalid-value` | error | A literal outside the prop's declared union, such as `layout="centered"` (now `center`) |
|
|
106
106
|
| `css-override` | error | Consumer CSS selecting Mortar's `.m-*` classes or `[data-m-component]` |
|
|
107
107
|
| `class-override` | error | A Tailwind arbitrary variant that targets `.m-*` classes, such as `[&_.m-button]:rounded-none` |
|
|
108
108
|
| `local-copy` | error | A copy of a Mortar source file, or code rendering Mortar's component marker |
|
|
109
109
|
| `raw-element` | error | A raw `<table>`, `<select>`, `<textarea>`, `<dialog>`, `<progress>` or `<input>` (by type; not `hidden`, `file`, `range`, `color` or `image`) anywhere in an app that uses Mortar, naming the component to use instead. A raw `<button>` is a warning. The mapping comes from each contract's `replaces` field, so new components extend it |
|
|
110
|
+
| `email-app-import` | error | In an email (a file importing `@tonycodes-ui/mortar/email` or React Email), an app component or `styles.css`, naming the email component to use. Raw elements in emails are not reported: email layout is tables |
|
|
111
|
+
| `email-peer-missing` | error | `@tonycodes-ui/mortar/email` is imported but `@react-email/components` is not in package.json |
|
|
110
112
|
| `missing-styles` | error | No import of `@tonycodes-ui/mortar/styles.css` |
|
|
111
113
|
| `styles-order` | warning | Mortar's styles imported before Tailwind |
|
|
112
114
|
| `missing-theme-provider` | warning | Mortar components rendered without a `ThemeProvider` |
|
package/docs/email.md
CHANGED
|
@@ -114,3 +114,13 @@ Send a password reset only to an address that has an account, and show the same
|
|
|
114
114
|
- Don't rely on hover, scripts or forms. Email clients remove them.
|
|
115
115
|
- Keep each email under about 100 KB of HTML. Gmail clips longer messages behind a "View entire message" link.
|
|
116
116
|
- Before a release, check new emails in real clients (Gmail, Outlook for Windows, Apple Mail) with a service such as Litmus or Email on Acid.
|
|
117
|
+
|
|
118
|
+
## Checks
|
|
119
|
+
|
|
120
|
+
`npx mortar audit` (or the MCP `audit_app` tool) treats a file that imports `@tonycodes-ui/mortar/email` or React Email as an email:
|
|
121
|
+
|
|
122
|
+
- **`email-app-import`** reports an app component or `styles.css` imported into an email, and names the email component to use (`Button` → `EmailButton`, `Notice` → `EmailCallout`, `OrderSummary` → `EmailSummary`).
|
|
123
|
+
- **`email-peer-missing`** reports a project that imports the email entry without `@react-email/components` in its package.json.
|
|
124
|
+
- Named imports from `@tonycodes-ui/mortar/email` are checked against what it exports.
|
|
125
|
+
- Raw `<table>` and other elements in an email are not reported, because email layout is tables.
|
|
126
|
+
- A service that only sends email isn't asked for `styles.css` or a ThemeProvider.
|
package/package.json
CHANGED
package/skills/mortar/SKILL.md
CHANGED
|
@@ -12,8 +12,9 @@ Mortar is an MIT React 19 + Tailwind 4 UI kit. Its agent tooling ships in the pa
|
|
|
12
12
|
1. **Discover.** Before writing UI, call `search_components` (or `list_kits`) for what the brief needs. Without the MCP server, run `npx mortar search "<need>"`.
|
|
13
13
|
2. **Packet.** Call `get_build_packet` with the chosen components or the brief (`npx mortar packet <Name…> --json`, or `--brief "…"`). Start composing when the packet answers the brief; read extra source or guides only for a specific gap (`get_component`, `get_guide`).
|
|
14
14
|
3. **Compose** following the defaults below.
|
|
15
|
-
4. **
|
|
16
|
-
5. **
|
|
15
|
+
4. **Emails.** Build transactional emails from `@tonycodes-ui/mortar/email` (`get_guide email`), never from the app components.
|
|
16
|
+
5. **Audit.** Run `audit_app` on the application (`npx mortar audit`), fix every error and review the warnings, then rerun it with the app's build and typecheck.
|
|
17
|
+
6. **Verify** in a browser and report the actual results.
|
|
17
18
|
|
|
18
19
|
## Defaults
|
|
19
20
|
|
package/src/display.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { KitImage, useImageFallback, type ImageFallback } from "./image.js";
|
|
1
2
|
import { useId, type ReactNode } from "react";
|
|
2
3
|
import { KitLink } from "./navigation.js";
|
|
3
4
|
import type { Tone } from "./primitives.js";
|
|
@@ -45,6 +46,8 @@ export function Avatar({
|
|
|
45
46
|
decorative = false,
|
|
46
47
|
className,
|
|
47
48
|
}: AvatarProps) {
|
|
49
|
+
// A broken or expired photo falls back to the placeholder.
|
|
50
|
+
const image = useImageFallback(src ?? "");
|
|
48
51
|
return (
|
|
49
52
|
<span
|
|
50
53
|
{...componentRoot("Avatar")}
|
|
@@ -57,8 +60,13 @@ export function Avatar({
|
|
|
57
60
|
"aria-label": status ? `${name}, ${status}` : name,
|
|
58
61
|
})}
|
|
59
62
|
>
|
|
60
|
-
{
|
|
61
|
-
<img
|
|
63
|
+
{image.current ? (
|
|
64
|
+
<img
|
|
65
|
+
ref={image.ref}
|
|
66
|
+
src={image.current}
|
|
67
|
+
alt=""
|
|
68
|
+
onError={image.onError}
|
|
69
|
+
/>
|
|
62
70
|
) : placeholder === "icon" ? (
|
|
63
71
|
<Person className="m-avatar-placeholder" />
|
|
64
72
|
) : (
|
|
@@ -329,7 +337,8 @@ export interface GridListItem {
|
|
|
329
337
|
/** Avatar or icon shown beside the title. */
|
|
330
338
|
media?: ReactNode;
|
|
331
339
|
/** Image across the top of the card. Use alt="" when the title already describes it. */
|
|
332
|
-
cover
|
|
340
|
+
/** A cover image. `fallbackSrc` and `fallback` cover a missing or broken image. */
|
|
341
|
+
cover?: { src: string; alt: string } & ImageFallback;
|
|
333
342
|
/** Badges, dates or counts under the description. */
|
|
334
343
|
meta?: ReactNode;
|
|
335
344
|
/** Term/value pairs under the body, e.g. a client card's last invoice and amount. */
|
|
@@ -372,7 +381,7 @@ export function GridList({
|
|
|
372
381
|
<li key={item.id}>
|
|
373
382
|
{item.cover && (
|
|
374
383
|
<div className="m-grid-list-cover">
|
|
375
|
-
<
|
|
384
|
+
<KitImage {...item.cover} loading="lazy" />
|
|
376
385
|
</div>
|
|
377
386
|
)}
|
|
378
387
|
<div className="m-grid-list-body">
|
package/src/ecommerce.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { KitImage, type ImageFallback } from "./image.js";
|
|
1
2
|
import {
|
|
2
3
|
useEffect,
|
|
3
4
|
useId,
|
|
@@ -26,7 +27,7 @@ import {
|
|
|
26
27
|
cx,
|
|
27
28
|
} from "./internal.js";
|
|
28
29
|
|
|
29
|
-
export interface ProductImage {
|
|
30
|
+
export interface ProductImage extends ImageFallback {
|
|
30
31
|
src: string;
|
|
31
32
|
/** Describe the product shown; images are the main product information. */
|
|
32
33
|
alt: string;
|
|
@@ -105,11 +106,7 @@ export function ProductList({
|
|
|
105
106
|
return (
|
|
106
107
|
<li key={product.id}>
|
|
107
108
|
<div className="m-product-image">
|
|
108
|
-
<
|
|
109
|
-
src={product.image.src}
|
|
110
|
-
alt={product.image.alt}
|
|
111
|
-
loading="lazy"
|
|
112
|
-
/>
|
|
109
|
+
<KitImage {...product.image} loading="lazy" />
|
|
113
110
|
{product.badge && (
|
|
114
111
|
<span className="m-product-badge">{product.badge}</span>
|
|
115
112
|
)}
|
|
@@ -217,7 +214,7 @@ export function ProductOverview({
|
|
|
217
214
|
<div className="m-product-gallery" data-gallery="grid">
|
|
218
215
|
{images.map((image) => (
|
|
219
216
|
<div key={image.src} className="m-product-image">
|
|
220
|
-
<
|
|
217
|
+
<KitImage {...image} />
|
|
221
218
|
</div>
|
|
222
219
|
))}
|
|
223
220
|
</div>
|
|
@@ -225,7 +222,7 @@ export function ProductOverview({
|
|
|
225
222
|
<div className="m-product-gallery">
|
|
226
223
|
{shown && (
|
|
227
224
|
<div className="m-product-image">
|
|
228
|
-
<
|
|
225
|
+
<KitImage {...shown} />
|
|
229
226
|
</div>
|
|
230
227
|
)}
|
|
231
228
|
{images.length > 1 && (
|
|
@@ -242,7 +239,7 @@ export function ProductOverview({
|
|
|
242
239
|
aria-label={`Show image ${index + 1} of ${images.length}: ${image.alt}`}
|
|
243
240
|
onClick={() => setCurrent(index)}
|
|
244
241
|
>
|
|
245
|
-
<
|
|
242
|
+
<KitImage {...image} alt="" />
|
|
246
243
|
</button>
|
|
247
244
|
))}
|
|
248
245
|
</div>
|
|
@@ -488,7 +485,7 @@ function CartLines({
|
|
|
488
485
|
return (
|
|
489
486
|
<li key={item.id}>
|
|
490
487
|
<div className="m-product-image">
|
|
491
|
-
<
|
|
488
|
+
<KitImage {...item.image} loading="lazy" />
|
|
492
489
|
</div>
|
|
493
490
|
<div className="m-cart-info">
|
|
494
491
|
<Heading className="m-cart-item-title">
|
|
@@ -1002,11 +999,7 @@ export function OrderHistory({
|
|
|
1002
999
|
{order.items.map((item) => (
|
|
1003
1000
|
<li key={item.id}>
|
|
1004
1001
|
<div className="m-product-image">
|
|
1005
|
-
<
|
|
1006
|
-
src={item.image.src}
|
|
1007
|
-
alt={item.image.alt}
|
|
1008
|
-
loading="lazy"
|
|
1009
|
-
/>
|
|
1002
|
+
<KitImage {...item.image} loading="lazy" />
|
|
1010
1003
|
</div>
|
|
1011
1004
|
<div>
|
|
1012
1005
|
<p className="m-order-item-name">
|
package/src/foundation.css
CHANGED
|
@@ -1227,6 +1227,22 @@
|
|
|
1227
1227
|
font-size: 12px;
|
|
1228
1228
|
font-weight: var(--m-weight-bold);
|
|
1229
1229
|
}
|
|
1230
|
+
/* A data-driven image that failed (KitImage, image.tsx): a placeholder that
|
|
1231
|
+
fills the container's reserved box. */
|
|
1232
|
+
.m-image-fallback {
|
|
1233
|
+
display: grid;
|
|
1234
|
+
place-items: center;
|
|
1235
|
+
width: 100%;
|
|
1236
|
+
height: 100%;
|
|
1237
|
+
/* Containers sized by aspect-ratio have no definite height to fill. */
|
|
1238
|
+
aspect-ratio: inherit;
|
|
1239
|
+
color: var(--m-muted);
|
|
1240
|
+
--m-icon-size: 28px;
|
|
1241
|
+
}
|
|
1242
|
+
.m-image-fallback svg {
|
|
1243
|
+
width: var(--m-icon-size);
|
|
1244
|
+
height: var(--m-icon-size);
|
|
1245
|
+
}
|
|
1230
1246
|
.m-avatar img {
|
|
1231
1247
|
width: 100%;
|
|
1232
1248
|
height: 100%;
|
package/src/icons.tsx
CHANGED
|
@@ -235,3 +235,14 @@ export function Circle() {
|
|
|
235
235
|
</Icon>
|
|
236
236
|
);
|
|
237
237
|
}
|
|
238
|
+
|
|
239
|
+
/** A picture frame, for an image that failed to load. */
|
|
240
|
+
export function ImageMissing({ className }: { className?: string }) {
|
|
241
|
+
return (
|
|
242
|
+
<Icon className={className} stroke="currentColor" strokeWidth="1.5">
|
|
243
|
+
<rect x="2.75" y="3.75" width="14.5" height="12.5" rx="2" />
|
|
244
|
+
<circle cx="7.25" cy="8" r="1.5" />
|
|
245
|
+
<path d="m3 14.5 4.25-4 3 2.75 2.5-2.25 4.25 3.75" />
|
|
246
|
+
</Icon>
|
|
247
|
+
);
|
|
248
|
+
}
|
package/src/image.tsx
ADDED
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Images the kit renders from data (covers, product photos, avatars, logos),
|
|
2
|
+
// with a one-shot fallback when the image fails. Internal: not exported.
|
|
3
|
+
import { useLayoutEffect, useRef, useState, type ReactNode } from "react";
|
|
4
|
+
import { ImageMissing } from "./icons.js";
|
|
5
|
+
|
|
6
|
+
/** Optional fallbacks on an image a component renders from data. */
|
|
7
|
+
export interface ImageFallback {
|
|
8
|
+
/** Shown once if `src` fails or is empty. Not retried if it fails too. */
|
|
9
|
+
fallbackSrc?: string;
|
|
10
|
+
/**
|
|
11
|
+
* Shown when every image fails, in the image's reserved box, instead of the
|
|
12
|
+
* default placeholder icon. It is visual only: the image's `alt` names it.
|
|
13
|
+
*/
|
|
14
|
+
fallback?: ReactNode;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Which source to show: `src`, then `fallbackSrc` once, then none. Each step
|
|
19
|
+
* happens at most once per `src`, so a failing fallback can't loop, and a new
|
|
20
|
+
* `src` starts over. An error that fired before hydration attached `onError`
|
|
21
|
+
* is caught on mount from the image's own state.
|
|
22
|
+
*/
|
|
23
|
+
export function useImageFallback(src: string, fallbackSrc?: string) {
|
|
24
|
+
const [failed, setFailed] = useState<{ src: string; stage: 1 | 2 } | null>(
|
|
25
|
+
null,
|
|
26
|
+
);
|
|
27
|
+
const second = fallbackSrc && fallbackSrc !== src ? fallbackSrc : undefined;
|
|
28
|
+
let stage = failed?.src === src ? failed.stage : 0;
|
|
29
|
+
if (stage === 0 && !src) stage = second ? 1 : 2;
|
|
30
|
+
if (stage === 1 && !second) stage = 2;
|
|
31
|
+
const current = stage === 0 ? src : stage === 1 ? second : undefined;
|
|
32
|
+
const fail = () => setFailed({ src, stage: stage === 0 && second ? 1 : 2 });
|
|
33
|
+
const ref = useRef<HTMLImageElement>(null);
|
|
34
|
+
useLayoutEffect(() => {
|
|
35
|
+
const img = ref.current;
|
|
36
|
+
if (img?.complete && img.naturalWidth === 0 && img.getAttribute("src"))
|
|
37
|
+
fail();
|
|
38
|
+
// `fail` reads this render's stage; re-run only when the source changes.
|
|
39
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
40
|
+
}, [current]);
|
|
41
|
+
return { current, ref, onError: fail };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* An image with the kit's fallback: `fallbackSrc` once, then `fallback` or a
|
|
46
|
+
* placeholder icon in the same reserved box (the container sets the size), so
|
|
47
|
+
* nothing shifts. The placeholder carries the image's accessible name.
|
|
48
|
+
*/
|
|
49
|
+
export function KitImage({
|
|
50
|
+
src,
|
|
51
|
+
alt,
|
|
52
|
+
fallbackSrc,
|
|
53
|
+
fallback,
|
|
54
|
+
loading,
|
|
55
|
+
}: ImageFallback & {
|
|
56
|
+
src: string;
|
|
57
|
+
alt: string;
|
|
58
|
+
loading?: "lazy";
|
|
59
|
+
}) {
|
|
60
|
+
const image = useImageFallback(src, fallbackSrc);
|
|
61
|
+
if (image.current)
|
|
62
|
+
return (
|
|
63
|
+
<img
|
|
64
|
+
ref={image.ref}
|
|
65
|
+
src={image.current}
|
|
66
|
+
alt={alt}
|
|
67
|
+
loading={loading}
|
|
68
|
+
onError={image.onError}
|
|
69
|
+
/>
|
|
70
|
+
);
|
|
71
|
+
return (
|
|
72
|
+
<span
|
|
73
|
+
className="m-image-fallback"
|
|
74
|
+
{...(alt ? { role: "img", "aria-label": alt } : { "aria-hidden": true })}
|
|
75
|
+
>
|
|
76
|
+
{fallback ? <span aria-hidden="true">{fallback}</span> : <ImageMissing />}
|
|
77
|
+
</span>
|
|
78
|
+
);
|
|
79
|
+
}
|
package/src/marketing.tsx
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { useImageFallback } from "./image.js";
|
|
1
2
|
import {
|
|
2
3
|
IconLinks,
|
|
3
4
|
KitLink,
|
|
@@ -545,6 +546,15 @@ export function Testimonial({
|
|
|
545
546
|
</figure>
|
|
546
547
|
);
|
|
547
548
|
}
|
|
549
|
+
/** A logo, or its name as text when there is no image or it fails to load. */
|
|
550
|
+
function Logo({ name, image }: { name: string; image?: string }) {
|
|
551
|
+
const logo = useImageFallback(image ?? "");
|
|
552
|
+
return logo.current ? (
|
|
553
|
+
<img ref={logo.ref} src={logo.current} alt={name} onError={logo.onError} />
|
|
554
|
+
) : (
|
|
555
|
+
<span>{name}</span>
|
|
556
|
+
);
|
|
557
|
+
}
|
|
548
558
|
export function LogoCloud({
|
|
549
559
|
id,
|
|
550
560
|
className,
|
|
@@ -576,11 +586,7 @@ export function LogoCloud({
|
|
|
576
586
|
<ul>
|
|
577
587
|
{items.map((item) => (
|
|
578
588
|
<li key={item.name}>
|
|
579
|
-
{item.image
|
|
580
|
-
<img src={item.image} alt={item.name} />
|
|
581
|
-
) : (
|
|
582
|
-
<span>{item.name}</span>
|
|
583
|
-
)}
|
|
589
|
+
<Logo name={item.name} image={item.image} />
|
|
584
590
|
</li>
|
|
585
591
|
))}
|
|
586
592
|
</ul>
|