Skip to content

Commit 0a8e879

Browse files
authored
refactor(SSR): get rid of deepHas
... because deepHas has issues with SSR
1 parent d9770bf commit 0a8e879

File tree

11 files changed

+41
-72
lines changed

11 files changed

+41
-72
lines changed

packages/components/src/components/Avatar/Avatar.module.scss

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,11 @@
4747

4848
/* Variants */
4949
@mixin color($color) {
50+
&.dynamic-#{$color}:has(.initials),
5051
&.#{$color} {
5152
--background-color: var(--decorative--#{$color}-background-color);
5253
--content-color: var(--decorative--#{$color}-content-color);
53-
--content-accent-color: var(
54-
--decorative--#{$color}-content-accent-color
55-
);
54+
--content-accent-color: var(--decorative--#{$color}-content-accent-color);
5655
}
5756
}
5857

packages/components/src/components/Avatar/Avatar.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ import { getColorFromChildren } from "@/components/Avatar/lib/getColorFromChildr
88
import type { PropsWithClassName } from "@/lib/types/props";
99
import type { FlowComponentProps } from "@/lib/componentFactory/flowComponent";
1010
import { flowComponent } from "@/lib/componentFactory/flowComponent";
11-
import { deepHas } from "@/lib/react/deepHas";
12-
import { Initials } from "@/components/Initials";
1311

1412
export const avatarColors = [
1513
"blue",
@@ -33,13 +31,12 @@ export interface AvatarProps
3331
export const Avatar = flowComponent("Avatar", (props) => {
3432
const { children, className, color, size = "m", refProp: ref } = props;
3533

36-
const hasInitials = deepHas(children, Initials);
37-
3834
const rootClassName = clsx(
3935
styles.avatar,
4036
styles[`size-${size}`],
4137
className,
42-
styles[color ?? (hasInitials ? getColorFromChildren(children) : "blue")],
38+
styles[color ?? "blue"],
39+
!color && styles[`dynamic-${getColorFromChildren(children)}`],
4340
);
4441

4542
const propsContext: PropsContext = {

packages/components/src/components/CheckboxGroup/CheckboxGroup.module.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@
77
:global(.flow--checkbox-button) {
88
width: auto;
99
}
10+
11+
&:empty {
12+
display: none;
13+
}
1014
}

packages/components/src/components/CheckboxGroup/CheckboxGroup.tsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@ import clsx from "clsx";
66
import type { PropsContext } from "@/lib/propsContext";
77
import { PropsContextProvider } from "@/lib/propsContext";
88
import { FieldError } from "@/components/FieldError";
9-
import { CheckboxButton } from "@/components/CheckboxButton";
109
import { TunnelExit, TunnelProvider } from "@mittwald/react-tunnel";
1110
import formFieldStyles from "../FormField/FormField.module.scss";
1211
import type { ColumnLayoutProps } from "@/components/ColumnLayout";
1312
import { ColumnLayout } from "@/components/ColumnLayout";
1413
import type { FlowComponentProps } from "@/lib/componentFactory/flowComponent";
1514
import { flowComponent } from "@/lib/componentFactory/flowComponent";
16-
import { deepHas } from "@/lib/react/deepHas";
1715

1816
export interface CheckboxGroupProps
1917
extends PropsWithChildren<Omit<Aria.CheckboxGroupProps, "children">>,
@@ -41,29 +39,23 @@ export const CheckboxGroup = flowComponent("CheckboxGroup", (props) => {
4139
tunnelId: "checkboxes",
4240
},
4341
CheckboxButton: {
44-
tunnelId: "checkboxes",
42+
tunnelId: "checkboxButtons",
4543
},
4644
};
4745

48-
const hasCheckboxButtons = deepHas(children, CheckboxButton);
49-
5046
return (
5147
<Aria.CheckboxGroup {...rest} className={rootClassName} ref={ref}>
5248
<PropsContextProvider props={propsContext}>
5349
<TunnelProvider>
5450
{children}
5551

56-
{hasCheckboxButtons && (
57-
<ColumnLayout s={s} m={m} l={l} className={styles.checkboxGroup}>
58-
<TunnelExit id="checkboxes" />
59-
</ColumnLayout>
60-
)}
52+
<ColumnLayout s={s} m={m} l={l} className={styles.checkboxGroup}>
53+
<TunnelExit id="checkboxButtons" />
54+
</ColumnLayout>
6155

62-
{!hasCheckboxButtons && (
63-
<div className={styles.checkboxGroup}>
64-
<TunnelExit id="checkboxes" />
65-
</div>
66-
)}
56+
<div className={styles.checkboxGroup}>
57+
<TunnelExit id="checkboxes" />
58+
</div>
6759

6860
<TunnelExit id="fieldDescription" />
6961
<TunnelExit id="fieldError" />

packages/components/src/components/ColumnLayout/ColumnLayout.module.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
.columnLayoutContainer {
22
container-type: inline-size;
3+
4+
&:has(.columnLayout:empty) {
5+
display: none;
6+
}
37
}
48

59
.columnLayout {

packages/components/src/components/MenuItem/MenuItemContent.tsx

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,7 @@ import {
1010
IconRadioOff,
1111
IconRadioOn,
1212
} from "@/components/Icon/components/icons";
13-
import { Text } from "@/components/Text";
14-
import { deepHas } from "@/lib/react/deepHas";
15-
import { Wrap } from "@/components/Wrap";
1613
import clsx from "clsx";
17-
import { Avatar } from "@/components/Avatar";
1814
import { Switch } from "@/components/Switch";
1915

2016
interface Props extends Aria.MenuItemRenderProps, PropsWithChildren {
@@ -67,18 +63,13 @@ export const MenuItemContent: FC<Props> = (props) => {
6763
<IconCheckboxEmpty />
6864
);
6965

70-
const hasText = deepHas(children, Text);
71-
const hasAvatar = deepHas(children, Avatar);
72-
7366
return (
7467
<>
7568
<PropsContextProvider props={controlIconPropsContext}>
7669
{selectionIcon}
7770
</PropsContextProvider>
7871
<PropsContextProvider props={propsContext}>
79-
<Wrap if={!hasText && !hasAvatar}>
80-
<Text>{children}</Text>
81-
</Wrap>
72+
{children}
8273
</PropsContextProvider>
8374
</>
8475
);

packages/components/src/components/Navigation/Navigation.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ import type { ComponentProps, FC, PropsWithChildren } from "react";
22
import React from "react";
33
import styles from "./Navigation.module.scss";
44
import clsx from "clsx";
5-
import { NavigationGroup } from "@/components/Navigation";
6-
import { Wrap } from "@/components/Wrap";
75
import type { PropsContext } from "@/lib/propsContext";
86
import { PropsContextProvider } from "@/lib/propsContext";
97
import type { PropsWithClassName } from "@/lib/types/props";
10-
import { deepHas } from "@/lib/react/deepHas";
8+
import { TunnelExit } from "@mittwald/react-tunnel";
119

1210
export interface NavigationProps
1311
extends PropsWithChildren<ComponentProps<"nav">>,
@@ -18,8 +16,6 @@ export const Navigation: FC<NavigationProps> = (props) => {
1816

1917
const rootClassName = clsx(styles.navigation, className);
2018

21-
const hasGroups = deepHas(children, NavigationGroup);
22-
2319
const propsContext: PropsContext = {
2420
Link: {
2521
wrapWith: <li />,
@@ -31,15 +27,17 @@ export const Navigation: FC<NavigationProps> = (props) => {
3127
Icon: {
3228
className: styles.icon,
3329
},
30+
tunnelId: "links",
3431
},
3532
};
3633

3734
return (
3835
<nav className={rootClassName} role="navigation" {...rest}>
3936
<PropsContextProvider props={propsContext} mergeInParentContext>
40-
<Wrap if={!hasGroups}>
41-
<ul>{children}</ul>
42-
</Wrap>
37+
<ul>
38+
<TunnelExit id="links" />
39+
</ul>
40+
{children}
4341
</PropsContextProvider>
4442
</nav>
4543
);

packages/components/src/components/Navigation/components/NavigationGroup/NavigationGroup.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const NavigationGroup: FC<NavigationGroupProps> = (props) => {
3131
"aria-hidden": true,
3232
},
3333
Link: {
34-
tunnelId: "links",
34+
tunnelId: "groupLinks",
3535
},
3636
};
3737

@@ -43,7 +43,7 @@ export const NavigationGroup: FC<NavigationGroupProps> = (props) => {
4343
{children}
4444
<Content clearPropsContext={false}>
4545
<ul>
46-
<TunnelExit id="links" />
46+
<TunnelExit id="groupLinks" />
4747
</ul>
4848
</Content>
4949
</Accordion>
@@ -64,7 +64,7 @@ export const NavigationGroup: FC<NavigationGroupProps> = (props) => {
6464
{children}
6565
<TunnelExit id="Label" />
6666
<ul>
67-
<TunnelExit id="links" />
67+
<TunnelExit id="groupLinks" />
6868
</ul>
6969
</PropsContextProvider>
7070
</section>

packages/components/src/components/RadioGroup/RadioGroup.module.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,8 @@
33
display: flex;
44
flex-direction: column;
55
row-gap: var(--form-control--spacing-y);
6+
7+
&:empty {
8+
display: none;
9+
}
610
}

packages/components/src/components/RadioGroup/RadioGroup.tsx

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,8 @@ import type { ColumnLayoutProps } from "@/components/ColumnLayout";
1010
import { ColumnLayout } from "@/components/ColumnLayout";
1111
import { TunnelExit, TunnelProvider } from "@mittwald/react-tunnel";
1212
import formFieldStyles from "../FormField/FormField.module.scss";
13-
import RadioButton from "./components/RadioButton";
1413
import type { FlowComponentProps } from "@/lib/componentFactory/flowComponent";
1514
import { flowComponent } from "@/lib/componentFactory/flowComponent";
16-
import { deepHas } from "@/lib/react/deepHas";
1715

1816
export interface RadioGroupProps
1917
extends PropsWithChildren<Omit<Aria.RadioGroupProps, "children">>,
@@ -42,15 +40,13 @@ export const RadioGroup = flowComponent("RadioGroup", (props) => {
4240
tunnelId: "fieldError",
4341
},
4442
RadioButton: {
45-
tunnelId: "radios",
43+
tunnelId: "radioButtons",
4644
},
4745
Radio: {
4846
tunnelId: "radios",
4947
},
5048
};
5149

52-
const hasRadioButtons = deepHas(children, RadioButton);
53-
5450
return (
5551
<Aria.RadioGroup {...rest} className={rootClassName} ref={ref}>
5652
<TunnelProvider>
@@ -61,17 +57,13 @@ export const RadioGroup = flowComponent("RadioGroup", (props) => {
6157
>
6258
{children}
6359

64-
{hasRadioButtons && (
65-
<ColumnLayout s={s} m={m} l={l} className={styles.radioGroup}>
66-
<TunnelExit id="radios" />
67-
</ColumnLayout>
68-
)}
60+
<ColumnLayout s={s} m={m} l={l} className={styles.radioGroup}>
61+
<TunnelExit id="radioButtons" />
62+
</ColumnLayout>
6963

70-
{!hasRadioButtons && (
71-
<div className={styles.radioGroup}>
72-
<TunnelExit id="radios" />
73-
</div>
74-
)}
64+
<div className={styles.radioGroup}>
65+
<TunnelExit id="radios" />
66+
</div>
7567

7668
<TunnelExit id="fieldDescription" />
7769
<TunnelExit id="fieldError" />

0 commit comments

Comments
 (0)