@ttoss/components 2.4.5 → 2.5.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,32 +1,11 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { IconifyIcon } from '@ttoss/react-icons';
3
- import { BoxProps } from '@ttoss/ui';
4
2
  import * as React from 'react';
5
3
 
6
4
  type MenuProps = {
7
- onClose: () => void;
8
- onOpen: () => void;
9
- isOpen: boolean;
10
5
  children: React.ReactNode;
11
- srcLogo?: string;
12
- sx?: BoxProps['sx'];
13
- /**
14
- * Default direction: `left`
15
- */
16
- direction?: 'left' | 'right';
17
- /**
18
- * Default size: `100%`
19
- */
20
- sizeOnMobile?: string | number;
21
- /**
22
- * Default size: `300px`
23
- */
24
- sizeOnDesktop?: string | number;
25
- /**
26
- * Default icon: `menu-open`
27
- */
28
- menuIcon?: IconifyIcon | string;
6
+ sx?: Record<string, unknown>;
7
+ menuIcon?: string;
29
8
  };
30
- declare const Menu: ({ children, srcLogo, onClose, onOpen, isOpen, sx, direction, sizeOnDesktop, sizeOnMobile, menuIcon, }: MenuProps) => react_jsx_runtime.JSX.Element;
9
+ declare const Menu: ({ children, sx, menuIcon }: MenuProps) => react_jsx_runtime.JSX.Element;
31
10
 
32
11
  export { Menu, type MenuProps };
@@ -3,135 +3,129 @@ import { Icon } from "../chunk-AZTAV4VC.js";
3
3
  import { __name } from "../chunk-V4MHYKRI.js";
4
4
 
5
5
  // src/components/Menu/Menu.tsx
6
- import { Box as Box2, Flex, Image, Text, useResponsiveValue } from "@ttoss/ui";
7
- import * as React2 from "react";
8
-
9
- // src/components/Drawer/Drawer.tsx
10
- import { Box } from "@ttoss/ui";
6
+ import { Box, Flex } from "@ttoss/ui";
11
7
  import * as React from "react";
