Skip to content

Commit

Permalink
Address config
Browse files Browse the repository at this point in the history
  • Loading branch information
igoroctaviano committed Nov 5, 2024
1 parent 0e896f5 commit 3136354
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ const messageProxy = new Proxy(originalMessage, {
return (...args: any[]) => {
const isMessageEnabled = isMessageTypeDisabled({ type: prop as string })
if (!isMessageEnabled) {
// For message methods like success, error, etc., the first argument might be config object
if (typeof args[0] === 'object' && args[0] !== null) {
args[0] = {
...args[0],
duration: config.messages?.duration ?? 5
}
} else {
// If first argument is just a string, wrap it in an object with our duration
args = [{
content: args[0],
duration: config.messages?.duration ?? 5
}]
}
return (target[prop as keyof typeof target] as Function).apply(message, args)
}
return { then: () => {} }
Expand All @@ -56,8 +69,11 @@ const messageProxy = new Proxy(originalMessage, {
return Reflect.get(target, prop)
}
})

// Apply the proxy
Object.assign(message, messageProxy)

// Set global config after proxy is in place
message.config({
top: config.messages?.top ?? 100,
duration: config.messages?.duration ?? 5
Expand Down

0 comments on commit 3136354

Please sign in to comment.