@expressms/smartapp-ui 1.1.3 → 1.1.5

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,4 @@
1
1
  import { IActionModalProps } from './types';
2
2
  import '../../styles/stories.module.scss';
3
- declare const ActionModal: ({ isModalOpen, title, buttonName, confirmButtonFunction, cancelButtonFunction, placeholder, defaultValue, iconColor, buttonWidth, backgroundColor, }: IActionModalProps) => import("react/jsx-runtime").JSX.Element;
3
+ declare const ActionModal: ({ isModalOpen, title, buttonName, confirmButtonFunction, cancelButtonFunction, platform, placeholder, defaultValue, isButtonDisabled, iconColor, buttonWidth, backgroundColor, }: IActionModalProps) => import("react/jsx-runtime").JSX.Element;
4
4
  export default ActionModal;
@@ -16,17 +16,24 @@ import { ReactComponent as CancelIcon } from '../../assets/icons/cancel-cross.sv
16
16
  import Button from '../Button';
17
17
  import Input from '../Input';
18
18
  import { TButtonColor, TButtonType } from '../Button/types';
19
- import { getColor } from '../../helpers';
20
- import { DEFAULT_GRAY_ICON_COLOR } from '../../constants';
19
+ import { getClassNames, getColor, isMobilePlatform } from '../../helpers';
20
+ import { DEFAULT_GRAY_ICON_COLOR, DEFAULT_POPUP_BACKGROUND_COLOR, PLATFORM } from '../../constants';
21
21
  import '../../styles/stories.module.scss';
