-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ [devext] extract an Alert component
- Loading branch information
1 parent
d76b25a
commit dfe3909
Showing
2 changed files
with
44 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import type { ReactNode } from 'react' | ||
import React from 'react' | ||
import { Alert as MantineAlert, Center, Group, MantineProvider, Space } from '@mantine/core' | ||
|
||
export function Alert({ | ||
level, | ||
title, | ||
message, | ||
button, | ||
}: { | ||
level: 'warning' | 'error' | ||
title?: string | ||
message: string | ||
button?: ReactNode | ||
}) { | ||
const color = level === 'warning' ? ('orange' as const) : ('red' as const) | ||
return ( | ||
<Center mt="xl"> | ||
<MantineAlert color={color} title={title}> | ||
{message} | ||
{button && ( | ||
<> | ||
<Space h="sm" /> | ||
<MantineProvider theme={{ components: { Button: { defaultProps: { color } } } }}> | ||
<Group position="right">{button}</Group> | ||
</MantineProvider> | ||
</> | ||
)} | ||
</MantineAlert> | ||
</Center> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters