@symply.io/basic-components 1.4.6-alpha.1 → 1.4.7-alpha.1

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,4 +1,5 @@
1
- import type { BasicModalProps } from "./types";
2
- declare function BasicModal(props: BasicModalProps): JSX.Element;
3
- export default BasicModal;
4
- export type { BasicModalProps };
1
+ /// <reference types="react" />
2
+ import type { BasicModalProps, BasicModalRefProps } from "./types";
3
+ declare const BasicModalWithRefForward: import("react").ForwardRefExoticComponent<Pick<BasicModalProps, "maxWidth" | "classes" | "slot" | "style" | "title" | "desc" | "className" | "children" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "contentEditable" | "contextMenu" | "dir" | "draggable" | "hidden" | "id" | "lang" | "placeholder" | "spellCheck" | "tabIndex" | "translate" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "color" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture" | "open" | "sx" | "transitionDuration" | "components" | "componentsProps" | "key" | "nonce" | "BackdropComponent" | "BackdropProps" | "closeAfterTransition" | "container" | "disableAutoFocus" | "disableEnforceFocus" | "disableEscapeKeyDown" | "disablePortal" | "disableRestoreFocus" | "disableScrollLock" | "hideBackdrop" | "keepMounted" | "onBackdropClick" | "onClose" | "primaryColor" | "secondaryColor" | "disabled" | "fullWidth" | "fullScreen" | "TransitionComponent" | "loading" | "buttons" | "noForm" | "submitText" | "cancelText" | "hideBottomButtons" | "showTopRightCloseButton" | "PaperComponent" | "PaperProps" | "scroll" | "TransitionProps"> & import("react").RefAttributes<BasicModalRefProps>>;
4
+ export default BasicModalWithRefForward;
5
+ export type { BasicModalProps, BasicModalRefProps };
@@ -57,7 +57,7 @@ var __rest = (this && this.__rest) || function (s, e) {
57
57
  return t;
58
58
  };
59
59
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
60
- import { useCallback, forwardRef, cloneElement, useRef } from "react";
60
+ import { useRef, forwardRef, useCallback, cloneElement, useImperativeHandle } from "react";
61
61
  import Grid from "@mui/material/Grid";
62
62
  import Button from "@mui/material/Button";
63
63
  import Dialog from "@mui/material/Dialog";
@@ -74,9 +74,12 @@ import useCustomTheme from "../useCustomTheme";
74
74
  var Transition = forwardRef(function Transition(props, ref) {
75
75
  return _jsx(Slide, __assign({ direction: "up" }, props, { ref: ref }));
76
76
  });
77
- function BasicModal(props) {
77
+ function BasicModal(props, ref) {
78
78
  var _this = this;
79
79
  var desc = props.desc, title = props.title, loading = props.loading, buttons = props.buttons, _a = props.open, open = _a === void 0 ? false : _a, _b = props.noForm, noForm = _b === void 0 ? false : _b, children = props.children, disabled = props.disabled, _c = props.maxWidth, maxWidth = _c === void 0 ? "sm" : _c, _d = props.color, color = _d === void 0 ? "primary" : _d, _e = props.submitText, submitText = _e === void 0 ? "Save" : _e, _f = props.cancelText, cancelText = _f === void 0 ? "Cancel" : _f, _g = props.hideBottomButtons, hideBottomButtons = _g === void 0 ? false : _g, _h = props.showTopRightCloseButton, showTopRightCloseButton = _h === void 0 ? false : _h, onClose = props.onClose, onSubmit = props.onSubmit, primaryColor = props.primaryColor, secondaryColor = props.secondaryColor, rest = __rest(props, ["desc", "title", "loading", "buttons", "open", "noForm", "children", "disabled", "maxWidth", "color", "submitText", "cancelText", "hideBottomButtons", "showTopRightCloseButton", "onClose", "onSubmit", "primaryColor", "secondaryColor"]);
80
+ if (!noForm && !buttons && !onSubmit) {
81
+ throw new Error("Error from @symply.io/basic-components/BasicModal: `onSubmit` is required when there are no custom buttons and `noForm` is true.");
82
+ }
80
83
  var formRef = useRef(null);
81
84
  var theme = useCustomTheme({ primaryColor: primaryColor, secondaryColor: secondaryColor });
82
85
  var fullScreen = useMediaQuery(theme.breakpoints.down("sm"));
@@ -90,7 +93,9 @@ function BasicModal(props) {
90
93
  if (!!allValid) return [3, 1];
91
94
  formRef.current.reportValidity();
92
95
  return [3, 3];
93
- case 1: return [4, onSubmit()];
96
+ case 1:
97
+ if (!onSubmit) return [3, 3];
98
+ return [4, onSubmit()];
94
99
  case 2:
95
100
  _a.sent();
96
101
  _a.label = 3;
@@ -98,6 +103,7 @@ function BasicModal(props) {
98
103
  }
99
104
  });
100
105
  }); }, [onSubmit]);
