Skip to content

Commit

Permalink
fix(form-builder): add new Alert component
Browse files Browse the repository at this point in the history
  • Loading branch information
bjoerge committed Mar 4, 2021
1 parent 3c6921c commit 4da7b5e
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions packages/@sanity/form-builder/src/components/Alert.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import {ErrorOutlineIcon, WarningOutlineIcon} from '@sanity/icons'
import {Box, Card, Flex, Text} from '@sanity/ui'
import React from 'react'
import styled from 'styled-components'

interface AlertProps {
children?: React.ReactNode
title: React.ReactNode
status?: 'warning' | 'error'
suffix?: React.ReactNode
}

const STATUS_TONES = {
warning: 'caution',
error: 'critical',
} as const

const SuffixBox = styled(Box)`
border-top: 1px solid var(--card-border-color);
`

export function Alert(props: AlertProps) {
const {children, status = 'warning', suffix, title} = props

return (
<Card radius={2} tone={STATUS_TONES[status]}>
<Flex padding={4}>
<Box>
<Text size={1}>
{status === 'warning' && <WarningOutlineIcon />}
{status === 'error' && <ErrorOutlineIcon />}
</Text>
</Box>

<Box flex={1} marginLeft={3}>
<Text size={1} weight="semibold">
{title}
</Text>

{children && <Box marginTop={3}>{children}</Box>}
</Box>
</Flex>

{suffix && <SuffixBox>{suffix}</SuffixBox>}
</Card>
)
}

0 comments on commit 4da7b5e

Please sign in to comment.