Skip to content

Commit

Permalink
feat(Banner): add show close button override prop
Browse files Browse the repository at this point in the history
  • Loading branch information
karrui committed Aug 16, 2022
1 parent a1eeaf2 commit ca45cc6
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions frontend/src/components/Banner/Banner.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useMemo } from 'react'
import { BiX } from 'react-icons/bi'
import ReactMarkdown from 'react-markdown'
import {
Expand All @@ -18,13 +19,15 @@ import { useMdComponents } from '~hooks/useMdComponents'
export interface BannerProps {
variant?: BannerVariant
children: string
useMarkdown: boolean
useMarkdown?: boolean
showCloseButton?: boolean
}

export const Banner = ({
variant = 'info',
children,
useMarkdown = false,
showCloseButton,
}: BannerProps): JSX.Element => {
const { isOpen, onToggle } = useDisclosure({
defaultIsOpen: true,
Expand All @@ -34,6 +37,12 @@ export const Banner = ({

const mdComponents = useMdComponents({ styles })

const shouldShowCloseButton = useMemo(() => {
// Prop supercedes all.
if (showCloseButton !== undefined) return showCloseButton
return variant === 'info'
}, [showCloseButton, variant])

return (
<Collapse in={isOpen} animateOpacity>
<Box __css={styles.banner}>
Expand All @@ -51,7 +60,7 @@ export const Banner = ({
children
)}
</Flex>
{variant === 'info' && (
{shouldShowCloseButton && (
<CloseButton
variant="subtle"
colorScheme="whiteAlpha"
Expand Down

0 comments on commit ca45cc6

Please sign in to comment.