@ansible/ansible-ui-framework 0.0.376 → 0.0.377

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.
Files changed (29) hide show
  1. package/cjs/PageForm/FormPage.d.ts +17 -0
  2. package/cjs/PageForm/FormPage.js +73 -0
  3. package/cjs/PageForm/Inputs/PageFormCheckbox.d.ts +9 -0
  4. package/cjs/PageForm/Inputs/PageFormCheckbox.js +24 -0
  5. package/cjs/PageForm/{PageFormSelectOption.d.ts → Inputs/PageFormSelectOption.d.ts} +3 -3
  6. package/cjs/PageForm/{PageFormSelectOption.js → Inputs/PageFormSelectOption.js} +1 -1
  7. package/cjs/PageForm/Inputs/PageFormSlider.d.ts +12 -0
  8. package/cjs/PageForm/Inputs/PageFormSlider.js +36 -0
  9. package/cjs/PageForm/Inputs/PageFormSwitch.d.ts +9 -0
  10. package/cjs/PageForm/Inputs/PageFormSwitch.js +34 -0
  11. package/cjs/PageForm/Inputs/PageFormTextArea.d.ts +11 -0
  12. package/cjs/PageForm/Inputs/PageFormTextArea.js +27 -0
  13. package/cjs/PageForm/Inputs/PageFormTextInput.d.ts +11 -0
  14. package/cjs/PageForm/Inputs/PageFormTextInput.js +48 -0
  15. package/cjs/PageForm/Inputs/PageFormTextSelect.d.ts +14 -0
  16. package/cjs/PageForm/Inputs/PageFormTextSelect.js +42 -0
  17. package/cjs/PageForm/PageForm.d.ts +3 -126
  18. package/cjs/PageForm/PageForm.js +3 -283
  19. package/cjs/PageForm/PageFormAlerts.d.ts +2 -0
  20. package/cjs/PageForm/PageFormAlerts.js +14 -0
  21. package/cjs/PageForm/PageFormButtons.d.ts +6 -0
  22. package/cjs/PageForm/PageFormButtons.js +28 -0
  23. package/cjs/PageForm/PageFormFromSchema.d.ts +6 -0
  24. package/cjs/PageForm/PageFormFromSchema.js +67 -0
  25. package/cjs/PageForm/PageFormInputPopover.d.ts +8 -0
  26. package/cjs/PageForm/PageFormInputPopover.js +2 -0
  27. package/cjs/index.d.ts +1 -1
  28. package/cjs/index.js +1 -1
  29. package/package.json +1 -1
@@ -0,0 +1,17 @@
1
+ import { ReactNode } from 'react';
2
+ import { SubmitHandler, UseFormReturn } from 'react-hook-form';
3
+ import { PartialDeep } from 'type-fest';
4
+ import { PageHeaderProps } from '../PageHeader';
5
+ export type FormPageProps<T extends object> = PageHeaderProps & {
6
+ children?: ReactNode;
7
+ defaultValues?: PartialDeep<T>;
8
+ onSubmit: SubmitHandler<PartialDeep<T>>;
9
+ schema?: unknown;
10
+ isVertical?: boolean;
11
+ onCancel?: () => void;
12
+ submitText?: string;
13
+ hideHeader?: boolean;
14
+ noPadding?: boolean;
15
+ form: UseFormReturn;
16
+ };
17
+ export declare function FormPage<T extends object>(props: FormPageProps<T>): JSX.Element;
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __read = (this && this.__read) || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o), r, ar = [], e;
17
+ try {
18
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
+ }
20
+ catch (error) { e = { error: error }; }
21
+ finally {
22
+ try {
23
+ if (r && !r.done && (m = i["return"])) m.call(i);
24
+ }
25
+ finally { if (e) throw e.error; }
26
+ }
27
+ return ar;
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.FormPage = void 0;
31
+ var jsx_runtime_1 = require("react/jsx-runtime");
32
+ var react_core_1 = require("@patternfly/react-core");
33
+ var react_1 = require("react");
34
+ var Scrollable_1 = require("../components/Scrollable");
35
+ var PageHeader_1 = require("../PageHeader");
36
+ var Settings_1 = require("../Settings");
37
+ var PageFormAlerts_1 = require("./PageFormAlerts");
38
+ var PageFormButtons_1 = require("./PageFormButtons");
39
+ function FormPage(props) {
40
+ // const methods = useForm<PartialDeep<T>>({
41
+ // defaultValues: props.defaultValues,
42
+ // resolver: ajvResolver(props.schema, { strict: false }),
43
+ // })
44
+ var children = react_1.Children.toArray(props.children);
45
+ var inputs = children.filter(function (child) {
46
+ if (!(0, react_1.isValidElement)(child))
47
+ return false;
48
+ if (child.type === PageFormAlerts_1.PageFormAlerts)
49
+ return false;
50
+ if (child.type === PageFormButtons_1.PageFormButtons)
51
+ return false;
52
+ return true;
53
+ });
54
+ var buttons = children.find(function (child) {
55
+ if (!(0, react_1.isValidElement)(child))
56
+ return false;
57
+ if (child.type === PageFormButtons_1.PageFormButtons)
58
+ return true;
59
+ return false;
60
+ });
61
+ var _a = __read((0, react_1.useContext)(Settings_1.SettingsContext), 1), settings = _a[0];
62
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [!props.hideHeader && (0, jsx_runtime_1.jsx)(PageHeader_1.PageHeader, __assign({}, props)), (0, jsx_runtime_1.jsxs)(react_core_1.Form
63
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
64
+ , __assign({
65
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
66
+ onSubmit: props.form.handleSubmit(props.onSubmit), isHorizontal: props.isVertical ? false : settings.formLayout === 'horizontal', style: {
67
+ display: 'flex',
68
+ flexDirection: 'column',
69
+ flexGrow: 1,
70
+ overflow: 'hidden',
71
+ } }, { children: [(0, jsx_runtime_1.jsx)(Scrollable_1.Scrollable, __assign({ style: { height: '100%', flexGrow: 1 } }, { children: (0, jsx_runtime_1.jsx)(react_core_1.PageSection, __assign({ padding: { default: props.noPadding ? 'noPadding' : 'padding' }, isWidthLimited: true }, { children: (0, jsx_runtime_1.jsx)(react_core_1.FormSection, { children: inputs }) })) })), buttons] }))] }));
72
+ }
73
+ exports.FormPage = FormPage;
@@ -0,0 +1,9 @@
1
+ import { ReactNode } from 'react';
2
+ export declare function PageFormCheckbox(props: {
3
+ label: string;
4
+ name: string;
5
+ helperText?: string;
6
+ required?: boolean;
7
+ description?: ReactNode;
8
+ body?: ReactNode;
9
+ }): JSX.Element;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.PageFormCheckbox = void 0;
15
+ var jsx_runtime_1 = require("react/jsx-runtime");
16
+ var react_core_1 = require("@patternfly/react-core");
17
+ var react_hook_form_1 = require("react-hook-form");
18
+ function PageFormCheckbox(props) {
19
+ var control = (0, react_hook_form_1.useFormContext)().control;
20
+ var field = (0, react_hook_form_1.useController)({ control: control, name: props.name }).field;
21
+ var id = props.name;
22
+ return ((0, jsx_runtime_1.jsx)(react_core_1.Checkbox, __assign({ label: props.label, id: id, "aria-describedby": "".concat(id, "-helper"), description: props.description, body: field.value ? props.body : undefined }, field, { isChecked: !!field.value })));
23
+ }
24
+ exports.PageFormCheckbox = PageFormCheckbox;
@@ -1,9 +1,9 @@
1
1
  /// <reference types="react" />
