zuii 1.4.7 → 1.4.8

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.
@@ -31,9 +31,11 @@ export declare const isItemDisabled: (item: ContextMenuItem) => boolean;
31
31
  * @param {number} y - Position Y souhaitée.
32
32
  * @param {number} menuWidth - Largeur du menu.
33
33
  * @param {number} menuHeight - Hauteur du menu.
34
+ * @param {number} [offsetX=2] - Décalage horizontal par rapport au clic.
35
+ * @param {number} [offsetY=2] - Décalage vertical par rapport au clic.
34
36
  * @returns {{x: number, y: number}} La position corrigée.
35
37
  */
36
- export declare const calculatePosition: (x: number, y: number, menuWidth: number, menuHeight: number) => {
38
+ export declare const calculatePosition: (x: number, y: number, menuWidth: number, menuHeight: number, offsetX?: number, offsetY?: number) => {
37
39
  x: number;
38
40
  y: number;
39
41
  };
@@ -1,19 +1,22 @@
1
- const n = (t) => {
1
+ const c = (t) => {
2
2
  const e = t.items && t.items.length > 0;
3
3
  return !!(t.disabled || !e && !t.onAction && !t.action && t.type !== "separator");
4
- }, r = (t, e, o, a) => {
5
- let l = t, i = e;
6
- return t + o > window.innerWidth && (l = t - o), e + a > window.innerHeight && (i = e - a), { x: Math.max(0, l), y: Math.max(0, i) };
7
- }, s = () => {
4
+ }, s = (t, e, o, a, n = 2, r = 2) => {
5
+ let l = t + n, i = e + r;
6
+ return l + o > window.innerWidth && (l = t - o - n), i + a > window.innerHeight && (i = e - a - r), {
7
+ x: Math.max(0, Math.min(l, window.innerWidth - o)),
8
+ y: Math.max(0, Math.min(i, window.innerHeight - a))
9
+ };
10
+ }, d = () => {
8
11
  document.body.style.overflow = "hidden";
9
- }, c = () => {
12
+ }, b = () => {
10
13
  document.body.style.overflow = "";
11
- }, d = (t) => {
14
+ }, h = (t) => {
12
15
  const e = t.getBoundingClientRect();
13
16
  e.right > window.innerWidth && (t.style.left = "auto", t.style.right = "100%", t.style.marginLeft = "0", t.style.marginRight = "2px"), e.bottom > window.innerHeight && (t.style.top = "auto", t.style.bottom = "0");
14
- }, b = (t, e) => {
15
- n(t) || t.type === "separator" || (t.onAction && t.onAction(), t.action && e && e(t.action));
16
- }, p = (t) => !t || t.length === 0 ? "" : t.join(" + "), h = {
17
+ }, p = (t, e) => {
18
+ c(t) || t.type === "separator" || (t.onAction && t.onAction(), t.action && e && e(t.action));
19
+ }, u = (t) => !t || t.length === 0 ? "" : t.join(" + "), w = {
17
20
  items: [
18
21
  {
19
22
  label: "Nouveau",
@@ -74,12 +77,12 @@ const n = (t) => {
74
77
  ]
75
78
  };
76
79
  export {
77
- d as adjustSubMenuPosition,
78
- r as calculatePosition,
79
- h as contextMenuData,
80
- b as executeAction,
81
- p as getDisplayShortcut,
82
- n as isItemDisabled,
83
- s as lockScroll,
84
- c as unlockScroll
80
+ h as adjustSubMenuPosition,
81
+ s as calculatePosition,
82
+ w as contextMenuData,
83
+ p as executeAction,
84
+ u as getDisplayShortcut,
85
+ c as isItemDisabled,
86
+ d as lockScroll,
87
+ b as unlockScroll
85
88
  };
@@ -1,29 +1,29 @@
1
- import { jsxs as M, jsx as u } from "react/jsx-runtime";
2
- import { useState as b, useRef as _, useCallback as x, useEffect as S } from "react";
3
- import { calculatePosition as C, lockScroll as y, unlockScroll as h, contextMenuData as g, getDisplayShortcut as N, isItemDisabled as k, adjustSubMenuPosition as D, executeAction as E } from "../js/context-menu.js";
1
+ import { jsxs as M, jsx as l } from "react/jsx-runtime";
2
+ import { useState as b, useRef as v, useCallback as h, useEffect as x } from "react";
3
+ import { calculatePosition as C, lockScroll as g, unlockScroll as y, contextMenuData as N, getDisplayShortcut as k, isItemDisabled as D, adjustSubMenuPosition as E, executeAction as I } from "../js/context-menu.js";
4
4
  import '../style/index.css';/* empty css */
5
- const $ = ({ item: e, onAction: f, closeMenu: p }) => {
6
- const [l, o] = b(!1), c = _(null), t = "context-menu", n = !!(e.items && e.items.length > 0), r = N(e.shortcuts), i = k(e);
7
- return S(() => {
8
- l && c.current && D(c.current);
9
- }, [l]), e.type === "separator" ? /* @__PURE__ */ u("div", { className: `${t}__separator` }) : /* @__PURE__ */ M(
5
+ const $ = ({ item: s, onAction: f, closeMenu: p }) => {
6
+ const [u, o] = b(!1), r = v(null), e = "context-menu", i = !!(s.items && s.items.length > 0), t = k(s.shortcuts), c = D(s);
7
+ return x(() => {
8
+ u && r.current && E(r.current);
9
+ }, [u]), s.type === "separator" ? /* @__PURE__ */ l("div", { className: `${e}__separator` }) : /* @__PURE__ */ M(
10
10
  "div",
11
11
  {
12
- className: `${t}__item ${n ? `${t}__sub-trigger` : ""} ${i ? "disabled" : ""}`.trim(),
13
- onMouseEnter: () => n && !i && o(!0),
14
- onMouseLeave: () => n && !i && o(!1),
12
+ className: `${e}__item ${i ? `${e}__sub-trigger` : ""} ${c ? "disabled" : ""}`.trim(),
13
+ onMouseEnter: () => i && !c && o(!0),
14
+ onMouseLeave: () => i && !c && o(!1),
15
15
  onClick: (a) => {
16
- !n && !i && (a.stopPropagation(), E(e, f), p());
16
+ !i && !c && (a.stopPropagation(), I(s, f), p());
17
17
  },
18
18
  children: [
19
- e.label,
20
- r && /* @__PURE__ */ u("span", { className: `${t}__shortcut`, children: r }),
21
- n && l && /* @__PURE__ */ u(
19
+ s.label,
20
+ t && /* @__PURE__ */ l("span", { className: `${e}__shortcut`, children: t }),
21
+ i && u && /* @__PURE__ */ l(
22
22
  "div",
23
23
  {
24
- ref: c,
25
- className: `${t} ${t}__sub-menu`,
26
- children: e.items.map((a, m) => /* @__PURE__ */ u(
24
+ ref: r,
25
+ className: `${e} ${e}__sub-menu`,
26
+ children: s.items.map((a, m) => /* @__PURE__ */ l(
27
27
  $,
28
28
  {
29
29
  item: a,
@@ -37,46 +37,51 @@ const $ = ({ item: e, onAction: f, closeMenu: p }) => {
37
37
  ]
38
38
  }
39
39
  );
40
- }, w = ({
41
- items: e = g.items,
40
+ }, L = ({
41
+ items: s = N.items,
42
42
  onAction: f,
43
43
  children: p,
44
- className: l = ""
44
+ className: u = ""
45
45
  }) => {
46
- const [o, c] = b(!1), [t, n] = b({ x: 0, y: 0 }), r = _(null), i = "context-menu", a = x((s) => {
47
- s.preventDefault(), c(!0);
48
- const { x: d, y: v } = C(s.clientX, s.clientY, 160, 200);
49
- n({ x: d, y: v });
50
- }, []), m = x(() => {
51
- c(!1);
46
+ const [o, r] = b(!1), [e, i] = b({ x: 0, y: 0 }), t = v(null), c = "context-menu", a = h((n) => {
47
+ n.preventDefault(), i({ x: n.clientX, y: n.clientY }), r(!0);
48
+ }, []), m = h(() => {
49
+ r(!1);
52
50
  }, []);
53
- return S(() => {
54
- const s = (d) => {
55
- r.current && !r.current.contains(d.target) && m();
51
+ return x(() => {
52
+ if (o && t.current) {
53
+ const { offsetWidth: n, offsetHeight: d } = t.current, { x: _, y: S } = C(e.x, e.y, n, d);
54
+ t.current.style.top = `${S}px`, t.current.style.left = `${_}px`, t.current.style.visibility = "visible";
55
+ }
56
+ }, [o, e.x, e.y]), x(() => {
57
+ const n = (d) => {
58
+ t.current && !t.current.contains(d.target) && m();
56
59
  };
57
- return o ? (document.addEventListener("mousedown", s), y()) : h(), () => {
58
- document.removeEventListener("mousedown", s), h();
60
+ return o ? (document.addEventListener("mousedown", n), g()) : y(), () => {
61
+ document.removeEventListener("mousedown", n), y();
59
62
  };
60
63
  }, [o, m]), /* @__PURE__ */ M(
61
64
  "div",
62
65
  {
63
66
  onContextMenu: a,
64
- className: `context-menu-wrapper ${l}`,
67
+ className: `context-menu-wrapper ${u}`,
65
68
  children: [
66
69
  p,
67
- o && /* @__PURE__ */ u(
70
+ o && /* @__PURE__ */ l(
68
71
  "div",
69
72
  {
70
- ref: r,
71
- className: i,
73
+ ref: t,
74
+ className: c,
72
75
  style: {
73
- top: t.y,
74
- left: t.x
76
+ top: e.y,
77
+ left: e.x,
78
+ visibility: "hidden"
79
+ // Caché le temps de la mesure au premier affichage
75
80
  },
76
- children: e.map((s, d) => /* @__PURE__ */ u(
81
+ children: s.map((n, d) => /* @__PURE__ */ l(
77
82
  $,
78
83
  {
79
- item: s,
84
+ item: n,
80
85
  onAction: f,
81
86
  closeMenu: m
82
87
  },
@@ -89,5 +94,5 @@ const $ = ({ item: e, onAction: f, closeMenu: p }) => {
89
94
  );
90
95
  };
91
96
  export {
92
- w as ContextMenu
97
+ L as ContextMenu
93
98
  };
@@ -3,6 +3,7 @@ interface DropdownItem {
3
3
  label?: string;
4
4
  href?: string;
5
5
  type?: "divider" | "item";
6
+ onClick?: () => void;
6
7
  }
7
8
  interface Props extends Omit<DropdownProps, "children"> {
8
9
  /**
@@ -25,6 +26,10 @@ interface Props extends Omit<DropdownProps, "children"> {
25
26
  * Contenu optionnel.
26
27
  */
27
28
  children?: React.ReactNode;
29
+ /**
30
+ * Fonction appelée lorsque le dropdown est ouvert.
31
+ */
32
+ onClick?: () => void;
28
33
  }
29
34
  /**
30
35
  * Composant Dropdown personnalisé.
@@ -34,7 +39,7 @@ interface Props extends Omit<DropdownProps, "children"> {
34
39
  * @returns {JSX.Element} Le composant Dropdown rendu.
35
40
  */
36
41
  export declare const Dropdown: {
37
- ({ label, variant, items, align, className, children, ...props }: Props): import("react/jsx-runtime").JSX.Element;
42
+ ({ label, variant, items, align, className, children, onClick, ...props }: Props): import("react/jsx-runtime").JSX.Element;
38
43
  Toggle({ className, ...props }: any): import("react/jsx-runtime").JSX.Element;
39
44
  Menu({ className, ...props }: any): import("react/jsx-runtime").JSX.Element;
40
45
  Item({ className, ...props }: any): import("react/jsx-runtime").JSX.Element;
@@ -1,33 +1,35 @@
1
- import { jsx as o, jsxs as c, Fragment as $ } from "react/jsx-runtime";
1
+ import { jsx as o, jsxs as _, Fragment as $ } from "react/jsx-runtime";
2
2
  import { Dropdown as d } from "react-bootstrap";
3
3
  import '../style/index.css';/* empty css */
4
- const s = ({
4
+ const n = ({
5
5
  label: r = "Dropdown",
6
6
  variant: e = "primary",
7
- items: t = [],
8
- align: l = "start",
9
- className: p = "",
10
- children: a,
11
- ..._
7
+ items: l = [],
8
+ align: t = "start",
9
+ className: c = "",
10
+ children: s,
11
+ onClick: g,
12
+ ...p
12
13
  }) => {
13
- const m = "dropdown";
14
- return /* @__PURE__ */ o(d, { className: `${m} ${p}`.trim(), align: l, ..._, children: a || /* @__PURE__ */ c($, { children: [
15
- /* @__PURE__ */ o(d.Toggle, { variant: e, id: `dropdown-${r}`, className: `${m}__toggle`, children: r }),
16
- /* @__PURE__ */ o(d.Menu, { className: `${m}__menu`, children: t.map((i, n) => i.type === "divider" ? /* @__PURE__ */ o(d.Divider, { className: `${m}__divider` }, n) : /* @__PURE__ */ o(
14
+ const i = "dropdown";
15
+ return /* @__PURE__ */ o(d, { className: `${i} ${c}`.trim(), align: t, ...p, children: s || /* @__PURE__ */ _($, { children: [
16
+ /* @__PURE__ */ o(d.Toggle, { variant: e, id: `dropdown-${r}`, className: `${i}__toggle`, children: r }),
17
+ /* @__PURE__ */ o(d.Menu, { className: `${i}__menu`, children: l.map((m, a) => m.type === "divider" ? /* @__PURE__ */ o(d.Divider, { className: `${i}__divider` }, a) : /* @__PURE__ */ o(
17
18
  d.Item,
18
19
  {
19
- href: i.href,
20
- className: `${m}__item`,
21
- children: i.label
20
+ href: m.href,
21
+ className: `${i}__item`,
22
+ onClick: m.onClick,
23
+ children: m.label
22
24
  },
23
- n
25
+ a
24
26
  )) })
25
27
  ] }) });
26
28
  };
27
- s.Toggle = ({ className: r = "", ...e }) => /* @__PURE__ */ o(d.Toggle, { className: `dropdown__toggle ${r}`.trim(), ...e });
28
- s.Menu = ({ className: r = "", ...e }) => /* @__PURE__ */ o(d.Menu, { className: `dropdown__menu ${r}`.trim(), ...e });
29
- s.Item = ({ className: r = "", ...e }) => /* @__PURE__ */ o(d.Item, { className: `dropdown__item ${r}`.trim(), ...e });
30
- s.Divider = ({ className: r = "", ...e }) => /* @__PURE__ */ o(d.Divider, { className: `dropdown__divider ${r}`.trim(), ...e });
29
+ n.Toggle = ({ className: r = "", ...e }) => /* @__PURE__ */ o(d.Toggle, { className: `dropdown__toggle ${r}`.trim(), ...e });
30
+ n.Menu = ({ className: r = "", ...e }) => /* @__PURE__ */ o(d.Menu, { className: `dropdown__menu ${r}`.trim(), ...e });
31
+ n.Item = ({ className: r = "", ...e }) => /* @__PURE__ */ o(d.Item, { className: `dropdown__item ${r}`.trim(), ...e });
32
+ n.Divider = ({ className: r = "", ...e }) => /* @__PURE__ */ o(d.Divider, { className: `dropdown__divider ${r}`.trim(), ...e });
31
33
  export {
32
- s as Dropdown
34
+ n as Dropdown
33
35
  };
@@ -71,6 +71,9 @@ export const Dropdowns = () => {
71
71
  Action 3
72
72
  </Group>
73
73
  </Dropdown.Item>
74
+ <Dropdown.Item onClick={() => console.log('Hello World')}>
75
+ Hello World console.log
76
+ </Dropdown.Item>
74
77
  </Dropdown.Menu>
75
78
  </Dropdown>
76
79
  </div>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zuii",
3
- "version": "1.4.7",
3
+ "version": "1.4.8",
4
4
  "description": "Bibliothèque de composants UI légère, intuitive et modulaire pour les interfaces web modernes.",
5
5
  "type": "module",
6
6
  "repository": {