@raketa-builder/ui 0.8.0 → 0.10.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,5 +1,5 @@
1
1
 
2
- > @raketa-builder/ui@0.8.0 build
2
+ > @raketa-builder/ui@0.10.0 build
3
3
  > tsup src/index.js --format cjs --loader ".js=jsx"
4
4
 
5
5
  CLI Building entry: src/index.js
@@ -7,5 +7,5 @@ CLI Using tsconfig: tsconfig.json
7
7
  CLI tsup v6.5.0
8
8
  CLI Target: es6
9
9
  CJS Build start
10
- CJS dist/index.js 30.99 KB
11
- CJS ⚡️ Build success in 164ms
10
+ CJS dist/index.js 31.03 KB
11
+ CJS ⚡️ Build success in 227ms
package/dist/index.js CHANGED
@@ -174,7 +174,19 @@ var P_default = P;
174
174
  var import_react3 = __toESM(require("react"));
175
175
  var import_jsx_runtime3 = require("react/jsx-runtime");
176
176
  var Button = (_a) => {
177
- var _b = _a, { as = "button", size, variant, className } = _b, rest = __objRest(_b, ["as", "size", "variant", "className"]);
177
+ var _b = _a, {
178
+ as = "button",
179
+ size = "md",
180
+ variant = "primary",
181
+ className,
182
+ type = "button"
183
+ } = _b, rest = __objRest(_b, [
184
+ "as",
185
+ "size",
186
+ "variant",
187
+ "className",
188
+ "type"
189
+ ]);
178
190
  const Component = as;
179
191
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
180
192
  Component,
@@ -190,11 +202,6 @@ var Button = (_a) => {
190
202
  }, rest)
191
203
  );
192
204
  };
193
- Button.defaultProps = {
194
- type: "button",
195
- size: "md",
196
- variant: "primary"
197
- };
198
205
  Button.variants = ["primary", "secondary", "success", "danger"];
199
206
  Button.sizes = {
200
207
  sm: "sm",
@@ -450,37 +457,47 @@ var Content = (_a) => {
450
457
  var _b = _a, { className } = _b, props = __objRest(_b, ["className"]);
451
458
  return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)("div", __spreadValues({ className: cn("r-reset", "r-modal-content", className) }, props));
452
459
  };
460
+ function checkForChanges(hasChanges, onClose) {
461
+ if (!hasChanges) {
462
+ onClose();
463
+ return;
464
+ }
465
+ if (!confirm(
466
+ "You\u2019ve made changes to the widget. Are you sure you want to cancel?"
467
+ ))
468
+ return;
469
+ onClose();
470
+ }
453
471
  var Modal = (_a) => {
454
472
  var _b = _a, {
455
473
  title,
456
474
  children,
457
475
  customWrapper,
458
476
  FooterContent,
459
- onClose
477
+ onClose,
478
+ areChanges
460
479
  } = _b, rest = __objRest(_b, [
461
480
  "title",
462
481
  "children",
463
482
  "customWrapper",
464
483
  "FooterContent",
465
- "onClose"
484
+ "onClose",
485
+ "areChanges"
466
486
  ]);
467
- const handleKeyUp = ({ key }) => {
468
- if (key === "Escape")
469
- onClose();
470
- };
471
- import_react17.default.useEffect(() => {
472
- document.addEventListener("keyup", handleKeyUp);
473
- return () => {
474
- document.removeEventListener("keyup", handleKeyUp);
475
- };
476
- });
477
487
  const ModalWrapper = customWrapper ? customWrapper : Wrapper;
478
488
  return /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(import_react17.default.Fragment, { children: [
479
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Overlay, { onClick: onClose }),
489
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Overlay, {}),
480
490
  /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(ModalWrapper, __spreadProps(__spreadValues({}, rest), { children: /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(Inner, { children: [
481
491
  /* @__PURE__ */ (0, import_jsx_runtime17.jsxs)(TitleBar, { children: [
482
492
  /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Title, { children: title }),
483
- /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(CloseButton, { type: "button", onClick: onClose, children: "\xD7" })
493
+ /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
494
+ CloseButton,
495
+ {
496
+ type: "button",
497
+ onClick: () => checkForChanges(areChanges, onClose),
498
+ children: "\xD7"
499
+ }
500
+ )
484
501
  ] }),
485
502
  /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(Content, { children }),
486
503
  FooterContent && /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(FooterBar, { children: /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(FooterContent, {}) })
@@ -729,7 +746,7 @@ var LanguageSwitcher_default = LanguageSwitcher;
729
746
  var import_react24 = __toESM(require("react"));
730
747
  var import_jsx_runtime24 = require("react/jsx-runtime");
731
748
  var ImageAvatar = (_a) => {
732
- var _b = _a, { size, className } = _b, props = __objRest(_b, ["size", "className"]);
749
+ var _b = _a, { size = "24px", className } = _b, props = __objRest(_b, ["size", "className"]);
733
750
  return /* @__PURE__ */ (0, import_jsx_runtime24.jsx)(
734
751
  "img",
735
752
  __spreadValues({
@@ -742,9 +759,6 @@ var ImageAvatar = (_a) => {
742
759
  }, props)
743
760
  );
744
761
  };
745
- ImageAvatar.defaultProps = {
746
- size: "24px"
747
- };
748
762
  var ImageAvatar_default = ImageAvatar;
749
763
 
750
764
  // src/DefaultAvatar.jsx
@@ -787,12 +801,8 @@ var DefaultAvatarStyles = (_a) => {
787
801
  );
788
802
  };
789
803
  var DefaultAvatar = (_a) => {
790
- var _b = _a, { initials } = _b, props = __objRest(_b, ["initials"]);
791
- return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(DefaultAvatarStyles, __spreadProps(__spreadValues({ initials }, props), { children: initials }));
792
- };
793
- DefaultAvatar.defaultProps = {
794
- size: "24px",
795
- initials: "AA"
804
+ var _b = _a, { initials = "AA", size = "24px" } = _b, props = __objRest(_b, ["initials", "size"]);
805
+ return /* @__PURE__ */ (0, import_jsx_runtime25.jsx)(DefaultAvatarStyles, __spreadProps(__spreadValues({ initials, size }, props), { children: initials }));
796
806
  };
797
807
  var DefaultAvatar_default = DefaultAvatar;
798
808
 
@@ -827,7 +837,7 @@ var CategoriesInner = (_a) => {
827
837
  var props = __objRest(_a, []);
828
838
  return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", __spreadProps(__spreadValues({}, props), { className: "r-reset r-categories-inner" }));
829
839
  };
830
- var CategoriesHiddenMenu = ({ paths }) => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: "r-reset r-categories-hidden-menu", children: paths.map(({ title, link }) => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("a", { href: link, className: "r-reset r-category-link", children: title })) });
840
+ var CategoriesHiddenMenu = ({ paths }) => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", { className: "r-reset r-categories-hidden-menu", children: paths.map(({ title, link }, idx) => /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("a", { href: link, className: "r-reset r-category-link", children: title }, `${idx}-${link}`)) });
831
841
  var CategoriesMenuWrapper = (_a) => {
832
842
  var props = __objRest(_a, []);
833
843
  return /* @__PURE__ */ (0, import_jsx_runtime26.jsx)("div", __spreadValues({ className: "r-reset r-categories-menu" }, props));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@raketa-builder/ui",
3
- "version": "0.8.0",
3
+ "version": "0.10.0",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "license": "MIT",
package/src/Button.jsx CHANGED
@@ -1,7 +1,14 @@
1
1
  import React from "react";
2
2
  import cn from "./cn";
3
3
 
4
- const Button = ({ as = "button", size, variant, className, ...rest }) => {
4
+ const Button = ({
5
+ as = "button",
6
+ size = "md",
7
+ variant = "primary",
8
+ className,
9
+ type = "button",
10
+ ...rest
11
+ }) => {
5
12
  const Component = as;
6
13
 
7
14
  return (
@@ -12,19 +19,13 @@ const Button = ({ as = "button", size, variant, className, ...rest }) => {
12
19
  "r-button",
13
20
  `r-button-${size}`,
14
21
  `r-button-${variant}`,
15
- className,
22
+ className
16
23
  )}
17
24
  {...rest}
18
25
  />
19
26
  );
20
27
  };
21
28
 
22
- Button.defaultProps = {
23
- type: "button",
24
- size: "md",
25
- variant: "primary",
26
- };
27
-
28
29
  Button.variants = ["primary", "secondary", "success", "danger"];
29
30
 
30
31
  Button.sizes = {
@@ -27,8 +27,8 @@ const CategoriesInner = ({ ...props }) => (
27
27
 
28
28
  const CategoriesHiddenMenu = ({ paths }) => (
29
29
  <div className="r-reset r-categories-hidden-menu">
30
- {paths.map(({ title, link }) => (
31
- <a href={link} className="r-reset r-category-link">
30
+ {paths.map(({ title, link }, idx) => (
31
+ <a key={`${idx}-${link}`} href={link} className="r-reset r-category-link">
32
32
  {title}
33
33
  </a>
34
34
  ))}
@@ -38,15 +38,10 @@ const DefaultAvatarStyles = ({ initials, size, className, ...props }) => (
38
38
  />
39
39
  );
40
40
 
41
- const DefaultAvatar = ({ initials, ...props }) => (
42
- <DefaultAvatarStyles initials={initials} {...props}>
41
+ const DefaultAvatar = ({ initials = "AA", size = "24px", ...props }) => (
42
+ <DefaultAvatarStyles initials={initials} size={size} {...props}>
43
43
  {initials}
44
44
  </DefaultAvatarStyles>
45
45
  );
46
46
 
47
- DefaultAvatar.defaultProps = {
48
- size: "24px",
49
- initials: "AA",
50
- };
51
-
52
47
  export default DefaultAvatar;
@@ -1,7 +1,7 @@
1
1
  import React from "react";
2
2
  import cn from "./cn";
3
3
 
4
- const ImageAvatar = ({ size, className, ...props }) => (
4
+ const ImageAvatar = ({ size = "24px", className, ...props }) => (
5
5
  <img
6
6
  alt=""
7
7
  style={{
@@ -13,8 +13,4 @@ const ImageAvatar = ({ size, className, ...props }) => (
13
13
  />
14
14
  );
15
15
 
16
- ImageAvatar.defaultProps = {
17
- size: "24px",
18
- };
19
-
20
16
  export default ImageAvatar;
package/src/Modal.jsx CHANGED
@@ -36,37 +36,45 @@ const Content = ({ className, ...props }) => (
36
36
  <div className={cn("r-reset", "r-modal-content", className)} {...props} />
37
37
  );
38
38
 
39
+ function checkForChanges(hasChanges, onClose) {
40
+ if (!hasChanges) {
41
+ onClose();
42
+ return;
43
+ }
44
+
45
+ if (
46
+ !confirm(
47
+ "You’ve made changes to the widget. Are you sure you want to cancel?"
48
+ )
49
+ )
50
+ return;
51
+
52
+ onClose();
53
+ }
54
+
39
55
  const Modal = ({
40
56
  title,
41
57
  children,
42
58
  customWrapper,
43
59
  FooterContent,
44
60
  onClose,
61
+ areChanges,
45
62
  ...rest
46
63
  }) => {
47
- const handleKeyUp = ({ key }) => {
48
- if (key === "Escape") onClose();
49
- };
50
-
51
- React.useEffect(() => {
52
- document.addEventListener("keyup", handleKeyUp);
53
-
54
- return () => {
55
- document.removeEventListener("keyup", handleKeyUp);
56
- };
57
- });
58
-
59
64
  const ModalWrapper = customWrapper ? customWrapper : Wrapper;
60
65
 
61
66
  return (
62
67
  <React.Fragment>
63
- <Overlay onClick={onClose} />
68
+ <Overlay />
64
69
 
65
70
  <ModalWrapper {...rest}>
66
71
  <Inner>
67
72
  <TitleBar>
68
73
  <Title>{title}</Title>
69
- <CloseButton type="button" onClick={onClose}>
74
+ <CloseButton
75
+ type="button"
76
+ onClick={() => checkForChanges(areChanges, onClose)}
77
+ >
70
78
  &times;
71
79
  </CloseButton>
72
80
  </TitleBar>
package/src/styles.css CHANGED
@@ -645,7 +645,6 @@
645
645
  left: 0;
646
646
  z-index: 1100;
647
647
  background-color: rgba(0, 0, 0, 0.6);
648
- cursor: pointer;
649
648
  }
650
649
 
651
650
  .r-modal-inner {