@performant-software/semantic-components 1.0.2 → 1.0.3-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/build/index.js +1 -1
  2. package/build/index.js.map +1 -1
  3. package/package.json +3 -3
  4. package/src/components/ArrowButtons.js +12 -10
  5. package/src/components/DataList.js +87 -3
  6. package/src/components/DataTable.js +83 -31
  7. package/src/components/DataTableColumnSelector.js +41 -5
  8. package/src/components/DataView.js +1 -1
  9. package/src/components/EditModal.js +23 -3
  10. package/src/components/EditPage.js +32 -3
  11. package/src/components/EmbeddedList.js +17 -35
  12. package/src/components/FileUpload.js +15 -0
  13. package/src/components/FileUploadModal.js +36 -3
  14. package/src/components/ItemCollection.js +43 -6
  15. package/src/components/ItemList.js +27 -30
  16. package/src/components/Items.js +79 -9
  17. package/src/components/List.js +128 -26
  18. package/src/components/ListTable.js +50 -15
  19. package/types/components/ArrowButtons.js.flow +12 -10
  20. package/types/components/DataList.js.flow +87 -3
  21. package/types/components/DataTable.js.flow +83 -31
  22. package/types/components/DataTableColumnSelector.js.flow +41 -5
  23. package/types/components/DataView.js.flow +1 -1
  24. package/types/components/EditModal.js.flow +23 -3
  25. package/types/components/EditPage.js.flow +32 -3
  26. package/types/components/EmbeddedList.js.flow +17 -35
  27. package/types/components/FileUpload.js.flow +15 -0
  28. package/types/components/FileUploadModal.js.flow +36 -3
  29. package/types/components/ItemCollection.js.flow +43 -6
  30. package/types/components/ItemList.js.flow +27 -30
  31. package/types/components/Items.js.flow +79 -9
  32. package/types/components/List.js.flow +128 -26
  33. package/types/components/ListTable.js.flow +50 -15
@@ -1,16 +1,11 @@
1
1
  // @flow
2
2
 
3
3
  import React, { useCallback, useEffect, useMemo } from 'react';
4
- import { Button, Dimmer, Loader } from 'semantic-ui-react';
4
+ import { Dimmer, Loader } from 'semantic-ui-react';
5
5
  import _ from 'underscore';
6
6
  import i18n from '../i18n/i18n';
7
- import Items from './Items';
8
- import useDataList, { SORT_ASCENDING } from './DataList';
9
-
10
- type ListButton = {
11
- ...typeof Button,
12
- accept: () => boolean
13
- };
7
+ import Items, { type ItemsProps } from './Items';
8
+ import useDataList, { SORT_ASCENDING, type Props as DataListProps } from './DataList';
14
9
 
