-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from oasisprotocol/ml/alerts
Add Alert component
- Loading branch information
Showing
13 changed files
with
267 additions
and
9 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,93 @@ | ||
.alert { | ||
min-height: 688px; | ||
text-align: center; | ||
|
||
h2 { | ||
color: var(--palatinate-blue); | ||
margin-top: 6rem; | ||
margin-bottom: 1rem; | ||
} | ||
|
||
p { | ||
max-width: 335px; | ||
font-size: 14px; | ||
font-weight: 400; | ||
line-height: 120%; | ||
letter-spacing: 0; | ||
margin: 0 auto; | ||
margin-bottom: 2.375rem; | ||
} | ||
|
||
.icon { | ||
margin: 0 auto; | ||
margin-bottom: 1.125rem; | ||
} | ||
|
||
.actions { | ||
&:empty { | ||
display: none; | ||
} | ||
|
||
span { | ||
font-size: 22px; | ||
font-weight: 500; | ||
line-height: 150%; | ||
letter-spacing: -0.03em; | ||
color: var(--palatinate-blue); | ||
} | ||
} | ||
} | ||
|
||
.alertError { | ||
svg { | ||
color: var(--mystic); | ||
} | ||
} | ||
|
||
.alertSuccess { | ||
svg { | ||
color: var(--green-sheen); | ||
} | ||
} | ||
|
||
@keyframes rotating { | ||
from { | ||
transform: rotate(0deg); | ||
} | ||
to { | ||
transform: rotate(360deg); | ||
} | ||
} | ||
|
||
.alertLoading { | ||
.icon { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
width: 106px; | ||
height: 106px; | ||
border-radius: 50%; | ||
background: linear-gradient(302.43deg, var(--medium-blue) -18.46%, var(--azure) 93.84%); | ||
} | ||
|
||
svg { | ||
color: var(--white); | ||
animation: rotating 3s linear infinite; | ||
} | ||
} | ||
|
||
.alertInsufficientBalance { | ||
.icon { | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
width: 106px; | ||
height: 106px; | ||
border-radius: 50%; | ||
background: linear-gradient(282.09deg, var(--mystic) 6.24%, var(--rose-red) 102.94%); | ||
} | ||
|
||
svg { | ||
color: var(--white); | ||
} | ||
} |
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,60 @@ | ||
import { FC, PropsWithChildren, ReactElement } from 'react' | ||
import classes from './index.module.css' | ||
import { Card } from '../Card' | ||
import { WarningCircleIcon } from '../icons/WarningCircleIcon.tsx' | ||
import { CheckCircleIcon } from '../icons/CheckCircleIcon.tsx' | ||
import { SpinnerIcon } from '../icons/SpinnerIcon.tsx' | ||
import { PiggyBankSvgIcon } from '../icons/PiggyBankIcon.tsx' | ||
|
||
type AlertType = 'error' | 'success' | 'loading' | 'insufficient-balance' | ||
|
||
interface AlertTypeValues { | ||
header: string | ||
icon: ReactElement | ||
} | ||
|
||
const alertTypeValuesMap: Record<AlertType, AlertTypeValues> = { | ||
error: { | ||
header: 'Something went wrong', | ||
icon: <WarningCircleIcon />, | ||
}, | ||
success: { | ||
header: 'Vote cast', | ||
icon: <CheckCircleIcon />, | ||
}, | ||
loading: { | ||
header: 'Casting your vote', | ||
icon: <SpinnerIcon />, | ||
}, | ||
'insufficient-balance': { | ||
header: 'Insufficient balance', | ||
icon: <PiggyBankSvgIcon />, | ||
}, | ||
} | ||
|
||
const alertTypeClassMap: Record<AlertType, string> = { | ||
error: classes.alertError, | ||
success: classes.alertSuccess, | ||
loading: classes.alertLoading, | ||
'insufficient-balance': classes.alertInsufficientBalance, | ||
} | ||
|
||
interface Props extends PropsWithChildren { | ||
type: AlertType | ||
actions?: ReactElement | ||
} | ||
|
||
export const Alert: FC<Props> = ({ children, type, actions }) => { | ||
const { header, icon } = alertTypeValuesMap[type] | ||
|
||
return ( | ||
<Card className={alertTypeClassMap[type]}> | ||
<div className={classes.alert}> | ||
<h2>{header}</h2> | ||
<p>{children}</p> | ||
<div className={classes.icon}>{icon}</div> | ||
<div className={classes.actions}>{actions}</div> | ||
</div> | ||
</Card> | ||
) | ||
} |
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
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 |
---|---|---|
@@ -1,6 +1,11 @@ | ||
import { FC, PropsWithChildren } from 'react' | ||
import classes from './index.module.css' | ||
import { StringUtils } from '../../utils/string.utils.ts' | ||
|
||
export const Card: FC<PropsWithChildren> = ({ children }) => { | ||
return <div className={classes.card}>{children}</div> | ||
interface Props extends PropsWithChildren { | ||
className?: string | ||
} | ||
|
||
export const Card: FC<Props> = ({ children, className }) => { | ||
return <div className={StringUtils.clsx(classes.card, className)}>{children}</div> | ||
} |
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
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
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,11 @@ | ||
/// <reference types="vite-plugin-svgr/client" /> | ||
|
||
import { FC } from 'react' | ||
import CheckCircleSvg from '@phosphor-icons/core/assets/fill/check-circle-fill.svg?react' | ||
import { Icon } from '../Icon' | ||
|
||
export const CheckCircleIcon: FC = () => ( | ||
<Icon size="xlarge"> | ||
<CheckCircleSvg /> | ||
</Icon> | ||
) |
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,11 @@ | ||
/// <reference types="vite-plugin-svgr/client" /> | ||
|
||
import { FC } from 'react' | ||
import PiggyBankSvg from '@phosphor-icons/core/assets/regular/piggy-bank.svg?react' | ||
import { Icon } from '../Icon' | ||
|
||
export const PiggyBankSvgIcon: FC = () => ( | ||
<Icon size="large"> | ||
<PiggyBankSvg /> | ||
</Icon> | ||
) |
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,11 @@ | ||
/// <reference types="vite-plugin-svgr/client" /> | ||
|
||
import { FC } from 'react' | ||
import SpinnerSvg from '@phosphor-icons/core/assets/regular/spinner.svg?react' | ||
import { Icon } from '../Icon' | ||
|
||
export const SpinnerIcon: FC = () => ( | ||
<Icon size="large"> | ||
<SpinnerSvg /> | ||
</Icon> | ||
) |
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,11 @@ | ||
/// <reference types="vite-plugin-svgr/client" /> | ||
|
||
import { FC } from 'react' | ||
import WarningCircleSvg from '@phosphor-icons/core/assets/fill/warning-circle-fill.svg?react' | ||
import { Icon } from '../Icon' | ||
|
||
export const WarningCircleIcon: FC = () => ( | ||
<Icon size="xlarge"> | ||
<WarningCircleSvg /> | ||
</Icon> | ||
) |
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
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
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