@ansible/ansible-ui-framework 0.0.374 → 0.0.375

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.
@@ -2,7 +2,7 @@ import { JSONSchema6 } from 'json-schema';
2
2
  import { CSSProperties, ReactNode } from 'react';
3
3
  import { DeepPartial, ErrorOption, FieldPath, FieldValues, SubmitHandler, UseFormReturn } from 'react-hook-form';
4
4
  import { PartialDeep } from 'type-fest';
5
- import { PageHeaderProps } from './PageHeader';
5
+ import { PageHeaderProps } from '../PageHeader';
6
6
  export type FormPageProps<T extends object> = PageHeaderProps & {
7
7
  children?: ReactNode;
8
8
  defaultValues?: PartialDeep<T>;
@@ -38,10 +38,11 @@ var react_icons_1 = require("@patternfly/react-icons");
38
38
  var fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
39
39
  var react_1 = require("react");
40
40
  var react_hook_form_1 = require("react-hook-form");
41
- var Scrollable_1 = require("./components/Scrollable");
42
- var useBreakPoint_1 = require("./components/useBreakPoint");
43
- var PageHeader_1 = require("./PageHeader");
44
- var Settings_1 = require("./Settings");
41
+ var Scrollable_1 = require("../components/Scrollable");
42
+ var useBreakPoint_1 = require("../components/useBreakPoint");
43
+ var PageHeader_1 = require("../PageHeader");
44
+ var Settings_1 = require("../Settings");
45
+ var PageFormSelectOption_1 = require("./PageFormSelectOption");
45
46
  function FormPage(props) {
46
47
  // const methods = useForm<PartialDeep<T>>({
47
48
  // defaultValues: props.defaultValues,
@@ -110,9 +111,7 @@ function FormTextInput(props) {
110
111
  var _c = __read((0, react_1.useState)(false), 2), showSecret = _c[0], setShowSecret = _c[1];
111
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) {
112
113
  void registration.onChange(e);
113
- },
114
- // innerRef={registration.ref}
115
- 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, {}) })))] }) })));
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, {}) })))] }) })));
116
115
  }
117
116
  exports.FormTextInput = FormTextInput;
118
117
  function FormTextArea(props) {
@@ -204,7 +203,7 @@ function FormSelect(props) {
204
203
  setOpen(false);
205
204
  }, [field, options]);
206
205
  var index = 0;
207
- 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, 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 () {
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 () {
208
207
  var _a, _b;
209
208
  setOpen(false);
210
209
  (_b = (_a = props.footer) === null || _a === void 0 ? void 0 : _a.click) === null || _b === void 0 ? void 0 : _b.call(_a);
@@ -282,7 +281,7 @@ function FormSchema(props) {
282
281
  case 'select': {
283
282
  if ('options' in property) {
284
283
  var formSelectProps = property;
285
- p.push((0, jsx_runtime_1.jsx)(FormSelect, { name: base + propertyName, label: title, placeholder: placeholder, required: required, options: formSelectProps.options, footer: formSelectProps.footer }, base + propertyName));
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));
286
285
  }
287
286
  else {
288
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));
@@ -353,14 +352,10 @@ function PageForm(props) {
353
352
  flexGrow: 1,
354
353
  overflow: props.disableScrolling ? undefined : 'hidden',
355
354
  gap: 0,
356
- } }, { children: [props.disableScrolling ? ((0, jsx_runtime_1.jsx)(react_core_1.PageSection, __assign({ isFilled: true,
357
- // padding={{ default: props.onCancel ? 'padding' : 'noPadding' }}
358
- variant: "light", style: { maxWidth: maxWidth } }, { 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)(react_core_1.PageSection, __assign({ isFilled: true,
359
- // padding={{ default: props.onCancel ? 'padding' : 'noPadding' }}
360
- variant: "light", style: { maxWidth: maxWidth } }, { 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)(react_core_1.PageSection, __assign({ isFilled: false, style: {
361
- borderTop: 'thin solid var(--pf-global--BorderColor--100)',
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: {
362
356
  backgroundColor: settings.theme === 'dark' ? 'var(--pf-global--BackgroundColor--400)' : undefined,
363
- }, variant: "light" }, { 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 })))] })) }))
357
+ padding: 24,
358
+ } }, { 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 })))] })) }))
364
359
  // </PageBody>
