-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6220 from Sage/FE-6050-refactor-ft
feat(flat-table, flat-table-row): components can now be wrapped, subRows no longer need to be arrays FE-6050
- Loading branch information
Showing
26 changed files
with
1,116 additions
and
1,081 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
18 changes: 18 additions & 0 deletions
18
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,18 @@ | ||
export default ( | ||
array: HTMLElement[], | ||
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][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"; |
32 changes: 32 additions & 0 deletions
32
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,32 @@ | ||
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, | ||
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.