Skip to content

Commit 19625b3

Browse files
feat(banner): Allow action prop to accept ReactNode in addition to Action object (#964)
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2708671 commit 19625b3

File tree

1 file changed

+24
-3
lines changed

1 file changed

+24
-3
lines changed

src/banner/banner.tsx

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ type BaseBanner = {
6363
id?: string
6464
title?: React.ReactNode
6565
description: Exclude<React.ReactNode, null | undefined | boolean>
66-
action?: Action
66+
action?: Action | React.ReactNode
6767
inlineLinks?: InlineLink[]
6868
} & CloseButton
6969

@@ -91,6 +91,18 @@ type SystemBanner = BaseBanner & {
9191

9292
type BannerProps = NeutralBanner | SystemBanner
9393

94+
/**
95+
* Type guard to check if the action is an Action object (button or link)
96+
*/
97+
function isActionObject(action: Action | React.ReactNode): action is Action {
98+
return (
99+
typeof action === 'object' &&
100+
action !== null &&
101+
'type' in action &&
102+
(action.type === 'button' || action.type === 'link')
103+
)
104+
}
105+
94106
const Banner = React.forwardRef<HTMLDivElement, BannerProps>(function Banner(
95107
{
96108
id,
@@ -175,8 +187,17 @@ const Banner = React.forwardRef<HTMLDivElement, BannerProps>(function Banner(
175187

176188
{action || closeButton ? (
177189
<Box className={styles.actions} display="flex" gap="small">
178-
{action?.type === 'button' ? <ActionButton {...action} /> : null}
179-
{action?.type === 'link' ? <ActionLink {...action} /> : null}
190+
{action ? (
191+
isActionObject(action) ? (
192+
action.type === 'button' ? (
193+
<ActionButton {...action} />
194+
) : (
195+
<ActionLink {...action} />
196+
)
197+
) : (
198+
action
199+
)
200+
) : null}
180201
{closeButton}
181202
</Box>
182203
) : null}

0 commit comments

Comments
 (0)