106
+ useImperativeHandle(ref, function () { return ({ onSubmit: noForm ? onSubmit : onFormSubmit }); }, [noForm, onSubmit, onFormSubmit]);
101
107
  return (_jsx(ThemeProvider, __assign({ theme: theme }, { children: _jsxs(Dialog, __assign({ disableEnforceFocus: true, open: open, onClose: function (_, reason) {
102
108
  if (reason !== "backdropClick") {
103
109
  onClose();
@@ -113,4 +119,6 @@ function BasicModal(props) {
113
119
  color: theme.palette.grey[500]
114
120
  } }, { children: _jsx(CloseIcon, {}) }))) : (_jsx(_Fragment, {}))] })), _jsx(DialogContent, __assign({ sx: { paddingTop: theme.spacing(1.25) } }, { children: _jsxs(Grid, __assign({ component: noForm ? "div" : "form", ref: noForm ? undefined : formRef }, { children: [desc && _jsx(DialogContentText, { children: desc }), Boolean(children) && cloneElement(children)] })) })), !hideBottomButtons && (_jsx(DialogActions, __assign({ sx: { padding: theme.spacing(1.25) } }, { children: _jsx(Grid, __assign({ container: true, spacing: 2, justifyContent: "flex-end", alignItems: "center", sx: { margin: 0 } }, { children: buttons || (_jsxs(_Fragment, { children: [_jsx(Grid, __assign({ item: true, xs: 12, md: 3, xl: 2 }, { children: _jsx(Button, __assign({ onClick: onClose, variant: "outlined", color: color, disabled: loading, fullWidth: true }, { children: cancelText })) })), _jsx(Grid, __assign({ item: true, xs: 12, md: 3, xl: 2 }, { children: _jsx(Button, __assign({ type: noForm ? "button" : "submit", onClick: noForm ? onSubmit : onFormSubmit, variant: "contained", color: color, disabled: loading || disabled, fullWidth: true }, { children: submitText })) }))] })) })) })))] })) })));
115
121
  }
116
- export default BasicModal;
122
+ var BasicModalWithRefForward = forwardRef(BasicModal);
123
+ BasicModalWithRefForward.displayName = "BasicModal";
124
+ export default BasicModalWithRefForward;
@@ -13,8 +13,11 @@ export interface BasicModalProps extends DialogProps {
13
13
  hideBottomButtons?: boolean;
14
14
  noForm?: boolean;
15
15
  onClose: () => unknown | Promise<unknown>;
16
- onSubmit: () => unknown | Promise<unknown>;
16
+ onSubmit?: () => unknown | Promise<unknown>;
17
17
  primaryColor?: CSSProperties["color"];
18
18
  secondaryColor?: CSSProperties["color"];
19
19
  showTopRightCloseButton?: boolean;
20
20
  }
21
+ export declare type BasicModalRefProps = {
22
+ onSubmit?: () => unknown | Promise<unknown>;
23
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@symply.io/basic-components",
3
- "version": "1.4.6-alpha.1",
3
+ "version": "1.4.7-alpha.1",
4
4
  "description": "Basic and reusable components for all frontend of Symply apps",
5
5
  "keywords": [
6
6
  "react",