Skip to content

Commit

Permalink
♻️ [devext] extract an Alert component
Browse files Browse the repository at this point in the history
  • Loading branch information
BenoitZugmeyer committed May 15, 2023
1 parent d76b25a commit dfe3909
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 15 deletions.
32 changes: 32 additions & 0 deletions developer-extension/src/panel/components/alert.tsx
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>
)
}
27 changes: 12 additions & 15 deletions developer-extension/src/panel/components/app.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Alert, Button, Center, Group, MantineProvider } from '@mantine/core'
import { Button, MantineProvider } from '@mantine/core'
import { useColorScheme } from '@mantine/hooks'
import React, { Suspense, useState } from 'react'
import { listenDisconnectEvent } from '../disconnectEvent'
import { Alert } from './alert'

import { Panel } from './panel'

Expand Down Expand Up @@ -30,19 +31,15 @@ export function App() {

function DisconnectAlert() {
return (
<Center
sx={{
height: '100vh',
}}
>
<Alert title="Extension disconnected!" color="red">
The extension has been disconnected. This can happen after an update.
<Group position="right">
<Button onClick={() => location.reload()} color="red">
Reload extension
</Button>
</Group>
</Alert>
</Center>
<Alert
level="error"
title="Extension disconnected!"
message="The extension has been disconnected. This can happen after an update."
button={
<Button onClick={() => location.reload()} color="red">
Reload extension
</Button>
}
/>
)
}

0 comments on commit dfe3909

Please sign in to comment.