@propellerads/table 4.2.0 → 4.3.2

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.
package/dist/types.d.ts CHANGED
@@ -26,7 +26,7 @@ export declare type PaginationProps = {
26
26
  gotoPage: (page: number) => void;
27
27
  };
28
28
  export declare type ControlledPagination = {
29
- paginationAmount: string | ReactNode | ReactElement;
29
+ paginationAmount?: string | ReactNode | ReactElement;
30
30
  pageSize: number;
31
31
  pageIndex: number;
32
32
  pageCount: number;
@@ -61,6 +61,7 @@ export declare type TableProps = {
61
61
  getFooterGroupProps?: ElementGetter;
62
62
  showLoadingState?: boolean;
63
63
  LoadingCellComponent?: FunctionComponent<DefaultObject>;
64
+ noDataMessage?: string | ReactElement;
64
65
  };
65
66
  export declare type TableOptions = {
66
67
  columns: Array<Column<DefaultObject>>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@propellerads/table",
3
- "version": "4.2.0",
3
+ "version": "4.3.2",
4
4
  "repository": "https://github.com/propellerads/ui-components",
5
5
  "author": "i.pasyuk@propellerads.net",
6
6
  "license": "MIT",
@@ -41,5 +41,5 @@
41
41
  "@types/react-table": "^7.7.12",
42
42
  "react-table": "^7.8.0"
43
43
  },
44
- "gitHead": "c091a2a2bbecfaac3f7f75fdfc234d0023e7433a"
44
+ "gitHead": "258e659f14a8f803795b18b0f2771c04e0a7d2e6"
45
45
  }
package/src/index.tsx CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  useTable,
10
10
  useRowSelect,
11
11
  usePagination,
12
- useBlockLayout,
12
+ useFlexLayout,
13
13
  Column,
14
14
  } from 'react-table';
15
15
 
@@ -76,6 +76,7 @@ export const defaultProps = {
76
76
  showLoadingState: false,
77
77
  LoadingCellComponent: EmptyStateCell,
78
78
  getRowPreProps: () => ({}),
79
+ noDataMessage: '',
79
80
  };
80
81
 
81
82
  type DefaultProps = Readonly<typeof defaultProps>;
@@ -147,6 +148,7 @@ const Table: FunctionComponent<TableProps & DefaultProps> = (props) => {
147
148
  getFooterProps,
148
149
  getFooterGroupProps,
149
150
  showLoadingState,
151
+ noDataMessage,
150
152
  } = props;
151
153
 
152
154
  const memoColumns = useMemo(() => columns, [columns]);
