-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(flat-table, flat-table-row): components can now be wrapped, subR…
…ows no longer need to be arrays Refactors `FlatTable` and sub-components to allow consumers greater flexibility with respect to wrapping the components by removing code that relied on iterating over children and cloning. Refactors `FlatTableRow` so that it is no longer required that an array is passed to the `subRows` prop. fix #6219
- Loading branch information
Showing
25 changed files
with
1,153 additions
and
1,092 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/components/flat-table/__internal__/build-position-map.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export default ( | ||
array: Element[], | ||
propertyName: "offsetWidth" | "offsetHeight" | ||
) => | ||
array.reduce((acc: Record<string, number>, _, index) => { | ||
const currentId = array[index].getAttribute("id"); | ||
if (currentId) { | ||
if (index === 0) { | ||
acc[currentId] = 0; | ||
} else { | ||
const previousId = array[index - 1].getAttribute("id"); | ||
if (previousId) { | ||
acc[currentId] = | ||
acc[previousId] + | ||
(array[index - 1] as HTMLTableCellElement)[propertyName]; | ||
} | ||
} | ||
} | ||
return acc; | ||
}, {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export { default as useCalculateStickyCells } from "./use-calculate-sticky-cells"; | ||
export { default as buildPositionMap } from "./build-position-map"; |
34 changes: 34 additions & 0 deletions
34
src/components/flat-table/__internal__/use-calculate-sticky-cells.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useContext } from "react"; | ||
import FlatTableRowContext from "../flat-table-row/__internal__/flat-table-row-context"; | ||
|
||
export default (id: string) => { | ||
const { | ||
expandable, | ||
firstCellId, | ||
firstColumnExpandable, | ||
leftPositions, | ||
rightPositions, | ||
onClick, | ||
onKeyDown, | ||
} = useContext(FlatTableRowContext); | ||
|
||
const leftPosition = leftPositions[id]; | ||
const rightPosition = rightPositions[id]; | ||
const makeCellSticky = | ||
leftPosition !== undefined || rightPosition !== undefined; | ||
const isFirstCell = id === firstCellId; | ||
const isExpandableCell = expandable && isFirstCell && firstColumnExpandable; | ||
|
||
return { | ||
expandable, | ||
firstCellId, | ||
firstColumnExpandable, | ||
leftPosition, | ||
rightPosition, | ||
makeCellSticky, | ||
onClick, | ||
onKeyDown, | ||
isFirstCell, | ||
isExpandableCell, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.