Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add token representing the height of the table with all rows visible #2307

Merged
merged 32 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d1e3ecb
Add attribute to make the table height fit to the number of rows
mollykreis Jul 25, 2024
2c26840
format
mollykreis Jul 25, 2024
c5f9c51
another attempt
mollykreis Jul 26, 2024
8ad460e
revert indention change
mollykreis Jul 26, 2024
923dfd5
rename attr
mollykreis Jul 26, 2024
3d6cf42
Change files
mollykreis Jul 26, 2024
267bae3
format
mollykreis Jul 26, 2024
b4b5e01
update comment
mollykreis Jul 29, 2024
379a784
Merge branch 'main' into table-height-styling
mollykreis Jul 29, 2024
989fe87
Merge branch 'main' into table-height-styling
mollykreis Aug 2, 2024
f752f36
allow table to be resizable in storybook
mollykreis Aug 5, 2024
4f96f3f
Merge branch 'main' into table-height-styling
mollykreis Aug 5, 2024
2984d39
Merge branch 'main' into table-height-styling
mollykreis Aug 14, 2024
0725093
token approach
mollykreis Aug 14, 2024
c75386e
updates
mollykreis Aug 14, 2024
837ee91
format
mollykreis Aug 14, 2024
4a740ce
fix import
mollykreis Aug 14, 2024
5e9ebe2
Merge branch 'main' into table-height-styling
mollykreis Aug 15, 2024
ed7a52b
Update docs, matrix story, rename token
mollykreis Aug 15, 2024
c280ac0
fixes
mollykreis Aug 15, 2024
4aec225
lint
mollykreis Aug 15, 2024
cdb2412
Merge branch 'main' into table-height-styling
mollykreis Aug 19, 2024
655811c
updates
mollykreis Aug 19, 2024
542bca2
unset -> none
mollykreis Aug 19, 2024
7d79ab4
Merge branch 'main' into table-height-styling
mollykreis Aug 20, 2024
47dc49d
PR feedback
mollykreis Aug 20, 2024
5a1808c
format
mollykreis Aug 20, 2024
f03a2b1
Change files
mollykreis Aug 20, 2024
1a65984
Update @ni-nimble-components-a5fd15e6-373b-4e3c-b562-fc2e440df26c.json
mollykreis Aug 20, 2024
a42e965
Update change/@ni-nimble-components-a5fd15e6-373b-4e3c-b562-fc2e440df…
rajsite Aug 20, 2024
ba3b6c3
Update change/@ni-nimble-components-a5fd15e6-373b-4e3c-b562-fc2e440df…
rajsite Aug 20, 2024
ea03b29
Merge branch 'main' into table-height-styling
rajsite Aug 23, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
mollykreis marked this conversation as resolved.
Show resolved Hide resolved
"type": "minor",
mollykreis marked this conversation as resolved.
Show resolved Hide resolved
"comment": "Add attribute to the table to make its height automatically adjust to the number of rows",
"packageName": "@ni/nimble-components",
"email": "[email protected]",
"dependentChangeType": "patch"
}
3 changes: 3 additions & 0 deletions packages/nimble-components/src/table/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ export class Table<
@attr({ attribute: 'selection-mode' })
public selectionMode: TableRowSelectionMode = TableRowSelectionMode.none;

@attr({ attribute: 'auto-height', mode: 'boolean' })
public autoHeight = false;

/**
* @internal
*/
Expand Down
25 changes: 24 additions & 1 deletion packages/nimble-components/src/table/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ import {
mediumPadding,
standardPadding,
tableRowBorderColor,
borderHoverColor
borderHoverColor,
controlHeight
} from '../theme-provider/design-tokens';
import { Theme } from '../theme-provider/types';
import { hexToRgbaCssColor } from '../utilities/style/colors';
Expand All @@ -25,10 +26,24 @@ export const styles = css`

:host {
height: 480px;
${
/**
* Set a default maximum height for the table of 250 rows (including the header row) so
* that clients don't accidentally create a table that tries to render too many rows at once.
* If needed, the max-height can be overridden by the client, but setting a default ensures
* that the max-height is considered if a larger one is needed rather than being overlooked.
*/ ''
}
max-height: calc(250 * ${controlHeight});
mollykreis marked this conversation as resolved.
Show resolved Hide resolved
flex-direction: column;
--ni-private-column-divider-width: 2px;
--ni-private-column-divider-padding: 3px;
}

:host([auto-height]) {
height: auto;
}

:host(${focusVisible}) {
${
/* The table can briefly be focused in some keyboard nav cases (e.g. regaining focus and we
Expand All @@ -51,6 +66,14 @@ export const styles = css`
font: ${bodyFont};
color: ${bodyFontColor};
cursor: var(--ni-private-table-cursor-override);
flex-grow: 1;
flex-shrink: 1;
}

:host([auto-height]) .table-container {
flex-basis: calc(
var(--ni-private-table-scroll-height) + ${controlHeight}
);
}

.glass-overlay {
Expand Down
18 changes: 18 additions & 0 deletions packages/storybook/src/nimble/table/table.stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ interface TableArgs extends BaseTableArgs {
selectionChange: undefined;
columnConfigurationChange: undefined;
rowExpandToggle: undefined;
autoHeight: boolean;
resizable: boolean;
}

const simpleData = [
Expand Down Expand Up @@ -272,6 +274,8 @@ export const table: StoryObj<TableArgs> = {
id-field-name="id"
data-unused="${x => x.updateData(x)}"
parent-id-field-name="parentId"
?auto-height="${x => x.autoHeight}"
style="${x => x.resizable && 'resize: both; overflow: hidden;'}"
>
<${tableColumnTextTag}
column-id="first-name-column"
Expand Down Expand Up @@ -482,6 +486,18 @@ export const table: StoryObj<TableArgs> = {
'Event emitted when the user expands or collapses a row in a table with hierarchy. This does not emit when group rows are expanded or collapsed.',
control: false,
table: { category: apiCategory.events }
},
autoHeight: {
name: 'auto-height',
description:
'When set to `true`, the table will automatically adjust its height to fit the number of rows in the table.',
table: { category: apiCategory.attributes }
},
resizable: {
name: 'resizable',
description:
'Not a property on the table -- temporarily added to demonstrate how the table behaves when `resize: both` is set on the table element.',
table: { category: apiCategory.attributes }
}
},
args: {
Expand All @@ -491,6 +507,8 @@ export const table: StoryObj<TableArgs> = {
validity: undefined,
checkValidity: undefined,
tableRef: undefined,
autoHeight: false,
resizable: false,
updateData: x => {
void (async () => {
// Safari workaround: the table element instance is made at this point
Expand Down