@expressms/smartapp-ui 1.0.4 → 1.0.6

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 }: IInputProps) => import("react/jsx-runtime").JSX.Element;
3
+ declare const Input: ({ onChange, title, placeholder, defaultValue, error, width, className, autoFocus, isPassword, }: IInputProps) => import("react/jsx-runtime").JSX.Element;
4
4
  export default Input;
@@ -10,11 +10,35 @@ var __assign = (this && this.__assign) || function () {
10
10
  return __assign.apply(this, arguments);
11
11
  };
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { useRef, useState, useEffect } from 'react';
13
14
  import classNames from 'classnames';
15
+ import { ReactComponent as IconEye } from '../../assets/icons/icon-eye.svg';
16
+ import { ReactComponent as IconEyeClosed } from '../../assets/icons/icon-eye-off.svg';
17
+ import { INPUT_TYPE_PASSWORD, INPUT_TYPE_TEXT } from '../../constants';
14
18
  import '../../styles/stories.module.scss';
15
19
  var Input = function (_a) {
16
20
  var _b;
17
- 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;
18
- 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 })), _jsx("input", { className: "smartapp-input__field", defaultValue: defaultValue, placeholder: placeholder, onChange: function (e) { return onChange(e.target.value); } }), error && _jsx("div", __assign({ className: "smartapp-input__error" }, { children: error }))] })));
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];
23
+ var inputRef = useRef(null);
24
+ useEffect(function () {
25
+ var _a;
26
+ var inputElement = inputRef.current;
27
+ if (inputElement) {
28
+ var textLength = inputElement.value.length;
29
+ inputElement.selectionStart = textLength;
30
+ inputElement.selectionEnd = textLength;
31
+ (_a = inputRef === null || inputRef === void 0 ? void 0 : inputRef.current) === null || _a === void 0 ? void 0 : _a.focus();
32
+ }
33
+ }, [isPasswordShown]);
34
+ var getInputType = function () {
35
+ if (isPassword) {
36
+ return isPasswordShown ? INPUT_TYPE_TEXT : INPUT_TYPE_PASSWORD;
37
+ }
38
+ return INPUT_TYPE_TEXT;
39
+ };
40
+ 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 () {
41
+ setPasswordShown(!isPasswordShown);
42
+ } }, { children: isPasswordShown ? _jsx(IconEye, {}) : _jsx(IconEyeClosed, {}) })))] })), error && _jsx("div", __assign({ className: "smartapp-input__error" }, { children: error }))] })));
19
43
  };
20
44
  export default Input;
@@ -1,10 +1,12 @@
1
1
  import { IntRange } from '../types';
2
2
  export interface IInputProps {
3
3
  onChange: (str: string) => void;
4
+ autoFocus?: boolean;
4
5
  title?: string;
5
6
  placeholder?: string;
6
7
  defaultValue?: string;
7
8
  error?: string;
8
9
  width?: IntRange<1, 101>;
9
10
  className?: string;
11
+ isPassword?: boolean;
10
12
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@expressms/smartapp-ui",
3
- "version": "1.0.4",
3
+ "version": "1.0.6",
4
4
  "description": "SmartApp UI library",
5
5
  "license": "MIT",
6
6
  "main": "build/main/index.js",