@ansible/ansible-ui-framework 0.0.424 → 0.0.426
Sign up to get free protection for your applications and to get access to all the features.
- package/cjs/PageForm/Inputs/FormGroupTextArea.d.ts +1 -1
- package/cjs/PageForm/Inputs/FormGroupTextInput.d.ts +4 -2
- package/cjs/PageForm/Inputs/FormGroupTextInput.js +7 -2
- package/cjs/PageForm/Inputs/PageFormGroup.d.ts +1 -1
- package/cjs/PageForm/Inputs/PageFormTextArea.d.ts +5 -0
- package/cjs/PageForm/Inputs/PageFormTextArea.js +27 -3
- package/cjs/PageForm/Inputs/PageFormTextInput.d.ts +10 -2
- package/cjs/PageForm/Inputs/PageFormTextInput.js +38 -8
- package/cjs/PageForm/Inputs/PageFormTextSelect.js +1 -3
- package/cjs/PageForm/PageForm.d.ts +1 -1
- package/cjs/PageForm/PageForm.js +6 -3
- package/cjs/utils/capitalize.d.ts +1 -0
- package/cjs/utils/capitalize.js +7 -0
- package/package.json +1 -1
@@ -1,6 +1,6 @@
|
|
1
1
|
/// <reference types="react" />
|
2
2
|
import { TextAreaProps } from '@patternfly/react-core';
|
3
3
|
import { PageFormGroupProps } from './PageFormGroup';
|
4
|
-
export type FormGroupTextAreaProps = Pick<TextAreaProps, 'placeholder' | 'value' | 'isDisabled' | 'isReadOnly' | 'isRequired' | 'validated' | 'onChange' | 'type' | 'aria-label'> & PageFormGroupProps;
|
4
|
+
export type FormGroupTextAreaProps = Pick<TextAreaProps, 'placeholder' | 'value' | 'isDisabled' | 'isReadOnly' | 'isRequired' | 'validated' | 'onChange' | 'type' | 'aria-label' | 'minLength' | 'maxLength'> & PageFormGroupProps;
|
5
5
|
/** A PatternFly FormGroup with a PatternFly TextArea */
|
6
6
|
export declare function FormGroupTextArea(props: FormGroupTextAreaProps): JSX.Element;
|
@@ -1,6 +1,8 @@
|
|
1
|
-
/// <reference types="react" />
|
2
1
|
import { TextInputProps } from '@patternfly/react-core';
|
2
|
+
import { ReactNode } from 'react';
|
3
3
|
import { PageFormGroupProps } from './PageFormGroup';
|
4
|
-
export type FormGroupTextInputProps = Pick<TextInputProps, 'placeholder' | 'value' | 'isDisabled' | 'isReadOnly' | 'isRequired' | 'validated' | 'onChange' | 'type' | 'aria-label' | 'autoComplete' | 'autoFocus'> & PageFormGroupProps
|
4
|
+
export type FormGroupTextInputProps = Pick<TextInputProps, 'placeholder' | 'value' | 'isDisabled' | 'isReadOnly' | 'isRequired' | 'validated' | 'onChange' | 'type' | 'aria-label' | 'autoComplete' | 'autoFocus' | 'innerRef' | 'minLength' | 'maxLength'> & PageFormGroupProps & {
|
5
|
+
children?: ReactNode;
|
6
|
+
};
|
5
7
|
/** A PatternFly FormGroup with a PatternFly TextInput */
|
6
8
|
export declare function FormGroupTextInput(props: FormGroupTextInputProps): JSX.Element;
|
@@ -47,7 +47,12 @@ var PageFormGroup_1 = require("./PageFormGroup");
|
|
47
47
|
/** A PatternFly FormGroup with a PatternFly TextInput */
|
48
48
|
function FormGroupTextInput(props) {
|
49
49
|
var _a = __read((0, react_1.useState)(false), 2), showSecret = _a[0], setShowSecret = _a[1];
|
50
|
-
var _helperTextInvalid = props.helperTextInvalid, textInputProps = __rest(props, ["helperTextInvalid"]);
|
51
|
-
|
50
|
+
var _helperTextInvalid = props.helperTextInvalid, _children = props.children, isReadOnly = props.isReadOnly, textInputProps = __rest(props, ["helperTextInvalid", "children", "isReadOnly"]);
|
51
|
+
var id = props.id
|
52
|
+
? props.id
|
53
|
+
: typeof props.label === 'string'
|
54
|
+
? props.label.toLowerCase().split(' ').join('-')
|
55
|
+
: undefined;
|
56
|
+
return ((0, jsx_runtime_1.jsx)(PageFormGroup_1.PageFormGroup, __assign({}, props, { id: id }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.InputGroup, { children: [(0, jsx_runtime_1.jsx)(react_core_1.TextInput, __assign({}, textInputProps, { id: id, label: undefined, "aria-describedby": id ? "".concat(id, "-form-group") : undefined, validated: props.helperTextInvalid ? 'error' : undefined, type: props.type === 'password' ? (showSecret ? 'text' : 'password') : props.type, readOnlyVariant: isReadOnly ? 'default' : undefined })), props.type === 'password' && ((0, jsx_runtime_1.jsx)(react_core_1.Button, __assign({ variant: "control", onClick: function () { return setShowSecret(!showSecret); }, isDisabled: props.isDisabled || props.isReadOnly }, { children: showSecret ? (0, jsx_runtime_1.jsx)(react_icons_1.EyeIcon, {}) : (0, jsx_runtime_1.jsx)(react_icons_1.EyeSlashIcon, {}) }))), props.children] }) })));
|
52
57
|
}
|
53
58
|
exports.FormGroupTextInput = FormGroupTextInput;
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import { FormGroupProps } from '@patternfly/react-core';
|
2
2
|
import { ReactNode } from 'react';
|
3
|
-
export type PageFormGroupProps = Pick<FormGroupProps, 'children' | '
|
3
|
+
export type PageFormGroupProps = Pick<FormGroupProps, 'children' | 'helperText' | 'helperTextInvalid' | 'isRequired' | 'label'> & {
|
4
4
|
id?: string;
|
5
5
|
labelHelpTitle?: string;
|
6
6
|
labelHelp?: ReactNode;
|
@@ -1,7 +1,12 @@
|
|
1
1
|
/// <reference types="react" />
|
2
|
+
import { Validate, ValidationRule } from 'react-hook-form';
|
2
3
|
import { FormGroupTextAreaProps } from './FormGroupTextArea';
|
3
4
|
export type PageFormTextAreaProps = {
|
4
5
|
name: string;
|
6
|
+
minLength?: number | ValidationRule<number>;
|
7
|
+
maxLength?: number | ValidationRule<number>;
|
8
|
+
pattern?: ValidationRule<RegExp>;
|
9
|
+
validate?: Validate<string> | Record<string, Validate<string>>;
|
5
10
|
} & Omit<FormGroupTextAreaProps, 'onChange' | 'value'>;
|
6
11
|
/** PatternFly TextArea wrapper for use with react-hook-form */
|
7
12
|
export declare function PageFormTextArea(props: PageFormTextAreaProps): JSX.Element;
|
@@ -14,13 +14,37 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
14
|
exports.PageFormTextArea = 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 capitalize_1 = require("../../utils/capitalize");
|
17
18
|
var FormGroupTextArea_1 = require("./FormGroupTextArea");
|
18
19
|
/** PatternFly TextArea wrapper for use with react-hook-form */
|
19
20
|
function PageFormTextArea(props) {
|
21
|
+
var name = props.name, label = props.label, isReadOnly = props.isReadOnly, isRequired = props.isRequired, minLength = props.minLength, maxLength = props.maxLength, pattern = props.pattern, validate = props.validate;
|
20
22
|
var _a = (0, react_hook_form_1.useFormContext)(), control = _a.control, isSubmitting = _a.formState.isSubmitting;
|
21
|
-
return ((0, jsx_runtime_1.jsx)(react_hook_form_1.Controller, { name:
|
22
|
-
var _b
|
23
|
-
|
23
|
+
return ((0, jsx_runtime_1.jsx)(react_hook_form_1.Controller, { name: name, control: control, render: function (_a) {
|
24
|
+
var _b;
|
25
|
+
var _c = _a.field, onChange = _c.onChange, value = _c.value, error = _a.fieldState.error;
|
26
|
+
return ((0, jsx_runtime_1.jsx)(FormGroupTextArea_1.FormGroupTextArea, __assign({}, props, { id: (_b = props.id) !== null && _b !== void 0 ? _b : name, value: value, onChange: onChange, helperTextInvalid: error === null || error === void 0 ? void 0 : error.message, isReadOnly: isReadOnly || isSubmitting, minLength: undefined, maxLength: undefined })));
|
27
|
+
}, rules: {
|
28
|
+
required: typeof label === 'string' && typeof isRequired === 'boolean'
|
29
|
+
? {
|
30
|
+
value: true,
|
31
|
+
message: "".concat((0, capitalize_1.capitalizeFirstLetter)(label.toLocaleLowerCase()), " is required."),
|
32
|
+
}
|
33
|
+
: isRequired,
|
34
|
+
minLength: typeof label === 'string' && typeof minLength === 'number'
|
35
|
+
? {
|
36
|
+
value: minLength,
|
37
|
+
message: "".concat((0, capitalize_1.capitalizeFirstLetter)(label.toLocaleLowerCase()), " must be at least ").concat(minLength, " characters."),
|
38
|
+
}
|
39
|
+
: minLength,
|
40
|
+
maxLength: typeof label === 'string' && typeof maxLength === 'number'
|
41
|
+
? {
|
42
|
+
value: maxLength,
|
43
|
+
message: "".concat((0, capitalize_1.capitalizeFirstLetter)(label.toLocaleLowerCase()), " cannot be greater than ").concat(maxLength, " characters."),
|
44
|
+
}
|
45
|
+
: maxLength,
|
46
|
+
pattern: pattern,
|
47
|
+
validate: validate,
|
24
48
|
} }));
|
25
49
|
}
|
26
50
|
exports.PageFormTextArea = PageFormTextArea;
|
@@ -1,7 +1,15 @@
|
|
1
1
|
/// <reference types="react" />
|
2
|
+
import { Validate, ValidationRule } from 'react-hook-form';
|
2
3
|
import { FormGroupTextInputProps } from './FormGroupTextInput';
|
3
|
-
export type PageFormTextInputProps = {
|
4
|
+
export type PageFormTextInputProps<T> = {
|
4
5
|
name: string;
|
6
|
+
minLength?: number | ValidationRule<number>;
|
7
|
+
maxLength?: number | ValidationRule<number>;
|
8
|
+
pattern?: ValidationRule<RegExp>;
|
9
|
+
validate?: Validate<string> | Record<string, Validate<string>>;
|
10
|
+
selectTitle?: string;
|
11
|
+
selectValue?: (item: T) => string | number;
|
12
|
+
selectOpen?: (callback: (item: T) => void, title: string) => void;
|
5
13
|
} & Omit<FormGroupTextInputProps, 'onChange' | 'value'>;
|
6
14
|
/** PatternFly TextInput wrapper for use with react-hook-form */
|
7
|
-
export declare function PageFormTextInput(props: PageFormTextInputProps): JSX.Element;
|
15
|
+
export declare function PageFormTextInput<T = unknown>(props: PageFormTextInputProps<T>): JSX.Element;
|
@@ -13,18 +13,48 @@ var __assign = (this && this.__assign) || function () {
|
|
13
13
|
Object.defineProperty(exports, "__esModule", { value: true });
|
14
14
|
exports.PageFormTextInput = void 0;
|
15
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");
|
16
18
|
var react_hook_form_1 = require("react-hook-form");
|
19
|
+
var capitalize_1 = require("../../utils/capitalize");
|
17
20
|
var FormGroupTextInput_1 = require("./FormGroupTextInput");
|
18
21
|
/** PatternFly TextInput wrapper for use with react-hook-form */
|
19
22
|
function PageFormTextInput(props) {
|
20
|
-
var
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
23
|
+
var label = props.label, name = props.name, isReadOnly = props.isReadOnly, isRequired = props.isRequired, minLength = props.minLength, maxLength = props.maxLength, pattern = props.pattern, validate = props.validate, selectTitle = props.selectTitle;
|
24
|
+
var _a = (0, react_hook_form_1.useFormContext)(), control = _a.control, setValue = _a.setValue, _b = _a.formState, isSubmitting = _b.isSubmitting, isValidating = _b.isValidating;
|
25
|
+
return ((0, jsx_runtime_1.jsx)(react_hook_form_1.Controller, { name: name, control: control, render: function (_a) {
|
26
|
+
var _b;
|
27
|
+
var _c = _a.field, onChange = _c.onChange, value = _c.value, error = _a.fieldState.error;
|
28
|
+
return ((0, jsx_runtime_1.jsx)(FormGroupTextInput_1.FormGroupTextInput, __assign({}, props, { id: (_b = props.id) !== null && _b !== void 0 ? _b : name.split('.').join('-'), value: value, onChange: onChange, helperTextInvalid: !(validate && isValidating) && (error === null || error === void 0 ? void 0 : error.message), isReadOnly: isReadOnly || isSubmitting, minLength: undefined, maxLength: undefined }, { children: selectTitle && ((0, jsx_runtime_1.jsx)(react_core_1.Button, __assign({ variant: "control", onClick: function () {
|
29
|
+
var _a;
|
30
|
+
return (_a = props.selectOpen) === null || _a === void 0 ? void 0 : _a.call(props, function (item) {
|
31
|
+
if (props.selectValue) {
|
32
|
+
var value_1 = props.selectValue(item);
|
33
|
+
setValue(name, value_1, { shouldValidate: true });
|
34
|
+
}
|
35
|
+
}, props.selectTitle);
|
36
|
+
}, "aria-label": "Options menu", isDisabled: isSubmitting }, { children: (0, jsx_runtime_1.jsx)(react_icons_1.SearchIcon, {}) }))) })));
|
37
|
+
}, rules: {
|
38
|
+
required: typeof label === 'string' && typeof isRequired === 'boolean'
|
39
|
+
? {
|
40
|
+
value: true,
|
41
|
+
message: "".concat((0, capitalize_1.capitalizeFirstLetter)(label.toLocaleLowerCase()), " is required."),
|
42
|
+
}
|
43
|
+
: isRequired,
|
44
|
+
minLength: typeof label === 'string' && typeof minLength === 'number'
|
45
|
+
? {
|
46
|
+
value: minLength,
|
47
|
+
message: "".concat((0, capitalize_1.capitalizeFirstLetter)(label.toLocaleLowerCase()), " must be at least ").concat(minLength, " characters."),
|
48
|
+
}
|
49
|
+
: minLength,
|
50
|
+
maxLength: typeof label === 'string' && typeof maxLength === 'number'
|
51
|
+
? {
|
52
|
+
value: maxLength,
|
53
|
+
message: "".concat((0, capitalize_1.capitalizeFirstLetter)(label.toLocaleLowerCase()), " cannot be greater than ").concat(maxLength, " characters."),
|
54
|
+
}
|
55
|
+
: maxLength,
|
56
|
+
pattern: pattern,
|
57
|
+
validate: validate,
|
28
58
|
} }));
|
29
59
|
}
|
30
60
|
exports.PageFormTextInput = PageFormTextInput;
|
@@ -25,9 +25,7 @@ function FormTextSelect(props) {
|
|
25
25
|
var error = fieldState.error;
|
26
26
|
var id = (_a = props.id) !== null && _a !== void 0 ? _a : props.name;
|
27
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
|
-
},
|
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) { return void registration.onChange(e); },
|
31
29
|
// innerRef={registration.ref}
|
32
30
|
isReadOnly: isSubmitting })), (0, jsx_runtime_1.jsx)(react_core_1.Button, __assign({ variant: "control", onClick: function () {
|
33
31
|
var _a;
|
@@ -6,7 +6,7 @@ export declare function PageForm<T extends object>(props: {
|
|
6
6
|
children?: ReactNode;
|
7
7
|
submitText: string;
|
8
8
|
onSubmit: PageFormSubmitHandler<T>;
|
9
|
-
cancelText
|
9
|
+
cancelText?: string;
|
10
10
|
onCancel?: () => void;
|
11
11
|
defaultValue?: DeepPartial<T>;
|
12
12
|
isVertical?: boolean;
|
package/cjs/PageForm/PageForm.js
CHANGED
@@ -72,8 +72,10 @@ var react_hook_form_1 = require("react-hook-form");
|
|
72
72
|
var Scrollable_1 = require("../components/Scrollable");
|
73
73
|
var useBreakPoint_1 = require("../components/useBreakPoint");
|
74
74
|
var Settings_1 = require("../Settings");
|
75
|
+
var useFrameworkTranslations_1 = require("../useFrameworkTranslations");
|
75
76
|
function PageForm(props) {
|
76
77
|
var _this = this;
|
78
|
+
var _a;
|
77
79
|
var schema = props.schema, defaultValue = props.defaultValue;
|
78
80
|
var form = (0, react_hook_form_1.useForm)({
|
79
81
|
defaultValues: defaultValue !== null && defaultValue !== void 0 ? defaultValue : {},
|
@@ -81,10 +83,11 @@ function PageForm(props) {
|
|
81
83
|
? (0, ajv_1.ajvResolver)(schema, { strict: false, addFormats: true })
|
82
84
|
: undefined,
|
83
85
|
});
|
86
|
+
var _b = __read((0, useFrameworkTranslations_1.useFrameworkTranslations)(), 1), frameworkTranslations = _b[0];
|
84
87
|
var handleSubmit = form.handleSubmit, setFieldError = form.setError;
|
85
|
-
var
|
88
|
+
var _c = __read((0, react_1.useState)(''), 2), error = _c[0], setError = _c[1];
|
86
89
|
var isMd = (0, useBreakPoint_1.useBreakpoint)('md');
|
87
|
-
var
|
90
|
+
var _d = __read((0, react_1.useContext)(Settings_1.SettingsContext), 1), settings = _d[0];
|
88
91
|
var isHorizontal = props.isVertical ? false : settings.formLayout === 'horizontal';
|
89
92
|
var multipleColumns = props.singleColumn ? false : settings.formColumns === 'multiple';
|
90
93
|
var sm = multipleColumns ? (isHorizontal ? 12 : 12) : 12;
|
@@ -128,7 +131,7 @@ function PageForm(props) {
|
|
128
131
|
} }, { children: [props.disableScrolling ? ((0, jsx_runtime_1.jsx)("div", __assign({ style: { maxWidth: maxWidth, padding: 24 } }, { children: (0, jsx_runtime_1.jsx)(react_core_1.Grid, __assign({ hasGutter: true, span: 12, sm: sm, md: md, lg: lg, xl: xl, xl2: xl2 }, { children: 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.jsx)(react_core_1.Grid, __assign({ hasGutter: true, span: 12, sm: sm, md: md, lg: lg, xl: xl, xl2: xl2 }, { children: 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: {
|
129
132
|
backgroundColor: settings.theme === 'dark' ? 'var(--pf-global--BackgroundColor--400)' : undefined,
|
130
133
|
padding: 24,
|
131
|
-
} }, { 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 })))] })) }))
|
134
|
+
} }, { 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: (_a = props.cancelText) !== null && _a !== void 0 ? _a : frameworkTranslations.cancelText })))] })) }))) : ((0, jsx_runtime_1.jsx)(PageFormSubmitButton, __assign({ style: { marginTop: 48 } }, { children: props.submitText })))] })) }))
|
132
135
|
// </PageBody>
|
133
136
|
);
|
134
137
|
}
|
@@ -0,0 +1 @@
|
|
1
|
+
export declare function capitalizeFirstLetter(text: string): string;
|
@@ -0,0 +1,7 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.capitalizeFirstLetter = void 0;
|
4
|
+
function capitalizeFirstLetter(text) {
|
5
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
6
|
+
}
|
7
|
+
exports.capitalizeFirstLetter = capitalizeFirstLetter;
|