@ansible/ansible-ui-framework 0.0.190

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. package/LICENSE +21 -0
  2. package/cjs/framework/BulkActionDialog.js +217 -0
  3. package/cjs/framework/BulkProgressDialog.js +240 -0
  4. package/cjs/framework/FilterDrawer.js +64 -0
  5. package/cjs/framework/PageBody.js +47 -0
  6. package/cjs/framework/PageCatalog.js +178 -0
  7. package/cjs/framework/PageCells.js +141 -0
  8. package/cjs/framework/PageColumnModal.js +130 -0
  9. package/cjs/framework/PageDataList.js +61 -0
  10. package/cjs/framework/PageDialog.js +28 -0
  11. package/cjs/framework/PageForm.js +376 -0
  12. package/cjs/framework/PageFramework.js +11 -0
  13. package/cjs/framework/PageHeader.js +96 -0
  14. package/cjs/framework/PageLayout.js +41 -0
  15. package/cjs/framework/PagePagination.js +28 -0
  16. package/cjs/framework/PageTable.js +205 -0
  17. package/cjs/framework/PageTabs.js +82 -0
  18. package/cjs/framework/PageToolbar.js +209 -0
  19. package/cjs/framework/Settings.js +122 -0
  20. package/cjs/framework/TypedActions.js +303 -0
  21. package/cjs/framework/components/BulkSelector.js +89 -0
  22. package/cjs/framework/components/Collapse.js +22 -0
  23. package/cjs/framework/components/DetailInfo.js +23 -0
  24. package/cjs/framework/components/Details.js +88 -0
  25. package/cjs/framework/components/Dotted.js +19 -0
  26. package/cjs/framework/components/DropdownControlled.js +28 -0
  27. package/cjs/framework/components/ErrorBoundary.js +45 -0
  28. package/cjs/framework/components/Grid.js +64 -0
  29. package/cjs/framework/components/Help.js +24 -0
  30. package/cjs/framework/components/IconWrapper.js +55 -0
  31. package/cjs/framework/components/LoadingPage.js +14 -0
  32. package/cjs/framework/components/Masonry.js +113 -0
  33. package/cjs/framework/components/Scrollable.js +87 -0
  34. package/cjs/framework/components/SingleSelect.js +70 -0
  35. package/cjs/framework/components/patternfly-colors.js +32 -0
  36. package/cjs/framework/components/useBreakPoint.js +145 -0
  37. package/cjs/framework/components/useOpen.js +36 -0
  38. package/cjs/framework/components/useWindowLocation.js +70 -0
  39. package/cjs/framework/index.js +39 -0
  40. package/cjs/framework/useFrameworkTranslations.js +38 -0
  41. package/cjs/framework/useSelectDialog.js +81 -0
  42. package/cjs/framework/useSelectMultipleDialog.js +62 -0
  43. package/cjs/framework/useTableItems.js +485 -0
  44. package/cjs/framework/useView.js +155 -0
  45. package/cjs/framework/utils/compare.js +59 -0
  46. package/cjs/framework/utils/download-file.js +23 -0
  47. package/cjs/framework/utils/random-string.js +17 -0
  48. package/cjs/frontend/controller/access/organizations/Organization.js +2 -0
  49. package/mjs/framework/BulkActionDialog.d.ts +25 -0
  50. package/mjs/framework/BulkActionDialog.js +104 -0
  51. package/mjs/framework/BulkProgressDialog.d.ts +20 -0
  52. package/mjs/framework/BulkProgressDialog.js +131 -0
  53. package/mjs/framework/FilterDrawer.d.ts +8 -0
  54. package/mjs/framework/FilterDrawer.js +24 -0
  55. package/mjs/framework/PageBody.d.ts +4 -0
  56. package/mjs/framework/PageBody.js +29 -0
  57. package/mjs/framework/PageCatalog.d.ts +113 -0
  58. package/mjs/framework/PageCatalog.js +140 -0
  59. package/mjs/framework/PageCells.d.ts +35 -0
  60. package/mjs/framework/PageCells.js +102 -0
  61. package/mjs/framework/PageColumnModal.d.ts +7 -0
  62. package/mjs/framework/PageColumnModal.js +64 -0
  63. package/mjs/framework/PageDataList.d.ts +46 -0
  64. package/mjs/framework/PageDataList.js +45 -0
  65. package/mjs/framework/PageDialog.d.ts +10 -0
  66. package/mjs/framework/PageDialog.js +12 -0
  67. package/mjs/framework/PageForm.d.ts +147 -0
  68. package/mjs/framework/PageForm.js +316 -0
  69. package/mjs/framework/PageFramework.d.ts +4 -0
  70. package/mjs/framework/PageFramework.js +7 -0
  71. package/mjs/framework/PageHeader.d.ts +45 -0
  72. package/mjs/framework/PageHeader.js +80 -0
  73. package/mjs/framework/PageLayout.d.ts +15 -0
  74. package/mjs/framework/PageLayout.js +23 -0
  75. package/mjs/framework/PagePagination.d.ts +10 -0
  76. package/mjs/framework/PagePagination.js +22 -0
  77. package/mjs/framework/PageTable.d.ts +68 -0
  78. package/mjs/framework/PageTable.js +170 -0
  79. package/mjs/framework/PageTabs.d.ts +15 -0
  80. package/mjs/framework/PageTabs.js +45 -0
  81. package/mjs/framework/PageToolbar.d.ts +57 -0
  82. package/mjs/framework/PageToolbar.js +148 -0
  83. package/mjs/framework/Settings.d.ts +19 -0
  84. package/mjs/framework/Settings.js +87 -0
  85. package/mjs/framework/TypedActions.d.ts +80 -0
  86. package/mjs/framework/TypedActions.js +251 -0
  87. package/mjs/framework/components/BulkSelector.d.ts +11 -0
  88. package/mjs/framework/components/BulkSelector.js +56 -0
  89. package/mjs/framework/components/Collapse.d.ts +5 -0
  90. package/mjs/framework/components/Collapse.js +7 -0
  91. package/mjs/framework/components/DetailInfo.d.ts +5 -0
  92. package/mjs/framework/components/DetailInfo.js +8 -0
  93. package/mjs/framework/components/Details.d.ts +38 -0
  94. package/mjs/framework/components/Details.js +68 -0
  95. package/mjs/framework/components/Dotted.d.ts +4 -0
  96. package/mjs/framework/components/Dotted.js +4 -0
  97. package/mjs/framework/components/DropdownControlled.d.ts +4 -0
  98. package/mjs/framework/components/DropdownControlled.js +8 -0
  99. package/mjs/framework/components/ErrorBoundary.d.ts +15 -0
  100. package/mjs/framework/components/ErrorBoundary.js +25 -0
  101. package/mjs/framework/components/Grid.d.ts +6 -0
  102. package/mjs/framework/components/Grid.js +27 -0
  103. package/mjs/framework/components/Help.d.ts +5 -0
  104. package/mjs/framework/components/Help.js +9 -0
  105. package/mjs/framework/components/IconWrapper.d.ts +8 -0
  106. package/mjs/framework/components/IconWrapper.js +40 -0
  107. package/mjs/framework/components/LoadingPage.d.ts +6 -0
  108. package/mjs/framework/components/LoadingPage.js +9 -0
  109. package/mjs/framework/components/Masonry.d.ts +6 -0
  110. package/mjs/framework/components/Masonry.js +69 -0
  111. package/mjs/framework/components/Scrollable.d.ts +7 -0
  112. package/mjs/framework/components/Scrollable.js +60 -0
  113. package/mjs/framework/components/SingleSelect.d.ts +18 -0
  114. package/mjs/framework/components/SingleSelect.js +37 -0
  115. package/mjs/framework/components/patternfly-colors.d.ts +13 -0
  116. package/mjs/framework/components/patternfly-colors.js +28 -0
  117. package/mjs/framework/components/useBreakPoint.d.ts +5 -0
  118. package/mjs/framework/components/useBreakPoint.js +118 -0
  119. package/mjs/framework/components/useOpen.d.ts +4 -0
  120. package/mjs/framework/components/useOpen.js +16 -0
  121. package/mjs/framework/components/useWindowLocation.d.ts +6 -0
  122. package/mjs/framework/components/useWindowLocation.js +48 -0
  123. package/mjs/framework/index.d.ts +23 -0
  124. package/mjs/framework/index.js +23 -0
  125. package/mjs/framework/useFrameworkTranslations.d.ts +17 -0
  126. package/mjs/framework/useFrameworkTranslations.js +22 -0
  127. package/mjs/framework/useSelectDialog.d.ts +30 -0
  128. package/mjs/framework/useSelectDialog.js +49 -0
  129. package/mjs/framework/useSelectMultipleDialog.d.ts +21 -0
  130. package/mjs/framework/useSelectMultipleDialog.js +29 -0
  131. package/mjs/framework/useTableItems.d.ts +76 -0
  132. package/mjs/framework/useTableItems.js +371 -0
  133. package/mjs/framework/useView.d.ts +15 -0
  134. package/mjs/framework/useView.js +108 -0
  135. package/mjs/framework/utils/compare.d.ts +3 -0
  136. package/mjs/framework/utils/compare.js +53 -0
  137. package/mjs/framework/utils/download-file.d.ts +2 -0
  138. package/mjs/framework/utils/download-file.js +18 -0
  139. package/mjs/framework/utils/random-string.d.ts +1 -0
  140. package/mjs/framework/utils/random-string.js +12 -0
  141. package/mjs/frontend/controller/access/organizations/Organization.d.ts +44 -0
  142. package/mjs/frontend/controller/access/organizations/Organization.js +1 -0
  143. package/package.json +39 -0
