@absreim/react-bootstrap-data-grid-pro 4.1.0 → 4.3.0

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 (133) hide show
  1. package/common/constants.d.ts +2 -0
  2. package/common/constants.js +2 -0
  3. package/common/editing/types.d.ts +30 -0
  4. package/common/export/types.d.ts +6 -0
  5. package/common/export/useExportFn.js +1 -1
  6. package/common/filtering/DateFilterRow.d.ts +1 -1
  7. package/common/filtering/DateFilterRow.js +1 -1
  8. package/common/filtering/FilterOptionsTable.d.ts +3 -2
  9. package/common/filtering/NumberFilterRow.d.ts +1 -1
  10. package/common/filtering/NumberFilterRow.js +1 -1
  11. package/common/filtering/StringFilterRow.js +1 -1
  12. package/common/filtering/constants.d.ts +19 -0
  13. package/common/filtering/constants.js +44 -0
  14. package/common/filtering/internalTypes.d.ts +77 -0
  15. package/common/filtering/types.d.ts +165 -22
  16. package/common/filtering/types.js +46 -17
  17. package/common/filtering/useFilterFormState.d.ts +1 -1
  18. package/common/icons/CaretDownFill.d.ts +4 -0
  19. package/common/icons/CaretDownFill.js +3 -0
  20. package/common/icons/CaretUp.d.ts +4 -0
  21. package/common/icons/CaretUp.js +3 -0
  22. package/common/icons/CaretUpFill.d.ts +4 -0
  23. package/common/icons/CaretUpFill.js +3 -0
  24. package/common/icons/internalTypes.d.ts +3 -0
  25. package/common/index.d.ts +0 -3
  26. package/common/index.js +0 -3
  27. package/common/internalTypes.d.ts +10 -0
  28. package/common/pagination/Pagination.d.ts +1 -1
  29. package/common/pagination/internalTypes.d.ts +8 -0
  30. package/common/pagination/internalTypes.js +1 -0
  31. package/common/pagination/types.d.ts +105 -5
  32. package/common/pipeline/{types.d.ts → internalTypes.d.ts} +5 -0
  33. package/common/pipeline/internalTypes.js +1 -0
  34. package/common/pipeline/useAugFormattedRows.d.ts +3 -2
  35. package/common/pipeline/useColNameToWidth.d.ts +2 -1
  36. package/common/pipeline/useCombinedPipeline/index.d.ts +4 -3
  37. package/common/pipeline/useCombinedPipeline/useCurrentPageRows.d.ts +2 -1
  38. package/common/pipeline/useCombinedPipeline/useCurrentPageRows.js +3 -2
  39. package/common/pipeline/useCombinedPipeline/useFilterStateFromEditable.d.ts +2 -1
  40. package/common/pipeline/useCombinedPipeline/useFilterStateStore.d.ts +2 -1
  41. package/common/pipeline/useGridSelectionFns.d.ts +2 -1
  42. package/common/selection/internalTypes.d.ts +34 -0
  43. package/common/selection/internalTypes.js +1 -0
  44. package/common/selection/types.d.ts +91 -17
  45. package/common/selection/types.js +0 -3
  46. package/common/sorting/ArrowPlaceholder.d.ts +3 -0
  47. package/common/sorting/ArrowPlaceholder.js +3 -0
  48. package/common/sorting/DownArrow.d.ts +6 -0
  49. package/common/sorting/DownArrow.js +3 -0
  50. package/common/sorting/UpArrow.d.ts +6 -0
  51. package/common/sorting/UpArrow.js +3 -0
  52. package/common/sorting/internalTypes.d.ts +10 -0
  53. package/common/sorting/internalTypes.js +1 -0
  54. package/common/sorting/types.d.ts +48 -4
  55. package/common/sorting/useSortHeaderStates.d.ts +1 -1
  56. package/common/sorting/useSortHeaderStates.js +8 -7
  57. package/common/styling/types.d.ts +57 -0
  58. package/common/toolbar/Toolbar.d.ts +1 -1
  59. package/common/toolbar/ToolbarContainer.d.ts +1 -1
  60. package/common/toolbar/{types.d.ts → internalTypes.d.ts} +27 -0
  61. package/common/toolbar/internalTypes.js +1 -0
  62. package/common/toolbar/useInterfaces.d.ts +1 -1
  63. package/common/types.d.ts +169 -16
  64. package/common/util/datetime.d.ts +17 -0
  65. package/common/util/datetime.js +17 -0
  66. package/common/util/getWidthStyle.d.ts +9 -0
  67. package/common/util/getWidthStyle.js +9 -0
  68. package/common/util/index.d.ts +0 -4
  69. package/common/util/index.js +0 -4
  70. package/common/util/isSubset.d.ts +12 -1
  71. package/common/util/isSubset.js +13 -2
  72. package/common/util/trueModulo.d.ts +8 -0
  73. package/common/util/trueModulo.js +8 -0
  74. package/common/util/useControlledHover.d.ts +5 -0
  75. package/common/util/useControlledHover.js +5 -0
  76. package/grid/focus/types.d.ts +11 -0
  77. package/grid/focus/useGridFocus.d.ts +1 -1
  78. package/grid/focus/useGridFocus.js +20 -5
  79. package/grid/main/Grid.d.ts +5 -0
  80. package/grid/main/Grid.js +14 -7
  81. package/grid/main/GridBody.d.ts +1 -1
  82. package/grid/main/GridHeader.d.ts +1 -1
  83. package/grid/main/GridHeader.js +29 -2
  84. package/grid/main/internalTypes.d.ts +31 -0
  85. package/grid/main/internalTypes.js +1 -0
  86. package/grid/main/types.d.ts +120 -19
  87. package/grid/sort/HeaderToggleButton.d.ts +11 -0
  88. package/grid/sort/HeaderToggleButton.js +29 -0
  89. package/grid.css +1 -1
  90. package/grid.scss +95 -33
  91. package/package.json +5 -5
  92. package/table/InternalTable.d.ts +1 -1
  93. package/table/Table.d.ts +5 -1
  94. package/table/Table.js +5 -0
  95. package/table/editing/EditableRow.d.ts +1 -1
  96. package/table/editing/EditableRow.js +1 -1
  97. package/table/internalTypes.d.ts +23 -0
  98. package/table/internalTypes.js +1 -0
  99. package/table/main/BodyRows.d.ts +4 -3
  100. package/table/main/ColHeaderCell/index.d.ts +1 -1
  101. package/table/selection/SelectAllHeaderCell.d.ts +1 -1
  102. package/table/styling/types.d.ts +122 -5
  103. package/table/types.d.ts +57 -15
  104. package/table-pro/ColHeaderCellPro.d.ts +1 -1
  105. package/table-pro/TablePro.d.ts +5 -0
  106. package/table-pro/TablePro.js +5 -0
  107. package/table-pro/index.d.ts +0 -1
  108. package/table-pro/index.js +0 -1
  109. package/table-pro/internalTypes.d.ts +11 -0
  110. package/table-pro/internalTypes.js +1 -0
  111. package/table-pro/reorder/ReorderHandleCell.d.ts +2 -1
  112. package/table-pro/reorder/internalTypes.d.ts +53 -0
  113. package/table-pro/reorder/internalTypes.js +1 -0
  114. package/table-pro/reorder/types.d.ts +36 -15
  115. package/table-pro/reorder/useKeyboardReorder.d.ts +1 -1
  116. package/table-pro/reorder/useKeyboardReorderListener.d.ts +2 -1
  117. package/table-pro/reorder/useReorderStyles.d.ts +2 -1
  118. package/table-pro/resize/internalType.d.ts +20 -0
  119. package/table-pro/resize/internalType.js +1 -0
  120. package/table-pro/resize/useResizeModel.d.ts +1 -1
  121. package/table-pro/types.d.ts +91 -8
  122. package/table-pro/util/reorderRows.d.ts +13 -0
  123. package/table-pro/util/reorderRows.js +13 -0
  124. package/common/sorting/arrowPlaceholder.d.ts +0 -2
  125. package/common/sorting/arrowPlaceholder.js +0 -7
  126. package/common/sorting/downArrow.d.ts +0 -2
  127. package/common/sorting/downArrow.js +0 -3
  128. package/common/sorting/upArrow.d.ts +0 -2
  129. package/common/sorting/upArrow.js +0 -4
  130. package/table-pro/resize/types.d.ts +0 -5
  131. /package/common/{pipeline/types.js → filtering/internalTypes.js} +0 -0
  132. /package/common/{toolbar/types.js → icons/internalTypes.js} +0 -0
  133. /package/{table-pro/resize/types.js → common/internalTypes.js} +0 -0
