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

[Table] ExpandableRow contentGutter-prop #3507

Merged
merged 4 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions .changeset/swift-lions-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@navikt/ds-react": minor
"@navikt/ds-css": minor
---

Table: New prop `contentGutter` added to `ExpandableRow`-component. This allows user more control for content layout inside expandable element.
22 changes: 20 additions & 2 deletions @navikt/core/css/darkside/table.darkside.css
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,27 @@
}

.navds-table__expanded-row-content {
padding: var(--ax-space-16) calc(var(--ax-space-8) + 3rem);
--__ac-table-expanded-row-pi: calc(var(--ax-space-8) + 3rem);

padding-block: var(--ax-space-16);
}

.navds-table--small .navds-table__expanded-row-content {
padding: var(--ax-space-8) calc(var(--ax-space-8) + 3rem);
padding-block: var(--ax-space-8);
}

.navds-table__expanded-row-content--gutter-both {
padding-inline: var(--__ac-table-expanded-row-pi);
}

.navds-table__expanded-row-content--gutter-left {
padding-inline: var(--__ac-table-expanded-row-pi) var(--ax-space-8);
}

.navds-table__expanded-row-content--gutter-right {
padding-inline: var(--ax-space-8) var(--__ac-table-expanded-row-pi);
}

.navds-table__expanded-row-content--gutter-none {
padding-inline: var(--ax-space-8);
}
22 changes: 20 additions & 2 deletions @navikt/core/css/table.css
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,29 @@
}

.navds-table__expanded-row-content {
padding: var(--a-spacing-4) calc(var(--a-spacing-2) + 3rem);
--__ac-table-expanded-row-pi: calc(var(--a-spacing-2) + 3rem);

padding-block: var(--a-spacing-4);
}

.navds-table--small .navds-table__expanded-row-content {
padding: var(--a-spacing-2) calc(var(--a-spacing-2) + 3rem);
padding-block: var(--a-spacing-2);
}

.navds-table__expanded-row-content--gutter-both {
padding-inline: var(--__ac-table-expanded-row-pi);
}

.navds-table__expanded-row-content--gutter-left {
padding-inline: var(--__ac-table-expanded-row-pi) var(--a-spacing-2);
}

.navds-table__expanded-row-content--gutter-right {
padding-inline: var(--a-spacing-2) var(--__ac-table-expanded-row-pi);
}

.navds-table__expanded-row-content--gutter-none {
padding-inline: var(--a-spacing-2);
}

@media (forced-colors: active) {
Expand Down
10 changes: 9 additions & 1 deletion @navikt/core/react/src/table/ExpandableRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ export interface ExpandableRowProps extends Omit<RowProps, "content"> {
* @default 999
*/
colSpan?: number;
/**
* Optional left, right-gutter for content
* @default Same as `togglePlacement`
*/
contentGutter?: "left" | "right" | "none";
}

export type ExpandableRowType = React.ForwardRefExoticComponent<
Expand All @@ -67,6 +72,7 @@ export const ExpandableRow: ExpandableRowType = forwardRef(
expansionDisabled = false,
expandOnRowClick = false,
colSpan = 999,
contentGutter,
onClick,
...rest
},
Expand Down Expand Up @@ -139,7 +145,9 @@ export const ExpandableRow: ExpandableRowType = forwardRef(
<td colSpan={colSpan} className="navds-table__expanded-row-cell">
<AnimateHeight
className="navds-table__expanded-row-collapse"
innerClassName="navds-table__expanded-row-content"
innerClassName={`navds-table__expanded-row-content navds-table__expanded-row-content--gutter-${
contentGutter ?? togglePlacement
}`}
height={_open ? "auto" : 0}
duration={150}
easing="cubic-bezier(0.39,0.57,0.56,1)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,68 @@ export const ExpandableSmall = () => {
);
};

export const ExpandableContentGutter = () => {
return (
<Table zebraStripes>
<Table.Header>
<Table.Row>
<Table.HeaderCell></Table.HeaderCell>
<Table.HeaderCell>Cell</Table.HeaderCell>
<Table.HeaderCell>Cell</Table.HeaderCell>
<Table.HeaderCell></Table.HeaderCell>
</Table.Row>
</Table.Header>
<Table.Body>
<Table.ExpandableRow
defaultOpen
content="ContentContent ContentContent ContentContent"
togglePlacement="left"
>
<Table.DataCell>Cell</Table.DataCell>
<Table.DataCell>Cell</Table.DataCell>
<Table.DataCell>Cell</Table.DataCell>
</Table.ExpandableRow>
<Table.ExpandableRow
content="ContentContent ContentContent ContentContent"
togglePlacement="right"
defaultOpen
>
<Table.DataCell>Cell</Table.DataCell>
<Table.DataCell>Cell</Table.DataCell>
<Table.DataCell>Cell</Table.DataCell>
</Table.ExpandableRow>
<Table.ExpandableRow
content="ContentContent ContentContent ContentContent"
defaultOpen
contentGutter="left"
>
<Table.DataCell>Cell</Table.DataCell>
<Table.DataCell>Cell</Table.DataCell>
<Table.DataCell>Cell</Table.DataCell>
</Table.ExpandableRow>
<Table.ExpandableRow
content="ContentContent ContentContent ContentContent"
defaultOpen
contentGutter="right"
>
<Table.DataCell>Cell</Table.DataCell>
<Table.DataCell>Cell</Table.DataCell>
<Table.DataCell>Cell</Table.DataCell>
</Table.ExpandableRow>
<Table.ExpandableRow
content="ContentContent ContentContent ContentContent Con.."
defaultOpen
contentGutter="none"
>
<Table.DataCell>Cell</Table.DataCell>
<Table.DataCell>Cell</Table.DataCell>
<Table.DataCell>Cell</Table.DataCell>
</Table.ExpandableRow>
</Table.Body>
</Table>
);
};

const columns = [
{
name: "Navn",
Expand Down
Loading