Skip to content

Commit d203986

Browse files
authored
fix: Allow for 2 buttons in Banner (#83)
* fix: Allow for 2 buttons in Banner * Row and gap * Merge branch 'main' into banner_two_buttons * Add type params to Banner * Merge branch 'main' into banner_two_buttons
1 parent 6eadc53 commit d203986

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/components/page/Banner.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
1-
import { Button, Stack, Typography, type ButtonProps } from "@mui/material"
2-
import { type FC } from "react"
1+
import { Stack, Typography } from "@mui/material"
32

3+
import { LinkButton, type LinkButtonProps } from "../router"
44
import { primary, secondary, tertiary } from "../../theme/colors"
55
import palette from "../../theme/palette"
66
import Image, { type ImageProps } from "../Image"
77
import Section from "./Section"
88

9-
export interface BannerProps {
9+
export interface BannerProps<
10+
Button1State extends Record<string, any> = Record<string, any>,
11+
Button2State extends Record<string, any> = Record<string, any>,
12+
> {
1013
header: string
1114
subheader?: string
1215
textAlign?: "start" | "center"
1316
imageProps?: ImageProps
14-
buttonProps?: ButtonProps
17+
button1Props?: LinkButtonProps<"to", Button1State>
18+
button2Props?: LinkButtonProps<"to", Button2State>
1519
bgcolor?: "primary" | "secondary" | "tertiary"
1620
}
1721

18-
const Banner: FC<BannerProps> = ({
22+
const Banner = <
23+
Button1State extends Record<string, any> = Record<string, any>,
24+
Button2State extends Record<string, any> = Record<string, any>,
25+
>({
1926
header,
2027
subheader,
2128
textAlign = "start",
2229
imageProps,
23-
buttonProps,
30+
button1Props,
31+
button2Props,
2432
bgcolor = "primary",
25-
}) => {
33+
}: BannerProps<Button1State, Button2State>) => {
2634
// @ts-expect-error guaranteed to be in palette
2735
const contrastText = palette[bgcolor].contrastText
2836

@@ -61,12 +69,15 @@ const Banner: FC<BannerProps> = ({
6169
<Typography
6270
color={contrastText}
6371
variant="h4"
64-
mb={buttonProps !== undefined ? undefined : 0}
72+
mb={button1Props !== undefined ? undefined : 0}
6573
>
6674
{subheader}
6775
</Typography>
6876
)}
69-
{buttonProps !== undefined && <Button {...buttonProps} />}
77+
<Stack direction="row" gap={2}>
78+
{button1Props !== undefined && <LinkButton {...button1Props} />}
79+
{button2Props !== undefined && <LinkButton {...button2Props} />}
80+
</Stack>
7081
</Stack>
7182
{imageProps !== undefined && (
7283
<Image

0 commit comments

Comments
 (0)