@indico-data/design-system 3.0.2 → 3.0.4

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indico-data/design-system",
3
- "version": "3.0.2",
3
+ "version": "3.0.4",
4
4
  "description": "",
5
5
  "author": "",
6
6
  "main": "lib/index.js",
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import classNames from 'classnames';
2
3
 
3
4
  export interface CheckboxProps {
4
5
  ref?: React.LegacyRef<HTMLInputElement>;
@@ -10,16 +11,20 @@ export interface CheckboxProps {
10
11
  onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
11
12
  isDisabled?: boolean;
12
13
  defaultChecked?: boolean;
14
+ className?: string;
13
15
  }
14
16
 
15
17
  export const Checkbox = React.forwardRef<HTMLInputElement, CheckboxProps>(
16
- ({ id, label, name, value, onChange, isDisabled, isChecked = false, ...rest }, ref) => {
18
+ (
19
+ { id, label, name, value, onChange, isDisabled, isChecked = false, className, ...rest },
20
+ ref,
21
+ ) => {
17
22
  return (
18
23
  <div className="form-control">
19
24
  <div className="checkbox-wrapper">
20
25
  <input
21
26
  data-testid={`form-checkbox-input-${name}`}
22
- className="checkbox-input"
27
+ className={classNames('checkbox-input', className)}
23
28
  type="checkbox"
24
29
  id={id}
25
30
  name={name}
@@ -56,6 +56,7 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
56
56
  const inputClasses = classNames(
57
57
  'input',
58
58
  {
59
+ 'is-clearable': isClearable,
59
60
  error: hasErrors,
60
61
  'input--has-icon': iconName,
61
62
  },
@@ -27,4 +27,7 @@
27
27
  color: var(--pf-form-input-color);
28
28
  cursor: pointer;
29
29
  }
30
+ .is-clearable {
31
+ padding-right: var(--pf-padding-6);
32
+ }
30
33
  }
@@ -64,7 +64,7 @@ export const Pagination = ({
64
64
  variant="link"
65
65
  onClick={handlePreviousPage}
66
66
  iconLeft="chevron-left"
67
- isDisabled={isPreviousButtonDisabled}
67
+ isDisabled={isPreviousButtonDisabled || totalPages === 0}
68
68
  />
69
69
  </div>
70
70
  </Col>
@@ -106,7 +106,7 @@ export const Pagination = ({
106
106
  variant="link"
107
107
  onClick={handleNextPage}
108
108
  iconLeft="chevron-right"
109
- isDisabled={isNextButtonDisabled}
109
+ isDisabled={isNextButtonDisabled || totalPages === 0}
110
110
  />
111
111
  </div>
112
112
  </Col>
@@ -35,6 +35,7 @@ export type Props<T extends object> = {
35
35
  clearFilters?: () => void;
36
36
  hasFilters?: boolean;
37
37
  isLoading?: boolean;
38
+ isLoadingMessage?: string;
38
39
  defaultPinnedColumns?: string[];
39
40
  onClickRow?: ((row: Row<T>) => void) | null;
40
41
  onRowClick?: (row: T) => void;
@@ -19,6 +19,7 @@ const meta: Meta = {
19
19
  clearFilters: () => {},
20
20
  hasFilters: false,
21
21
  isLoading: false,
22
+ isLoadingMessage: 'Table is loading...',
22
23
  enableRowSelection: true,
23
24
  showPagination: false,
24
25
  onClickRow: null,
@@ -130,6 +131,15 @@ const meta: Meta = {
130
131
  defaultValue: { summary: 'false' },
131
132
  },
132
133
  },
134
+ isLoadingMessage: {
135
+ description: 'Message to display when the table is loading.',
136
+ control: { type: 'text' },
137
+ table: {
138
+ category: 'Props',
139
+ type: { summary: 'string' },
140
+ defaultValue: { summary: 'Table is loading...' },
141
+ },
142
+ },
133
143
  defaultPinnedColumns: {
134
144
  description: 'Columns that are pinned by default.',
135
145
  control: false,
@@ -16,6 +16,7 @@ import { Props } from './TankstackTable.types';
16
16
  import { useTanstackTable } from './useTanstackTable';
17
17
  import { TableHeader } from './components/TableHeader';
18
18
  import { TableBody } from './components/TableBody';
19
+ import { TableLoading } from './components/TableLoading/TableLoading';
19
20
 
20
21
  export function TanstackTable<T extends object>({
21
22
  columns: defaultColumns,
@@ -33,6 +34,7 @@ export function TanstackTable<T extends object>({
33
34
  hasFilters,
34
35
  showPagination = true,
35
36
  isLoading = false,
37
+ isLoadingMessage = 'Table is loading...',
36
38
  defaultPinnedColumns,
37
39
  onRowClick,
38
40
  activeRows = [],
@@ -129,12 +131,14 @@ export function TanstackTable<T extends object>({
129
131
  );
130
132
  }
131
133
 
134
+ if (isLoading) {
135
+ return <TableLoading columns={columns} message={isLoadingMessage} />;
136
+ }
137
+
132
138
  return (
133
139
  <TableBody<T & { id: string }>
134
140
  table={table}
135
141
  onRowClick={onRowClick}
136
- isLoading={isLoading}
137
- columnsLength={columns.length}
138
142
  activeRows={activeRows}
139
143
  />
140
144
  );
@@ -145,7 +149,6 @@ export function TanstackTable<T extends object>({
145
149
  <div className="tanstack-table__container">
146
150
  <table
147
151
  className={classNames('tanstack-table', className, {
148
- 'is-Loading': isLoading,
149
152
  'is-striped': isStriped,
150
153
  })}
151
154
  >
@@ -165,7 +168,11 @@ export function TanstackTable<T extends object>({
165
168
  rowCount={rowCount}
166
169
  onChangePage={onChangePage}
167
170
  rowsPerPage={rowsPerPage}
168
- totalEntriesText={totalEntriesText ?? `${totalRowsOnPage} of ${rowCount} entries`}
171
+ totalEntriesText={
172
+ totalEntriesText ?? rowCount === 1
173
+ ? '1 entry'
174
+ : `${totalRowsOnPage} of ${rowCount} entries`
175
+ }
169
176
  />
170
177
  ) : null}
171
178
  </div>
@@ -11,10 +11,10 @@
11
11
  &__text {
12
12
  font-size: var(--pf-line-height-md);
13
13
  font-weight: var(--pf-font-weight-medium);
14
- color: var(--pf-primary-color-50);
14
+ color: var(--pf-tanstack-table-font-color);
15
15
 
16
16
  span {
17
- color: var(--pf-white-color);
17
+ color: var(--pf-tanstack-table-font-color);
18
18
  cursor: pointer;
19
19
  &:hover {
20
20
  text-decoration: underline;
@@ -1,25 +1,14 @@
1
1
  import { flexRender, Table } from '@tanstack/react-table';
2
- import { Row } from '@tanstack/react-table';
3
2
  import classNames from 'classnames';
4
3
  import { getTdStyles } from '../../helpers';
5
- import { CirclePulse } from '@/components/loading-indicators/CirclePulse';
6
- import { Dispatch, SetStateAction } from 'react';
7
4
 
8
5
  export type Props<T> = {
9
6
  table: Table<T>;
10
7
  onRowClick?: ((row: T & { id: string }) => void) | null | undefined;
11
- isLoading: boolean;
12
- columnsLength: number;
13
8
  activeRows: string[];
14
9
  };
15
10
 
16
- export const TableBody = <T,>({
17
- table,
18
- onRowClick,
19
- isLoading,
20
- columnsLength,
21
- activeRows,
22
- }: Props<T>) => {
11
+ export const TableBody = <T,>({ table, onRowClick, activeRows }: Props<T>) => {
23
12
  return (
24
13
  <>
25
14
  {table.getRowModel().rows.map((row) => (
@@ -60,19 +49,6 @@ export const TableBody = <T,>({
60
49
  })}
61
50
  </tr>
62
51
  ))}
63
- {isLoading && (
64
- <tr className="tanstack-table__tbody__tr">
65
- <td
66
- className={classNames('tanstack-table__centered-row', {
67
- 'is-loading': isLoading,
68
- })}
69
- colSpan={columnsLength}
70
- >
71
- <h2 className="mb-12">Table is loading...</h2>
72
- <CirclePulse data-testid="loading-indicator" />
73
- </td>
74
- </tr>
75
- )}
76
52
  </>
77
53
  );
78
54
  };
@@ -0,0 +1,18 @@
1
+ import { ColumnDef } from '@tanstack/react-table';
2
+ import { CirclePulse } from '../../../loading-indicators/CirclePulse';
3
+
4
+ export type Props<T> = {
5
+ columns: ColumnDef<T>[];
6
+ message?: string;
7
+ };
8
+
9
+ export const TableLoading = <T,>({ columns, message }: Props<T>) => {
10
+ return (
11
+ <tr className="tanstack-table__tbody__tr ">
12
+ <td className="tanstack-table__centered-row pa-6" colSpan={columns.length}>
13
+ <h2 className="my-12">{message}</h2>
14
+ <CirclePulse data-testid="loading-indicator" className="mb-14" />
15
+ </td>
16
+ </tr>
17
+ );
18
+ };
@@ -32,7 +32,7 @@ const PinHeaderColumns = ({
32
32
  };
33
33
 
34
34
  const CheckboxContainer = styled.div`
35
- padding: 14px;
35
+ height: 28px;
36
36
  `;
37
37
 
38
38
  export const columns = [
@@ -51,7 +51,7 @@ export const columns = [
51
51
  },
52
52
  },
53
53
  header: ({ table }) => (
54
- <CheckboxContainer>
54
+ <CheckboxContainer className="pl-3 pt-2">
55
55
  <Checkbox
56
56
  data-testid="select-all-checkbox"
57
57
  name="select-all"
@@ -70,12 +70,11 @@ export const columns = [
70
70
  />
71
71
  </CheckboxContainer>
72
72
  ),
73
- cell: (
74
- { row }, // todo - look at
75
- ) => (
76
- <CheckboxContainer>
73
+ cell: ({ row }) => (
74
+ <div className="pb-3">
77
75
  <Checkbox
78
76
  name="select"
77
+ className="mb-2"
79
78
  id={row.id}
80
79
  label=""
81
80
  aria-label={`checkbox-${row.id}`}
@@ -83,7 +82,7 @@ export const columns = [
83
82
  isDisabled={!row.getCanSelect()}
84
83
  onChange={row.getToggleSelectedHandler()}
85
84
  />
86
- </CheckboxContainer>
85
+ </div>
87
86
  ),
88
87
  },
89
88
  {
@@ -1,5 +1,4 @@
1
1
  @import './_variables.scss';
2
- @import './test.scss';
3
2
 
4
3
  @import '../components/ActionBar/ActionBar.scss';
5
4
  @import '../components/NoResults/NoResults.scss';
@@ -82,12 +81,6 @@
82
81
  }
83
82
  }
84
83
 
85
- .is-loading {
86
- border: var(--pf-border-thin) solid var(--pf-border-color-primary);
87
- height: 350px;
88
- width: 100%;
89
- }
90
-
91
84
  &__thead {
92
85
  position: sticky;
93
86
  top: 0;
@@ -1,19 +0,0 @@
1
- .tanstack-table__action-bar-test {
2
- left: 20% !important;
3
- }
4
-
5
- .tanstack-table__action-bar-docs {
6
- bottom: unset !important;
7
- top: 50% !important;
8
- transform: translate(-50%, -50%) !important;
9
- }
10
-
11
- .tanstack-table__column {
12
- &.is-pinned {
13
- opacity: 1;
14
- }
15
-
16
- &.is-not-pinned {
17
- opacity: 0.3;
18
- }
19
- }