@canonical/react-components 2.10.0 → 2.12.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,6 +1,7 @@
1
- import React from "react";
1
+ import React, { type ReactNode } from "react";
2
2
  import type { MouseEvent, HTMLProps } from "react";
3
3
  import { ValueOf, PropsWithSpread } from "../../types";
4
+ import { ICONS } from "../Icon";
4
5
  export declare enum Label {
5
6
  Dismiss = "Dismiss"
6
7
  }
@@ -15,6 +16,29 @@ export type Props = PropsWithSpread<{
15
16
  * The appearance of the chip.
16
17
  */
17
18
  appearance?: ValueOf<typeof ChipType>;
19
+ /**
20
+ * Whether the chip is read-only.
21
+ * If true, the chip will not be interactive.
22
+ */
23
+ isReadOnly?: boolean;
24
+ /**
25
+ * A badge to display on the chip.
26
+ */
27
+ badge?: ReactNode;
28
+ /**
29
+ * The name of an icon to display on the chip.
30
+ */
31
+ iconName?: ValueOf<typeof ICONS> | string;
32
+ /**
33
+ * Whether the chip is dense.
34
+ * Reduces the height of the chip by removing padding.
35
+ */
36
+ isDense?: boolean;
37
+ /**
38
+ * Whether the chip is inline.
39
+ * If true, the chip will be displayed inline with other content (such as text).
40
+ */
41
+ isInline?: boolean;
18
42
  /**
19
43
  * The lead for the chip.
20
44
  */
@@ -53,5 +77,5 @@ export type Props = PropsWithSpread<{
53
77
  *
54
78
  * It can be used to display a small value attached to a component.
55
79
  */
56
- declare const Chip: ({ appearance, lead, onClick, onDismiss, quoteValue, selected, subString, value, ...props }: Props) => React.JSX.Element;
80
+ declare const Chip: ({ appearance, lead, onClick, onDismiss, quoteValue, selected, subString, isReadOnly, isDense, isInline, iconName, badge, value, ...props }: Props) => React.JSX.Element;
57
81
  export default Chip;
@@ -33,6 +33,11 @@ const Chip = _ref => {
33
33
  quoteValue,
34
34
  selected,
35
35
  subString = "",
36
+ isReadOnly = false,
37
+ isDense = false,
38
+ isInline = false,
39
+ iconName,
40
+ badge,
36
41
  value,
37
42
  ...props
38
43
  } = _ref;
@@ -50,19 +55,28 @@ const Chip = _ref => {
50
55
  }
51
56
  };
52
57
  const chipValue = (0, _utils.highlightSubString)(value, subString).text;
53
- const chipContent = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, lead && /*#__PURE__*/_react.default.createElement("span", {
58
+ const chipContent = /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, iconName && /*#__PURE__*/_react.default.createElement("i", {
59
+ className: "p-icon--".concat(iconName)
60
+ }), lead && /*#__PURE__*/_react.default.createElement("span", {
54
61
  className: "p-chip__lead"
55
62
  }, lead.toUpperCase()), /*#__PURE__*/_react.default.createElement("span", {
56
63
  className: "p-chip__value",
57
64
  dangerouslySetInnerHTML: {
58
65
  __html: quoteValue ? "'".concat(chipValue, "'") : chipValue
59
66
  }
60
- }));
67
+ }), badge && badge);
61
68
  const chipClassName = (0, _classnames.default)({
62
69
  ["p-chip--".concat(appearance)]: !!appearance,
63
- "p-chip": !appearance
70
+ "p-chip": !appearance,
71
+ "is-dense": isDense,
72
+ "is-readonly": isReadOnly,
73
+ "is-inline": isInline
64
74
  }, props.className);