@@ -1,4 +1,4 @@
1
- import { ToolbarOption } from "./types";
1
+ import { ToolbarOption } from "./internalTypes";
2
2
  import { FC } from "react";
3
3
  export interface ToolbarProps {
4
4
  enabledFeatures: Partial<Record<ToolbarOption, boolean>>;
@@ -1,4 +1,4 @@
1
- import { InterfaceNodeGenerator } from "./types";
1
+ import { InterfaceNodeGenerator } from "./internalTypes";
2
2
  import { FC } from "react";
3
3
  import { ToolbarStyleModel } from "../styling/types";
4
4
  interface ToolbarContainerProps {
@@ -1,11 +1,38 @@
1
1
  import { ReactNode } from "react";
2
2
  import { FilterOptionsTableProps } from "../filtering/FilterOptionsTable";
3
3
  import { ExportFormProps } from "../export/ExportForm";
4
+ /**
5
+ * Strings representing different tools on the toolbar.
6
+ *
7
+ * @internal
8
+ */
4
9
  export type ToolbarOption = "filtering" | "exporting";
10
+ /**
11
+ * A mapping React elements for different toolbar tools.
12
+ *
13
+ * @internal
14
+ */
5
15
  export type ToolbarInterfaces = Partial<Record<ToolbarOption, ReactNode>>;
16
+ /**
17
+ * Props to pass to the components that implement different tools.
18
+ *
19
+ * @internal
20
+ */
6
21
  export interface InterfaceParams {
7
22
  filtering?: FilterOptionsTableProps;
8
23
  exporting?: ExportFormProps;
9
24
  }
25
+ /**
26
+ * Defines props for toolbar tool UI React components while allowing the
27
+ * callback to close the tool UI to be supplied later.
28
+ *
29
+ * @internal
30
+ */
10
31
  export type InterfacePropGenerator = (closeUiCallback: () => void) => InterfaceParams;
32
+ /**
33
+ * Defines toolbar tool UI React elements while allowing the callback
34
+ * to close the tool UI to be supplied later.
35
+ *
36
+ * @internal
37
+ */
11
38
  export type InterfaceNodeGenerator = (closeUiCallback: () => void) => ToolbarInterfaces;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,3 @@
1
- import { InterfacePropGenerator, ToolbarInterfaces } from "./types";
1
+ import { InterfacePropGenerator, ToolbarInterfaces } from "./internalTypes";
2
2
  declare const useInterfaces: (gen: InterfacePropGenerator) => (closeCallback: () => void) => ToolbarInterfaces;
3
3
  export default useInterfaces;
package/common/types.d.ts CHANGED
@@ -1,57 +1,210 @@
1
- import { EditModel } from "./editing/types";
2
- import { PaginationModel } from "./pagination/types";
3
1
  import { SortModel } from "./sorting/types";
4
- import { FilterModel } from "./filtering/types";
5
- import { SelectModel } from "./selection/types";
6
- import { StyleModel } from "./styling/types";
2
+ /**
3
+ * Union of all possible column data types.
4
+ *
5
+ * @public
6
+ */
7
7
  export type ColDataType = string | number | Date;
8
+ /**
9
+ * Union of strings that describe the type of a column.
10
+ *
11
+ * @public
12
+ */
8
13
  export type ColDataTypeStrings = "string" | "number" | "date" | "datetime";
14
+ /**
15
+ * Properties to a define a column that is shared between community and pro
16
+ * editions.
17
+ *
18
+ * @typeParam ValueType - the type of the value of the column (e.g. string,
19
+ * number, or Date)
20
+ *
21
+ * @public
22
+ */
9
23
  export interface ColDefBase<ValueType = any> {
24
+ /**
25
+ * String that specifies the data type of the column.
26
+ */
10
27
  type: ColDataTypeStrings;
28
+ /**
29
+ * The name of the property for the column in the {@link RowDef} object.
30
+ */
11
31
  name: string;
32
+ /**
33
+ * The display name of the property in places like the column heading.
34
+ */
12
35
  label: string;
36
+ /**
37
+ * The formatter function for the column.
38
+ */
13
39
  formatter?: (value: ValueType) => string;
40
+ /**
41
+ * Specifies whether the column is sortable.
42
+ *
43
+ * @defaultValue false
44
+ */
14
45
  sortable?: boolean;
15
46
  }
16
- export type ColDef<ValueType = any> = ColDefBase<ValueType> & {
47
+ /**
48
+ * Column definition properties specific to the community edition of the table
49
+ * and grid.
50
+ *
51
+ * @public
52
+ */
53
+ export interface CommunitySpecificColProps {
54
+ /**
55
+ * Sets the min-width and max-width CSS properties for all cells of the
56
+ * column.
57
+ *
58
+ * For the table, if no value is specified, then no value for min-width
59
+ * or max-width will be set.
60
+ *
61
+ * @defaultValue - 100 for the grid, undefined for the table
62
+ */
17
63
  width?: number;
18
- };
64
+ }
65
+ /**
66
+ * Column definition object for the community edition of the table and grid.
67
+ *
68
+ * @typeParam ValueType - the type of the value of the column (e.g. string,
69
+ * number, or Date)
70
+ *
71
+ * @public
72
+ */
73
+ export type ColDef<ValueType = any> = ColDefBase<ValueType> & CommunitySpecificColProps;
74
+ /**
75
+ * Type alias for "data" property of the {@link RowDef} interface. This type
76
+ * alias represents the most general type possible. One can specify a more
77
+ * specific type via the Data type parameter.
78
+ *
79
+ * @public
80
+ */
19
81
  export type ValidRowData = Record<string, any>;
82
+ /**
83
+ * The data fields for a row in a table or grid. Excludes the primary key for
84
+ * the row, which is stored separately in the "id" field of the {@link RowDef}
85
+ * interface.
86
+ *
87
+ * @typeParam Data - the type of the object. A more specific type can be
88
+ * specified in place of the default {@link ValidRowData} type to assist in
89
+ * type safety and IDE coding assistance.
90
+ *
91
+ * @public
92
+ */
20
93
  export type RowData<Data extends ValidRowData = ValidRowData> = Data;
94
+ /**
95
+ * A union of the possible values for an id of a {@link RowDef} object.
96
+ *
97
+ * @public
98
+ */
21
99
  export type RowId = string | number;
100
+ /**
101
+ * An object that represents a single row.
102
+ *
103
+ * @typeParam Data - the type of the "data" property. Can be specified to
104
+ * enhance type safety.
105
+ *
106
+ * @public
107
+ */
22
108
  export interface RowDef<Data extends ValidRowData = ValidRowData> {
109
+ /**
110
+ * An id for the row that must be unique among all rows passed in the "rows"
111
+ * prop of the {@link Table} or {@link Grid}.
112
+ */
23
113
  id: RowId;
114
+ /**
115
+ * Contains all data fields for different columns of the row.
116
+ */
24
117
  data: RowData<Data>;
25
118
  }
119
+ /**
120
+ * Interface that contains parameters shared between the {@link Table},
121
+ * {@link TablePro}, and {@link Grid} components.
122
+ *
123
+ * @public
124
+ */
26
125
  export interface MainComponentSharedProps {
126
+ /**
127
+ * The rows of data to be displayed by the table or grid.
128
+ */
27
129
  rows: RowDef[];
130
+ /**
131
+ * The column definitions of the table or grid.
132
+ */
28
133
  cols: ColDef[];
29
- pagination?: PaginationModel;
134
+ /**
135
+ * The sort model of the table or grid. Passing a truthy value enables the
136
+ * sorting feature of the component.
137
+ */
30
138
  sortModel?: SortModel;
31
- filterModel?: FilterModel;
32
- selectModel?: SelectModel;
33
- editModel?: EditModel;
34
- styleModel?: StyleModel;
35
- allowExport?: boolean;
36
139
  }
140
+ /**
141
+ * {@link RowDef} object that additionally contains the index of the row in the
142
+ * original array.
143
+ *
144
+ * @typeParam Data - type of the data property of the {@link RowDef} object
145
+ *
146
+ * @public
147
+ */
37
148
  export type AugRowDef<Data extends ValidRowData = ValidRowData> = RowDef<Data> & {
38
149
  origIndex: number;
39
150
  };
151
+ /**
152
+ * Row definition object that additionally contains index of the row before
153
+ * pagination was applied.
154
+ *
155
+ * @public
156
+ */
40
157
  export type PostPaginationRowDef<Data extends ValidRowData = ValidRowData> = AugRowDef<Data> & {
41
158
  prePaginationIndex: number;
42
159
  };
160
+ /**
161
+ * Object that describes the contents for a single table or grid cell along
162
+ * with various metadata.
163
+ *
164
+ * @public
165
+ */
43
166
  export interface CellData {
167
+ /**
168
+ * The name of the property in the {@link RowDef} "data" property that
169
+ * contains the value for the cell.
170
+ */
44
171
  fieldName: string;
172
+ /**
173
+ * The raw, unformatted, value of the cell.
174
+ */
45
175
  value: ColDataType;
176
+ /**
177
+ * A string that specifies of the value type of the column for the cell.
178
+ * Same as the "type" property in corresponding {@link ColDef} object.
179
+ */
46
180
  type: ColDataTypeStrings;
181
+ /**
182
+ * The ARIA column index of the column that contains the cell.
183
+ */
47
184
  ariaColIndex: number;
185
+ /**
186
+ * The value of the cell after the column's formatter function is applied.
187
+ */
48
188
  formattedValue: string;
189
+ /**
190
+ * The label of the column that the cell is in. Same as the property of the
191
+ * same name in the corresponding {@link ColDef} object.
192
+ */
49
193
  label: string;
194
+ /**
195
+ * The width of the column that the cell is in. Same as the property of the
196
+ * same name in the corresponding {@link ColDef} object.
197
+ */
50
198
  width?: number;
51
199
  }
200
+ /**
201
+ * Comprehensive information for an entire row of a table or grid, after
202
+ * postprocessing such as sorting, pagination, and filtering are applied.
203
+ *
204
+ * Contains an array of {@link CellData} in the order that the columns appear.
205
+ *
206
+ * @public
207
+ */
52
208
  export type FormattedRow = {
53
209
  contents: Omit<CellData, "width">[];
54
210
  } & Omit<PostPaginationRowDef, "data">;
55
- export type AugFormattedRow = {
56
- contents: CellData[];
57
- } & Omit<PostPaginationRowDef, "data">;
@@ -1,2 +1,19 @@
1
+ /**
2
+ * Returns a string that represents a date in the format used by the input
3
+ * element of type "date".
4
+ *
5
+ * @param date - the Date object to format
6
+ * @returns a string in the format YYYY-MM-DD
7
+ *
8
+ * @public
9
+ */
1
10
  export declare const dateToInputStr: (date: Date) => string;
11
+ /**
12
+ * Returns of string representation of datetime from a Date object.
13
+ *
14
+ * @param date - the Date object to format
15
+ * @returns a string in the format YYYY-MM-DDTHH:mm
16
+ *
17
+ * @public
18
+ */
2
19
  export declare const dateToDatetimeInputStr: (date: Date) => string;
@@ -1,3 +1,20 @@
1
1
  import dayjs from "dayjs";
2
+ /**
3
+ * Returns a string that represents a date in the format used by the input
4
+ * element of type "date".
5
+ *
6
+ * @param date - the Date object to format
7
+ * @returns a string in the format YYYY-MM-DD
8
+ *
9
+ * @public
10
+ */
2
11
  export const dateToInputStr = (date) => dayjs(date).format("YYYY-MM-DD");
12
+ /**
13
+ * Returns of string representation of datetime from a Date object.
14
+ *
15
+ * @param date - the Date object to format
16
+ * @returns a string in the format YYYY-MM-DDTHH:mm
17
+ *
18
+ * @public
19
+ */
3
20
  export const dateToDatetimeInputStr = (date) => dayjs(date).format("YYYY-MM-DDTHH:mm");
@@ -1,3 +1,12 @@
1
1
  import { CSSProperties } from "react";
2
+ /**
3
+ * Given a number representing a width, returns a React CSSProperties object
4
+ * that sets the min-width and max-width CSS properties based on that number.
5
+ * Returns undefined if the input is undefined.
6
+ *
7
+ * @param width - the number representing the width, or undefined
8
+ *
9
+ * @internal
10
+ */
2
11
  declare const getWidthStyle: (width: number | undefined) => CSSProperties | undefined;
3
12
  export default getWidthStyle;
@@ -1,3 +1,12 @@
1
+ /**
2
+ * Given a number representing a width, returns a React CSSProperties object
3
+ * that sets the min-width and max-width CSS properties based on that number.
4
+ * Returns undefined if the input is undefined.
5
+ *
6
+ * @param width - the number representing the width, or undefined
7
+ *
8
+ * @internal
9
+ */
1
10
  const getWidthStyle = (width) => width === undefined
2
11
  ? undefined
3
12
  : {
@@ -1,5 +1 @@
1
1
  export * from "./datetime";
2
- export { default as getWidthStyle } from "./getWidthStyle";
3
- export { default as isSubset } from "./isSubset";
4
- export { default as trueModulo } from "./trueModulo";
5
- export { default as useControlledHover } from "./useControlledHover";
@@ -1,5 +1 @@
1
1
  export * from "./datetime";
2
- export { default as getWidthStyle } from "./getWidthStyle";
3
- export { default as isSubset } from "./isSubset";
4
- export { default as trueModulo } from "./trueModulo";
5
- export { default as useControlledHover } from "./useControlledHover";
@@ -1,2 +1,13 @@
1
- declare const isSubset: <T>(subset: T[], superSet: T[]) => boolean;
1
+ /**
2
+ * Determines whether the elements of an array is the subset of another.
3
+ *
4
+ * @param subset - an array that may be the subset of another set
5
+ * @param superset - an array that may be the superset of another set
6
+ *
7
+ * @returns a boolean value indicating whether the elements in subset are a
8
+ * subset of the elements in superset
9
+ *
10
+ * @internal
11
+ */
12
+ declare const isSubset: <T>(subset: T[], superset: T[]) => boolean;
2
13
  export default isSubset;
@@ -1,5 +1,16 @@
1
- const isSubset = (subset, superSet) => {
2
- const supersetSet = new Set(superSet);
1
+ /**
2
+ * Determines whether the elements of an array is the subset of another.
3
+ *
4
+ * @param subset - an array that may be the subset of another set
5
+ * @param superset - an array that may be the superset of another set
6
+ *
7
+ * @returns a boolean value indicating whether the elements in subset are a
8
+ * subset of the elements in superset
9
+ *
10
+ * @internal
11
+ */
12
+ const isSubset = (subset, superset) => {
13
+ const supersetSet = new Set(superset);
3
14
  for (const member of subset) {
4
15
  if (!supersetSet.has(member)) {
5
16
  return false;
@@ -1,2 +1,10 @@
1
+ /**
2
+ * Computes a mathematical modulo.
3
+ *
4
+ * @param num - to number to which to apply the modulo operator
5
+ * @param divisor - the divisor of the module operator
6
+ *
7
+ * @internal
8
+ */
1
9
  declare const trueModulo: (num: number, divisor: number) => number;
2
10
  export default trueModulo;
@@ -1,2 +1,10 @@
1
+ /**
2
+ * Computes a mathematical modulo.
3
+ *
4
+ * @param num - to number to which to apply the modulo operator
5
+ * @param divisor - the divisor of the module operator
6
+ *
7
+ * @internal
8
+ */
1
9
  const trueModulo = (num, divisor) => ((num % divisor) + divisor) % divisor;
2
10
  export default trueModulo;
@@ -5,5 +5,10 @@ export interface UseControlledHoverHook<T> {
5
5
  handleMouseOver: MouseEventHandler<T>;
6
6
  handleMouseOut: MouseEventHandler<T>;
7
7
  }
8
+ /**
9
+ * Implements React state-based hovering for an element.
10
+ *
11
+ * @internal
12
+ */
8
13
  declare const useControlledHover: <T>() => UseControlledHoverHook<T>;
9
14
  export default useControlledHover;
@@ -1,4 +1,9 @@
1
1
  import { useState } from "react";
2
+ /**
3
+ * Implements React state-based hovering for an element.
4
+ *
5
+ * @internal
6
+ */
2
7
  const useControlledHover = () => {
3
8
  const [isHovering, setIsHovering] = useState(false);
4
9
  const handleMouseOver = () => setIsHovering(true);
@@ -1,4 +1,15 @@
1
+ /**
2
+ * Grid cell coordinates based on ARIA row index and column index.
3
+ *
4
+ * @public
5
+ */
1
6
  export interface FocusCoordinates {
7
+ /**
8
+ * The ARIA row index.
9
+ */
2
10
  ariaRowIndex: number;
11
+ /**
12
+ * The ARIA column index.
13
+ */
3
14
  ariaColIndex: number;
4
15
  }
@@ -6,5 +6,5 @@ export interface GridFocusOutput {
6
6
  gridKeydownHandler: KeyboardEventHandler<HTMLDivElement>;
7
7
  }
8
8
  declare const useGridFocus: (gridRef: RefObject<HTMLDivElement | null>, numRows: number, // Number that includes the header row
9
- numCols: number) => GridFocusOutput;
9
+ numCols: number, sortableColIndices: number[]) => GridFocusOutput;
10
10
  export default useGridFocus;
@@ -3,7 +3,7 @@ const startingCoordinates = {
3
3
  ariaColIndex: 1,
4
4
  ariaRowIndex: 1,
5
5
  };
6
- const useGridFocus = (gridRef, numRows, numCols) => {
6
+ const useGridFocus = (gridRef, numRows, numCols, sortableColIndices) => {
7
7
  const [coords, setCoords] = useState(startingCoordinates);
8
8
  // Even though row and col count can be gotten from attributes, it needs to
9
9
  // be a prop here to update effective coordinates at the appropriate times.
@@ -11,9 +11,16 @@ const useGridFocus = (gridRef, numRows, numCols) => {
11
11
  ariaColIndex: Math.min(coords.ariaColIndex, numCols),
12
12
  ariaRowIndex: Math.min(coords.ariaRowIndex, numRows),
13
13
  }), [coords.ariaColIndex, coords.ariaRowIndex, numCols, numRows]);
14
+ const currentCellIsSortableHeader = useMemo(() => {
15
+ if (coords.ariaRowIndex !== 1) {
16
+ return false;
17
+ }
18
+ return sortableColIndices.includes(coords.ariaColIndex);
19
+ }, [coords.ariaColIndex, coords.ariaRowIndex, sortableColIndices]);
14
20
  const gridClickHandler = useCallback((event) => {
15
21
  let cursor = event.target;
16
- while (cursor !== event.currentTarget && !cursor.hasAttribute("aria-colindex")) {
22
+ while (cursor !== event.currentTarget &&
23
+ !cursor.hasAttribute("aria-colindex")) {
17
24
  cursor = cursor.parentElement;
18
25
  }
19
26
  if (!cursor.hasAttribute("aria-colindex")) {
@@ -116,15 +123,23 @@ const useGridFocus = (gridRef, numRows, numCols) => {
116
123
  if (!gridRef.current.contains(document.activeElement)) {
117
124
  return;
118
125
  }
119
- const elToFocus = gridRef.current.querySelector(`:scope > div > div[aria-rowindex="${effectiveCoords.ariaRowIndex}"] > div[aria-colindex="${effectiveCoords.ariaColIndex}"]`);
126
+ const cellSelector = `:scope > div > div[aria-rowindex="${effectiveCoords.ariaRowIndex}"] > div[aria-colindex="${effectiveCoords.ariaColIndex}"]`;
127
+ const elToFocus = gridRef.current.querySelector(currentCellIsSortableHeader
128
+ ? cellSelector + " .rbdg-grid-header-button"
129
+ : cellSelector);
120
130
  if (elToFocus !== document.activeElement) {
121
131
  elToFocus.focus({ preventScroll: true });
122
132
  }
123
- }, [effectiveCoords.ariaColIndex, effectiveCoords.ariaRowIndex, gridRef]);
133
+ }, [
134
+ effectiveCoords.ariaColIndex,
135
+ effectiveCoords.ariaRowIndex,
136
+ gridRef,
137
+ currentCellIsSortableHeader,
138
+ ]);
124
139
  return {
125
140
  effectiveCoords,
126
141
  gridClickHandler,
127
- gridKeydownHandler
142
+ gridKeydownHandler,
128
143
  };
129
144
  };
130
145
  export default useGridFocus;
@@ -1,4 +1,9 @@
1
1
  import { FC } from "react";
2
2
  import { GridProps } from "./types";
3
+ /**
4
+ * The main component for the grid feature of react-bootstrap-data-grid.
5
+ *
6
+ * @public
7
+ */
3
8
  declare const Grid: FC<GridProps>;
4
9
  export default Grid;
package/grid/main/Grid.js CHANGED
@@ -9,14 +9,16 @@ import GridBody from "./GridBody";
9
9
  import classNames from "classnames";
10
10
  import { CSS_PREFIX } from "../../common/constants";
11
11
  import useGridFocus from "../focus/useGridFocus";
12
- const Grid = ({ rows, cols, filterModel, sortModel, pagination, selectModel, width, height, variant, stripes, hover, borders, small, divider, borderVariant, headerCellVariant, headerRowVariant, bodyCellVariant, bodyRowVariant, headerCellFocusVariant, bodyCellFocusVariant }) => {
13
- const { displayRows, filteredRows } = useCombinedPipeline({
12
+ /**
13
+ * The main component for the grid feature of react-bootstrap-data-grid.
14
+ *
15
+ * @public
16
+ */
17
+ const Grid = ({ rows, cols, sortModel, width, height, variant, stripes, hover, borders, small, divider, borderVariant, headerCellVariant, headerRowVariant, bodyCellVariant, bodyRowVariant, headerCellFocusVariant, bodyCellFocusVariant, }) => {
18
+ const { displayRows, filteredRows, sortedRowsOutput } = useCombinedPipeline({
14
19
  rows,
15
20
  cols,
16
- filterModel,
17
21
  sortModel,
18
- pagination,
19
- selectModel,
20
22
  });
21
23
  const colNameToWidth = useColNameToWidth(cols);
22
24
  const augFormattedRows = useAugFormattedRows(colNameToWidth, displayRows);
@@ -46,7 +48,12 @@ const Grid = ({ rows, cols, filterModel, sortModel, pagination, selectModel, wid
46
48
  }, [width, height]);
47
49
  const vertScrollable = height !== undefined && height !== "auto";
48
50
  const gridRef = useRef(null);
49
- const { effectiveCoords, gridClickHandler, gridKeydownHandler } = useGridFocus(gridRef, rows.length + 1, cols.length);
51
+ const sortableColIndices = sortModel
52
+ ? cols
53
+ .map((_, index) => index + 1)
54
+ .filter((ariaColIndex) => cols[ariaColIndex - 1].sortable)
55
+ : [];
56
+ const { effectiveCoords, gridClickHandler, gridKeydownHandler } = useGridFocus(gridRef, rows.length + 1, cols.length, sortableColIndices);
50
57
  const onCopy = useCallback((event) => {
51
58
  var _a;
52
59
  if (!((_a = gridRef.current) === null || _a === void 0 ? void 0 : _a.contains(document.activeElement))) {
@@ -71,6 +78,6 @@ const Grid = ({ rows, cols, filterModel, sortModel, pagination, selectModel, wid
71
78
  "rbdg-grid-group-divider": !!divider,
72
79
  }, "rbdg-grid", variant && `${CSS_PREFIX}-${variant}`, borderVariant && `border-${borderVariant}`), role: "grid", "aria-colcount": cols.length, "aria-rowcount": filteredRows.length + 1, children: [_jsx(GridHeader, { cols: cols, rowVariant: headerRowVariant, cellVariant: headerCellVariant, vertScrollable: vertScrollable, focusColIndex: effectiveCoords.ariaRowIndex === 1
73
80
  ? effectiveCoords.ariaColIndex
74
- : null, cellFocusVariant: headerCellFocusVariant }), _jsx(GridBody, { focusCoords: effectiveCoords, augFormattedRows: augFormattedRows, cols: cols, rowVariant: bodyRowVariant, cellVariant: bodyCellVariant, cellFocusVariant: bodyCellFocusVariant })] }));
81
+ : null, cellFocusVariant: headerCellFocusVariant, sortInfo: sortedRowsOutput }), _jsx(GridBody, { focusCoords: effectiveCoords, augFormattedRows: augFormattedRows, cols: cols, rowVariant: bodyRowVariant, cellVariant: bodyCellVariant, cellFocusVariant: bodyCellFocusVariant })] }));
75
82
  };
76
83
  export default Grid;
@@ -1,4 +1,4 @@
1
1
  import { FC } from "react";
2
- import { GridBodyProps } from "./types";
2
+ import { GridBodyProps } from "./internalTypes";
3
3
  declare const GridBody: FC<GridBodyProps>;
4
4
  export default GridBody;
@@ -1,4 +1,4 @@
1
1
  import { FC } from "react";
2
- import { GridHeaderProps } from "./types";
2
+ import { GridHeaderProps } from "./internalTypes";
3
3
  declare const GridHeader: FC<GridHeaderProps>;
4
4
  export default GridHeader;
@@ -3,13 +3,40 @@ import getWidthStyles from "./getWidthStyles";
3
3
  import classNames from "classnames";
4
4
  import { CSS_PREFIX, DEFAULT_COL_WIDTH } from "../../common/constants";
5
5
  import { GRID_HEADER_DATA_TEST_ID } from "../constants";
6
- const GridHeader = ({ cols, vertScrollable, rowVariant, cellVariant, focusColIndex, cellFocusVariant }) => {
6
+ import HeaderToggleButton from "../sort/HeaderToggleButton";
7
+ import sortOrderToAriaSort from "../../common/sorting/sortOrderToAriaSort";
8
+ const GridHeader = ({ cols, vertScrollable, rowVariant, cellVariant, focusColIndex, cellFocusVariant, sortInfo, }) => {
9
+ const { sortingEnabled, sortColDef, setSortColDef } = sortInfo;
10
+ const getSortButtonListener = (colName) => () => {
11
+ if ((sortColDef === null || sortColDef === void 0 ? void 0 : sortColDef.name) !== colName) {
12
+ setSortColDef({
13
+ name: colName,
14
+ order: "asc",
15
+ });
16
+ return;
17
+ }
18
+ if (sortColDef.order === "asc") {
19
+ setSortColDef({
20
+ name: colName,
21
+ order: "desc",
22
+ });
23
+ return;
24
+ }
25
+ setSortColDef(null);
26
+ };
7
27
  return (_jsx("div", { "data-testid": GRID_HEADER_DATA_TEST_ID, role: "rowgroup", className: classNames(vertScrollable ? ["position-sticky", "z-1", "top-0"] : []), children: _jsx("div", { role: "row", className: classNames("d-flex", "flex-row", rowVariant && `${CSS_PREFIX}-${rowVariant}`), "aria-rowindex": 1, children: cols.map((col, index) => {
8
28
  const ariaColIndex = index + 1;
9
29
  const isFocused = focusColIndex === ariaColIndex;
10
30
  const cellVariantVal = cellVariant && cellVariant(col, index);
11
31
  const cellFocusVariantVal = cellFocusVariant && cellFocusVariant(col, index);
12
- return (_jsx("div", { tabIndex: isFocused ? 0 : -1, className: classNames("rbdg-grid-cell", "fw-bold", cellVariantVal && `${CSS_PREFIX}-${cellVariantVal}`, cellFocusVariantVal && `focus-ring-${cellFocusVariantVal}`, { "z-2": isFocused, "rbdg-focusable-cell": isFocused }), role: "columnheader", "aria-colindex": ariaColIndex, style: getWidthStyles(col.width || DEFAULT_COL_WIDTH), children: col.label }, col.name));
32
+ const currentColSortingEnabled = sortingEnabled && col.sortable;
33
+ return (_jsx("div", { tabIndex: isFocused && !currentColSortingEnabled ? 0 : -1, className: classNames("rbdg-grid-cell", "fw-bold", cellVariantVal && `${CSS_PREFIX}-${cellVariantVal}`, cellFocusVariantVal && `focus-ring-${cellFocusVariantVal}`, {
34
+ "z-2": isFocused,
35
+ "rbdg-focusable-cell": isFocused && !currentColSortingEnabled,
36
+ "rbdg-sortable-header-cell": currentColSortingEnabled,
37
+ }), role: "columnheader", "aria-colindex": ariaColIndex, "aria-sort": currentColSortingEnabled && (sortColDef === null || sortColDef === void 0 ? void 0 : sortColDef.name) === col.name
38
+ ? sortOrderToAriaSort(sortColDef.order)
39
+ : undefined, style: getWidthStyles(col.width || DEFAULT_COL_WIDTH), children: currentColSortingEnabled ? (_jsx(HeaderToggleButton, { tabIndex: isFocused ? 0 : -1, colLabel: col.label, sortOrder: (sortColDef === null || sortColDef === void 0 ? void 0 : sortColDef.name) === col.name ? sortColDef.order : null, onClick: getSortButtonListener(col.name) })) : (col.label) }, col.name));
13
40
  }) }) }));
14
41
  };
15
42
  export default GridHeader;