@konstructio/ui 0.1.2-alpha.85 → 0.1.2-alpha.86

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,11 +1,16 @@
1
1
  import { t as a } from "../../../../utils-COaoD3PI.js";
2
+ import { useSidebarContext as e } from "../../contexts/SidebarContext.js";
2
3
  import { logoVariants as m } from "./Logo.variants.js";
3
- import { jsx as t } from "react/jsx-runtime";
4
- var s = ({ children: o, className: r }) => /* @__PURE__ */ t("header", {
5
- className: a(m({ className: r })),
6
- children: o
7
- });
8
- s.displayName = "KonstructSidebarLogo";
4
+ import { jsx as s } from "react/jsx-runtime";
5
+ var i = ({ children: o, className: r }) => {
6
+ const { closeDrawer: t } = e();
7
+ return /* @__PURE__ */ s("header", {
8
+ className: a(m({ className: r })),
9
+ onClick: () => t(),
10
+ children: o
11
+ });
12
+ };
13
+ i.displayName = "KonstructSidebarLogo";
9
14
  export {
10
- s as Logo
15
+ i as Logo
11
16
  };
@@ -1,26 +1,31 @@
1
- import { t as p } from "../../../../utils-COaoD3PI.js";
2
- import { useSidebarContext as l } from "../../contexts/SidebarContext.js";
1
+ import { t as u } from "../../../../utils-COaoD3PI.js";
2
+ import { useSidebarContext as v } from "../../contexts/SidebarContext.js";
3
3
  import { navigationOptionVariants as m } from "./NavigationOption.variants.js";
