armtek-uikit-react 1.0.259 → 1.0.262

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.
@@ -13,6 +13,7 @@ const BackDropBase = exports.BackDropBase = (0, _helpers.fixedForwardRef)((props
13
13
  className,
14
14
  onClick
15
15
  } = props;
16
+ const isAutoWidth = width === 'auto';
16
17
  const handleClick = e => {
17
18
  e.stopPropagation();
18
19
  if (onClick) onClick(e);
@@ -25,10 +26,12 @@ const BackDropBase = exports.BackDropBase = (0, _helpers.fixedForwardRef)((props
25
26
  className: 'arm-backdrop__overlay',
26
27
  onClick: handleClick
27
28
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
28
- className: 'arm-backdrop__inner',
29
- style: {
29
+ className: (0, _clsx.default)('arm-backdrop__inner', {
30
+ 'arm-backdrop__inner_auto': isAutoWidth
31
+ }),
32
+ style: !isAutoWidth ? {
30
33
  maxWidth: width + 'px'
31
- },
34
+ } : undefined,
32
35
  children: children
33
36
  })]
34
37
  })
@@ -31,6 +31,10 @@ const dateToText = (d, format) => {
31
31
  if (typeof d === 'string') d = new Date(d);
32
32
  return d.toLocaleString('ru-RU', getDateFormat(format));
33
33
  };
34
+
35
+ /*
36
+ TODO: Не отрабатывает ...register из react-hook-form при предзаполненном поле
37
+ */
34
38
  const DateField = exports.DateField = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
35
39
  let {
36
40
  onChange,
@@ -1,8 +1,8 @@
1
1
  import { ButtonProps } from '../../../ui/Button';
2
2
  import { ComponentPropsWithoutRef, MouseEvent } from 'react';
3
3
  type OwnProps = {
4
- onSubmit?: (e: MouseEvent<HTMLButtonElement>) => void;
5
- onCancel?: (e: MouseEvent<HTMLButtonElement>) => void;
4
+ onSubmit?: (e?: MouseEvent<HTMLButtonElement>) => void;
5
+ onCancel?: (e?: MouseEvent<HTMLButtonElement>) => void;
6
6
  submitProps?: Omit<ButtonProps<'button'>, 'children'> & {
7
7
  text: string;
8
8
  };
@@ -18,7 +18,7 @@ const FormControls = props => {
18
18
  ...divProps
19
19
  } = props;
20
20
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
21
- className: _const.FORM_CONTROLS_CLASSNAME,
21
+ className: (0, _clsx.default)(_const.FORM_CONTROLS_CLASSNAME),
22
22
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
23
23
  ...divProps,
24
24
  className: (0, _clsx.default)(className, 'arm-form-controls__stack'),
@@ -1 +1,2 @@
1
1
  export declare const FORM_CONTROLS_CLASSNAME = "arm-form-controls";
2
+ export declare const FORM_CONTROLS_SKIP_REPLACE_CLASSNAME = "_skip_replace";
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
 
3
3
  exports.__esModule = true;
4
- exports.FORM_CONTROLS_CLASSNAME = void 0;
5
- const FORM_CONTROLS_CLASSNAME = exports.FORM_CONTROLS_CLASSNAME = 'arm-form-controls';
4
+ exports.FORM_CONTROLS_SKIP_REPLACE_CLASSNAME = exports.FORM_CONTROLS_CLASSNAME = void 0;
5
+ const FORM_CONTROLS_CLASSNAME = exports.FORM_CONTROLS_CLASSNAME = 'arm-form-controls';
6
+ const FORM_CONTROLS_SKIP_REPLACE_CLASSNAME = exports.FORM_CONTROLS_SKIP_REPLACE_CLASSNAME = '_skip_replace';
@@ -6,6 +6,17 @@ export type PeriodChangeEvent = (Event & {
6
6
  name: string;
7
7
  };
8
8
  });
9
+ export type PeriodProps = {
10
+ onChange?: (e: PeriodChangeEvent) => void;
11
+ value?: [Date | null, Date | null];
12
+ defaultValue?: [Date | null, Date | null];
13
+ disableSameDate?: boolean;
14
+ minDate?: Date | null;
15
+ maxDate?: Date | null;
16
+ showMonthDropdown?: boolean;
17
+ showYearDropdown?: boolean;
18
+ datePickerProps?: DatePickerProps;
19
+ } & Omit<TextFieldProps, 'value' | 'onChange' | 'defaultValue'>;
9
20
  export declare function getPeriodDisplay(date1: Date | null | undefined, date2: Date | null | undefined): string;
10
21
  declare const Period: import("react").ForwardRefExoticComponent<{
11
22
  onChange?: (e: PeriodChangeEvent) => void;
@@ -114,9 +114,22 @@ const Period = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
114
114
  }
115
115
  }
