-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add token representing the height of the table with all rows visible (#…
…2307) # Pull Request ## 🤨 Rationale Resolves #1624 ## 👩💻 Implementation The table already knows the combined height of all the rows in the table because it uses this value to size the `table-scroll` container. Therefore, I was able to create a token that gets assigned a value within the scope of the table styling that has a value of the size of the height the table needs to show all rows. The token's name is `tableFitRowsHeight`. The table also now sets a default max-height on itself to keep a client from accidentally using `tableFitRowsHeight` and trying to render thousands of rows at once. To use the new token, a client would create their table exactly as before and add the following style: ```scss nimble-table { height: $ni-nimble-table-fit-rows-height; } ``` ## 🧪 Testing - Manually tested in storybook - Wrote chromatic tests that verify the height of the table is correct when its height is set to the new token value when: - There are 5 records, with & without grouping - There are 10 records, with & without grouping - There are 50 records, with & without grouping ## ✅ Checklist <!--- Review the list and put an x in the boxes that apply or ~~strike through~~ around items that don't (along with an explanation). --> - [ ] I have updated the project documentation to reflect my changes or determined no changes are needed. --------- Co-authored-by: Milan Raj <[email protected]>
- Loading branch information
1 parent
a1809d6
commit dc9d005
Showing
14 changed files
with
241 additions
and
17 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@ni-nimble-components-a5fd15e6-373b-4e3c-b562-fc2e440df26c.json
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,7 @@ | ||
{ | ||
"type": "major", | ||
"comment": "Create token representing the table's height with all rows visible; **Breaking change:** the table now specifies a max-height; if a different max-height is required, it needs to be configured.", | ||
"packageName": "@ni/nimble-components", | ||
"email": "[email protected]", | ||
"dependentChangeType": "major" | ||
} |
7 changes: 7 additions & 0 deletions
7
change/@ni-nimble-tokens-2857f29e-c895-406b-a302-78a6ca683d9d.json
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,7 @@ | ||
{ | ||
"type": "minor", | ||
"comment": "Create token representing the table's height with all rows visible", | ||
"packageName": "@ni/nimble-tokens", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
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
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
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
86 changes: 86 additions & 0 deletions
86
packages/storybook/src/nimble/table/table-fit-rows-height-matrix.stories.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,86 @@ | ||
import type { Meta, StoryFn } from '@storybook/html'; | ||
import { html, ViewTemplate } from '@microsoft/fast-element'; | ||
import { tableColumnTextTag } from '../../../../nimble-components/src/table-column/text'; | ||
import { Table, tableTag } from '../../../../nimble-components/src/table'; | ||
import type { TableRecord } from '../../../../nimble-components/src/table/types'; | ||
import { tableFitRowsHeight } from '../../../../nimble-components/src/theme-provider/design-tokens'; | ||
import { createFixedThemeStory } from '../../utilities/storybook'; | ||
import { createMatrix, sharedMatrixParameters } from '../../utilities/matrix'; | ||
import { backgroundStates } from '../../utilities/states'; | ||
|
||
interface SimpleData extends TableRecord { | ||
firstName: string; | ||
lastName: string; | ||
favoriteColor: string; | ||
} | ||
|
||
const data: SimpleData[] = []; | ||
for (let i = 0; i < 50; i++) { | ||
data.push({ | ||
firstName: `First Name ${i}`, | ||
lastName: `Last Name ${i}`, | ||
favoriteColor: `Favorite Color ${i}` | ||
}); | ||
} | ||
|
||
const groupingStates = [ | ||
['Not Grouped', undefined], | ||
['Grouped', 0] | ||
] as const; | ||
type GroupingState = (typeof groupingStates)[number]; | ||
|
||
const metadata: Meta = { | ||
title: 'Tests/Table', | ||
parameters: { | ||
...sharedMatrixParameters() | ||
} | ||
}; | ||
|
||
export default metadata; | ||
|
||
// prettier-ignore | ||
const component = ( | ||
[_groupingName, groupIndex]: GroupingState | ||
): ViewTemplate => html` | ||
<style> | ||
${tableTag} { | ||
height: var(${tableFitRowsHeight.cssCustomProperty}); | ||
margin-bottom: 20px; | ||
} | ||
</style> | ||
<${tableTag}> | ||
<${tableColumnTextTag} field-name="firstName" group-index="${() => groupIndex}">First Name</${tableColumnTextTag}> | ||
<${tableColumnTextTag} field-name="lastName">Last Name</${tableColumnTextTag}> | ||
<${tableColumnTextTag} field-name="favoriteColor">Favorite Color</${tableColumnTextTag}> | ||
</${tableTag}> | ||
`; | ||
|
||
const playFunction = async (rowCount: number): Promise<void> => { | ||
const tableData = data.slice(0, rowCount); | ||
await Promise.all( | ||
Array.from(document.querySelectorAll<Table>(tableTag)).map( | ||
async table => { | ||
await table.setData(tableData); | ||
} | ||
) | ||
); | ||
}; | ||
|
||
export const tableFitRowsHeightWith5Rows: StoryFn = createFixedThemeStory( | ||
createMatrix(component, [groupingStates]), | ||
backgroundStates[0] | ||
); | ||
|
||
tableFitRowsHeightWith5Rows.play = async () => playFunction(5); | ||
|
||
export const tableFitRowsHeightWith10Rows: StoryFn = createFixedThemeStory( | ||
createMatrix(component, [groupingStates]), | ||
backgroundStates[0] | ||
); | ||
tableFitRowsHeightWith10Rows.play = async () => playFunction(10); | ||
|
||
export const tableFitRowsHeightWith50Rows: StoryFn = createFixedThemeStory( | ||
createMatrix(component, [groupingStates]), | ||
backgroundStates[0] | ||
); | ||
tableFitRowsHeightWith50Rows.play = async () => playFunction(50); |
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.