Skip to content

Commit

Permalink
ToastProvider: update to allow animations to come in from the top (#1450
Browse files Browse the repository at this point in the history
)

* ToastProvider: update to allow animations to come in from the top

* ToastProvider: update logic for using top/bottom css

* Animation: Add 2 new options SlideInTop and SlideOutTop

* ToastProvider: update unit test
  • Loading branch information
ryan-hunt-priceline authored Feb 8, 2024
1 parent 3a97f95 commit a49e734
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "pcln-design-system",
"comment": "ToastProvider: update to allow animations to come in from the top",
"type": "minor"
}
],
"packageName": "pcln-design-system"
}
10 changes: 10 additions & 0 deletions packages/core/src/Animate/Animate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ export type MotionVariant =
| 'scaleOnTap'
| 'slideOutLeft'
| 'slideInLeft'
| 'slideInTop'
| 'slideOutTop'

/**
* @public
Expand Down Expand Up @@ -79,6 +81,14 @@ export const MotionVariants: Record<MotionVariant, HTMLMotionProps<'div'>> = {
initial: { opacity: 0, x: '-100%' },
animate: { opacity: 1, x: 0 },
},
slideInTop: {
initial: { opacity: 0, y: '-100%' },
animate: { opacity: 1, y: 0 },
},
slideOutTop: {
initial: { opacity: 1, y: 0 },
animate: { opacity: 0, y: '-100%' },
},
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/ToastProvider/ToastProvider.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ describe('ToastProvider', () => {

it('renders a custom toast', () => {
render(
<ToastProvider enterAnimation='scaleFromCenter' exitAnimation='expandDown'>
<ToastProvider enterAnimation='scaleFromCenter' exitAnimation='expandDown' top={20}>
<MockToastChildren variation='fill' />
</ToastProvider>
)
Expand Down
11 changes: 11 additions & 0 deletions packages/core/src/ToastProvider/ToastProvider.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,14 @@ const Template = (args) => (
)

export const _ToastProvider = Template.bind({})

export const TopAnimation = (args) => (
<ToastProvider
domRootId='ToastProviderRoot'
top={20}
enterAnimation='slideInTop'
exitAnimation='slideOutTop'
>
<MockToastChildren variation={args.variation} />
</ToastProvider>
)
6 changes: 5 additions & 1 deletion packages/core/src/ToastProvider/ToastProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ export type ToastProviderProps = {
lifespan?: number
maxToasts?: number
theme: unknown
top?: number
bottom?: number
}

let id = 0
Expand All @@ -61,6 +63,8 @@ function _ToastProvider({
lifespan,
maxToasts = 3,
theme,
bottom = 20,
top,
}: ToastProviderProps) {
const [toasts, setToasts] = useState<ToastOptions[]>([])

Expand Down Expand Up @@ -91,7 +95,7 @@ function _ToastProvider({
{children}
{createPortal(
<ThemeProvider theme={theme}>
<ClickthroughAbsolute bottom={20} width='100%'>
<ClickthroughAbsolute top={top ? top : undefined} bottom={top ? undefined : bottom} width='100%'>
<Flex justifyContent='center' width='100%'>
<Flex flexDirection='column-reverse' justifyContent='center' minWidth='300px'>
{toastsToRender.map((toast) => {
Expand Down

0 comments on commit a49e734

Please sign in to comment.