365
360
  );
366
361
  }
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ import { PageSelectOptionProps } from '../components/PageSelectOption';
3
+ export type PageFormSelectOption<T> = {
4
+ name: string;
5
+ } & Omit<PageSelectOptionProps<T>, 'onSelect' | 'value'>;
6
+ /**
7
+ * A PageSelectOption for use in PageForms
8
+ */
9
+ export declare function PageFormSelectOption<T>(props: PageFormSelectOption<T>): JSX.Element;
@@ -0,0 +1,29 @@
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.PageFormSelectOption = void 0;
15
+ var jsx_runtime_1 = require("react/jsx-runtime");
16
+ var react_hook_form_1 = require("react-hook-form");
17
+ var PageSelectOption_1 = require("../components/PageSelectOption");
18
+ /**
19
+ * A PageSelectOption for use in PageForms
20
+ */
21
+ function PageFormSelectOption(props) {
22
+ var _a = (0, react_hook_form_1.useFormContext)(), control = _a.control, isSubmitting = _a.formState.isSubmitting;
23
+ var name = props.name;
24
+ return ((0, jsx_runtime_1.jsx)(react_hook_form_1.Controller, { name: name, control: control, render: function (_a) {
25
+ var _b = _a.field, onChange = _b.onChange, value = _b.value, error = _a.fieldState.error;
26
+ return ((0, jsx_runtime_1.jsx)(PageSelectOption_1.PageSelectOption, __assign({}, props, { value: value, onSelect: onChange, helperTextInvalid: error === null || error === void 0 ? void 0 : error.message, readOnly: isSubmitting })));
27
+ } }));
28
+ }
29
+ exports.PageFormSelectOption = PageFormSelectOption;
@@ -44,7 +44,7 @@ var react_core_1 = require("@patternfly/react-core");
44
44
  var react_icons_1 = require("@patternfly/react-icons");
45
45
  var react_1 = require("react");
46
46
  var BulkSelector_1 = require("./components/BulkSelector");
47
- var SingleSelect_1 = require("./components/SingleSelect");
47
+ var PageSelect_1 = require("./components/PageSelect");
48
48
  var useBreakPoint_1 = require("./components/useBreakPoint");
49
49
  var PageActions_1 = require("./PageActions/PageActions");
50
50
  var PageActionType_1 = require("./PageActions/PageActionType");
