colibri-ui 0.8.44 → 0.8.45

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.
@@ -16,6 +16,9 @@
16
16
  cursor: not-allowed;
17
17
  pointer-events: none;
18
18
  }
19
+ .item_selected {
20
+ background-color: var(--palette-bg-2, rgb(232, 240, 254));
21
+ }
19
22
  .item_variant_primary {
20
23
  background-color: var(--palette-white);
21
24
  }
@@ -27,24 +27,26 @@ var MenuItem = function MenuItem(_a) {
27
27
  onMouseEnter = _a.onMouseEnter,
28
28
  ref = _a.ref,
29
29
  props = tslib.__rest(_a, ["className", "isSelected", "variant", "disabled", "onClick", "children", "onMouseEnter", "ref"]);
30
- return (
31
- /*#__PURE__*/
32
- // eslint-disable-next-line jsx-a11y/click-events-have-key-events
33
- React__default.default.createElement("li", Object.assign({
34
- ref: ref,
35
- style: {
36
- backgroundColor: isSelected ? "var(--palette-bg-2, rgb(232, 240, 254))" : ""
37
- },
38
- "aria-label": "MenuItem",
39
- "data-testid": "menuitem",
40
- "aria-disabled": disabled,
41
- className: clx("item", _defineProperty__default.default({
42
- item_disabled: !!disabled
43
- }, "item_variant_".concat(variant), !!variant), className),
44
- onClick: !disabled ? onClick : undefined,
45
- onMouseEnter: onMouseEnter
46
- }, props), children)
47
- );
30
+ var handleKeyDown = function handleKeyDown(event) {
31
+ if (!disabled && (event.key === 'Enter' || event.key === ' ')) {
32
+ event.preventDefault();
33
+ onClick === null || onClick === void 0 ? void 0 : onClick(event);
34
+ }
35
+ };
36
+ return /*#__PURE__*/React__default.default.createElement("li", Object.assign({
37
+ ref: ref,
38
+ role: "menuitem",
39
+ tabIndex: disabled ? -1 : 0,
40
+ "data-testid": "menuitem",
41
+ "aria-disabled": disabled || undefined,
42
+ className: clx("item", _defineProperty__default.default({
43
+ item_disabled: disabled,
44
+ item_selected: isSelected
45
+ }, "item_variant_".concat(variant), true), className),
46
+ onClick: !disabled ? onClick : undefined,
47
+ onKeyDown: handleKeyDown,
48
+ onMouseEnter: onMouseEnter
49
+ }, props), children);
48
50
  };
49
51
 
50
52
  exports.default = MenuItem;
@@ -1,9 +1,9 @@
1
- import type { MouseEvent } from "react";
1
+ import type { KeyboardEvent, MouseEvent } from "react";
2
2
  import type { MenuVariant } from "../../index.props";
3
3
  export interface MenuItemProps {
4
4
  className?: string;
5
5
  isSelected?: boolean;
6
- onClick?: (e: MouseEvent) => void;
6
+ onClick?: (event: MouseEvent<Element> | KeyboardEvent<Element>) => void;
7
7
  variant?: MenuVariant;
8
8
  disabled?: boolean;
9
9
  ref?: React.Ref<HTMLLIElement>;
package/Menu/index.js CHANGED
@@ -22,26 +22,25 @@ var Menu = function Menu(_ref) {
22
22
  ref = _ref.ref;
23
23
  var renderChild = React.useMemo(function () {
24
24
  return React.Children.map(children, function (child) {
25
- if (/*#__PURE__*/React.isValidElement(child)) {
26
- var isSelected = selected ? selected.includes(String(child.key)) : undefined;
27
- var onClickHandler = function onClickHandler(event) {
28
- if (child.props.onClick) child.props.onClick(event);
29
- if (onClick && child.key) onClick(child.key.toString(), event);
30
- };
31
- return /*#__PURE__*/React.cloneElement(child, {
32
- isSelected: isSelected,
33
- onClick: onClickHandler,
34
- variant: variant
35
- });
36
- }
37
- return child;
25
+ if (! /*#__PURE__*/React.isValidElement(child)) return child;
26
+ var childKey = child.key ? String(child.key) : null;
27
+ var isSelected = selected && childKey ? selected.includes(childKey) : undefined;
28
+ var onClickHandler = function onClickHandler(event) {
29
+ var _a, _b;
30
+ (_b = (_a = child.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, event);
31
+ if (onClick && childKey) onClick(childKey, event);
32
+ };
33
+ return /*#__PURE__*/React.cloneElement(child, {
34
+ isSelected: isSelected,
35
+ onClick: onClickHandler,
36
+ variant: variant
37
+ });
38
38
  });
39
- },
40
- // eslint-disable-next-line react-hooks/exhaustive-deps
41
- [children, selected, onClick]);
39
+ }, [children, selected, onClick, variant]);
42
40
  return /*#__PURE__*/React__default.default.createElement("ul", {
43
41
  ref: ref,
44
- className: clx(styles__default.default.menu, className)
42
+ className: clx('menu', className),
43
+ role: "menu"
45
44
  }, renderChild);
46
45
  };
