wings-plugin-ui 0.4.0 → 0.5.0

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/README.md CHANGED
@@ -86,6 +86,10 @@ message.
86
86
  | `Combobox` | `label`, `value`, `onInput`, `options: { value, label, detail? }[]`, `onPick`, `onEnter`, `onKeyDown`, `freeText`, `openOnFocus`, `open`, `filter`, `empty` | A text field with suggestions under it: arrows, Enter, Escape and Tab, and a press outside closes it. With `freeText` it keeps what you type; otherwise it picks one of `options`. `openOnFocus={false}` for a page that puts focus back into it after a render. Without `freeText` the picked label is selected when the field gets focus and after a pick, so typing replaces it. `onEnter(text)` runs on Enter when no option is highlighted, with the typed text, and stops the Enter from submitting a form around it. An `onKeyDown` you pass runs first; `e.preventDefault()` in it skips the combobox's own keys. ArrowDown on a closed combobox opens it and highlights the first option, as in the [WAI-ARIA APG combobox pattern](https://www.w3.org/WAI/ARIA/apg/patterns/combobox/). `open="whileText"` keeps the list shown for as long as the field has text and an option matches, even after Escape, Tab or a press outside (those only clear the highlighted option) and it closes when the text is emptied or an option is picked; `aria-expanded` follows whether the list is shown. Accessibility caveat: the APG pattern has Escape dismiss the popup and treats it as shown only while the user is working in the combobox, so this mode departs from it. Use it only where the suggestions are the page's main content, such as a people search that is useful to keep in view, and not for a field where a stray list would cover other controls |
87
87
  | `Menu` | `label`, `items: { id, label, onSelect, tone? }[]`, `align`, `variant`, `size` | A button that opens a menu: arrows, Home, End, Enter, Escape |
88
88
  | `Disclosure` | `summary` | More behind a line that opens it |
89
+ | `Time`, `ago` | `Time`: `iso`, `prefix`; `ago(iso)` gives the text | A moment as how long ago it was ("5 min ago", "3 h ago", "2 d ago", then the date) in a `time` element with the exact date and time on hover |
90
+ | `Summary`, `SummaryChip` | `SummaryChip`: `tone` (`info`, `success`, `warn`, `danger`), `onClick` | A row of small facts under a page's header, like "2 approved" or "Priority 1"; with `onClick` a chip is a button that goes to where the fact comes from |
91
+ | `Skeletons`, `Skeleton` | `Skeletons`: `label`; `Skeleton`: `width`, `height` | Blocks that stand in for loading content, announced once as `label` with `aria-busy`; they shimmer unless the user asked for less motion |
92
+ | `Timeline`, `TimelineCard`, `TimelineNote` | `Timeline`: `label`; `TimelineCard`: `author`, `at`, `tag`, `actions`, `quiet`, `clamp`; `TimelineNote`: `author`, `at` | A conversation or activity feed: a card per entry with the author's `Avatar`, name, time, an optional tag and actions, and the body as children (`Markdown` or your own); `quiet` for bots and the system; `clamp` cuts a long body with a "Show more" button that only appears when something was cut; a `TimelineNote` is a one-line entry like "Ada moved it to Active" |
89
93
  | `Markdown` | `source`, `inline` | Markdown as React: headings, lists with read-only task checkboxes, GFM tables, fenced code, quotes, rules, bold, italics, strikethrough, links and bare https URLs, images, and emoji shortcodes (`:white_check_mark:`, `:x:`, `:bulb:`: the GitHub and Slack names, flags left out; unknown names, and anything inside code, stay as typed). No HTML is ever parsed; only `https:` links open (through `wings.openUrl`, so the manifest needs `permissions.openUrl` with an `https://` prefix) and images load only from `https:` or `data:image/` png, jpeg, gif or webp URLs up to 8,000 characters (`MAX_DATA_IMAGE`); an `https:` image shows as a "Load image from <host>" button and loads only when clicked (no option to turn that off), because the text may come from an agent and the URL could carry data out, and a `data:` image shows at once; `[![alt](img)](url)` is a link with the alt as its text. `inline` renders just the inline parts in a span. Memoized on `source` |
90
94
 
91
95
  Every component passes other props, like `id`, `title`, `className`, `onClick` and `aria-*`, to its element.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wings-plugin-ui",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "React components and the stylesheet for Wings plugin pages, on Base UI like the Wings app's shadcn/ui components.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/plugin-ui.css CHANGED