@@ -112,7 +112,7 @@ function PageTableToolbar(props) {
112
112
  paddingBottom: sm ? undefined : 8,
113
113
  paddingTop: sm ? undefined : 8,
114
114
  backgroundColor: settings.theme === 'dark' ? 'var(--pf-global--BackgroundColor--300)' : undefined,
115
- } }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.ToolbarContent, { children: [showSelect && ((0, jsx_runtime_1.jsx)(react_core_1.ToolbarGroup, { children: (0, jsx_runtime_1.jsx)(react_core_1.ToolbarItem, __assign({ variant: "bulk-select" }, { children: (0, jsx_runtime_1.jsx)(BulkSelector_1.BulkSelector, __assign({}, props)) })) })), toolbarFilters && toolbarFilters.length > 0 && ((0, jsx_runtime_1.jsx)(react_core_1.ToolbarToggleGroup, __assign({ toggleIcon: (0, jsx_runtime_1.jsx)(react_icons_1.FilterIcon, {}), breakpoint: "md", style: { zIndex: 302 } }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.ToolbarGroup, __assign({ variant: "filter-group" }, { children: [(0, jsx_runtime_1.jsx)(react_core_1.ToolbarItem, { children: (0, jsx_runtime_1.jsx)(SingleSelect_1.SingleSelect2, __assign({ onChange: setSeletedFilter, value: selectedFilter }, { children: toolbarFilters.map(function (filter) { return ((0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: filter.key }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.Flex, __assign({ spaceItems: { default: 'spaceItemsNone' }, alignItems: { default: 'alignItemsCenter' }, flexWrap: { default: 'nowrap' } }, { children: [(0, jsx_runtime_1.jsx)(react_core_1.FlexItem, __assign({ style: { paddingLeft: 4, paddingRight: 8 } }, { children: (0, jsx_runtime_1.jsx)(react_icons_1.FilterIcon, {}) })), (0, jsx_runtime_1.jsx)(react_core_1.FlexItem, { children: filter.label })] })) }), filter.key)); }) })) }), (0, jsx_runtime_1.jsx)(react_core_1.ToolbarItem, { children: (0, jsx_runtime_1.jsx)(ToolbarFilterInput, { filter: toolbarFilters.find(function (filter) { return filter.key === selectedFilter; }), addFilter: function (value) {
115
+ } }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.ToolbarContent, { children: [showSelect && ((0, jsx_runtime_1.jsx)(react_core_1.ToolbarGroup, { children: (0, jsx_runtime_1.jsx)(react_core_1.ToolbarItem, __assign({ variant: "bulk-select" }, { children: (0, jsx_runtime_1.jsx)(BulkSelector_1.BulkSelector, __assign({}, props)) })) })), toolbarFilters && toolbarFilters.length > 0 && ((0, jsx_runtime_1.jsx)(react_core_1.ToolbarToggleGroup, __assign({ toggleIcon: (0, jsx_runtime_1.jsx)(react_icons_1.FilterIcon, {}), breakpoint: "md", style: { zIndex: 302 } }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.ToolbarGroup, __assign({ variant: "filter-group" }, { children: [(0, jsx_runtime_1.jsx)(react_core_1.ToolbarItem, { children: (0, jsx_runtime_1.jsx)(PageSelect_1.PageSelect, __assign({ onSelect: setSeletedFilter, value: selectedFilter }, { children: toolbarFilters.map(function (filter) { return ((0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: filter.key }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.Flex, __assign({ spaceItems: { default: 'spaceItemsNone' }, alignItems: { default: 'alignItemsCenter' }, flexWrap: { default: 'nowrap' } }, { children: [(0, jsx_runtime_1.jsx)(react_core_1.FlexItem, __assign({ style: { paddingLeft: 4, paddingRight: 8 } }, { children: (0, jsx_runtime_1.jsx)(react_icons_1.FilterIcon, {}) })), (0, jsx_runtime_1.jsx)(react_core_1.FlexItem, { children: filter.label })] })) }), filter.key)); }) })) }), (0, jsx_runtime_1.jsx)(react_core_1.ToolbarItem, { children: (0, jsx_runtime_1.jsx)(ToolbarFilterInput, { filter: toolbarFilters.find(function (filter) { return filter.key === selectedFilter; }), addFilter: function (value) {
116
116
  var _a;
117
117
  var values = filters === null || filters === void 0 ? void 0 : filters[selectedFilter];
118
118
  if (!values)
package/cjs/Settings.js CHANGED
@@ -31,7 +31,7 @@ exports.SettingsDialog = exports.useSettingsDialog = exports.SettingsProvider =
31
31
  var jsx_runtime_1 = require("react/jsx-runtime");
32
32
  var react_core_1 = require("@patternfly/react-core");
33
33
  var react_1 = require("react");
34
- var SingleSelect_1 = require("./components/SingleSelect");
34
+ var PageSelect_1 = require("./components/PageSelect");
35
35
  var PageDialog_1 = require("./PageDialog");
36
36
  var useFrameworkTranslations_1 = require("./useFrameworkTranslations");
37
37
  exports.SettingsContext = (0, react_1.createContext)([
@@ -110,14 +110,14 @@ function SettingsDialog(props) {
110
110
  var _f = __read((0, useFrameworkTranslations_1.useFrameworkTranslations)(), 1), translations = _f[0];
111
111
  return ((0, jsx_runtime_1.jsx)(react_core_1.Modal, __assign({ title: "Settings", isOpen: props.open, onClose: onClose, variant: react_core_1.ModalVariant.medium, tabIndex: 0, actions: [
112
112
  (0, jsx_runtime_1.jsx)(react_core_1.Button, __assign({ variant: "primary", onClick: onClose }, { children: translations.closeText }), "close"),
113
- ] }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.Form, __assign({ isHorizontal: settings.formLayout === 'horizontal' }, { children: [(0, jsx_runtime_1.jsxs)(SingleSelect_1.SingleSelect, __assign({ label: "Theme", value: (_a = settings.theme) !== null && _a !== void 0 ? _a : 'system', onChange: function (theme) {
113
+ ] }, { children: (0, jsx_runtime_1.jsxs)(react_core_1.Form, __assign({ isHorizontal: settings.formLayout === 'horizontal' }, { children: [(0, jsx_runtime_1.jsxs)(PageSelect_1.PageSelect, __assign({ label: "Theme", value: (_a = settings.theme) !== null && _a !== void 0 ? _a : 'system', onSelect: function (theme) {
114
114
  return setSettings(__assign(__assign({}, settings), { theme: theme }));
115
- } }, { children: [(0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "system" }, { children: 'System default' })), (0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "light" }, { children: 'Light' })), (0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "dark" }, { children: 'Dark' }))] })), (0, jsx_runtime_1.jsxs)(SingleSelect_1.SingleSelect, __assign({ label: "Table Layout", value: (_b = settings.tableLayout) !== null && _b !== void 0 ? _b : 'comfortable', onChange: function (tableLayout) {
115
+ } }, { children: [(0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "system" }, { children: 'System default' })), (0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "light" }, { children: 'Light' })), (0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "dark" }, { children: 'Dark' }))] })), (0, jsx_runtime_1.jsxs)(PageSelect_1.PageSelect, __assign({ label: "Table Layout", value: (_b = settings.tableLayout) !== null && _b !== void 0 ? _b : 'comfortable', onSelect: function (tableLayout) {
116
116
  return setSettings(__assign(__assign({}, settings), { tableLayout: tableLayout }));
117
- } }, { children: [(0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "comfortable" }, { children: 'Comfortable' })), (0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "compact" }, { children: 'Compact' }))] })), (0, jsx_runtime_1.jsxs)(SingleSelect_1.SingleSelect, __assign({ label: "Form Columns", value: (_c = settings.formColumns) !== null && _c !== void 0 ? _c : 'multiple', onChange: function (formColumns) {
117
+ } }, { children: [(0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "comfortable" }, { children: 'Comfortable' })), (0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "compact" }, { children: 'Compact' }))] })), (0, jsx_runtime_1.jsxs)(PageSelect_1.PageSelect, __assign({ label: "Form Columns", value: (_c = settings.formColumns) !== null && _c !== void 0 ? _c : 'multiple', onSelect: function (formColumns) {
118
118
  return setSettings(__assign(__assign({}, settings), { formColumns: formColumns }));
119
- } }, { children: [(0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "multiple" }, { children: 'Multiple columns' })), (0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "single" }, { children: 'Single column' }))] })), (0, jsx_runtime_1.jsxs)(SingleSelect_1.SingleSelect, __assign({ label: "Form Layout", value: (_d = settings.formLayout) !== null && _d !== void 0 ? _d : 'vertical', onChange: function (formLayout) {
119
+ } }, { children: [(0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "multiple" }, { children: 'Multiple columns' })), (0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "single" }, { children: 'Single column' }))] })), (0, jsx_runtime_1.jsxs)(PageSelect_1.PageSelect, __assign({ label: "Form Layout", value: (_d = settings.formLayout) !== null && _d !== void 0 ? _d : 'vertical', onSelect: function (formLayout) {
120
120
  return setSettings(__assign(__assign({}, settings), { formLayout: formLayout }));
121
- } }, { children: [(0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "vertical" }, { children: 'Vertical labels' })), (0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "horizontal" }, { children: 'Horizontal labels' }))] })), (0, jsx_runtime_1.jsxs)(SingleSelect_1.SingleSelect, __assign({ label: "Borders", value: settings.borders ? 'true' : 'false', onChange: function (value) { return setSettings(__assign(__assign({}, settings), { borders: value === 'true' })); }, style: { paddingBottom: 120 } }, { children: [(0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "true" }, { children: 'Yes' })), (0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "false" }, { children: 'No' }))] }))] })) })));
121
+ } }, { children: [(0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "vertical" }, { children: 'Vertical labels' })), (0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "horizontal" }, { children: 'Horizontal labels' }))] })), (0, jsx_runtime_1.jsxs)(PageSelect_1.PageSelect, __assign({ label: "Borders", value: settings.borders ? 'true' : 'false', onSelect: function (value) { return setSettings(__assign(__assign({}, settings), { borders: value === 'true' })); } }, { children: [(0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "true" }, { children: 'Yes' })), (0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: "false" }, { children: 'No' }))] }))] })) })));
122
122
  }
