@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
|
@@ -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,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;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
var _excluded = ["
|
|
1
|
+
var _excluded = ["children", "className", "disabled", "loading", "success"];
|
|
2
2
|
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
|
|
3
3
|
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
4
4
|
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
5
5
|
import classNames from "classnames";
|
|
6
6
|
import React, { useEffect, useRef, useState } from "react";
|
|
7
7
|
import Icon from "../Icon";
|
|
8
|
+
import Button from "../Button";
|
|
8
9
|
export var LOADER_MIN_DURATION = 400; // minimium duration (ms) loader displays
|
|
9
10
|
export var SUCCESS_DURATION = 2000; // duration (ms) success tick is displayed
|
|
10
11
|
|
|
@@ -22,12 +23,9 @@ export var Label = /*#__PURE__*/function (Label) {
|
|
|
22
23
|
*/
|
|
23
24
|
var ActionButton = _ref => {
|
|
24
25
|
var {
|
|
25
|
-
appearance,
|
|
26
26
|
children,
|
|
27
27
|
className,
|
|
28
|
-
onClick,
|
|
29
28
|
disabled = null,
|
|
30
|
-
inline = false,
|
|
31
29
|
loading = false,
|
|
32
30
|
success = false
|
|
33
31
|
} = _ref,
|
|
@@ -98,26 +96,16 @@ var ActionButton = _ref => {
|
|
|
98
96
|
}
|
|
99
97
|
return () => window.clearTimeout(successTimeout);
|
|
100
98
|
}, [showSuccess]);
|
|
101
|
-
var buttonClasses = classNames(className, "p-action-button",
|
|
102
|
-
"is-processing": showLoader || showSuccess
|
|
103
|
-
"is-disabled": disabled === null ? showLoader : disabled,
|
|
104
|
-
"is-inline": inline
|
|
99
|
+
var buttonClasses = classNames(className, "p-action-button", {
|
|
100
|
+
"is-processing": showLoader || showSuccess
|
|
105
101
|
});
|
|
106
102
|
var showIcon = showLoader || showSuccess;
|
|
107
|
-
var isDisabled = disabled === null ? showLoader : disabled;
|
|
108
103
|
var icon = showLoader && "spinner" || showSuccess && "success" || null;
|
|
109
|
-
var iconLight = appearance === "positive" || appearance === "negative";
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
// This component uses the base button element instead of the Button component
|
|
113
|
-
// as the button requires a ref and Button would have to be updated to use
|
|
114
|
-
// forwardRef which is not currently supported by components that use
|
|
115
|
-
// typescript generics.
|
|
116
|
-
return /*#__PURE__*/React.createElement("button", _extends({
|
|
104
|
+
var iconLight = buttonProps.appearance === "positive" || buttonProps.appearance === "negative";
|
|
105
|
+
return /*#__PURE__*/React.createElement(Button, _extends({
|
|
117
106
|
className: buttonClasses,
|
|
118
107
|
ref: ref,
|
|
119
|
-
|
|
120
|
-
"aria-disabled": isDisabled || undefined,
|
|
108
|
+
disabled: disabled === null ? showLoader : disabled,
|
|
121
109
|
style: height && width ? {
|
|
122
110
|
height: "".concat(height, "px"),
|
|
123
111
|
width: "".concat(width, "px")
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import type { ButtonHTMLAttributes, ComponentType, ElementType, MouseEventHandler, ReactNode } from "react";
|
|
2
|
+
import type { ButtonHTMLAttributes, ComponentType, ElementType, MouseEventHandler, ReactNode, Ref } from "react";
|
|
3
3
|
import type { ClassName, ValueOf } from "../../types";
|
|
4
4
|
export declare const ButtonAppearance: {
|
|
5
5
|
readonly BASE: "base";
|
|
@@ -54,6 +54,10 @@ export type Props<P = null> = {
|
|
|
54
54
|
* Whether the button should be small.
|
|
55
55
|
*/
|
|
56
56
|
small?: boolean;
|
|
57
|
+
/**
|
|
58
|
+
* A ref to the button.
|
|
59
|
+
*/
|
|
60
|
+
ref?: Ref<HTMLButtonElement>;
|
|
57
61
|
} & (Omit<ButtonHTMLAttributes<HTMLButtonElement>, "onClick"> | P);
|
|
58
62
|
/**
|
|
59
63
|
* This is a [React](https://reactjs.org/) component for the Vanilla [Button](https://docs.vanillaframework.io/patterns/buttons/).
|
|
@@ -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(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
|
};
|
|
@@ -2,6 +2,7 @@ import { useState } from "react";
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import ConfirmationModal from "./ConfirmationModal";
|
|
4
4
|
import Input from "../Input";
|
|
5
|
+
import Icon from "../Icon";
|
|
5
6
|
var doNothing = () => {};
|
|
6
7
|
var meta = {
|
|
7
8
|
component: ConfirmationModal,
|
|
@@ -17,9 +18,15 @@ export var Default = {
|
|
|
17
18
|
onClick: () => setModalOpen(true)
|
|
18
19
|
}, "Open confirmation modal"), modalOpen ? /*#__PURE__*/React.createElement(ConfirmationModal, {
|
|
19
20
|
title: "Confirm delete",
|
|
20
|
-
confirmButtonLabel:
|
|
21
|
+
confirmButtonLabel: /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Icon, {
|
|
22
|
+
name: "delete",
|
|
23
|
+
light: true
|
|
24
|
+
}), /*#__PURE__*/React.createElement("span", null, "Delete")),
|
|
21
25
|
onConfirm: doNothing,
|
|
22
|
-
close: closeHandler
|
|
26
|
+
close: closeHandler,
|
|
27
|
+
confirmButtonProps: {
|
|
28
|
+
hasIcon: true
|
|
29
|
+
}
|
|
23
30
|
}, /*#__PURE__*/React.createElement("p", null, "This will permanently delete the user \"Simon\".", /*#__PURE__*/React.createElement("br", null), "You cannot undo this action.")) : null);
|
|
24
31
|
},
|
|
25
32
|
name: "Default"
|
|
@@ -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(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;
|