Skip to content

Commit e6ed104

Browse files
committed
Enable to provide brandTop and homeLinkProps to the Footer #141
1 parent f2d84ce commit e6ed104

File tree

2 files changed

+33
-5
lines changed

2 files changed

+33
-5
lines changed

src/Footer.tsx

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ export type FooterProps = {
3737
alt: string;
3838
};
3939
license?: ReactNode;
40+
/** If not provided the brandTop from the Header will be used,
41+
* Be aware that if your Header is not used as a server component while the Footer is
42+
* you need to provide the brandTop to the Footer.
43+
*/
44+
brandTop?: ReactNode;
45+
/** If not provided the homeLinkProps from the Header will be used,
46+
* Be aware that if your Header is not used as a server component while the Footer is
47+
* you need to provide the homeLinkProps to the Footer.
48+
*/
49+
homeLinkProps?: RegisteredLinkProps & { title: string };
4050
classes?: Partial<
4151
Record<
4252
| "root"
@@ -151,14 +161,36 @@ export const Footer = memo(
151161
partnersLogos,
152162
operatorLogo,
153163
license,
164+
brandTop: brandTop_prop,
165+
homeLinkProps: homeLinkProps_prop,
154166
style,
155167
linkList,
156168
...rest
157169
} = props;
158170

159171
assert<Equals<keyof typeof rest, never>>();
160172

161-
const { brandTop, homeLinkProps } = getBrandTopAndHomeLinkProps();
173+
const { brandTop, homeLinkProps } = (() => {
174+
175+
const wrap = getBrandTopAndHomeLinkProps();
176+
177+
const brandTop = brandTop_prop ?? wrap?.brandTop;
178+
const homeLinkProps = homeLinkProps_prop ?? wrap?.homeLinkProps;
179+
180+
const exceptionMessage = " hasn't been provided to the Footer and we cannot retrieve it from the Header (it's probably client side)";
181+
182+
if (brandTop === undefined) {
183+
throw new Error(symToStr({ brandTop }) + exceptionMessage);
184+
}
185+
186+
if (homeLinkProps === undefined) {
187+
throw new Error(symToStr({ homeLinkProps }) + exceptionMessage);
188+
}
189+
190+
return { brandTop, homeLinkProps};
191+
192+
})();
193+
162194

163195
const { Link } = getLink();
164196

src/zz_internal/brandTopAndHomeLinkProps.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,5 @@ export function setBrandTopAndHomeLinkProps(params: {
1616
}
1717

1818
export function getBrandTopAndHomeLinkProps() {
19-
if (wrap === undefined) {
20-
throw new Error("The footer should be used in conjunction with the header.");
21-
}
22-
2319
return wrap;
2420
}

0 commit comments

Comments
 (0)