12
- import DrawerUi from "react-modern-drawer";
13
- var Drawer = /* @__PURE__ */__name(({
14
- children,
15
- sx,
16
- ...props
17
- }) => {
18
- return /* @__PURE__ */React.createElement(Box, {
19
- "data-testid": "drawer-container",
20
- sx: {
21
- /**
22
- * https://github.com/Farzin-Firoozi/react-modern-drawer/blob/master/src/styles.css
23
- */
24
- zIndex: "overlay",
25
- width: "100%",
26
- height: "100%",
27
- ".EZDrawer__checkbox": {
28
- display: "none"
29
- },
30
- ".EZDrawer__checkbox:checked ~ .EZDrawer__overlay": {
31
- display: "block",
32
- opacity: 1
33
- },
34
- ".EZDrawer__checkbox:checked ~ .EZDrawer__container": {
35
- visibility: "visible",
36
- transform: "translate3d(0, 0, 0) !important"
37
- },
38
- ".EZDrawer__overlay ": {
39
- display: "none",
40
- height: "100vh",
41
- left: "0",
42
- position: "fixed",
43
- top: "0",
44
- width: "100%"
45
- },
46
- ".EZDrawer__container": {
47
- position: "fixed",
48
- visibility: "hidden",
49
- backgroundColor: "navigation.background.muted.default",
50
- transition: "all",
51
- boxShadow: "0 0 10px 5px rgba(0, 0, 0, 0.1)",
52
- paddingX: "6",
53
- overflowY: "auto"
54
- },
55
- ...sx
56
- }
57
- }, /* @__PURE__ */React.createElement(DrawerUi, props, /* @__PURE__ */React.createElement(Box, {
58
- sx: {
59
- width: "100%",
60
- height: "100%"
61
- }
62
- }, children)));
63
- }, "Drawer");
64
-
65
- // src/components/Menu/Menu.tsx
66
8
  var Menu = /* @__PURE__ */__name(({
67
9
  children,
68
- srcLogo,
69
- onClose,
70
- onOpen,
71
- isOpen,
72
10
  sx,
73
- direction = "left",
74
- sizeOnDesktop = "300px",
75
- sizeOnMobile = "100%",
76
11
  menuIcon = "menu-open"
77
12
  }) => {
78
- const responsiveSize = useResponsiveValue([sizeOnMobile, sizeOnDesktop]);
79
- return /* @__PURE__ */React2.createElement(React2.Fragment, null, /* @__PURE__ */React2.createElement(Text, {
80
- sx: {
81
- cursor: "pointer"
82
- },
83
- onClick: onOpen
84
- }, /* @__PURE__ */React2.createElement(Icon, {
85
- icon: menuIcon
86
- })), /* @__PURE__ */React2.createElement(Drawer, {
87
- size: responsiveSize,
88
- direction,
89
- open: isOpen
90
- }, /* @__PURE__ */React2.createElement(Box2, {
13
+ const [isOpen, setIsOpen] = React.useState(false);
14
+ const [stylePos, setStylePos] = React.useState({});
15
+ const triggerRef = React.useRef(null);
16
+ const panelRef = React.useRef(null);
17
+ const toggle = /* @__PURE__ */__name(() => {
18
+ return setIsOpen(v => {
19
+ return !v;
20
+ });
21
+ }, "toggle");
22
+ React.useEffect(() => {
23
+ if (!isOpen) return;
24
+ const onDocClick = /* @__PURE__ */__name(e => {
25
+ const t = e.target;
26
+ if (panelRef.current && !panelRef.current.contains(t) && triggerRef.current && !triggerRef.current.contains(t)) {
27
+ setIsOpen(false);
28
+ }
29
+ }, "onDocClick");
30
+ document.addEventListener("mousedown", onDocClick);
31
+ return () => {
32
+ return document.removeEventListener("mousedown", onDocClick);
33
+ };
34
+ }, [isOpen]);
35
+ React.useLayoutEffect(() => {
36
+ if (!isOpen) return;
37
+ let rafId = 0;
38
+ const getWidth = /* @__PURE__ */__name(() => {
39
+ const w = sx?.width ?? sx?.maxWidth ?? sx?.minWidth;
40
+ return Array.isArray(w) ? w[w.length - 1] : w;
41
+ }, "getWidth");
42
+ const compute = /* @__PURE__ */__name(() => {
43
+ const trigger = triggerRef.current;
44
+ const panel2 = panelRef.current;
45
+ if (!trigger || !panel2) return;
46
+ const width = getWidth();
47
+ if (width) panel2.style.width = typeof width === "number" ? `${width}px` : String(width);
48
+ const tr = trigger.getBoundingClientRect();
49
+ const pr = panel2.getBoundingClientRect();
50
+ const vw = window.innerWidth,
51
+ vh = window.innerHeight,
52
+ m = 8;
53
+ if (pr.width === 0) {
54
+ rafId = requestAnimationFrame(compute);
55
+ return;
56
+ }
57
+ const left = Math.max(m, Math.min(tr.left + tr.width / 2 - pr.width / 2, vw - pr.width - m));
58
+ const top = vh - tr.bottom < pr.height + m ? Math.max(m, tr.top - pr.height - m) : tr.bottom + m;
59
+ setStylePos({
60
+ position: "fixed",
61
+ left: `${left}px`,
62
+ top: `${top}px`,
63
+ zIndex: 9999,
64
+ ...(width && {
65
+ width: typeof width === "number" ? `${width}px` : String(width)
66
+ })
67
+ });
68
+ }, "compute");
69
+ rafId = requestAnimationFrame(compute);
70
+ const onResizeScroll = /* @__PURE__ */__name(() => {
71
+ return rafId = requestAnimationFrame(compute);
72
+ }, "onResizeScroll");
73
+ window.addEventListener("resize", onResizeScroll);
74
+ window.addEventListener("scroll", onResizeScroll, true);
75
+ return () => {
76
+ cancelAnimationFrame(rafId);
77
+ window.removeEventListener("resize", onResizeScroll);
78
+ window.removeEventListener("scroll", onResizeScroll, true);
79
+ };
80
+ }, [isOpen, children, sx]);
81
+ const panel = isOpen ? /* @__PURE__ */React.createElement(Flex, {
82
+ ref: panelRef,
91
83
  sx: {
92
- position: "fixed",
93
- height: "100%",
94
- backgroundColor: "background",
95
- width: "100%",
96
- maxWidth: "2",
97
- right: 0,
98
- boxShadow: "4",
99
- paddingX: "5",
100
- paddingTop: "4",
101
- paddingBottom: "6",
84
+ width: ["280px", "320px"],
85
+ maxHeight: "400px",
86
+ flexDirection: "column",
87
+ gap: "3",
88
+ padding: "3",
89
+ backgroundColor: "input.background.muted.default",
90
+ borderRadius: "xl",
91
+ boxShadow: "xl",
92
+ overflowY: "auto",
93
+ border: "md",
94
+ borderColor: "display.border.muted.default",
102
95
  ...sx
96
+ },
97
+ style: {
98
+ pointerEvents: "auto",
99
+ ...stylePos
103
100
  }
104
- }, /* @__PURE__ */React2.createElement(Flex, {
101
+ }, /* @__PURE__ */React.createElement(Box, {
102
+ as: "nav"
103
+ }, children)) : null;
104
+ return /* @__PURE__ */React.createElement(Flex, {
105
105
  sx: {
106
- justifyContent: "space-between"
106
+ position: "relative",
107
+ display: "inline-block"
107
108
  }
108
- }, /* @__PURE__ */React2.createElement(Image, {
109
- src: srcLogo,
110
- sx: {
111
- maxWidth: "200px",
112
- height: "44px",
113
- objectFit: "cover"
114
- },
115
- "data-testid": "img"
116
- }), /* @__PURE__ */React2.createElement(Text, {
117
- "data-testid": "button",
109
+ }, /* @__PURE__ */React.createElement(Box, {
118
110
  sx: {
119
- marginLeft: "auto",
120
- fontSize: "2xl",
121
- alignSelf: "center",
122
- flexShrink: 0,
111
+ position: "relative"
112
+ }
113
+ }, /* @__PURE__ */React.createElement("button", {
114
+ ref: triggerRef,
115
+ onClick: toggle,
116
+ "aria-haspopup": "true",
117
+ "aria-expanded": isOpen,
118
+ style: {
119
+ background: "transparent",
120
+ border: 0,
121
+ padding: 4,
123
122
  cursor: "pointer",
124
- lineHeight: 0
125
- },
126
- role: "button",
127
- onClick: onClose
128
- }, /* @__PURE__ */React2.createElement(Icon, {
129
- icon: "close"
130
- }))), /* @__PURE__ */React2.createElement(Box2, {
131
- sx: {
132
- paddingTop: "6"
133
- },
134
- as: "nav"
135
- }, children))));
123
+ display: "inline-flex",
124
+ alignItems: "center",
125
+ justifyContent: "center"
126
+ }
127
+ }, /* @__PURE__ */React.createElement(Icon, {
128
+ icon: menuIcon
129
+ })), isOpen && panel));
136
130
  }, "Menu");
