@kolking/react-ui 1.9.0 → 1.9.2

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.
@@ -13,14 +13,14 @@ const b = (a, e) => /* @__PURE__ */ m.createElement("svg", { xmlns: "http://www.
13
13
  size: a = 50,
14
14
  name: e,
15
15
  email: o,
16
- src: n,
16
+ src: c,
17
17
  colorize: v,
18
- className: d,
19
- style: u,
18
+ className: u,
19
+ style: d,
20
20
  children: g,
21
21
  ...f
22
22
  }) => {
23
- const t = e?.trim(), p = v && t ? k(t) : void 0, s = x(() => n || (o ? M(a, o) : void 0), [n, a, o]), [c, l] = A(s);
23
+ const t = e?.trim(), p = v && t ? k(t) : void 0, s = x(() => c || (o ? M(a, o) : void 0), [c, a, o]), [n, l] = A(s);
24
24
  N(() => {
25
25
  l(s);
26
26
  }, [s]);
@@ -28,23 +28,23 @@ const b = (a, e) => /* @__PURE__ */ m.createElement("svg", { xmlns: "http://www.
28
28
  l(void 0);
29
29
  }, []);
30
30
  return /* @__PURE__ */ _(
31
- "div",
31
+ "figure",
32
32
  {
33
33
  ...f,
34
34
  "data-avatar": !0,
35
- className: h(r.avatar, d),
36
- style: { ...u, ...C({ size: a, backgroundColor: p }) },
35
+ className: h(r.avatar, u),
36
+ style: { ...d, ...C({ size: a, backgroundColor: p }) },
37
37
  children: [
38
- c ? /* @__PURE__ */ i(
38
+ n ? /* @__PURE__ */ i(
39
39
  "img",
40
40
  {
41
41
  "data-avatar-image": !0,
42
42
  className: r.image,
43
- src: c,
43
+ src: n,
44
44
  alt: t ?? "",
45
45
  onError: w
46
46
  }
47
- ) : t ? /* @__PURE__ */ i("span", { "data-avatar-initials": !0, className: r.initials, children: R(t) }) : /* @__PURE__ */ i(j, { "aria-hidden": !0, "data-avatar-default": !0, className: r.default }),
47
+ ) : t ? /* @__PURE__ */ i("figcaption", { "data-avatar-initials": !0, className: r.initials, children: R(t) }) : /* @__PURE__ */ i(j, { "aria-hidden": !0, "data-avatar-default": !0, className: r.default }),
48
48
  g
49
49
  ]
50
50
  }
@@ -1,22 +1,21 @@
1
- import { md5 as r } from "js-md5";
2
- function n(i, t) {
3
- const e = r(t.toLowerCase().trim()), o = window.devicePixelRatio * i;
4
- return `https://www.gravatar.com/avatar/${e}?s=${o}&d=404`;
1
+ import { md5 as o } from "js-md5";
2
+ function l(e, t) {
3
+ const i = o(t.toLowerCase().trim()), r = window.devicePixelRatio || 1, n = Math.round(r * e);
4
+ return `https://www.gravatar.com/avatar/${i}?s=${n}&d=404`;
5
5
  }
6
- function l(i) {
7
- const t = i.trim().split(/\s+/gu) || [];
8
- let e = [...t.shift() || ""][0];
9
- return t.length > 0 && (e += [...t.pop() || ""][0]), e.toUpperCase();
6
+ function s(e) {
7
+ const t = e.trim().split(/\s+/gu).filter(Boolean);
8
+ return t.length === 0 ? "" : ([...t[0]][0] + (t.length > 1 ? [...t[t.length - 1]][0] : "")).toUpperCase();
10
9
  }
11
- function s(i) {
10
+ function h(e) {
12
11
  let t = 0;
13
- if (i.length > 0)
14
- for (let e = 0; e < i.length; e += 1)
15
- t = i.charCodeAt(e) + ((t << 5) - t), t &= t;
16
- return `hsl(${t % 360}, 75%, 50%)`;
12
+ if (e.length > 0)
13
+ for (let r = 0; r < e.length; r += 1)
14
+ t = e.charCodeAt(r) + ((t << 5) - t), t &= t;
15
+ return `hsl(${(t % 360 + 360) % 360}, 75%, 50%)`;
17
16
  }
18
17
  export {
19
- n as getGravatarUri,
20
- l as getInitials,
21
- s as getStringColor
18
+ l as getGravatarUri,
19
+ s as getInitials,
20
+ h as getStringColor
22
21
  };
@@ -2,7 +2,7 @@ import { jsx as h } from "react/jsx-runtime";
2
2
  import { useRef as _, useLayoutEffect as w, useEffect as l } from "react";
3
3
  import E from "classnames";
4
4
  import { wrapNode as P, cssProps as H } from "../../utils/helpers.js";
5
- const M = "Badge_badge_-mEE7", k = "Badge_appear_LbxbS", x = "Badge_accent_BIYve", L = "Badge_gray_7jA-J", v = "Badge_brown_x1GS7", I = "Badge_red_zPgCR", R = "Badge_orange_EoLmF", S = "Badge_yellow_qvbb6", X = "Badge_green_XX-1c", j = "Badge_teal_VHoFK", C = "Badge_cyan_1ksBn", F = "Badge_blue_YulfT", K = "Badge_indigo_2KXUy", N = "Badge_purple_o55fQ", O = "Badge_pink_T5H--", d = {
5
+ const M = "Badge_badge_-mEE7", k = "Badge_appear_LbxbS", x = "Badge_accent_BIYve", L = "Badge_gray_7jA-J", v = "Badge_brown_x1GS7", I = "Badge_red_zPgCR", R = "Badge_orange_EoLmF", S = "Badge_yellow_qvbb6", X = "Badge_green_XX-1c", j = "Badge_teal_VHoFK", C = "Badge_cyan_1ksBn", F = "Badge_blue_YulfT", K = "Badge_indigo_2KXUy", N = "Badge_purple_o55fQ", O = "Badge_pink_T5H--", c = {
6
6
  badge: M,
7
7
  appear: k,
8
8
  accent: x,
@@ -35,15 +35,15 @@ const A = ({
35
35
  style: f,
36
36
  ...y
37
37
  }) => {
38
- const e = !r, g = T(e), t = _(null);
38
+ const e = !r, d = T(e), t = _(null);
39
39
  if (w(() => {
40
- g && !e && t.current?.classList.add(d.appear);
41
- }, [g, e]), l(() => {
42
- if (!e && a && t.current) {
43
- const i = t.current.clientHeight, c = t.current.parentElement, p = c ? Math.min(
44
- parseInt(getComputedStyle(c).getPropertyValue("border-radius")),
45
- c.clientHeight / 2
46
- ) : 0, b = p * (1 - Math.sin(45 * Math.PI / 180)), m = (1 + Math.min(p / i, 1)) * (i / 4);
40
+ d && !e && t.current?.classList.add(c.appear);
41
+ }, [d, e]), l(() => {
42
+ if (!e && a && t.current?.parentElement) {
43
+ const g = t.current.clientHeight, p = t.current.parentElement, i = Math.min(
44
+ parseInt(getComputedStyle(p).getPropertyValue("border-radius")) || 0,
45
+ p.clientHeight / 2
46
+ ), b = i * (1 - Math.sin(45 * Math.PI / 180)), m = (1 + Math.min(i / g, 1)) * (g / 4);
47
47
  t.current.style.setProperty("--offset", `${b - m}px`);
48
48
  }
49
49
  }, [e, a]), e)
@@ -56,7 +56,7 @@ const A = ({
56
56
  ref: t,
57
57
  "data-badge": n,
58
58
  "data-placement": a,
59
- className: E(d.badge, d[n], u),
59
+ className: E(c.badge, c[n], u),
60
60
  style: { ...f, ...H({ size: o }) },
61
61
  children: P(B ? `${s}+` : r, "span")
62
62
  }
@@ -7,7 +7,7 @@ export type DialogProps = React.HTMLAttributes<HTMLDivElement> & {
7
7
  width?: React.CSSProperties['width'];
8
8
  lockScroll?: boolean;
9
9
  requestClose: () => void;
10
- setTriggerProps?: React.Dispatch<React.SetStateAction<object>>;
10
+ setTriggerProps?: React.Dispatch<React.SetStateAction<Record<string, unknown>>>;
11
11
  };
12
12
  export declare const Dialog: React.ForwardRefExoticComponent<React.HTMLAttributes<HTMLDivElement> & {
13
13
  open?: boolean;
@@ -15,7 +15,7 @@ export declare const Dialog: React.ForwardRefExoticComponent<React.HTMLAttribute
15
15
  width?: React.CSSProperties["width"];
16
16
  lockScroll?: boolean;
17
17
  requestClose: () => void;
18
- setTriggerProps?: React.Dispatch<React.SetStateAction<object>>;
18
+ setTriggerProps?: React.Dispatch<React.SetStateAction<Record<string, unknown>>>;
19
19
  } & React.RefAttributes<HTMLDivElement>>;
20
20
  export declare const DialogTitle: ({ className, children, ...props }: Omit<HeadingProps, "title">) => import("react/jsx-runtime").JSX.Element;
21
21
  export declare const DialogContent: (props: React.HTMLAttributes<HTMLDivElement>) => import("react/jsx-runtime").JSX.Element;
@@ -1,22 +1,28 @@
1
- export type DialogOptions<T, R> = {
1
+ export type DialogShowOptions<R> = {
2
+ onConfirm?: (values: R) => void;
3
+ onCancel?: () => void;
4
+ };
5
+ export type DialogOptions<T, R> = DialogShowOptions<R> & {
2
6
  defaultOpen?: boolean;
3
7
  onShow?: (values: T) => void;
4
- onConfirm?: (result: R) => void;
5
- onCancel?: () => void;
6
8
  };
7
9
  export type DialogType<T, R> = ReturnType<typeof useDialog<T, R>>;
8
10
  export declare function useDialog<T, R>(options?: DialogOptions<T, R>): {
9
11
  props: {
10
12
  ref: import('react').RefObject<HTMLDivElement | null>;
11
13
  open: boolean;
12
- setTriggerProps: import('react').Dispatch<import('react').SetStateAction<{}>>;
14
+ setTriggerProps: import('react').Dispatch<import('react').SetStateAction<Record<string, unknown>>>;
13
15
  requestClose: () => void;
14
16
  };
17
+ triggerProps: Record<string, unknown>;
18
+ /**
19
+ * @deprecated The property will be removed in the next major release
20
+ */
15
21
  trigger: {
16
- onClick: (values: T) => void;
22
+ onClick: (values: T, showOptions?: DialogShowOptions<R>) => void;
17
23
  };
18
24
  data: T | undefined;
19
- show: (values: T) => void;
25
+ show: (values: T, showOptions?: DialogShowOptions<R>) => void;
20
26
  cancel: () => void;
21
27
  confirm: (values: R) => void;
22
28
  preventClose: <T_1>(promise: Promise<T_1>) => Promise<T_1>;
@@ -1,32 +1,36 @@
1
- import { useRef as u, useState as a, useCallback as t } from "react";
2
- import { afterTransition as y } from "../../utils/helpers.js";
3
- function h(s) {
4
- const c = u(null), n = u(s), r = u(!1), [g, d] = a({}), [m, f] = a(s?.defaultOpen ?? !1), [C, i] = a();
1
+ import { useRef as c, useState as f, useCallback as t } from "react";
2
+ import { afterTransition as v } from "../../utils/helpers.js";
3
+ function S(s) {
4
+ const u = c(null), e = c(!1), n = c(s), a = c(void 0), [i, g] = f({}), [m, l] = f(s?.defaultOpen ?? !1), [w, p] = f();
5
5
  n.current = s;
6
- const l = t((e) => {
7
- r.current || (f(!0), i(e), n.current?.onShow?.(e));
8
- }, []), o = t((e) => {
9
- r.current || (r.current = !0, c.current?.setAttribute("data-open", "false"), y(c.current, () => {
10
- e !== void 0 ? n.current?.onConfirm?.(e) : n.current?.onCancel?.(), f(!1), i(void 0), r.current = !1;
6
+ const C = t((r, h = {}) => {
7
+ e.current || (a.current = h, l(!0), p(r), n.current?.onShow?.(r));
8
+ }, []), o = t((r) => {
9
+ e.current || (e.current = !0, u.current?.setAttribute("data-open", "false"), v(u.current, () => {
10
+ r !== void 0 ? (n.current?.onConfirm?.(r), a.current?.onConfirm?.(r)) : (n.current?.onCancel?.(), a.current?.onCancel?.()), l(!1), p(void 0), e.current = !1;
11
11
  }));
12
- }, []), p = t(() => o(), [o]), b = t((e) => o(e), [o]), w = t(async (e) => {
13
- r.current = !0;
12
+ }, []), d = t(() => o(), [o]), O = t((r) => o(r), [o]), b = t(async (r) => {
13
+ e.current = !0;
14
14
  try {
15
- return await e;
15
+ return await r;
16
16
  } finally {
17
- r.current = !1;
17
+ e.current = !1;
18
18
  }
19
19
  }, []);
20
20
  return {
21
- props: { ref: c, open: m, setTriggerProps: d, requestClose: p },
22
- trigger: { ...g, onClick: l },
23
- data: C,
24
- show: l,
25
- cancel: p,
26
- confirm: b,
27
- preventClose: w
21
+ props: { ref: u, open: m, setTriggerProps: g, requestClose: d },
22
+ triggerProps: i,
23
+ /**
24
+ * @deprecated The property will be removed in the next major release
25
+ */
26
+ trigger: { ...i, onClick: C },
27
+ data: w,
28
+ show: C,
29
+ cancel: d,
30
+ confirm: O,
31
+ preventClose: b
28
32
  };
29
33
  }
30
34
  export {
31
- h as useDialog
35
+ S as useDialog
32
36
  };
@@ -1,12 +1,18 @@
1
1
  import { default as React } from 'react';
2
2
  import { DialogProps } from './Dialog';
3
- import { DialogOptions, DialogType } from './useDialog';
3
+ import { DialogOptions, DialogShowOptions, DialogType } from './useDialog';
4
4
  type PartialDialogProps = Omit<DialogProps, 'children' | 'ref' | 'requestClose'>;
5
5
  type ComponentProps<T, R> = PartialDialogProps & DialogOptions<T, R> & {
6
- children: (dialog: DialogType<T, R>) => React.ReactNode;
6
+ children: React.ReactNode | ((dialog: DialogType<T, R>) => React.ReactNode);
7
7
  };
8
8
  export type WithDialogProps<T extends object, R> = T & {
9
9
  dialog: DialogType<T, R>;
10
10
  };
11
- export declare function withDialog<T extends object, R>(Component: React.ComponentType<WithDialogProps<T, R>>, withProps?: PartialDialogProps): React.ComponentType<ComponentProps<T, R>>;
11
+ export declare function withDialog<T extends object, R>(Component: React.ComponentType<WithDialogProps<T, R>>, withProps?: PartialDialogProps): {
12
+ ({ children, defaultOpen, onShow, onConfirm, onCancel, ...props }: ComponentProps<T, R>): import("react/jsx-runtime").JSX.Element;
13
+ useTrigger(): {
14
+ props: Record<string, unknown>;
15
+ show(_values: T, _showOptions?: DialogShowOptions<R>): void;
16
+ };
17
+ };
12
18
  export {};
@@ -1,22 +1,32 @@
1
- import { jsxs as d, Fragment as g, jsx as r } from "react/jsx-runtime";
2
- import { Dialog as f } from "./Dialog.js";
3
- import { useDialog as u } from "./useDialog.js";
4
- function j(t, i) {
5
- function a({
6
- children: n,
7
- defaultOpen: p,
8
- onShow: e,
9
- onConfirm: s,
10
- onCancel: l,
11
- ...m
1
+ import { jsxs as h, Fragment as w, jsx as r } from "react/jsx-runtime";
2
+ import i, { useMemo as x } from "react";
3
+ import { Dialog as d } from "./Dialog.js";
4
+ import { useDialog as D } from "./useDialog.js";
5
+ function j(a, p) {
6
+ const e = i.createContext({
7
+ props: {},
8
+ show(t, n) {
9
+ throw new Error("Dialog context is not available");
10
+ }
11
+ });
12
+ function s({
13
+ children: t,
14
+ defaultOpen: n,
15
+ onShow: u,
16
+ onConfirm: g,
17
+ onCancel: c,
18
+ ...l
12
19
  }) {
13
- const o = u({ defaultOpen: p, onShow: e, onConfirm: s, onCancel: l }), c = { ...i, ...m, ...o.props };
14
- return /* @__PURE__ */ d(g, { children: [
15
- n(o),
16
- /* @__PURE__ */ r(f, { ...c, children: o.data && /* @__PURE__ */ r(t, { ...o.data, dialog: o }) })
20
+ const o = D({ defaultOpen: n, onShow: u, onConfirm: g, onCancel: c }), m = { ...p, ...l, ...o.props }, f = x(() => ({
21
+ props: o.triggerProps,
22
+ show: o.show
23
+ }), [o.show, o.triggerProps]);
24
+ return /* @__PURE__ */ h(w, { children: [
25
+ /* @__PURE__ */ r(e, { value: f, children: typeof t == "function" ? t(o) : t }),
26
+ /* @__PURE__ */ r(d, { ...m, children: o.data && /* @__PURE__ */ r(a, { ...o.data, dialog: o }) })
17
27
  ] });
18
28
  }
19
- return a;
29
+ return s.useTrigger = () => i.useContext(e), s;
20
30
  }
21
31
  export {
22
32
  j as withDialog
@@ -1,28 +1,28 @@
1
- import { jsxs as h, jsx as a } from "react/jsx-runtime";
1
+ import { jsxs as h, jsx as o } from "react/jsx-runtime";
2
2
  import i from "classnames";
3
- import p, { useRef as x, useImperativeHandle as b, useEffect as k } from "react";
3
+ import k, { useRef as x, useImperativeHandle as b, useEffect as p } from "react";
4
4
  import { cssProps as R } from "../../utils/helpers.js";
5
- import { I as y, s as l } from "../../Input-BG84zXZH.js";
6
- const q = p.forwardRef(
7
- ({ size: c, error: n, label: t, className: u, style: f, required: m, indeterminate: r, ...o }, d) => {
8
- const s = o.checked, e = x(null);
9
- return b(d, () => e.current), k(() => {
10
- r != null && e.current != null && (e.current.indeterminate = !s && r);
11
- }, [e, r, s]), /* @__PURE__ */ h(
5
+ import { I as y, s } from "../../Input-BG84zXZH.js";
6
+ const _ = k.forwardRef(
7
+ ({ size: t, error: u, label: a, className: f, style: n, required: d, indeterminate: c, ...r }, m) => {
8
+ const l = r.checked || r.defaultChecked, e = x(null);
9
+ return b(m, () => e.current), p(() => {
10
+ c != null && e.current != null && (e.current.indeterminate = !l && c);
11
+ }, [e, c, l]), /* @__PURE__ */ h(
12
12
  "label",
13
13
  {
14
14
  "data-checkbox": !0,
15
- "data-required": m,
16
- className: i(l.checkbox, u),
17
- style: { ...f, ...R({ size: c }) },
15
+ "data-required": d,
16
+ className: i(s.checkbox, f),
17
+ style: { ...n, ...R({ size: t }) },
18
18
  children: [
19
- /* @__PURE__ */ a(y, { ...o, ref: e, type: "checkbox", size: c, error: n }),
20
- t && /* @__PURE__ */ a("div", { "data-checkbox-label": !0, className: l.label, children: t })
19
+ /* @__PURE__ */ o(y, { ...r, ref: e, type: "checkbox", size: t, error: u }),
20
+ a && /* @__PURE__ */ o("div", { "data-checkbox-label": !0, className: s.label, children: a })
21
21
  ]
22
22
  }
23
23
  );
24
24
  }
25
25
  );
26
26
  export {
27
- q as Checkbox
27
+ _ as Checkbox
28
28
  };
@@ -1,45 +1,46 @@
1
- import { jsx as d } from "react/jsx-runtime";
1
+ import { jsx as b } from "react/jsx-runtime";
2
2
  import { useRef as C, useState as v, useEffect as w } from "react";
3
3
  import j from "classnames";
4
4
  import { Composite as x } from "@floating-ui/react";
5
5
  import { cssProps as R } from "../../utils/helpers.js";
6
6
  import { s as S } from "../../styles.module-D0C-vMZX.js";
7
7
  const O = ({
8
- gap: s,
9
- loop: o = !1,
8
+ gap: o,
9
+ loop: l = !1,
10
10
  cols: e = "auto",
11
11
  itemSize: n,
12
12
  objectFit: m,
13
- marginStart: l,
14
- marginEnd: u,
15
- className: a,
16
- style: c,
17
- children: i,
18
- ...f
13
+ marginStart: u,
14
+ marginEnd: a,
15
+ className: c,
16
+ style: i,
17
+ children: f,
18
+ ...p
19
19
  }) => {
20
- const t = C(null), [p, g] = v(e === "auto" ? 1 : e);
20
+ const t = C(null), [s, g] = v(e === "auto" ? 1 : e);
21
21
  return w(() => {
22
22
  const r = new ResizeObserver((y) => {
23
- const b = window.getComputedStyle(y[0].target).gridTemplateColumns;
24
- g(b.split(" ").length);
23
+ const d = window.getComputedStyle(y[0].target).gridTemplateColumns;
24
+ g(d.split(" ").length);
25
25
  });
26
26
  return t.current && (e === "auto" ? r.observe(t.current) : r.unobserve(t.current)), () => {
27
27
  r.disconnect();
28
28
  };
29
- }, [e]), /* @__PURE__ */ d(
29
+ }, [e]), /* @__PURE__ */ b(
30
30
  x,
31
31
  {
32
- ...f,
32
+ ...p,
33
33
  ref: t,
34
- loop: o,
35
- cols: p,
34
+ loop: l,
35
+ cols: s,
36
36
  "data-gallery": !0,
37
- className: j(S.gallery, a),
37
+ "data-gallery-cols": s,
38
+ className: j(S.gallery, c),
38
39
  style: {
39
- ...c,
40
- ...R({ gap: s, marginStart: l, marginEnd: u, itemSize: n, imageObjectFit: m })
40
+ ...i,
41
+ ...R({ gap: o, marginStart: u, marginEnd: a, itemSize: n, imageObjectFit: m })
41
42
  },
42
- children: i
43
+ children: f
43
44
  }
44
45
  );
45
46
  };