22
22
  var ActionModal = function (_a) {
23
- var isModalOpen = _a.isModalOpen, title = _a.title, buttonName = _a.buttonName, confirmButtonFunction = _a.confirmButtonFunction, cancelButtonFunction = _a.cancelButtonFunction, placeholder = _a.placeholder, _b = _a.defaultValue, defaultValue = _b === void 0 ? '' : _b, iconColor = _a.iconColor, _c = _a.buttonWidth, buttonWidth = _c === void 0 ? 100 : _c, backgroundColor = _a.backgroundColor;
24
- var _d = useState(defaultValue), value = _d[0], setValue = _d[1];
25
- var ref = useRef();
23
+ var isModalOpen = _a.isModalOpen, title = _a.title, buttonName = _a.buttonName, confirmButtonFunction = _a.confirmButtonFunction, cancelButtonFunction = _a.cancelButtonFunction, _b = _a.platform, platform = _b === void 0 ? PLATFORM.web : _b, placeholder = _a.placeholder, _c = _a.defaultValue, defaultValue = _c === void 0 ? '' : _c, isButtonDisabled = _a.isButtonDisabled, iconColor = _a.iconColor, _d = _a.buttonWidth, buttonWidth = _d === void 0 ? 100 : _d, backgroundColor = _a.backgroundColor;
24
+ var ref = useRef(null);
25
+ var _e = useState(defaultValue), value = _e[0], setValue = _e[1];
26
+ var onConfirmClick = function () {
27
+ confirmButtonFunction(value);
28
+ setValue('');
29
+ };
26
30
  var onCloseModal = function () {
27
31
  setValue('');
28
32
  cancelButtonFunction();
29
33
  };
34
+ useEffect(function () {
35
+ document.documentElement.style.setProperty('--action-modal-background', getColor(backgroundColor, DEFAULT_POPUP_BACKGROUND_COLOR));
36
+ }, [backgroundColor]);
30
37
  useEffect(function () {
31
38
  var checkIfClickedOutside = function (e) {
32
39
  if (isModalOpen && ref.current && !ref.current.contains(e.target)) {
@@ -37,10 +44,11 @@ var ActionModal = function (_a) {
37
44
  return function () {
38
45
  document === null || document === void 0 ? void 0 : document.removeEventListener('click', checkIfClickedOutside, true);
39
46
  };
47
+ // eslint-disable-next-line
40
48
  }, [isModalOpen, cancelButtonFunction]);
41
49
  var onChange = function (value) {
42
50
  setValue(value);
43
51
  };
44
- return (_jsx(Popup, __assign({ closeOnDocumentClick: true, modal: true, open: isModalOpen }, { children: _jsx("div", __assign({ ref: ref, className: "smartapp-action-modal" }, { children: _jsxs("div", __assign({ className: "smartapp-action-modal__content" }, { children: [_jsx("p", __assign({ className: "smartapp-action-modal__content--title" }, { children: title })), _jsx("div", __assign({ onClick: onCloseModal, className: "smartapp-action-modal__content__cancel-cross" }, { children: _jsx(CancelIcon, { style: { color: getColor(iconColor, DEFAULT_GRAY_ICON_COLOR) } }) })), _jsx("div", __assign({ className: "smartapp-action-modal__content--input" }, { children: _jsx(Input, { defaultValue: value, placeholder: placeholder, onChange: onChange }) })), _jsx("div", __assign({ className: "smartapp-action-modal__content--buttons" }, { children: _jsx(Button, { width: buttonWidth, title: buttonName, typeButton: TButtonType.standard, color: TButtonColor.blue, onClickFunction: function () { return confirmButtonFunction(value); } }) }))] })) })) })));
52
+ return (_jsx(Popup, __assign({ className: getClassNames('action-modal', '-', platform), closeOnDocumentClick: true, modal: true, open: isModalOpen }, { children: _jsx("div", __assign({ ref: ref, className: getClassNames('smartapp-action-modal', '__', platform) }, { children: _jsxs("div", __assign({ className: getClassNames('smartapp-action-modal__content', '--', platform) }, { children: [_jsx("p", __assign({ className: getClassNames('smartapp-action-modal__content--title', '__', platform) }, { children: title })), _jsx("div", __assign({ onClick: onCloseModal, className: "smartapp-action-modal__content--cancel-cross" }, { children: _jsx(CancelIcon, { style: { color: getColor(iconColor, DEFAULT_GRAY_ICON_COLOR) } }) })), _jsx("div", __assign({ className: "smartapp-action-modal__content--input" }, { children: _jsx(Input, { defaultValue: value, placeholder: placeholder, onChange: onChange }) })), isMobilePlatform(platform) && _jsx("div", { className: "smartapp-action-modal__content--delimiter" }), _jsx("div", __assign({ className: "smartapp-action-modal__content--buttons" }, { children: _jsx(Button, { width: buttonWidth, isDisabled: isButtonDisabled, title: buttonName, typeButton: TButtonType.standard, color: TButtonColor.blue, onClickFunction: onConfirmClick }) }))] })) })) })));
45
53
  };
46
54
  export default ActionModal;
@@ -5,8 +5,10 @@ export interface IActionModalProps {
5
5
  buttonName: string;
6
6
  confirmButtonFunction: (str: string) => void;
7
7
  cancelButtonFunction: () => void;
8
+ platform?: 'web' | 'ios' | 'android';
8
9
  placeholder?: string;
9
10
  defaultValue?: string;
11
+ isButtonDisabled?: boolean;
10
12
  iconColor?: string;
11
13
  buttonWidth?: IntRange<1, 101>;
12
14
  backgroundColor?: string;
@@ -1,4 +1,4 @@
1
1
  import { IConfirmationModalProps } from './types';
2
2
  import '../../styles/stories.module.scss';
3
- declare const ConfirmationModal: ({ title, text, cancelButtonName, confirmButtonName, cancelButtonFunction, confirmButtonFunction, isModalOpen, }: IConfirmationModalProps) => import("react/jsx-runtime").JSX.Element;
3
+ declare const ConfirmationModal: ({ isModalOpen, title, text, cancelButtonName, confirmButtonName, cancelButtonFunction, confirmButtonFunction, platform, backgroundColor, }: IConfirmationModalProps) => import("react/jsx-runtime").JSX.Element;
4
4
  export default ConfirmationModal;
@@ -14,10 +14,15 @@ import { useEffect, useRef } from 'react';
14
14
  import Popup from 'reactjs-popup';
15
15
  import Button from '../Button';
16
16
  import { TButtonColor, TButtonType } from '../Button/types';
17
+ import { DEFAULT_POPUP_BACKGROUND_COLOR, PLATFORM } from '../../constants';
18
+ import { getClassNames, getColor, isMobilePlatform } from '../../helpers';
17
19
  import '../../styles/stories.module.scss';
18
20
  var ConfirmationModal = function (_a) {
19
- var title = _a.title, text = _a.text, cancelButtonName = _a.cancelButtonName, confirmButtonName = _a.confirmButtonName, cancelButtonFunction = _a.cancelButtonFunction, confirmButtonFunction = _a.confirmButtonFunction, isModalOpen = _a.isModalOpen;
20
- var ref = useRef();
21
+ var isModalOpen = _a.isModalOpen, title = _a.title, text = _a.text, cancelButtonName = _a.cancelButtonName, confirmButtonName = _a.confirmButtonName, cancelButtonFunction = _a.cancelButtonFunction, confirmButtonFunction = _a.confirmButtonFunction, _b = _a.platform, platform = _b === void 0 ? PLATFORM.web : _b, backgroundColor = _a.backgroundColor;
22
+ var ref = useRef(null);
23
+ useEffect(function () {
24
+ document.documentElement.style.setProperty('--confirmation-modal-background', getColor(backgroundColor, DEFAULT_POPUP_BACKGROUND_COLOR));
25
+ }, [backgroundColor]);
21
26
  useEffect(function () {
22
27
  var checkIfClickedOutside = function (e) {
23
28
  if (isModalOpen && ref.current && !ref.current.contains(e.target)) {
@@ -29,6 +34,6 @@ var ConfirmationModal = function (_a) {
29
34
  document === null || document === void 0 ? void 0 : document.removeEventListener('click', checkIfClickedOutside, true);
30
35
  };
31
36
  }, [isModalOpen, cancelButtonFunction]);
32
- return (_jsx(Popup, __assign({ closeOnDocumentClick: true, modal: true, open: isModalOpen }, { children: _jsx("div", __assign({ ref: ref, className: "smartapp-confirmation-modal" }, { children: _jsxs("div", __assign({ className: "smartapp-confirmation-modal__content" }, { children: [_jsx("p", __assign({ className: "smartapp-confirmation-modal__content--title" }, { children: title })), _jsx("p", __assign({ className: "smartapp-confirmation-modal__content--text" }, { children: text })), _jsxs("div", __assign({ className: "smartapp-confirmation-modal__content--buttons" }, { children: [_jsx(Button, { width: 50, title: cancelButtonName, typeButton: TButtonType.standard, onClickFunction: cancelButtonFunction, color: TButtonColor.white }), _jsx(Button, { width: 50, title: confirmButtonName, typeButton: TButtonType.standard, onClickFunction: confirmButtonFunction, color: TButtonColor.blue })] }))] })) })) })));
37
+ return (_jsx(Popup, __assign({ className: getClassNames('confirmation-modal', '-', platform), closeOnDocumentClick: true, modal: true, open: isModalOpen }, { children: _jsx("div", __assign({ ref: ref, className: getClassNames('smartapp-confirmation-modal', '__', platform) }, { children: _jsxs("div", __assign({ className: getClassNames('smartapp-confirmation-modal__content', '--', platform) }, { children: [title && _jsx("p", __assign({ className: "smartapp-confirmation-modal__content--title" }, { children: title })), _jsx("p", __assign({ className: "smartapp-confirmation-modal__content--text" }, { children: text })), isMobilePlatform(platform) && _jsx("div", { className: "smartapp-confirmation-modal__content--delimiter" }), _jsxs("div", __assign({ className: "smartapp-confirmation-modal__content--buttons" }, { children: [_jsx(Button, { width: 50, title: cancelButtonName, typeButton: TButtonType.standard, onClickFunction: cancelButtonFunction, color: TButtonColor.white }), _jsx(Button, { width: 50, title: confirmButtonName, typeButton: TButtonType.standard, onClickFunction: confirmButtonFunction, color: TButtonColor.blue })] }))] })) })) })));
33
38
  };
34
39
  export default ConfirmationModal;
@@ -1,9 +1,11 @@
1
1
  export interface IConfirmationModalProps {
2
- title: string;
2
+ isModalOpen: boolean;
3
+ title?: string;
3
4
  text: string;
4
5
  cancelButtonName: string;
5
6
  confirmButtonName: string;
6
7
  cancelButtonFunction: () => void;
7
8
  confirmButtonFunction: (option?: any) => void;
8
- isModalOpen: boolean;
9
+ platform?: 'web' | 'ios' | 'android';
10
+ backgroundColor?: string;
9
11
  }
@@ -1,4 +1,4 @@
1
1
  import { IInputProps } from './types';
2
2
  import '../../styles/stories.module.scss';
3
- declare const Input: ({ onChange, title, placeholder, defaultValue, error, width, className, autoFocus, isPassword, }: IInputProps) => import("react/jsx-runtime").JSX.Element;
3
+ declare const Input: ({ isPassword, isClearable, autoFocus, title, placeholder, defaultValue, error, textSize, width, className, onChange, onEnterPress, onClearClick, }: IInputProps) => import("react/jsx-runtime").JSX.Element;
4
4
  export default Input;
@@ -14,13 +14,14 @@ import { useRef, useState, useEffect } from 'react';
14
14
  import classNames from 'classnames';
15
15
  import { ReactComponent as IconEye } from '../../assets/icons/icon-eye.svg';
16
16
  import { ReactComponent as IconEyeClosed } from '../../assets/icons/icon-eye-off.svg';
17
- import { INPUT_TYPE_PASSWORD, INPUT_TYPE_TEXT } from '../../constants';
17
+ import { ReactComponent as ClearIcon } from '../../assets/icons/clear.svg';
18
+ import { ENTER_KEY, FONT_SIZE, INPUT_TYPE_PASSWORD, INPUT_TYPE_TEXT, LINE_HEIGHT } from '../../constants';
18
19
  import '../../styles/stories.module.scss';
19
20
  var Input = function (_a) {
20
21
  var _b;
21
- var onChange = _a.onChange, title = _a.title, placeholder = _a.placeholder, defaultValue = _a.defaultValue, error = _a.error, _c = _a.width, width = _c === void 0 ? 100 : _c, _d = _a.className, className = _d === void 0 ? '' : _d, _e = _a.autoFocus, autoFocus = _e === void 0 ? false : _e, _f = _a.isPassword, isPassword = _f === void 0 ? false : _f;
22
- var _g = useState(false), isPasswordShown = _g[0], setPasswordShown = _g[1];
22
+ var _c = _a.isPassword, isPassword = _c === void 0 ? false : _c, _d = _a.isClearable, isClearable = _d === void 0 ? false : _d, _e = _a.autoFocus, autoFocus = _e === void 0 ? false : _e, title = _a.title, placeholder = _a.placeholder, defaultValue = _a.defaultValue, error = _a.error, _f = _a.textSize, textSize = _f === void 0 ? 'small' : _f, _g = _a.width, width = _g === void 0 ? 100 : _g, _h = _a.className, className = _h === void 0 ? '' : _h, onChange = _a.onChange, onEnterPress = _a.onEnterPress, onClearClick = _a.onClearClick;
23
23
  var inputRef = useRef(null);
24
+ var _j = useState(false), isPasswordShown = _j[0], setIsPasswordShown = _j[1];
24
25
  useEffect(function () {
25
26
  var inputElement = inputRef.current;
26
27
  if (inputElement && inputElement.value.length) {
@@ -30,17 +31,27 @@ var Input = function (_a) {
30
31
  inputElement.focus();
31
32
  }
32
33
  }, [isPasswordShown]);
34
+ var getTextStyles = function () { return ({
35
+ fontSize: FONT_SIZE[textSize],
36
+ lineHeight: LINE_HEIGHT[textSize],
37
+ }); };
33
38
  var getInputType = function () {
34
39
  if (isPassword) {
35
40
  return isPasswordShown ? INPUT_TYPE_TEXT : INPUT_TYPE_PASSWORD;
36
41
  }
37
42
  return INPUT_TYPE_TEXT;
38
43
  };
44
+ var handleKeyDown = function (_a) {
45
+ var key = _a.key;
46
+ if (key === ENTER_KEY && onEnterPress) {
47
+ onEnterPress();
48
+ }
49
+ };
39
50
  var onClickButton = function () {
40
51
  var _a, _b;
41
- setPasswordShown(!isPasswordShown);
52
+ setIsPasswordShown(!isPasswordShown);
42
53
  !((_a = inputRef.current) === null || _a === void 0 ? void 0 : _a.value.length) && ((_b = inputRef.current) === null || _b === void 0 ? void 0 : _b.focus());
43
54
  };
44
- return (_jsxs("div", __assign({ style: { width: "".concat(width, "%") }, className: classNames((_b = { 'smartapp-input': true }, _b[className] = className, _b)) }, { children: [title && _jsx("p", __assign({ className: "smartapp-input__title" }, { children: title })), _jsxs("div", __assign({ className: "smartapp-input__container" }, { children: [_jsx("input", { ref: inputRef, className: "smartapp-input__container--field", type: getInputType(), defaultValue: defaultValue, autoFocus: autoFocus, placeholder: placeholder, onChange: function (e) { return onChange(e.target.value); } }), isPassword && (_jsx("button", __assign({ className: "smartapp-input__container--eye-button", type: "button", onClick: function () { return onClickButton(); } }, { children: isPasswordShown ? _jsx(IconEye, {}) : _jsx(IconEyeClosed, {}) })))] })), error && _jsx("div", __assign({ className: "smartapp-input__error" }, { children: error }))] })));
55
+ return (_jsxs("div", __assign({ style: { width: "".concat(width, "%") }, className: classNames((_b = { 'smartapp-input': true }, _b[className] = className, _b)) }, { children: [title && _jsx("p", __assign({ className: "smartapp-input__title" }, { children: title })), _jsxs("div", __assign({ className: "smartapp-input__container" }, { children: [_jsx("input", { ref: inputRef, className: classNames('smartapp-input__container--field', { 'smartapp-input__container--field__with-clear-button': isClearable }), style: getTextStyles(), type: getInputType(), defaultValue: defaultValue, autoFocus: autoFocus, placeholder: placeholder, onKeyDown: handleKeyDown, onChange: function (e) { return onChange(e.target.value); } }), isPassword && (_jsx("button", __assign({ className: "smartapp-input__container--eye-button", type: "button", onClick: function () { return onClickButton(); } }, { children: isPasswordShown ? _jsx(IconEye, {}) : _jsx(IconEyeClosed, {}) }))), isClearable && _jsx(ClearIcon, { className: "smartapp-input__container--clear-icon", onClick: onClearClick })] })), error && _jsx("div", __assign({ className: "smartapp-input__error" }, { children: error }))] })));
45
56
  };
46
57
  export default Input;
@@ -1,12 +1,16 @@
1
1
  import { IntRange } from '../types';
2
2
  export interface IInputProps {
3
- onChange: (str: string) => void;
3
+ isPassword?: boolean;
4
+ isClearable?: boolean;
4
5
  autoFocus?: boolean;
5
6
  title?: string;
6
7
  placeholder?: string;
7
8
  defaultValue?: string;
8
9
  error?: string;
10
+ textSize?: 'small' | 'default' | 'large';
9
11
  width?: IntRange<1, 101>;
10
12
  className?: string;
11
- isPassword?: boolean;
13
+ onChange: (str: string) => void;
14
+ onEnterPress?: () => void;
15
+ onClearClick?: () => void;
12
16
  }
@@ -0,0 +1,4 @@
1
+ import { IModalProps } from './types';
2
+ import '../../styles/stories.module.scss';
3
+ declare const Modal: ({ isModalOpen, content, handleCloseModal, title, platform, iconColor, backgroundColor }: IModalProps) => import("react/jsx-runtime").JSX.Element;
4
+ export default Modal;
@@ -0,0 +1,38 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { useEffect, useRef } from 'react';
14
+ import Popup from 'reactjs-popup';
15
+ import { ReactComponent as CloseIcon } from '../../assets/icons/cancel-cross.svg';
16
+ import { DEFAULT_GRAY_ICON_COLOR, DEFAULT_POPUP_BACKGROUND_COLOR, PLATFORM } from '../../constants';
17
+ import { getClassNames, getColor } from '../../helpers';
18
+ import '../../styles/stories.module.scss';
19
+ var Modal = function (_a) {
20
+ var isModalOpen = _a.isModalOpen, content = _a.content, handleCloseModal = _a.handleCloseModal, title = _a.title, _b = _a.platform, platform = _b === void 0 ? PLATFORM.web : _b, iconColor = _a.iconColor, backgroundColor = _a.backgroundColor;
21
+ var ref = useRef(null);
22
+ useEffect(function () {
23
+ document.documentElement.style.setProperty('--modal-background', getColor(backgroundColor, DEFAULT_POPUP_BACKGROUND_COLOR));
24
+ }, [backgroundColor]);
25
+ useEffect(function () {
26
+ var checkIfClickedOutside = function (e) {
27
+ if (isModalOpen && ref.current && !ref.current.contains(e.target)) {
28
+ handleCloseModal();
29
+ }
30
+ };
31
+ document === null || document === void 0 ? void 0 : document.addEventListener('click', checkIfClickedOutside, true);
32
+ return function () {
33
+ document === null || document === void 0 ? void 0 : document.removeEventListener('click', checkIfClickedOutside, true);
34
+ };
35
+ }, [isModalOpen, handleCloseModal]);
36
+ return (_jsx(Popup, __assign({ className: getClassNames('modal', '-', platform), closeOnDocumentClick: true, modal: true, open: isModalOpen }, { children: _jsx("div", __assign({ ref: ref, className: getClassNames('smartapp-modal', '__', platform) }, { children: _jsxs("div", __assign({ className: getClassNames('smartapp-modal__content', '--', platform) }, { children: [title && _jsx("p", __assign({ className: "smartapp-modal__content--title" }, { children: title })), _jsx("div", __assign({ onClick: handleCloseModal, className: "smartapp-modal__content--close-icon" }, { children: _jsx(CloseIcon, { style: { color: getColor(iconColor, DEFAULT_GRAY_ICON_COLOR) } }) })), content] })) })) })));
37
+ };
38
+ export default Modal;
@@ -0,0 +1 @@
1
+ export { default } from './Modal';
@@ -0,0 +1 @@
1
+ export { default } from './Modal';
@@ -0,0 +1,10 @@
1
+ import { ReactElement } from 'react';
2
+ export interface IModalProps {
3
+ isModalOpen: boolean;
4
+ content: ReactElement;
5
+ handleCloseModal: () => void;
6
+ title?: string;
7
+ platform?: 'web' | 'ios' | 'android';
8
+ iconColor?: string;
9
+ backgroundColor?: string;
10
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -19,3 +19,4 @@ export { default as Switcher } from './Switcher';
19
19
  export { default as Toggle } from './Toggle';
20
20
  export { default as Stories } from './Stories';
21
21
  export { default as SyncLoader } from './SyncLoader';
22
+ export { default as Modal } from './Modal';
@@ -19,3 +19,4 @@ export { default as Switcher } from './Switcher';
19
19
  export { default as Toggle } from './Toggle';
20
20
  export { default as Stories } from './Stories';
21
21
  export { default as SyncLoader } from './SyncLoader';
22
+ export { default as Modal } from './Modal';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressms/smartapp-ui",
3
- "version": "1.1.3",
3
+ "version": "1.1.5",
4
4
  "description": "SmartApp UI library",
5
5
  "license": "MIT",
6
6
  "main": "build/main/index.js",