-
Notifications
You must be signed in to change notification settings - Fork 341
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor
Indicator
to ToastIcon
component
- Also export resolveValue to render custom JSX content
- Loading branch information
Showing
5 changed files
with
86 additions
and
93 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,79 @@ | ||
import * as React from 'react'; | ||
import { styled, keyframes } from 'goober'; | ||
|
||
import { Toast } from '../core/types'; | ||
import { ErrorIcon, ErrorTheme } from './error'; | ||
import { LoaderIcon, LoaderTheme } from './loader'; | ||
import { CheckmarkIcon, CheckmarkTheme } from './checkmark'; | ||
|
||
const StatusWrapper = styled('div')` | ||
position: absolute; | ||
`; | ||
|
||
const IndicatorWrapper = styled('div')` | ||
position: relative; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
min-width: 20px; | ||
min-height: 20px; | ||
`; | ||
|
||
const enter = keyframes` | ||
from { | ||
transform: scale(0.6); | ||
opacity: 0.4; | ||
} | ||
to { | ||
transform: scale(1); | ||
opacity: 1; | ||
} | ||
`; | ||
|
||
export const AnimatedIconWrapper = styled('div')` | ||
position: relative; | ||
transform: scale(0.6); | ||
opacity: 0.4; | ||
min-width: 20px; | ||
animation: ${enter} 0.3s 0.12s cubic-bezier(0.175, 0.885, 0.32, 1.275) | ||
forwards; | ||
`; | ||
|
||
export type IconThemes = Partial<{ | ||
success: CheckmarkTheme; | ||
error: ErrorTheme; | ||
loading: LoaderTheme; | ||
}>; | ||
|
||
export const ToastIcon: React.FC<{ | ||
toast: Toast; | ||
}> = ({ toast }) => { | ||
const { icon, type, iconTheme } = toast; | ||
if (icon !== undefined) { | ||
if (typeof icon === 'string') { | ||
return <AnimatedIconWrapper>{icon}</AnimatedIconWrapper>; | ||
} else { | ||
return icon; | ||
} | ||
} | ||
|
||
if (type === 'blank') { | ||
return null; | ||
} | ||
|
||
return ( | ||
<IndicatorWrapper> | ||
<LoaderIcon {...iconTheme} /> | ||
{type !== 'loading' && ( | ||
<StatusWrapper> | ||
{type === 'error' ? ( | ||
<ErrorIcon {...iconTheme} /> | ||
) : ( | ||
<CheckmarkIcon {...iconTheme} /> | ||
)} | ||
</StatusWrapper> | ||
)} | ||
</IndicatorWrapper> | ||
); | ||
}; |
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 |
---|---|---|
|
@@ -7,12 +7,10 @@ import { | |
} from './core/types'; | ||
export { useToaster } from './core/use-toaster'; | ||
export { ToastBar } from './components/toast-bar'; | ||
export { ToastIcon } from './components/toast-icon'; | ||
export { Toaster } from './components/toaster'; | ||
export { useStore as useToasterStore } from './core/store'; | ||
|
||
export { CheckmarkIcon } from './components/checkmark'; | ||
export { ErrorIcon } from './components/error'; | ||
export { LoaderIcon } from './components/loader'; | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
jlalmes
Contributor
|
||
export { resolveValue } from './core/types'; | ||
|
||
export type ToastOptions = _ToastOptions; | ||
export type ToastPosition = _ToastPosition; | ||
|
This is a breaking change that wasn't mentioned on the 2.0 docs. Can we bring this back? @timolins