update toast options (#517)
* f * u * u * a * u * u * u * u * Create old-donkeys-report.md
This commit is contained in:
parent
f6b7ca3a7e
commit
f9b9220c8b
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
"@status-im/components": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
update toast options
|
|
@ -7,33 +7,44 @@ import { create } from 'zustand'
|
||||||
import { Toast } from './toast'
|
import { Toast } from './toast'
|
||||||
|
|
||||||
import type { ToastProps } 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 = {
|
type ToastState = {
|
||||||
toast: ToastProps | null
|
toast: (ToastProps & ToastRootProps) | null
|
||||||
dismiss: () => void
|
dismiss: () => void
|
||||||
positive: (
|
positive: (message: string, options?: Options) => void
|
||||||
message: string,
|
negative: (message: string, options?: Options) => void
|
||||||
actionProps?: Pick<ToastProps, 'action' | 'onAction'>
|
custom: (message: string, icon: React.ReactElement, options?: Options) => void
|
||||||
) => void
|
|
||||||
negative: (
|
|
||||||
message: string,
|
|
||||||
actionProps?: Pick<ToastProps, 'action' | 'onAction'>
|
|
||||||
) => void
|
|
||||||
custom: (
|
|
||||||
message: string,
|
|
||||||
icon: React.ReactElement,
|
|
||||||
actionProps?: Pick<ToastProps, 'action' | 'onAction'>
|
|
||||||
) => void
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const useStore = create<ToastState>()(set => ({
|
const useStore = create<ToastState>()(set => ({
|
||||||
toast: null,
|
toast: null,
|
||||||
positive: (message, actionProps) =>
|
positive: (message, options) =>
|
||||||
set({ toast: { ...actionProps, message, type: 'positive' } }),
|
set({
|
||||||
negative: (message, actionProps) =>
|
toast: {
|
||||||
set({ toast: { ...actionProps, message, type: 'negative' } }),
|
message,
|
||||||
custom: (message, icon, actionProps) =>
|
...options,
|
||||||
set({ toast: { ...actionProps, message, icon } }),
|
type: 'positive',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
negative: (message, options) =>
|
||||||
|
set({
|
||||||
|
toast: {
|
||||||
|
message,
|
||||||
|
...options,
|
||||||
|
type: 'negative',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
custom: (message, icon, options) =>
|
||||||
|
set({
|
||||||
|
toast: { message, icon, ...options },
|
||||||
|
}),
|
||||||
dismiss: () => set({ toast: null }),
|
dismiss: () => set({ toast: null }),
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
@ -50,14 +61,23 @@ const ToastContainer = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const { duration, originType, ...restProps } = store.toast
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Provider>
|
<Provider>
|
||||||
<ToastRoot
|
<ToastRoot
|
||||||
defaultOpen
|
defaultOpen
|
||||||
onOpenChange={handleOpenChange}
|
onOpenChange={handleOpenChange}
|
||||||
style={{ position: 'fixed' }}
|
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>
|
</ToastRoot>
|
||||||
<Viewport />
|
<Viewport />
|
||||||
</Provider>
|
</Provider>
|
||||||
|
@ -72,6 +92,7 @@ const useToast = () => {
|
||||||
positive: store.positive,
|
positive: store.positive,
|
||||||
negative: store.negative,
|
negative: store.negative,
|
||||||
custom: store.custom,
|
custom: store.custom,
|
||||||
|
dismiss: store.dismiss,
|
||||||
}),
|
}),
|
||||||
[store]
|
[store]
|
||||||
)
|
)
|
||||||
|
|
|
@ -38,7 +38,7 @@ const Toast = (props: Props) => {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Base action={Boolean(action)}>
|
<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>
|
<Stack width={20}>{renderIcon()}</Stack>
|
||||||
<Description asChild>
|
<Description asChild>
|
||||||
<Text size={13} weight={'medium'} color="$white-100">
|
<Text size={13} weight={'medium'} color="$white-100">
|
||||||
|
|
Loading…
Reference in New Issue