@canonical/react-components 4.5.4 → 4.6.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.
- package/dist/components/ActionButton/ActionButton.d.ts +4 -29
- package/dist/components/ActionButton/ActionButton.js +7 -19
- package/dist/components/Button/Button.d.ts +5 -1
- package/dist/components/CheckboxInput/CheckboxInput.d.ts +12 -3
- package/dist/components/CheckboxInput/CheckboxInput.js +53 -7
- package/dist/components/CheckboxInput/CheckboxInput.stories.d.ts +7 -3
- package/dist/components/CheckboxInput/CheckboxInput.stories.js +43 -15
- package/dist/components/ConfirmationModal/ConfirmationModal.stories.js +9 -2
- package/dist/components/Field/Field.d.ts +5 -1
- package/dist/components/Field/Field.js +13 -6
- package/dist/components/Input/Input.js +26 -16
- package/dist/components/RadioInput/RadioInput.d.ts +13 -3
- package/dist/components/RadioInput/RadioInput.js +52 -5
- package/dist/components/RadioInput/RadioInput.stories.d.ts +5 -1
- package/dist/components/RadioInput/RadioInput.stories.js +33 -6
- package/dist/esm/components/ActionButton/ActionButton.d.ts +4 -29
- package/dist/esm/components/ActionButton/ActionButton.js +7 -19
- package/dist/esm/components/Button/Button.d.ts +5 -1
- package/dist/esm/components/CheckboxInput/CheckboxInput.d.ts +12 -3
- package/dist/esm/components/CheckboxInput/CheckboxInput.js +52 -7
- package/dist/esm/components/CheckboxInput/CheckboxInput.stories.d.ts +7 -3
- package/dist/esm/components/CheckboxInput/CheckboxInput.stories.js +42 -14
- package/dist/esm/components/ConfirmationModal/ConfirmationModal.stories.js +9 -2
- package/dist/esm/components/Field/Field.d.ts +5 -1
- package/dist/esm/components/Field/Field.js +13 -6
- package/dist/esm/components/Input/Input.js +26 -16
- package/dist/esm/components/RadioInput/RadioInput.d.ts +13 -3
- package/dist/esm/components/RadioInput/RadioInput.js +51 -5
- package/dist/esm/components/RadioInput/RadioInput.stories.d.ts +5 -1
- package/dist/esm/components/RadioInput/RadioInput.stories.js +32 -5
- package/package.json +3 -3
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import type { ButtonHTMLAttributes, ReactNode } from "react";
|
|
1
|
+
import React from "react";
|
|
3
2
|
import type { ButtonProps } from "../Button";
|
|
4
|
-
import type {
|
|
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
|
-
},
|
|
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: ({
|
|
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
|
-
|
|
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",
|
|
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
|
-
|
|
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
|
-
|
|
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/).
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
2
|
import type { CheckableInputProps } from "./CheckableInput";
|
|
3
|
-
export type Props = Omit<CheckableInputProps, "inputType"
|
|
3
|
+
export type Props = Omit<CheckableInputProps, "inputType"> & {
|
|
4
|
+
caution?: ReactNode;
|
|
5
|
+
className?: string;
|
|
6
|
+
error?: ReactNode;
|
|
7
|
+
help?: ReactNode;
|
|
8
|
+
helpClassName?: string;
|
|
9
|
+
id?: string;
|
|
10
|
+
inline?: boolean;
|
|
11
|
+
success?: ReactNode;
|
|
12
|
+
};
|
|
4
13
|
/**
|
|
5
14
|
* This is a [React](https://reactjs.org/) component for the Vanilla [Checkbox input](https://docs.vanillaframework.io/base/forms#checkbox).
|
|
6
15
|
*
|
|
7
16
|
* Use the checkbox component to select one or more options.
|
|
8
17
|
*/
|
|
9
|
-
declare const CheckboxInput: ({ label, indeterminate, ...checkboxProps }: Props) => React.JSX.Element;
|
|
18
|
+
declare const CheckboxInput: ({ label, indeterminate, caution, className, error, help, helpClassName, id, inline, success, ...checkboxProps }: Props) => React.JSX.Element;
|
|
10
19
|
export default CheckboxInput;
|
|
@@ -4,9 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
8
10
|
var _CheckableInput = _interopRequireDefault(require("./CheckableInput"));
|
|
9
|
-
|
|
11
|
+
var _Field = _interopRequireDefault(require("../Field"));
|
|
12
|
+
const _excluded = ["label", "indeterminate", "caution", "className", "error", "help", "helpClassName", "id", "inline", "success"];
|
|
13
|
+
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); }
|
|
10
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
15
|
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); }
|
|
12
16
|
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; }
|
|
@@ -19,13 +23,55 @@ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t =
|
|
|
19
23
|
const CheckboxInput = _ref => {
|
|
20
24
|
let {
|
|
21
25
|
label,
|
|
22
|
-
indeterminate = false
|
|
26
|
+
indeterminate = false,
|
|
27
|
+
caution,
|
|
28
|
+
className,
|
|
29
|
+
error,
|
|
30
|
+
help,
|
|
31
|
+
helpClassName,
|
|
32
|
+
id,
|
|
33
|
+
inline,
|
|
34
|
+
success
|
|
23
35
|
} = _ref,
|
|
24
36
|
checkboxProps = _objectWithoutProperties(_ref, _excluded);
|
|
25
|
-
|
|
26
|
-
|
|
37
|
+
const defaultInputId = (0, _react.useId)();
|
|
38
|
+
const inputId = id || defaultInputId;
|
|
39
|
+
const validationId = (0, _react.useId)();
|
|
40
|
+
const helpId = (0, _react.useId)();
|
|
41
|
+
const hasError = !!error;
|
|
42
|
+
return /*#__PURE__*/_react.default.createElement(_Field.default, {
|
|
43
|
+
caution: caution,
|
|
44
|
+
className: (0, _classnames.default)(className, {
|
|
45
|
+
"p-checkbox--inline": inline
|
|
46
|
+
}),
|
|
47
|
+
error: error,
|
|
48
|
+
forId: inputId,
|
|
49
|
+
help: help,
|
|
50
|
+
helpClassName: helpClassName,
|
|
51
|
+
helpId: helpId,
|
|
52
|
+
inline: inline,
|
|
53
|
+
isTickElement: true,
|
|
54
|
+
success: success,
|
|
55
|
+
validationId: validationId
|
|
56
|
+
}, /*#__PURE__*/_react.default.createElement(_CheckableInput.default, _extends({}, checkboxProps, {
|
|
57
|
+
"aria-describedby": help ? helpId : undefined,
|
|
58
|
+
"aria-errormessage": hasError ? validationId : undefined,
|
|
59
|
+
"aria-invalid": hasError,
|
|
60
|
+
id: inputId,
|
|
61
|
+
indeterminate: indeterminate,
|
|
62
|
+
inline: inline,
|
|
27
63
|
inputType: "checkbox",
|
|
28
|
-
|
|
29
|
-
}
|
|
64
|
+
label: label
|
|
65
|
+
})));
|
|
66
|
+
};
|
|
67
|
+
CheckboxInput.propTypes = {
|
|
68
|
+
caution: _propTypes.default.node,
|
|
69
|
+
className: _propTypes.default.string,
|
|
70
|
+
error: _propTypes.default.node,
|
|
71
|
+
help: _propTypes.default.node,
|
|
72
|
+
helpClassName: _propTypes.default.string,
|
|
73
|
+
id: _propTypes.default.string,
|
|
74
|
+
inline: _propTypes.default.bool,
|
|
75
|
+
success: _propTypes.default.node
|
|
30
76
|
};
|
|
31
77
|
var _default = exports.default = CheckboxInput;
|
|
@@ -4,8 +4,12 @@ declare const meta: Meta<typeof CheckboxInput>;
|
|
|
4
4
|
export default meta;
|
|
5
5
|
type Story = StoryObj<typeof CheckboxInput>;
|
|
6
6
|
export declare const Default: Story;
|
|
7
|
-
export declare const
|
|
7
|
+
export declare const Caution: Story;
|
|
8
8
|
export declare const Disabled: Story;
|
|
9
|
-
export declare const
|
|
10
|
-
export declare const
|
|
9
|
+
export declare const Error: Story;
|
|
10
|
+
export declare const Help: Story;
|
|
11
11
|
export declare const Indeterminate: Story;
|
|
12
|
+
export declare const Inline: Story;
|
|
13
|
+
export declare const LabelWithChildElements: Story;
|
|
14
|
+
export declare const Required: Story;
|
|
15
|
+
export declare const Success: Story;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.Required = exports.Inline = exports.Indeterminate = exports.Disabled = exports.Default = exports.
|
|
6
|
+
exports.default = exports.Success = exports.Required = exports.LabelWithChildElements = exports.Inline = exports.Indeterminate = exports.Help = exports.Error = exports.Disabled = exports.Default = exports.Caution = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _CheckboxInput = _interopRequireDefault(require("./CheckboxInput"));
|
|
9
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -45,14 +45,12 @@ var _default = exports.default = meta;
|
|
|
45
45
|
const Default = exports.Default = {
|
|
46
46
|
name: "Default"
|
|
47
47
|
};
|
|
48
|
-
const
|
|
48
|
+
const Caution = exports.Caution = {
|
|
49
49
|
render: () => /*#__PURE__*/_react.default.createElement(_CheckboxInput.default, {
|
|
50
|
-
label:
|
|
51
|
-
|
|
52
|
-
}, "Terms and Conditions")),
|
|
53
|
-
name: "CheckboxInput"
|
|
50
|
+
label: "Caution",
|
|
51
|
+
caution: "This is a caution message"
|
|
54
52
|
}),
|
|
55
|
-
name: "
|
|
53
|
+
name: "Caution"
|
|
56
54
|
};
|
|
57
55
|
const Disabled = exports.Disabled = {
|
|
58
56
|
render: () => /*#__PURE__*/_react.default.createElement(_CheckboxInput.default, {
|
|
@@ -61,19 +59,19 @@ const Disabled = exports.Disabled = {
|
|
|
61
59
|
}),
|
|
62
60
|
name: "Disabled"
|
|
63
61
|
};
|
|
64
|
-
const
|
|
62
|
+
const Error = exports.Error = {
|
|
65
63
|
render: () => /*#__PURE__*/_react.default.createElement(_CheckboxInput.default, {
|
|
66
|
-
label: "
|
|
67
|
-
|
|
64
|
+
label: "Error",
|
|
65
|
+
error: "This is an error message"
|
|
68
66
|
}),
|
|
69
|
-
name: "
|
|
67
|
+
name: "Error"
|
|
70
68
|
};
|
|
71
|
-
const
|
|
69
|
+
const Help = exports.Help = {
|
|
72
70
|
render: () => /*#__PURE__*/_react.default.createElement(_CheckboxInput.default, {
|
|
73
|
-
label: "
|
|
74
|
-
|
|
71
|
+
label: "Help",
|
|
72
|
+
help: "This is a help message"
|
|
75
73
|
}),
|
|
76
|
-
name: "
|
|
74
|
+
name: "Help"
|
|
77
75
|
};
|
|
78
76
|
const Indeterminate = exports.Indeterminate = {
|
|
79
77
|
render: () => /*#__PURE__*/_react.default.createElement(_CheckboxInput.default, {
|
|
@@ -81,4 +79,34 @@ const Indeterminate = exports.Indeterminate = {
|
|
|
81
79
|
indeterminate: true
|
|
82
80
|
}),
|
|
83
81
|
name: "Indeterminate"
|
|
82
|
+
};
|
|
83
|
+
const Inline = exports.Inline = {
|
|
84
|
+
render: () => /*#__PURE__*/_react.default.createElement(_CheckboxInput.default, {
|
|
85
|
+
inline: true,
|
|
86
|
+
label: "Inline"
|
|
87
|
+
}),
|
|
88
|
+
name: "Inline"
|
|
89
|
+
};
|
|
90
|
+
const LabelWithChildElements = exports.LabelWithChildElements = {
|
|
91
|
+
render: () => /*#__PURE__*/_react.default.createElement(_CheckboxInput.default, {
|
|
92
|
+
label: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, "I agree to", /*#__PURE__*/_react.default.createElement("a", {
|
|
93
|
+
href: "http://ubuntu.com/legal"
|
|
94
|
+
}, "Terms and Conditions")),
|
|
95
|
+
name: "CheckboxInput"
|
|
96
|
+
}),
|
|
97
|
+
name: "Label with child elements"
|
|
98
|
+
};
|
|
99
|
+
const Required = exports.Required = {
|
|
100
|
+
render: () => /*#__PURE__*/_react.default.createElement(_CheckboxInput.default, {
|
|
101
|
+
label: "Required",
|
|
102
|
+
required: true
|
|
103
|
+
}),
|
|
104
|
+
name: "Required"
|
|
105
|
+
};
|
|
106
|
+
const Success = exports.Success = {
|
|
107
|
+
render: () => /*#__PURE__*/_react.default.createElement(_CheckboxInput.default, {
|
|
108
|
+
label: "Success",
|
|
109
|
+
success: "This is a success message"
|
|
110
|
+
}),
|
|
111
|
+
name: "Success"
|
|
84
112
|
};
|
|
@@ -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:
|
|
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"
|
|
@@ -42,6 +42,10 @@ export type Props = {
|
|
|
42
42
|
* An id to give to the help element.
|
|
43
43
|
*/
|
|
44
44
|
helpId?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Whether the component is inline.
|
|
47
|
+
*/
|
|
48
|
+
inline?: boolean;
|
|
45
49
|
/**
|
|
46
50
|
* Whether the component is wrapping a select element.
|
|
47
51
|
*/
|
|
@@ -87,5 +91,5 @@ export type Props = {
|
|
|
87
91
|
*/
|
|
88
92
|
validationId?: string;
|
|
89
93
|
};
|
|
90
|
-
declare const Field: ({ caution, children, className, error, forId, help, helpClassName, helpAfterLabel, helpId, isSelect, isTickElement, label, labelClassName, labelFirst, required, stacked, stackedFieldColumns, stackedLabelColumns, success, validationId, ...props }: Props) => React.JSX.Element;
|
|
94
|
+
declare const Field: ({ caution, children, className, error, forId, help, helpClassName, helpAfterLabel, helpId, inline, isSelect, isTickElement, label, labelClassName, labelFirst, required, stacked, stackedFieldColumns, stackedLabelColumns, success, validationId, ...props }: Props) => React.JSX.Element;
|
|
91
95
|
export default Field;
|
|
@@ -8,7 +8,7 @@ var _classnames = _interopRequireDefault(require("classnames"));
|
|
|
8
8
|
var _react = _interopRequireDefault(require("react"));
|
|
9
9
|
var _Label = _interopRequireDefault(require("../Label"));
|
|
10
10
|
var _Col = _interopRequireDefault(require("../Col"));
|
|
11
|
-
const _excluded = ["caution", "children", "className", "error", "forId", "help", "helpClassName", "helpAfterLabel", "helpId", "isSelect", "isTickElement", "label", "labelClassName", "labelFirst", "required", "stacked", "stackedFieldColumns", "stackedLabelColumns", "success", "validationId"];
|
|
11
|
+
const _excluded = ["caution", "children", "className", "error", "forId", "help", "helpClassName", "helpAfterLabel", "helpId", "inline", "isSelect", "isTickElement", "label", "labelClassName", "labelFirst", "required", "stacked", "stackedFieldColumns", "stackedLabelColumns", "success", "validationId"];
|
|
12
12
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
13
|
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); }
|
|
14
14
|
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; }
|
|
@@ -67,10 +67,14 @@ const generateContent = _ref2 => {
|
|
|
67
67
|
caution,
|
|
68
68
|
success,
|
|
69
69
|
validationId,
|
|
70
|
-
helpAfterLabel
|
|
70
|
+
helpAfterLabel,
|
|
71
|
+
inline
|
|
71
72
|
} = _ref2;
|
|
72
|
-
|
|
73
|
-
|
|
73
|
+
const WrapperComponent = inline ? "span" : "div";
|
|
74
|
+
return /*#__PURE__*/_react.default.createElement(WrapperComponent, {
|
|
75
|
+
className: (0, _classnames.default)("p-form__control", {
|
|
76
|
+
"u-clearfix": !inline
|
|
77
|
+
})
|
|
74
78
|
}, isSelect ? /*#__PURE__*/_react.default.createElement("div", {
|
|
75
79
|
className: "p-form-validation__select-wrapper"
|
|
76
80
|
}, children) : children, !labelFirst && labelNode, helpAfterLabel ? null : help, generateError(error, caution, success, validationId));
|
|
@@ -86,6 +90,7 @@ const Field = _ref3 => {
|
|
|
86
90
|
helpClassName,
|
|
87
91
|
helpAfterLabel,
|
|
88
92
|
helpId,
|
|
93
|
+
inline,
|
|
89
94
|
isSelect,
|
|
90
95
|
isTickElement,
|
|
91
96
|
label,
|
|
@@ -116,9 +121,11 @@ const Field = _ref3 => {
|
|
|
116
121
|
caution,
|
|
117
122
|
success,
|
|
118
123
|
validationId,
|
|
119
|
-
helpAfterLabel
|
|
124
|
+
helpAfterLabel,
|
|
125
|
+
inline
|
|
120
126
|
});
|
|
121
|
-
|
|
127
|
+
const WrapperComponent = inline ? "span" : "div";
|
|
128
|
+
return /*#__PURE__*/_react.default.createElement(WrapperComponent, _extends({
|
|
122
129
|
className: (0, _classnames.default)("p-form__group", "p-form-validation", className, {
|
|
123
130
|
"is-error": error,
|
|
124
131
|
"is-caution": caution,
|
|
@@ -52,7 +52,6 @@ const Input = _ref => {
|
|
|
52
52
|
} = _ref,
|
|
53
53
|
inputProps = _objectWithoutProperties(_ref, _excluded);
|
|
54
54
|
const inputRef = (0, _react.useRef)(null);
|
|
55
|
-
const fieldLabel = !["checkbox", "radio"].includes(type) ? label : "";
|
|
56
55
|
const defaultInputId = (0, _react.useId)();
|
|
57
56
|
const inputId = id || defaultInputId;
|
|
58
57
|
const validationId = (0, _react.useId)();
|
|
@@ -75,22 +74,30 @@ const Input = _ref => {
|
|
|
75
74
|
}
|
|
76
75
|
}
|
|
77
76
|
}, [takeFocus, takeFocusDelay]);
|
|
78
|
-
let input;
|
|
79
77
|
if (type === "checkbox") {
|
|
80
|
-
|
|
78
|
+
return /*#__PURE__*/_react.default.createElement(_CheckboxInput.default, _extends({
|
|
81
79
|
label: label,
|
|
82
|
-
labelClassName: labelClassName
|
|
80
|
+
labelClassName: labelClassName,
|
|
81
|
+
caution: caution,
|
|
82
|
+
className: wrapperClassName,
|
|
83
|
+
error: error,
|
|
84
|
+
help: help,
|
|
85
|
+
helpClassName: helpClassName,
|
|
86
|
+
required: required,
|
|
87
|
+
success: success
|
|
83
88
|
}, commonProps));
|
|
84
|
-
}
|
|
85
|
-
|
|
89
|
+
}
|
|
90
|
+
if (type === "radio") {
|
|
91
|
+
return /*#__PURE__*/_react.default.createElement(_RadioInput.default, _extends({
|
|
86
92
|
label: label,
|
|
87
|
-
labelClassName: labelClassName
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
labelClassName: labelClassName,
|
|
94
|
+
caution: caution,
|
|
95
|
+
className: wrapperClassName,
|
|
96
|
+
error: error,
|
|
97
|
+
help: help,
|
|
98
|
+
helpClassName: helpClassName,
|
|
99
|
+
required: required,
|
|
100
|
+
success: success
|
|
94
101
|
}, commonProps));
|
|
95
102
|
}
|
|
96
103
|
return /*#__PURE__*/_react.default.createElement(_Field.default, {
|
|
@@ -102,8 +109,7 @@ const Input = _ref => {
|
|
|
102
109
|
helpAfterLabel: helpAfterLabel,
|
|
103
110
|
helpClassName: helpClassName,
|
|
104
111
|
helpId: helpId,
|
|
105
|
-
|
|
106
|
-
label: fieldLabel,
|
|
112
|
+
label: label,
|
|
107
113
|
labelClassName: labelClassName,
|
|
108
114
|
required: required,
|
|
109
115
|
stacked: stacked,
|
|
@@ -111,6 +117,10 @@ const Input = _ref => {
|
|
|
111
117
|
stackedLabelColumns: stackedLabelColumns,
|
|
112
118
|
success: success,
|
|
113
119
|
validationId: validationId
|
|
114
|
-
}, input
|
|
120
|
+
}, /*#__PURE__*/_react.default.createElement("input", _extends({
|
|
121
|
+
className: (0, _classnames.default)("p-form-validation__input", className),
|
|
122
|
+
ref: inputRef,
|
|
123
|
+
type: type
|
|
124
|
+
}, commonProps)));
|
|
115
125
|
};
|
|
116
126
|
var _default = exports.default = Input;
|
|
@@ -1,10 +1,20 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
2
|
import type { CheckableInputProps } from "../CheckboxInput/CheckableInput";
|
|
3
|
-
export type Props = Omit<CheckableInputProps, "inputType"
|
|
3
|
+
export type Props = Omit<CheckableInputProps, "inputType"> & {
|
|
4
|
+
caution?: ReactNode;
|
|
5
|
+
className?: string;
|
|
6
|
+
error?: ReactNode;
|
|
7
|
+
help?: ReactNode;
|
|
8
|
+
helpClassName?: string;
|
|
9
|
+
id?: string;
|
|
10
|
+
inline?: boolean;
|
|
11
|
+
success?: ReactNode;
|
|
12
|
+
wrapperClassName?: string;
|
|
13
|
+
};
|
|
4
14
|
/**
|
|
5
15
|
* This is a [React](https://reactjs.org/) component for the Vanilla [Radio input](https://docs.vanillaframework.io/base/forms#radio-button).
|
|
6
16
|
*
|
|
7
17
|
* Use radio buttons to select one of the given set of options.
|
|
8
18
|
*/
|
|
9
|
-
declare const RadioInput: ({ label, ...radioProps }: Props) => React.JSX.Element;
|
|
19
|
+
declare const RadioInput: ({ label, caution, className, error, help, helpClassName, id, inline, success, ...radioProps }: Props) => React.JSX.Element;
|
|
10
20
|
export default RadioInput;
|
|
@@ -4,9 +4,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
var
|
|
7
|
+
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
8
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
9
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
8
10
|
var _CheckableInput = _interopRequireDefault(require("../CheckboxInput/CheckableInput"));
|
|
9
|
-
|
|
11
|
+
var _Field = _interopRequireDefault(require("../Field"));
|
|
12
|
+
const _excluded = ["label", "caution", "className", "error", "help", "helpClassName", "id", "inline", "success"];
|
|
13
|
+
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); }
|
|
10
14
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
15
|
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); }
|
|
12
16
|
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; }
|
|
@@ -18,12 +22,55 @@ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t =
|
|
|
18
22
|
*/
|
|
19
23
|
const RadioInput = _ref => {
|
|
20
24
|
let {
|
|
21
|
-
label
|
|
25
|
+
label,
|
|
26
|
+
caution,
|
|
27
|
+
className,
|
|
28
|
+
error,
|
|
29
|
+
help,
|
|
30
|
+
helpClassName,
|
|
31
|
+
id,
|
|
32
|
+
inline,
|
|
33
|
+
success
|
|
22
34
|
} = _ref,
|
|
23
35
|
radioProps = _objectWithoutProperties(_ref, _excluded);
|
|
24
|
-
|
|
36
|
+
const defaultInputId = (0, _react.useId)();
|
|
37
|
+
const inputId = id || defaultInputId;
|
|
38
|
+
const validationId = (0, _react.useId)();
|
|
39
|
+
const helpId = (0, _react.useId)();
|
|
40
|
+
const hasError = !!error;
|
|
41
|
+
return /*#__PURE__*/_react.default.createElement(_Field.default, {
|
|
42
|
+
caution: caution,
|
|
43
|
+
className: (0, _classnames.default)(className, {
|
|
44
|
+
"p-radio--inline": inline
|
|
45
|
+
}),
|
|
46
|
+
error: error,
|
|
47
|
+
forId: inputId,
|
|
48
|
+
help: help,
|
|
49
|
+
helpClassName: helpClassName,
|
|
50
|
+
helpId: helpId,
|
|
51
|
+
isTickElement: true,
|
|
52
|
+
success: success,
|
|
53
|
+
validationId: validationId,
|
|
54
|
+
inline: inline
|
|
55
|
+
}, /*#__PURE__*/_react.default.createElement(_CheckableInput.default, _extends({}, radioProps, {
|
|
56
|
+
"aria-describedby": help ? helpId : undefined,
|
|
57
|
+
"aria-errormessage": hasError ? validationId : undefined,
|
|
58
|
+
"aria-invalid": hasError,
|
|
59
|
+
id: inputId,
|
|
60
|
+
inline: inline,
|
|
25
61
|
inputType: "radio",
|
|
26
62
|
label: label
|
|
27
|
-
}
|
|
63
|
+
})));
|
|
64
|
+
};
|
|
65
|
+
RadioInput.propTypes = {
|
|
66
|
+
caution: _propTypes.default.node,
|
|
67
|
+
className: _propTypes.default.string,
|
|
68
|
+
error: _propTypes.default.node,
|
|
69
|
+
help: _propTypes.default.node,
|
|
70
|
+
helpClassName: _propTypes.default.string,
|
|
71
|
+
id: _propTypes.default.string,
|
|
72
|
+
inline: _propTypes.default.bool,
|
|
73
|
+
success: _propTypes.default.node,
|
|
74
|
+
wrapperClassName: _propTypes.default.string
|
|
28
75
|
};
|
|
29
76
|
var _default = exports.default = RadioInput;
|
|
@@ -4,7 +4,11 @@ declare const meta: Meta<typeof RadioInput>;
|
|
|
4
4
|
export default meta;
|
|
5
5
|
type Story = StoryObj<typeof RadioInput>;
|
|
6
6
|
export declare const Default: Story;
|
|
7
|
+
export declare const Caution: Story;
|
|
7
8
|
export declare const Children: Story;
|
|
8
9
|
export declare const Disabled: Story;
|
|
9
|
-
export declare const
|
|
10
|
+
export declare const Error: Story;
|
|
11
|
+
export declare const Help: Story;
|
|
10
12
|
export declare const Inline: Story;
|
|
13
|
+
export declare const Required: Story;
|
|
14
|
+
export declare const Success: Story;
|