@@ -1687,4 +1687,194 @@ span.w-md {
1687
1687
  .w-md-table [data-align="right"] {
1688
1688
  text-align: right;
1689
1689
  }
1690
+
1691
+ /* Activity: a summary row, skeletons and a timeline, shared by pages like a pull request and a work item. */
1692
+ .w-summary {
1693
+ display: flex;
1694
+ flex-wrap: wrap;
1695
+ align-items: center;
1696
+ gap: 6px;
1697
+ }
1698
+ .w-summary-chip {
1699
+ display: inline-flex;
1700
+ align-items: center;
1701
+ gap: 6px;
1702
+ max-width: 100%;
1703
+ height: 26px;
1704
+ padding: 0 10px;
1705
+ border: 1px solid var(--wings-hairline-strong);
1706
+ border-radius: 999px;
1707
+ background: var(--wings-surface);
1708
+ color: var(--wings-fg);
1709
+ font-size: 12px;
1710
+ font-weight: 500;
1711
+ white-space: nowrap;
1712
+ }
1713
+ button.w-summary-chip {
1714
+ cursor: pointer;
1715
+ transition: background-color 150ms;
1716
+ }
1717
+ button.w-summary-chip:hover {
1718
+ background: var(--wings-hover);
1719
+ }
1720
+ button.w-summary-chip:focus-visible {
1721
+ outline: 2px solid var(--wings-ring);
1722
+ outline-offset: 2px;
1723
+ }
1724
+ .w-summary-chip[data-tone="info"] {
1725
+ --w-tone: var(--wings-info);
1726
+ }
1727
+ .w-summary-chip[data-tone="success"] {
1728
+ --w-tone: var(--wings-success);
1729
+ }
1730
+ .w-summary-chip[data-tone="warn"] {
1731
+ --w-tone: var(--wings-warning);
1732
+ }
1733
+ .w-summary-chip[data-tone="danger"] {
1734
+ --w-tone: var(--wings-danger);
1735
+ }
1736
+ .w-summary-chip[data-tone] {
1737
+ border-color: color-mix(in srgb, var(--w-tone) 40%, transparent);
1738
+ color: var(--w-tone);
1739
+ }
1740
+
1741
+ .w-visually-hidden {
1742
+ position: absolute;
1743
+ width: 1px;
1744
+ height: 1px;
1745
+ overflow: hidden;
1746
+ clip-path: inset(50%);
1747
+ white-space: nowrap;
1748
+ }
1749
+ .w-skeletons {
1750
+ display: flex;
1751
+ flex-direction: column;
1752
+ gap: 12px;
1753
+ }
1754
+ .w-skeleton {
1755
+ display: block;
1756
+ width: var(--w-width, 100%);
1757
+ height: var(--w-height, 14px);
1758
+ border-radius: var(--wings-radius);
1759
+ background: linear-gradient(90deg, var(--wings-surface), var(--wings-hover), var(--wings-surface)) 0 0 / 200% 100%;
1760
+ animation: w-shimmer 1.4s ease-in-out infinite;
1761
+ }
1762
+ @keyframes w-shimmer {
1763
+ to {
1764
+ background-position: -200% 0;
1765
+ }
1766
+ }
1767
+ @media (prefers-reduced-motion: reduce) {
1768
+ .w-skeleton {
1769
+ animation: none;
1770
+ }
1771
+ }
1772
+
1773
+ .w-timeline {
1774
+ display: flex;
1775
+ flex-direction: column;
1776
+ gap: 10px;
1777
+ min-width: 0;
1778
+ margin: 0;
1779
+ padding: 0;
1780
+ list-style: none;
1781
+ }
1782
+ .w-timeline-item {
1783
+ min-width: 0;
1784
+ content-visibility: auto;
1785
+ contain-intrinsic-size: auto 96px;
1786
+ }
1787
+ .w-timeline-card {
1788
+ display: flex;
1789
+ flex-direction: column;
1790
+ gap: 10px;
1791
+ min-width: 0;
1792
+ padding: 12px 14px;
1793
+ border: 1px solid var(--wings-hairline);
1794
+ border-radius: var(--wings-radius);
1795
+ background: var(--wings-surface);
1796
+ }
1797
+ .w-timeline-item[data-quiet] > .w-timeline-card {
1798
+ background: transparent;
1799
+ font-size: 12px;
1800
+ }
1801
+ .w-timeline-head {
1802
+ display: flex;
1803
+ flex-wrap: wrap;
1804
+ align-items: center;
1805
+ gap: 4px 8px;
1806
+ min-width: 0;
1807
+ }
1808
+ .w-timeline-author {
1809
+ font-weight: 600;
1810
+ overflow-wrap: anywhere;
1811
+ }
1812
+ .w-timeline-tag {
1813
+ padding: 0 6px;
1814
+ border: 1px solid var(--wings-hairline-strong);
1815
+ border-radius: 999px;
1816
+ color: var(--wings-muted);
1817
+ font-size: 11px;
1818
+ line-height: 16px;
1819
+ }
1820
+ .w-timeline-time {
1821
+ color: var(--wings-muted);
1822
+ font-size: 12px;
1823
+ }
1824
+ .w-timeline-actions {
1825
+ display: inline-flex;
1826
+ align-items: center;
1827
+ gap: 6px;
1828
+ margin-left: auto;
1829
+ }
1830
+ .w-timeline-note {
1831
+ display: flex;
1832
+ align-items: center;
1833
+ gap: 8px;
1834
+ padding: 0 14px;
1835
+ color: var(--wings-muted);
1836
+ font-size: 12px;
1837
+ }
1838
+ .w-timeline-note-text {
1839
+ min-width: 0;
1840
+ overflow-wrap: anywhere;
1841
+ }
1842
+ .w-timeline-note-text strong {
1843
+ color: var(--wings-fg);
1844
+ font-weight: 600;
1845
+ }
1846
+ .w-clamp {
1847
+ display: flex;
1848
+ flex-direction: column;
1849
+ align-items: flex-start;
1850
+ gap: 4px;
1851
+ min-width: 0;
1852
+ }
1853
+ .w-clamp-box {
1854
+ width: 100%;
1855
+ min-width: 0;
1856
+ }
1857
+ .w-clamp-box[data-clamped] {
1858
+ max-height: 11em;
1859
+ overflow: hidden;
1860
+ }
1861
+ .w-clamp-box[data-cut] {
1862
+ mask-image: linear-gradient(to bottom, #000 70%, transparent);
1863
+ }
1864
+ .w-clamp-toggle {
1865
+ padding: 2px 6px;
1866
+ border: 0;
1867
+ border-radius: 6px;
1868
+ background: transparent;
1869
+ color: var(--wings-info);
1870
+ font-size: 12px;
1871
+ cursor: pointer;
1872
+ }
1873
+ .w-clamp-toggle:hover {
1874
+ background: var(--wings-hover);
1875
+ }
1876
+ .w-clamp-toggle:focus-visible {
1877
+ outline: 2px solid var(--wings-ring);
1878
+ outline-offset: 2px;
1879
+ }
1690
1880
  }
package/ui.d.ts CHANGED
@@ -354,3 +354,28 @@ export function Disclosure(
354
354
  export function Markdown(props: Omit<Props<"div">, "children"> & { source: string; inline?: boolean }): ReactElement;
355
355
  /** The longest `data:image/` URL, in characters, that `Markdown` shows. */
356
356
  export const MAX_DATA_IMAGE: number;
357
+
358
+ // ---------- activity: times, a summary row, skeletons and a timeline ----------
359
+
360
+ /** "just now", "5 min ago", "3 h ago", "2 d ago", then the date; "" when `iso` isn't a date. `now` is for tests. */
361
+ export function ago(iso: string, now?: number): string;
362
+ /** A moment as a `time` element: how long ago (after `prefix`), the exact date and time as its title. Renders nothing when `iso` isn't a date. */
363
+ export function Time(props: Omit<Props<"time">, "dateTime" | "children"> & { iso: string; prefix?: ReactNode; now?: number }): ReactElement | null;
364
+ /** A row of `SummaryChip`s under a page's header. */
365
+ export function Summary(props: Props<"div">): ReactElement;
366
+ /** One fact in a `Summary`: a button when it has `onClick`, text otherwise. `tone` colours it. */
367
+ export function SummaryChip(props: Omit<Props<"span">, "onClick"> & { tone?: "info" | "success" | "warn" | "danger"; onClick?: Props<"button">["onClick"]; type?: "button" | "submit" }): ReactElement;
368
+ /** A block that stands in for loading content, `width` and `height` in px or any CSS length. Decoration: wrap a group in `Skeletons`. */
369
+ export function Skeleton(props: Props<"span"> & { width?: number | string; height?: number | string }): ReactElement;
370
+ /** A group of `Skeleton`s announced once as `label`, with `aria-busy`. */
371
+ export function Skeletons(props: Omit<Props<"div">, "role" | "aria-label"> & { label: string }): ReactElement;
372
+ /** An ordered list of `TimelineCard`s and `TimelineNote`s, named `label`. */
373
+ export function Timeline(props: Props<"ol"> & { label: string }): ReactElement;
374
+ /**
375
+ * An entry of a `Timeline`: the `Avatar`, name and time of `author` and `at` (ISO), an optional `tag` and `actions`
376
+ * at the right of that line, and `children` as the body. `quiet` for what a bot or the system wrote; `clamp` cuts a long
377
+ * body until "Show more".
378
+ */
379
+ export function TimelineCard(props: Omit<Props<"li">, "children"> & { author: string; at?: string; tag?: ReactNode; actions?: ReactNode; quiet?: boolean; clamp?: boolean; children?: ReactNode }): ReactElement;
380
+ /** A quiet one-line entry of a `Timeline`: a small avatar, the author in bold, `children`, then the time. */
381
+ export function TimelineNote(props: Omit<Props<"li">, "children"> & { author: string; at?: string; children?: ReactNode }): ReactElement;
package/ui.js CHANGED
@@ -903,3 +903,128 @@ export const Markdown = memo(function Markdown({ source, inline, className, ...r
903
903
  }),
904
904
  );
905
905
  });
