@canonical/react-components 2.4.0 → 2.5.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.
- package/dist/components/Stepper/Step/Step.scss +1 -1
- package/dist/components/Switch/Switch.d.ts +10 -1
- package/dist/components/Switch/Switch.js +13 -3
- package/dist/components/Switch/Switch.scss +3 -0
- package/dist/components/Switch/Switch.stories.d.ts +1 -0
- package/dist/components/Switch/Switch.stories.js +8 -1
- package/dist/esm/components/Stepper/Step/Step.scss +1 -1
- package/dist/esm/components/Switch/Switch.d.ts +10 -1
- package/dist/esm/components/Switch/Switch.js +13 -4
- package/dist/esm/components/Switch/Switch.scss +3 -0
- package/dist/esm/components/Switch/Switch.stories.d.ts +1 -0
- package/dist/esm/components/Switch/Switch.stories.js +7 -0
- package/package.json +1 -1
|
@@ -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 =
|
|
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
|
-
|
|
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;
|
|
@@ -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
|
};
|
|
@@ -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
|
-
|
|
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;
|