@megafon/ui-core 3.0.0-beta.2 → 3.0.0-beta.3

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.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,29 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [3.0.0-beta.3](https://github.com/MegafonWebLab/megafon-ui/compare/@megafon/ui-core@3.0.0-beta.2...@megafon/ui-core@3.0.0-beta.3) (2022-01-24)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **accordion:** add focus on arrow after tab press, add open/close accordion after enter press ([9bfa0ac](https://github.com/MegafonWebLab/megafon-ui/commit/9bfa0ac5348ac25c0e37a4df51e26e2dabde02ba))
12
+ * **accordion:** change type of onClickAccordion prop ([9a150c5](https://github.com/MegafonWebLab/megafon-ui/commit/9a150c5de309547763a714b0eb630dfb386a8107))
13
+ * **calendar/month:** add focus on month arrows, add enter press handlers ([63f1e47](https://github.com/MegafonWebLab/megafon-ui/commit/63f1e4761e57ed6d56464b632dce9fd5e77655e1))
14
+ * **checkbox:** add focus on custom checkbox, add enter press handler ([83d111d](https://github.com/MegafonWebLab/megafon-ui/commit/83d111d0e4b41d3915bdd079bed4a7f9715ce7a5))
15
+ * **checkbox:** add isChecked state, change type of onChange prop ([f535caf](https://github.com/MegafonWebLab/megafon-ui/commit/f535caf39a02ab6793d3c63b654a1f1f3e9b2b93))
16
+ * **tooltip:** add check event function from ui-helpers ([a784ab4](https://github.com/MegafonWebLab/megafon-ui/commit/a784ab4f288124eb941fe8f52e46b2efc9aa2f82))
17
+
18
+
19
+ ### BREAKING CHANGES
20
+
21
+ * **checkbox:** change type of onChange prop on (checked: boolean) => void
22
+ * **accordion:** remove parameter 'title' in onClickAccordion prop
23
+ * **tooltip:** change onOpen, onClose types; AccessibilityEventTypeNative from @megafon/ui-helpers
24
+
25
+
26
+
27
+
28
+
6
29
  # [3.0.0-beta.2](https://github.com/MegafonWebLab/megafon-ui/compare/@megafon/ui-core@3.0.0-beta.1...@megafon/ui-core@3.0.0-beta.2) (2022-01-21)
7
30
 
8
31
  **Note:** Version bump only for package @megafon/ui-core
@@ -20,7 +20,7 @@ export interface IAccordionProps extends IFilterDataAttrs {
20
20
  titleWrap?: string;
21
21
  };
22
22
  /** Обработчик клика */
23
- onClickAccordion?: (isOpened: boolean, title: string | React.ReactNode | React.ReactNode[]) => void;
23
+ onClickAccordion?: (isOpened: boolean) => void;
24
24
  }
25
25
  declare const Accordion: React.FC<IAccordionProps>;
26
26
  export default Accordion;
@@ -1,7 +1,7 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import _extends from "@babel/runtime/helpers/extends";
3
3
  import * as React from 'react';
4
- import { cnCreate, filterDataAttrs } from '@megafon/ui-helpers';
4
+ import { cnCreate, filterDataAttrs, checkEventIsClickOrEnterPress } from '@megafon/ui-helpers';
5
5
  import * as PropTypes from 'prop-types';
6
6
  import Collapse from "../Collapse/Collapse";
7
7
  import Header from "../Header/Header";
@@ -52,9 +52,11 @@ var Accordion = function Accordion(_ref) {
52
52
  setIsOpenedState(isOpened);
53
53
  }, [isOpened]);
54
54
 
55
- var handleClickTitle = function handleClickTitle() {
56
- onClickAccordion && onClickAccordion(!isOpenedState, title);
57
- setIsOpenedState(!isOpenedState);
55
+ var handleClickTitle = function handleClickTitle(e) {
56
+ if (checkEventIsClickOrEnterPress(e)) {
57
+ onClickAccordion && onClickAccordion(!isOpenedState);
58
+ setIsOpenedState(!isOpenedState);
59
+ }
58
60
  };
59
61
 
60
62
  var openedClassName = isOpenedState ? openedClass : undefined;
@@ -65,10 +67,13 @@ var Accordion = function Accordion(_ref) {
65
67
  }, [className, rootPropsClasses, openedClassName])
66
68
  }), /*#__PURE__*/React.createElement("div", {
67
69
  className: cn('title-wrap', [titleWrapPropsClasses]),
68
- onClick: handleClickTitle
70
+ onClick: handleClickTitle,
71
+ onKeyDown: handleClickTitle
69
72
  }, /*#__PURE__*/React.createElement(Header, {
70
73
  as: "h5"
71
74
  }, title), /*#__PURE__*/React.createElement("div", {
75
+ tabIndex: 0,
76
+ role: "button",
72
77
  className: cn('icon-box', {
73
78
  open: isOpenedState
74
79
  })
@@ -2,7 +2,7 @@ import "core-js/modules/es.array.concat";
2
2
  import "core-js/modules/es.array.map";
3
3
  import _extends from "@babel/runtime/helpers/extends";
4
4
  import React from 'react';
5
- import { cnCreate } from '@megafon/ui-helpers';
5
+ import { checkEventIsClickOrEnterPress, cnCreate } from '@megafon/ui-helpers';
6
6
  import "./Month.css";
7
7
  import PropTypes from 'prop-types';
8
8
 
@@ -38,12 +38,22 @@ var Month = function Month(_ref) {
38
38
  goToNextMonth = _ref.goToNextMonth,
39
39
  children = _ref.children;
40
40
 
41
- var handleArrowLeftClick = function handleArrowLeftClick() {
42
- !isPrevMonthDisabled && goToPreviousMonth();
41
+ var handleArrowLeftClick = function handleArrowLeftClick(e) {
42
+ if (checkEventIsClickOrEnterPress(e)) {
43
+ !isPrevMonthDisabled && goToPreviousMonth();
44
+ }
43
45
  };
44
46
 
45
- var handleArrowRightClick = function handleArrowRightClick() {
46
- !isNextMonthDisabled && goToNextMonth();
47
+ var handleArrowRightClick = function handleArrowRightClick(e) {
48
+ if (checkEventIsClickOrEnterPress(e)) {
49
+ !isNextMonthDisabled && goToNextMonth();
50
+ }
51
+ };
52
+
53
+ var getTabIndex = function getTabIndex(hasFocus) {
54
+ var tabIndexWithFocus = 0;
55
+ var tabIndexWithoutFocus = -1;
56
+ return hasFocus ? tabIndexWithFocus : tabIndexWithoutFocus;
47
57
  };
48
58
 
49
59
  return /*#__PURE__*/React.createElement("div", {
@@ -51,16 +61,22 @@ var Month = function Month(_ref) {
51
61
  }, /*#__PURE__*/React.createElement("div", {
52
62
  className: cn('header')
53
63
  }, /*#__PURE__*/React.createElement(ArrowLeft, {
64
+ role: "button",
65
+ tabIndex: getTabIndex(!isPrevMonthDisabled),
54
66
  className: cn('arrow', {
55
67
  disabled: isPrevMonthDisabled
56
68
  }),
69
+ onKeyDown: handleArrowLeftClick,
57
70
  onClick: handleArrowLeftClick
58
71
  }), /*#__PURE__*/React.createElement("span", {
59
72
  className: cn('title')
60
73
  }, "".concat(monthLabel, " ").concat(year)), /*#__PURE__*/React.createElement(ArrowRight, {
74
+ role: "button",
75
+ tabIndex: getTabIndex(!isNextMonthDisabled),
61
76
  className: cn('arrow', {
62
77
  disabled: isNextMonthDisabled
63
78
  }),
79
+ onKeyDown: handleArrowRightClick,
64
80
  onClick: handleArrowRightClick
65
81
  })), /*#__PURE__*/React.createElement("div", {
66
82
  className: cn('weekday-labels')
@@ -1,6 +1,5 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { IFilterDataAttrs } from '@megafon/ui-helpers';
3
- import * as PropTypes from 'prop-types';
4
3
  import './Checkbox.less';
5
4
  export interface ICheckboxProps extends IFilterDataAttrs {
6
5
  /** Цвет чекбокса */
@@ -28,28 +27,7 @@ export interface ICheckboxProps extends IFilterDataAttrs {
28
27
  extraContent?: JSX.Element[] | Element[] | JSX.Element | Element | string;
29
28
  children: JSX.Element[] | Element[] | JSX.Element | Element | string;
30
29
  /** Обработчик изменения значения */
31
- onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
32
- }
33
- declare class Checkbox extends React.Component<ICheckboxProps, {}> {
34
- static propTypes: {
35
- className: PropTypes.Requireable<string>;
36
- fontSize: PropTypes.Requireable<string>;
37
- color: PropTypes.Requireable<string>;
38
- name: PropTypes.Requireable<string>;
39
- value: PropTypes.Requireable<string>;
40
- checked: PropTypes.Requireable<boolean>;
41
- disabled: PropTypes.Requireable<boolean>;
42
- error: PropTypes.Requireable<boolean>;
43
- children: PropTypes.Requireable<string | PropTypes.ReactElementLike | (PropTypes.ReactElementLike | null | undefined)[]>;
44
- extraContent: PropTypes.Requireable<string | PropTypes.ReactElementLike | (PropTypes.ReactElementLike | null | undefined)[]>;
45
- dataAttrs: PropTypes.Requireable<{
46
- [x: string]: string;
47
- }>;
48
- onChange: PropTypes.Requireable<(...args: any[]) => any>;
49
- };
50
- static defaultProps: Partial<ICheckboxProps>;
51
- isTouch: boolean;
52
- handleChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
53
- render(): JSX.Element;
30
+ onChange?: (checked: boolean) => void;
54
31
  }
32
+ declare const Checkbox: React.FC<ICheckboxProps>;
55
33
  export default Checkbox;
@@ -1,21 +1,8 @@
1
- import "core-js/modules/es.date.to-string";
2
1
  import "core-js/modules/es.function.name";
3
- import "core-js/modules/es.object.to-string";
4
- import "core-js/modules/es.reflect.construct";
5
- import "core-js/modules/es.regexp.to-string";
6
- import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
7
- import _createClass from "@babel/runtime/helpers/createClass";
8
- import _inherits from "@babel/runtime/helpers/inherits";
9
- import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
10
- import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
11
3
  import _extends from "@babel/runtime/helpers/extends";
12
-
13
- function _createSuper(Derived) { return function () { var Super = _getPrototypeOf(Derived), result; if (_isNativeReflectConstruct()) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
14
-
15
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
16
-
17
- import * as React from 'react';
18
- import { cnCreate, detectTouch, filterDataAttrs } from '@megafon/ui-helpers';
4
+ import React, { useState, useEffect } from 'react';
5
+ import { checkEventIsClickOrEnterPress, cnCreate, detectTouch, filterDataAttrs } from '@megafon/ui-helpers';
19
6
  import * as PropTypes from 'prop-types';
20
7
  import "./Checkbox.css";
21
8
 
@@ -27,79 +14,79 @@ var CheckedIcon = function CheckedIcon(props) {
27
14
  }));
28
15
  };
29
16
 
17
+ var CHANGE_KEY = 'change';
30
18
  var cn = cnCreate('mfui-checkbox');
31
19
 
32
- var Checkbox = /*#__PURE__*/function (_React$Component) {
33
- _inherits(Checkbox, _React$Component);
34
-
35
- var _super = _createSuper(Checkbox);
36
-
37
- function Checkbox() {
38
- var _this;
20
+ var Checkbox = function Checkbox(_ref) {
21
+ var className = _ref.className,
22
+ _ref$fontSize = _ref.fontSize,
23
+ fontSize = _ref$fontSize === void 0 ? 'regular' : _ref$fontSize,
24
+ name = _ref.name,
25
+ _ref$color = _ref.color,
26
+ color = _ref$color === void 0 ? 'dark' : _ref$color,
27
+ value = _ref.value,
28
+ _ref$checked = _ref.checked,
29
+ checked = _ref$checked === void 0 ? false : _ref$checked,
30
+ disabled = _ref.disabled,
31
+ error = _ref.error,
32
+ children = _ref.children,
33
+ extraContent = _ref.extraContent,
34
+ dataAttrs = _ref.dataAttrs,
35
+ classes = _ref.classes,
36
+ onChange = _ref.onChange;
37
+ var isTouch = detectTouch();
39
38
 
40
- _classCallCheck(this, Checkbox);
39
+ var _useState = useState(checked),
40
+ _useState2 = _slicedToArray(_useState, 2),
41
+ isChecked = _useState2[0],
42
+ setIsChecked = _useState2[1];
41
43
 
42
- _this = _super.apply(this, arguments);
43
- _this.isTouch = detectTouch();
44
+ useEffect(function () {
45
+ setIsChecked(checked);
46
+ }, [checked]);
44
47
 
45
- _this.handleChange = function (e) {
46
- var onChange = _this.props.onChange;
47
- onChange && onChange(e);
48
- };
49
-
50
- return _this;
51
- }
52
-
53
- _createClass(Checkbox, [{
54
- key: "render",
55
- value: function render() {
56
- var _this$props = this.props,
57
- className = _this$props.className,
58
- fontSize = _this$props.fontSize,
59
- name = _this$props.name,
60
- color = _this$props.color,
61
- value = _this$props.value,
62
- checked = _this$props.checked,
63
- disabled = _this$props.disabled,
64
- error = _this$props.error,
65
- children = _this$props.children,
66
- extraContent = _this$props.extraContent,
67
- dataAttrs = _this$props.dataAttrs,
68
- classes = _this$props.classes;
69
- return /*#__PURE__*/React.createElement("div", _extends({
70
- className: cn('', {
71
- 'font-size': fontSize,
72
- color: color,
73
- checked: checked,
74
- disabled: disabled,
75
- error: error
76
- }, className)
77
- }, filterDataAttrs(dataAttrs)), /*#__PURE__*/React.createElement("div", {
78
- className: cn('inner', [classes === null || classes === void 0 ? void 0 : classes.inner])
79
- }, /*#__PURE__*/React.createElement("label", {
80
- className: cn('label', {
81
- 'no-touch': !this.isTouch
82
- })
83
- }, /*#__PURE__*/React.createElement("input", {
84
- className: cn('input'),
85
- type: "checkbox",
86
- name: name,
87
- value: value,
88
- checked: checked,
89
- onChange: this.handleChange,
90
- disabled: disabled
91
- }), /*#__PURE__*/React.createElement("div", {
92
- className: cn('custom-input', [classes === null || classes === void 0 ? void 0 : classes.icon])
93
- }, /*#__PURE__*/React.createElement(CheckedIcon, {
94
- className: cn('icon')
95
- })), children), extraContent && /*#__PURE__*/React.createElement("span", {
96
- className: cn('extra-content')
97
- }, extraContent)));
48
+ var handleChange = function handleChange(e) {
49
+ if (checkEventIsClickOrEnterPress(e) || e.type === CHANGE_KEY) {
50
+ setIsChecked(!isChecked);
51
+ onChange && onChange(!isChecked);
98
52
  }
99
- }]);
53
+ };
100
54
 
101
- return Checkbox;
102
- }(React.Component);
55
+ return /*#__PURE__*/React.createElement("div", _extends({
56
+ className: cn('', {
57
+ 'font-size': fontSize,
58
+ color: color,
59
+ checked: isChecked,
60
+ disabled: disabled,
61
+ error: error
62
+ }, className)
63
+ }, filterDataAttrs(dataAttrs)), /*#__PURE__*/React.createElement("div", {
64
+ className: cn('inner', [classes === null || classes === void 0 ? void 0 : classes.inner])
65
+ }, /*#__PURE__*/React.createElement("label", {
66
+ className: cn('label', {
67
+ 'no-touch': !isTouch
68
+ })
69
+ }, /*#__PURE__*/React.createElement("input", {
70
+ className: cn('input'),
71
+ type: "checkbox",
72
+ tabIndex: -1,
73
+ name: name,
74
+ value: value,
75
+ checked: isChecked,
76
+ onChange: handleChange,
77
+ disabled: disabled
78
+ }), /*#__PURE__*/React.createElement("div", {
79
+ tabIndex: 0,
80
+ role: "checkbox",
81
+ "aria-checked": isChecked,
82
+ className: cn('custom-input', [classes === null || classes === void 0 ? void 0 : classes.icon]),
83
+ onKeyDown: handleChange
84
+ }, /*#__PURE__*/React.createElement(CheckedIcon, {
85
+ className: cn('icon')
86
+ })), children), extraContent && /*#__PURE__*/React.createElement("span", {
87
+ className: cn('extra-content')
88
+ }, extraContent)));
89
+ };
103
90
 
104
91
  Checkbox.propTypes = {
105
92
  className: PropTypes.string,
@@ -110,14 +97,9 @@ Checkbox.propTypes = {
110
97
  checked: PropTypes.bool,
111
98
  disabled: PropTypes.bool,
112
99
  error: PropTypes.bool,
113
- children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.element), PropTypes.element, PropTypes.string]),
114
- extraContent: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.element), PropTypes.element, PropTypes.string]),
100
+ children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.element.isRequired), PropTypes.element, PropTypes.string]).isRequired,
101
+ extraContent: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.element.isRequired), PropTypes.element, PropTypes.string]),
115
102
  dataAttrs: PropTypes.objectOf(PropTypes.string.isRequired),
116
103
  onChange: PropTypes.func
117
104
  };
118
- Checkbox.defaultProps = {
119
- color: 'dark',
120
- fontSize: 'regular',
121
- checked: false
122
- };
123
105
  export default Checkbox;
@@ -132,7 +132,7 @@ declare class Select<T extends SelectItemValueType> extends React.Component<ISel
132
132
  handleClosed: () => void;
133
133
  handleClickOutside: (e: MouseEvent) => void;
134
134
  handleOpenDropdown: () => void;
135
- handleSelectItem: (e: React.MouseEvent<HTMLDivElement, MouseEvent> | React.KeyboardEvent<HTMLDivElement>) => void;
135
+ handleSelectItem: (e: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
136
136
  handleHoverItem: (index: number) => (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
137
137
  handleComboboxFocus: (e: React.FocusEvent<HTMLInputElement>) => void;
138
138
  handleChangeCombobox: (e: React.ChangeEvent<HTMLInputElement>) => void;
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import type { AccessibilityEventTypeNative } from '@megafon/ui-helpers';
2
3
  import './Tooltip.less';
3
4
  export declare const Placement: {
4
5
  readonly LEFT: "left";
@@ -46,9 +47,9 @@ export interface ITooltipProps {
46
47
  contentShadow?: string;
47
48
  };
48
49
  /** Обработчик на открытие */
49
- onOpen?: (e: MouseEvent) => void;
50
+ onOpen?: (e: AccessibilityEventTypeNative) => void;
50
51
  /** Обработчик на закрытие */
51
- onClose?: (e: MouseEvent | FocusEvent) => void;
52
+ onClose?: (e: AccessibilityEventTypeNative | FocusEvent) => void;
52
53
  }
53
54
  declare const Tooltip: React.FC<ITooltipProps>;
54
55
  export default Tooltip;
@@ -4,15 +4,13 @@ import _typeof from "@babel/runtime/helpers/typeof";
4
4
  import _extends from "@babel/runtime/helpers/extends";
5
5
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
6
6
  import React, { useState, useCallback, useEffect, useMemo } from 'react';
7
- import { cnCreate, detectTouch } from '@megafon/ui-helpers';
7
+ import { cnCreate, detectTouch, checkNativeEventIsClickOrEnterPress } from '@megafon/ui-helpers';
8
8
  import PropTypes from 'prop-types';
9
9
  import { usePopper } from 'react-popper';
10
10
  import Tile from "../Tile/Tile";
11
11
  import "./Tooltip.css";
12
12
  var TOOLTIP_PADDING_FOR_FLIP = 14;
13
13
  var MOUSE_KEY = 'mousedown';
14
- var KEYBOARD_ENTER_KEY = 'Enter';
15
- var KEYBOARD_NUMPAD_ENTER_KEY = 'NumpadEnter';
16
14
  var TOUCH_KEY = 'touchstart';
17
15
  export var Placement = {
18
16
  LEFT: 'left',
@@ -20,11 +18,6 @@ export var Placement = {
20
18
  RIGHT: 'right',
21
19
  BOTTOM: 'bottom'
22
20
  };
23
-
24
- var checkEventIsClickOrEnterPress = function checkEventIsClickOrEnterPress(e) {
25
- return e.type === TOUCH_KEY || e.type === MOUSE_KEY || e.code === KEYBOARD_ENTER_KEY || e.code === KEYBOARD_NUMPAD_ENTER_KEY;
26
- };
27
-
28
21
  export var Paddings = {
29
22
  NONE: 'none',
30
23
  SMALL: 'small',
@@ -142,7 +135,7 @@ var Tooltip = function Tooltip(_ref) {
142
135
  }
143
136
  }, [isOpen, onOpen, setIsOpen]);
144
137
  var handleClick = useCallback(function (e) {
145
- if (!checkEventIsClickOrEnterPress(e)) {
138
+ if (!checkNativeEventIsClickOrEnterPress(e)) {
146
139
  return;
147
140
  }
148
141
 
@@ -20,7 +20,7 @@ export interface IAccordionProps extends IFilterDataAttrs {
20
20
  titleWrap?: string;
21
21
  };
22
22
  /** Обработчик клика */
23
- onClickAccordion?: (isOpened: boolean, title: string | React.ReactNode | React.ReactNode[]) => void;
23
+ onClickAccordion?: (isOpened: boolean) => void;
24
24
  }
25
25
  declare const Accordion: React.FC<IAccordionProps>;
26
26
  export default Accordion;
@@ -72,9 +72,11 @@ var Accordion = function Accordion(_ref) {
72
72
  setIsOpenedState(isOpened);
73
73
  }, [isOpened]);
74
74
 
75
- var handleClickTitle = function handleClickTitle() {
76
- onClickAccordion && onClickAccordion(!isOpenedState, title);
77
- setIsOpenedState(!isOpenedState);
75
+ var handleClickTitle = function handleClickTitle(e) {
76
+ if ((0, _uiHelpers.checkEventIsClickOrEnterPress)(e)) {
77
+ onClickAccordion && onClickAccordion(!isOpenedState);
78
+ setIsOpenedState(!isOpenedState);
79
+ }
78
80
  };
79
81
 
80
82
  var openedClassName = isOpenedState ? openedClass : undefined;
@@ -85,10 +87,13 @@ var Accordion = function Accordion(_ref) {
85
87
  }, [className, rootPropsClasses, openedClassName])
86
88
  }), /*#__PURE__*/React.createElement("div", {
87
89
  className: cn('title-wrap', [titleWrapPropsClasses]),
88
- onClick: handleClickTitle
90
+ onClick: handleClickTitle,
91
+ onKeyDown: handleClickTitle
89
92
  }, /*#__PURE__*/React.createElement(_Header["default"], {
90
93
  as: "h5"
91
94
  }, title), /*#__PURE__*/React.createElement("div", {
95
+ tabIndex: 0,
96
+ role: "button",
92
97
  className: cn('icon-box', {
93
98
  open: isOpenedState
94
99
  })
@@ -51,12 +51,22 @@ var Month = function Month(_ref) {
51
51
  goToNextMonth = _ref.goToNextMonth,
52
52
  children = _ref.children;
53
53
 
54
- var handleArrowLeftClick = function handleArrowLeftClick() {
55
- !isPrevMonthDisabled && goToPreviousMonth();
54
+ var handleArrowLeftClick = function handleArrowLeftClick(e) {
55
+ if ((0, _uiHelpers.checkEventIsClickOrEnterPress)(e)) {
56
+ !isPrevMonthDisabled && goToPreviousMonth();
57
+ }
56
58
  };
57
59
 
58
- var handleArrowRightClick = function handleArrowRightClick() {
59
- !isNextMonthDisabled && goToNextMonth();
60
+ var handleArrowRightClick = function handleArrowRightClick(e) {
61
+ if ((0, _uiHelpers.checkEventIsClickOrEnterPress)(e)) {
62
+ !isNextMonthDisabled && goToNextMonth();
63
+ }
64
+ };
65
+
66
+ var getTabIndex = function getTabIndex(hasFocus) {
67
+ var tabIndexWithFocus = 0;
68
+ var tabIndexWithoutFocus = -1;
69
+ return hasFocus ? tabIndexWithFocus : tabIndexWithoutFocus;
60
70
  };
61
71
 
62
72
  return /*#__PURE__*/_react["default"].createElement("div", {
@@ -64,16 +74,22 @@ var Month = function Month(_ref) {
64
74
  }, /*#__PURE__*/_react["default"].createElement("div", {
65
75
  className: cn('header')
66
76
  }, /*#__PURE__*/_react["default"].createElement(ArrowLeft, {
77
+ role: "button",
78
+ tabIndex: getTabIndex(!isPrevMonthDisabled),
67
79
  className: cn('arrow', {
68
80
  disabled: isPrevMonthDisabled
69
81
  }),
82
+ onKeyDown: handleArrowLeftClick,
70
83
  onClick: handleArrowLeftClick
71
84
  }), /*#__PURE__*/_react["default"].createElement("span", {
72
85
  className: cn('title')
73
86
  }, "".concat(monthLabel, " ").concat(year)), /*#__PURE__*/_react["default"].createElement(ArrowRight, {
87
+ role: "button",
88
+ tabIndex: getTabIndex(!isNextMonthDisabled),
74
89
  className: cn('arrow', {
75
90
  disabled: isNextMonthDisabled
76
91
  }),
92
+ onKeyDown: handleArrowRightClick,
77
93
  onClick: handleArrowRightClick
78
94
  })), /*#__PURE__*/_react["default"].createElement("div", {
79
95
  className: cn('weekday-labels')
@@ -1,6 +1,5 @@
1
- import * as React from 'react';
1
+ import React from 'react';
2
2
  import { IFilterDataAttrs } from '@megafon/ui-helpers';
3
- import * as PropTypes from 'prop-types';
4
3
  import './Checkbox.less';
5
4
  export interface ICheckboxProps extends IFilterDataAttrs {
6
5
  /** Цвет чекбокса */
@@ -28,28 +27,7 @@ export interface ICheckboxProps extends IFilterDataAttrs {
28
27
  extraContent?: JSX.Element[] | Element[] | JSX.Element | Element | string;
29
28
  children: JSX.Element[] | Element[] | JSX.Element | Element | string;
30
29
  /** Обработчик изменения значения */
31
- onChange?: (e: React.ChangeEvent<HTMLInputElement>) => void;
32
- }
33
- declare class Checkbox extends React.Component<ICheckboxProps, {}> {
34
- static propTypes: {
35
- className: PropTypes.Requireable<string>;
36
- fontSize: PropTypes.Requireable<string>;
37
- color: PropTypes.Requireable<string>;
38
- name: PropTypes.Requireable<string>;
39
- value: PropTypes.Requireable<string>;
40
- checked: PropTypes.Requireable<boolean>;
41
- disabled: PropTypes.Requireable<boolean>;
42
- error: PropTypes.Requireable<boolean>;
43
- children: PropTypes.Requireable<string | PropTypes.ReactElementLike | (PropTypes.ReactElementLike | null | undefined)[]>;
44
- extraContent: PropTypes.Requireable<string | PropTypes.ReactElementLike | (PropTypes.ReactElementLike | null | undefined)[]>;
45
- dataAttrs: PropTypes.Requireable<{
46
- [x: string]: string;
47
- }>;
48
- onChange: PropTypes.Requireable<(...args: any[]) => any>;
49
- };
50
- static defaultProps: Partial<ICheckboxProps>;
51
- isTouch: boolean;
52
- handleChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
53
- render(): JSX.Element;
30
+ onChange?: (checked: boolean) => void;
54
31
  }
32
+ declare const Checkbox: React.FC<ICheckboxProps>;
55
33
  export default Checkbox;
@@ -7,29 +7,13 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports["default"] = void 0;
9
9
 
10
- require("core-js/modules/es.date.to-string");
11
-
12
10
  require("core-js/modules/es.function.name");
13
11
 
14
- require("core-js/modules/es.object.to-string");
15
-
16
- require("core-js/modules/es.reflect.construct");
17
-
18
- require("core-js/modules/es.regexp.to-string");
19
-
20
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
21
-
22
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
23
-
24
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
25
-
26
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
27
-
28
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
12
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
29
13
 
30
14
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
31
15
 
32
- var React = _interopRequireWildcard(require("react"));
16
+ var _react = _interopRequireWildcard(require("react"));
33
17
 
34
18
  var _uiHelpers = require("@megafon/ui-helpers");
35
19
 
@@ -41,114 +25,87 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;
41
25
 
42
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
43
27
 
44
- function _createSuper(Derived) {
45
- return function () {
46
- var Super = (0, _getPrototypeOf2["default"])(Derived),
47
- result;
48
-
49
- if (_isNativeReflectConstruct()) {
50
- var NewTarget = (0, _getPrototypeOf2["default"])(this).constructor;
51
- result = Reflect.construct(Super, arguments, NewTarget);
52
- } else {
53
- result = Super.apply(this, arguments);
54
- }
55
-
56
- return (0, _possibleConstructorReturn2["default"])(this, result);
57
- };
58
- }
59
-
60
- function _isNativeReflectConstruct() {
61
- if (typeof Reflect === "undefined" || !Reflect.construct) return false;
62
- if (Reflect.construct.sham) return false;
63
- if (typeof Proxy === "function") return true;
64
-
65
- try {
66
- Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
67
- return true;
68
- } catch (e) {
69
- return false;
70
- }
71
- }
72
-
73
28
  var CheckedIcon = function CheckedIcon(props) {
74
- return /*#__PURE__*/React.createElement("svg", (0, _extends2["default"])({
29
+ return /*#__PURE__*/_react["default"].createElement("svg", (0, _extends2["default"])({
75
30
  viewBox: "0 0 20 20"
76
- }, props), /*#__PURE__*/React.createElement("path", {
31
+ }, props), /*#__PURE__*/_react["default"].createElement("path", {
77
32
  d: "M8.832 11.547L6.619 9.335l-1.414 1.413 2.462 2.462 1.445 1.446 5.932-8.486-1.638-1.148-4.574 6.525z"
78
33
  }));
79
34
  };
80
35
 
36
+ var CHANGE_KEY = 'change';
81
37
  var cn = (0, _uiHelpers.cnCreate)('mfui-checkbox');
82
38
 
83
- var Checkbox = /*#__PURE__*/function (_React$Component) {
84
- (0, _inherits2["default"])(Checkbox, _React$Component);
85
-
86
- var _super = _createSuper(Checkbox);
87
-
88
- function Checkbox() {
89
- var _this;
90
-
91
- (0, _classCallCheck2["default"])(this, Checkbox);
92
- _this = _super.apply(this, arguments);
93
- _this.isTouch = (0, _uiHelpers.detectTouch)();
94
-
95
- _this.handleChange = function (e) {
96
- var onChange = _this.props.onChange;
97
- onChange && onChange(e);
98
- };
99
-
100
- return _this;
101
- }
102
-
103
- (0, _createClass2["default"])(Checkbox, [{
104
- key: "render",
105
- value: function render() {
106
- var _this$props = this.props,
107
- className = _this$props.className,
108
- fontSize = _this$props.fontSize,
109
- name = _this$props.name,
110
- color = _this$props.color,
111
- value = _this$props.value,
112
- checked = _this$props.checked,
113
- disabled = _this$props.disabled,
114
- error = _this$props.error,
115
- children = _this$props.children,
116
- extraContent = _this$props.extraContent,
117
- dataAttrs = _this$props.dataAttrs,
118
- classes = _this$props.classes;
119
- return /*#__PURE__*/React.createElement("div", (0, _extends2["default"])({
120
- className: cn('', {
121
- 'font-size': fontSize,
122
- color: color,
123
- checked: checked,
124
- disabled: disabled,
125
- error: error
126
- }, className)
127
- }, (0, _uiHelpers.filterDataAttrs)(dataAttrs)), /*#__PURE__*/React.createElement("div", {
128
- className: cn('inner', [classes === null || classes === void 0 ? void 0 : classes.inner])
129
- }, /*#__PURE__*/React.createElement("label", {
130
- className: cn('label', {
131
- 'no-touch': !this.isTouch
132
- })
133
- }, /*#__PURE__*/React.createElement("input", {
134
- className: cn('input'),
135
- type: "checkbox",
136
- name: name,
137
- value: value,
138
- checked: checked,
139
- onChange: this.handleChange,
140
- disabled: disabled
141
- }), /*#__PURE__*/React.createElement("div", {
142
- className: cn('custom-input', [classes === null || classes === void 0 ? void 0 : classes.icon])
143
- }, /*#__PURE__*/React.createElement(CheckedIcon, {
144
- className: cn('icon')
145
- })), children), extraContent && /*#__PURE__*/React.createElement("span", {
146
- className: cn('extra-content')
147
- }, extraContent)));
39
+ var Checkbox = function Checkbox(_ref) {
40
+ var className = _ref.className,
41
+ _ref$fontSize = _ref.fontSize,
42
+ fontSize = _ref$fontSize === void 0 ? 'regular' : _ref$fontSize,
43
+ name = _ref.name,
44
+ _ref$color = _ref.color,
45
+ color = _ref$color === void 0 ? 'dark' : _ref$color,
46
+ value = _ref.value,
47
+ _ref$checked = _ref.checked,
48
+ checked = _ref$checked === void 0 ? false : _ref$checked,
49
+ disabled = _ref.disabled,
50
+ error = _ref.error,
51
+ children = _ref.children,
52
+ extraContent = _ref.extraContent,
53
+ dataAttrs = _ref.dataAttrs,
54
+ classes = _ref.classes,
55
+ onChange = _ref.onChange;
56
+ var isTouch = (0, _uiHelpers.detectTouch)();
57
+
58
+ var _useState = (0, _react.useState)(checked),
59
+ _useState2 = (0, _slicedToArray2["default"])(_useState, 2),
60
+ isChecked = _useState2[0],
61
+ setIsChecked = _useState2[1];
62
+
63
+ (0, _react.useEffect)(function () {
64
+ setIsChecked(checked);
65
+ }, [checked]);
66
+
67
+ var handleChange = function handleChange(e) {
68
+ if ((0, _uiHelpers.checkEventIsClickOrEnterPress)(e) || e.type === CHANGE_KEY) {
69
+ setIsChecked(!isChecked);
70
+ onChange && onChange(!isChecked);
148
71
  }
149
- }]);
150
- return Checkbox;
151
- }(React.Component);
72
+ };
73
+
74
+ return /*#__PURE__*/_react["default"].createElement("div", (0, _extends2["default"])({
75
+ className: cn('', {
76
+ 'font-size': fontSize,
77
+ color: color,
78
+ checked: isChecked,
79
+ disabled: disabled,
80
+ error: error
81
+ }, className)
82
+ }, (0, _uiHelpers.filterDataAttrs)(dataAttrs)), /*#__PURE__*/_react["default"].createElement("div", {
83
+ className: cn('inner', [classes === null || classes === void 0 ? void 0 : classes.inner])
84
+ }, /*#__PURE__*/_react["default"].createElement("label", {
85
+ className: cn('label', {
86
+ 'no-touch': !isTouch
87
+ })
88
+ }, /*#__PURE__*/_react["default"].createElement("input", {
89
+ className: cn('input'),
90
+ type: "checkbox",
91
+ tabIndex: -1,
92
+ name: name,
93
+ value: value,
94
+ checked: isChecked,
95
+ onChange: handleChange,
96
+ disabled: disabled
97
+ }), /*#__PURE__*/_react["default"].createElement("div", {
98
+ tabIndex: 0,
99
+ role: "checkbox",
100
+ "aria-checked": isChecked,
101
+ className: cn('custom-input', [classes === null || classes === void 0 ? void 0 : classes.icon]),
102
+ onKeyDown: handleChange
103
+ }, /*#__PURE__*/_react["default"].createElement(CheckedIcon, {
104
+ className: cn('icon')
105
+ })), children), extraContent && /*#__PURE__*/_react["default"].createElement("span", {
106
+ className: cn('extra-content')
107
+ }, extraContent)));
108
+ };
152
109
 
153
110
  Checkbox.propTypes = {
154
111
  className: PropTypes.string,
@@ -159,15 +116,10 @@ Checkbox.propTypes = {
159
116
  checked: PropTypes.bool,
160
117
  disabled: PropTypes.bool,
161
118
  error: PropTypes.bool,
162
- children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.element), PropTypes.element, PropTypes.string]),
163
- extraContent: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.element), PropTypes.element, PropTypes.string]),
119
+ children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.element.isRequired), PropTypes.element, PropTypes.string]).isRequired,
120
+ extraContent: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.element.isRequired), PropTypes.element, PropTypes.string]),
164
121
  dataAttrs: PropTypes.objectOf(PropTypes.string.isRequired),
165
122
  onChange: PropTypes.func
166
123
  };
167
- Checkbox.defaultProps = {
168
- color: 'dark',
169
- fontSize: 'regular',
170
- checked: false
171
- };
172
124
  var _default = Checkbox;
173
125
  exports["default"] = _default;
@@ -132,7 +132,7 @@ declare class Select<T extends SelectItemValueType> extends React.Component<ISel
132
132
  handleClosed: () => void;
133
133
  handleClickOutside: (e: MouseEvent) => void;
134
134
  handleOpenDropdown: () => void;
135
- handleSelectItem: (e: React.MouseEvent<HTMLDivElement, MouseEvent> | React.KeyboardEvent<HTMLDivElement>) => void;
135
+ handleSelectItem: (e: React.KeyboardEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
136
136
  handleHoverItem: (index: number) => (e: React.MouseEvent<HTMLDivElement, MouseEvent>) => void;
137
137
  handleComboboxFocus: (e: React.FocusEvent<HTMLInputElement>) => void;
138
138
  handleChangeCombobox: (e: React.ChangeEvent<HTMLInputElement>) => void;
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import type { AccessibilityEventTypeNative } from '@megafon/ui-helpers';
2
3
  import './Tooltip.less';
3
4
  export declare const Placement: {
4
5
  readonly LEFT: "left";
@@ -46,9 +47,9 @@ export interface ITooltipProps {
46
47
  contentShadow?: string;
47
48
  };
48
49
  /** Обработчик на открытие */
49
- onOpen?: (e: MouseEvent) => void;
50
+ onOpen?: (e: AccessibilityEventTypeNative) => void;
50
51
  /** Обработчик на закрытие */
51
- onClose?: (e: MouseEvent | FocusEvent) => void;
52
+ onClose?: (e: AccessibilityEventTypeNative | FocusEvent) => void;
52
53
  }
53
54
  declare const Tooltip: React.FC<ITooltipProps>;
54
55
  export default Tooltip;
@@ -35,8 +35,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "d
35
35
 
36
36
  var TOOLTIP_PADDING_FOR_FLIP = 14;
37
37
  var MOUSE_KEY = 'mousedown';
38
- var KEYBOARD_ENTER_KEY = 'Enter';
39
- var KEYBOARD_NUMPAD_ENTER_KEY = 'NumpadEnter';
40
38
  var TOUCH_KEY = 'touchstart';
41
39
  var Placement = {
42
40
  LEFT: 'left',
@@ -45,11 +43,6 @@ var Placement = {
45
43
  BOTTOM: 'bottom'
46
44
  };
47
45
  exports.Placement = Placement;
48
-
49
- var checkEventIsClickOrEnterPress = function checkEventIsClickOrEnterPress(e) {
50
- return e.type === TOUCH_KEY || e.type === MOUSE_KEY || e.code === KEYBOARD_ENTER_KEY || e.code === KEYBOARD_NUMPAD_ENTER_KEY;
51
- };
52
-
53
46
  var Paddings = {
54
47
  NONE: 'none',
55
48
  SMALL: 'small',
@@ -169,7 +162,7 @@ var Tooltip = function Tooltip(_ref) {
169
162
  }
170
163
  }, [isOpen, onOpen, setIsOpen]);
171
164
  var handleClick = (0, _react.useCallback)(function (e) {
172
- if (!checkEventIsClickOrEnterPress(e)) {
165
+ if (!(0, _uiHelpers.checkNativeEventIsClickOrEnterPress)(e)) {
173
166
  return;
174
167
  }
175
168
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@megafon/ui-core",
3
- "version": "3.0.0-beta.2",
3
+ "version": "3.0.0-beta.3",
4
4
  "files": [
5
5
  "dist",
6
6
  "styles"
@@ -53,7 +53,7 @@
53
53
  "@babel/preset-env": "^7.8.6",
54
54
  "@babel/preset-react": "^7.8.3",
55
55
  "@babel/preset-typescript": "^7.8.3",
56
- "@megafon/ui-icons": "^1.0.0-beta.1",
56
+ "@megafon/ui-icons": "^1.0.0-beta.2",
57
57
  "@svgr/core": "^2.4.1",
58
58
  "@testing-library/react-hooks": "^7.0.1",
59
59
  "@types/enzyme": "^3.10.5",
@@ -85,7 +85,7 @@
85
85
  "dependencies": {
86
86
  "@babel/runtime": "^7.8.4",
87
87
  "@datepicker-react/hooks": "^2.7.0",
88
- "@megafon/ui-helpers": "^2.0.0-beta.1",
88
+ "@megafon/ui-helpers": "^2.0.0-beta.2",
89
89
  "@popperjs/core": "^2.5.3",
90
90
  "core-js": "^3.6.4",
91
91
  "date-fns": "^2.16.1",
@@ -96,5 +96,5 @@
96
96
  "react-popper": "^2.2.3",
97
97
  "swiper": "^6.5.6"
98
98
  },
99
- "gitHead": "c67eea9c2568acefa0e6c8504e09da707c406703"
99
+ "gitHead": "c7d00f10bbf88ff8049558ee9b7fbe6cb9691547"
100
100
  }