123
123
  exports.SettingsDialog = SettingsDialog;
@@ -0,0 +1,11 @@
1
+ import { ReactNode } from 'react';
2
+ export type PageFormGroupProps = {
3
+ children: ReactNode;
4
+ helperText?: ReactNode | undefined;
5
+ helperTextInvalid?: ReactNode | undefined;
6
+ id?: string;
7
+ isRequired?: boolean;
8
+ label?: string;
9
+ };
10
+ /** Wrapper over the PatternFly FormGroup making it optional based on if label is given. */
11
+ export declare function PageFormGroup(props: PageFormGroupProps): 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.PageFormGroup = void 0;
15
+ var jsx_runtime_1 = require("react/jsx-runtime");
16
+ var react_core_1 = require("@patternfly/react-core");
17
+ /** Wrapper over the PatternFly FormGroup making it optional based on if label is given. */
18
+ function PageFormGroup(props) {
19
+ var _a;
20
+ var children = props.children, helperText = props.helperText, helperTextInvalid = props.helperTextInvalid, isRequired = props.isRequired, label = props.label;
21
+ if (!label) {
22
+ return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: props.children });
23
+ }
24
+ var id = (_a = props.id) !== null && _a !== void 0 ? _a : label === null || label === void 0 ? void 0 : label.toLocaleLowerCase().split(' ').join('-');
25
+ return ((0, jsx_runtime_1.jsx)(react_core_1.FormGroup, __assign({ fieldId: id, helperText: helperText, helperTextInvalid: helperTextInvalid, id: "".concat(id, "-form-group"), isRequired: isRequired, label: label, validated: helperTextInvalid ? 'error' : undefined }, { children: children })));
26
+ }
27
+ exports.PageFormGroup = PageFormGroup;
@@ -0,0 +1,16 @@
1
+ import React, { ChangeEvent, ReactNode } from 'react';
2
+ import { PageFormGroupProps } from './PageFormGroup';
3
+ export type PageSelectProps = {
4
+ footer?: ReactNode;
5
+ isCreatable?: boolean;
6
+ isGrouped?: boolean | undefined;
7
+ onSelect: (value: string, event: React.MouseEvent<Element, MouseEvent> | ChangeEvent<Element>) => void;
8
+ placeholder?: string;
9
+ value: string | undefined;
10
+ readOnly?: boolean;
11
+ } & PageFormGroupProps;
12
+ /** Wrapper over a PatternFly Select.
13
+ * Simplifies the PatternFly Select.
14
+ * Supports a PageFormGroup with label if label is specififed.
15
+ */
16
+ export declare function PageSelect(props: PageSelectProps): JSX.Element;
@@ -0,0 +1,54 @@
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.PageSelect = 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 PageFormGroup_1 = require("./PageFormGroup");
35
+ /** Wrapper over a PatternFly Select.
36
+ * Simplifies the PatternFly Select.
37
+ * Supports a PageFormGroup with label if label is specififed.
38
+ */
39
+ function PageSelect(props) {
40
+ var _a;
41
+ var children = props.children, footer = props.footer, helperTextInvalid = props.helperTextInvalid, isCreatable = props.isCreatable, isGrouped = props.isGrouped, isReadonly = props.readOnly, label = props.label, onSelect = props.onSelect, placeholder = props.placeholder, value = props.value;
42
+ var _b = __read((0, react_1.useState)(false), 2), open = _b[0], setOpen = _b[1];
43
+ var onToggle = (0, react_1.useCallback)(function () { return setOpen(function (open) { return !open; }); }, []);
44
+ var onSelectHandler = (0, react_1.useCallback)(function (event, value) {
45
+ if (typeof value === 'string')
46
+ onSelect(value, event);
47
+ else
48
+ onSelect(value.toString(), event);
49
+ setOpen(false);
50
+ }, [onSelect]);
51
+ var id = (_a = props.id) !== null && _a !== void 0 ? _a : label === null || label === void 0 ? void 0 : label.toLocaleLowerCase().split(' ').join('-');
52
+ return ((0, jsx_runtime_1.jsx)(PageFormGroup_1.PageFormGroup, __assign({}, props, { children: (0, jsx_runtime_1.jsx)(react_core_1.Select, __assign({ "aria-describedby": id ? "".concat(id, "-form-group") : undefined, footer: footer, id: id, isCreatable: isCreatable, isGrouped: isGrouped, isInputFilterPersisted: isCreatable, isOpen: open, maxHeight: 280, onSelect: onSelectHandler, onToggle: onToggle, placeholderText: placeholder, selections: value, validated: helperTextInvalid ? 'error' : undefined, variant: react_core_1.SelectVariant.single, isDisabled: isReadonly }, { children: children })) })));
53
+ }
54
+ exports.PageSelect = PageSelect;
@@ -0,0 +1,14 @@
1
+ import { ChangeEvent } from 'react';
2
+ import { PageSelectProps } from './PageSelect';
3
+ export interface IPageSelectOption<T> {
4
+ group?: string;
5
+ label: string;
6
+ description?: string;
7
+ value: T;
8
+ }
9
+ export type PageSelectOptionProps<T> = {
10
+ options: IPageSelectOption<T>[];
11
+ onSelect: (value: T | undefined, event: React.MouseEvent<Element, MouseEvent> | ChangeEvent<Element>) => void;
12
+ value: T | undefined;
13
+ } & Omit<PageSelectProps, 'onSelect' | 'value' | 'children'>;
14
+ export declare function PageSelectOption<T>(props: PageSelectOptionProps<T>): JSX.Element;
@@ -0,0 +1,56 @@
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.PageSelectOption = void 0;
15
+ var jsx_runtime_1 = require("react/jsx-runtime");
16
+ var react_core_1 = require("@patternfly/react-core");
17
+ var react_1 = require("react");
18
+ var PageSelect_1 = require("./PageSelect");
19
+ function PageSelectOption(props) {
20
+ var onSelect = props.onSelect, value = props.value;
21
+ var onSelectHandler = (0, react_1.useCallback)(function (label, event) {
22
+ var _a;
23
+ onSelect((_a = props.options.find(function (option) { return option.label === label; })) === null || _a === void 0 ? void 0 : _a.value, event);
24
+ }, [onSelect, props.options]);
25
+ var options = props.options;
26
+ options.sort(function (l, r) {
27
+ var _a, _b, _c, _d;
28
+ if (((_a = l.group) !== null && _a !== void 0 ? _a : '') < ((_b = r.group) !== null && _b !== void 0 ? _b : ''))
29
+ return -1;
30
+ if (((_c = l.group) !== null && _c !== void 0 ? _c : '') > ((_d = r.group) !== null && _d !== void 0 ? _d : ''))
31
+ return 1;
32
+ if (l.label < r.label)
33
+ return -1;
34
+ if (l.label > r.label)
35
+ return 1;
36
+ return 0;
37
+ });
38
+ var groups = options.reduce(function (groups, option) {
39
+ var _a;
40
+ var group = (_a = option.group) !== null && _a !== void 0 ? _a : '';
41
+ var optionsArray = groups[group];
42
+ if (!optionsArray) {
43
+ optionsArray = [];
44
+ groups[group] = optionsArray;
45
+ }
46
+ optionsArray.push(option);
47
+ return groups;
48
+ }, {});
49
+ var isGrouped = Object.keys(groups).length > 1 ||
50
+ (Object.keys(groups).length === 1 && Object.keys(groups)[0] !== '');
51
+ var selected = props.options.find(function (option) { return option.value === value; });
52
+ return ((0, jsx_runtime_1.jsx)(PageSelect_1.PageSelect, __assign({}, props, { value: selected === null || selected === void 0 ? void 0 : selected.label, onSelect: onSelectHandler, isGrouped: isGrouped }, { children: !isGrouped
53
+ ? options.map(function (option) { return ((0, jsx_runtime_1.jsx)(react_core_1.SelectOption, __assign({ value: option.label, label: option.label, description: option.description }, { children: option.label }), option.label)); })
54
+ : 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: option.label, label: option.label, description: option.description }, { children: option.label }), option.label)); }) }), group)); }) })));
55
+ }
56
+ exports.PageSelectOption = PageSelectOption;
@@ -1,4 +1,4 @@
1
- export declare function useOpen(props: {
1
+ export declare function useOpen(props?: {
2
2
  open?: boolean;
3
3
  setOpen?: (open: boolean) => void;
4
4
  }): [boolean, (open: boolean) => void, () => void];
@@ -19,14 +19,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
19
19
  exports.useOpen = void 0;
20
20
  var react_1 = require("react");
21
21
  function useOpen(props) {
22
- var _a = __read((0, react_1.useState)(function () { var _a; return (_a = props.open) !== null && _a !== void 0 ? _a : false; }), 2), open = _a[0], setOpenState = _a[1];
22
+ var _a = __read((0, react_1.useState)(function () { var _a; return (_a = props === null || props === void 0 ? void 0 : props.open) !== null && _a !== void 0 ? _a : false; }), 2), open = _a[0], setOpenState = _a[1];
23
23
  (0, react_1.useEffect)(function () {
24
- if (props.open !== undefined) {
25
- setOpenState(props.open);
24
+ if ((props === null || props === void 0 ? void 0 : props.open) !== undefined) {
25
+ setOpenState(props === null || props === void 0 ? void 0 : props.open);
26
26
  }
27
- }, [props.open, setOpenState]);
27
+ }, [props === null || props === void 0 ? void 0 : props.open, setOpenState]);
28
28
  var setOpen = (0, react_1.useCallback)(function (open) {
29
- props.setOpen ? props.setOpen(open) : setOpenState(open);
29
+ (props === null || props === void 0 ? void 0 : props.setOpen) ? props === null || props === void 0 ? void 0 : props.setOpen(open) : setOpenState(open);
30
30
  }, [props]);
31
31
  var onToggle = (0, react_1.useCallback)(function () {
32
32
  setOpen(!open);
package/cjs/index.d.ts CHANGED
@@ -12,6 +12,8 @@ export * from './components/Collapse';
12
12
  export * from './components/Details';
13
13
  export * from './components/Help';
14
14
  export * from './components/icons/RunningIcon';
15
+ export * from './components/PageSelect';
16
+ export * from './components/PageSelectOption';
15
17
  export * from './components/pfcolors';
16
18
  export * from './components/Scrollable';
17
19
  export * from './components/useBreakPoint';
@@ -22,7 +24,8 @@ export * from './PageAlertToaster';
22
24
  export * from './PageBody';
23
25
  export * from './PageDataList';
24
26
  export * from './PageDialog';
25
- export * from './PageForm';
27
+ export * from './PageForm/PageForm';
28
+ export * from './PageForm/PageFormSelectOption';
26
29
  export * from './PageFramework';
27
30
  export * from './PageHeader';
28
31
  export * from './PageLayout';
package/cjs/index.js CHANGED
@@ -28,6 +28,8 @@ __exportStar(require("./components/Collapse"), exports);
28
28
  __exportStar(require("./components/Details"), exports);
29
29
  __exportStar(require("./components/Help"), exports);
30
30
  __exportStar(require("./components/icons/RunningIcon"), exports);
31
+ __exportStar(require("./components/PageSelect"), exports);
32
+ __exportStar(require("./components/PageSelectOption"), exports);
31
33
  __exportStar(require("./components/pfcolors"), exports);
32
34
  __exportStar(require("./components/Scrollable"), exports);
33
35
  __exportStar(require("./components/useBreakPoint"), exports);
@@ -38,7 +40,8 @@ __exportStar(require("./PageAlertToaster"), exports);
38
40
  __exportStar(require("./PageBody"), exports);
39
41
  __exportStar(require("./PageDataList"), exports);
40
42
  __exportStar(require("./PageDialog"), exports);
41
- __exportStar(require("./PageForm"), exports);
43
+ __exportStar(require("./PageForm/PageForm"), exports);
44
+ __exportStar(require("./PageForm/PageFormSelectOption"), exports);
42
45
  __exportStar(require("./PageFramework"), exports);
43
46
  __exportStar(require("./PageHeader"), exports);
44
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.374",
4
+ "version": "0.0.375",
5
5
  "author": "Red Hat",
6
6
  "license": "MIT",
7
7
  "repository": {
@@ -1,18 +0,0 @@
1
- import { CSSProperties, ReactNode } from 'react';
2
- export declare function SingleSelect(props: {
3
- id?: string;
4
- label: string;
5
- value: string;
6
- onChange: (value: string) => void;
7
- children: ReactNode;
8
- style?: CSSProperties;
9
- open?: boolean;
10
- setOpen?: (open: boolean) => void;
11
- }): JSX.Element;
12
- export declare function SingleSelect2(props: {
13
- id?: string;
14
- children: ReactNode;
15
- value?: string;
16
- onChange: (value: string) => void;
17
- label?: string;
18
- }): JSX.Element;
@@ -1,70 +0,0 @@
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.SingleSelect2 = exports.SingleSelect = 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 useOpen_1 = require("./useOpen");
35
- function SingleSelect(props) {
36
- var _a;
37
- var onChange = props.onChange;
38
- var _b = __read((0, useOpen_1.useOpen)(props), 3), open = _b[0], setOpen = _b[1], onToggle = _b[2];
39
- var onSelect = (0, react_1.useCallback)(function (_e, v) {
40
- if (typeof v === 'string') {
41
- onChange(v);
42
- }
43
- else {
44
- onChange(v.toString());
45
- }
46
- setOpen(false);
47
- }, [onChange, setOpen]);
48
- var id = (_a = props.id) !== null && _a !== void 0 ? _a : props.label.toLocaleLowerCase().split(' ').join('-');
49
- return ((0, jsx_runtime_1.jsx)(react_core_1.FormGroup, __assign({ label: props.label, fieldId: id, style: props.style }, { children: (0, jsx_runtime_1.jsx)(react_core_1.Select, __assign({ id: id, selections: props.value, isOpen: open, onToggle: onToggle, onSelect: onSelect }, { children: props.children })) })));
50
- }
51
- exports.SingleSelect = SingleSelect;
52
- function SingleSelect2(props) {
53
- var onChange = props.onChange;
54
- var id = props.id;
55
- var _a = __read((0, react_1.useState)(false), 2), open = _a[0], setOpen = _a[1];
56
- var onToggle = (0, react_1.useCallback)(function () {
57
- setOpen(function (open) { return !open; });
58
- }, []);
59
- var onSelect = (0, react_1.useCallback)(function (_e, v) {
60
- if (typeof v === 'string') {
61
- onChange(v);
62
- }
63
- else {
64
- onChange(v.toString());
65
- }
66
- setOpen(false);
67
- }, [onChange]);
68
- return ((0, jsx_runtime_1.jsx)(react_core_1.Select, __assign({ id: id, selections: props.value, isOpen: open, onToggle: onToggle, onSelect: onSelect }, { children: props.children })));
69
- }
70
- exports.SingleSelect2 = SingleSelect2;