906
+
907
+ // ---------- activity: times, a summary row, skeletons and a timeline ----------
908
+
909
+ /** "just now", "5 min ago", "3 h ago", "2 d ago", then the date. "" for something that isn't a date. */
910
+ export function ago(iso, now = Date.now()) {
911
+ const t = Date.parse(iso);
912
+ if (Number.isNaN(t)) return "";
913
+ const minutes = Math.max(0, Math.round((now - t) / 60_000));
914
+ if (minutes < 1) return "just now";
915
+ if (minutes < 60) return `${minutes} min ago`;
916
+ if (minutes < 1440) return `${Math.round(minutes / 60)} h ago`;
917
+ if (minutes < 43_200) return `${Math.round(minutes / 1440)} d ago`;
918
+ return new Date(t).toLocaleDateString(undefined, { year: "numeric", month: "short", day: "numeric" });
919
+ }
920
+
921
+ /** A moment as a `time` element: how long ago, with the exact date and time on hover. Nothing when `iso` isn't a date. */
922
+ export function Time({ iso, prefix, now, className, ...rest }) {
923
+ const text = ago(iso, now);
924
+ if (!text) return null;
925
+ return h("time", { title: new Date(iso).toLocaleString(), ...rest, className, dateTime: iso }, prefix, text);
926
+ }
927
+
928
+ /** A row of `SummaryChip`s under a page's header: the facts about the thing at a glance. */
929
+ export function Summary({ className, ...rest }) {
930
+ return h("div", { ...rest, className: cx("w-summary", className) });
931
+ }
932
+
933
+ /** One fact in a `Summary`. With `onClick` it's a button (it takes you to where the fact comes from); without, plain text. */
934
+ export function SummaryChip({ tone, className, onClick, type = "button", ...rest }) {
935
+ const props = { ...rest, className: cx("w-summary-chip", className), "data-tone": tone };
936
+ return onClick ? h("button", { ...props, type, onClick }) : h("span", props);
937
+ }
938
+
939
+ /** A grey block that stands in for content that is still loading, sized by `width` and `height` (CSS lengths or px). It shimmers unless the user asked for less motion. */
940
+ export function Skeleton({ width, height, className, style, ...rest }) {
941
+ const size = (v) => (typeof v === "number" ? `${v}px` : v);
942
+ return h("span", {
943
+ ...rest,
944
+ className: cx("w-skeleton", className),
945
+ style: { ...style, ...(width === undefined ? null : { "--w-width": size(width) }), ...(height === undefined ? null : { "--w-height": size(height) }) },
946
+ "aria-hidden": true,
947
+ });
948
+ }
949
+
950
+ /** Skeletons that stand in for a section, announced once as `label` and `aria-busy`. */
951
+ export function Skeletons({ label, children, className, ...rest }) {
952
+ // The label is text inside the region, which a live region announces; an aria-label alone isn't.
953
+ return h("div", { ...rest, className: cx("w-skeletons", className), role: "status", "aria-busy": true }, h("span", { className: "w-visually-hidden" }, label), children);
954
+ }
955
+
956
+ /** A conversation or an activity feed: an ordered list of `TimelineCard`s and `TimelineNote`s. */
957
+ export function Timeline({ label, className, ...rest }) {
958
+ return h("ol", { ...rest, className: cx("w-timeline", className), "aria-label": label });
959
+ }
960
+
961
+ const FOCUSABLE = "a[href], button, input, select, textarea, summary, [tabindex]";
962
+
963
+ /** Cuts `children` after a few lines until the reader asks for the rest; focusable things below the cut are inert meanwhile. The button only shows when something was cut. */
964
+ function Clamped({ children }) {
965
+ const box = useRef(null);
966
+ const [more, setMore] = useState(false);
967
+ const [cut, setCut] = useState(false);
968
+ useLayoutEffect(() => {
969
+ const el = box.current;
970
+ if (!el) return;
971
+ if (more) {
972
+ for (const f of el.querySelectorAll(FOCUSABLE)) f.inert = false;
973
+ return;
974
+ }
975
+ const measure = () => {
976
+ setCut(el.scrollHeight > el.clientHeight + 1);
977
+ // What the cut hides can't be reached by keyboard or screen reader until "Show more".
978
+ const bottom = el.getBoundingClientRect().bottom;
979
+ for (const f of el.querySelectorAll(FOCUSABLE)) f.inert = f.getBoundingClientRect().top >= bottom - 1;
980
+ };
981
+ measure();
982
+ if (typeof ResizeObserver === "undefined") return;
983
+ const watch = new ResizeObserver(measure);
984
+ watch.observe(el);
985
+ return () => watch.disconnect();
986
+ }, [more]);
987
+ return h(
988
+ "div",
989
+ { className: "w-clamp" },
990
+ h("div", { ref: box, className: "w-clamp-box", "data-clamped": more ? undefined : "", "data-cut": cut && !more ? "" : undefined }, children),
991
+ cut || more ? h("button", { type: "button", className: "w-clamp-toggle", "aria-expanded": more, onClick: () => setMore(!more) }, more ? "Show less" : "Show more") : null,
992
+ );
993
+ }
994
+
995
+ /**
996
+ * One entry of a `Timeline`, a card: the author's `Avatar`, name and when, a `tag` (like "Author") and `actions` on the
997
+ * right, and `children` as the body. `quiet` draws it without a fill, for what a bot or the system wrote. `clamp` cuts
998
+ * a long body until "Show more" is pressed.
999
+ */
1000
+ export function TimelineCard({ author, at, tag, actions, quiet, clamp, children, className, ...rest }) {
1001
+ return h(
1002
+ "li",
1003
+ { ...rest, className: cx("w-timeline-item", className), "data-quiet": quiet ? "" : undefined },
1004
+ h(
1005
+ "article",
1006
+ { className: "w-timeline-card", "aria-label": `By ${author}` },
1007
+ h(
1008
+ "div",
1009
+ { className: "w-timeline-head" },
1010
+ h(Avatar, { name: author }),
1011
+ h("strong", { className: "w-timeline-author" }, author),
1012
+ tag ? h("span", { className: "w-timeline-tag" }, tag) : null,
1013
+ h(Time, { iso: at, className: "w-timeline-time" }),
1014
+ actions ? h("span", { className: "w-timeline-actions" }, actions) : null,
1015
+ ),
1016
+ clamp ? h(Clamped, null, children) : children,
1017
+ ),
1018
+ );
1019
+ }
1020
+
1021
+ /** A quiet one-line entry of a `Timeline`, like "Ada moved it to Active": a small avatar, then `children`, then when. */
1022
+ export function TimelineNote({ author, at, children, className, ...rest }) {
1023
+ return h(
1024
+ "li",
1025
+ { ...rest, className: cx("w-timeline-item w-timeline-note", className) },
1026
+ h(Avatar, { name: author, size: "small" }),
1027
+ h("span", { className: "w-timeline-note-text" }, h("strong", null, author), " ", children),
1028
+ h(Time, { iso: at, className: "w-timeline-time" }),
1029
+ );
1030
+ }