116
116
  }
117
- if (startDateValid && endDateValid) {
117
+ if (startDateValid && endDateValid && startDateValid.getTime() <= endDateValid.getTime()) {
118
118
  handleSelect([startDateValid, endDateValid]);
119
- } else {
119
+ }
120
+ // else
121
+ // {
122
+ // handleSelect([null, null])
123
+ // }
124
+ };
125
+ const handleBlur = e => {
126
+ setActive(false);
127
+ const value = e.target.value;
128
+ const valueParts = value.split(DELIMITER);
129
+ const startDateValid = valueParts[0] ? validateDate(valueParts[0], minDate, maxDate) : null;
130
+ const endDateValid = valueParts[1] ? validateDate(valueParts[1], minDate, maxDate) : null;
131
+ if (!startDateValid || !endDateValid || startDateValid && endDateValid && endDateValid.getTime() < startDateValid.getTime()) {
132
+ setTextValue('');
120
133
  handleSelect([null, null]);
121
134
  }
122
135
  };
@@ -147,9 +160,8 @@ const Period = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
147
160
  placeholder: 'дд.мм.гггг - дд.мм.гггг',
148
161
  ...restProps,
149
162
  disabled: disabled,
150
- id: 'period',
151
163
  value: textValue,
152
- onBlur: () => setActive(false),
164
+ onBlur: handleBlur,
153
165
  onChange: handleChange,
154
166
  onFocus: () => setActive(false),
155
167
  autoComplete: 'off',
@@ -59,12 +59,19 @@ function Select(props, ref) {
59
59
  return inputRef.current;
60
60
  }, []);
61
61
  const handleOpen = () => {
62
+ if (open !== undefined) return;
62
63
  if (!inputProps.disabled) {
63
64
  setActive(true);
64
65
  // if( e.target instanceof HTMLDivElement )
65
66
  // setAnchorEl(e.currentTarget)
66
67
  }
67
68
  };
