@aseguragonzalez/ui 1.0.5 → 1.2.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.
@@ -1,150 +1,154 @@
1
- import e from "./Sidebar.module.css.js";
2
- import { forwardRef as t, useCallback as n, useEffect as r, useRef as i, useState as a } from "react";
3
- import { jsx as o, jsxs as s } from "react/jsx-runtime";
4
- import { createPortal as c } from "react-dom";
1
+ import { ItemLink as e } from "../shared/ItemLink.js";
2
+ import t from "./Sidebar.module.css.js";
3
+ import { forwardRef as n, useCallback as r, useEffect as i, useRef as a, useState as o } from "react";
4
+ import { jsx as s, jsxs as c } from "react/jsx-runtime";
5
+ import { createPortal as l } from "react-dom";
5
6
  //#region src/components/Sidebar/Sidebar.tsx
6
- var l = "a[href], button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex=\"-1\"])", u = () => /* @__PURE__ */ o("svg", {
7
+ var u = "a[href], button:not([disabled]), input:not([disabled]), [tabindex]:not([tabindex=\"-1\"])", d = () => /* @__PURE__ */ s("svg", {
7
8
  width: "16",
8
9
  height: "16",
9
10
  viewBox: "0 0 16 16",
10
11
  fill: "none",
11
12
  "aria-hidden": "true",
12
- children: /* @__PURE__ */ o("path", {
13
+ children: /* @__PURE__ */ s("path", {
13
14
  d: "M10 4L6 8L10 12",
14
15
  stroke: "currentColor",
15
16
  strokeWidth: "1.5",
16
17
  strokeLinecap: "round",
17
18
  strokeLinejoin: "round"
18
19
  })
19
- }), d = () => /* @__PURE__ */ o("svg", {
20
+ }), f = () => /* @__PURE__ */ s("svg", {
20
21
  width: "16",
21
22
  height: "16",
22
23
  viewBox: "0 0 16 16",
23
24
  fill: "none",
24
25
  "aria-hidden": "true",
25
- children: /* @__PURE__ */ o("path", {
26
+ children: /* @__PURE__ */ s("path", {
26
27
  d: "M6 4L10 8L6 12",
27
28
  stroke: "currentColor",
28
29
  strokeWidth: "1.5",
29
30
  strokeLinecap: "round",
30
31
  strokeLinejoin: "round"
31
32
  })
32
- }), f = () => /* @__PURE__ */ o("svg", {
33
+ }), p = () => /* @__PURE__ */ s("svg", {
33
34
  width: "20",
34
35
  height: "20",
35
36
  viewBox: "0 0 20 20",
36
37
  fill: "currentColor",
37
38
  "aria-hidden": "true",
38
- children: /* @__PURE__ */ o("path", { d: "M6.28 5.22a.75.75 0 0 0-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 1 0 1.06 1.06L10 11.06l3.72 3.72a.75.75 0 1 0 1.06-1.06L11.06 10l3.72-3.72a.75.75 0 0 0-1.06-1.06L10 8.94 6.28 5.22Z" })
39
- }), p = t(({ items: t, logo: p, header: m, footer: h, "aria-label": g = "Sidebar navigation", defaultCollapsed: _ = !1, isCollapsed: v, onCollapsedChange: y, defaultMobileOpen: b = !1, isMobileOpen: x, onMobileOpenChange: S, className: C }, w) => {
40
- let [T, E] = a(_), D = v ?? T, [O, k] = a(b), A = x ?? O, [j] = a(() => typeof document < "u"), M = i(null), N = i(null);
41
- r(() => {
42
- if (window.matchMedia?.("(max-width: 767px)")?.matches ?? !1) return A ? (N.current = document.activeElement, document.body.style.overflow = "hidden", (M.current?.querySelector(l))?.focus()) : (document.body.style.overflow = "", N.current?.focus(), N.current = null), () => {
39
+ children: /* @__PURE__ */ s("path", { d: "M6.28 5.22a.75.75 0 0 0-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 1 0 1.06 1.06L10 11.06l3.72 3.72a.75.75 0 1 0 1.06-1.06L11.06 10l3.72-3.72a.75.75 0 0 0-1.06-1.06L10 8.94 6.28 5.22Z" })
40
+ }), m = n(({ items: n, logo: m, header: h, footer: g, "aria-label": _ = "Sidebar navigation", linkComponent: v, defaultCollapsed: y = !1, isCollapsed: b, onCollapsedChange: x, defaultMobileOpen: S = !1, isMobileOpen: C, onMobileOpenChange: w, className: T }, E) => {
41
+ let [D, O] = o(y), k = b ?? D, [A, j] = o(S), M = C ?? A, [N] = o(() => typeof document < "u"), P = a(null), F = a(null);
42
+ i(() => {
43
+ if (window.matchMedia?.("(max-width: 767px)")?.matches ?? !1) return M ? (F.current = document.activeElement, document.body.style.overflow = "hidden", (P.current?.querySelector(u))?.focus()) : (document.body.style.overflow = "", F.current?.focus(), F.current = null), () => {
43
44
  document.body.style.overflow = "";
44
45
  };
45
- }, [A]);
46
- let P = n(() => {
47
- let e = !D;
48
- v === void 0 && E(e), y?.(e);
46
+ }, [M]);
47
+ let I = r(() => {
48
+ let e = !k;
49
+ b === void 0 && O(e), x?.(e);
49
50
  }, [
50
- D,
51
- v,
52
- y
53
- ]), F = n(() => {
54
- x === void 0 && k(!1), S?.(!1);
55
- }, [x, S]), I = n((e) => {
56
- e.key === "Escape" && F();
57
- }, [F]), L = [
58
- e.sidebar,
59
- D ? e.collapsed : "",
60
- A ? e.mobileOpen : "",
61
- C ?? ""
51
+ k,
52
+ b,
53
+ x
54
+ ]), L = r(() => {
55
+ C === void 0 && j(!1), w?.(!1);
56
+ }, [C, w]), R = r((e) => {
57
+ e.key === "Escape" && L();
58
+ }, [L]), z = [
59
+ t.sidebar,
60
+ k ? t.collapsed : "",
61
+ M ? t.mobileOpen : "",
62
+ T ?? ""
62
63
  ].filter(Boolean).join(" ");
63
- return /* @__PURE__ */ s("aside", {
64
- ref: w,
65
- className: L,
66
- children: [j && A && c(/* @__PURE__ */ o("div", {
67
- className: e.backdrop,
68
- onClick: F,
64
+ return /* @__PURE__ */ c("aside", {
65
+ ref: E,
66
+ className: z,
67
+ children: [N && M && l(/* @__PURE__ */ s("div", {
68
+ className: t.backdrop,
69
+ onClick: L,
69
70
  "aria-hidden": "true"
70
- }), document.body), /* @__PURE__ */ s("div", {
71
- ref: M,
72
- className: e.panel,
73
- onKeyDown: I,
71
+ }), document.body), /* @__PURE__ */ c("div", {
72
+ ref: P,
73
+ className: t.panel,
74
+ onKeyDown: R,
74
75
  tabIndex: -1,
75
76
  children: [
76
- (p || m) && /* @__PURE__ */ s("div", {
77
- className: e.panelTop,
78
- children: [/* @__PURE__ */ s("div", {
79
- className: e.logoRow,
80
- children: [p && /* @__PURE__ */ o("div", {
81
- className: e.logoSlot,
82
- children: p
83
- }), m && /* @__PURE__ */ o("div", {
84
- className: e.headerContent,
77
+ (m || h) && /* @__PURE__ */ c("div", {
78
+ className: t.panelTop,
79
+ children: [/* @__PURE__ */ c("div", {
80
+ className: t.logoRow,
81
+ children: [m && /* @__PURE__ */ s("div", {
82
+ className: t.logoSlot,
85
83
  children: m
84
+ }), h && /* @__PURE__ */ s("div", {
85
+ className: t.headerContent,
86
+ children: h
86
87
  })]
87
- }), /* @__PURE__ */ o("button", {
88
+ }), /* @__PURE__ */ s("button", {
88
89
  type: "button",
89
- className: e.mobileCloseButton,
90
- onClick: F,
90
+ className: t.mobileCloseButton,
91
+ onClick: L,
91
92
  "aria-label": "Close sidebar",
92
- children: /* @__PURE__ */ o(f, {})
93
+ children: /* @__PURE__ */ s(p, {})
93
94
  })]
94
95
  }),
95
- !p && !m && /* @__PURE__ */ o("div", {
96
- className: e.mobileCloseRow,
97
- children: /* @__PURE__ */ o("button", {
96
+ !m && !h && /* @__PURE__ */ s("div", {
97
+ className: t.mobileCloseRow,
98
+ children: /* @__PURE__ */ s("button", {
98
99
  type: "button",
99
- className: e.mobileCloseButton,
100
- onClick: F,
100
+ className: t.mobileCloseButton,
101
+ onClick: L,
101
102
  "aria-label": "Close sidebar",
102
- children: /* @__PURE__ */ o(f, {})
103
+ children: /* @__PURE__ */ s(p, {})
103
104
  })
104
105
  }),
105
- /* @__PURE__ */ o("nav", {
106
- "aria-label": g,
107
- className: e.nav,
108
- children: /* @__PURE__ */ o("ul", {
109
- className: e.navList,
106
+ /* @__PURE__ */ s("nav", {
107
+ "aria-label": _,
108
+ className: t.nav,
109
+ children: /* @__PURE__ */ s("ul", {
110
+ className: t.navList,
110
111
  tabIndex: 0,
111
- children: t.map((t) => /* @__PURE__ */ o("li", {
112
- className: e.navItem,
113
- children: /* @__PURE__ */ s("a", {
114
- href: t.href,
115
- onClick: t.onClick,
116
- className: [e.navLink, t.isActive ? e.navLinkActive : ""].filter(Boolean).join(" "),
117
- "aria-current": t.isActive ? "page" : void 0,
118
- "aria-label": t.icon && D ? t.label : void 0,
119
- title: t.icon && D ? t.label : void 0,
120
- children: [t.icon && /* @__PURE__ */ o("span", {
121
- className: e.navLinkIcon,
112
+ children: n.map((n) => /* @__PURE__ */ s("li", {
113
+ className: t.navItem,
114
+ children: /* @__PURE__ */ c(e, {
115
+ linkComponent: v,
116
+ href: n.href,
117
+ onClick: () => {
118
+ n.onClick?.(), M && L();
119
+ },
120
+ className: [t.navLink, n.isActive ? t.navLinkActive : ""].filter(Boolean).join(" "),
121
+ "aria-current": n.isActive ? "page" : void 0,
122
+ "aria-label": n.icon && k ? n.label : void 0,
123
+ title: n.icon && k ? n.label : void 0,
124
+ children: [n.icon && /* @__PURE__ */ s("span", {
125
+ className: t.navLinkIcon,
122
126
  "aria-hidden": "true",
123
- children: t.icon
124
- }), /* @__PURE__ */ o("span", {
125
- className: e.navLinkLabel,
126
- children: t.label
127
+ children: n.icon
128
+ }), /* @__PURE__ */ s("span", {
129
+ className: t.navLinkLabel,
130
+ children: n.label
127
131
  })]
128
132
  })
129
- }, t.key))
133
+ }, n.key))
130
134
  })
131
135
  }),
132
- h && /* @__PURE__ */ o("div", {
133
- className: e.footer,
134
- children: h
136
+ g && /* @__PURE__ */ s("div", {
137
+ className: t.footer,
138
+ children: g
135
139
  }),
136
- /* @__PURE__ */ o("button", {
140
+ /* @__PURE__ */ s("button", {
137
141
  type: "button",
138
- className: e.collapseButton,
139
- onClick: P,
140
- "aria-label": D ? "Expand sidebar" : "Collapse sidebar",
141
- "aria-expanded": !D,
142
- children: o(D ? d : u, {})
142
+ className: t.collapseButton,
143
+ onClick: I,
144
+ "aria-label": k ? "Expand sidebar" : "Collapse sidebar",
145
+ "aria-expanded": !k,
146
+ children: s(k ? f : d, {})
143
147
  })
144
148
  ]
145
149
  })]
146
150
  });
147
151
  });
148
- p.displayName = "Sidebar";
152
+ m.displayName = "Sidebar";
149
153
  //#endregion
150
- export { p as Sidebar };
154
+ export { m as Sidebar };
@@ -0,0 +1 @@
1
+ let e=require("react/jsx-runtime");function t({linkComponent:t,href:n,...r}){return t&&n?(0,e.jsx)(t,{href:n,...r}):(0,e.jsx)(`a`,{href:n,...r})}exports.ItemLink=t;
@@ -0,0 +1,7 @@
1
+ import type { LinkComponent, LinkComponentProps } from './LinkComponent';
2
+ export interface ItemLinkProps extends Omit<LinkComponentProps, 'href'> {
3
+ href?: string;
4
+ linkComponent?: LinkComponent;
5
+ }
6
+ /** Renders a navigation item's link through `linkComponent` when it has an `href`, otherwise as a plain `<a>`. */
7
+ export declare function ItemLink({ linkComponent: Link, href, ...rest }: ItemLinkProps): import("react").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { jsx as e } from "react/jsx-runtime";
2
+ //#region src/components/shared/ItemLink.tsx
3
+ function t({ linkComponent: t, href: n, ...r }) {
4
+ return e(t && n ? t : "a", {
5
+ href: n,
6
+ ...r
7
+ });
8
+ }
9
+ //#endregion
10
+ export { t as ItemLink };
@@ -0,0 +1,16 @@
1
+ import type { AriaAttributes, ComponentType, MouseEventHandler, ReactNode } from 'react';
2
+ /** Props a navigation component passes to a consumer-supplied link component. */
3
+ export interface LinkComponentProps {
4
+ href: string;
5
+ className?: string;
6
+ children?: ReactNode;
7
+ onClick?: MouseEventHandler<HTMLAnchorElement>;
8
+ 'aria-current'?: AriaAttributes['aria-current'];
9
+ 'aria-label'?: string;
10
+ title?: string;
11
+ }
12
+ /**
13
+ * A link component, typically a thin adapter over the router's own (`<Link to={href} … />`), that a
14
+ * navigation component renders for items with an `href` instead of a plain `<a>`.
15
+ */
16
+ export type LinkComponent = ComponentType<LinkComponentProps>;