@canonical/react-components 4.5.3 → 4.6.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,7 +1,6 @@
1
- import React, { MouseEventHandler } from "react";
2
- import type { ButtonHTMLAttributes, ReactNode } from "react";
1
+ import React from "react";
3
2
  import type { ButtonProps } from "../Button";
4
- import type { ClassName, PropsWithSpread } from "../../types";
3
+ import type { PropsWithSpread } from "../../types";
5
4
  export declare const LOADER_MIN_DURATION = 400;
6
5
  export declare const SUCCESS_DURATION = 2000;
7
6
  export declare enum Label {
@@ -9,39 +8,15 @@ export declare enum Label {
9
8
  SUCCESS = "Action completed"
10
9
  }
11
10
  export type Props = PropsWithSpread<{
12
- /**
13
- * The appearance of the button.
14
- */
15
- appearance?: ButtonProps["appearance"];
16
- /**
17
- * The content of the button.
18
- */
19
- children?: ReactNode;
20
- /**
21
- * Optional class(es) to pass to the button element.
22
- */
23
- className?: ClassName;
24
- /**
25
- * Whether the button should be disabled.
26
- */
27
- disabled?: boolean;
28
- /**
29
- * Whether the button should display inline.
30
- */
31
- inline?: boolean;
32
11
  /**
33
12
  * Whether the button should be in the loading state.
34
13
  */
35
14
  loading?: boolean;
36
- /**
37
- * Function for handling button click event.
38
- */
39
- onClick?: MouseEventHandler<HTMLButtonElement>;
40
15
  /**
41
16
  * Whether the button should be in the success state.
42
17
  */
43
18
  success?: boolean;
44
- }, ButtonHTMLAttributes<HTMLButtonElement>>;
19
+ }, ButtonProps>;
45
20
  /**
46
21
  * This is a not an existing Vanilla component. It can be used to display submitting states for forms or other actions.
47
22
  *
@@ -49,5 +24,5 @@ export type Props = PropsWithSpread<{
49
24
  * [Button](?path=/docs/components-button--docs) in addition to those in the
50
25
  * props table:
51
26
  */
52
- declare const ActionButton: ({ appearance, children, className, onClick, disabled, inline, loading, success, ...buttonProps }: Props) => React.JSX.Element;
27
+ declare const ActionButton: ({ children, className, disabled, loading, success, ...buttonProps }: Props) => React.JSX.Element;
53
28
  export default ActionButton;
@@ -7,7 +7,8 @@ exports.default = exports.SUCCESS_DURATION = exports.Label = exports.LOADER_MIN_
7
7
  var _classnames = _interopRequireDefault(require("classnames"));
8
8
  var _react = _interopRequireWildcard(require("react"));
9
9
  var _Icon = _interopRequireDefault(require("../Icon"));
10
- const _excluded = ["appearance", "children", "className", "onClick", "disabled", "inline", "loading", "success"];
10
+ var _Button = _interopRequireDefault(require("../Button"));
11
+ const _excluded = ["children", "className", "disabled", "loading", "success"];
11
12
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
12
13
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
13
14
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
@@ -29,12 +30,9 @@ let Label = exports.Label = /*#__PURE__*/function (Label) {
29
30
  */
30
31
  const ActionButton = _ref => {
31
32
  let {
32
- appearance,
33
33
  children,
34
34
  className,
35
- onClick,
36
35
  disabled = null,
37
- inline = false,
38
36
  loading = false,
39
37
  success = false
40
38
  } = _ref,
@@ -105,26 +103,16 @@ const ActionButton = _ref => {
105
103
  }
106
104
  return () => window.clearTimeout(successTimeout);
107
105
  }, [showSuccess]);
