Skip to content

Commit 1388b02

Browse files
benjamindehliadamhaegerMagnusrmAdam Haeger
authored
Feat/2062 group (#2208)
* Add support for compact display type for groups * chore: renamed compact to isCompact --------- Co-authored-by: Adam Haeger <adamgullerud@gmail.com> Co-authored-by: Magnus Revheim Martinsen <mrmartinsen.96@gmail.com> Co-authored-by: Adam Haeger <adam.haeger@Adams-MacBook-Pro-2.local>
1 parent 26ae88e commit 1388b02

File tree

12 files changed

+111
-46
lines changed

12 files changed

+111
-46
lines changed

src/layout/Checkboxes/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export class Checkboxes extends CheckboxesDef {
5252
renderSummary2(
5353
componentNode: LayoutNode<'Checkboxes'>,
5454
summaryOverrides?: CheckboxSummaryOverrideProps,
55+
isCompact?: boolean,
5556
): JSX.Element | null {
5657
const displayData = this.useDisplayData(componentNode);
5758
const maxStringLength = 75;
@@ -64,6 +65,7 @@ export class Checkboxes extends CheckboxesDef {
6465
title={<Lang id={title} />}
6566
componentNode={componentNode}
6667
showAsList={showAsList}
68+
isCompact={isCompact}
6769
/>
6870
);
6971
}

src/layout/Group/GroupSummary.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,19 @@ const RenderChildComponents = ({ componentNode, hierarchyLevel, summaryOverrides
4343
componentNode={child as LayoutNode<'Group'>}
4444
hierarchyLevel={hierarchyLevel ? hierarchyLevel + 1 : 1}
4545
key={componentNode.item.id}
46+
summaryOverrides={summaryOverrides as CompGroupInternal['summaryProps']}
4647
/>
4748
);
4849
} else {
50+
const isCompact = summaryOverrides?.['isCompact'];
4951
return (
5052
<div
5153
key={child?.item?.id}
5254
className={cn(classes.childItem)}
5355
>
5456
<ComponentSummary
5557
componentNode={child}
56-
summaryOverrides={summaryOverrides as CompSummary2Internal['overrides']}
58+
isCompact={isCompact}
5759
/>
5860
</div>
5961
);
@@ -68,6 +70,7 @@ export const GroupSummary = ({ componentNode, hierarchyLevel = 0, summaryOverrid
6870
const headingLevel = getHeadingLevel(hierarchyLevel);
6971
const isGroup = componentNode.item.type === 'Group';
7072
const isNestedGroup = isGroup && hierarchyLevel > 0;
73+
7174
return (
7275
<section className={isNestedGroup ? cn(classes.groupContainer, classes.nested) : cn(classes.groupContainer)}>
7376
<div className={cn(classes.groupHeading)}>

src/layout/Group/config.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
import { CG, Variant } from 'src/codegen/CG';
22
import { CompCategory } from 'src/layout/common';
33

4-
export const GROUP_SUMMARY_PROPS = new CG.obj()
4+
export const GROUP_SUMMARY_PROPS = new CG.obj(
5+
new CG.prop(
6+
'isCompact',
7+
new CG.bool()
8+
.optional()
9+
.setTitle('Compact summary')
10+
.setDescription('Boolean value indicating if the summary should be compact'),
11+
),
12+
)
513
.extends(CG.common('ISummaryOverridesCommon'))
614
.optional()
715
.setTitle('Summary properties')
8-
.setDescription('Properties for how to display the summary of the component');
16+
.setDescription('Properties for how to display the summary of the component')
17+
.exportAs('GroupSummaryOverrideProps');
918

1019
export const Config = new CG.component({
1120
category: CompCategory.Container,

src/layout/Input/InputSummary.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@ import { Lang } from 'src/features/language/Lang';
44
import { useUnifiedValidationsForNode } from 'src/features/validation/selectors/unifiedValidationsForNode';
55
import { validationsOfSeverity } from 'src/features/validation/utils';
66
import { SingleValueSummary } from 'src/layout/Summary2/CommonSummaryComponents/SingleValueSummary';
7-
import type { InputSummaryOverrideProps } from 'src/layout/Summary2/config.generated';
87
import type { LayoutNode } from 'src/utils/layout/LayoutNode';
98

109
type InputComponentSummaryProps = {
10+
isCompact?: boolean;
1111
componentNode: LayoutNode<'Input'>;
1212
displayData: string;
13-
summaryOverrides?: InputSummaryOverrideProps;
1413
};
15-
export const InputSummary = ({ componentNode, displayData }: InputComponentSummaryProps) => {
14+
export const InputSummary = ({ componentNode, displayData, isCompact }: InputComponentSummaryProps) => {
1615
const validations = useUnifiedValidationsForNode(componentNode);
1716
const errors = validationsOfSeverity(validations, 'error');
1817
const title = componentNode.item.textResourceBindings?.title;
@@ -23,6 +22,7 @@ export const InputSummary = ({ componentNode, displayData }: InputComponentSumma
2322
displayData={displayData}
2423
errors={errors}
2524
componentNode={componentNode}
25+
isCompact={isCompact}
2626
/>
2727
);
2828
};

src/layout/Input/index.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,16 @@ export class Input extends InputDef {
4646
return <SummaryItemSimple formDataAsString={displayData} />;
4747
}
4848

49-
renderSummary2(componentNode: LayoutNode<'Input'>, summaryOverrides?: InputSummaryOverrideProps): JSX.Element | null {
49+
renderSummary2(
50+
componentNode: LayoutNode<'Input'>,
51+
_?: InputSummaryOverrideProps,
52+
isCompact?: boolean,
53+
): JSX.Element | null {
5054
return (
5155
<InputSummary
5256
componentNode={componentNode}
53-
summaryOverrides={summaryOverrides}
5457
displayData={this.useDisplayData(componentNode)}
58+
isCompact={isCompact}
5559
/>
5660
);
5761
}

src/layout/RadioButtons/RadioButtonsSummary.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import type { RadioSummaryOverrideProps } from 'src/layout/Summary2/config.gener
88
import type { LayoutNode } from 'src/utils/layout/LayoutNode';
99

1010
type RadioButtonsSummaryProps = {
11+
isCompact?: boolean;
1112
componentNode: LayoutNode<'RadioButtons'>;
1213
displayData: string;
1314
summaryOverrides?: RadioSummaryOverrideProps;
1415
};
1516

16-
export const RadioButtonsSummary = ({ componentNode, displayData }: RadioButtonsSummaryProps) => {
17+
export const RadioButtonsSummary = ({ componentNode, displayData, isCompact }: RadioButtonsSummaryProps) => {
1718
const validations = useUnifiedValidationsForNode(componentNode);
1819
const errors = validationsOfSeverity(validations, 'error');
1920
const title = componentNode.item.textResourceBindings?.title;
@@ -23,6 +24,7 @@ export const RadioButtonsSummary = ({ componentNode, displayData }: RadioButtons
2324
displayData={displayData}
2425
errors={errors}
2526
componentNode={componentNode}
27+
isCompact={isCompact}
2628
/>
2729
);
2830
};

src/layout/RadioButtons/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,15 @@ export class RadioButtons extends RadioButtonsDef {
3737
renderSummary2(
3838
componentNode: LayoutNode<'RadioButtons'>,
3939
summaryOverrides?: RadioSummaryOverrideProps,
40+
isCompact?: boolean,
4041
): JSX.Element | null {
4142
const displayData = this.useDisplayData(componentNode);
4243
return (
4344
<RadioButtonsSummary
4445
componentNode={componentNode}
4546
summaryOverrides={summaryOverrides}
4647
displayData={displayData}
48+
isCompact={isCompact}
4749
/>
4850
);
4951
}

src/layout/Summary2/CommonSummaryComponents/MultipleValueSummary.module.css

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
.labelValueWrapper:not(.compact) {
2+
display: flex;
3+
flex-direction: column;
4+
gap: var(--fds-spacing-2);
5+
}
6+
7+
.labelValueWrapper.compact {
8+
display: inline-block;
9+
}
10+
11+
.labelValueWrapper.compact label {
12+
margin-right: var(--fds-spacing-2);
13+
}
14+
115
.formValue {
216
font-weight: 500;
317
}
@@ -11,12 +25,6 @@
1125
border-bottom: var(--fds-semantic-border-danger-default) solid 2px;
1226
}
1327

14-
.labelValueWrapper {
15-
display: flex;
16-
flex-direction: column;
17-
gap: var(--fds-spacing-2);
18-
}
19-
2028
.checkboxSummaryItem {
2129
display: flex;
2230
align-items: flex-start;

src/layout/Summary2/CommonSummaryComponents/MultipleValueSummary.tsx

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type MultipleValueSummaryProps = {
1919
title: React.ReactNode;
2020
componentNode: LayoutNode;
2121
showAsList?: boolean;
22+
isCompact?: boolean;
2223
};
2324

2425
function getSummaryData(
@@ -36,7 +37,21 @@ function getSummaryData(
3637
return getCommaSeparatedOptionsToText(value, optionList, langTools);
3738
}
3839

39-
export const MultipleValueSummary = ({ title, componentNode, showAsList }: MultipleValueSummaryProps) => {
40+
function getDisplayType(
41+
displayValues: string[],
42+
showAsList?: boolean,
43+
compact?: boolean,
44+
): 'list' | 'inline' | 'empty' | null {
45+
if (!displayValues || displayValues?.length < 1) {
46+
return 'empty';
47+
}
48+
if (compact || !showAsList) {
49+
return 'inline';
50+
}
51+
return 'list';
52+
}
53+
54+
export const MultipleValueSummary = ({ title, componentNode, showAsList, isCompact }: MultipleValueSummaryProps) => {
4055
const formDataSelector = FD.useDebouncedSelector();
4156

4257
const langTools = useLanguage();
@@ -47,11 +62,15 @@ export const MultipleValueSummary = ({ title, componentNode, showAsList }: Multi
4762
const validations = useUnifiedValidationsForNode(componentNode);
4863
const errors = validationsOfSeverity(validations, 'error');
4964

65+
const displayType = getDisplayType(displayValues, showAsList, isCompact);
66+
5067
return (
5168
<div className={classes.checkboxSummaryItem}>
52-
<div className={cn(classes.labelValueWrapper, { [classes.error]: errors.length > 0 })}>
69+
<div
70+
className={cn(classes.labelValueWrapper, { [classes.error]: errors.length > 0, [classes.compact]: isCompact })}
71+
>
5372
<Label weight={'regular'}>{title}</Label>
54-
{displayValues?.length > 0 && showAsList && (
73+
{displayType === 'list' && (
5574
<List.Root>
5675
<List.Unordered>
5776
{displayValues?.map((item) => (
@@ -65,25 +84,24 @@ export const MultipleValueSummary = ({ title, componentNode, showAsList }: Multi
6584
</List.Unordered>
6685
</List.Root>
6786
)}
68-
{displayValues?.length > 0 && !showAsList && (
87+
{displayType === 'inline' && (
6988
<Paragraph
7089
asChild
7190
className={classes.formValue}
7291
>
7392
<span>{displayValues.join(', ')}</span>
7493
</Paragraph>
7594
)}
76-
{!displayValues ||
77-
(displayValues?.length < 1 && (
78-
<Paragraph
79-
asChild
80-
className={classes.emptyValue}
81-
>
82-
<span>
83-
<Lang id={'general.empty_summary'}></Lang>
84-
</span>
85-
</Paragraph>
86-
))}
95+
{displayType === 'empty' && (
96+
<Paragraph
97+
asChild
98+
className={classes.emptyValue}
99+
>
100+
<span>
101+
<Lang id={'general.empty_summary'}></Lang>
102+
</span>
103+
</Paragraph>
104+
)}
87105
{errors.length > 0 &&
88106
errors.map(({ message }) => (
89107
<ErrorMessage key={message.key}>

src/layout/Summary2/CommonSummaryComponents/SingleValueSummary.module.css

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
1+
.inputSummaryItem {
2+
display: flex;
3+
flex-direction: row;
4+
align-items: flex-start;
5+
}
6+
7+
.labelValueWrapper:not(.compact) {
8+
display: flex;
9+
flex-direction: column;
10+
gap: var(--fds-spacing-2);
11+
}
12+
13+
.labelValueWrapper.compact {
14+
display: inline-block;
15+
}
16+
17+
.labelValueWrapper.compact label {
18+
margin-right: var(--fds-spacing-2);
19+
}
20+
121
.formValue {
222
font-weight: 500;
323
}
@@ -7,22 +27,10 @@
727
font-style: italic;
828
}
929

10-
.inputSummaryItem {
11-
display: flex;
12-
flex-direction: row;
13-
align-items: flex-start;
14-
}
15-
1630
.error {
1731
border-bottom: var(--fds-semantic-border-danger-default) solid 2px;
1832
}
1933

20-
.labelValueWrapper {
21-
display: flex;
22-
flex-direction: column;
23-
gap: var(--fds-spacing-2);
24-
}
25-
2634
.editButton {
2735
margin-left: auto;
2836
min-width: unset;

src/layout/Summary2/CommonSummaryComponents/SingleValueSummary.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ type SingleValueSummaryProps = {
1616
displayData?: string;
1717
hideEditButton?: boolean;
1818
multiline?: boolean;
19+
isCompact?: boolean;
1920
};
2021

2122
export const SingleValueSummary = ({
@@ -25,10 +26,17 @@ export const SingleValueSummary = ({
2526
displayData,
2627
hideEditButton,
2728
multiline,
29+
isCompact,
2830
}: SingleValueSummaryProps) => (
2931
<div className={classes.inputSummaryItem}>
30-
<div className={classes.labelValueWrapper}>
31-
<Label weight={'regular'}>{title}</Label>
32+
<div className={cn(classes.labelValueWrapper, isCompact && classes.compact)}>
33+
<Label
34+
weight={'regular'}
35+
className={classes.formLabel}
36+
>
37+
{title}
38+
{!!title?.toString()?.length && isCompact && ':'}
39+
</Label>
3240
<Paragraph
3341
asChild
3442
className={cn({

src/layout/Summary2/SummaryComponent2/ComponentSummary.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,18 @@ import type { LayoutNode } from 'src/utils/layout/LayoutNode';
1212
interface ComponentSummaryProps {
1313
componentNode: LayoutNode;
1414
summaryOverrides?: CompSummary2Internal['overrides'];
15+
isCompact?: boolean;
1516
}
1617

1718
interface ResolveComponentProps {
1819
summaryProps: CompSummary2External;
1920
summaryOverrides?: CompSummary2Internal['overrides'];
2021
}
21-
export function ComponentSummary({ componentNode, summaryOverrides }: ComponentSummaryProps) {
22+
export function ComponentSummary({ componentNode, summaryOverrides, isCompact }: ComponentSummaryProps) {
2223
const override = summaryOverrides?.find((override) => override.componentId === componentNode.item.id);
2324

2425
const renderedComponent = componentNode.def.renderSummary2
25-
? componentNode.def.renderSummary2(componentNode as LayoutNode<any>, override)
26+
? componentNode.def.renderSummary2(componentNode as LayoutNode<any>, override, isCompact)
2627
: null;
2728

2829
if (!renderedComponent) {

0 commit comments

Comments
 (0)