carbon-react 141.0.7 → 141.1.0

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,5 +1,5 @@
1
1
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
- import React, { useCallback, useEffect, useRef, useState } from "react";
2
+ import React, { useCallback, useEffect, useRef, useState, useMemo } from "react";
3
3
  import PropTypes from "prop-types";
4
4
  import { Transition } from "react-transition-group";
5
5
  import { flip, offset } from "@floating-ui/dom";
@@ -56,14 +56,14 @@ export const renderClose = ({
56
56
  })), /*#__PURE__*/React.createElement(Icon, {
57
57
  type: "close"
58
58
  }));
59
- function getPopoverMiddleware(shouldCoverButton) {
60
- return [offset(shouldCoverButton ? ({
59
+ function usePopoverMiddleware(shouldCoverButton) {
60
+ return useMemo(() => [offset(shouldCoverButton ? ({
61
61
  rects
62
62
  }) => ({
63
63
  mainAxis: -rects.reference.height
64
64
  }) : 6), flip({
65
65
  fallbackStrategy: "initialPlacement"
66
- })];
66
+ })], [shouldCoverButton]);
67
67
  }
68
68
  export const PopoverContainer = ({
69
69
  children,
@@ -93,6 +93,7 @@ export const PopoverContainer = ({
93
93
  const popoverContainerId = title ? `PopoverContainer_${guid.current}` : undefined;
94
94
  const isOpen = isControlled ? open : isOpenInternal;
95
95
  const reduceMotion = !useMediaQuery("screen and (prefers-reduced-motion: no-preference)");
96
+ const popoverMiddleware = usePopoverMiddleware(shouldCoverButton);
96
97
  const closePopover = useCallback(ev => {
97
98
  if (!isControlled) {
98
99
  setIsOpenInternal(false);
@@ -198,7 +199,7 @@ export const PopoverContainer = ({
198
199
  reference: popoverReference,
199
200
  placement: position === "right" ? "bottom-start" : "bottom-end",
200
201
  popoverStrategy: disableAnimation || reduceMotion ? "fixed" : "absolute",
201
- middleware: getPopoverMiddleware(shouldCoverButton),
202
+ middleware: popoverMiddleware,
202
203
  childRefOverride: popoverContentNodeRef
203
204
  }, childrenToRender(state))));
204
205
  };
@@ -9,7 +9,7 @@ export interface OptionGroupHeaderProps extends TagProps {
9
9
  */
10
10
  id?: string;
11
11
  /** Heading text */
12
- label: string;
12
+ label?: string;
13
13
  /** Any valid Carbon icon name */
14
14
  icon?: IconProps["type"];
15
15
  /**
@@ -17,6 +17,11 @@ export interface OptionGroupHeaderProps extends TagProps {
17
17
  * @ignore
18
18
  * object containing CSS styles to be passed to the underlying DOM element */
19
19
  style?: CSSProperties;
20
+ /**
21
+ * Content to be rendered inside the OptionGroupHeader.
22
+ * When the `children` prop is passed it will take precedence over the `label` and
23
+ * `icon` props meaning they will not be rendered */
24
+ children?: React.ReactNode;
20
25
  }
21
26
  declare const OptionGroupHeader: React.ForwardRefExoticComponent<OptionGroupHeaderProps & React.RefAttributes<HTMLDivElement>>;
22
27
  export default OptionGroupHeader;
@@ -9,26 +9,32 @@ const OptionGroupHeader = /*#__PURE__*/React.forwardRef(({
9
9
  icon,
10
10
  style,
11
11
  id,
12
+ children,
12
13
  ...rest
13
14
  }, ref) => {
14
15
  const internalIdRef = useRef(id || guid());
16
+ if (!(children || label)) {
17
+ // eslint-disable-next-line no-console
18
+ console.warn("OptionGroupHeader requires either a label or children to be provided");
19
+ }
15
20
  return /*#__PURE__*/React.createElement(StyledOptionGroupHeader, _extends({
16
21
  style: style,
17
22
  id: internalIdRef.current
18
23
  }, rest, {
19
24
  ref: ref
20
- }), icon && /*#__PURE__*/React.createElement(Icon, {
25
+ }), children || /*#__PURE__*/React.createElement(React.Fragment, null, icon && /*#__PURE__*/React.createElement(Icon, {
21
26
  type: icon
22
- }), /*#__PURE__*/React.createElement("h4", null, label));
27
+ }), /*#__PURE__*/React.createElement("h4", null, label)));
23
28
  });
24
29
  if (process.env.NODE_ENV !== "production") {
25
30
  OptionGroupHeader.propTypes = {
31
+ "children": PropTypes.node,
26
32
  "data-component": PropTypes.string,
27
33
  "data-element": PropTypes.string,
28
34
  "data-role": PropTypes.string,
29
35
  "icon": PropTypes.oneOf(["accessibility_web", "add", "admin", "alert_on", "alert", "analysis", "app_facebook", "app_instagram", "app_tiktok", "app_twitter", "app_youtube", "apps", "arrow_bottom_right_circle", "arrow_down", "arrow_left_boxed", "arrow_left_right_small", "arrow_left_small", "arrow_left", "arrow_right_small", "arrow_right", "arrow_top_left_circle", "arrow_up", "arrow", "arrows_left_right", "attach", "bank_with_card", "bank", "basket_with_squares", "basket", "bed", "bill_paid", "bill_unpaid", "bin", "biometric", "block_arrow_right", "blocked_square", "blocked", "bold", "box_arrow_left", "box_arrow_right", "boxed_shapes", "bulk_destroy", "bullet_list_dotted", "bullet_list_numbers", "bullet_list", "business", "calendar_pay_date", "calendar_today", "calendar", "call", "camera", "car_lock", "car_money", "car_repair", "card_view", "card_wallet", "caret_down", "caret_large_down", "caret_large_left", "caret_large_right", "caret_large_up", "caret_left", "caret_right", "caret_up", "cart", "cash", "chart_bar", "chart_line", "chart_pie", "chat_notes", "chat", "check_all", "check_none", "chevron_down_thick", "chevron_down", "chevron_left_thick", "chevron_left", "chevron_right_thick", "chevron_right", "chevron_up_thick", "chevron_up", "circle_with_dots", "circles_connection", "clock", "close", "cloud_co2", "coins", "collaborate", "computer_clock", "connect_off", "connect", "construction", "contact_card", "contacts", "copy", "create", "credit_card_slash", "credit_card", "cross_circle", "cross", "csv", "dashboard", "delete", "delivery", "disconnect", "disputed", "document_right_align", "document_tick", "document_vertical_lines", "download", "draft", "drag_vertical", "drag", "drill", "dropdown", "duplicate", "edit", "edited", "ellipsis_horizontal", "ellipsis_vertical", "email_switch", "email", "entry", "envelope_dollar", "envelope_euro", "error_square", "error", "euro", "expand", "export", "factory", "favourite_lined", "favourite", "fax", "feedback", "file_excel", "file_generic", "file_image", "file_pdf", "file_word", "files_leaning", "filter_new", "filter", "fit_height", "fit_width", "flag", "folder", "form_refresh", "gift", "go", "graduation_hat", "graph", "grid", "hand_cash_coins", "hand_cash_note", "heart_pulse", "help", "hide", "home", "image", "import", "in_progress", "in_transit", "individual", "info", "intranet", "italic", "job_seeked", "key", "laptop", "leaf", "ledger_arrow_left", "ledger_arrow_right", "ledger", "lightbulb_off", "lightbulb_on", "like_no", "like", "link_cloud", "link_on", "link", "list_view", "location", "locked", "logout", "lookup", "maintenance", "marker", "message", "messages", "microphone", "minimise", "minus_large", "minus", "mobile", "money_bag", "new", "none", "old_warning", "palm_tree", "pause_circle", "pause", "pdf", "people_switch", "people", "percentage_boxed", "person_info", "person_tick", "person", "petrol_pump", "phone", "piggy_bank", "pin", "plane", "play_circle", "play", "plus_large", "plus", "pound", "print", "progress", "progressed", "protect", "question_hollow", "question_mark", "question", "recruiting", "refresh_clock", "refresh", "remove", "sage_coin", "save", "scan", "search", "send", "services", "settings_old", "settings", "share", "shop", "sort_down", "sort_up", "spanner", "split_container", "split", "square_dot", "squares_nine", "stacked_boxes", "stacked_squares", "submitted", "success", "support_online", "sync", "tag", "talk", "target_man", "target", "theatre_masks", "three_boxes", "tick_circle", "tick_thick", "tick", "true_tick", "u_turn_left", "u_turn_right", "undo", "unlocked", "upload", "uploaded", "video", "view", "volunteering", "warning", "website", "welfare"]),
30
36
  "id": PropTypes.string,
31
- "label": PropTypes.string.isRequired,
37
+ "label": PropTypes.string,
32
38
  "style": PropTypes.object
33
39
  };
34
40
  }
@@ -67,14 +67,14 @@ const renderClose = ({
67
67
  type: "close"
68
68
  }));
69
69
  exports.renderClose = renderClose;
70
- function getPopoverMiddleware(shouldCoverButton) {
71
- return [(0, _dom.offset)(shouldCoverButton ? ({
70
+ function usePopoverMiddleware(shouldCoverButton) {
71
+ return (0, _react.useMemo)(() => [(0, _dom.offset)(shouldCoverButton ? ({
72
72
  rects
73
73
  }) => ({
74
74
  mainAxis: -rects.reference.height
75
75
  }) : 6), (0, _dom.flip)({
76
76
  fallbackStrategy: "initialPlacement"
77
- })];
77
+ })], [shouldCoverButton]);
78
78
  }
79
79
  const PopoverContainer = ({
80
80
  children,
@@ -104,6 +104,7 @@ const PopoverContainer = ({
104
104
  const popoverContainerId = title ? `PopoverContainer_${guid.current}` : undefined;
105
105
  const isOpen = isControlled ? open : isOpenInternal;
106
106
  const reduceMotion = !(0, _useMediaQuery.default)("screen and (prefers-reduced-motion: no-preference)");
107
+ const popoverMiddleware = usePopoverMiddleware(shouldCoverButton);
107
108
  const closePopover = (0, _react.useCallback)(ev => {
108
109
  if (!isControlled) {
109
110
  setIsOpenInternal(false);
@@ -209,7 +210,7 @@ const PopoverContainer = ({
209
210
  reference: popoverReference,
210
211
  placement: position === "right" ? "bottom-start" : "bottom-end",
211
212
  popoverStrategy: disableAnimation || reduceMotion ? "fixed" : "absolute",
212
- middleware: getPopoverMiddleware(shouldCoverButton),
213
+ middleware: popoverMiddleware,
213
214
  childRefOverride: popoverContentNodeRef
214
215
  }, childrenToRender(state))));
215
216
  };
@@ -9,7 +9,7 @@ export interface OptionGroupHeaderProps extends TagProps {
9
9
  */
10
10
  id?: string;
11
11
  /** Heading text */
12
- label: string;
12
+ label?: string;
13
13
  /** Any valid Carbon icon name */
14
14
  icon?: IconProps["type"];
15
15
  /**
@@ -17,6 +17,11 @@ export interface OptionGroupHeaderProps extends TagProps {
17
17
  * @ignore
18
18
  * object containing CSS styles to be passed to the underlying DOM element */
19
19
  style?: CSSProperties;
20
+ /**
21
+ * Content to be rendered inside the OptionGroupHeader.
22
+ * When the `children` prop is passed it will take precedence over the `label` and
23
+ * `icon` props meaning they will not be rendered */
24
+ children?: React.ReactNode;
20
25
  }
21
26
  declare const OptionGroupHeader: React.ForwardRefExoticComponent<OptionGroupHeaderProps & React.RefAttributes<HTMLDivElement>>;
22
27
  export default OptionGroupHeader;
@@ -18,26 +18,32 @@ const OptionGroupHeader = /*#__PURE__*/_react.default.forwardRef(({
18
18
  icon,
19
19
  style,
20
20
  id,
21
+ children,
21
22
  ...rest
22
23
  }, ref) => {
23
24
  const internalIdRef = (0, _react.useRef)(id || (0, _guid.default)());
25
+ if (!(children || label)) {
26
+ // eslint-disable-next-line no-console
27
+ console.warn("OptionGroupHeader requires either a label or children to be provided");
28
+ }
24
29
  return /*#__PURE__*/_react.default.createElement(_optionGroupHeader.default, _extends({
25
30
  style: style,
26
31
  id: internalIdRef.current
27
32
  }, rest, {
28
33
  ref: ref
29
- }), icon && /*#__PURE__*/_react.default.createElement(_icon.default, {
34
+ }), children || /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, icon && /*#__PURE__*/_react.default.createElement(_icon.default, {
30
35
  type: icon
31
- }), /*#__PURE__*/_react.default.createElement("h4", null, label));
36
+ }), /*#__PURE__*/_react.default.createElement("h4", null, label)));
32
37
  });
33
38
  if (process.env.NODE_ENV !== "production") {
34
39
  OptionGroupHeader.propTypes = {
40
+ "children": _propTypes.default.node,
35
41
  "data-component": _propTypes.default.string,
36
42
  "data-element": _propTypes.default.string,
37
43
  "data-role": _propTypes.default.string,
38
44
  "icon": _propTypes.default.oneOf(["accessibility_web", "add", "admin", "alert_on", "alert", "analysis", "app_facebook", "app_instagram", "app_tiktok", "app_twitter", "app_youtube", "apps", "arrow_bottom_right_circle", "arrow_down", "arrow_left_boxed", "arrow_left_right_small", "arrow_left_small", "arrow_left", "arrow_right_small", "arrow_right", "arrow_top_left_circle", "arrow_up", "arrow", "arrows_left_right", "attach", "bank_with_card", "bank", "basket_with_squares", "basket", "bed", "bill_paid", "bill_unpaid", "bin", "biometric", "block_arrow_right", "blocked_square", "blocked", "bold", "box_arrow_left", "box_arrow_right", "boxed_shapes", "bulk_destroy", "bullet_list_dotted", "bullet_list_numbers", "bullet_list", "business", "calendar_pay_date", "calendar_today", "calendar", "call", "camera", "car_lock", "car_money", "car_repair", "card_view", "card_wallet", "caret_down", "caret_large_down", "caret_large_left", "caret_large_right", "caret_large_up", "caret_left", "caret_right", "caret_up", "cart", "cash", "chart_bar", "chart_line", "chart_pie", "chat_notes", "chat", "check_all", "check_none", "chevron_down_thick", "chevron_down", "chevron_left_thick", "chevron_left", "chevron_right_thick", "chevron_right", "chevron_up_thick", "chevron_up", "circle_with_dots", "circles_connection", "clock", "close", "cloud_co2", "coins", "collaborate", "computer_clock", "connect_off", "connect", "construction", "contact_card", "contacts", "copy", "create", "credit_card_slash", "credit_card", "cross_circle", "cross", "csv", "dashboard", "delete", "delivery", "disconnect", "disputed", "document_right_align", "document_tick", "document_vertical_lines", "download", "draft", "drag_vertical", "drag", "drill", "dropdown", "duplicate", "edit", "edited", "ellipsis_horizontal", "ellipsis_vertical", "email_switch", "email", "entry", "envelope_dollar", "envelope_euro", "error_square", "error", "euro", "expand", "export", "factory", "favourite_lined", "favourite", "fax", "feedback", "file_excel", "file_generic", "file_image", "file_pdf", "file_word", "files_leaning", "filter_new", "filter", "fit_height", "fit_width", "flag", "folder", "form_refresh", "gift", "go", "graduation_hat", "graph", "grid", "hand_cash_coins", "hand_cash_note", "heart_pulse", "help", "hide", "home", "image", "import", "in_progress", "in_transit", "individual", "info", "intranet", "italic", "job_seeked", "key", "laptop", "leaf", "ledger_arrow_left", "ledger_arrow_right", "ledger", "lightbulb_off", "lightbulb_on", "like_no", "like", "link_cloud", "link_on", "link", "list_view", "location", "locked", "logout", "lookup", "maintenance", "marker", "message", "messages", "microphone", "minimise", "minus_large", "minus", "mobile", "money_bag", "new", "none", "old_warning", "palm_tree", "pause_circle", "pause", "pdf", "people_switch", "people", "percentage_boxed", "person_info", "person_tick", "person", "petrol_pump", "phone", "piggy_bank", "pin", "plane", "play_circle", "play", "plus_large", "plus", "pound", "print", "progress", "progressed", "protect", "question_hollow", "question_mark", "question", "recruiting", "refresh_clock", "refresh", "remove", "sage_coin", "save", "scan", "search", "send", "services", "settings_old", "settings", "share", "shop", "sort_down", "sort_up", "spanner", "split_container", "split", "square_dot", "squares_nine", "stacked_boxes", "stacked_squares", "submitted", "success", "support_online", "sync", "tag", "talk", "target_man", "target", "theatre_masks", "three_boxes", "tick_circle", "tick_thick", "tick", "true_tick", "u_turn_left", "u_turn_right", "undo", "unlocked", "upload", "uploaded", "video", "view", "volunteering", "warning", "website", "welfare"]),
39
45
  "id": _propTypes.default.string,
40
- "label": _propTypes.default.string.isRequired,
46
+ "label": _propTypes.default.string,
41
47
  "style": _propTypes.default.object
42
48
  };
43
49
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "carbon-react",
3
- "version": "141.0.7",
3
+ "version": "141.1.0",
4
4
  "description": "A library of reusable React components for easily building user interfaces.",
5
5
  "files": [
6
6
  "lib",