@ksojecki/purpose-ui 0.2.1 → 0.3.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.
@@ -0,0 +1,15 @@
1
+ export type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
2
+ export interface AvatarProps {
3
+ /** The person's name, used for both initials and the accessible name. */
4
+ name: string;
5
+ /** An optional image URL. Missing or failed images fall back to initials or a person icon. */
6
+ src?: string;
7
+ /** Frame size, from 24px (xs) to 96px (xl). Defaults to md (40px). */
8
+ size?: AvatarSize;
9
+ /** Hide the avatar from assistive technology when nearby text already names the person. */
10
+ decorative?: boolean;
11
+ /** Additional classes for the avatar frame. */
12
+ className?: string;
13
+ }
14
+ /** A round image of a person, with initials or a person icon when no image is available. */
15
+ export declare const Avatar: ({ name, src, size, decorative, className }: AvatarProps) => import("react").JSX.Element;
@@ -1,8 +1,9 @@
1
1
  /**
2
- * Tables and metrics.
2
+ * Avatars, tables and metrics.
3
3
  *
4
4
  * @module @ksojecki/purpose-ui/data
5
5
  */
6
+ export * from './Avatar';
6
7
  export * from './Table';
7
8
  export * from './DataTable';
8
9
  export * from './Metric';
@@ -1,85 +1,134 @@
1
1
  import { t as e } from "../classNames-x6JVYA2t.js";