69
+ function handleClose() {
70
+ if (onClose) onClose();else {
71
+ if (open !== undefined) return;
72
+ setActive(false);
73
+ }
74
+ }
68
75
  const handleSelect = (e, option) => {
69
76
  if (e.target.classList.contains(_const.CHECKBOX_LABEL_CLASSNAME)) {
70
77
  e.stopPropagation();
@@ -90,7 +97,7 @@ function Select(props, ref) {
90
97
  if (search && !multiple) {
91
98
  setQ(options.find(item => getOptionValue(item) === newValueS).text);
92
99
  }
93
- if (!multiple) setActive(false);
100
+ if (!multiple) handleClose();
94
101
  };
95
102
  const handleSearch = e => {
96
103
  setQ(e.target.value);
@@ -148,9 +155,6 @@ function Select(props, ref) {
148
155
  if (!!search) options = options.filter(item => item.text.toLowerCase().includes(q.toLowerCase()));
149
156
  let valueArr = realValue ? Array.isArray(realValue) ? realValue : [realValue] : [];
150
157
  let selectedOptions = options.filter(item => valueArr.includes(getOptionValue(item)));
151
- function handleClose() {
152
- if (onClose) onClose();else setActive(false);
153
- }
154
158
  let displayClear = clear && (multiple ? realValue && realValue.length > 0 : !!realValue);
155
159
  let selectEndAdornment = /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
156
160
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_Adornment.default, {
@@ -1,8 +1,17 @@
1
1
  import { ComponentPropsWithoutRef, MouseEvent, ReactNode } from 'react';
2
2
  import { FormControlsProps } from '../../ui/Form/FormControls';
3
+ export type ModalClasses = Partial<{
4
+ root: string;
5
+ header: string;
6
+ title: string;
7
+ close: string;
8
+ body: string;
9
+ footer: string;
10
+ formControls: string;
11
+ }>;
3
12
  export type BaseModalProps = Omit<ComponentPropsWithoutRef<'div'>, 'title'> & Partial<Omit<FormControlsProps, 'title'>> & {
4
- onClose?: (e?: MouseEvent<any>) => void;
5
- classes?: Record<string, string>;
13
+ onClose?: (e?: MouseEvent<any> | KeyboardEvent) => void;
14
+ classes?: ModalClasses;
6
15
  title?: ReactNode;
7
16
  };
8
17
  export declare const BaseModal: (props: BaseModalProps) => import("react/jsx-runtime").JSX.Element;
@@ -3,6 +3,7 @@
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
  exports.__esModule = true;
5
5
  exports.BaseModal = void 0;
6
+ var _react = require("react");
6
7
  var _clsx = _interopRequireDefault(require("clsx"));
7
8
  var _FormControls = _interopRequireDefault(require("../Form/FormControls"));
8
9
  var _ButtonIcon = _interopRequireDefault(require("../ButtonIcon"));
@@ -22,20 +23,27 @@ const BaseModal = props => {
22
23
  ...divProps
23
24
  } = props;
24
25
  const showControls = !!onSubmit || !!onCancel;
26
+ const titleId = (0, _react.useId)();
27
+ const hasTitle = !!title;
25
28
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
26
29
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
27
30
  ...divProps,
28
- className: (0, _clsx.default)(className, 'arm-modal', classes == null ? void 0 : classes['Arm-Modal']),
31
+ role: 'dialog',
32
+ "aria-modal": true,
33
+ "aria-labelledby": hasTitle ? titleId : undefined,
34
+ tabIndex: -1,
35
+ className: (0, _clsx.default)(className, 'arm-modal', classes == null ? void 0 : classes.root),
29
36
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
30
37
  className: 'arm-modal__inner',
31
38
  children: [title && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
32
- className: (0, _clsx.default)('arm-modal__header', classes == null ? void 0 : classes['Arm-Modal__header']),
39
+ className: (0, _clsx.default)('arm-modal__header', classes == null ? void 0 : classes.header),
33
40
  children: /*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
34
- className: (0, _clsx.default)('arm-modal__title', classes == null ? void 0 : classes['Arm-Modal__title']),
41
+ id: titleId,
42
+ className: (0, _clsx.default)('arm-modal__title', classes == null ? void 0 : classes.title),
35
43
  children: [title, onClose && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ButtonIcon.default, {
36
44
  variant: 'transparent',
37
45
  onClick: onClose,
38
- className: (0, _clsx.default)('arm-modal__close', classes == null ? void 0 : classes['Arm-Modal__close']),
46
+ className: (0, _clsx.default)('arm-modal__close', classes == null ? void 0 : classes.close),
39
47
  color: 'neutral',
40
48
  size: 'medium',
41
49
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
@@ -44,15 +52,25 @@ const BaseModal = props => {
44
52
  })
45
53
  })]
46
54
  })
55
+ }), !title && onClose && /*#__PURE__*/(0, _jsxRuntime.jsx)(_ButtonIcon.default, {
56
+ variant: 'transparent',
57
+ onClick: onClose,
58
+ className: (0, _clsx.default)('arm-modal__close', 'arm-modal__close_noHeader', classes == null ? void 0 : classes.close),
59
+ color: 'neutral',
60
+ size: 'medium',
61
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)("span", {
62
+ className: 'material_icon',
63
+ children: "close"
64
+ })
47
65
  }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
48
- className: (0, _clsx.default)(_const.MODAL_BODY_CLASSNAME, classes == null ? void 0 : classes['Arm-Modal__body']),
66
+ className: (0, _clsx.default)(_const.MODAL_BODY_CLASSNAME, classes == null ? void 0 : classes.body),
49
67
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
50
68
  children: children
51
69
  })
52
70
  }), showControls && /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
53
- className: (0, _clsx.default)(_const.MODAL_FOOTER_CLASSNAME, classes == null ? void 0 : classes['Arm-Modal__footer']),
71
+ className: (0, _clsx.default)(_const.MODAL_FOOTER_CLASSNAME, classes == null ? void 0 : classes.footer),
54
72
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_FormControls.default, {
55
- className: (0, _clsx.default)(classes == null ? void 0 : classes['Arm-FormControls'], 'arm-modal__controls'),
73
+ className: (0, _clsx.default)(classes == null ? void 0 : classes.formControls, 'arm-modal__controls'),
56
74
  onSubmit: onSubmit,
57
75
  onCancel: onCancel,
58
76
  submitProps: submitProps,
@@ -2,7 +2,7 @@ import { BaseModalProps } from './BaseModal';
2
2
  import { CSSTransitionProps } from 'react-transition-group/CSSTransition';
3
3
  export type ModalProps = BaseModalProps & {
4
4
  open?: boolean;
5
- width?: number;
5
+ width?: number | 'auto';
6
6
  transitionProps?: Partial<CSSTransitionProps<HTMLElement>>;
7
7
  };
8
8
  declare const Modal: (props: ModalProps) => import("react/jsx-runtime").JSX.Element;
package/ui/Modal/Modal.js CHANGED
@@ -10,8 +10,19 @@ var _BackDrop = _interopRequireDefault(require("../BackDrop"));
10
10
  var _reactTransitionGroup = require("react-transition-group");
11
11
  var _const = require("../Form/FormControls/const");
12
12
  var _const2 = require("./const");
13
+ var _useEventCallback = _interopRequireDefault(require("../../lib/hooks/useEventCallback"));
13
14
  var _jsxRuntime = require("react/jsx-runtime");
14
15
  const BACKDROP_CLASSNAME = 'arm-modal__backdrop';
16
+ function isTopmostModal(backdropContainer) {
17
+ let nextElement = backdropContainer.nextElementSibling;
18
+ while (nextElement) {
19
+ if (nextElement.classList.contains(BACKDROP_CLASSNAME)) {
20
+ return false;
21
+ }
22
+ nextElement = nextElement.nextElementSibling;
23
+ }
24
+ return true;
25
+ }
15
26
  function replaceControlsIfExists(container, props) {
16
27
  var _props$classes, _props$classes2;
17
28
  if (!container) return;
@@ -19,9 +30,10 @@ function replaceControlsIfExists(container, props) {
19
30
  if (!body) return;
20
31
  const controls = body.querySelectorAll(`.${_const.FORM_CONTROLS_CLASSNAME}`);
21
32
  if (controls.length !== 1) return;
33
+ if (controls[0].querySelector(`.${_const.FORM_CONTROLS_SKIP_REPLACE_CLASSNAME}`)) return;
22
34
  const footer = document.createElement("div");
23
35
  footer.classList.add(_const2.MODAL_FOOTER_CLASSNAME);
24
- if ((_props$classes = props.classes) != null && _props$classes['Arm-Modal__footer']) footer.classList.add((_props$classes2 = props.classes) == null ? void 0 : _props$classes2['Arm-Modal__footer']);
36
+ if ((_props$classes = props.classes) != null && _props$classes.footer) footer.classList.add((_props$classes2 = props.classes) == null ? void 0 : _props$classes2.footer);
25
37
  controls[0].remove();
26
38
  footer.appendChild(controls[0]);
27
39
  body.after(footer);
@@ -34,18 +46,25 @@ const Modal = props => {
34
46
  ...modalProps
35
47
  } = props;
36
48
  const nodeRef = (0, _react.useRef)(null);
49
+ const handleClose = (0, _useEventCallback.default)(event => {
50
+ modalProps.onClose == null || modalProps.onClose(event);
51
+ });
52
+ const focusModal = (0, _useEventCallback.default)(() => {
53
+ var _nodeRef$current;
54
+ const modalElement = (_nodeRef$current = nodeRef.current) == null ? void 0 : _nodeRef$current.querySelector('[data-testid="base-modal"]');
55
+ modalElement == null || modalElement.focus();
56
+ });
37
57
  (0, _react.useEffect)(() => {
38
58
  function subscribeToEsc(e) {
39
59
  if (e.key !== 'Escape' || !nodeRef.current) return;
40
- const nextElement = nodeRef.current.nextElementSibling;
41
- if (nextElement && nextElement.classList.contains(BACKDROP_CLASSNAME)) return;
42
- modalProps.onClose == null || modalProps.onClose(e);
60
+ if (!isTopmostModal(nodeRef.current)) return;
61
+ handleClose(e);
43
62
  }
44
63
  document.addEventListener('keyup', subscribeToEsc);
45
64
  return () => {
46
65
  document.removeEventListener('keyup', subscribeToEsc);
47
66
  };
48
- }, []);
67
+ }, [handleClose]);
49
68
  (0, _react.useEffect)(() => {
50
69
  replaceControlsIfExists(nodeRef.current, modalProps);
51
70
  }, []);
@@ -53,6 +72,10 @@ const Modal = props => {
53
72
  replaceControlsIfExists(nodeRef.current, modalProps);
54
73
  transitionProps == null || transitionProps.onEntering == null || transitionProps.onEntering(isAppearing);
55
74
  };
75
+ const handleEnteredDone = isAppearing => {
76
+ focusModal();
77
+ transitionProps == null || transitionProps.onEntered == null || transitionProps.onEntered(isAppearing);
78
+ };
56
79
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
57
80
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactTransitionGroup.CSSTransition, {
58
81
  classNames: {
@@ -70,6 +93,7 @@ const Modal = props => {
70
93
  unmountOnExit: true,
71
94
  ...transitionProps,
72
95
  onEntering: handleEntered,
96
+ onEntered: handleEnteredDone,
73
97
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_BackDrop.default, {
74
98
  width: width,
75
99
  ref: nodeRef,
@@ -1,4 +1,4 @@
1
1
  import { PopperBaseProps } from './PopperBase';
2
2
  export type PopperProps = {} & PopperBaseProps;
3
- export declare const Popper: (props: PopperProps) => import("react/jsx-runtime").JSX.Element | null;
3
+ export declare const Popper: (props: PopperBaseProps & import("react").RefAttributes<HTMLDivElement>) => JSX.Element;
4
4
  export default Popper;
@@ -4,17 +4,18 @@ exports.__esModule = true;
4
4
  exports.default = exports.Popper = void 0;
5
5
  var _reactDom = require("react-dom");
6
6
  var _PopperBase = require("./PopperBase");
7
+ var _helpers = require("../../lib/helpers");
7
8
  var _jsxRuntime = require("react/jsx-runtime");
8
9
  //TODO TESTS
9
10
 
10
- const Popper = props => {
11
+ const Popper = exports.Popper = (0, _helpers.fixedForwardRef)((props, ref) => {
11
12
  if (!props.open) return null;
12
13
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
13
14
  children: /*#__PURE__*/(0, _reactDom.createPortal)(/*#__PURE__*/(0, _jsxRuntime.jsx)(_PopperBase.PopperBase, {
15
+ ref: ref,
14
16
  ...props,
15
17
  children: props.children
16
18
  }), document.body)
17
19
  });
18
- };
19
- exports.Popper = Popper;
20
+ });
20
21
  var _default = exports.default = Popper;
@@ -10,5 +10,5 @@ export type PopperBaseProps = {
10
10
  className?: string;
11
11
  placement?: 'bottom-end' | 'bottom-start' | 'bottom' | 'left-end' | 'left-start' | 'left' | 'right-end' | 'right-start' | 'right' | 'top-end' | 'top-start' | 'top';
12
12
  };
13
- export declare const PopperBase: (props: PopperBaseProps) => import("react/jsx-runtime").JSX.Element;
13
+ export declare const PopperBase: (props: PopperBaseProps & import("react").RefAttributes<HTMLDivElement>) => JSX.Element;
14
14
  export default PopperBase;
@@ -7,17 +7,19 @@ exports.default = exports.PopperBase = void 0;
7
7
  var _react = require("react");
8
8
  var _core = require("@popperjs/core");
9
9
  var _clsx = _interopRequireDefault(require("clsx"));
10
+ var _helpers = require("../../lib/helpers");
10
11
  var _jsxRuntime = require("react/jsx-runtime");
11
- const PopperBase = props => {
12
+ const PopperBase = exports.PopperBase = (0, _helpers.fixedForwardRef)((props, ref) => {
12
13
  const {
13
14
  anchorEl,
14
15
  children,
15
- placement,
16
+ placement = 'top',
16
17
  className,
17
18
  anchorPosition,
18
19
  open
19
20
  } = props;
20
21
  const tooltipRef = (0, _react.useRef)(null);
22
+ (0, _react.useImperativeHandle)(ref, () => tooltipRef.current, []);
21
23
  (0, _react.useEffect)(() => {
22
24
  let modifiers = [{
23
25
  name: 'offset',
@@ -54,6 +56,5 @@ const PopperBase = props => {
54
56
  children: children
55
57
  })
56
58
  });
57
- };
58
- exports.PopperBase = PopperBase;
59
+ });
59
60
  var _default = exports.default = PopperBase;
package/ui/Table/Table.js CHANGED
@@ -20,6 +20,9 @@ function TableInit(props, ref) {
20
20
  getRow,
21
21
  ...tableProps
22
22
  } = props;
23
+ const handleRowClick = row => {
24
+ return onClick ? e => onClick(row, e) : undefined;
25
+ };
23
26
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
24
27
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_TableBase.TableBase, {
25
28
  ...tableProps,
@@ -42,7 +45,7 @@ function TableInit(props, ref) {
42
45
  children: getRow(row, index)
43
46
  }, index) : /*#__PURE__*/(0, _jsxRuntime.jsx)(_TableRow.TableRow, {
44
47
  className: rowClass,
45
- onClick: e => onClick ? onClick(row, e) : null,
48
+ onClick: handleRowClick(row),
46
49
  children: structure.map((item, itemIndex) => {
47
50
  let cellClass = !!(classes != null && classes.tableCell) ? typeof classes.tableCell === 'string' ? classes.tableCell : classes.tableCell(row, item.code) : '';
48
51
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(_TableCell.TableCell, {