@canonical/react-components 2.4.0 → 2.5.1

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.
@@ -35,7 +35,7 @@
35
35
  .toast-notification-list {
36
36
  background-color: white;
37
37
  box-shadow: 0 0 2rem 0.5rem rgb(0 0 0 / 22%);
38
- max-height: calc(100vh - 4.5rem);
38
+ max-height: calc(100dvh - 4.5rem);
39
39
  overflow: auto;
40
40
  padding: 0 0.5rem;
41
41
  z-index: 102;
@@ -85,7 +85,7 @@
85
85
  }
86
86
  }
87
87
 
88
- .stepper-vertical {
88
+ .stepper-vertical:not(.stepper-horizontal) {
89
89
  .p-list__item {
90
90
  padding-bottom: 0;
91
91
  padding-top: 0;
@@ -1,6 +1,7 @@
1
1
  import React from "react";
2
2
  import type { HTMLProps, ReactNode } from "react";
3
3
  import type { PropsWithSpread } from "../../types";
4
+ import "./Switch.scss";
4
5
  export type Props = PropsWithSpread<{
5
6
  /**
6
7
  * The label name for the switch
@@ -10,9 +11,17 @@ export type Props = PropsWithSpread<{
10
11
  * Whether the switch is disabled or not
11
12
  */
12
13
  disabled?: boolean;
14
+ /**
15
+ * Help text to show below the field.
16
+ */
17
+ help?: ReactNode;
18
+ /**
19
+ * Optional class(es) to pass to the help text element.
20
+ */
21
+ helpClassName?: string;
13
22
  }, HTMLProps<HTMLInputElement>>;
14
23
  /**
15
24
  * This is a [React](https://reactjs.org/) component for the Vanilla [Switch](https://vanillaframework.io/docs/patterns/switch) component.
16
25
  */
17
- export declare const Switch: ({ label, disabled, ...inputProps }: Props) => React.JSX.Element;
26
+ export declare const Switch: ({ label, disabled, help, helpClassName, ...inputProps }: Props) => React.JSX.Element;
18
27
  export default Switch;
@@ -4,8 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = exports.Switch = void 0;
7
- var _react = _interopRequireDefault(require("react"));
7
+ var _react = _interopRequireWildcard(require("react"));
8
+ var _classnames = _interopRequireDefault(require("classnames"));
9
+ require("./Switch.scss");
8
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
12
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
9
13
  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); }
10
14
  /**
11
15
  * This is a [React](https://reactjs.org/) component for the Vanilla [Switch](https://vanillaframework.io/docs/patterns/switch) component.
@@ -14,9 +18,12 @@ const Switch = _ref => {
14
18
  let {
15
19
  label,
16
20
  disabled = false,
21
+ help,
22
+ helpClassName,
17
23
  ...inputProps
18
24
  } = _ref;
19
- return /*#__PURE__*/_react.default.createElement("label", {
25
+ const helpId = (0, _react.useId)();
26
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement("label", {
20
27
  className: "p-switch"
21
28
  }, /*#__PURE__*/_react.default.createElement("input", _extends({
22
29
  type: "checkbox",
@@ -27,7 +34,10 @@ const Switch = _ref => {
27
34
  className: "p-switch__slider"
28
35
  }), /*#__PURE__*/_react.default.createElement("span", {
29
36
  className: "p-switch__label"
30
- }, label));
37
+ }, label)), help && /*#__PURE__*/_react.default.createElement("p", {
38
+ className: (0, _classnames.default)("p-form-help-text", "switch-help-text", helpClassName),
39
+ id: helpId
40
+ }, help));
31
41
  };
32
42
  exports.Switch = Switch;
33
43
  var _default = exports.default = Switch;
@@ -0,0 +1,3 @@
1
+ .switch-help-text {
2
+ margin-left: 2.5rem;
3
+ }
@@ -5,3 +5,4 @@ export default meta;
5
5
  type Story = StoryObj<typeof Switch>;
6
6
  export declare const Default: Story;
7
7
  export declare const Disabled: Story;
8
+ export declare const HelpText: Story;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = exports.Disabled = exports.Default = void 0;
6
+ exports.default = exports.HelpText = exports.Disabled = exports.Default = void 0;
7
7
  var _Switch = _interopRequireDefault(require("./Switch"));
8
8
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
9
  const meta = {
@@ -23,4 +23,11 @@ const Disabled = exports.Disabled = {
23
23
  disabled: true,
24
24
  label: "Disabled switch"
25
25
  }
26
+ };
27
+ const HelpText = exports.HelpText = {
28
+ name: "Help Text",
29
+ args: {
30
+ label: "Switch with help text",
31
+ help: "This is some help text"
32
+ }
26
33
  };