47
46
 
@@ -1,11 +1,11 @@
1
- import type { ReactElement, MouseEvent } from "react";
1
+ import type { ReactElement, KeyboardEvent, MouseEvent } from "react";
2
2
  import type { MenuItemProps } from "./components/MenuItem/index.props";
3
3
  export type MenuVariant = "primary";
4
4
  export type Props = {
5
5
  selected?: string[];
6
6
  variant?: MenuVariant;
7
7
  className?: string;
8
- onClick?: (key: string, e: MouseEvent) => void;
8
+ onClick?: (key: string, e: MouseEvent | KeyboardEvent) => void;
9
9
  children?: ReactElement<MenuItemProps> | ReactElement<MenuItemProps>[];
10
10
  ref?: React.Ref<HTMLUListElement>;
11
11
  };
@@ -16,6 +16,9 @@
16
16
  cursor: not-allowed;
17
17
  pointer-events: none;
18
18
  }
19
+ .item_selected {
20
+ background-color: var(--palette-bg-2, rgb(232, 240, 254));
21
+ }
19
22
  .item_variant_primary {
20
23
  background-color: var(--palette-white);
21
24
  }
@@ -16,24 +16,26 @@ var MenuItem = function MenuItem(_a) {
16
16
  onMouseEnter = _a.onMouseEnter,
17
17
  ref = _a.ref,
18
18
  props = __rest(_a, ["className", "isSelected", "variant", "disabled", "onClick", "children", "onMouseEnter", "ref"]);
19
- return (
20
- /*#__PURE__*/
21
- // eslint-disable-next-line jsx-a11y/click-events-have-key-events
22
- React__default.createElement("li", Object.assign({
23
- ref: ref,
24
- style: {
25
- backgroundColor: isSelected ? "var(--palette-bg-2, rgb(232, 240, 254))" : ""
26
- },
27
- "aria-label": "MenuItem",
28
- "data-testid": "menuitem",
29
- "aria-disabled": disabled,
30
- className: clx("item", _defineProperty({
31
- item_disabled: !!disabled
32
- }, "item_variant_".concat(variant), !!variant), className),
33
- onClick: !disabled ? onClick : undefined,
34
- onMouseEnter: onMouseEnter
35
- }, props), children)
36
- );
19
+ var handleKeyDown = function handleKeyDown(event) {
20
+ if (!disabled && (event.key === 'Enter' || event.key === ' ')) {
21
+ event.preventDefault();
22
+ onClick === null || onClick === void 0 ? void 0 : onClick(event);
23
+ }
24
+ };
25
+ return /*#__PURE__*/React__default.createElement("li", Object.assign({
26
+ ref: ref,
27
+ role: "menuitem",
28
+ tabIndex: disabled ? -1 : 0,
29
+ "data-testid": "menuitem",
30
+ "aria-disabled": disabled || undefined,
31
+ className: clx("item", _defineProperty({
32
+ item_disabled: disabled,
33
+ item_selected: isSelected
34
+ }, "item_variant_".concat(variant), true), className),
35
+ onClick: !disabled ? onClick : undefined,
36
+ onKeyDown: handleKeyDown,
37
+ onMouseEnter: onMouseEnter
38
+ }, props), children);
37
39
  };