137
131
  export { Menu };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttoss/components",
3
- "version": "2.4.5",
3
+ "version": "2.5.0",
4
4
  "description": "React components for ttoss ecosystem.",
5
5
  "license": "MIT",
6
6
  "author": "ttoss",
@@ -101,9 +101,9 @@
101
101
  },
102
102
  "peerDependencies": {
103
103
  "react": ">=16.8.0",
104
- "@ttoss/react-i18n": "^2.0.18",
105
104
  "@ttoss/react-hooks": "^2.1.4",
106
- "@ttoss/ui": "^5.10.2"
105
+ "@ttoss/ui": "^5.10.2",
106
+ "@ttoss/react-i18n": "^2.0.18"
107
107
  },
108
108
  "devDependencies": {
109
109
  "@types/jest": "^30.0.0",
@@ -112,13 +112,13 @@
112
112
  "react": "^19.1.0",
113
113
  "tsup": "^8.5.0",
114
114
  "tsx": "^4.19.2",
115
- "@ttoss/i18n-cli": "^0.7.34",
116
115
  "@ttoss/config": "^1.35.8",
117
- "@ttoss/react-i18n": "^2.0.18",
118
- "@ttoss/ui": "^5.10.2",
116
+ "@ttoss/i18n-cli": "^0.7.34",
117
+ "@ttoss/react-hooks": "^2.1.4",
119
118
  "@ttoss/react-icons": "^0.4.17",
119
+ "@ttoss/ui": "^5.10.2",
120
120
  "@ttoss/test-utils": "^2.1.28",
121
- "@ttoss/react-hooks": "^2.1.4"
121
+ "@ttoss/react-i18n": "^2.0.18"
122
122
  },
123
123
  "keywords": [
124
124
  "React",