4
- import { jsx as v } from "react/jsx-runtime";
5
- var d = ({ children: o, className: r, isVisible: i = !0, isActive: t, ...a }) => {
6
- const { isCollapsed: e, expandOnHover: n } = l(), s = e && n;
7
- return i ? /* @__PURE__ */ v("li", {
8
- ...a,
4
+ import { jsx as d } from "react/jsx-runtime";
5
+ var k = ({ children: i, className: r, closeDrawerOnClick: n = !0, isVisible: t = !0, isActive: a, ...o }) => {
6
+ const { isCollapsed: e, expandOnHover: s, closeDrawer: l } = v(), p = e && s;
7
+ if (!t) return null;
8
+ const c = "onClick" in o ? o.onClick : void 0;
9
+ return /* @__PURE__ */ d("li", {
10
+ ...o,
9
11
  role: "option",
10
- className: p(m({
12
+ onClick: () => {
13
+ n && l(), c?.();
14
+ },
15
+ className: u(m({
11
16
  className: r,
12
- isActive: t
13
- }), s && [
17
+ isActive: a
18
+ }), p && [
14
19
  "group/sidebar-option",
15
20
  "relative",
16
21
  "hover:z-50",
17
22
  "hover:shadow-lg",
18
23
  "hover:bg-kubefirst-dark-blue-900"
19
24
  ]),
20
- children: o
21
- }) : null;
25
+ children: i
26
+ });
22
27
  };
23
- d.displayName = "KonstructSidebarNavigationOption";
28
+ k.displayName = "KonstructSidebarNavigationOption";
24
29
  export {
25
- d as NavigationOption
30
+ k as NavigationOption
26
31
  };
@@ -1,101 +1,105 @@
1
1
  import { t as X } from "../../../../HamburgerTrigger-BzCfBWzH.js";
2
- import { t as f } from "../../../../utils-COaoD3PI.js";
2
+ import { t as h } from "../../../../utils-COaoD3PI.js";
3
3
  import { Drawer as W } from "../../../Drawer/Drawer.js";
4
- import { SidebarContext as R } from "../../contexts/SidebarContext.js";
4
+ import { SidebarContext as O } from "../../contexts/SidebarContext.js";
5
5
  import { useSidebarMode as q } from "../../hooks/useSidebarMode.js";
6
- import { dragVariants as B, wrapperSiderbarVariants as O } from "../../Sidebar.variants.js";
7
- import { useCallback as c, useEffect as v, useRef as u, useState as S } from "react";
8
- import { Fragment as G, jsx as s, jsxs as N } from "react/jsx-runtime";
9
- var J = 280, K = ({ animateOnHover: z = !0, canResize: C = !0, children: w, dividerClassName: H, drawerBreakpoint: V, drawerMaxWidth: h = J, expandedBreakpoint: A, expandOnHover: F = !0, initialWidth: y = 256, maxWith: o = 300, minWith: a = 240, mode: I = "auto", separatorClassName: x, theme: b, triggerClassName: P, wrapperClassName: g }) => {
10
- const t = q(I, A, V), [D, L] = S(!1), [M, T] = S(null), n = u(null), e = u(null), p = u(!1), E = u(!1);
11
- v(() => {
12
- if (t !== "drawer") return;
13
- const r = () => {
14
- T(window.innerWidth);
6
+ import { dragVariants as B, wrapperSiderbarVariants as S } from "../../Sidebar.variants.js";
7
+ import { useCallback as c, useEffect as u, useRef as p, useState as N } from "react";
8
+ import { Fragment as G, jsx as s, jsxs as z } from "react/jsx-runtime";
9
+ var J = 280, K = ({ animateOnHover: C = !0, canResize: H = !0, children: y, dividerClassName: V, drawerBreakpoint: A, drawerMaxWidth: x = J, expandedBreakpoint: F, expandOnHover: I = !0, initialWidth: D = 256, maxWith: o = 300, minWith: a = 240, mode: P = "auto", separatorClassName: b, theme: g, triggerClassName: T, wrapperClassName: L }) => {
10
+ const r = q(P, F, A), [M, m] = N(!1), [E, _] = N(null), n = p(null), e = p(null), f = p(!1), R = p(!1);
11
+ u(() => {
12
+ if (r !== "drawer") return;
13
+ const t = () => {
14
+ _(window.innerWidth);
15
15
  };
16
- return r(), window.addEventListener("resize", r), () => {
17
- window.removeEventListener("resize", r);
16
+ return t(), window.addEventListener("resize", t), () => {
17
+ window.removeEventListener("resize", t);
18
18
  };
19
- }, [t]);
20
- const l = c((r) => {
21
- if (!p.current) {
19
+ }, [r]);
20
+ const l = c((t) => {
21
+ if (!f.current) {
22
22
  n.current && (n.current.style.opacity = "0");
23
23
  return;
24
24
  }
25
- let i = r.clientX;
25
+ let i = t.clientX;
26
26
  i < a && (i = a), i > o && (i = o), e.current && n.current && (e.current.style.width = `${i}px`, n.current.classList.add("opacity-100"));
27
- }, [o, a]), m = c(() => {
28
- p.current = !1, n.current && n.current.classList.remove("opacity-100"), e.current && e.current.classList.remove("transition-none"), document.body.style.userSelect = "", document.body.style.cursor = "", document.removeEventListener("mousemove", l), document.removeEventListener("mouseup", m);
29
- }, [l]), _ = c((r) => {
30
- r.preventDefault(), r.stopPropagation(), p.current = !0, e.current && e.current.classList.add("transition-none"), document.body.style.userSelect = "none", document.body.style.cursor = "col-resize", document.addEventListener("mousemove", l), document.addEventListener("mouseup", m);
31
- }, [l, m]);
32
- v(() => {
33
- t !== "expanded" && e.current && (e.current.style.width = "");
34
- }, [t]), v(() => {
35
- if (E.current || t !== "expanded" || !e.current) return;
36
- const r = Math.min(Math.max(y, a), o);
37
- e.current.style.width = `${r}px`, E.current = !0;
27
+ }, [o, a]), v = c(() => {
28
+ f.current = !1, n.current && n.current.classList.remove("opacity-100"), e.current && e.current.classList.remove("transition-none"), document.body.style.userSelect = "", document.body.style.cursor = "", document.removeEventListener("mousemove", l), document.removeEventListener("mouseup", v);
29
+ }, [l]), $ = c((t) => {
30
+ t.preventDefault(), t.stopPropagation(), f.current = !0, e.current && e.current.classList.add("transition-none"), document.body.style.userSelect = "none", document.body.style.cursor = "col-resize", document.addEventListener("mousemove", l), document.addEventListener("mouseup", v);
31
+ }, [l, v]);
32
+ u(() => {
33
+ r !== "expanded" && e.current && (e.current.style.width = "");
34
+ }, [r]), u(() => {
35
+ r !== "drawer" && m(!1);
36
+ }, [r]), u(() => {
37
+ if (R.current || r !== "expanded" || !e.current) return;
38
+ const t = Math.min(Math.max(D, a), o);
39
+ e.current.style.width = `${t}px`, R.current = !0;
38
40
  }, [
39
- y,
41
+ D,
40
42
  o,
41
43
  a,
42
- t
44
+ r
43
45
  ]);
44
- const $ = c(() => {
45
- L(!0);
46
- }, []), j = c(() => {
47
- L(!1);
46
+ const j = c(() => {
47
+ m(!0);
48
+ }, []), w = c(() => {
49
+ m(!1);
48
50
  }, []);
49
- if (t === "drawer") return /* @__PURE__ */ N(G, { children: [/* @__PURE__ */ s(X, {
50
- isOpen: D,
51
- onClick: $,
52
- className: P
51
+ if (r === "drawer") return /* @__PURE__ */ z(G, { children: [/* @__PURE__ */ s(X, {
52
+ isOpen: M,
53
+ onClick: j,
54
+ className: T
53
55
  }), /* @__PURE__ */ s(W, {
54
- isOpen: D,
55
- onClose: j,
56
+ isOpen: M,
57
+ onClose: w,
56
58
  position: "left",
57
- defaultWidth: M !== null ? Math.min(M, h) : h,
58
- theme: b,
59
+ defaultWidth: E !== null ? Math.min(E, x) : x,
60
+ theme: g,
59
61
  classNames: {
60
- panel: f(O({ mode: "expanded" }), "h-full border-r-0", g),
62
+ panel: h(S({ mode: "expanded" }), "h-full border-r-0", L),
61
63
  content: "gap-0"
62
64
  },
63
- children: /* @__PURE__ */ s(R.Provider, {
65
+ children: /* @__PURE__ */ s(O.Provider, {
64
66
  value: {
65
67
  mode: "expanded",
66
68
  isCollapsed: !1,
67
69
  expandOnHover: !1,
68
70
  animateOnHover: !1,
69
- separatorClassName: x
71
+ separatorClassName: b,
72
+ closeDrawer: w
70
73
  },
71
74
  children: /* @__PURE__ */ s("div", {
72
75
  className: "group/sidebar flex flex-col flex-1 min-h-0",
73
76
  "data-mode": "expanded",
74
- children: w
77
+ children: y
75
78
  })
76
79
  })
77
80
  })] });
78
- const d = t, k = C && d === "expanded", U = {
81
+ const d = r, k = H && d === "expanded", U = {
79
82
  mode: d,
80
83
  isCollapsed: d === "collapsed",
81
- expandOnHover: F,
82
- animateOnHover: z,
83
- separatorClassName: x
84
+ expandOnHover: I,
85
+ animateOnHover: C,
86
+ separatorClassName: b,
87
+ closeDrawer: w
84
88
  };
85
- return /* @__PURE__ */ s(R.Provider, {
89
+ return /* @__PURE__ */ s(O.Provider, {
86
90
  value: U,
87
- children: /* @__PURE__ */ N("aside", {
91
+ children: /* @__PURE__ */ z("aside", {
88
92
  ref: e,
89
- className: f(O({
93
+ className: h(S({
90
94
  mode: d,
91
- className: g
95
+ className: L
92
96
  })),
93
- "data-theme": b,
97
+ "data-theme": g,
94
98
  "data-mode": d,
95
- children: [w, k && /* @__PURE__ */ s("div", {
99
+ children: [y, k && /* @__PURE__ */ s("div", {
96
100
  ref: n,
97
- className: f(B({ className: H })),
98
- onMouseDown: _
101
+ className: h(B({ className: V })),
102
+ onMouseDown: $
99
103
  })]
100
104
  })
101
105
  });
@@ -1,11 +1,13 @@
1
- import { createContext as e, useContext as t } from "react";
2
- var r = e({
1
+ import { createContext as e, useContext as r } from "react";
2
+ var t = e({
3
3
  mode: "expanded",
4
4
  isCollapsed: !1,
5
5
  expandOnHover: !1,
6
- animateOnHover: !0
7
- }), o = () => t(r);
6
+ animateOnHover: !0,
7
+ closeDrawer: () => {
8
+ }
9
+ }), o = () => r(t);
8
10
  export {
9
- r as SidebarContext,
11
+ t as SidebarContext,
10
12
  o as useSidebarContext
11
13
  };
@@ -5,6 +5,12 @@ type NavigationOption = VariantProps<typeof navigationOptionVariants> & {
5
5
  className?: string;
6
6
  isVisible?: boolean;
7
7
  isActive?: boolean;
8
+ /**
9
+ * Whether clicking this option should close the drawer when the Sidebar
10
+ * is in `drawer` mode. Defaults to `true`. Has no effect in `expanded` or
11
+ * `collapsed` modes.
12
+ */
13
+ closeDrawerOnClick?: boolean;
8
14
  };
9
15
  export type Props = NavigationOption & ({
10
16
  role: 'button';
@@ -5,6 +5,12 @@ export interface SidebarContextValue {
5
5
  expandOnHover: boolean;
6
6
  animateOnHover: boolean;
7
7
  separatorClassName?: string;
8
+ /**
9
+ * Closes the drawer when the Sidebar is in `drawer` mode. No-op in
10
+ * `expanded` or `collapsed` modes. Useful for closing the drawer on
11
+ * navigation events (e.g. when the user clicks a link).
12
+ */
13
+ closeDrawer: () => void;
8
14
  }
9
15
  export declare const SidebarContext: import('react').Context<SidebarContextValue>;
10
16
  export declare const useSidebarContext: () => SidebarContextValue;
package/dist/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@konstructio/ui",
3
3
  "description": "A set of reusable and customizable React components built for konstruct.io",
4
4
  "private": false,
5
- "version": "0.1.2-alpha.84",
5
+ "version": "0.1.2-alpha.85",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "main": "dist/index.js",
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@konstructio/ui",
3
3
  "description": "A set of reusable and customizable React components built for konstruct.io",
4
4
  "private": false,
5
- "version": "0.1.2-alpha.85",
5
+ "version": "0.1.2-alpha.86",
6
6
  "type": "module",
7
7
  "license": "MIT",
8
8
  "main": "dist/index.js",