@canonical/react-components 4.6.0 → 4.6.2
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/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/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/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/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 +2 -2
|
@@ -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)("p-checkbox-wrapper", 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
|
};
|
|
@@ -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)("p-radio-wrapper", 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;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.default = exports.Required = exports.Inline = exports.Disabled = exports.Default = exports.Children = void 0;
|
|
6
|
+
exports.default = exports.Success = exports.Required = exports.Inline = exports.Help = exports.Error = exports.Disabled = exports.Default = exports.Children = exports.Caution = void 0;
|
|
7
7
|
var _react = _interopRequireDefault(require("react"));
|
|
8
8
|
var _RadioInput = _interopRequireDefault(require("./RadioInput"));
|
|
9
9
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
@@ -48,6 +48,13 @@ const Default = exports.Default = {
|
|
|
48
48
|
}),
|
|
49
49
|
name: "Default"
|
|
50
50
|
};
|
|
51
|
+
const Caution = exports.Caution = {
|
|
52
|
+
render: () => /*#__PURE__*/_react.default.createElement(_RadioInput.default, {
|
|
53
|
+
label: "Caution",
|
|
54
|
+
caution: "This is a caution message"
|
|
55
|
+
}),
|
|
56
|
+
name: "Caution"
|
|
57
|
+
};
|
|
51
58
|
const Children = exports.Children = {
|
|
52
59
|
render: () => /*#__PURE__*/_react.default.createElement(_RadioInput.default, {
|
|
53
60
|
label: /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, "I agree to", /*#__PURE__*/_react.default.createElement("a", {
|
|
@@ -65,6 +72,27 @@ const Disabled = exports.Disabled = {
|
|
|
65
72
|
}),
|
|
66
73
|
name: "Disabled"
|
|
67
74
|
};
|
|
75
|
+
const Error = exports.Error = {
|
|
76
|
+
render: () => /*#__PURE__*/_react.default.createElement(_RadioInput.default, {
|
|
77
|
+
label: "Error",
|
|
78
|
+
error: "This is an error message"
|
|
79
|
+
}),
|
|
80
|
+
name: "Error"
|
|
81
|
+
};
|
|
82
|
+
const Help = exports.Help = {
|
|
83
|
+
render: () => /*#__PURE__*/_react.default.createElement(_RadioInput.default, {
|
|
84
|
+
label: "Help",
|
|
85
|
+
help: "This is a help message"
|
|
86
|
+
}),
|
|
87
|
+
name: "Help"
|
|
88
|
+
};
|
|
89
|
+
const Inline = exports.Inline = {
|
|
90
|
+
render: () => /*#__PURE__*/_react.default.createElement(_RadioInput.default, {
|
|
91
|
+
inline: true,
|
|
92
|
+
label: "Inline"
|
|
93
|
+
}),
|
|
94
|
+
name: "Inline"
|
|
95
|
+
};
|
|
68
96
|
const Required = exports.Required = {
|
|
69
97
|
render: () => /*#__PURE__*/_react.default.createElement(_RadioInput.default, {
|
|
70
98
|
label: "Required",
|
|
@@ -73,11 +101,10 @@ const Required = exports.Required = {
|
|
|
73
101
|
}),
|
|
74
102
|
name: "Required"
|
|
75
103
|
};
|
|
76
|
-
const
|
|
104
|
+
const Success = exports.Success = {
|
|
77
105
|
render: () => /*#__PURE__*/_react.default.createElement(_RadioInput.default, {
|
|
78
|
-
label: "
|
|
79
|
-
|
|
80
|
-
inline: true
|
|
106
|
+
label: "Success",
|
|
107
|
+
success: "This is a success message"
|
|
81
108
|
}),
|
|
82
|
-
name: "
|
|
109
|
+
name: "Success"
|
|
83
110
|
};
|
|
@@ -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;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import _pt from "prop-types";
|
|
2
|
+
var _excluded = ["label", "indeterminate", "caution", "className", "error", "help", "helpClassName", "id", "inline", "success"];
|
|
2
3
|
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
4
|
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
5
|
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
|
-
import React from "react";
|
|
6
|
+
import React, { useId } from "react";
|
|
7
|
+
import classnames from "classnames";
|
|
6
8
|
import CheckableInput from "./CheckableInput";
|
|
9
|
+
import Field from "../Field";
|
|
7
10
|
/**
|
|
8
11
|
* This is a [React](https://reactjs.org/) component for the Vanilla [Checkbox input](https://docs.vanillaframework.io/base/forms#checkbox).
|
|
9
12
|
*
|
|
@@ -12,13 +15,55 @@ import CheckableInput from "./CheckableInput";
|
|
|
12
15
|
var CheckboxInput = _ref => {
|
|
13
16
|
var {
|
|
14
17
|
label,
|
|
15
|
-
indeterminate = false
|
|
18
|
+
indeterminate = false,
|
|
19
|
+
caution,
|
|
20
|
+
className,
|
|
21
|
+
error,
|
|
22
|
+
help,
|
|
23
|
+
helpClassName,
|
|
24
|
+
id,
|
|
25
|
+
inline,
|
|
26
|
+
success
|
|
16
27
|
} = _ref,
|
|
17
28
|
checkboxProps = _objectWithoutProperties(_ref, _excluded);
|
|
18
|
-
|
|
19
|
-
|
|
29
|
+
var defaultInputId = useId();
|
|
30
|
+
var inputId = id || defaultInputId;
|
|
31
|
+
var validationId = useId();
|
|
32
|
+
var helpId = useId();
|
|
33
|
+
var hasError = !!error;
|
|
34
|
+
return /*#__PURE__*/React.createElement(Field, {
|
|
35
|
+
caution: caution,
|
|
36
|
+
className: classnames("p-checkbox-wrapper", className, {
|
|
37
|
+
"p-checkbox--inline": inline
|
|
38
|
+
}),
|
|
39
|
+
error: error,
|
|
40
|
+
forId: inputId,
|
|
41
|
+
help: help,
|
|
42
|
+
helpClassName: helpClassName,
|
|
43
|
+
helpId: helpId,
|
|
44
|
+
inline: inline,
|
|
45
|
+
isTickElement: true,
|
|
46
|
+
success: success,
|
|
47
|
+
validationId: validationId
|
|
48
|
+
}, /*#__PURE__*/React.createElement(CheckableInput, _extends({}, checkboxProps, {
|
|
49
|
+
"aria-describedby": help ? helpId : undefined,
|
|
50
|
+
"aria-errormessage": hasError ? validationId : undefined,
|
|
51
|
+
"aria-invalid": hasError,
|
|
52
|
+
id: inputId,
|
|
53
|
+
indeterminate: indeterminate,
|
|
54
|
+
inline: inline,
|
|
20
55
|
inputType: "checkbox",
|
|
21
|
-
|
|
22
|
-
}
|
|
56
|
+
label: label
|
|
57
|
+
})));
|
|
58
|
+
};
|
|
59
|
+
CheckboxInput.propTypes = {
|
|
60
|
+
caution: _pt.node,
|
|
61
|
+
className: _pt.string,
|
|
62
|
+
error: _pt.node,
|
|
63
|
+
help: _pt.node,
|
|
64
|
+
helpClassName: _pt.string,
|
|
65
|
+
id: _pt.string,
|
|
66
|
+
inline: _pt.bool,
|
|
67
|
+
success: _pt.node
|
|
23
68
|
};
|
|
24
69
|
export 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;
|
|
@@ -38,14 +38,12 @@ export default meta;
|
|
|
38
38
|
export var Default = {
|
|
39
39
|
name: "Default"
|
|
40
40
|
};
|
|
41
|
-
export var
|
|
41
|
+
export var Caution = {
|
|
42
42
|
render: () => /*#__PURE__*/React.createElement(CheckboxInput, {
|
|
43
|
-
label:
|
|
44
|
-
|
|
45
|
-
}, "Terms and Conditions")),
|
|
46
|
-
name: "CheckboxInput"
|
|
43
|
+
label: "Caution",
|
|
44
|
+
caution: "This is a caution message"
|
|
47
45
|
}),
|
|
48
|
-
name: "
|
|
46
|
+
name: "Caution"
|
|
49
47
|
};
|
|
50
48
|
export var Disabled = {
|
|
51
49
|
render: () => /*#__PURE__*/React.createElement(CheckboxInput, {
|
|
@@ -54,19 +52,19 @@ export var Disabled = {
|
|
|
54
52
|
}),
|
|
55
53
|
name: "Disabled"
|
|
56
54
|
};
|
|
57
|
-
export var
|
|
55
|
+
export var Error = {
|
|
58
56
|
render: () => /*#__PURE__*/React.createElement(CheckboxInput, {
|
|
59
|
-
label: "
|
|
60
|
-
|
|
57
|
+
label: "Error",
|
|
58
|
+
error: "This is an error message"
|
|
61
59
|
}),
|
|
62
|
-
name: "
|
|
60
|
+
name: "Error"
|
|
63
61
|
};
|
|
64
|
-
export var
|
|
62
|
+
export var Help = {
|
|
65
63
|
render: () => /*#__PURE__*/React.createElement(CheckboxInput, {
|
|
66
|
-
label: "
|
|
67
|
-
|
|
64
|
+
label: "Help",
|
|
65
|
+
help: "This is a help message"
|
|
68
66
|
}),
|
|
69
|
-
name: "
|
|
67
|
+
name: "Help"
|
|
70
68
|
};
|
|
71
69
|
export var Indeterminate = {
|
|
72
70
|
render: () => /*#__PURE__*/React.createElement(CheckboxInput, {
|
|
@@ -74,4 +72,34 @@ export var Indeterminate = {
|
|
|
74
72
|
indeterminate: true
|
|
75
73
|
}),
|
|
76
74
|
name: "Indeterminate"
|
|
75
|
+
};
|
|
76
|
+
export var Inline = {
|
|
77
|
+
render: () => /*#__PURE__*/React.createElement(CheckboxInput, {
|
|
78
|
+
inline: true,
|
|
79
|
+
label: "Inline"
|
|
80
|
+
}),
|
|
81
|
+
name: "Inline"
|
|
82
|
+
};
|
|
83
|
+
export var LabelWithChildElements = {
|
|
84
|
+
render: () => /*#__PURE__*/React.createElement(CheckboxInput, {
|
|
85
|
+
label: /*#__PURE__*/React.createElement(React.Fragment, null, "I agree to", /*#__PURE__*/React.createElement("a", {
|
|
86
|
+
href: "http://ubuntu.com/legal"
|
|
87
|
+
}, "Terms and Conditions")),
|
|
88
|
+
name: "CheckboxInput"
|
|
89
|
+
}),
|
|
90
|
+
name: "Label with child elements"
|
|
91
|
+
};
|
|
92
|
+
export var Required = {
|
|
93
|
+
render: () => /*#__PURE__*/React.createElement(CheckboxInput, {
|
|
94
|
+
label: "Required",
|
|
95
|
+
required: true
|
|
96
|
+
}),
|
|
97
|
+
name: "Required"
|
|
98
|
+
};
|
|
99
|
+
export var Success = {
|
|
100
|
+
render: () => /*#__PURE__*/React.createElement(CheckboxInput, {
|
|
101
|
+
label: "Success",
|
|
102
|
+
success: "This is a success message"
|
|
103
|
+
}),
|
|
104
|
+
name: "Success"
|
|
77
105
|
};
|
|
@@ -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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["caution", "children", "className", "error", "forId", "help", "helpClassName", "helpAfterLabel", "helpId", "isSelect", "isTickElement", "label", "labelClassName", "labelFirst", "required", "stacked", "stackedFieldColumns", "stackedLabelColumns", "success", "validationId"];
|
|
1
|
+
var _excluded = ["caution", "children", "className", "error", "forId", "help", "helpClassName", "helpAfterLabel", "helpId", "inline", "isSelect", "isTickElement", "label", "labelClassName", "labelFirst", "required", "stacked", "stackedFieldColumns", "stackedLabelColumns", "success", "validationId"];
|
|
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; }
|
|
@@ -61,10 +61,14 @@ var generateContent = _ref2 => {
|
|
|
61
61
|
caution,
|
|
62
62
|
success,
|
|
63
63
|
validationId,
|
|
64
|
-
helpAfterLabel
|
|
64
|
+
helpAfterLabel,
|
|
65
|
+
inline
|
|
65
66
|
} = _ref2;
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
var WrapperComponent = inline ? "span" : "div";
|
|
68
|
+
return /*#__PURE__*/React.createElement(WrapperComponent, {
|
|
69
|
+
className: classNames("p-form__control", {
|
|
70
|
+
"u-clearfix": !inline
|
|
71
|
+
})
|
|
68
72
|
}, isSelect ? /*#__PURE__*/React.createElement("div", {
|
|
69
73
|
className: "p-form-validation__select-wrapper"
|
|
70
74
|
}, children) : children, !labelFirst && labelNode, helpAfterLabel ? null : help, generateError(error, caution, success, validationId));
|
|
@@ -80,6 +84,7 @@ var Field = _ref3 => {
|
|
|
80
84
|
helpClassName,
|
|
81
85
|
helpAfterLabel,
|
|
82
86
|
helpId,
|
|
87
|
+
inline,
|
|
83
88
|
isSelect,
|
|
84
89
|
isTickElement,
|
|
85
90
|
label,
|
|
@@ -110,9 +115,11 @@ var Field = _ref3 => {
|
|
|
110
115
|
caution,
|
|
111
116
|
success,
|
|
112
117
|
validationId,
|
|
113
|
-
helpAfterLabel
|
|
118
|
+
helpAfterLabel,
|
|
119
|
+
inline
|
|
114
120
|
});
|
|
115
|
-
|
|
121
|
+
var WrapperComponent = inline ? "span" : "div";
|
|
122
|
+
return /*#__PURE__*/React.createElement(WrapperComponent, _extends({
|
|
116
123
|
className: classNames("p-form__group", "p-form-validation", className, {
|
|
117
124
|
"is-error": error,
|
|
118
125
|
"is-caution": caution,
|
|
@@ -45,7 +45,6 @@ var Input = _ref => {
|
|
|
45
45
|
} = _ref,
|
|
46
46
|
inputProps = _objectWithoutProperties(_ref, _excluded);
|
|
47
47
|
var inputRef = useRef(null);
|
|
48
|
-
var fieldLabel = !["checkbox", "radio"].includes(type) ? label : "";
|
|
49
48
|
var defaultInputId = useId();
|
|
50
49
|
var inputId = id || defaultInputId;
|
|
51
50
|
var validationId = useId();
|
|
@@ -68,22 +67,30 @@ var Input = _ref => {
|
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
}, [takeFocus, takeFocusDelay]);
|
|
71
|
-
var input;
|
|
72
70
|
if (type === "checkbox") {
|
|
73
|
-
|
|
71
|
+
return /*#__PURE__*/React.createElement(CheckboxInput, _extends({
|
|
74
72
|
label: label,
|
|
75
|
-
labelClassName: labelClassName
|
|
73
|
+
labelClassName: labelClassName,
|
|
74
|
+
caution: caution,
|
|
75
|
+
className: wrapperClassName,
|
|
76
|
+
error: error,
|
|
77
|
+
help: help,
|
|
78
|
+
helpClassName: helpClassName,
|
|
79
|
+
required: required,
|
|
80
|
+
success: success
|
|
76
81
|
}, commonProps));
|
|
77
|
-
}
|
|
78
|
-
|
|
82
|
+
}
|
|
83
|
+
if (type === "radio") {
|
|
84
|
+
return /*#__PURE__*/React.createElement(RadioInput, _extends({
|
|
79
85
|
label: label,
|
|
80
|
-
labelClassName: labelClassName
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
labelClassName: labelClassName,
|
|
87
|
+
caution: caution,
|
|
88
|
+
className: wrapperClassName,
|
|
89
|
+
error: error,
|
|
90
|
+
help: help,
|
|
91
|
+
helpClassName: helpClassName,
|
|
92
|
+
required: required,
|
|
93
|
+
success: success
|
|
87
94
|
}, commonProps));
|
|
88
95
|
}
|
|
89
96
|
return /*#__PURE__*/React.createElement(Field, {
|
|
@@ -95,8 +102,7 @@ var Input = _ref => {
|
|
|
95
102
|
helpAfterLabel: helpAfterLabel,
|
|
96
103
|
helpClassName: helpClassName,
|
|
97
104
|
helpId: helpId,
|
|
98
|
-
|
|
99
|
-
label: fieldLabel,
|
|
105
|
+
label: label,
|
|
100
106
|
labelClassName: labelClassName,
|
|
101
107
|
required: required,
|
|
102
108
|
stacked: stacked,
|
|
@@ -104,6 +110,10 @@ var Input = _ref => {
|
|
|
104
110
|
stackedLabelColumns: stackedLabelColumns,
|
|
105
111
|
success: success,
|
|
106
112
|
validationId: validationId
|
|
107
|
-
}, input
|
|
113
|
+
}, /*#__PURE__*/React.createElement("input", _extends({
|
|
114
|
+
className: classNames("p-form-validation__input", className),
|
|
115
|
+
ref: inputRef,
|
|
116
|
+
type: type
|
|
117
|
+
}, commonProps)));
|
|
108
118
|
};
|
|
109
119
|
export 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;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
import _pt from "prop-types";
|
|
2
|
+
var _excluded = ["label", "caution", "className", "error", "help", "helpClassName", "id", "inline", "success"];
|
|
2
3
|
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
4
|
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
5
|
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
|
-
import React from "react";
|
|
6
|
+
import React, { useId } from "react";
|
|
7
|
+
import classnames from "classnames";
|
|
6
8
|
import CheckableInput from "../CheckboxInput/CheckableInput";
|
|
9
|
+
import Field from "../Field";
|
|
7
10
|
/**
|
|
8
11
|
* This is a [React](https://reactjs.org/) component for the Vanilla [Radio input](https://docs.vanillaframework.io/base/forms#radio-button).
|
|
9
12
|
*
|
|
@@ -11,12 +14,55 @@ import CheckableInput from "../CheckboxInput/CheckableInput";
|
|
|
11
14
|
*/
|
|
12
15
|
var RadioInput = _ref => {
|
|
13
16
|
var {
|
|
14
|
-
label
|
|
17
|
+
label,
|
|
18
|
+
caution,
|
|
19
|
+
className,
|
|
20
|
+
error,
|
|
21
|
+
help,
|
|
22
|
+
helpClassName,
|
|
23
|
+
id,
|
|
24
|
+
inline,
|
|
25
|
+
success
|
|
15
26
|
} = _ref,
|
|
16
27
|
radioProps = _objectWithoutProperties(_ref, _excluded);
|
|
17
|
-
|
|
28
|
+
var defaultInputId = useId();
|
|
29
|
+
var inputId = id || defaultInputId;
|
|
30
|
+
var validationId = useId();
|
|
31
|
+
var helpId = useId();
|
|
32
|
+
var hasError = !!error;
|
|
33
|
+
return /*#__PURE__*/React.createElement(Field, {
|
|
34
|
+
caution: caution,
|
|
35
|
+
className: classnames("p-radio-wrapper", className, {
|
|
36
|
+
"p-radio--inline": inline
|
|
37
|
+
}),
|
|
38
|
+
error: error,
|
|
39
|
+
forId: inputId,
|
|
40
|
+
help: help,
|
|
41
|
+
helpClassName: helpClassName,
|
|
42
|
+
helpId: helpId,
|
|
43
|
+
isTickElement: true,
|
|
44
|
+
success: success,
|
|
45
|
+
validationId: validationId,
|
|
46
|
+
inline: inline
|
|
47
|
+
}, /*#__PURE__*/React.createElement(CheckableInput, _extends({}, radioProps, {
|
|
48
|
+
"aria-describedby": help ? helpId : undefined,
|
|
49
|
+
"aria-errormessage": hasError ? validationId : undefined,
|
|
50
|
+
"aria-invalid": hasError,
|
|
51
|
+
id: inputId,
|
|
52
|
+
inline: inline,
|
|
18
53
|
inputType: "radio",
|
|
19
54
|
label: label
|
|
20
|
-
}
|
|
55
|
+
})));
|
|
56
|
+
};
|
|
57
|
+
RadioInput.propTypes = {
|
|
58
|
+
caution: _pt.node,
|
|
59
|
+
className: _pt.string,
|
|
60
|
+
error: _pt.node,
|
|
61
|
+
help: _pt.node,
|
|
62
|
+
helpClassName: _pt.string,
|
|
63
|
+
id: _pt.string,
|
|
64
|
+
inline: _pt.bool,
|
|
65
|
+
success: _pt.node,
|
|
66
|
+
wrapperClassName: _pt.string
|
|
21
67
|
};
|
|
22
68
|
export 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;
|
|
@@ -41,6 +41,13 @@ export var Default = {
|
|
|
41
41
|
}),
|
|
42
42
|
name: "Default"
|
|
43
43
|
};
|
|
44
|
+
export var Caution = {
|
|
45
|
+
render: () => /*#__PURE__*/React.createElement(RadioInput, {
|
|
46
|
+
label: "Caution",
|
|
47
|
+
caution: "This is a caution message"
|
|
48
|
+
}),
|
|
49
|
+
name: "Caution"
|
|
50
|
+
};
|
|
44
51
|
export var Children = {
|
|
45
52
|
render: () => /*#__PURE__*/React.createElement(RadioInput, {
|
|
46
53
|
label: /*#__PURE__*/React.createElement(React.Fragment, null, "I agree to", /*#__PURE__*/React.createElement("a", {
|
|
@@ -58,6 +65,27 @@ export var Disabled = {
|
|
|
58
65
|
}),
|
|
59
66
|
name: "Disabled"
|
|
60
67
|
};
|
|
68
|
+
export var Error = {
|
|
69
|
+
render: () => /*#__PURE__*/React.createElement(RadioInput, {
|
|
70
|
+
label: "Error",
|
|
71
|
+
error: "This is an error message"
|
|
72
|
+
}),
|
|
73
|
+
name: "Error"
|
|
74
|
+
};
|
|
75
|
+
export var Help = {
|
|
76
|
+
render: () => /*#__PURE__*/React.createElement(RadioInput, {
|
|
77
|
+
label: "Help",
|
|
78
|
+
help: "This is a help message"
|
|
79
|
+
}),
|
|
80
|
+
name: "Help"
|
|
81
|
+
};
|
|
82
|
+
export var Inline = {
|
|
83
|
+
render: () => /*#__PURE__*/React.createElement(RadioInput, {
|
|
84
|
+
inline: true,
|
|
85
|
+
label: "Inline"
|
|
86
|
+
}),
|
|
87
|
+
name: "Inline"
|
|
88
|
+
};
|
|
61
89
|
export var Required = {
|
|
62
90
|
render: () => /*#__PURE__*/React.createElement(RadioInput, {
|
|
63
91
|
label: "Required",
|
|
@@ -66,11 +94,10 @@ export var Required = {
|
|
|
66
94
|
}),
|
|
67
95
|
name: "Required"
|
|
68
96
|
};
|
|
69
|
-
export var
|
|
97
|
+
export var Success = {
|
|
70
98
|
render: () => /*#__PURE__*/React.createElement(RadioInput, {
|
|
71
|
-
label: "
|
|
72
|
-
|
|
73
|
-
inline: true
|
|
99
|
+
label: "Success",
|
|
100
|
+
success: "This is a success message"
|
|
74
101
|
}),
|
|
75
|
-
name: "
|
|
102
|
+
name: "Success"
|
|
76
103
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canonical/react-components",
|
|
3
|
-
"version": "4.6.
|
|
3
|
+
"version": "4.6.2",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"module": "dist/index.js",
|
|
6
6
|
"author": {
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"tsc-alias": "1.8.10",
|
|
97
97
|
"typescript": "5.7.3",
|
|
98
98
|
"typescript-eslint": "8.24.1",
|
|
99
|
-
"vanilla-framework": "4.
|
|
99
|
+
"vanilla-framework": "4.52.0",
|
|
100
100
|
"wait-on": "9.0.3",
|
|
101
101
|
"webpack": "5.105.0"
|
|
102
102
|
},
|