38
40
 
39
41
  export { MenuItem as default };
@@ -1,9 +1,9 @@
1
- import type { MouseEvent } from "react";
1
+ import type { KeyboardEvent, MouseEvent } from "react";
2
2
  import type { MenuVariant } from "../../index.props";
3
3
  export interface MenuItemProps {
4
4
  className?: string;
5
5
  isSelected?: boolean;
6
- onClick?: (e: MouseEvent) => void;
6
+ onClick?: (event: MouseEvent<Element> | KeyboardEvent<Element>) => void;
7
7
  variant?: MenuVariant;
8
8
  disabled?: boolean;
9
9
  ref?: React.Ref<HTMLLIElement>;
package/esm/Menu/index.js CHANGED
@@ -12,26 +12,25 @@ var Menu = function Menu(_ref) {
12
12
  ref = _ref.ref;
13
13
  var renderChild = useMemo(function () {
14
14
  return Children.map(children, function (child) {
15
- if (/*#__PURE__*/isValidElement(child)) {
16
- var isSelected = selected ? selected.includes(String(child.key)) : undefined;
17
- var onClickHandler = function onClickHandler(event) {
18
- if (child.props.onClick) child.props.onClick(event);
19
- if (onClick && child.key) onClick(child.key.toString(), event);
20
- };
21
- return /*#__PURE__*/cloneElement(child, {
22
- isSelected: isSelected,
23
- onClick: onClickHandler,
24
- variant: variant
25
- });
26
- }
27
- return child;
15
+ if (! /*#__PURE__*/isValidElement(child)) return child;
16
+ var childKey = child.key ? String(child.key) : null;
17
+ var isSelected = selected && childKey ? selected.includes(childKey) : undefined;
18
+ var onClickHandler = function onClickHandler(event) {
19
+ var _a, _b;
20
+ (_b = (_a = child.props).onClick) === null || _b === void 0 ? void 0 : _b.call(_a, event);
21
+ if (onClick && childKey) onClick(childKey, event);
22
+ };
23
+ return /*#__PURE__*/cloneElement(child, {
24
+ isSelected: isSelected,
25
+ onClick: onClickHandler,
26
+ variant: variant
27
+ });
28
28
  });
29
- },
30
- // eslint-disable-next-line react-hooks/exhaustive-deps
31
- [children, selected, onClick]);
29
+ }, [children, selected, onClick, variant]);
32
30
  return /*#__PURE__*/React__default.createElement("ul", {
33
31
  ref: ref,
34
- className: clx(styles.menu, className)
32
+ className: clx('menu', className),
33
+ role: "menu"
35
34
  }, renderChild);
36
35
  };
37
36
 
@@ -1,11 +1,11 @@
1
- import type { ReactElement, MouseEvent } from "react";
1
+ import type { ReactElement, KeyboardEvent, MouseEvent } from "react";
2
2
  import type { MenuItemProps } from "./components/MenuItem/index.props";
3
3
  export type MenuVariant = "primary";
4
4
  export type Props = {
5
5
  selected?: string[];
6
6
  variant?: MenuVariant;
7
7
  className?: string;
8
- onClick?: (key: string, e: MouseEvent) => void;
8
+ onClick?: (key: string, e: MouseEvent | KeyboardEvent) => void;
9
9
  children?: ReactElement<MenuItemProps> | ReactElement<MenuItemProps>[];
10
10
  ref?: React.Ref<HTMLUListElement>;
11
11
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "colibri-ui",
3
- "version": "0.8.44",
3
+ "version": "0.8.45",
4
4
  "description": "React UI components library",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",