@expressms/smartapp-ui 1.1.4 → 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 { 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.4",
3
+ "version": "1.1.5",
4
4
  "description": "SmartApp UI library",
5
5
  "license": "MIT",
6
6
  "main": "build/main/index.js",