2
- import { PageSelectOptionProps } from '../components/PageSelectOption';
3
- export type PageFormSelectOption<T> = {
2
+ import { PageSelectOptionProps } from '../../components/PageSelectOption';
3
+ export type PageFormSelectOptionProps<T> = {
4
4
  name: string;
5
5
  } & Omit<PageSelectOptionProps<T>, 'onSelect' | 'value'>;
6
6
  /**
7
7
  * A PageSelectOption for use in PageForms
8
8
  */
9
- export declare function PageFormSelectOption<T>(props: PageFormSelectOption<T>): JSX.Element;
9
+ export declare function PageFormSelectOption<T>(props: PageFormSelectOptionProps<T>): JSX.Element;
@@ -14,7 +14,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.PageFormSelectOption = void 0;
15
15
  var jsx_runtime_1 = require("react/jsx-runtime");
16
16
  var react_hook_form_1 = require("react-hook-form");
17
- var PageSelectOption_1 = require("../components/PageSelectOption");
17
+ var PageSelectOption_1 = require("../../components/PageSelectOption");
18
18
  /**
19
19
  * A PageSelectOption for use in PageForms
20
20
  */
@@ -0,0 +1,12 @@
1
+ /// <reference types="react" />
2
+ export declare function PageFormSlider(props: {
3
+ id?: string;
4
+ label: string;
5
+ name: string;
6
+ helperText?: string;
7
+ required?: boolean;
8
+ autoFocus?: boolean;
9
+ min?: number;
10
+ max?: number;
11
+ valueLabel?: string;
12
+ }): JSX.Element;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.PageFormSlider = void 0;
15
+ var jsx_runtime_1 = require("react/jsx-runtime");
16
+ var react_core_1 = require("@patternfly/react-core");
17
+ var react_hook_form_1 = require("react-hook-form");
18
+ function PageFormSlider(props) {
19
+ var _a, _b, _c;
20
+ var isSubmitting = (0, react_hook_form_1.useFormContext)().formState.isSubmitting;
21
+ var _d = (0, react_hook_form_1.useController)({ name: props.name }), field = _d.field, fieldState = _d.fieldState;
22
+ var error = fieldState.error;
23
+ var id = (_a = props.id) !== null && _a !== void 0 ? _a : props.name;
24
+ var max = (_b = props.max) !== null && _b !== void 0 ? _b : 100;
25
+ var min = (_c = props.min) !== null && _c !== void 0 ? _c : 1;
26
+ var value = Number(field.value);
27
+ return ((0, jsx_runtime_1.jsx)(react_core_1.FormGroup, __assign({ id: "".concat(id, "-form-group"), fieldId: id, label: props.label, helperText: props.helperText, isRequired: props.required, validated: (error === null || error === void 0 ? void 0 : error.message) ? 'error' : undefined, helperTextInvalid: error === null || error === void 0 ? void 0 : error.message }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.Flex, __assign({ alignItems: { default: 'alignItemsFlexStart' } }, { children: [(0, jsx_runtime_1.jsxs)(react_core_1.Flex, __assign({ alignItems: { default: 'alignItemsFlexStart' }, spaceItems: { default: 'spaceItemsSm' } }, { children: [(0, jsx_runtime_1.jsx)(react_core_1.FlexItem, __assign({ style: { paddingTop: 6, minWidth: 20, textAlign: 'right' } }, { children: Math.floor((max - min) * value + min) })), props.valueLabel && ((0, jsx_runtime_1.jsx)(react_core_1.FlexItem, __assign({ style: { paddingTop: 6, minWidth: 40 } }, { children: props.valueLabel })))] })), (0, jsx_runtime_1.jsx)(react_core_1.FlexItem, __assign({ grow: { default: 'grow' } }, { children: (0, jsx_runtime_1.jsx)(react_core_1.Slider, { id: id, "aria-describedby": "".concat(id, "-form-group"),
28
+ // isRequired={props.required}
29
+ // validated={error?.message ? 'error' : undefined}
30
+ autoFocus: props.autoFocus,
31
+ // {...registration}
32
+ value: (max - min) * value + min, onChange: function (v) { return field.onChange((v - min) / (max - min)); }, max: max, min: min,
33
+ // innerRef={registration.ref}
34
+ isDisabled: isSubmitting, showBoundaries: false }) }))] })) })));
35
+ }
36
+ exports.PageFormSlider = PageFormSlider;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ export declare function PageFormSwitch(props: {
3
+ id?: string;
4
+ label: string;
5
+ name: string;
6
+ helperText?: string;
7
+ required?: boolean;
8
+ autoFocus?: boolean;
9
+ }): JSX.Element;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.PageFormSwitch = void 0;
15
+ var jsx_runtime_1 = require("react/jsx-runtime");
16
+ var react_core_1 = require("@patternfly/react-core");
17
+ var react_hook_form_1 = require("react-hook-form");
18
+ function PageFormSwitch(props) {
19
+ var _a;
20
+ var isSubmitting = (0, react_hook_form_1.useFormContext)().formState.isSubmitting;
21
+ var _b = (0, react_hook_form_1.useController)({ name: props.name }), field = _b.field, fieldState = _b.fieldState;
22
+ var error = fieldState.error;
23
+ var id = (_a = props.id) !== null && _a !== void 0 ? _a : props.name;
24
+ return ((0, jsx_runtime_1.jsx)(react_core_1.FormGroup, __assign({ id: "".concat(id, "-form-group"), fieldId: id, label: props.label, helperText: props.helperText, isRequired: props.required, validated: (error === null || error === void 0 ? void 0 : error.message) ? 'error' : undefined, helperTextInvalid: error === null || error === void 0 ? void 0 : error.message }, { children: (0, jsx_runtime_1.jsx)(react_core_1.Switch, { id: id, "aria-describedby": "".concat(id, "-form-group"),
25
+ // isRequired={props.required}
26
+ // validated={error?.message ? 'error' : undefined}
27
+ autoFocus: props.autoFocus,
28
+ // placeholder={props.placeholder}
29
+ // {...registration}
30
+ isChecked: typeof field.value === 'boolean' ? field.value : false, onChange: function (e) { return field.onChange(e); },
31
+ // innerRef={registration.ref}
32
+ isDisabled: isSubmitting }) })));
33
+ }
34
+ exports.PageFormSwitch = PageFormSwitch;
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ export declare function PageFormTextArea(props: {
3
+ id?: string;
4
+ label: string;
5
+ name: string;
6
+ helperText?: string;
7
+ required?: boolean;
8
+ secret?: boolean;
9
+ autoFocus?: boolean;
10
+ placeholder?: string;
11
+ }): JSX.Element;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.PageFormTextArea = void 0;
15
+ var jsx_runtime_1 = require("react/jsx-runtime");
16
+ var react_core_1 = require("@patternfly/react-core");
17
+ var react_hook_form_1 = require("react-hook-form");
18
+ function PageFormTextArea(props) {
19
+ var _a;
20
+ var _b = (0, react_hook_form_1.useFormContext)(), register = _b.register, isSubmitting = _b.formState.isSubmitting;
21
+ var registration = register(props.name);
22
+ var fieldState = (0, react_hook_form_1.useController)({ name: props.name }).fieldState;
23
+ var error = fieldState.error;
24
+ var id = (_a = props.id) !== null && _a !== void 0 ? _a : props.name;
25
+ return ((0, jsx_runtime_1.jsx)(react_core_1.FormGroup, __assign({ id: "".concat(id, "-form-group"), fieldId: id, label: props.label, helperText: props.helperText, isRequired: props.required, validated: (error === null || error === void 0 ? void 0 : error.message) ? 'error' : undefined, helperTextInvalid: error === null || error === void 0 ? void 0 : error.message }, { children: (0, jsx_runtime_1.jsx)(react_core_1.TextArea, __assign({ id: id, type: props.secret ? 'password' : 'text', "aria-describedby": "".concat(id, "-form-group"), isRequired: props.required, validated: (error === null || error === void 0 ? void 0 : error.message) ? 'error' : undefined, autoFocus: props.autoFocus, placeholder: props.placeholder }, registration, { onChange: function (v, e) { return void registration.onChange(e); }, resizeOrientation: "vertical", isReadOnly: isSubmitting })) })));
26
+ }
27
+ exports.PageFormTextArea = PageFormTextArea;
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ export declare function PageFormTextInput(props: {
3
+ id?: string;
4
+ label: string;
5
+ name: string;
6
+ helperText?: string;
7
+ required?: boolean;
8
+ secret?: boolean;
9
+ autoFocus?: boolean;
10
+ placeholder?: string;
11
+ }): JSX.Element;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __read = (this && this.__read) || function (o, n) {
14
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
15
+ if (!m) return o;
16
+ var i = m.call(o), r, ar = [], e;
17
+ try {
18
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
19
+ }
20
+ catch (error) { e = { error: error }; }
21
+ finally {
22
+ try {
23
+ if (r && !r.done && (m = i["return"])) m.call(i);
24
+ }
25
+ finally { if (e) throw e.error; }
26
+ }
27
+ return ar;
28
+ };
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.PageFormTextInput = void 0;
31
+ var jsx_runtime_1 = require("react/jsx-runtime");
32
+ var react_core_1 = require("@patternfly/react-core");
33
+ var react_icons_1 = require("@patternfly/react-icons");
34
+ var react_1 = require("react");
35
+ var react_hook_form_1 = require("react-hook-form");
36
+ function PageFormTextInput(props) {
37
+ var _a;
38
+ var _b = (0, react_hook_form_1.useFormContext)(), register = _b.register, isSubmitting = _b.formState.isSubmitting;
39
+ var registration = register(props.name);
40
+ var fieldState = (0, react_hook_form_1.useController)({ name: props.name }).fieldState;
41
+ var error = fieldState.error;
42
+ var id = (_a = props.id) !== null && _a !== void 0 ? _a : props.name;
43
+ var _c = __read((0, react_1.useState)(false), 2), showSecret = _c[0], setShowSecret = _c[1];
44
+ return ((0, jsx_runtime_1.jsx)(react_core_1.FormGroup, __assign({ id: "".concat(id, "-form-group"), fieldId: id, label: props.label, helperText: props.helperText, isRequired: props.required, validated: (error === null || error === void 0 ? void 0 : error.message) ? 'error' : undefined, helperTextInvalid: error === null || error === void 0 ? void 0 : error.message }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.InputGroup, { children: [(0, jsx_runtime_1.jsx)(react_core_1.TextInput, __assign({ id: id, type: props.secret && !showSecret ? 'password' : 'text', "aria-describedby": "".concat(id, "-form-group"), isRequired: props.required, validated: (error === null || error === void 0 ? void 0 : error.message) ? 'error' : undefined, autoFocus: props.autoFocus, placeholder: props.placeholder }, registration, { onChange: function (v, e) {
45
+ void registration.onChange(e);
46
+ }, isReadOnly: isSubmitting })), props.secret && ((0, jsx_runtime_1.jsx)(react_core_1.Button, __assign({ variant: "control", onClick: function () { return setShowSecret(!showSecret); }, "aria-label": "Options menu", isDisabled: isSubmitting }, { children: showSecret ? (0, jsx_runtime_1.jsx)(react_icons_1.EyeIcon, {}) : (0, jsx_runtime_1.jsx)(react_icons_1.EyeSlashIcon, {}) })))] }) })));
47
+ }
48
+ exports.PageFormTextInput = PageFormTextInput;
@@ -0,0 +1,14 @@
1
+ /// <reference types="react" />
2
+ export declare function FormTextSelect<T>(props: {
3
+ id?: string;
4
+ label: string;
5
+ name: string;
6
+ helperText?: string;
7
+ required?: boolean;
8
+ secret?: boolean;
9
+ autoFocus?: boolean;
10
+ placeholder?: string;
11
+ selectTitle?: string;
12
+ selectValue?: (item: T) => string | number;
13
+ selectOpen?: (callback: (item: T) => void, title: string) => void;
14
+ }): JSX.Element;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.FormTextSelect = void 0;
15
+ var jsx_runtime_1 = require("react/jsx-runtime");
16
+ var react_core_1 = require("@patternfly/react-core");
17
+ var react_icons_1 = require("@patternfly/react-icons");
18
+ var react_1 = require("react");
19
+ var react_hook_form_1 = require("react-hook-form");
20
+ function FormTextSelect(props) {
21
+ var _a;
22
+ var _b = (0, react_hook_form_1.useFormContext)(), register = _b.register, setValue = _b.setValue, isSubmitting = _b.formState.isSubmitting;
23
+ var registration = register(props.name);
24
+ var fieldState = (0, react_hook_form_1.useController)({ name: props.name }).fieldState;
25
+ var error = fieldState.error;
26
+ var id = (_a = props.id) !== null && _a !== void 0 ? _a : props.name;
27
+ id = id.split('.').join('-');
28
+ return ((0, jsx_runtime_1.jsx)(react_1.Fragment, { children: (0, jsx_runtime_1.jsx)(react_core_1.FormGroup, __assign({ id: "".concat(id, "-form-group"), fieldId: id, label: props.label, helperText: props.helperText, isRequired: props.required, validated: (error === null || error === void 0 ? void 0 : error.message) ? 'error' : undefined, helperTextInvalid: error === null || error === void 0 ? void 0 : error.message }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.InputGroup, { children: [(0, jsx_runtime_1.jsx)(react_core_1.TextInput, __assign({ id: id, type: props.secret ? 'password' : 'text', "aria-describedby": "".concat(id, "-form-group"), isRequired: props.required, validated: (error === null || error === void 0 ? void 0 : error.message) ? 'error' : undefined, autoFocus: props.autoFocus, placeholder: props.placeholder }, registration, { onChange: function (v, e) {
29
+ void registration.onChange(e);
30
+ },
31
+ // innerRef={registration.ref}
32
+ isReadOnly: isSubmitting })), (0, jsx_runtime_1.jsx)(react_core_1.Button, __assign({ variant: "control", onClick: function () {
33
+ var _a;
34
+ return (_a = props.selectOpen) === null || _a === void 0 ? void 0 : _a.call(props, function (item) {
35
+ if (props.selectValue) {
36
+ var value = props.selectValue(item);
37
+ setValue(props.name, value, { shouldValidate: true });
38
+ }
39
+ }, props.selectTitle);
40
+ }, "aria-label": "Options menu", isDisabled: isSubmitting }, { children: (0, jsx_runtime_1.jsx)(react_icons_1.SearchIcon, {}) }))] }) })) }));
41
+ }
42
+ exports.FormTextSelect = FormTextSelect;
@@ -1,134 +1,11 @@
1
1
  import { JSONSchema6 } from 'json-schema';