108
- const buttonClasses = (0, _classnames.default)(className, "p-action-button", appearance ? "p-button--".concat(appearance) : "p-button", {
109
- "is-processing": showLoader || showSuccess,
110
- "is-disabled": disabled === null ? showLoader : disabled,
111
- "is-inline": inline
106
+ const buttonClasses = (0, _classnames.default)(className, "p-action-button", {
107
+ "is-processing": showLoader || showSuccess
112
108
  });
113
109
  const showIcon = showLoader || showSuccess;
114
- const isDisabled = disabled === null ? showLoader : disabled;
115
110
  const icon = showLoader && "spinner" || showSuccess && "success" || null;
116
- const iconLight = appearance === "positive" || appearance === "negative";
117
- const onClickDisabled = e => e.preventDefault();
118
-
119
- // This component uses the base button element instead of the Button component
120
- // as the button requires a ref and Button would have to be updated to use
121
- // forwardRef which is not currently supported by components that use
122
- // typescript generics.
123
- return /*#__PURE__*/_react.default.createElement("button", _extends({
111
+ const iconLight = buttonProps.appearance === "positive" || buttonProps.appearance === "negative";
112
+ return /*#__PURE__*/_react.default.createElement(_Button.default, _extends({
124
113
  className: buttonClasses,
125
114
  ref: ref,
126
- onClick: isDisabled ? onClickDisabled : onClick,
127
- "aria-disabled": isDisabled || undefined,
115
+ disabled: disabled === null ? showLoader : disabled,
128
116
  style: height && width ? {
129
117
  height: "".concat(height, "px"),
130
118
  width: "".concat(width, "px")
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import type { ButtonHTMLAttributes, ComponentType, ElementType, MouseEventHandler, ReactNode } from "react";
2
+ import type { ButtonHTMLAttributes, ComponentType, ElementType, MouseEventHandler, ReactNode, Ref } from "react";
3
3
  import type { ClassName, ValueOf } from "../../types";
4
4
  export declare const ButtonAppearance: {
5
5
  readonly BASE: "base";
@@ -54,6 +54,10 @@ export type Props<P = null> = {
54
54
  * Whether the button should be small.
55
55
  */
56
56
  small?: boolean;
57
+ /**
58
+ * A ref to the button.
59
+ */
60
+ ref?: Ref<HTMLButtonElement>;
57
61
  } & (Omit<ButtonHTMLAttributes<HTMLButtonElement>, "onClick"> | P);
58
62
  /**
59
63
  * This is a [React](https://reactjs.org/) component for the Vanilla [Button](https://docs.vanillaframework.io/patterns/buttons/).
@@ -7,6 +7,7 @@ exports.default = exports.Positive = exports.NoTitle = exports.Extra = exports.D
7
7
  var _react = _interopRequireWildcard(require("react"));
8
8
  var _ConfirmationModal = _interopRequireDefault(require("./ConfirmationModal"));
9
9
  var _Input = _interopRequireDefault(require("../Input"));
10
+ var _Icon = _interopRequireDefault(require("../Icon"));
10
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
11
12
  function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
12
13
  const doNothing = () => {};
@@ -24,9 +25,15 @@ const Default = exports.Default = {
24
25
  onClick: () => setModalOpen(true)
25
26
  }, "Open confirmation modal"), modalOpen ? /*#__PURE__*/_react.default.createElement(_ConfirmationModal.default, {
26
27
  title: "Confirm delete",
27
- confirmButtonLabel: "Delete",
28
+ confirmButtonLabel: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(_Icon.default, {
29
+ name: "delete",
30
+ light: true
31
+ }), /*#__PURE__*/_react.default.createElement("span", null, "Delete")),
28
32
  onConfirm: doNothing,
29
- close: closeHandler
33
+ close: closeHandler,
34
+ confirmButtonProps: {
35
+ hasIcon: true
36
+ }
30
37
  }, /*#__PURE__*/_react.default.createElement("p", null, "This will permanently delete the user \"Simon\".", /*#__PURE__*/_react.default.createElement("br", null), "You cannot undo this action.")) : null);
31
38
  },
32
39
  name: "Default"
@@ -8,10 +8,6 @@
8
8
  .page-card {
9
9
  border: 0;
10
10
  }
11
-
12
- .is-paper {
13
- background-color: #fff;
14
- }
15
11
  }
16
12
 
17
13
  .page-inner {
@@ -1,7 +1,6 @@
1
- import React, { MouseEventHandler } from "react";
2
- import type { ButtonHTMLAttributes, ReactNode } from "react";
1
+ import React from "react";
3
2
  import type { ButtonProps } from "../Button";
4
- import type { ClassName, PropsWithSpread } from "../../types";
3
+ import type { PropsWithSpread } from "../../types";
5
4
  export declare const LOADER_MIN_DURATION = 400;
6
5
  export declare const SUCCESS_DURATION = 2000;
7
6
  export declare enum Label {
@@ -9,39 +8,15 @@ export declare enum Label {
9
8
  SUCCESS = "Action completed"
10
9
  }
11
10
  export type Props = PropsWithSpread<{
12
- /**
13
- * The appearance of the button.
14
- */
15
- appearance?: ButtonProps["appearance"];
16
- /**
17
- * The content of the button.
18
- */
19
- children?: ReactNode;
20
- /**
21
- * Optional class(es) to pass to the button element.
22
- */
23
- className?: ClassName;
24
- /**
25
- * Whether the button should be disabled.
26
- */
27
- disabled?: boolean;
28
- /**
29
- * Whether the button should display inline.
30
- */
31
- inline?: boolean;
32
11
  /**
33
12
  * Whether the button should be in the loading state.
34
13
  */
35
14
  loading?: boolean;
36
- /**
37
- * Function for handling button click event.
38
- */
39
- onClick?: MouseEventHandler<HTMLButtonElement>;
40
15
  /**
41
16
  * Whether the button should be in the success state.
42
17
  */
43
18
  success?: boolean;
44
- }, ButtonHTMLAttributes<HTMLButtonElement>>;
19
+ }, ButtonProps>;
45
20
  /**
46
21
  * This is a not an existing Vanilla component. It can be used to display submitting states for forms or other actions.
47
22
  *
@@ -49,5 +24,5 @@ export type Props = PropsWithSpread<{
49
24
  * [Button](?path=/docs/components-button--docs) in addition to those in the
50
25
  * props table:
51
26
  */
52
- declare const ActionButton: ({ appearance, children, className, onClick, disabled, inline, loading, success, ...buttonProps }: Props) => React.JSX.Element;
27
+ declare const ActionButton: ({ children, className, disabled, loading, success, ...buttonProps }: Props) => React.JSX.Element;
53
28
  export default ActionButton;
@@ -1,10 +1,11 @@
1
- var _excluded = ["appearance", "children", "className", "onClick", "disabled", "inline", "loading", "success"];
1
+ var _excluded = ["children", "className", "disabled", "loading", "success"];
2
2
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
3
  function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
4
4
  function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
5
5
  import classNames from "classnames";
6
6
  import React, { useEffect, useRef, useState } from "react";
7
7
  import Icon from "../Icon";
8
+ import Button from "../Button";
8
9
  export var LOADER_MIN_DURATION = 400; // minimium duration (ms) loader displays
9
10
  export var SUCCESS_DURATION = 2000; // duration (ms) success tick is displayed
10
11
 
@@ -22,12 +23,9 @@ export var Label = /*#__PURE__*/function (Label) {
22
23
  */
23
24
  var ActionButton = _ref => {
24
25
  var {
25
- appearance,
26
26
  children,
27
27
  className,
28
- onClick,
29
28
  disabled = null,
30
- inline = false,
31
29
  loading = false,
32
30
  success = false
33
31
  } = _ref,
@@ -98,26 +96,16 @@ var ActionButton = _ref => {
98
96
  }
99
97
  return () => window.clearTimeout(successTimeout);
100
98
  }, [showSuccess]);
101
- var buttonClasses = classNames(className, "p-action-button", appearance ? "p-button--".concat(appearance) : "p-button", {
102
- "is-processing": showLoader || showSuccess,
103
- "is-disabled": disabled === null ? showLoader : disabled,
104
- "is-inline": inline
99
+ var buttonClasses = classNames(className, "p-action-button", {
100
+ "is-processing": showLoader || showSuccess
105
101
  });
106
102
  var showIcon = showLoader || showSuccess;
107
- var isDisabled = disabled === null ? showLoader : disabled;
108
103
  var icon = showLoader && "spinner" || showSuccess && "success" || null;
109
- var iconLight = appearance === "positive" || appearance === "negative";
110
- var onClickDisabled = e => e.preventDefault();
111
-
112
- // This component uses the base button element instead of the Button component
113
- // as the button requires a ref and Button would have to be updated to use
114
- // forwardRef which is not currently supported by components that use
115
- // typescript generics.
116
- return /*#__PURE__*/React.createElement("button", _extends({
104
+ var iconLight = buttonProps.appearance === "positive" || buttonProps.appearance === "negative";
105
+ return /*#__PURE__*/React.createElement(Button, _extends({
117
106
  className: buttonClasses,
118
107
  ref: ref,
119
- onClick: isDisabled ? onClickDisabled : onClick,
120
- "aria-disabled": isDisabled || undefined,
108
+ disabled: disabled === null ? showLoader : disabled,
121
109
  style: height && width ? {
122
110
  height: "".concat(height, "px"),
123
111
  width: "".concat(width, "px")
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import type { ButtonHTMLAttributes, ComponentType, ElementType, MouseEventHandler, ReactNode } from "react";
2
+ import type { ButtonHTMLAttributes, ComponentType, ElementType, MouseEventHandler, ReactNode, Ref } from "react";
3
3
  import type { ClassName, ValueOf } from "../../types";
4
4
  export declare const ButtonAppearance: {
5
5
  readonly BASE: "base";
@@ -54,6 +54,10 @@ export type Props<P = null> = {
54
54
  * Whether the button should be small.
55
55
  */
56
56
  small?: boolean;
57
+ /**
58
+ * A ref to the button.
59
+ */
60
+ ref?: Ref<HTMLButtonElement>;
57
61
  } & (Omit<ButtonHTMLAttributes<HTMLButtonElement>, "onClick"> | P);
58
62
  /**
59
63
  * This is a [React](https://reactjs.org/) component for the Vanilla [Button](https://docs.vanillaframework.io/patterns/buttons/).
@@ -2,6 +2,7 @@ import { useState } from "react";
2
2
  import React from "react";
3
3
  import ConfirmationModal from "./ConfirmationModal";
4
4
  import Input from "../Input";
5
+ import Icon from "../Icon";
5
6
  var doNothing = () => {};
6
7
  var meta = {
7
8
  component: ConfirmationModal,
@@ -17,9 +18,15 @@ export var Default = {
17
18
  onClick: () => setModalOpen(true)
18
19
  }, "Open confirmation modal"), modalOpen ? /*#__PURE__*/React.createElement(ConfirmationModal, {
19
20
  title: "Confirm delete",
20
- confirmButtonLabel: "Delete",
21
+ confirmButtonLabel: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Icon, {
22
+ name: "delete",
23
+ light: true
24
+ }), /*#__PURE__*/React.createElement("span", null, "Delete")),
21
25
  onConfirm: doNothing,
22
- close: closeHandler
26
+ close: closeHandler,
27
+ confirmButtonProps: {
28
+ hasIcon: true
29
+ }
23
30
  }, /*#__PURE__*/React.createElement("p", null, "This will permanently delete the user \"Simon\".", /*#__PURE__*/React.createElement("br", null), "You cannot undo this action.")) : null);
24
31
  },
25
32
  name: "Default"
@@ -8,10 +8,6 @@
8
8
  .page-card {
9
9
  border: 0;
10
10
  }
11
-
12
- .is-paper {
13
- background-color: #fff;
14
- }
15
11
  }
16
12
 
17
13
  .page-inner {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonical/react-components",
3
- "version": "4.5.3",
3
+ "version": "4.6.0",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": {
@@ -37,7 +37,7 @@
37
37
  "@eslint/compat": "2.0.1",
38
38
  "@eslint/eslintrc": "3.3.3",
39
39
  "@eslint/js": "9.39.2",
40
- "@percy/cli": "1.31.8",
40
+ "@percy/cli": "1.31.14",
41
41
  "@percy/storybook": "9.1.0",
42
42
  "@semantic-release/changelog": "6.0.3",
43
43
  "@semantic-release/git": "10.0.1",