Skip to content

Commit f00b643

Browse files
authored
<Banner/>: Hide Dismiss button if onClose handler is not provided. (#31362)
* feat: Hide `Dismiss` button if `onClose` handler is not provided. * tests: Update snapshots for `packages/shared-components`.
1 parent f46869e commit f00b643

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

8.33 KB
Loading

packages/shared-components/src/composer/Banner/Banner.stories.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,9 @@ export const WithAvatarImage: Story = {
6565
avatar: <img alt="Example" src="https://picsum.photos/32/32" />,
6666
},
6767
};
68+
69+
export const WithoutClose: Story = {
70+
args: {
71+
onClose: undefined,
72+
},
73+
};

packages/shared-components/src/composer/Banner/Banner.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface BannerProps {
4141
/**
4242
* Called when the user presses the "dismiss" button.
4343
*/
44-
onClose: MouseEventHandler<HTMLButtonElement>;
44+
onClose?: MouseEventHandler<HTMLButtonElement>;
4545
}
4646

4747
/**
@@ -82,9 +82,11 @@ export function Banner({
8282
<span className={styles.content}>{children}</span>
8383
<div className={styles.actions}>
8484
{actions}
85-
<Button kind="secondary" size="sm" onClick={onClose}>
86-
{_t("action|dismiss")}
87-
</Button>
85+
{onClose && (
86+
<Button kind="secondary" size="sm" onClick={onClose}>
87+
{_t("action|dismiss")}
88+
</Button>
89+
)}
8890
</div>
8991
</div>
9092
);

0 commit comments

Comments
 (0)