@@ -35,7 +35,7 @@
35
35
  .toast-notification-list {
36
36
  background-color: white;
37
37
  box-shadow: 0 0 2rem 0.5rem rgb(0 0 0 / 22%);
38
- max-height: calc(100vh - 4.5rem);
38
+ max-height: calc(100dvh - 4.5rem);
39
39
  overflow: auto;
40
40
  padding: 0 0.5rem;
41
41
  z-index: 102;
@@ -85,7 +85,7 @@
85
85
  }
86
86
  }
87
87
 
88
- .stepper-vertical {
88
+ .stepper-vertical:not(.stepper-horizontal) {
89
89
  .p-list__item {
90
90
  padding-bottom: 0;
91
91
  padding-top: 0;
@@ -1,6 +1,7 @@
1
1
  import React from "react";
2
2
  import type { HTMLProps, ReactNode } from "react";
3
3
  import type { PropsWithSpread } from "../../types";
4
+ import "./Switch.scss";
4
5
  export type Props = PropsWithSpread<{
5
6
  /**
6
7
  * The label name for the switch
@@ -10,9 +11,17 @@ export type Props = PropsWithSpread<{
10
11
  * Whether the switch is disabled or not
11
12
  */
12
13
  disabled?: boolean;
14
+ /**
15
+ * Help text to show below the field.
16
+ */
17
+ help?: ReactNode;
18
+ /**
19
+ * Optional class(es) to pass to the help text element.
20
+ */
21
+ helpClassName?: string;
13
22
  }, HTMLProps<HTMLInputElement>>;
14
23
  /**
15
24
  * This is a [React](https://reactjs.org/) component for the Vanilla [Switch](https://vanillaframework.io/docs/patterns/switch) component.
16
25
  */
17
- export declare const Switch: ({ label, disabled, ...inputProps }: Props) => React.JSX.Element;
26
+ export declare const Switch: ({ label, disabled, help, helpClassName, ...inputProps }: Props) => React.JSX.Element;
18
27
  export default Switch;
@@ -1,18 +1,24 @@
1
- var _excluded = ["label", "disabled"];
1
+ var _excluded = ["label", "disabled", "help", "helpClassName"];
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; }
5
5
  import React from "react";
6
+ import classNames from "classnames";
7
+ import { useId } from "react";
8
+ import "./Switch.scss";
6
9
  /**
7
10
  * This is a [React](https://reactjs.org/) component for the Vanilla [Switch](https://vanillaframework.io/docs/patterns/switch) component.
8
11
  */
9
12
  export var Switch = _ref => {
10
13
  var {
11
14
  label,
12
- disabled = false
15
+ disabled = false,
16
+ help,
17
+ helpClassName
13
18
  } = _ref,
14
19
  inputProps = _objectWithoutProperties(_ref, _excluded);
15
- return /*#__PURE__*/React.createElement("label", {
20
+ var helpId = useId();
21
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("label", {
16
22
  className: "p-switch"
17
23
  }, /*#__PURE__*/React.createElement("input", _extends({
18
24
  type: "checkbox",
@@ -23,6 +29,9 @@ export var Switch = _ref => {
23
29
  className: "p-switch__slider"
24
30
  }), /*#__PURE__*/React.createElement("span", {
25
31
  className: "p-switch__label"
26
- }, label));
32
+ }, label)), help && /*#__PURE__*/React.createElement("p", {
33
+ className: classNames("p-form-help-text", "switch-help-text", helpClassName),
34
+ id: helpId
35
+ }, help));
27
36
  };
28
37
  export default Switch;
@@ -0,0 +1,3 @@
1
+ .switch-help-text {
2
+ margin-left: 2.5rem;
3
+ }
@@ -5,3 +5,4 @@ export default meta;
5
5
  type Story = StoryObj<typeof Switch>;
6
6
  export declare const Default: Story;
7
7
  export declare const Disabled: Story;
8
+ export declare const HelpText: Story;
@@ -16,4 +16,11 @@ export var Disabled = {
16
16
  disabled: true,
17
17
  label: "Disabled switch"
18
18
  }
19
+ };
20
+ export var HelpText = {
21
+ name: "Help Text",
22
+ args: {
23
+ label: "Switch with help text",
24
+ help: "This is some help text"
25
+ }
19
26
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonical/react-components",
3
- "version": "2.4.0",
3
+ "version": "2.5.1",
4
4
  "main": "dist/index.js",
5
5
  "module": "dist/index.js",
6
6
  "author": {