65
- if (onDismiss) {
75
+ if (isReadOnly) {
76
+ return /*#__PURE__*/_react.default.createElement("span", _extends({}, props, {
77
+ className: chipClassName
78
+ }), chipContent);
79
+ } else if (onDismiss) {
66
80
  return /*#__PURE__*/_react.default.createElement("span", _extends({}, props, {
67
81
  className: chipClassName
68
82
  }), chipContent, /*#__PURE__*/_react.default.createElement("button", {
@@ -7,3 +7,8 @@ export declare const Default: Story;
7
7
  export declare const LeadValue: Story;
8
8
  export declare const Appearance: Story;
9
9
  export declare const Dismissible: Story;
10
+ export declare const Dense: Story;
11
+ export declare const Inline: Story;
12
+ export declare const ReadOnly: Story;
13
+ export declare const WithIcon: Story;
14
+ export declare const WithBadge: Story;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.LeadValue = exports.Dismissible = exports.Default = exports.Appearance = void 0;
6
+ exports.default = exports.WithIcon = exports.WithBadge = exports.ReadOnly = exports.LeadValue = exports.Inline = exports.Dismissible = exports.Dense = exports.Default = exports.Appearance = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  var _Chip = _interopRequireDefault(require("./Chip"));
9
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
@@ -42,4 +42,46 @@ const Dismissible = exports.Dismissible = {
42
42
  }
43
43
  }),
44
44
  name: "Dismissible"
45
+ };
46
+ const Dense = exports.Dense = {
47
+ render: () => /*#__PURE__*/_react.default.createElement(_Chip.default, {
48
+ lead: "Owner",
49
+ value: "Bob",
50
+ isDense: true
51
+ }),
52
+ name: "Dense"
53
+ };
54
+ const Inline = exports.Inline = {
55
+ render: () => /*#__PURE__*/_react.default.createElement("p", null, "This is text with an inline", " ", /*#__PURE__*/_react.default.createElement(_Chip.default, {
56
+ value: "chip",
57
+ isDense: true,
58
+ isInline: true
59
+ })),
60
+ name: "Inline"
61
+ };
62
+ const ReadOnly = exports.ReadOnly = {
63
+ render: () => /*#__PURE__*/_react.default.createElement(_Chip.default, {
64
+ lead: "Owner",
65
+ value: "Bob",
66
+ isReadOnly: true
67
+ }),
68
+ name: "Read-only"
69
+ };
70
+ const WithIcon = exports.WithIcon = {
71
+ render: () => /*#__PURE__*/_react.default.createElement(_Chip.default, {
72
+ value: "Users",
73
+ iconName: "user"
74
+ }),
75
+ name: "With Icon"
76
+ };
77
+ const WithBadge = exports.WithBadge = {
78
+ render: () => /*#__PURE__*/_react.default.createElement(_Chip.default, {
79
+ lead: "Owner",
80
+ value: "Bob",
81
+ badge: /*#__PURE__*/_react.default.createElement("span", {
82
+ className: "p-badge",
83
+ "aria-label": "More than 2.5 billion items"
84
+ }, "2.5B")
85
+ }),
86
+ name: "With Badge"
45
87
  };
@@ -34,6 +34,7 @@ const PreloadedList = () => {
34
34
  toastNotify.success("Settings saved successfully");
35
35
  toastNotify.info("Your changes are syncing in the background");
36
36
  toastNotify.failure("Save failed", new Error("500 Internal Server Error"), "Please try again.");
37
+ toastNotify.caution("You have unsaved changes.");
37
38
  toastNotify.toggleListView();
38
39
  // eslint-disable-next-line react-hooks/exhaustive-deps
39
40
  }, []);
@@ -8,9 +8,10 @@ export type ToastNotificationType = NotificationType & {
8
8
  };
9
9
  interface ToastNotificationHelper {
10
10
  notifications: ToastNotificationType[];
11
- success: (message: ReactNode, actions?: NotificationAction[]) => ToastNotificationType;
12
- info: (message: ReactNode, title?: string) => ToastNotificationType;
11
+ success: (message: ReactNode, actions?: NotificationAction[], title?: string) => ToastNotificationType;
12
+ info: (message: ReactNode, title?: string, actions?: NotificationAction[]) => ToastNotificationType;
13
13
  failure: (title: string, error: unknown, message?: ReactNode, actions?: NotificationAction[]) => ToastNotificationType;
14
+ caution: (message: ReactNode, actions?: NotificationAction[], title?: string) => ToastNotificationType;
14
15
  clear: (notification?: ToastNotificationType[]) => void;
15
16
  toggleListView: () => void;
16
17
  isListView: boolean;
@@ -25,11 +26,12 @@ export type GroupedNotificationCount = {
25
26
  Wrap your application with this provider, and in any child component you can get the helper with `const toastNotify = useToastNotification()` to trigger notifications.
26
27
  Notifications automatically dismiss after a delay unless manually dismissed or expanded.
27
28
 
28
- | **Values** | **Description** |
29
- |----------------------------------|---------------------------------------------------------------------------------|
30
- | `toastNotify.success()` | Displays a success toast. Optionally accepts actions. |
29
+ | **Values** | **Description** |
30
+ |----------------------------------|--------------------------------------------------------------------------------|
31
+ | `toastNotify.success()` | Displays a success toast. Optionally accepts actions and a title. |
31
32
  | `toastNotify.info()` | Displays an info toast. Optionally accepts a custom title. |
32
33
  | `toastNotify.failure()` | Displays a failure toast with an error and optional message or actions. |
34
+ | `toastNotify.caution()` | Displays a caution toast. Optionally accepts actions and a title. |
33
35
  | `toastNotify.clear()` | Clears specific toasts, or all toasts if none are specified. |
34
36
  | `toastNotify.toggleListView()` | Toggles the notification list view open or closed. |
35
37
  | `toastNotify.countBySeverity` | Returns the count of notifications grouped by severity (e.g., success, info). |
@@ -41,6 +43,7 @@ Some example usages:
41
43
  toastNotify.success("Your changes have been saved.");
42
44
  toastNotify.success("Your changes have been saved.", [{label: "Undo", onClick: () => console.log("Undo clicked")}]);
43
45
  ```
46
+
44
47
  2. **Show an info toast:**
45
48
  ```
46
49
  toastNotify.info("Your changes are syncing in the background.");
@@ -52,16 +55,25 @@ toastNotify.info("Your changes are syncing in the background.", "Syncing");
52
55
  toastNotify.failure("Save failed", new Error("500 Internal Server Error"), "Please try again.");
53
56
  toastNotify.failure("Save failed", new Error("500 Internal Server Error"), "Please try again.", [{label: "Retry", onClick: () => console.log("Retry clicked")}]);
54
57
  ```
55
- 4. **Clear notifications:**
58
+
59
+ 4. **Show a caution toast:**
60
+ ```
61
+ toastNotify.caution("Your changes have not been saved.");
62
+ toastNotify.caution("Your changes have not been saved.", [{label: "Undo", onClick: () => console.log("Undo clicked")}]);
63
+ ```
64
+
65
+ 5. **Clear notifications:**
56
66
  ```
57
67
  toastNotify.clear(); // clears all toast notifications
58
68
  toastNotify.clear([notificationId]); // clears specific toast notifications
59
69
  ```
60
- 5. **Toggle the notification list view:**
70
+
71
+ 6. **Toggle the notification list view:**
61
72
  ```
62
73
  toastNotify.toggleListView();
63
74
  ```
64
- 6. **Get the count of notifications by severity:**
75
+
76
+ 7. **Get the count of notifications by severity:**
65
77
  ```
66
78
  const count = toastNotify.countBySeverity;
67
79
  console.log(count.positive);
@@ -21,12 +21,14 @@ const initialNotification = {
21
21
  const ToastNotificationContext = /*#__PURE__*/(0, _react.createContext)({
22
22
  /** List of all active toast notifications */
23
23
  notifications: [],
24
- /** Show a success toast. Optionally pass actions. */
24
+ /** Show a success toast. Optionally pass actions and a title. */
25
25
  success: () => initialNotification,
26
- /** Show an info toast. Optionally pass a custom title. */
26
+ /** Show an info toast. Optionally pass a custom title and actions. */
27
27
  info: () => initialNotification,
28
28
  /** Show a failure toast with an error and optional message/actions. */
29
29
  failure: () => initialNotification,
30
+ /** Show a caution toast. Optionally pass actions and a title. */
31
+ caution: () => initialNotification,
30
32
  /** Clear one or more specific toasts, or all if none provided. */
31
33
  clear: () => null,
32
34
  /** Toggle between single toast view and list view. */
@@ -43,11 +45,12 @@ const ToastNotificationContext = /*#__PURE__*/(0, _react.createContext)({
43
45
  Wrap your application with this provider, and in any child component you can get the helper with `const toastNotify = useToastNotification()` to trigger notifications.
44
46
  Notifications automatically dismiss after a delay unless manually dismissed or expanded.
45
47
 
46
- | **Values** | **Description** |
47
- |----------------------------------|---------------------------------------------------------------------------------|
48
- | `toastNotify.success()` | Displays a success toast. Optionally accepts actions. |
48
+ | **Values** | **Description** |
49
+ |----------------------------------|--------------------------------------------------------------------------------|
50
+ | `toastNotify.success()` | Displays a success toast. Optionally accepts actions and a title. |
49
51
  | `toastNotify.info()` | Displays an info toast. Optionally accepts a custom title. |
50
52
  | `toastNotify.failure()` | Displays a failure toast with an error and optional message or actions. |
53
+ | `toastNotify.caution()` | Displays a caution toast. Optionally accepts actions and a title. |
51
54
  | `toastNotify.clear()` | Clears specific toasts, or all toasts if none are specified. |
52
55
  | `toastNotify.toggleListView()` | Toggles the notification list view open or closed. |
53
56
  | `toastNotify.countBySeverity` | Returns the count of notifications grouped by severity (e.g., success, info). |
@@ -59,6 +62,7 @@ Some example usages:
59
62
  toastNotify.success("Your changes have been saved.");
60
63
  toastNotify.success("Your changes have been saved.", [{label: "Undo", onClick: () => console.log("Undo clicked")}]);
61
64
  ```
65
+
62
66
  2. **Show an info toast:**
63
67
  ```
64
68
  toastNotify.info("Your changes are syncing in the background.");
@@ -70,16 +74,25 @@ toastNotify.info("Your changes are syncing in the background.", "Syncing");
70
74
  toastNotify.failure("Save failed", new Error("500 Internal Server Error"), "Please try again.");
71
75
  toastNotify.failure("Save failed", new Error("500 Internal Server Error"), "Please try again.", [{label: "Retry", onClick: () => console.log("Retry clicked")}]);
72
76
  ```
73
- 4. **Clear notifications:**
77
+
78
+ 4. **Show a caution toast:**
79
+ ```
80
+ toastNotify.caution("Your changes have not been saved.");
81
+ toastNotify.caution("Your changes have not been saved.", [{label: "Undo", onClick: () => console.log("Undo clicked")}]);
82
+ ```
83
+
84
+ 5. **Clear notifications:**
74
85
  ```
75
86
  toastNotify.clear(); // clears all toast notifications
76
87
  toastNotify.clear([notificationId]); // clears specific toast notifications
77
88
  ```
78
- 5. **Toggle the notification list view:**
89
+
90
+ 6. **Toggle the notification list view:**
79
91
  ```
80
92
  toastNotify.toggleListView();
81
93
  ```
82
- 6. **Get the count of notifications by severity:**
94
+
95
+ 7. **Get the count of notifications by severity:**
83
96
  ```
84
97
  const count = toastNotify.countBySeverity;
85
98
  console.log(count.positive);
@@ -174,12 +187,24 @@ const ToastNotificationProvider = _ref => {
174
187
  const helper = {
175
188
  notifications,
176
189
  failure: (title, error, message, actions) => addNotification((0, _NotificationProvider.failure)(title, error, message, actions)),
177
- info: (message, title) => addNotification((0, _NotificationProvider.info)(message, title)),
178
- success: (message, actions) => addNotification({
190
+ info: (message, title, actions) => addNotification({
179
191
  message,
180
192
  actions,
193
+ title,
194
+ type: _.NotificationSeverity.INFORMATION
195
+ }),
196
+ success: (message, actions, title) => addNotification({
197
+ message,
198
+ actions,
199
+ title,
181
200
  type: _.NotificationSeverity.POSITIVE
182
201
  }),
202
+ caution: (message, actions, title) => addNotification({
203
+ message,
204
+ actions,
205
+ title,
206
+ type: _.NotificationSeverity.CAUTION
207
+ }),
183
208
  clear,
184
209
  toggleListView,
185
210
  isListView: showList,
@@ -27,8 +27,8 @@ export type Props = PropsWithSpread<{
27
27
  }, HTMLProps<HTMLDivElement>>;
28
28
  /**
29
29
  * This is a [React](https://reactjs.org/) component for the Vanilla [Label](https://vanillaframework.io/docs/patterns/labels).
30
- *
31
30
  * Labels are static elements which you can apply to signify status, tags or any other information you find useful.
31
+ * @deprecated StatusLabel is deprecated. Use Read-only Chip instead.
32
32
  */
33
33
  declare const StatusLabel: ({ appearance, children, className, ...labelProps }: Props) => React.JSX.Element;
34
34
  export default StatusLabel;
@@ -22,8 +22,8 @@ const StatusLabelAppearance = exports.StatusLabelAppearance = {
22
22
 
23
23
  /**
24
24
  * This is a [React](https://reactjs.org/) component for the Vanilla [Label](https://vanillaframework.io/docs/patterns/labels).
25
- *
26
25
  * Labels are static elements which you can apply to signify status, tags or any other information you find useful.
26
+ * @deprecated StatusLabel is deprecated. Use Read-only Chip instead.
27
27
  */
28
28
  const StatusLabel = _ref => {
29
29
  let {
@@ -1,6 +1,7 @@
1
- import React from "react";
1
+ import React, { type ReactNode } from "react";
2
2
  import type { MouseEvent, HTMLProps } from "react";
3
3
  import { ValueOf, PropsWithSpread } from "../../types";
4
+ import { ICONS } from "../Icon";
4
5
  export declare enum Label {
5
6
  Dismiss = "Dismiss"
6
7
  }
@@ -15,6 +16,29 @@ export type Props = PropsWithSpread<{
15
16
  * The appearance of the chip.
16
17
  */
17
18
  appearance?: ValueOf<typeof ChipType>;
19
+ /**
20
+ * Whether the chip is read-only.
21
+ * If true, the chip will not be interactive.
22
+ */
23
+ isReadOnly?: boolean;
24
+ /**
25
+ * A badge to display on the chip.
26
+ */
27
+ badge?: ReactNode;
28
+ /**
29
+ * The name of an icon to display on the chip.
30
+ */
31
+ iconName?: ValueOf<typeof ICONS> | string;
32
+ /**
33
+ * Whether the chip is dense.
34
+ * Reduces the height of the chip by removing padding.
35
+ */
36
+ isDense?: boolean;
37
+ /**
38
+ * Whether the chip is inline.
39
+ * If true, the chip will be displayed inline with other content (such as text).
40
+ */
41
+ isInline?: boolean;
18
42
  /**
19
43
  * The lead for the chip.
20
44
  */
@@ -53,5 +77,5 @@ export type Props = PropsWithSpread<{
53
77
  *
54
78
  * It can be used to display a small value attached to a component.
55
79
  */
56
- declare const Chip: ({ appearance, lead, onClick, onDismiss, quoteValue, selected, subString, value, ...props }: Props) => React.JSX.Element;
80
+ declare const Chip: ({ appearance, lead, onClick, onDismiss, quoteValue, selected, subString, isReadOnly, isDense, isInline, iconName, badge, value, ...props }: Props) => React.JSX.Element;
57
81
  export default Chip;
@@ -1,4 +1,4 @@
1
- var _excluded = ["appearance", "lead", "onClick", "onDismiss", "quoteValue", "selected", "subString", "value"];
1
+ var _excluded = ["appearance", "lead", "onClick", "onDismiss", "quoteValue", "selected", "subString", "isReadOnly", "isDense", "isInline", "iconName", "badge", "value"];
2
2
  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); }
3
3
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
4
4
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
@@ -29,6 +29,11 @@ var Chip = _ref => {
29
29
  quoteValue,
30
30
  selected,
31
31
  subString = "",
32
+ isReadOnly = false,
33
+ isDense = false,
34
+ isInline = false,
35
+ iconName,
36
+ badge,
32
37
  value
33
38
  } = _ref,
34
39
  props = _objectWithoutProperties(_ref, _excluded);
@@ -46,19 +51,28 @@ var Chip = _ref => {
46
51
  }
47
52
  };
48
53
  var chipValue = highlightSubString(value, subString).text;
49
- var chipContent = /*#__PURE__*/React.createElement(React.Fragment, null, lead && /*#__PURE__*/React.createElement("span", {
54
+ var chipContent = /*#__PURE__*/React.createElement(React.Fragment, null, iconName && /*#__PURE__*/React.createElement("i", {
55
+ className: "p-icon--".concat(iconName)
56
+ }), lead && /*#__PURE__*/React.createElement("span", {
50
57
  className: "p-chip__lead"
51
58
  }, lead.toUpperCase()), /*#__PURE__*/React.createElement("span", {
52
59
  className: "p-chip__value",
53
60
  dangerouslySetInnerHTML: {
54
61
  __html: quoteValue ? "'".concat(chipValue, "'") : chipValue
55
62
  }
56
- }));
63
+ }), badge && badge);
57
64
  var chipClassName = classNames({
58
65
  ["p-chip--".concat(appearance)]: !!appearance,
59
- "p-chip": !appearance
66
+ "p-chip": !appearance,
67
+ "is-dense": isDense,
68
+ "is-readonly": isReadOnly,
69
+ "is-inline": isInline
60
70
  }, props.className);
61
- if (onDismiss) {
71
+ if (isReadOnly) {
72
+ return /*#__PURE__*/React.createElement("span", _extends({}, props, {
73
+ className: chipClassName
74
+ }), chipContent);
75
+ } else if (onDismiss) {
62
76
  return /*#__PURE__*/React.createElement("span", _extends({}, props, {
63
77
  className: chipClassName
64
78
  }), chipContent, /*#__PURE__*/React.createElement("button", {
@@ -7,3 +7,8 @@ export declare const Default: Story;
7
7
  export declare const LeadValue: Story;
8
8
  export declare const Appearance: Story;
9
9
  export declare const Dismissible: Story;
10
+ export declare const Dense: Story;
11
+ export declare const Inline: Story;
12
+ export declare const ReadOnly: Story;
13
+ export declare const WithIcon: Story;
14
+ export declare const WithBadge: Story;
@@ -35,4 +35,46 @@ export var Dismissible = {
35
35
  }
36
36
  }),
37
37
  name: "Dismissible"
38
+ };
39
+ export var Dense = {
40
+ render: () => /*#__PURE__*/React.createElement(Chip, {
41
+ lead: "Owner",
42
+ value: "Bob",
43
+ isDense: true
44
+ }),
45
+ name: "Dense"
46
+ };
47
+ export var Inline = {
48
+ render: () => /*#__PURE__*/React.createElement("p", null, "This is text with an inline", " ", /*#__PURE__*/React.createElement(Chip, {
49
+ value: "chip",
50
+ isDense: true,
51
+ isInline: true
52
+ })),
53
+ name: "Inline"
54
+ };
55
+ export var ReadOnly = {
56
+ render: () => /*#__PURE__*/React.createElement(Chip, {
57
+ lead: "Owner",
58
+ value: "Bob",
59
+ isReadOnly: true
60
+ }),
61
+ name: "Read-only"
62
+ };
63
+ export var WithIcon = {
64
+ render: () => /*#__PURE__*/React.createElement(Chip, {
65
+ value: "Users",
66
+ iconName: "user"
67
+ }),
68
+ name: "With Icon"
69
+ };
70
+ export var WithBadge = {
71
+ render: () => /*#__PURE__*/React.createElement(Chip, {
72
+ lead: "Owner",
73
+ value: "Bob",
74
+ badge: /*#__PURE__*/React.createElement("span", {
75
+ className: "p-badge",
76
+ "aria-label": "More than 2.5 billion items"
77
+ }, "2.5B")
78
+ }),
79
+ name: "With Badge"
38
80
  };
@@ -25,6 +25,7 @@ var PreloadedList = () => {
25
25
  toastNotify.success("Settings saved successfully");
26
26
  toastNotify.info("Your changes are syncing in the background");
27
27
  toastNotify.failure("Save failed", new Error("500 Internal Server Error"), "Please try again.");
28
+ toastNotify.caution("You have unsaved changes.");
28
29
  toastNotify.toggleListView();
29
30
  // eslint-disable-next-line react-hooks/exhaustive-deps
30
31
  }, []);
@@ -8,9 +8,10 @@ export type ToastNotificationType = NotificationType & {
8
8
  };
9
9
  interface ToastNotificationHelper {
10
10
  notifications: ToastNotificationType[];
11
- success: (message: ReactNode, actions?: NotificationAction[]) => ToastNotificationType;
12
- info: (message: ReactNode, title?: string) => ToastNotificationType;
11
+ success: (message: ReactNode, actions?: NotificationAction[], title?: string) => ToastNotificationType;
12
+ info: (message: ReactNode, title?: string, actions?: NotificationAction[]) => ToastNotificationType;
13
13
  failure: (title: string, error: unknown, message?: ReactNode, actions?: NotificationAction[]) => ToastNotificationType;
14
+ caution: (message: ReactNode, actions?: NotificationAction[], title?: string) => ToastNotificationType;
14
15
  clear: (notification?: ToastNotificationType[]) => void;
15
16
  toggleListView: () => void;
16
17
  isListView: boolean;
@@ -25,11 +26,12 @@ export type GroupedNotificationCount = {
25
26
  Wrap your application with this provider, and in any child component you can get the helper with `const toastNotify = useToastNotification()` to trigger notifications.
26
27
  Notifications automatically dismiss after a delay unless manually dismissed or expanded.
27
28
 
28
- | **Values** | **Description** |
29
- |----------------------------------|---------------------------------------------------------------------------------|
30
- | `toastNotify.success()` | Displays a success toast. Optionally accepts actions. |
29
+ | **Values** | **Description** |
30
+ |----------------------------------|--------------------------------------------------------------------------------|
31
+ | `toastNotify.success()` | Displays a success toast. Optionally accepts actions and a title. |
31
32
  | `toastNotify.info()` | Displays an info toast. Optionally accepts a custom title. |
32
33
  | `toastNotify.failure()` | Displays a failure toast with an error and optional message or actions. |
34
+ | `toastNotify.caution()` | Displays a caution toast. Optionally accepts actions and a title. |
33
35
  | `toastNotify.clear()` | Clears specific toasts, or all toasts if none are specified. |
34
36
  | `toastNotify.toggleListView()` | Toggles the notification list view open or closed. |
35
37
  | `toastNotify.countBySeverity` | Returns the count of notifications grouped by severity (e.g., success, info). |
@@ -41,6 +43,7 @@ Some example usages:
41
43
  toastNotify.success("Your changes have been saved.");
42
44
  toastNotify.success("Your changes have been saved.", [{label: "Undo", onClick: () => console.log("Undo clicked")}]);
43
45
  ```
46
+
44
47
  2. **Show an info toast:**
45
48
  ```
46
49
  toastNotify.info("Your changes are syncing in the background.");
@@ -52,16 +55,25 @@ toastNotify.info("Your changes are syncing in the background.", "Syncing");
52
55
  toastNotify.failure("Save failed", new Error("500 Internal Server Error"), "Please try again.");
53
56
  toastNotify.failure("Save failed", new Error("500 Internal Server Error"), "Please try again.", [{label: "Retry", onClick: () => console.log("Retry clicked")}]);
54
57
  ```
55
- 4. **Clear notifications:**
58
+
59
+ 4. **Show a caution toast:**
60
+ ```
61
+ toastNotify.caution("Your changes have not been saved.");
62
+ toastNotify.caution("Your changes have not been saved.", [{label: "Undo", onClick: () => console.log("Undo clicked")}]);
63
+ ```
64
+
65
+ 5. **Clear notifications:**
56
66
  ```
57
67
  toastNotify.clear(); // clears all toast notifications
58
68
  toastNotify.clear([notificationId]); // clears specific toast notifications
59
69
  ```
60
- 5. **Toggle the notification list view:**
70
+
71
+ 6. **Toggle the notification list view:**
61
72
  ```
62
73
  toastNotify.toggleListView();
63
74
  ```
64
- 6. **Get the count of notifications by severity:**
75
+
76
+ 7. **Get the count of notifications by severity:**
65
77
  ```
66
78
  const count = toastNotify.countBySeverity;
67
79
  console.log(count.positive);
@@ -3,7 +3,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
3
3
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
4
4
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : String(i); }
5
5
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
6
- import { failure as _failure, info as _info } from "../../NotificationProvider";
6
+ import { failure as _failure } from "../../NotificationProvider";
7
7
  import { NotificationSeverity } from "./..";
8
8
  import ToastNotification from "./ToastNotification";
9
9
  import ToastNotificationList from "./ToastNotificationList";
@@ -18,12 +18,14 @@ var initialNotification = {
18
18
  var ToastNotificationContext = /*#__PURE__*/createContext({
19
19
  /** List of all active toast notifications */
20
20
  notifications: [],
21
- /** Show a success toast. Optionally pass actions. */
21
+ /** Show a success toast. Optionally pass actions and a title. */
22
22
  success: () => initialNotification,
23
- /** Show an info toast. Optionally pass a custom title. */
23
+ /** Show an info toast. Optionally pass a custom title and actions. */
24
24
  info: () => initialNotification,
25
25
  /** Show a failure toast with an error and optional message/actions. */
26
26
  failure: () => initialNotification,
27
+ /** Show a caution toast. Optionally pass actions and a title. */
28
+ caution: () => initialNotification,
27
29
  /** Clear one or more specific toasts, or all if none provided. */
28
30
  clear: () => null,
29
31
  /** Toggle between single toast view and list view. */
@@ -40,11 +42,12 @@ var ToastNotificationContext = /*#__PURE__*/createContext({
40
42
  Wrap your application with this provider, and in any child component you can get the helper with `const toastNotify = useToastNotification()` to trigger notifications.
41
43
  Notifications automatically dismiss after a delay unless manually dismissed or expanded.
42
44
 
43
- | **Values** | **Description** |
44
- |----------------------------------|---------------------------------------------------------------------------------|
45
- | `toastNotify.success()` | Displays a success toast. Optionally accepts actions. |
45
+ | **Values** | **Description** |
46
+ |----------------------------------|--------------------------------------------------------------------------------|
47
+ | `toastNotify.success()` | Displays a success toast. Optionally accepts actions and a title. |
46
48
  | `toastNotify.info()` | Displays an info toast. Optionally accepts a custom title. |
47
49
  | `toastNotify.failure()` | Displays a failure toast with an error and optional message or actions. |
50
+ | `toastNotify.caution()` | Displays a caution toast. Optionally accepts actions and a title. |
48
51
  | `toastNotify.clear()` | Clears specific toasts, or all toasts if none are specified. |
49
52
  | `toastNotify.toggleListView()` | Toggles the notification list view open or closed. |
50
53
  | `toastNotify.countBySeverity` | Returns the count of notifications grouped by severity (e.g., success, info). |
@@ -56,6 +59,7 @@ Some example usages:
56
59
  toastNotify.success("Your changes have been saved.");
57
60
  toastNotify.success("Your changes have been saved.", [{label: "Undo", onClick: () => console.log("Undo clicked")}]);
58
61
  ```
62
+
59
63
  2. **Show an info toast:**
60
64
  ```
61
65
  toastNotify.info("Your changes are syncing in the background.");
@@ -67,16 +71,25 @@ toastNotify.info("Your changes are syncing in the background.", "Syncing");
67
71
  toastNotify.failure("Save failed", new Error("500 Internal Server Error"), "Please try again.");
68
72
  toastNotify.failure("Save failed", new Error("500 Internal Server Error"), "Please try again.", [{label: "Retry", onClick: () => console.log("Retry clicked")}]);
69
73
  ```
70
- 4. **Clear notifications:**
74
+
75
+ 4. **Show a caution toast:**
76
+ ```
77
+ toastNotify.caution("Your changes have not been saved.");
78
+ toastNotify.caution("Your changes have not been saved.", [{label: "Undo", onClick: () => console.log("Undo clicked")}]);
79
+ ```
80
+
81
+ 5. **Clear notifications:**
71
82
  ```
72
83
  toastNotify.clear(); // clears all toast notifications
73
84
  toastNotify.clear([notificationId]); // clears specific toast notifications
74
85
  ```
75
- 5. **Toggle the notification list view:**
86
+
87
+ 6. **Toggle the notification list view:**
76
88
  ```
77
89
  toastNotify.toggleListView();
78
90
  ```
79
- 6. **Get the count of notifications by severity:**
91
+
92
+ 7. **Get the count of notifications by severity:**
80
93
  ```
81
94
  const count = toastNotify.countBySeverity;
82
95
  console.log(count.positive);
@@ -170,12 +183,24 @@ var ToastNotificationProvider = _ref => {
170
183
  var helper = {
171
184
  notifications,
172
185
  failure: (title, error, message, actions) => addNotification(_failure(title, error, message, actions)),
173
- info: (message, title) => addNotification(_info(message, title)),
174
- success: (message, actions) => addNotification({
186
+ info: (message, title, actions) => addNotification({
175
187
  message,
176
188
  actions,
189
+ title,
190
+ type: NotificationSeverity.INFORMATION
191
+ }),
192
+ success: (message, actions, title) => addNotification({
193
+ message,
194
+ actions,
195
+ title,
177
196
  type: NotificationSeverity.POSITIVE
178
197
  }),
198
+ caution: (message, actions, title) => addNotification({
199
+ message,
200
+ actions,
201
+ title,
202
+ type: NotificationSeverity.CAUTION
203
+ }),
179
204
  clear,
180
205
  toggleListView,
181
206
  isListView: showList,
@@ -27,8 +27,8 @@ export type Props = PropsWithSpread<{
27
27
  }, HTMLProps<HTMLDivElement>>;
28
28
  /**
29
29
  * This is a [React](https://reactjs.org/) component for the Vanilla [Label](https://vanillaframework.io/docs/patterns/labels).
30
- *
31
30
  * Labels are static elements which you can apply to signify status, tags or any other information you find useful.
31
+ * @deprecated StatusLabel is deprecated. Use Read-only Chip instead.
32
32
  */
33
33
  declare const StatusLabel: ({ appearance, children, className, ...labelProps }: Props) => React.JSX.Element;
34
34
  export default StatusLabel;
@@ -18,8 +18,8 @@ export var StatusLabelAppearance = {
18
18
 
19
19
  /**
20
20
  * This is a [React](https://reactjs.org/) component for the Vanilla [Label](https://vanillaframework.io/docs/patterns/labels).
21
- *
22
21
  * Labels are static elements which you can apply to signify status, tags or any other information you find useful.
22
+ * @deprecated StatusLabel is deprecated. Use Read-only Chip instead.
23
23
  */
24
24
  var StatusLabel = _ref => {
25
25
  var {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonical/react-components",
3
- "version": "2.10.0",
3
+ "version": "2.12.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": {