15
10
  type Sort = {
16
11
  key: any,
@@ -19,30 +14,36 @@ type Sort = {
19
14
  direction: ?string
20
15
  };
21
16
 
22
- type Props = {
23
- buttons: Array<ListButton>,
24
- isRowSelected: (item: any) => boolean,
25
- items: Array<any>,
26
- loading?: boolean,
27
- page: number,
28
- onRowSelect: (item: any) => void,
17
+ type Props = DataListProps & ItemsProps & {
18
+ /**
19
+ * Callback fired when the sort dropdown is changed. This prop is provided by the <code>DataList</code>
20
+ * higher-order component.
21
+ */
29
22
  onSort: (column: string, direction: ?string, page?: number) => void,
30
- selectable?: boolean,
23
+
24
+ /**
25
+ * An array of sort attributes to apply to the list. The values provided will display in a dropdown in the
26
+ * list header.
27
+ */
31
28
  sort?: Array<Sort>,
29
+
30
+ /**
31
+ * Name of the current sort column.
32
+ */
32
33
  sortColumn?: string,
34
+
35
+ /**
36
+ * Current sort direction (ascending or descending).
37
+ */
33
38
  sortDirection?: string
34
39
  };
35
40
 
36
41
  /**
37
- * An ItemList component can be used to render a list of records returned from an API. Under the hood, the DataList
38
- * component handles calling the API, storing the records, filters, etc, and the Items component handles the
39
- * presentation.
40
- *
41
- * @param props
42
- *
43
- * @returns {*}
42
+ * An <code>ItemList</code> component can be used to render a list of records returned from an API. Under the
43
+ * hood, the <code>DataList</code> component handles calling the API, storing the records, filters, etc, and
44
+ * the <code>Items</code> component handles the presentation.
44
45
  */
45
- const ItemList = (props: Props) => {
46
+ const ItemList = useDataList((props: Props) => {
46
47
  useEffect(() => {
47
48
  const { page } = props;
48
49
 
@@ -112,15 +113,11 @@ const ItemList = (props: Props) => {
112
113
  />
113
114
  </>
114
115
  );
115
- };
116
+ });
116
117
 
117
118
  ItemList.defaultProps = {
118
119
  filters: {},
119
- onCopy: undefined,
120
- onSort: () => {},
121
- renderDeleteModal: undefined,
122
- renderEmptyRow: undefined,
123
120
  searchable: true,
124
121
  };
125
122
 
126
- export default useDataList(ItemList);
123
+ export default ItemList;
@@ -20,30 +20,95 @@ import './Items.css';
20
20
  import type { Props as ListProps } from './List';
21
21
 
22
22
  type Props = ListProps & {
23
- children: Element<any>,
24
- className: string,
23
+ /**
24
+ * Child elements to append below the list content.
25
+ */
26
+ children?: Element<any>,
27
+
28
+ /**
29
+ * Callback returning <code>true</code> if the row for the passed item is selected.
30
+ */
25
31
  isRowSelected?: (item: any) => boolean,
32
+
33
+ /**
34
+ * An array of objects to render as rows in the list.
35
+ */
26
36
  items: Array<any>,
27
- loading: boolean,
37
+
38
+ /**
39
+ * Callback fired when a table row is dragged
40
+ */
28
41
  onDrag?: (dragIndex: number, hoverIndex: number) => void,
42
+
43
+ /**
44
+ * Callback fired when the passed item is selected. This callback is <i>only</i> fired if the <code>selectable</code>
45
+ * prop is passed as <code>true</code>.
46
+ */
29
47
  onRowSelect?: (item: any) => void,
48
+
49
+ /**
50
+ * Callback fired when the select all checkbox is checked.
51
+ */
30
52
  onSelectAllRows?: (items: Array<any>) => void,
53
+
54
+ /**
55
+ * A function that returns a JSX element to render as additional card content.
56
+ */
31
57
  renderAdditionalContent?: (item: any) => Element<any>,
58
+
59
+ /**
60
+ * A function that returns a JSX element to render as the card description.
61
+ * See Semantic UI <a href="https://react.semantic-ui.com/views/card/">Card</a>.
62
+ */
32
63
  renderDescription?: (item: any) => Element<any>,
33
- renderEmptyList: () => Element<any>,
64
+
65
+ /**
66
+ * A function that returns a JSX element to render when the list has no items.
67
+ */
68
+ renderEmptyList?: () => Element<any>,
69
+
70
+ /**
71
+ * A function that returns a JSX element to render as the card extra content.
72
+ * See Semantic UI <a href="https://react.semantic-ui.com/views/card/">Card</a>.
73
+ */
34
74
  renderExtra?: (item: any) => Element<any>,
75
+
76
+ /**
77
+ * A function that returns a JSX element to render as the card header.
78
+ * See Semantic UI <a href="https://react.semantic-ui.com/views/card/">Card</a>.
79
+ */
35
80
  renderHeader?: (item: any) => Element<any>,
81
+
82
+ /**
83
+ * A function that returns a JSX element to render as the card image.
84
+ * See Semantic UI <a href="https://react.semantic-ui.com/views/card/">Card</a>.
85
+ */
36
86
  renderImage?: (item: any) => Element<any>,
87
+
88
+ /**
89
+ * A function that returns a JSX element to render as the card meta.
90
+ * See Semantic UI <a href="https://react.semantic-ui.com/views/card/">Card</a>.
91
+ */
37
92
  renderMeta?: (item: any) => Element<any>,
93
+
94
+ /**
95
+ * If <code>true</code>, a selection box will display for each row.
96
+ */
38
97
  selectable?: boolean,
98
+
99
+ /**
100
+ * Toggles between list view and grid view. This prop is provided by the <code>ItemsToggle</code> higher-order
101
+ * component.
102
+ */
39
103
  view: number
40
104
  };
41
105
 
42
106
  /**
43
- * The Items component is used as the presentation for a list of records. The component renders both a list
44
- * (see Semantic-UI List) and grid (see Semantic-UI Card) views.
107
+ * The <code>Items</code> component is used as the presentation for a list of records. The component renders
108
+ * both a <a href="https://react.semantic-ui.com/elements/list/" target="_blank">List</a> and
109
+ * <a href="https://react.semantic-ui.com/views/card/" target="_blank">Card</a> views.
45
110
  */
46
- class Items extends Component<Props, {}> {
111
+ class ItemsClass extends Component<Props, {}> {
47
112
  static defaultProps: any;
48
113
 
49
114
  /**
@@ -360,8 +425,13 @@ class Items extends Component<Props, {}> {
360
425
  }
361
426
  }
362
427
 
363
- Items.defaultProps = {
428
+ ItemsClass.defaultProps = {
364
429
  actions: []
365
430
  };
366
431
 
367
- export default useItemsToggle(useList(Items));
432
+ const Items = useItemsToggle(useList(ItemsClass));
433
+ export default Items;
434
+
435
+ export type {
436
+ Props
437
+ };
@@ -37,8 +37,17 @@ type ListButton = {
37
37
  };
38
38
 
39
39
  type Props = {
40
- actions: Array<Action>,
41
- addButton: {
40
+ /**
41
+ * A list of actions to render for each element in the row. Actions with the names "edit" and "delete" will be
42
+ * handled specially by the <code>List</code> higher-order component.
43
+ */
44
+ actions?: Array<Action>,
45
+
46
+ /**
47
+ * If provided, a button will display in the list header allowing the addition of items to the list. When clicked,
48
+ * the <code>modal</code> prop will be rendered.
49
+ */
50
+ addButton?: {
42
51
  basic: boolean,
43
52
  color: string,
44
53
  content?: string,
@@ -47,15 +56,50 @@ type Props = {
47
56
  onClick?: () => void,
48
57
  secondary?: boolean
49
58
  },
50
- buttons: Array<ListButton>,
51
- count: number,
52
- className: string,
53
- configurable: boolean,
59
+
60
+ /**
61
+ * A list of arbitrary buttons to the display in the list header. All actions will be handled by the consuming
62
+ * component.
63
+ * <br />
64
+ * <br />
65
+ *
66
+ * In addition to the props listed here for each button, buttons will also accept any of the Semantic UI
67
+ * <a href="https://react.semantic-ui.com/elements/button/" target="_blank">Button</a> props.
68
+ */
69
+ buttons?: Array<ListButton>,
70
+
71
+ /**
72
+ * The number of total records in the list (not just the current page).
73
+ */
74
+ count?: number,
75
+
76
+ /**
77
+ * CSS class name to append to the <code>div</code> container.
78
+ */
79
+ className?: string,
80
+
81
+ /**
82
+ * If provided, a "delete all" button will be rendered in the list header.
83
+ */
54
84
  deleteButton?: {
55
85
  color: string,
56
86
  location: string,
57
87
  onClick?: () => void
58
88
  },
89
+
90
+ /**
91
+ * If provided, the passed <code>component</code> will be rendered when the filter button is clicked.
92
+ * <br />
93
+ * <br />
94
+ *
95
+ * Values passed in the <code>defaults</code> and <code>props</code> properties will be made available in the
96
+ * passed component.
97
+ * <br />
98
+ * <br />
99
+ *
100
+ * The <code>onChange</code> callback will fire when the filters are modified. This action will also reload the list,
101
+ * passing the new filters the <code>onLoad</code> callback.
102
+ */
59
103
  filters?: {
60
104
  active: boolean,
61
105
  component: Component<{}>,
@@ -63,32 +107,94 @@ type Props = {
63
107
  state?: any,
64
108
  onChange: (params: any) => Promise<any>
65
109
  },
66
- items: ?Array<any>,
67
- loading?: boolean,
110
+
111
+ /**
112
+ * If provided, the passed modal will be rendered when the "add" button is clicked.
113
+ */
68
114
  modal?: {
69
- component: Element<any>,
115
+ component: ComponentType<any>,
70
116
  props: any,
71
117
  state: any
72
118
  },
73
- page: number,
74
- pages: number,
119
+
120
+ /**
121
+ * If provided, this callback is fired when the "copy" action is clicked for an item. The consuming component
122
+ * should generate a copy of the selected item and return that value. The return value is then set at the
123
+ * current item in the edit modal.
124
+ */
75
125
  onCopy?: (item: any) => any,
76
- onDelete: (item: any) => void,
126
+
127
+ /**
128
+ * Callback fired when the "delete" action is clicked for an item.
129
+ */
130
+ onDelete?: (item: any) => void,
131
+
132
+ /**
133
+ * Callback fired when the delete all button is clicked. This prop expects a Promise as the return value.
134
+ */
77
135
  onDeleteAll?: () => Promise<any>,
78
- onPageChange: () => void,
79
- onPerPageChange: () => void,
80
- onSave: (item: any) => Promise<any>,
81
- onSelectAll?: (items: Array<any>) => void,
82
- perPage: number,
83
- perPageOptions: Array<number>,
136
+
137
+ /**
138
+ * Callback fired when the page is changed via the pagination component.
139
+ */
140
+ onPageChange?: () => void,
141
+
142
+ /**
143
+ * Callback fired when the per page value is changed.
144
+ */
145
+ onPerPageChange?: () => void,
146
+
147
+ /**
148
+ * Callback fired when the save button is clicked in the add/edit modal. This function expects a Promise as the
149
+ * return value.
150
+ */
151
+ onSave?: (item: any) => Promise<any>,
152
+
153
+ /**
154
+ * Current page number.
155
+ */
156
+ page?: number,
157
+
158
+ /**
159
+ * Number of pages in the list.
160
+ */
161
+ pages?: number,
162
+
163
+ /**
164
+ * The number of records to display per page.
165
+ */
166
+ perPage?: number,
167
+
168
+ /**
169
+ * The options to display in the dropdown for the per page selector.
170
+ */
171
+ perPageOptions?: Array<number>,
172
+
173
+ /**
174
+ * Custom render function for the modal that appears on the "delete" action.
175
+ */
84
176
  renderDeleteModal?: ({ selectedItem: any, onCancel: () => void, onConfirm: () => void }) => Element<any>,
85
- renderEmptyRow?: () => void,
86
- renderItem?: (item: any, index: number, children?: any) => Element<any>,
177
+
178
+ /**
179
+ * If provided, this function will return a JSX element that will prepend to the list header.
180
+ */
87
181
  renderListHeader?: () => ?Element<any>,
182
+
183
+ /**
184
+ * If provided, this function will return a JSX element that will replace the default search input.
185
+ */
88
186
  renderSearch?: () => Element<any>,
187
+
188
+ /**
189
+ * If set to <code>true</code>, checkboxes will render as the first table column, allowing each row to be selectable.
190
+ * The consuming component is responsible for tracking the selected items.
191
+ */
89
192
  selectable?: boolean,
90
- showRecordCount: boolean,
91
- t: (key: string) => string
193
+
194
+ /**
195
+ * If <code>true</code>, the total number of records will display in the list header.
196
+ */
197
+ showRecordCount?: boolean
92
198
  };
93
199
 
94
200
  type State = {
@@ -122,8 +228,6 @@ const useList = (WrappedComponent: ComponentType<any>) => (
122
228
  buttons: [],
123
229
  className: '',
124
230
  filters: undefined,
125
- items: [],
126
- loading: false,
127
231
  modal: undefined,
128
232
  page: 1,
129
233
  pages: 1,
@@ -131,9 +235,7 @@ const useList = (WrappedComponent: ComponentType<any>) => (
131
235
  onCopy: undefined,
132
236
  onPageChange: () => {},
133
237
  renderDeleteModal: undefined,
134
- renderEmptyRow: undefined,
135
238
  renderSearch: undefined,
136
- renderItem: undefined,
137
239
  sortColumn: undefined,
138
240
  sortDirection: undefined
139
241
  };
@@ -4,23 +4,61 @@ import { Hooks, Object as ObjectUtils } from '@performant-software/shared-compon
4
4
  import React, { useEffect } from 'react';
5
5
  import _ from 'underscore';
6
6
  import DataTable from './DataTable';
7
- import useDataList, { SORT_ASCENDING, SORT_DESCENDING } from './DataList';
7
+ import type { Props as DataTableProps } from './DataTable';
8
+ import useDataList, { SORT_ASCENDING, SORT_DESCENDING, type Props as DataListProps } from './DataList';
8
9
  import './ListTable.css';
9
10
 
10
- import type { Column } from './DataTable';
11
+ type Props = DataListProps & DataTableProps & {
12
+ /**
13
+ * If true, columns can be shown/hidden by the user.
14
+ */
15
+ configurable?: boolean,
11
16
 
12
- type Props = {
13
- columns: Array<Column>,
17
+ /**
18
+ * The name of the default sort column.
19
+ */
14
20
  defaultSort?: string,
21
+
22
+ /**
23
+ * The default direction to sort the list (ascending vs. descending).
24
+ */
15
25
  defaultSortDirection?: string,
16
- page: number,
17
- onSort: (sortColumn: string, sortDirection: string, page?: number) => void,
18
- onInit: (page?: number) => void,
19
- sortColumn: string,
20
- sortDirection: string
26
+
27
+ /**
28
+ * Callback supplied by the <code>DataList</code> higher-order component which can be used to initialize the list.
29
+ */
30
+ onInit?: (page?: number) => void,
31
+
32
+ /**
33
+ * Callback supplied by the <code>DataList</code> higher-order component which can be used to sort the list.
34
+ */
35
+ onSort?: (sortColumn: string, sortDirection: string, page?: number) => void,
36
+
37
+ /**
38
+ * Current sort column supplied by the <code>DataList</code> higher-order component.
39
+ */
40
+ sortColumn?: string,
41
+
42
+ /**
43
+ * Current sort direction supplied by the <code>DataList</code> higher-order component.
44
+ */
45
+ sortDirection?: string,
46
+
47
+ /**
48
+ * Customization props for the
49
+ * <a target="_blank" href="https://react.semantic-ui.com/collections/table/"><code>Table</code></a>
50
+ * component.
51
+ */
52
+ tableProps?: any
21
53
  };
22
54
 
23
- const ListTable = (props: Props) => {
55
+ /**
56
+ * The <code>ListTable</code> component renders a list which has the ability to load, save, and delete records from
57
+ * an API (via the <code>DataList</code> higher-order component). This component will integrate seamlessly with a
58
+ * back-end implementing the <code>resource-api</code>. See the
59
+ * <a href="https://github.com/performant-software/resource-api">GitHub page</a> for more details.
60
+ */
61
+ const ListTable = useDataList((props: Props) => {
24
62
  const prevColumns = Hooks.usePrevious(props.columns);
25
63
 
26
64
  /**
@@ -82,17 +120,14 @@ const ListTable = (props: Props) => {
82
120
  onColumnClick={onColumnClick.bind(this)}
83
121
  />
84
122
  );
85
- };
123
+ });
86
124
 
87
125
  ListTable.defaultProps = {
88
126
  configurable: true,
89
- onCopy: undefined,
90
- renderDeleteModal: undefined,
91
- renderEmptyRow: undefined,
92
127
  tableProps: {
93
128
  celled: true,
94
129
  sortable: true
95
130
  }
96
131
  };
97
132
 
98
- export default useDataList(ListTable);
133
+ export default ListTable;