-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: new error dialog design #511
Changes from 5 commits
b8a89a5
336f310
0e89703
9bcdf4a
6343885
2fa4225
9da75b9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { Trans } from '@lingui/macro' | ||
import ActionButton from 'components/ActionButton' | ||
import Column from 'components/Column' | ||
import Expando from 'components/Expando' | ||
import Row from 'components/Row' | ||
import { iconHoverCss } from 'css/hover' | ||
import { AlertTriangle, Icon, LargeIcon, X } from 'icons' | ||
import { ReactNode, useState } from 'react' | ||
import styled from 'styled-components/macro' | ||
import { Color, ThemedText } from 'theme' | ||
|
||
const HeaderIcon = styled(LargeIcon)` | ||
flex-grow: 1; | ||
margin: 2em 0; | ||
` | ||
|
||
interface StatusHeaderProps { | ||
icon: Icon | ||
iconColor?: Color | ||
iconSize?: number | ||
children: ReactNode | ||
} | ||
|
||
export function StatusHeader({ icon: Icon, iconColor, iconSize = 2.5, children }: StatusHeaderProps) { | ||
return ( | ||
<> | ||
<Column flex style={{ flexGrow: 1 }}> | ||
<HeaderIcon icon={Icon} color={iconColor} size={iconSize} /> | ||
<Column gap={0.75} flex style={{ textAlign: 'center' }}> | ||
{children} | ||
</Column> | ||
</Column> | ||
</> | ||
) | ||
} | ||
|
||
const ExpandoContent = styled(ThemedText.Code)` | ||
margin: 0.5em; | ||
` | ||
|
||
const StyledXButton = styled(X)` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I feel like i've seen this component declared a couple times across the widget repo now, could we extract it into a single file and re-use via exporting? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OH we actually have one already ! wow good catch |
||
${iconHoverCss} | ||
` | ||
|
||
const ErrorDialogWrapper = styled(Column)` | ||
background-color: ${({ theme }) => theme.container}; | ||
` | ||
|
||
interface ErrorDialogProps { | ||
header?: ReactNode | ||
message: ReactNode | ||
error?: Error | ||
action: ReactNode | ||
onClick: () => void | ||
onDismiss: () => void | ||
} | ||
|
||
export default function ErrorDialog({ header, message, error, action, onClick, onDismiss }: ErrorDialogProps) { | ||
const [open, setOpen] = useState(false) | ||
|
||
return ( | ||
<ErrorDialogWrapper flex padding="1em 0.5em 0.25em" gap={0.5} align="stretch"> | ||
<Row flex flow="row-reverse"> | ||
<LargeIcon icon={StyledXButton} onClick={onDismiss} /> | ||
</Row> | ||
<StatusHeader icon={AlertTriangle} iconColor="warning" iconSize={2.5}> | ||
<Column gap={0.75}> | ||
<ThemedText.H4>{header || <Trans>Something went wrong</Trans>}</ThemedText.H4> | ||
<ThemedText.Body1 color="secondary">{message}</ThemedText.Body1> | ||
</Column> | ||
</StatusHeader> | ||
{error ? ( | ||
<Expando | ||
title={open ? <Trans>Show less</Trans> : <Trans>Show more</Trans>} | ||
open={open} | ||
onExpand={() => setOpen((open) => !open)} | ||
maxHeight={11.5 /* em */} | ||
> | ||
<Column flex grow padded> | ||
<ExpandoContent userSelect>{error.toString()}</ExpandoContent> | ||
</Column> | ||
</Expando> | ||
) : ( | ||
<Column style={{ height: '7.5em' }} /> | ||
)} | ||
<ActionButton color="accentSoft" onClick={onClick} narrow> | ||
{action} | ||
</ActionButton> | ||
</ErrorDialogWrapper> | ||
) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason behind why we're using a mix of class and functional react components in widget repo?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes - the ErrorBoundary needs to be a class component. this should be the only one afaik.
https://reactjs.org/docs/error-boundaries.html#introducing-error-boundaries