Skip to content

Commit

Permalink
[@mantine/core] Alert: Allow usage of close button when title is not …
Browse files Browse the repository at this point in the history
…set (#1348)
  • Loading branch information
rtivital committed Aug 12, 2022
1 parent e3e5e1f commit f4dbc3c
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
8 changes: 7 additions & 1 deletion src/mantine-core/src/Alert/Alert.story.tsx
Expand Up @@ -14,7 +14,13 @@ export function Variants() {
Something terrible happened! You made a mistake and there is no going back, your data was
lost forever!
</Alert>
<Alert withCloseButton title="Bummer!" color="red" variant="outline" mt="xl">
<Alert
withCloseButton
title="Something terrible happened! You made a mistake and there is no going back, your data was lost forever!"
color="red"
variant="outline"
mt="xl"
>
Something terrible happened! You made a mistake and there is no going back, your data was
lost forever!
</Alert>
Expand Down
8 changes: 7 additions & 1 deletion src/mantine-core/src/Alert/Alert.styles.ts
Expand Up @@ -75,6 +75,10 @@ export default createStyles((theme, { color, radius, variant }: AlertStylesParam
lineHeight: theme.lineHeight,
fontSize: theme.fontSizes.sm,
fontWeight: 700,

'&[data-with-close-button]': {
paddingRight: theme.spacing.md,
},
},

label: {
Expand Down Expand Up @@ -111,7 +115,9 @@ export default createStyles((theme, { color, radius, variant }: AlertStylesParam
},

closeButton: {
marginTop: 2,
position: 'absolute',
top: theme.spacing.sm,
right: theme.spacing.sm,
color: 'inherit',
},
}));
24 changes: 12 additions & 12 deletions src/mantine-core/src/Alert/Alert.tsx
Expand Up @@ -92,24 +92,24 @@ export const Alert = forwardRef<HTMLDivElement, AlertProps>((props: AlertProps,

<div className={classes.body}>
{title && (
<div className={classes.title}>
<div className={classes.title} data-with-close-button={withCloseButton || undefined}>
<span id={titleId} className={classes.label}>
{title}
</span>

{withCloseButton && (
<CloseButton
className={classes.closeButton}
onClick={onClose}
variant="transparent"
size={16}
iconSize={16}
aria-label={closeButtonLabel}
/>
)}
</div>
)}

{withCloseButton && (
<CloseButton
className={classes.closeButton}
onClick={onClose}
variant="transparent"
size={16}
iconSize={16}
aria-label={closeButtonLabel}
/>
)}

<div id={bodyId} className={classes.message}>
{children}
</div>
Expand Down

0 comments on commit f4dbc3c

Please sign in to comment.