Skip to content

Commit

Permalink
feat: allow to specify notification duration (#13)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Sakhaev <alsakhaev@gmail.com>
  • Loading branch information
Lisofffa and alsakhaev authored Sep 9, 2024
1 parent 7300baa commit 7dd15ba
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
3 changes: 2 additions & 1 deletion libs/engine/src/app/contexts/modal-context/modal-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export type ModalProps = {
subject: string
body: string
type: NotificationType
actions: {
duration?: number
actions?: {
label: string
type?: 'primary' | 'default'
onClick?: () => void
Expand Down
7 changes: 5 additions & 2 deletions libs/engine/src/app/contexts/modal-context/modal-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,16 @@ const ModalProvider: FC<Props> = ({ children, onModalApiReady }) => {
}

const modalId = counterRef.current++
const duration = modalProps.duration ?? 4.5

api[modalProps.type]({
key: modalId,
message: modalProps.subject,
description: modalProps.body,
placement: 'bottomRight',
duration: null,
duration: duration,
showProgress: duration !== 0,
pauseOnHover: false,
btn:
modalProps.actions && modalProps.actions.length
? modalProps.actions.map((action, i) => (
Expand All @@ -57,7 +60,7 @@ const ModalProvider: FC<Props> = ({ children, onModalApiReady }) => {

useEffect(() => {
onModalApiReady({ notify })
}, [notify, onModalApiReady]);
}, [notify, onModalApiReady])

const state: ModalContextState = {
notify,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const mutationSwitched = ({
subject: 'Mutation Switched',
body: `The mutation has been switched from ${fromMutationId} to ${toMutationId}`,
type: NotificationType.Info,
duration: 0,
actions: [
{ label: 'Ok, got it', type: 'primary' },
{
Expand All @@ -26,6 +27,7 @@ export const mutationDisabled = ({ onBack }: { onBack: () => void }): ModalProps
subject: 'Mutation Disabled',
body: `You disabled all mutations`,
type: NotificationType.Warning,
duration: 0,
actions: [
{ label: 'Ok, got it', type: 'primary' },
{
Expand Down
2 changes: 1 addition & 1 deletion libs/engine/src/custom-elements/dapplet-overlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const ModalBackdrop = styled.div`
outline: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 'Ubuntu',
'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', sans-serif;
z-index: 2147483647;
z-index: 2030;
visibility: visible;
`

Expand Down

0 comments on commit 7dd15ba

Please sign in to comment.