Skip to content

fix: Allow for 2 buttons in Banner #83

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
29 changes: 20 additions & 9 deletions src/components/page/Banner.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,36 @@
import { Button, Stack, Typography, type ButtonProps } from "@mui/material"
import { type FC } from "react"
import { Stack, Typography } from "@mui/material"

import { LinkButton, type LinkButtonProps } from "../router"
import { primary, secondary, tertiary } from "../../theme/colors"
import palette from "../../theme/palette"
import Image, { type ImageProps } from "../Image"
import Section from "./Section"

export interface BannerProps {
export interface BannerProps<
Button1State extends Record<string, any> = Record<string, any>,
Button2State extends Record<string, any> = Record<string, any>,
> {
header: string
subheader?: string
textAlign?: "start" | "center"
imageProps?: ImageProps
buttonProps?: ButtonProps
button1Props?: LinkButtonProps<"to", Button1State>
button2Props?: LinkButtonProps<"to", Button2State>
bgcolor?: "primary" | "secondary" | "tertiary"
}

const Banner: FC<BannerProps> = ({
const Banner = <
Button1State extends Record<string, any> = Record<string, any>,
Button2State extends Record<string, any> = Record<string, any>,
>({
header,
subheader,
textAlign = "start",
imageProps,
buttonProps,
button1Props,
button2Props,
bgcolor = "primary",
}) => {
}: BannerProps<Button1State, Button2State>) => {
// @ts-expect-error guaranteed to be in palette
const contrastText = palette[bgcolor].contrastText

@@ -61,12 +69,15 @@ const Banner: FC<BannerProps> = ({
<Typography
color={contrastText}
variant="h4"
mb={buttonProps !== undefined ? undefined : 0}
mb={button1Props !== undefined ? undefined : 0}
>
{subheader}
</Typography>
)}
{buttonProps !== undefined && <Button {...buttonProps} />}
<Stack direction="row" gap={2}>
{button1Props !== undefined && <LinkButton {...button1Props} />}
{button2Props !== undefined && <LinkButton {...button2Props} />}
</Stack>
</Stack>
{imageProps !== undefined && (
<Image