Skip to content

Commit

Permalink
update toast options (#517)
Browse files Browse the repository at this point in the history
* f

* u

* u

* a

* u

* u

* u

* u

* Create old-donkeys-report.md
  • Loading branch information
felicio authored Dec 15, 2023
1 parent f6b7ca3 commit f9b9220
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
5 changes: 5 additions & 0 deletions .changeset/old-donkeys-report.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@status-im/components": patch
---

update toast options
63 changes: 42 additions & 21 deletions packages/components/src/toast/toast-container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,44 @@ import { create } from 'zustand'
import { Toast } from './toast'

import type { ToastProps } from './toast'
import type { ToastProps as RootProps } from '@radix-ui/react-toast'

type ToastRootProps = Partial<Pick<RootProps, 'duration'>> & {
originType?: RootProps['type']
}

type Options = ToastRootProps & Pick<ToastProps, 'action' | 'onAction'>

type ToastState = {
toast: ToastProps | null
toast: (ToastProps & ToastRootProps) | null
dismiss: () => void
positive: (
message: string,
actionProps?: Pick<ToastProps, 'action' | 'onAction'>
) => void
negative: (
message: string,
actionProps?: Pick<ToastProps, 'action' | 'onAction'>
) => void
custom: (
message: string,
icon: React.ReactElement,
actionProps?: Pick<ToastProps, 'action' | 'onAction'>
) => void
positive: (message: string, options?: Options) => void
negative: (message: string, options?: Options) => void
custom: (message: string, icon: React.ReactElement, options?: Options) => void
}

const useStore = create<ToastState>()(set => ({
toast: null,
positive: (message, actionProps) =>
set({ toast: { ...actionProps, message, type: 'positive' } }),
negative: (message, actionProps) =>
set({ toast: { ...actionProps, message, type: 'negative' } }),
custom: (message, icon, actionProps) =>
set({ toast: { ...actionProps, message, icon } }),
positive: (message, options) =>
set({
toast: {
message,
...options,
type: 'positive',
},
}),
negative: (message, options) =>
set({
toast: {
message,
...options,
type: 'negative',
},
}),
custom: (message, icon, options) =>
set({
toast: { message, icon, ...options },
}),
dismiss: () => set({ toast: null }),
}))

Expand All @@ -50,14 +61,23 @@ const ToastContainer = () => {
}
}

const { duration, originType, ...restProps } = store.toast

return (
<Provider>
<ToastRoot
defaultOpen
onOpenChange={handleOpenChange}
style={{ position: 'fixed' }}
// note: prevent swipe gestures from closing the toast until animation is implemented
onSwipeStart={event => event.preventDefault()}
onSwipeMove={event => event.preventDefault()}
onSwipeCancel={event => event.preventDefault()}
onSwipeEnd={event => event.preventDefault()}
duration={duration}
type={originType}
>
<Toast {...store.toast} />
<Toast {...restProps} />
</ToastRoot>
<Viewport />
</Provider>
Expand All @@ -72,6 +92,7 @@ const useToast = () => {
positive: store.positive,
negative: store.negative,
custom: store.custom,
dismiss: store.dismiss,
}),
[store]
)
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/toast/toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const Toast = (props: Props) => {

return (
<Base action={Boolean(action)}>
<Stack flex={1} flexDirection="row" gap={4}>
<Stack flex={1} flexDirection="row" gap={4} alignItems="center">
<Stack width={20}>{renderIcon()}</Stack>
<Description asChild>
<Text size={13} weight={'medium'} color="$white-100">
Expand Down

2 comments on commit f9b9220

@vercel
Copy link

@vercel vercel bot commented on f9b9220 Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

status-components – ./packages/components

status-components.vercel.app
status-components-git-main-status-im-web.vercel.app
status-components-status-im-web.vercel.app

@vercel
Copy link

@vercel vercel bot commented on f9b9220 Dec 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

status-web – ./apps/web

status-web-git-main-status-im-web.vercel.app
status-web-status-im-web.vercel.app
status-web.vercel.app

Please sign in to comment.