2
- import { Fragment as t, jsx as n, jsxs as r } from "react/jsx-runtime";
3
- // src/data/Table.tsx
4
- var i = {
2
+ import { useCallback as t, useState as n } from "react";
3
+ import { Fragment as r, jsx as i, jsxs as a } from "react/jsx-runtime";
4
+ import { TbUser as o } from "react-icons/tb";
5
+ // src/internal/initials.ts
6
+ function s(e) {
7
+ let t = e.split(/\s+/u).flatMap((e) => e.match(/\p{L}/u) ?? []);
8
+ return [t[0], t.length > 1 ? t.at(-1) : void 0].map((e) => {
9
+ if (!e) return "";
10
+ let t = e.toLocaleUpperCase();
11
+ return [...t].length === 1 ? t : e;
12
+ }).join("");
13
+ }
14
+ // src/data/Avatar.tsx
15
+ var c = {
16
+ xs: "size-6 text-xs",
17
+ sm: "size-8 text-sm",
18
+ md: "size-10 text-base",
19
+ lg: "size-16 text-2xl",
20
+ xl: "size-24 text-4xl"
21
+ };
22
+ function l({ name: e, src: c }) {
23
+ let [l, u] = n("pending"), d = t((e) => {
24
+ e?.complete && u(e.naturalWidth > 0 ? "loaded" : "failed");
25
+ }, []), f = l === "loaded" ? "" : s(e);
26
+ return /* @__PURE__ */ a(r, { children: [c && l !== "failed" ? /* @__PURE__ */ i("img", {
27
+ alt: "",
28
+ className: "size-full object-cover",
29
+ hidden: l !== "loaded",
30
+ onError: () => u("failed"),
31
+ onLoad: () => u("loaded"),
32
+ ref: d,
33
+ src: c
34
+ }) : null, l === "loaded" ? null : /* @__PURE__ */ i("span", {
35
+ "aria-hidden": "true",
36
+ className: "flex size-full items-center justify-center bg-neutral font-semibold text-neutral-content",
37
+ children: f || /* @__PURE__ */ i(o, { className: "size-3/5" })
38
+ })] });
39
+ }
40
+ var u = ({ name: t, src: n, size: r = "md", decorative: a = !1, className: o }) => {
41
+ let s = a || !t.trim() ? { "aria-hidden": !0 } : {
42
+ role: "img",
43
+ "aria-label": t
44
+ };
45
+ return /* @__PURE__ */ i("span", {
46
+ ...s,
47
+ className: e("avatar shrink-0 overflow-hidden rounded-full", c[r], o),
48
+ children: /* @__PURE__ */ i(l, {
49
+ name: t,
50
+ src: n
51
+ }, n)
52
+ });
53
+ }, d = {
5
54
  xs: "table-xs",
6
55
  sm: "table-sm",
7
56
  md: "",
8
57
  lg: "table-lg"
9
58
  };
10
- function a({ tableSize: t = "sm", zebra: r = !1, wrapperClassName: a, className: o, children: s, label: c, ...l }) {
11
- return /* @__PURE__ */ n("div", {
12
- "aria-label": c,
13
- className: e("overflow-x-auto", a),
14
- role: c ? "region" : void 0,
15
- tabIndex: c ? 0 : void 0,
16
- children: /* @__PURE__ */ n("table", {
17
- ...l,
18
- className: e("table", i[t], r ? "table-zebra" : void 0, "w-full", o),
19
- children: s
59
+ function f({ tableSize: t = "sm", zebra: n = !1, wrapperClassName: r, className: a, children: o, label: s, ...c }) {
60
+ return /* @__PURE__ */ i("div", {
61
+ "aria-label": s,
62
+ className: e("overflow-x-auto", r),
63
+ role: s ? "region" : void 0,
64
+ tabIndex: s ? 0 : void 0,
65
+ children: /* @__PURE__ */ i("table", {
66
+ ...c,
67
+ className: e("table", d[t], n ? "table-zebra" : void 0, "w-full", a),
68
+ children: o
20
69
  })
21
70
  });
22
71
  }
23
72
  // src/data/DataTable.tsx
24
- var o = "whitespace-nowrap text-right tabular-nums", s = (e) => e.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").toLowerCase().replace(/^./, (e) => e.toUpperCase()), c = (e, t) => e.id ?? e.key ?? String(t);
25
- function l(e) {
73
+ var p = "whitespace-nowrap text-right tabular-nums", m = (e) => e.replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/[_-]+/g, " ").toLowerCase().replace(/^./, (e) => e.toUpperCase()), h = (e, t) => e.id ?? e.key ?? String(t);
74
+ function g(e) {
26
75
  return e[0] ? Object.keys(e[0]).map((e) => ({ key: e })) : [];
27
76
  }
28
- function u(e, t) {
77
+ function _(e, t) {
29
78
  if (e.render) return e.render(t);
30
79
  if (!e.key) return null;
31
80
  let n = t[e.key];
32
81
  return e.format ? e.format(n, t) : n == null ? "" : String(n);
33
82
  }
34
- function d({ rows: i, columns: d, getRowKey: f = (e, t) => e.id ?? t, empty: p, ...m }) {
35
- if (i.length === 0 && p !== void 0) return /* @__PURE__ */ n(t, { children: p });
36
- let h = (d ?? l(i)).filter((e) => !e.hidden);
37
- return /* @__PURE__ */ r(a, {
38
- ...m,
39
- children: [/* @__PURE__ */ n("thead", { children: /* @__PURE__ */ n("tr", { children: h.map((t, r) => /* @__PURE__ */ n("th", {
83
+ function v({ rows: t, columns: n, getRowKey: o = (e, t) => e.id ?? t, empty: s, ...c }) {
84
+ if (t.length === 0 && s !== void 0) return /* @__PURE__ */ i(r, { children: s });
85
+ let l = (n ?? g(t)).filter((e) => !e.hidden);
86
+ return /* @__PURE__ */ a(f, {
87
+ ...c,
88
+ children: [/* @__PURE__ */ i("thead", { children: /* @__PURE__ */ i("tr", { children: l.map((t, n) => /* @__PURE__ */ i("th", {
40
89
  className: e(t.kind === "number" ? "text-right" : void 0, t.className),
41
- children: t.srOnlyHeader ? /* @__PURE__ */ n("span", {
90
+ children: t.srOnlyHeader ? /* @__PURE__ */ i("span", {
42
91
  className: "sr-only",
43
92
  children: t.header
44
- }) : t.header ?? (t.key ? s(t.key) : null)
45
- }, c(t, r))) }) }), /* @__PURE__ */ n("tbody", { children: i.map((t, r) => /* @__PURE__ */ n("tr", { children: h.map((r, i) => /* @__PURE__ */ n("td", {
46
- className: e(r.kind === "number" ? o : void 0, r.className),
47
- children: u(r, t)
48
- }, c(r, i))) }, f(t, r))) })]
93
+ }) : t.header ?? (t.key ? m(t.key) : null)
94
+ }, h(t, n))) }) }), /* @__PURE__ */ i("tbody", { children: t.map((t, n) => /* @__PURE__ */ i("tr", { children: l.map((n, r) => /* @__PURE__ */ i("td", {
95
+ className: e(n.kind === "number" ? p : void 0, n.className),
96
+ children: _(n, t)
97
+ }, h(n, r))) }, o(t, n))) })]
49
98
  });
50
99
  }
51
100
  // src/data/Metric.tsx
52
- var f = {
101
+ var y = {
53
102
  default: void 0,
54
103
  boxed: "rounded-box border border-base-300 bg-base-100"
55
- }, p = {
104
+ }, b = {
56
105
  info: "text-info",
57
106
  success: "text-success",
58
107
  warning: "text-warning",
59
108
  error: "text-error"
60
- }, m = ({ children: t, className: r, responsive: i = !1, vertical: a = !1 }) => /* @__PURE__ */ n("div", {
61
- className: e("stats", i ? "stats-vertical sm:stats-horizontal" : a ? "stats-vertical" : void 0, r),
109
+ }, x = ({ children: t, className: n, responsive: r = !1, vertical: a = !1 }) => /* @__PURE__ */ i("div", {
110
+ className: e("stats", r ? "stats-vertical sm:stats-horizontal" : a ? "stats-vertical" : void 0, n),
62
111
  children: t
63
- }), h = ({ appearance: t = "default", className: i, description: a, figure: o, label: s, tone: c, value: l, valueClassName: u, ...d }) => /* @__PURE__ */ r("div", {
112
+ }), S = ({ appearance: t = "default", className: n, description: r, figure: o, label: s, tone: c, value: l, valueClassName: u, ...d }) => /* @__PURE__ */ a("div", {
64
113
  ...d,
65
- className: e("stat", f[t], i),
114
+ className: e("stat", y[t], n),
66
115
  children: [
67
- o ? /* @__PURE__ */ n("div", {
116
+ o ? /* @__PURE__ */ i("div", {
68
117
  className: "stat-figure",
69
118
  children: o
70
119
  }) : null,
71
- /* @__PURE__ */ n("div", {
120
+ /* @__PURE__ */ i("div", {
72
121
  className: "stat-title",
73
122
  children: s
74
123
  }),
75
- /* @__PURE__ */ n("div", {
76
- className: e("stat-value", c ? p[c] : void 0, u),
124
+ /* @__PURE__ */ i("div", {
125
+ className: e("stat-value", c ? b[c] : void 0, u),
77
126
  children: l
78
127
  }),
79
- a ? /* @__PURE__ */ n("div", {
128
+ r ? /* @__PURE__ */ i("div", {
80
129
  className: "stat-desc",
81
- children: a
130
+ children: r
82
131
  }) : null
83
132
  ]
84
133
  });
85
- export { d as DataTable, h as Metric, m as MetricGroup, a as Table };
134
+ export { u as Avatar, v as DataTable, S as Metric, x as MetricGroup, f as Table };
@@ -0,0 +1 @@
1
+ export declare function initials(name: string): string;
package/package.json CHANGED
@@ -1,7 +1,19 @@
1
1
  {
2
2
  "name": "@ksojecki/purpose-ui",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "description": "React UI components and daisyUI themes with semantic purpose props.",
5
+ "keywords": [
6
+ "components",
7
+ "daisyui",
8
+ "design-system",
9
+ "react",
10
+ "tailwindcss",
11
+ "ui"
12
+ ],
13
+ "homepage": "https://sojecki.pl/ui/",
14
+ "bugs": {
15
+ "url": "https://github.com/ksojecki/purpose-ui/issues"
16
+ },
5
17
  "license": "MIT",
6
18
  "repository": {
7
19
  "type": "git",