2
2
  import { CSSProperties, ReactNode } from 'react';
3
- import { DeepPartial, ErrorOption, FieldPath, FieldValues, SubmitHandler, UseFormReturn } from 'react-hook-form';
4
- import { PartialDeep } from 'type-fest';
5
- import { PageHeaderProps } from '../PageHeader';
6
- export type FormPageProps<T extends object> = PageHeaderProps & {
7
- children?: ReactNode;
8
- defaultValues?: PartialDeep<T>;
9
- onSubmit: SubmitHandler<PartialDeep<T>>;
10
- schema?: unknown;
11
- isVertical?: boolean;
12
- onCancel?: () => void;
13
- submitText?: string;
14
- hideHeader?: boolean;
15
- noPadding?: boolean;
16
- form: UseFormReturn;
17
- };
18
- export declare function FormPage<T extends object>(props: FormPageProps<T>): JSX.Element;
19
- export declare function FormPageAlerts(): JSX.Element;
20
- export declare function FormPageButtons(props: {
21
- submitText: string;
22
- cancelText: string;
23
- onCancel: () => void;
24
- }): JSX.Element;
25
- export declare function FormInputCheckbox(props: {
26
- label: string;
27
- name: string;
28
- helperText?: string;
29
- required?: boolean;
30
- description?: ReactNode;
31
- body?: ReactNode;
32
- }): JSX.Element;
33
- export declare function FormTextInput(props: {
34
- id?: string;
35
- label: string;
36
- name: string;
37
- helperText?: string;
38
- required?: boolean;
39
- secret?: boolean;
40
- autoFocus?: boolean;
41
- placeholder?: string;
42
- }): JSX.Element;
43
- export declare function FormTextArea(props: {
44
- id?: string;
45
- label: string;
46
- name: string;
47
- helperText?: string;
48
- required?: boolean;
49
- secret?: boolean;
50
- autoFocus?: boolean;
51
- placeholder?: string;
52
- }): JSX.Element;
53
- export declare function FormNumberInput(props: {
54
- id?: string;
55
- label: string;
56
- name: string;
57
- helperText?: string;
58
- required?: boolean;
59
- autoFocus?: boolean;
60
- min?: number;
61
- max?: number;
62
- valueLabel?: string;
63
- }): JSX.Element;
64
- export declare function FormBooleanInput(props: {
65
- id?: string;
66
- label: string;
67
- name: string;
68
- helperText?: string;
69
- required?: boolean;
70
- autoFocus?: boolean;
71
- }): JSX.Element;
72
- export interface FormInputPopover {
73
- title?: string;
74
- body?: string[];
75
- link?: {
76
- label: string;
77
- url: string;
78
- };
79
- }
80
- export interface FormSelectOption<T> {
81
- group?: string;
82
- label: string;
83
- description?: string;
84
- value: T;
85
- }
86
- export interface FormSelectProps<T> {
87
- id?: string;
88
- name: string;
89
- label: string;
90
- popover?: FormInputPopover;
91
- placeholder?: string;
92
- help?: string;
93
- required?: boolean;
94
- footer?: {
95
- label?: string;
96
- click?: () => void;
97
- };
98
- create?: boolean;
99
- options: FormSelectOption<T>[];
100
- }
101
- export declare function FormSelect<T>(props: FormSelectProps<T>): JSX.Element;
102
- export declare function FormSelectInput(props: {
103
- label: string;
104
- name: string;
105
- helperText?: string;
106
- required?: boolean;
107
- children?: ReactNode;
108
- footer?: ReactNode;
109
- }): JSX.Element;
110
- export declare function FormTextSelect<T>(props: {
111
- id?: string;
112
- label: string;
113
- name: string;
114
- helperText?: string;
115
- required?: boolean;
116
- secret?: boolean;
117
- autoFocus?: boolean;
118
- placeholder?: string;
119
- selectTitle?: string;
120
- selectValue?: (item: T) => string | number;
121
- selectOpen?: (callback: (item: T) => void, title: string) => void;
122
- }): JSX.Element;
123
- export declare function FormSchema(props: {
124
- schema: JSONSchema6;
125
- base?: string;
126
- }): JSX.Element;
3
+ import { DeepPartial, ErrorOption, FieldPath, FieldValues } from 'react-hook-form';
127
4
  export declare function PageForm<T extends object>(props: {
128
5
  schema?: JSONSchema6;
129
6
  children?: ReactNode;
130
7
  submitText: string;
131
- onSubmit: FormPageSubmitHandler<T>;
8
+ onSubmit: PageFormSubmitHandler<T>;
132
9
  cancelText: string;
133
10
  onCancel?: () => void;
134
11
  defaultValue?: DeepPartial<T>;
@@ -136,7 +13,7 @@ export declare function PageForm<T extends object>(props: {
136
13
  singleColumn?: boolean;
137
14
  disableScrolling?: boolean;
138
15
  }): JSX.Element;
139
- export type FormPageSubmitHandler<T extends FieldValues> = (data: T, setError: (error: string) => void, setFieldError: (fieldName: FieldPath<T>, error: ErrorOption) => void) => Promise<unknown>;
16
+ export type PageFormSubmitHandler<T extends FieldValues> = (data: T, setError: (error: string) => void, setFieldError: (fieldName: FieldPath<T>, error: ErrorOption) => void) => Promise<unknown>;
140
17
  export declare function PageFormSubmitButton(props: {
141
18
  children: ReactNode;
142
19
  style?: CSSProperties;
@@ -26,297 +26,17 @@ var __read = (this && this.__read) || function (o, n) {
26
26
  }
27
27
  return ar;
28
28
  };
29
- var __importDefault = (this && this.__importDefault) || function (mod) {
30
- return (mod && mod.__esModule) ? mod : { "default": mod };
31
- };
32
29
  Object.defineProperty(exports, "__esModule", { value: true });
33
- exports.PageFormCancelButton = exports.PageFormSubmitButton = exports.PageForm = exports.FormSchema = exports.FormTextSelect = exports.FormSelectInput = exports.FormSelect = exports.FormBooleanInput = exports.FormNumberInput = exports.FormTextArea = exports.FormTextInput = exports.FormInputCheckbox = exports.FormPageButtons = exports.FormPageAlerts = exports.FormPage = void 0;
30
+ exports.PageFormCancelButton = exports.PageFormSubmitButton = exports.PageForm = void 0;
34
31
  var jsx_runtime_1 = require("react/jsx-runtime");
35
32
  var ajv_1 = require("@hookform/resolvers/ajv");
36
33
  var react_core_1 = require("@patternfly/react-core");
37
- var react_icons_1 = require("@patternfly/react-icons");
38
- var fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
39
34
  var react_1 = require("react");
40
35
  var react_hook_form_1 = require("react-hook-form");
41
36
  var Scrollable_1 = require("../components/Scrollable");
42
37
  var useBreakPoint_1 = require("../components/useBreakPoint");
43
- var PageHeader_1 = require("../PageHeader");
44
38
  var Settings_1 = require("../Settings");
45
- var PageFormSelectOption_1 = require("./PageFormSelectOption");
46
- function FormPage(props) {
47
- // const methods = useForm<PartialDeep<T>>({
48
- // defaultValues: props.defaultValues,
49
- // resolver: ajvResolver(props.schema, { strict: false }),
50
- // })
51
- var children = react_1.Children.toArray(props.children);
52
- var inputs = children.filter(function (child) {
53
- if (!(0, react_1.isValidElement)(child))
54
- return false;
55
- if (child.type === FormPageAlerts)
56
- return false;
57
- if (child.type === FormPageButtons)
58
- return false;
59
- return true;
60
- });
61
- var buttons = children.find(function (child) {
62
- if (!(0, react_1.isValidElement)(child))
63
- return false;
64
- if (child.type === FormPageButtons)
65
- return true;
66
- return false;
67
- });
68
- var _a = __read((0, react_1.useContext)(Settings_1.SettingsContext), 1), settings = _a[0];
69
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [!props.hideHeader && (0, jsx_runtime_1.jsx)(PageHeader_1.PageHeader, __assign({}, props)), (0, jsx_runtime_1.jsxs)(react_core_1.Form
70
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
71
- , __assign({
72
- // eslint-disable-next-line @typescript-eslint/no-misused-promises
73
- onSubmit: props.form.handleSubmit(props.onSubmit), isHorizontal: props.isVertical ? false : settings.formLayout === 'horizontal', style: {
74
- display: 'flex',
75
- flexDirection: 'column',
76
- flexGrow: 1,
77
- overflow: 'hidden',
78
- } }, { children: [(0, jsx_runtime_1.jsx)(Scrollable_1.Scrollable, __assign({ style: { height: '100%', flexGrow: 1 } }, { children: (0, jsx_runtime_1.jsx)(react_core_1.PageSection, __assign({ padding: { default: props.noPadding ? 'noPadding' : 'padding' }, isWidthLimited: true }, { children: (0, jsx_runtime_1.jsx)(react_core_1.FormSection, { children: inputs }) })) })), buttons] }))] }));
79
- }
80
- exports.FormPage = FormPage;
81
- function FormPageAlerts() {
82
- var errors = (0, react_hook_form_1.useFormState)().errors;
83
- var isMd = (0, useBreakPoint_1.useBreakpoint)('md');
84
- return ((0, jsx_runtime_1.jsx)(react_1.Fragment, { children: errors && Object.keys(errors).length > 0 && ((0, jsx_runtime_1.jsx)(react_core_1.Alert, { title: "Please fix validation errors.", isInline: true, style: { width: '100%', paddingLeft: isMd ? 190 : undefined }, variant: "danger" })) }));
85
- }
86
- exports.FormPageAlerts = FormPageAlerts;
87
- function FormPageButtons(props) {
88
- var errors = (0, react_hook_form_1.useFormState)().errors;
89
- return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(FormPageAlerts, {}), (0, jsx_runtime_1.jsx)(react_core_1.PageSection, __assign({ isFilled: true, style: {
90
- display: 'flex',
91
- flexDirection: 'column',
92
- maxHeight: '100%',
93
- borderTop: 'thin solid var(--pf-global--BorderColor--100)',
94
- }, variant: "light" }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.ActionGroup, __assign({ style: { marginTop: 0 } }, { children: [errors && Object.keys(errors).length > 0 ? ((0, jsx_runtime_1.jsx)(react_core_1.Tooltip, __assign({ content: 'Please fix validation errors' }, { children: (0, jsx_runtime_1.jsx)(react_core_1.Button, __assign({ type: "submit", isAriaDisabled: true }, { children: props.submitText })) }))) : ((0, jsx_runtime_1.jsx)(react_core_1.Button, __assign({ type: "submit" }, { children: props.submitText }))), (0, jsx_runtime_1.jsx)(react_core_1.Button, __assign({ type: "button", variant: "link", onClick: props.onCancel }, { children: props.cancelText }))] })) }))] }));
95
- }
96
- exports.FormPageButtons = FormPageButtons;
97
- function FormInputCheckbox(props) {
98
- var control = (0, react_hook_form_1.useFormContext)().control;
99
- var field = (0, react_hook_form_1.useController)({ control: control, name: props.name }).field;
100
- var id = props.name;
101
- return ((0, jsx_runtime_1.jsx)(react_core_1.Checkbox, __assign({ label: props.label, id: id, "aria-describedby": "".concat(id, "-helper"), description: props.description, body: field.value ? props.body : undefined }, field, { isChecked: !!field.value })));
102
- }
103
- exports.FormInputCheckbox = FormInputCheckbox;
104
- function FormTextInput(props) {
105
- var _a;
106
- var _b = (0, react_hook_form_1.useFormContext)(), register = _b.register, isSubmitting = _b.formState.isSubmitting;
107
- var registration = register(props.name);
108
- var fieldState = (0, react_hook_form_1.useController)({ name: props.name }).fieldState;
109
- var error = fieldState.error;
110
- var id = (_a = props.id) !== null && _a !== void 0 ? _a : props.name;
111
- var _c = __read((0, react_1.useState)(false), 2), showSecret = _c[0], setShowSecret = _c[1];
112
- return ((0, jsx_runtime_1.jsx)(react_core_1.FormGroup, __assign({ id: "".concat(id, "-form-group"), fieldId: id, label: props.label, helperText: props.helperText, isRequired: props.required, validated: (error === null || error === void 0 ? void 0 : error.message) ? 'error' : undefined, helperTextInvalid: error === null || error === void 0 ? void 0 : error.message }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.InputGroup, { children: [(0, jsx_runtime_1.jsx)(react_core_1.TextInput, __assign({ id: id, type: props.secret && !showSecret ? 'password' : 'text', "aria-describedby": "".concat(id, "-form-group"), isRequired: props.required, validated: (error === null || error === void 0 ? void 0 : error.message) ? 'error' : undefined, autoFocus: props.autoFocus, placeholder: props.placeholder }, registration, { onChange: function (v, e) {
113
- void registration.onChange(e);
114
- }, isReadOnly: isSubmitting })), props.secret && ((0, jsx_runtime_1.jsx)(react_core_1.Button, __assign({ variant: "control", onClick: function () { return setShowSecret(!showSecret); }, "aria-label": "Options menu", isDisabled: isSubmitting }, { children: showSecret ? (0, jsx_runtime_1.jsx)(react_icons_1.EyeIcon, {}) : (0, jsx_runtime_1.jsx)(react_icons_1.EyeSlashIcon, {}) })))] }) })));
115
- }
116
- exports.FormTextInput = FormTextInput;
117
- function FormTextArea(props) {
118
- var _a;
119
- var _b = (0, react_hook_form_1.useFormContext)(), register = _b.register, isSubmitting = _b.formState.isSubmitting;
120
- var registration = register(props.name);
121
- var fieldState = (0, react_hook_form_1.useController)({ name: props.name }).fieldState;
122
- var error = fieldState.error;
123
- var id = (_a = props.id) !== null && _a !== void 0 ? _a : props.name;
124
- return ((0, jsx_runtime_1.jsx)(react_core_1.FormGroup, __assign({ id: "".concat(id, "-form-group"), fieldId: id, label: props.label, helperText: props.helperText, isRequired: props.required, validated: (error === null || error === void 0 ? void 0 : error.message) ? 'error' : undefined, helperTextInvalid: error === null || error === void 0 ? void 0 : error.message }, { children: (0, jsx_runtime_1.jsx)(react_core_1.TextArea, __assign({ id: id, type: props.secret ? 'password' : 'text', "aria-describedby": "".concat(id, "-form-group"), isRequired: props.required, validated: (error === null || error === void 0 ? void 0 : error.message) ? 'error' : undefined, autoFocus: props.autoFocus, placeholder: props.placeholder }, registration, { onChange: function (v, e) { return void registration.onChange(e); }, resizeOrientation: "vertical", isReadOnly: isSubmitting })) })));
125
- }
126
- exports.FormTextArea = FormTextArea;
127
- function FormNumberInput(props) {
128
- var _a, _b, _c;
129
- var isSubmitting = (0, react_hook_form_1.useFormContext)().formState.isSubmitting;
130
- var _d = (0, react_hook_form_1.useController)({ name: props.name }), field = _d.field, fieldState = _d.fieldState;
131
- var error = fieldState.error;
132
- var id = (_a = props.id) !== null && _a !== void 0 ? _a : props.name;
133
- var max = (_b = props.max) !== null && _b !== void 0 ? _b : 100;
134
- var min = (_c = props.min) !== null && _c !== void 0 ? _c : 1;
135
- var value = Number(field.value);
136
- return ((0, jsx_runtime_1.jsx)(react_core_1.FormGroup, __assign({ id: "".concat(id, "-form-group"), fieldId: id, label: props.label, helperText: props.helperText, isRequired: props.required, validated: (error === null || error === void 0 ? void 0 : error.message) ? 'error' : undefined, helperTextInvalid: error === null || error === void 0 ? void 0 : error.message }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.Flex, __assign({ alignItems: { default: 'alignItemsFlexStart' } }, { children: [(0, jsx_runtime_1.jsxs)(react_core_1.Flex, __assign({ alignItems: { default: 'alignItemsFlexStart' }, spaceItems: { default: 'spaceItemsSm' } }, { children: [(0, jsx_runtime_1.jsx)(react_core_1.FlexItem, __assign({ style: { paddingTop: 6, minWidth: 20, textAlign: 'right' } }, { children: Math.floor((max - min) * value + min) })), props.valueLabel && ((0, jsx_runtime_1.jsx)(react_core_1.FlexItem, __assign({ style: { paddingTop: 6, minWidth: 40 } }, { children: props.valueLabel })))] })), (0, jsx_runtime_1.jsx)(react_core_1.FlexItem, __assign({ grow: { default: 'grow' } }, { children: (0, jsx_runtime_1.jsx)(react_core_1.Slider, { id: id, "aria-describedby": "".concat(id, "-form-group"),
137
- // isRequired={props.required}
138
- // validated={error?.message ? 'error' : undefined}
139
- autoFocus: props.autoFocus,
140
- // {...registration}
141
- value: (max - min) * value + min, onChange: function (v) { return field.onChange((v - min) / (max - min)); }, max: max, min: min,
142
- // innerRef={registration.ref}
143
- isDisabled: isSubmitting, showBoundaries: false }) }))] })) })));
144
- }
145
- exports.FormNumberInput = FormNumberInput;
146
- function FormBooleanInput(props) {
147
- var _a;
148
- var isSubmitting = (0, react_hook_form_1.useFormContext)().formState.isSubmitting;
149
- var _b = (0, react_hook_form_1.useController)({ name: props.name }), field = _b.field, fieldState = _b.fieldState;
150
- var error = fieldState.error;
151
- var id = (_a = props.id) !== null && _a !== void 0 ? _a : props.name;
152
- return ((0, jsx_runtime_1.jsx)(react_core_1.FormGroup, __assign({ id: "".concat(id, "-form-group"), fieldId: id, label: props.label, helperText: props.helperText, isRequired: props.required, validated: (error === null || error === void 0 ? void 0 : error.message) ? 'error' : undefined, helperTextInvalid: error === null || error === void 0 ? void 0 : error.message }, { children: (0, jsx_runtime_1.jsx)(react_core_1.Switch, { id: id, "aria-describedby": "".concat(id, "-form-group"),
153
- // isRequired={props.required}
154
- // validated={error?.message ? 'error' : undefined}
155
- autoFocus: props.autoFocus,
156
- // placeholder={props.placeholder}
157
- // {...registration}
158
- isChecked: typeof field.value === 'boolean' ? field.value : false, onChange: function (e) { return field.onChange(e); },
159
- // innerRef={registration.ref}
160
- isDisabled: isSubmitting }) })));
161
- }
162
- exports.FormBooleanInput = FormBooleanInput;
163
- function FormSelect(props) {
164
- var _a, _b;
165
- var _c = (0, react_hook_form_1.useController)({ name: props.name }), field = _c.field, fieldError = _c.fieldState.error;
166
- var _d = __read((0, react_1.useState)(false), 2), open = _d[0], setOpen = _d[1];
167
- var id = (_a = props.id) !== null && _a !== void 0 ? _a : props.name;
168
- var error = fieldError !== undefined && fieldError.message;
169
- var options = props.options;
170
- options.sort(function (l, r) {
171
- var _a, _b, _c, _d;
172
- if (((_a = l.group) !== null && _a !== void 0 ? _a : '') < ((_b = r.group) !== null && _b !== void 0 ? _b : ''))
173
- return -1;
174
- if (((_c = l.group) !== null && _c !== void 0 ? _c : '') > ((_d = r.group) !== null && _d !== void 0 ? _d : ''))
175
- return 1;
176
- if (l.label < r.label)
177
- return -1;
178
- if (l.label > r.label)
179
- return 1;
180
- return 0;
181
- });
182
- var selectedIndex = options.findIndex(function (option) { return (0, fast_deep_equal_1.default)(option.value, field.value); });
183
- var groups = options.reduce(function (groups, option) {
184
- var _a;
185
- var group = (_a = option.group) !== null && _a !== void 0 ? _a : '';
186
- var optionsArray = groups[group];
187
- if (!optionsArray) {
188
- optionsArray = [];
189
- groups[group] = optionsArray;
190
- }
191
- optionsArray.push(option);
192
- return groups;
193
- }, {});
194
- var isGrouped = Object.keys(groups).length > 1 ||
195
- (Object.keys(groups).length === 1 && Object.keys(groups)[0] !== '');
196
- var onSelect = (0, react_1.useCallback)(function (_event, value) {
197
- if (typeof value !== 'string') {
198
- value = value.toString();
199
- }
200
- var selectedIndex = Number(value);
201
- var selected = options[selectedIndex].value;
202
- field.onChange(selected);
203
- setOpen(false);
204
- }, [field, options]);
205
- var index = 0;
206
- return ((0, jsx_runtime_1.jsx)(react_core_1.FormGroup, __assign({ id: "".concat(id, "-form-group"), fieldId: id, label: props.label, helperTextInvalid: error, helperText: props.help, isRequired: props.required, validated: error ? 'error' : undefined }, { children: (0, jsx_runtime_1.jsx)(react_core_1.Select, __assign({ id: id, variant: react_core_1.SelectVariant.single, "aria-describedby": "".concat(id, "-helper"), validated: error ? 'error' : undefined }, field, { isOpen: open, onToggle: function () { return setOpen(!open); }, selections: selectedIndex === -1 ? '' : selectedIndex.toString(), onSelect: onSelect, isCreatable: props.create, isInputFilterPersisted: props.create, placeholderText: props.placeholder, isGrouped: isGrouped, ref: field.ref, footer: ((_b = props.footer) === null || _b === void 0 ? void 0 : _b.label) && ((0, jsx_runtime_1.jsx)(react_core_1.Button, __assign({ variant: "link", isInline: true, onClick: function () {
207
- var _a, _b;
208
- setOpen(false);
209
- (_b = (_a = props.footer) === null || _a === void 0 ? void 0 : _a.click) === null || _b === void 0 ? void 0 : _b.call(_a);
210
- } }, { children: props.footer.label }))), maxHeight: 280 }, { children: !isGrouped
211
- ? options.map(function (option, index) { return ((0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: index.toString(), label: option.label, description: option.description }, { children: option.label }), index)); })
212
- : Object.keys(groups).map(function (group) { return ((0, jsx_runtime_1.jsx)(react_core_1.SelectGroup, __assign({ label: group }, { children: groups[group].map(function (option) { return ((0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: (index++).toString(), label: option.label, description: option.description }, { children: option.label }), index)); }) }), group)); }) })) })));
213
- }
214
- exports.FormSelect = FormSelect;
215
- function FormSelectInput(props) {
216
- var control = (0, react_hook_form_1.useFormContext)().control;
217
- var _a = (0, react_hook_form_1.useController)({ control: control, name: props.name }), field = _a.field, error = _a.fieldState.error;
218
- var menuItems = react_1.Children.toArray(props.children)
219
- .filter(function (child) { return (0, react_1.isValidElement)(child) && child.type === react_core_1.SelectOption; })
220
- .map(function (child) {
221
- if ((0, react_1.isValidElement)(child) && child.type === react_core_1.SelectOption) {
222
- return ((0, jsx_runtime_1.jsx)(react_core_1.MenuItem, { children: child.props.children }, child.props.value));
223
- }
224
- return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {});
225
- });
226
- var _b = __read((0, react_1.useState)(false), 2), open = _b[0], setOpen = _b[1];
227
- var id = props.name;
228
- var errorMessage;
229
- switch (error === null || error === void 0 ? void 0 : error.type) {
230
- case 'required':
231
- errorMessage = props.label + ' is required.';
232
- break;
233
- default:
234
- errorMessage = error === null || error === void 0 ? void 0 : error.type;
235
- break;
236
- }
237
- return ((0, jsx_runtime_1.jsx)(react_core_1.FormGroup, __assign({ fieldId: id, label: props.label, helperTextInvalid: errorMessage, helperText: props.helperText, isRequired: props.required, validated: errorMessage ? 'error' : undefined }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.TextInputGroup, { children: [(0, jsx_runtime_1.jsx)(react_core_1.TextInputGroupMain, __assign({}, field)), (0, jsx_runtime_1.jsx)(react_core_1.TextInputGroupUtilities, { children: (0, jsx_runtime_1.jsx)(react_core_1.Button, __assign({ variant: "plain", onClick: function () { return setOpen(!open); }, "aria-label": "Options menu" }, { children: (0, jsx_runtime_1.jsx)(react_icons_1.CaretDownIcon, {}) })) }), open && ((0, jsx_runtime_1.jsx)(react_core_1.Menu, __assign({ style: { position: 'absolute', right: 0, top: 36, width: '100%' } }, { children: menuItems })))] }) })));
238
- }
239
- exports.FormSelectInput = FormSelectInput;
240
- function FormTextSelect(props) {
241
- var _a;
242
- var _b = (0, react_hook_form_1.useFormContext)(), register = _b.register, setValue = _b.setValue, isSubmitting = _b.formState.isSubmitting;
243
- var registration = register(props.name);
244
- var fieldState = (0, react_hook_form_1.useController)({ name: props.name }).fieldState;
245
- var error = fieldState.error;
246
- var id = (_a = props.id) !== null && _a !== void 0 ? _a : props.name;
247
- id = id.split('.').join('-');
248
- return ((0, jsx_runtime_1.jsx)(react_1.Fragment, { children: (0, jsx_runtime_1.jsx)(react_core_1.FormGroup, __assign({ id: "".concat(id, "-form-group"), fieldId: id, label: props.label, helperText: props.helperText, isRequired: props.required, validated: (error === null || error === void 0 ? void 0 : error.message) ? 'error' : undefined, helperTextInvalid: error === null || error === void 0 ? void 0 : error.message }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.InputGroup, { children: [(0, jsx_runtime_1.jsx)(react_core_1.TextInput, __assign({ id: id, type: props.secret ? 'password' : 'text', "aria-describedby": "".concat(id, "-form-group"), isRequired: props.required, validated: (error === null || error === void 0 ? void 0 : error.message) ? 'error' : undefined, autoFocus: props.autoFocus, placeholder: props.placeholder }, registration, { onChange: function (v, e) {
249
- void registration.onChange(e);
250
- },
251
- // innerRef={registration.ref}
252
- isReadOnly: isSubmitting })), (0, jsx_runtime_1.jsx)(react_core_1.Button, __assign({ variant: "control", onClick: function () {
253
- var _a;
254
- return (_a = props.selectOpen) === null || _a === void 0 ? void 0 : _a.call(props, function (item) {
255
- if (props.selectValue) {
256
- var value = props.selectValue(item);
257
- setValue(props.name, value, { shouldValidate: true });
258
- }
259
- }, props.selectTitle);
260
- }, "aria-label": "Options menu", isDisabled: isSubmitting }, { children: (0, jsx_runtime_1.jsx)(react_icons_1.SearchIcon, {}) }))] }) })) }));
261
- }
262
- exports.FormTextSelect = FormTextSelect;
263
- function FormSchema(props) {
264
- var schema = props.schema;
265
- var base = props.base ? props.base + '.' : '';
266
- var p = [];
267
- for (var propertyName in schema.properties) {
268
- var property = schema.properties[propertyName];
269
- switch (property) {
270
- case true:
271
- case false:
272
- continue;
273
- }
274
- var title = typeof property.title === 'string' ? property.title : propertyName;
275
- var placeholder = property.placeholder;
276
- placeholder = typeof placeholder === 'string' ? placeholder : undefined;
277
- var required = Array.isArray(schema.required) && schema.required.includes(propertyName);
278
- switch (property.type) {
279
- case 'string': {
280
- switch (property.variant) {
281
- case 'select': {
282
- if ('options' in property) {
283
- var formSelectProps = property;
284
- p.push((0, jsx_runtime_1.jsx)(PageFormSelectOption_1.PageFormSelectOption, { name: base + propertyName, label: title, placeholder: placeholder, isRequired: required, options: formSelectProps.options, footer: formSelectProps.footer }, base + propertyName));
285
- }
286
- else {
287
- p.push((0, jsx_runtime_1.jsx)(FormTextSelect, { name: base + propertyName, label: title, placeholder: placeholder, required: required, selectTitle: property.selectTitle, selectValue: property.selectValue, selectOpen: property.selectOpen }, base + propertyName));
288
- }
289
- break;
290
- }
291
- case 'textarea':
292
- p.push((0, jsx_runtime_1.jsx)(FormTextArea, { name: base + propertyName, label: title, placeholder: placeholder, required: required }, base + propertyName));
293
- break;
294
- case 'secret':
295
- p.push((0, jsx_runtime_1.jsx)(FormTextInput, { name: base + propertyName, label: title, placeholder: placeholder, required: required, secret: true }, base + propertyName));
296
- break;
297
- default:
298
- p.push((0, jsx_runtime_1.jsx)(FormTextInput, { name: base + propertyName, label: title, placeholder: placeholder, required: required }, base + propertyName));
299
- break;
300
- }
301
- break;
302
- }
303
- case 'number': {
304
- p.push((0, jsx_runtime_1.jsx)(FormNumberInput, { name: base + propertyName, label: title, required: required, min: property.min, max: property.max, valueLabel: property.valueLabel }, base + propertyName));
305
- break;
306
- }
307
- case 'boolean': {
308
- p.push((0, jsx_runtime_1.jsx)(FormBooleanInput, { name: base + propertyName, label: title, required: required }, base + propertyName));
309
- break;
310
- }
311
- case 'object': {
312
- p.push((0, jsx_runtime_1.jsx)(FormSchema, { schema: property, base: base + propertyName }, propertyName));
313
- break;
314
- }
315
- }
316
- }
317
- return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: p });
318
- }
319
- exports.FormSchema = FormSchema;
39
+ var PageFormFromSchema_1 = require("./PageFormFromSchema");
320
40
  function PageForm(props) {
321
41
  var schema = props.schema, defaultValue = props.defaultValue;
322
42
  var form = (0, react_hook_form_1.useForm)({
@@ -352,7 +72,7 @@ function PageForm(props) {
352
72
  flexGrow: 1,
353
73
  overflow: props.disableScrolling ? undefined : 'hidden',
354
74
  gap: 0,
355
- } }, { children: [props.disableScrolling ? ((0, jsx_runtime_1.jsx)("div", __assign({ style: { maxWidth: maxWidth, padding: 24 } }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.Grid, __assign({ hasGutter: true, span: 12, sm: sm, md: md, lg: lg, xl: xl, xl2: xl2 }, { children: [props.schema && (0, jsx_runtime_1.jsx)(FormSchema, { schema: props.schema }), props.children] })) }))) : ((0, jsx_runtime_1.jsx)(Scrollable_1.Scrollable, __assign({ style: { height: '100%', flexGrow: 1 } }, { children: (0, jsx_runtime_1.jsx)("div", __assign({ style: { maxWidth: maxWidth, padding: 24 } }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.Grid, __assign({ hasGutter: true, span: 12, sm: sm, md: md, lg: lg, xl: xl, xl2: xl2 }, { children: [props.schema && (0, jsx_runtime_1.jsx)(FormSchema, { schema: props.schema }), props.children] })) })) }))), error && ((0, jsx_runtime_1.jsx)(react_core_1.Alert, { variant: "danger", title: error !== null && error !== void 0 ? error : '', isInline: true, style: { paddingLeft: isMd && props.onCancel ? 190 : undefined } })), props.onCancel ? ((0, jsx_runtime_1.jsx)("div", __assign({ style: {
75
+ } }, { children: [props.disableScrolling ? ((0, jsx_runtime_1.jsx)("div", __assign({ style: { maxWidth: maxWidth, padding: 24 } }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.Grid, __assign({ hasGutter: true, span: 12, sm: sm, md: md, lg: lg, xl: xl, xl2: xl2 }, { children: [props.schema && (0, jsx_runtime_1.jsx)(PageFormFromSchema_1.FormSchema, { schema: props.schema }), props.children] })) }))) : ((0, jsx_runtime_1.jsx)(Scrollable_1.Scrollable, __assign({ style: { height: '100%', flexGrow: 1 } }, { children: (0, jsx_runtime_1.jsx)("div", __assign({ style: { maxWidth: maxWidth, padding: 24 } }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.Grid, __assign({ hasGutter: true, span: 12, sm: sm, md: md, lg: lg, xl: xl, xl2: xl2 }, { children: [props.schema && (0, jsx_runtime_1.jsx)(PageFormFromSchema_1.FormSchema, { schema: props.schema }), props.children] })) })) }))), error && ((0, jsx_runtime_1.jsx)(react_core_1.Alert, { variant: "danger", title: error !== null && error !== void 0 ? error : '', isInline: true, style: { paddingLeft: isMd && props.onCancel ? 190 : undefined } })), props.onCancel ? ((0, jsx_runtime_1.jsx)("div", __assign({ style: {
356
76
  backgroundColor: settings.theme === 'dark' ? 'var(--pf-global--BackgroundColor--400)' : undefined,
357
77
  padding: 24,
358
78
  } }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.ActionGroup, __assign({ style: { marginTop: 0 } }, { children: [(0, jsx_runtime_1.jsx)(PageFormSubmitButton, { children: props.submitText }), props.onCancel && ((0, jsx_runtime_1.jsx)(PageFormCancelButton, __assign({ onCancel: props.onCancel }, { children: props.cancelText })))] })) }))) : ((0, jsx_runtime_1.jsx)(PageFormSubmitButton, __assign({ style: { marginTop: 48 } }, { children: props.submitText })))] })) }))
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare function PageFormAlerts(): JSX.Element;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PageFormAlerts = void 0;
4
+ var jsx_runtime_1 = require("react/jsx-runtime");
5
+ var react_core_1 = require("@patternfly/react-core");
6
+ var react_1 = require("react");
7
+ var react_hook_form_1 = require("react-hook-form");
8
+ var useBreakPoint_1 = require("../components/useBreakPoint");
9
+ function PageFormAlerts() {
10
+ var errors = (0, react_hook_form_1.useFormState)().errors;
11
+ var isMd = (0, useBreakPoint_1.useBreakpoint)('md');
12
+ return ((0, jsx_runtime_1.jsx)(react_1.Fragment, { children: errors && Object.keys(errors).length > 0 && ((0, jsx_runtime_1.jsx)(react_core_1.Alert, { title: "Please fix validation errors.", isInline: true, style: { width: '100%', paddingLeft: isMd ? 190 : undefined }, variant: "danger" })) }));
13
+ }
14
+ exports.PageFormAlerts = PageFormAlerts;
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ export declare function PageFormButtons(props: {
3
+ submitText: string;
4
+ cancelText: string;
5
+ onCancel: () => void;
6
+ }): JSX.Element;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.PageFormButtons = void 0;
15
+ var jsx_runtime_1 = require("react/jsx-runtime");
16
+ var react_core_1 = require("@patternfly/react-core");
17
+ var react_hook_form_1 = require("react-hook-form");
18
+ var PageFormAlerts_1 = require("./PageFormAlerts");
19
+ function PageFormButtons(props) {
20
+ var errors = (0, react_hook_form_1.useFormState)().errors;
21
+ return ((0, jsx_runtime_1.jsxs)("div", { children: [(0, jsx_runtime_1.jsx)(PageFormAlerts_1.PageFormAlerts, {}), (0, jsx_runtime_1.jsx)(react_core_1.PageSection, __assign({ isFilled: true, style: {
22
+ display: 'flex',
23
+ flexDirection: 'column',
24
+ maxHeight: '100%',
25
+ borderTop: 'thin solid var(--pf-global--BorderColor--100)',
26
+ }, variant: "light" }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.ActionGroup, __assign({ style: { marginTop: 0 } }, { children: [errors && Object.keys(errors).length > 0 ? ((0, jsx_runtime_1.jsx)(react_core_1.Tooltip, __assign({ content: 'Please fix validation errors' }, { children: (0, jsx_runtime_1.jsx)(react_core_1.Button, __assign({ type: "submit", isAriaDisabled: true }, { children: props.submitText })) }))) : ((0, jsx_runtime_1.jsx)(react_core_1.Button, __assign({ type: "submit" }, { children: props.submitText }))), (0, jsx_runtime_1.jsx)(react_core_1.Button, __assign({ type: "button", variant: "link", onClick: props.onCancel }, { children: props.cancelText }))] })) }))] }));
27
+ }
28
+ exports.PageFormButtons = PageFormButtons;
@@ -0,0 +1,6 @@
1
+ /// <reference types="react" />
2
+ import { JSONSchema6 } from 'json-schema';
3
+ export declare function FormSchema(props: {
4
+ schema: JSONSchema6;
5
+ base?: string;
6
+ }): JSX.Element;
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.FormSchema = void 0;
4
+ var jsx_runtime_1 = require("react/jsx-runtime");
5
+ var PageFormSelectOption_1 = require("./Inputs/PageFormSelectOption");
6
+ var PageFormSlider_1 = require("./Inputs/PageFormSlider");
7
+ var PageFormSwitch_1 = require("./Inputs/PageFormSwitch");
8
+ var PageFormTextArea_1 = require("./Inputs/PageFormTextArea");
9
+ var PageFormTextInput_1 = require("./Inputs/PageFormTextInput");
10
+ var PageFormTextSelect_1 = require("./Inputs/PageFormTextSelect");
11
+ function FormSchema(props) {
12
+ var schema = props.schema;
13
+ var base = props.base ? props.base + '.' : '';
14
+ var p = [];
15
+ for (var propertyName in schema.properties) {
16
+ var property = schema.properties[propertyName];
17
+ switch (property) {
18
+ case true:
19
+ case false:
20
+ continue;
21
+ }
22
+ var title = typeof property.title === 'string' ? property.title : propertyName;
23
+ var placeholder = property.placeholder;
24
+ placeholder = typeof placeholder === 'string' ? placeholder : undefined;
25
+ var required = Array.isArray(schema.required) && schema.required.includes(propertyName);
26
+ switch (property.type) {
27
+ case 'string': {
28
+ switch (property.variant) {
29
+ case 'select': {
30
+ if ('options' in property) {
31
+ var formSelectProps = property;
32
+ p.push((0, jsx_runtime_1.jsx)(PageFormSelectOption_1.PageFormSelectOption, { name: base + propertyName, label: title, placeholder: placeholder, isRequired: required, options: formSelectProps.options, footer: formSelectProps.footer }, base + propertyName));
33
+ }
34
+ else {
35
+ p.push((0, jsx_runtime_1.jsx)(PageFormTextSelect_1.FormTextSelect, { name: base + propertyName, label: title, placeholder: placeholder, required: required, selectTitle: property.selectTitle, selectValue: property.selectValue, selectOpen: property.selectOpen }, base + propertyName));
36
+ }
37
+ break;
38
+ }
39
+ case 'textarea':
40
+ p.push((0, jsx_runtime_1.jsx)(PageFormTextArea_1.PageFormTextArea, { name: base + propertyName, label: title, placeholder: placeholder, required: required }, base + propertyName));
41
+ break;
42
+ case 'secret':
43
+ p.push((0, jsx_runtime_1.jsx)(PageFormTextInput_1.PageFormTextInput, { name: base + propertyName, label: title, placeholder: placeholder, required: required, secret: true }, base + propertyName));
44
+ break;
45
+ default:
46
+ p.push((0, jsx_runtime_1.jsx)(PageFormTextInput_1.PageFormTextInput, { name: base + propertyName, label: title, placeholder: placeholder, required: required }, base + propertyName));
47
+ break;
48
+ }
49
+ break;
50
+ }
51
+ case 'number': {
52
+ p.push((0, jsx_runtime_1.jsx)(PageFormSlider_1.PageFormSlider, { name: base + propertyName, label: title, required: required, min: property.min, max: property.max, valueLabel: property.valueLabel }, base + propertyName));
53
+ break;
54
+ }
55
+ case 'boolean': {
56
+ p.push((0, jsx_runtime_1.jsx)(PageFormSwitch_1.PageFormSwitch, { name: base + propertyName, label: title, required: required }, base + propertyName));
57
+ break;
58
+ }
59
+ case 'object': {
60
+ p.push((0, jsx_runtime_1.jsx)(FormSchema, { schema: property, base: base + propertyName }, propertyName));
61
+ break;
62
+ }
63
+ }
64
+ }
65
+ return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: p });
66
+ }
67
+ exports.FormSchema = FormSchema;
@@ -0,0 +1,8 @@
1
+ export interface PageFormInputPopover {
2
+ title?: string;
3
+ body?: string[];
4
+ link?: {
5
+ label: string;
6
+ url: string;
7
+ };
8
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/cjs/index.d.ts CHANGED
@@ -24,8 +24,8 @@ export * from './PageCells/LabelsCell';
24
24
  export * from './PageCells/TextCell';
25
25
  export * from './PageDataList';
26
26
  export * from './PageDialog';
27
+ export * from './PageForm/Inputs/PageFormSelectOption';
27
28
  export * from './PageForm/PageForm';
28
- export * from './PageForm/PageFormSelectOption';
29
29
  export * from './PageFramework';
30
30
  export * from './PageHeader';
31
31
  export * from './PageLayout';
package/cjs/index.js CHANGED
@@ -40,8 +40,8 @@ __exportStar(require("./PageCells/LabelsCell"), exports);
40
40
  __exportStar(require("./PageCells/TextCell"), exports);
41
41
  __exportStar(require("./PageDataList"), exports);
42
42
  __exportStar(require("./PageDialog"), exports);
43
+ __exportStar(require("./PageForm/Inputs/PageFormSelectOption"), exports);
43
44
  __exportStar(require("./PageForm/PageForm"), exports);
44
- __exportStar(require("./PageForm/PageFormSelectOption"), exports);
45
45
  __exportStar(require("./PageFramework"), exports);
46
46
  __exportStar(require("./PageHeader"), exports);
47
47
  __exportStar(require("./PageLayout"), exports);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@ansible/ansible-ui-framework",
3
3
  "description": "A framework for building applications using PatternFly.",
4
- "version": "0.0.376",
4
+ "version": "0.0.377",
5
5
  "author": "Red Hat",
6
6
  "license": "MIT",
7
7
  "repository": {