@@ -245,7 +247,7 @@ const Table: FunctionComponent<TableProps & DefaultProps> = (props) => {
245
247
  ...rest
246
248
  } = useTable(
247
249
  options,
248
- useBlockLayout,
250
+ useFlexLayout,
249
251
  useSortBy,
250
252
  usePagination,
251
253
  useRowSelect,
@@ -355,7 +357,7 @@ const Table: FunctionComponent<TableProps & DefaultProps> = (props) => {
355
357
 
356
358
  delete headerProps?.style;
357
359
 
358
- if (hasManualSortBy && !column.canSort && headerProps) {
360
+ if (hasManualSortBy && column.canSort && headerProps) {
359
361
  headerProps.onClick = () => {
360
362
  onSortedChange?.(column.id, Boolean(column.isSortedDesc));
361
363
  setSortBy([{
@@ -371,25 +373,26 @@ const Table: FunctionComponent<TableProps & DefaultProps> = (props) => {
371
373
  const tBodyTr = (hasControlledPagination || hasDefaultPagination) ? page : rows;
372
374
 
373
375
  return (
374
- <TableRoot>
375
- <TableLoading isLoading={!showLoadingState && isLoading}>
376
+ <TableRoot className="table-root">
377
+ <TableLoading isLoading={!showLoadingState && isLoading} className="table-loading">
376
378
  <TableLoadingInner>
377
379
  {loadingMessage}
378
380
  </TableLoadingInner>
379
381
  </TableLoading>
380
- <TableWrapper ref={tableWrapperRef}>
381
- <TableContent id={tableContentId}>
382
+ <TableWrapper ref={tableWrapperRef} className="table-wrapper">
383
+ <TableContent id={tableContentId} className="table-content">
382
384
  <TableCore {..._getTableProps(getTableBodyProps(getTableProps))} ref={tableRef}>
383
- <THead>
385
+ <THead className="table-head">
384
386
  {headerGroups.map((headerGroup) => (
385
387
  <TR {...headerGroup.getHeaderGroupProps(getTableElementProps(getHeaderGroupProps))}>
386
388
  {headerGroup.headers.map((column) => {
387
389
  const headerProps = extendSortByProps(column) as DefaultObject;
388
390
 
389
391
  return (
390
- <TH {...column.getHeaderProps(getTableElementInternalProps(
391
- headerProps, getHeaderProps, mainCellGetter,
392
- ))}
392
+ <TH
393
+ {...column.getHeaderProps(getTableElementInternalProps(
394
+ headerProps, getHeaderProps, mainCellGetter,
395
+ ))}
393
396
  >
394
397
  {getHeadContent(column)}
395
398
  </TH>
@@ -399,7 +402,7 @@ const Table: FunctionComponent<TableProps & DefaultProps> = (props) => {
399
402
  ))}
400
403
  </THead>
401
404
  {footerPlacement.includes(FOOTER_PLACEMENT.TOP) && (
402
- <TFoot>
405
+ <TFoot className="table-footer-top">
403
406
  {footerGroups.map((group) => (
404
407
  <TR {...group.getFooterGroupProps(getTableElementProps(getFooterGroupProps))}>
405
408
  {group.headers.map((column) => (
@@ -411,7 +414,7 @@ const Table: FunctionComponent<TableProps & DefaultProps> = (props) => {
411
414
  ))}
412
415
  </TFoot>
413
416
  )}
414
- <TBody>
417
+ <TBody className="table-body">
415
418
  {tBodyTr.map((row: StandardRow) => {
416
419
  prepareRow(row);
417
420
  const {isDelimiterTd} = getRowPreProps(row);
@@ -445,7 +448,7 @@ const Table: FunctionComponent<TableProps & DefaultProps> = (props) => {
445
448
  })}
446
449
  </TBody>
447
450
  {footerPlacement.includes(FOOTER_PLACEMENT.BOTTOM) && (
448
- <TFoot>
451
+ <TFoot className="table-footer-bottom">
449
452
  {footerGroups.map((group) => (
450
453
  <TR {...group.getFooterGroupProps(getTableElementProps(getFooterGroupProps))}>
451
454
  {group.headers.map((column) => (
@@ -460,6 +463,7 @@ const Table: FunctionComponent<TableProps & DefaultProps> = (props) => {
460
463
  </TableCore>
461
464
  </TableContent>
462
465
  </TableWrapper>
466
+ {!isLoading && !data.length && noDataMessage}
463
467
  {pagination}
464
468
  </TableRoot>
465
469
  );
package/src/style.tsx CHANGED
@@ -121,7 +121,6 @@ export const TableCore = styled.div`
121
121
  flex-direction: column;
122
122
  align-items: stretch;
123
123
  border-collapse: collapse;
124
- width: max-content;
125
124
  `;
126
125
 
127
126
  export const HeadCell = styled.div`
@@ -180,11 +179,11 @@ export const TRGroup = styled.div`
180
179
  display: flex;
181
180
  flex: 1 0 auto;
182
181
  box-shadow: inset 0 -1px 0 0 ${gray95};
182
+ min-width: 100%;
183
+ width: max-content;
183
184
  `;
184
185
 
185
186
  export const TR = styled.div`
186
- flex: 1 0 auto;
187
- display: inline-flex;
188
187
  padding: 0;
189
188
  -webkit-box-align: center;
190
189
  align-items: center;
@@ -193,6 +192,8 @@ export const TR = styled.div`
193
192
  export const TBody = styled.div`
194
193
  border-top: 1px solid ${gray80};
195
194
  margin-top: ${spacing * 2}px;
195
+ min-width: 100%;
196
+ width: max-content;
196
197
  `;
197
198
 
198
199
  export const TFoot = styled.div`
package/src/types.tsx CHANGED
@@ -51,7 +51,7 @@ export type PaginationProps = {
51
51
  }
52
52
 
53
53
  export type ControlledPagination = {
54
- paginationAmount: string | ReactNode | ReactElement,
54
+ paginationAmount?: string | ReactNode | ReactElement,
55
55
  pageSize: number,
56
56
  pageIndex: number,
57
57
  pageCount: number,
@@ -83,7 +83,8 @@ export type TableProps = {
83
83
  getFooterProps?: ElementGetter,
84
84
  getFooterGroupProps?: ElementGetter,
85
85
  showLoadingState?: boolean,
86
- LoadingCellComponent?: FunctionComponent<DefaultObject>
86
+ LoadingCellComponent?: FunctionComponent<DefaultObject>,
87
+ noDataMessage?: string | ReactElement
87
88
  }
88
89
 
89
90
  export type TableOptions = {
@@ -1,4 +1,4 @@
1
- import {FunctionComponent, useMemo} from 'react';
1
+ import React, {FunctionComponent, useMemo} from 'react';
2
2
  import {Column} from 'react-table';
3
3
  import {DefaultObject, LoadingState} from './types';
4
4
 
@@ -12,7 +12,7 @@ const useLoadingState = (
12
12
  const loadingColumns: Column<DefaultObject>[] | undefined = useMemo(() => (showLoadingState && loading ? columns
13
13
  .map(({maxWidth, width, Header}: Column, key: number) => {
14
14
  const column: Column<DefaultObject> = {
15
- Cell: LoadingCellComponent,
15
+ Cell: () => <LoadingCellComponent />,
16
16
  accessor: `empty_${key}`,
17
17
  };
18
18
  if (maxWidth) {