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

feat 1265: Grid summary compact #2250

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 2 additions & 3 deletions src/layout/Grid/GridSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ import type {
ITableColumnProperties,
} from 'src/layout/common.generated';
import type { ITextResourceBindings } from 'src/layout/layout';
import type { GridSummaryOverrideProps } from 'src/layout/Summary2/config.generated';
import type { BaseLayoutNode, LayoutNode } from 'src/utils/layout/LayoutNode';

type GridSummaryProps = {
componentNode: LayoutNode<'Grid'>;
summaryOverrides?: GridSummaryOverrideProps;
};

export const GridSummary = ({ componentNode }: GridSummaryProps) => {
const { rows, textResourceBindings } = componentNode.item;
const { title } = textResourceBindings ?? {};

const columnSettings: ITableColumnFormatting = {};
const isMobile = useIsMobile();
const pdfModeActive = usePdfModeActive();

const isSmall = isMobile && !pdfModeActive;

const tableSections: JSX.Element[] = [];
Expand Down Expand Up @@ -156,7 +156,6 @@ export function GridRowRenderer({ row, mutableColumnSettings, node, currentHeade
const pdfModeActive = usePdfModeActive();

const isSmall = isMobile && !pdfModeActive;

const firstComponentCell = row.cells.find((cell) => cell && 'node' in cell);
const firstComponentNode =
firstComponentCell &&
Expand Down
15 changes: 15 additions & 0 deletions src/layout/Grid/config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
import { CG } from 'src/codegen/CG';
import { CompCategory } from 'src/layout/common';

export const GRID_SUMMARY_PROPS = new CG.obj(
new CG.prop(
'isCompact',
new CG.bool()
.optional()
.setTitle('Compact summary')
.setDescription('Boolean value indicating if the summary should be compact'),
),
)
.extends(CG.common('ISummaryOverridesCommon'))
.optional()
.setTitle('Summary properties')
.setDescription('Properties for how to display the summary of the component')
.exportAs('GridSummaryOverrideProps');

export const Config = new CG.component({
category: CompCategory.Container,
rendersWithLabel: false,
Expand Down
10 changes: 8 additions & 2 deletions src/layout/Grid/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { GridHierarchyGenerator } from 'src/layout/Grid/hierarchy';
import type { PropsFromGenericComponent } from 'src/layout';
import type { CompExternalExact } from 'src/layout/layout';
import type { SummaryRendererProps } from 'src/layout/LayoutComponent';
import type { GridSummaryOverrideProps } from 'src/layout/Summary2/config.generated';
import type { ComponentHierarchyGenerator } from 'src/utils/layout/HierarchyGenerator';
import type { LayoutNode } from 'src/utils/layout/LayoutNode';

Expand All @@ -27,8 +28,13 @@ export class Grid extends GridDef {
return <GridSummaryComponent {...props} />;
}

renderSummary2(componentNode: LayoutNode<'Grid'>): JSX.Element | null {
return <GridSummary componentNode={componentNode} />;
renderSummary2(componentNode: LayoutNode<'Grid'>, summaryOverrides?: GridSummaryOverrideProps): JSX.Element | null {
return (
<GridSummary
componentNode={componentNode}
summaryOverrides={summaryOverrides}
/>
);
}

renderSummaryBoilerplate(): boolean {
Expand Down
7 changes: 3 additions & 4 deletions src/layout/Group/GroupSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ import type { HeadingProps } from '@digdir/designsystemet-react';

import classes from 'src/layout/Group/GroupSummary.module.css';
import { ComponentSummary } from 'src/layout/Summary2/SummaryComponent2/ComponentSummary';
import type { CompGroupInternal } from 'src/layout/Group/config.generated';
import type { CompSummary2Internal } from 'src/layout/Summary2/config.generated';
import type { GroupSummaryOverrideProps } from 'src/layout/Summary2/config.generated';
import type { LayoutNode } from 'src/utils/layout/LayoutNode';

type GroupComponentSummaryProps = {
componentNode: LayoutNode<'Group'>;
hierarchyLevel?: number;
summaryOverrides?: CompGroupInternal['summaryProps'] | CompSummary2Internal['overrides'];
summaryOverrides?: GroupSummaryOverrideProps;
};

type HeadingLevel = HeadingProps['level'];
Expand Down Expand Up @@ -43,7 +42,7 @@ const RenderChildComponents = ({ componentNode, hierarchyLevel, summaryOverrides
componentNode={child as LayoutNode<'Group'>}
hierarchyLevel={hierarchyLevel ? hierarchyLevel + 1 : 1}
key={componentNode.item.id}
summaryOverrides={summaryOverrides as CompGroupInternal['summaryProps']}
summaryOverrides={summaryOverrides as GroupSummaryOverrideProps}
/>
);
} else {
Expand Down
3 changes: 1 addition & 2 deletions src/layout/Group/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,5 +68,4 @@ export const Config = new CG.component({
.setTitle('Heading level')
.setDescription('The heading level of the group title.'),
),
)
.addProperty(new CG.prop('summaryProps', GROUP_SUMMARY_PROPS).onlyIn(Variant.Internal));
);
7 changes: 2 additions & 5 deletions src/layout/Group/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import { SummaryGroupComponent } from 'src/layout/Group/SummaryGroupComponent';
import type { LayoutValidationCtx } from 'src/features/devtools/layoutValidation/types';
import type { ComponentValidation, ValidationDataSources } from 'src/features/validation';
import type { PropsFromGenericComponent, ValidateComponent } from 'src/layout';
import type { CompGroupInternal } from 'src/layout/Group/config.generated';
import type { SummaryRendererProps } from 'src/layout/LayoutComponent';
import type { GroupSummaryOverrideProps } from 'src/layout/Summary2/config.generated';
import type { ComponentHierarchyGenerator } from 'src/utils/layout/HierarchyGenerator';
import type { LayoutNode } from 'src/utils/layout/LayoutNode';

Expand Down Expand Up @@ -57,10 +57,7 @@ export class Group extends GroupDef implements ValidateComponent {
);
}

renderSummary2(
componentNode: LayoutNode<'Group'>,
summaryOverrides?: CompGroupInternal['summaryProps'],
): JSX.Element | null {
renderSummary2(componentNode: LayoutNode<'Group'>, summaryOverrides?: GroupSummaryOverrideProps): JSX.Element | null {
return (
<GroupSummary
componentNode={componentNode}
Expand Down
4 changes: 4 additions & 0 deletions src/layout/Summary2/config.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { CG } from 'src/codegen/CG';
import { CHECKBOX_SUMMARY_OVERRIDE_PROPS } from 'src/layout/Checkboxes/config';
import { CompCategory } from 'src/layout/common';
import { DROPDOWN_SUMMARY_OVERRIDE_PROPS } from 'src/layout/Dropdown/config';
import { GRID_SUMMARY_PROPS } from 'src/layout/Grid/config';
import { GROUP_SUMMARY_PROPS } from 'src/layout/Group/config';
import { INPUT_SUMMARY_OVERRIDE_PROPS } from 'src/layout/Input/config';
import { MULTIPLE_SELECT_SUMMARY_OVERRIDE_PROPS } from 'src/layout/MultipleSelect/config';
import { RADIO_SUMMARY_OVERRIDE_PROPS } from 'src/layout/RadioButtons/config';
Expand Down Expand Up @@ -50,6 +52,8 @@ export const Config = new CG.component({
RADIO_SUMMARY_OVERRIDE_PROPS,
DROPDOWN_SUMMARY_OVERRIDE_PROPS,
MULTIPLE_SELECT_SUMMARY_OVERRIDE_PROPS,
GROUP_SUMMARY_PROPS,
GRID_SUMMARY_PROPS,
),
).optional(),
),
Expand Down
Loading