@@ -0,0 +1,35 @@
1
+ import { ReactNode } from 'react';
2
+ import { PatternFlyColor } from './components/patternfly-colors';
3
+ export declare function LabelsCell(props: {
4
+ labels: string[];
5
+ }): JSX.Element;
6
+ export declare function DateCell(props: {
7
+ value: number | string;
8
+ }): JSX.Element;
9
+ export declare function TextCell(props: {
10
+ icon?: ReactNode;
11
+ text?: string;
12
+ iconSize?: 'sm' | 'md' | 'lg';
13
+ to?: string;
14
+ onClick?: () => void;
15
+ textColor?: PatternFlyColor;
16
+ }): JSX.Element;
17
+ export declare function CopyCell(props: {
18
+ text?: string;
19
+ minWidth?: number;
20
+ }): JSX.Element;
21
+ export declare function SinceCell(props: {
22
+ value: string | undefined | null;
23
+ author?: string;
24
+ onClick?: () => void;
25
+ t?: (t: string) => string;
26
+ }): JSX.Element;
27
+ export declare function CapacityCell(props: {
28
+ format?: string;
29
+ used: number;
30
+ capacity: number;
31
+ }): JSX.Element;
32
+ export declare function BytesCell(props: {
33
+ bytes: number;
34
+ decimals?: number;
35
+ }): JSX.Element;
@@ -0,0 +1,102 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Button, ClipboardCopy, Flex, FlexItem, Label, LabelGroup, Split, SplitItem, Tooltip, Truncate, } from '@patternfly/react-core';
3
+ import { DateTime } from 'luxon';
4
+ import { useEffect, useState } from 'react';
5
+ import { useTranslation } from 'react-i18next';
6
+ import { Link } from 'react-router-dom';
7
+ import { IconWrapper } from './components/IconWrapper';
8
+ import { getPatternflyColor } from './components/patternfly-colors';
9
+ import { useSettings } from './Settings';
10
+ export function LabelsCell(props) {
11
+ return (_jsx(LabelGroup, { numLabels: 999, style: { flexWrap: 'nowrap' }, children: props.labels.map((label) => (_jsx(Label, { children: label }, label))) }));
12
+ }
13
+ export function DateCell(props) {
14
+ const date = new Date(props.value);
15
+ return (_jsxs(Split, { hasGutter: true, children: [_jsx(SplitItem, { children: date.toLocaleDateString() }), _jsx(SplitItem, { children: date.toLocaleTimeString() })] }));
16
+ }
17
+ export function TextCell(props) {
18
+ return (_jsxs(Split, { children: [props.icon && (_jsx(SplitItem, { children: _jsx(IconWrapper, { size: props.iconSize ?? 'md', children: props.icon }) })), props.to ? (_jsx(SplitItem, { children: _jsx(Tooltip, { content: props.text ?? '', children: _jsx("div", { style: {
19
+ maxWidth: 300,
20
+ whiteSpace: 'nowrap',
21
+ textOverflow: 'ellipsis',
22
+ overflow: 'hidden',
23
+ }, children: _jsx(Link, { to: props.to, children: props.text ?? '' }) }) }) })) : props.onClick !== undefined ? (_jsx(SplitItem, { onClick: props.onClick, children: _jsx(Button, { variant: "link", isInline: true, style: {
24
+ whiteSpace: 'nowrap',
25
+ }, children: props.text }) })) : (_jsx(SplitItem, { style: {
26
+ color: props.textColor ? getPatternflyColor(props.textColor) : undefined,
27
+ }, children: _jsx(Tooltip, { content: props.text ?? '', children: _jsx("div", { style: {
28
+ maxWidth: 300,
29
+ whiteSpace: 'nowrap',
30
+ textOverflow: 'ellipsis',
31
+ overflow: 'hidden',
32
+ }, children: props.text ?? '' }) }) }))] }));
33
+ }
34
+ export function CopyCell(props) {
35
+ if (!props.text)
36
+ return _jsx(_Fragment, {});
37
+ return (_jsx(ClipboardCopy, { hoverTip: "Copy", clickTip: "Copied", variant: "inline-compact", style: { display: 'flex', flexWrap: 'nowrap', borderRadius: 4 }, onCopy: () => {
38
+ void navigator.clipboard.writeText(props.text ?? '');
39
+ }, children: _jsx(Truncate, { content: props.text, style: { minWidth: props.minWidth } }) }));
40
+ }
41
+ export function SinceCell(props) {
42
+ let { t } = props;
43
+ t = t ? t : (t) => t;
44
+ const { author, onClick } = props;
45
+ const [dateTime, setDateTime] = useState(null);
46
+ useEffect(() => {
47
+ if (props.value) {
48
+ setDateTime(DateTime.fromISO(props.value).toRelative());
49
+ }
50
+ const timeout = setInterval(() => {
51
+ if (props.value) {
52
+ setDateTime(DateTime.fromISO(props.value).toRelative());
53
+ }
54
+ }, 1000);
55
+ return () => clearTimeout(timeout);
56
+ }, [props.value]);
57
+ if (props.value === undefined)
58
+ return _jsx(_Fragment, {});
59
+ return (_jsxs("span", { style: { whiteSpace: 'nowrap' }, children: [dateTime, author && _jsxs("span", { children: ["\u00A0", t('by'), "\u00A0"] }), onClick ? (_jsx(Button, { variant: "link", isInline: true, onClick: onClick, children: author })) : (_jsx("span", { children: author }))] }));
60
+ }
61
+ export function CapacityCell(props) {
62
+ const { t } = useTranslation();
63
+ const settings = useSettings();
64
+ const ratio = props.used / props.capacity;
65
+ if (props.capacity === 0)
66
+ return _jsx(_Fragment, {});
67
+ const base = ratio >= 0.8
68
+ ? 'var(--pf-global--palette--red'
69
+ : ratio >= 0.5
70
+ ? 'var(--pf-global--palette--gold'
71
+ : 'var(--pf-global--palette--green';
72
+ const color1 = settings.theme === 'light' ? `${base}-100)` : `${base}-600)`;
73
+ const color2 = settings.theme === 'light' ? `${base}-400)` : `${base}-200)`;
74
+ const borderColor = settings.theme === 'light' ? `#0002` : `#fff2`;
75
+ return (_jsxs(Flex, { alignItems: { default: 'alignItemsBaseline' }, spaceItems: { default: 'spaceItemsSm' }, children: [props.capacity > 0 && (_jsx(FlexItem, { children: _jsx("div", { style: {
76
+ width: 18,
77
+ height: 25,
78
+ background: color1,
79
+ marginBottom: -9,
80
+ paddingTop: Math.max(0, Math.min(25, (25 * (props.capacity - props.used)) / props.capacity)),
81
+ borderRadius: 2,
82
+ border: `thin solid ${borderColor}`,
83
+ }, children: _jsx("div", { style: {
84
+ width: '100%',
85
+ height: '100%',
86
+ background: color2,
87
+ borderRadius: 2,
88
+ } }) }) })), props.format ? (_jsx(FlexItem, { children: props.format
89
+ .replace('{used}', props.used.toString())
90
+ .replace('{capacity}', props.capacity.toString()) })) : (_jsxs(FlexItem, { children: [props.used, t(' of '), props.capacity] }))] }));
91
+ }
92
+ export function BytesCell(props) {
93
+ const { bytes } = props;
94
+ if (!+bytes)
95
+ return _jsx(_Fragment, {});
96
+ const k = 1024;
97
+ const decimals = props.decimals ? props.decimals : 0;
98
+ const dm = decimals < 0 ? 0 : decimals;
99
+ const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
100
+ const i = Math.floor(Math.log(bytes) / Math.log(k));
101
+ return _jsx(_Fragment, { children: `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}` });
102
+ }
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { ITableColumn } from './PageTable';
3
+ export declare function useColumnModal<T extends object>(columns: ITableColumn<T>[], t?: (t: string) => string): {
4
+ openColumnModal: () => void;
5
+ columnModal: JSX.Element;
6
+ managedColumns: ITableColumn<T>[];
7
+ };
@@ -0,0 +1,64 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button, DataList, DataListCell, DataListCheck, DataListControl, DataListDragButton, DataListItem, DataListItemCells, DataListItemRow, Modal, ModalVariant, } from '@patternfly/react-core';
3
+ import { useCallback, useEffect, useState } from 'react';
4
+ export function useColumnModal(columns, t) {
5
+ t = t ? t : (t) => t;
6
+ const [columnModalOpen, setColumnModalOpen] = useState(false);
7
+ const openColumnModal = useCallback(() => {
8
+ setColumnModalOpen(true);
9
+ }, []);
10
+ const [managedColumns, setManagedColumns] = useState(() => columns);
11
+ useEffect(() => {
12
+ setManagedColumns((managedColumns) => managedColumns.map((managedColumn) => columns.find((column) => column.header === managedColumn.header) ?? managedColumn));
13
+ }, [columns]);
14
+ const onClose = useCallback(() => {
15
+ setColumnModalOpen(false);
16
+ }, []);
17
+ // const selectAllColumns = useCallback(() => {
18
+ // setManagedColumns((managedColumns) => {
19
+ // for (const column of managedColumns) {
20
+ // column.enabled = true
21
+ // }
22
+ // return [...managedColumns]
23
+ // })
24
+ // }, [])
25
+ const onDragFinish = useCallback((itemOrder) => {
26
+ setManagedColumns((managedColumns) => {
27
+ return itemOrder.map((header) => managedColumns.find((column) => column.header === header));
28
+ });
29
+ }, []);
30
+ const handleChange = useCallback((checked, event) => {
31
+ const columnHeader = event.target.name;
32
+ if (columnHeader) {
33
+ setManagedColumns((managedColumns) => {
34
+ for (const column of managedColumns) {
35
+ if (column.header !== columnHeader)
36
+ continue;
37
+ column.enabled = checked;
38
+ }
39
+ return [...managedColumns];
40
+ });
41
+ }
42
+ }, []);
43
+ const columnModal = (_jsx(Modal, { variant: ModalVariant.medium, title: "Manage columns",
44
+ // description={
45
+ // <TextContent>
46
+ // <Text component={TextVariants.p}>Selected categories will be displayed in the table.</Text>
47
+ // <Button isInline onClick={selectAllColumns} variant="link">
48
+ // Select all
49
+ // </Button>
50
+ // </TextContent>
51
+ // }
52
+ isOpen: columnModalOpen, onClose: onClose, actions: [
53
+ _jsx(Button, { variant: "primary", onClick: onClose, children: t('Close') }, "save"),
54
+ // <Button key="cancel" variant="link" onClick={onClose}>
55
+ // Cancel
56
+ // </Button>,
57
+ ], children: _jsx(DataList, { "aria-label": "Table column management", id: "table-column-management", isCompact: true, onDragFinish: onDragFinish, itemOrder: managedColumns.map((column) => column.header), gridBreakpoint: "none", style: { borderTopWidth: 'thin' }, children: managedColumns.map((column) => {
58
+ // if (index === 0) return <Fragment />
59
+ return (_jsx(DataListItem, { id: column.header, "aria-labelledby": "table-column-management-item1", style: { borderBottomWidth: 'thin' }, children: _jsxs(DataListItemRow, { children: [_jsxs(DataListControl, { children: [_jsx(DataListDragButton, { "aria-label": "Reorder", "aria-labelledby": "table-column-management-item1", "aria-describedby": "Press space or enter to begin dragging, and use the arrow keys to navigate up or down. Press enter to confirm the drag, or any other key to cancel the drag operation.", "aria-pressed": "false" }), _jsx(DataListCheck, { "aria-labelledby": "table-column-management-item1", checked: column.enabled !== false, name: column.header, id: column.header, onChange: handleChange, otherControls: true })] }), _jsx(DataListItemCells, { dataListCells: [
60
+ _jsx(DataListCell, { id: "table-column-management-item1", children: _jsx("label", { htmlFor: column.header, children: column.header }) }, column.header),
61
+ ] })] }) }, column.header));
62
+ }) }) }));
63
+ return { openColumnModal, columnModal, managedColumns };
64
+ }
@@ -0,0 +1,46 @@
1
+ import { Dispatch, ReactNode, SetStateAction } from 'react';
2
+ import { PageHeaderProps } from './PageHeader';
3
+ import { IToolbarFilter } from './PageToolbar';
4
+ import { ITypedAction } from './TypedActions';
5
+ export declare type DataListPageProps<T extends object> = PageHeaderProps & PageDataListProps<T> & {
6
+ error?: Error;
7
+ };
8
+ export declare function DataListPage<T extends object>(props: DataListPageProps<T>): JSX.Element;
9
+ export declare type PageDataListProps<T extends object> = {
10
+ keyFn: (item: T) => string | number;
11
+ itemCount?: number;
12
+ pageItems: T[] | undefined;
13
+ toolbarActions?: ITypedAction<T>[];
14
+ dataCells: ((item: T) => ReactNode)[];
15
+ actions: ITypedAction<T>[];
16
+ toolbarFilters?: IToolbarFilter[];
17
+ filters?: Record<string, string[]>;
18
+ setFilters?: Dispatch<SetStateAction<Record<string, string[]>>>;
19
+ clearAllFilters?: () => void;
20
+ sort?: string;
21
+ setSort?: (sort: string) => void;
22
+ sortDirection?: 'asc' | 'desc';
23
+ setSortDirection?: (sortDirection: 'asc' | 'desc') => void;
24
+ compact?: boolean;
25
+ page: number;
26
+ perPage: number;
27
+ setPage: (page: number) => void;
28
+ setPerPage: (perPage: number) => void;
29
+ autoHidePagination?: boolean;
30
+ isSelected?: (item: T) => boolean;
31
+ selectedItems?: T[];
32
+ selectItem?: (item: T) => void;
33
+ unselectItem?: (item: T) => void;
34
+ selectItems?: (items: T[]) => void;
35
+ unselectAll?: () => void;
36
+ onSelect?: (item: T) => void;
37
+ selectNoneText?: string;
38
+ errorStateTitle: string;
39
+ error?: Error;
40
+ emptyStateTitle: string;
41
+ emptyStateDescription?: string;
42
+ emptyStateButtonText?: string;
43
+ emptyStateButtonClick?: () => void;
44
+ t?: (t: string) => string;
45
+ };
46
+ export declare function PageDataList<T extends object>(props: PageDataListProps<T>): JSX.Element;
@@ -0,0 +1,45 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Button, DataList, DataListAction, DataListCell, DataListCheck, DataListItem, DataListItemCells, DataListItemRow, DropdownPosition, EmptyState, EmptyStateBody, EmptyStateIcon, EmptyStateVariant, Title, } from '@patternfly/react-core';
3
+ import { ExclamationCircleIcon, PlusCircleIcon } from '@patternfly/react-icons';
4
+ import { Fragment } from 'react';
5
+ import { Scrollable } from './components/Scrollable';
6
+ import { PageBody } from './PageBody';
7
+ import { PageHeader } from './PageHeader';
8
+ import { PageLayout } from './PageLayout';
9
+ import { PagePagination } from './PagePagination';
10
+ import { PageTableToolbar } from './PageToolbar';
11
+ import { useSettings } from './Settings';
12
+ import { TypedActions, TypedActionType } from './TypedActions';
13
+ export function DataListPage(props) {
14
+ return (_jsx(_Fragment, { children: _jsxs(PageLayout, { children: [_jsx(PageHeader, { ...props }), _jsx(PageBody, { children: _jsx(PageDataList, { ...props }) })] }) }));
15
+ }
16
+ export function PageDataList(props) {
17
+ const { pageItems, selectItem, unselectItem, isSelected, keyFn, toolbarActions, itemCount, perPage,
18
+ // clearAllFilters,
19
+ filters, error, dataCells, } = props;
20
+ const showSelect = toolbarActions?.find((toolbarAction) => TypedActionType.bulk === toolbarAction.type) !==
21
+ undefined;
22
+ const settings = useSettings();
23
+ if (error) {
24
+ return (_jsx("div", { style: {
25
+ backgroundColor: settings.theme === 'dark' ? 'var(--pf-global--BackgroundColor--300)' : undefined,
26
+ height: '100%',
27
+ }, children: _jsxs(EmptyState, { variant: EmptyStateVariant.small, style: {
28
+ paddingTop: 64,
29
+ }, children: [_jsx(EmptyStateIcon, { icon: ExclamationCircleIcon, color: "var(--pf-global--danger-color--100)" }), _jsx(Title, { headingLevel: "h2", size: "lg", children: props.errorStateTitle }), _jsx(EmptyStateBody, { children: error.message })] }) }));
30
+ }
31
+ if (itemCount === 0 && Object.keys(filters ?? {}).length === 0) {
32
+ return (_jsxs(EmptyState, { variant: EmptyStateVariant.large, style: { paddingTop: 64 }, children: [_jsx(EmptyStateIcon, { icon: PlusCircleIcon }), _jsx(Title, { headingLevel: "h4", size: "lg", children: props.emptyStateTitle }), props.emptyStateDescription && (_jsx(EmptyStateBody, { children: props.emptyStateDescription })), props.emptyStateButtonClick && (_jsx(Button, { variant: "primary", onClick: props.emptyStateButtonClick, children: props.emptyStateButtonText }))] }));
33
+ }
34
+ return (_jsxs(Fragment, { children: [_jsx(PageTableToolbar, { ...props, disableBorderBottom: true }), _jsx(Scrollable, { children: _jsx(DataList, { "aria-label": "Simple data list example", children: pageItems?.map((item) => (_jsx(DataListItem, { "aria-labelledby": "simple-item1", children: _jsxs(DataListItemRow, { children: [showSelect && (_jsx(DataListCheck, { "aria-labelledby": "check-action-item1", name: "check-action-check1", isChecked: isSelected?.(item), onClick: () => {
35
+ if (isSelected?.(item)) {
36
+ selectItem?.(item);
37
+ }
38
+ else {
39
+ unselectItem?.(item);
40
+ }
41
+ } })), _jsx(DataListItemCells, { dataListCells: dataCells.map((dataCell, index) => (_jsx(DataListCell, { width: index === 0 ? 5 : 1, children: _jsx("span", { id: "simple-item1", children: dataCell(item) }) }, "primary content"))) }), props.actions && _jsx(DataListActions, { actions: props.actions })] }) }, keyFn(item)))) }) }), (!props.autoHidePagination || (itemCount ?? 0) > perPage) && _jsx(PagePagination, { ...props })] }));
42
+ }
43
+ function DataListActions(props) {
44
+ return (_jsx(DataListAction, { "aria-labelledby": "check-action-item1 check-action-action1", id: "check-action-action1", "aria-label": "Actions", isPlainButtonAction: true, style: { whiteSpace: 'nowrap' }, children: _jsx(TypedActions, { actions: props.actions, position: DropdownPosition.right }) }));
45
+ }
@@ -0,0 +1,10 @@
1
+ import { Dispatch, ReactNode, SetStateAction } from 'react';
2
+ export declare const DialogContext: import("react").Context<ReactNode>;
3
+ export declare const SetDialogContext: import("react").Context<(dialog?: ReactNode) => void>;
4
+ export declare function PageDialogProvider(props: {
5
+ children: ReactNode;
6
+ }): JSX.Element;
7
+ export declare function usePageDialog(): [
8
+ dialog: ReactNode | undefined,
9
+ setDialog: Dispatch<SetStateAction<ReactNode | undefined>>
10
+ ];
@@ -0,0 +1,12 @@
1
+ import { jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createContext, useContext, useState } from 'react';
3
+ export const DialogContext = createContext(undefined);
4
+ export const SetDialogContext = createContext(() => null);
5
+ const PageDialogContext = createContext([undefined, () => alert('Use PageDialogProvider')]);
6
+ export function PageDialogProvider(props) {
7
+ const state = useState();
8
+ return (_jsxs(PageDialogContext.Provider, { value: state, children: [state[0] !== undefined && state[0], props.children] }));
9
+ }
10
+ export function usePageDialog() {
11
+ return useContext(PageDialogContext);
12
+ }
@@ -0,0 +1,147 @@
1
+ import { JSONSchema6 } from 'json-schema';
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 '.';
6
+ export declare 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;
127
+ export declare function PageForm<T extends object>(props: {
128
+ schema?: JSONSchema6;
129
+ children?: ReactNode;
130
+ submitText: string;
131
+ onSubmit: FormPageSubmitHandler<T>;
132
+ cancelText: string;
133
+ onCancel?: () => void;
134
+ defaultValue?: DeepPartial<T>;
135
+ isVertical?: boolean;
136
+ singleColumn?: boolean;
137
+ disableScrolling?: boolean;
138
+ }): JSX.Element;
139
+ export declare type FormPageSubmitHandler<T extends FieldValues> = (data: T, setError: (error: string) => void, setFieldError: (fieldName: FieldPath<T>, error: ErrorOption) => void) => Promise<unknown>;
140
+ export declare function PageFormSubmitButton(props: {
141
+ children: ReactNode;
142
+ style?: CSSProperties;
143
+ }): JSX.Element;
144
+ export declare function PageFormCancelButton(props: {
145
+ onCancel: () => void;
146
+ children: ReactNode;
147
+ }): JSX.Element;