File size: 1,044 Bytes
f23825d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import styled from "@emotion/styled"
import Warning from "mdi-react/AlertIcon"
import Info from "mdi-react/InformationIcon"
import { CSSProperties, FC } from "react"

const Wrapper = styled.div`
  background: ${({ theme }) => theme.secondaryBackgroundColor};
  display: flex;
  padding: 1rem;
  border-radius: 0.5rem;
`

export type Severity = "info" | "warning"

const SeverityIcon: FC<{ severity: Severity; style: CSSProperties }> = ({
  severity,
  ...props
}) => {
  switch (severity) {
    case "info":
      return <Info {...props} />
    case "warning":
      return <Warning {...props} />
  }
}

const Content = styled.div`
  flex-grow: 1;
  display: flex;
  align-items: center;
`

export const Alert: FC<
  React.DetailedHTMLProps<
    React.HTMLAttributes<HTMLDivElement>,
    HTMLDivElement
  > & { severity: Severity }
> = ({ children, severity, ...props }) => {
  return (
    <Wrapper {...props}>
      <SeverityIcon severity={severity} style={{ marginRight: "1rem" }} />
      <Content>{children}</Content>
    </Wrapper>
  )
}