Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
CanRau authored Dec 30, 2023
2 parents ab3ce97 + 3ac2386 commit d65ae76
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
14 changes: 11 additions & 3 deletions src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class Observer {
promise,
type: 'loading',
message: data.loading,
description: typeof data.description !== 'function' ? data.description : undefined,
});
}

Expand All @@ -131,18 +132,25 @@ class Observer {
const message =
// @ts-expect-error
typeof data.error === 'function' ? data.error(`HTTP error! status: ${response.status}`) : data.error;
this.create({ id, type: 'error', message });
const description =
typeof data.description === 'function'
? // @ts-expect-error
data.description(`HTTP error! status: ${response.status}`)
: data.description;
this.create({ id, type: 'error', message, description });
} else if (data.success !== undefined) {
shouldDismiss = false;
const message = typeof data.success === 'function' ? data.success(response) : data.success;
this.create({ id, type: 'success', message });
const description = typeof data.description === 'function' ? data.description(response) : data.description;
this.create({ id, type: 'success', message, description });
}
})
.catch((error) => {
if (data.error !== undefined) {
shouldDismiss = false;
const message = typeof data.error === 'function' ? data.error(error) : data.error;
this.create({ id, type: 'error', message });
const description = typeof data.description === 'function' ? data.description(error) : data.description;
this.create({ id, type: 'error', message, description });
}
})
.finally(() => {
Expand Down
5 changes: 4 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ export type ToastTypes = 'normal' | 'action' | 'success' | 'info' | 'warning' |

export type PromiseT<Data = any> = Promise<Data> | (() => Promise<Data>);

export type PromiseData<ToastData = any> = ExternalToast & {
export type PromiseExternalToast = Omit<ExternalToast, 'description'>;

export type PromiseData<ToastData = any> = PromiseExternalToast & {
loading?: string | React.ReactNode;
success?: string | React.ReactNode | ((data: ToastData) => React.ReactNode | string);
error?: string | React.ReactNode | ((error: any) => React.ReactNode | string);
description?: string | React.ReactNode | ((data: any) => React.ReactNode | string);
finally?: () => void | Promise<void>;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
border: 1px solid var(--gray3);
display: flex;
align-items: center;
color: var(--gray12);
}

.copy {
Expand Down
5 changes: 3 additions & 2 deletions website/src/globals.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
:root {
:root,
.light {
--gray0: #fff;
--gray1: hsl(0, 0%, 99%);
--gray2: hsl(0, 0%, 97.3%);
Expand Down Expand Up @@ -48,6 +49,7 @@

.wrapper {
--side-padding: 16px;
background: var(--gray0);
margin: 0;
padding: 0;
padding-top: 100px;
Expand Down Expand Up @@ -175,7 +177,6 @@ m .wrapper h2 {
}

.wrapper a {
color: inherit;
text-decoration-color: var(--gray10);
text-underline-position: from-font;
}
Expand Down
2 changes: 1 addition & 1 deletion website/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default function Home() {
const [closeButton, setCloseButton] = React.useState(false);

return (
<div className="wrapper">
<div className="wrapper light">
<Head />
<Toaster theme="light" richColors={richColors} closeButton={closeButton} expand={expand} position={position} />
<main className="container">
Expand Down

0 comments on commit d65ae76

Please sign in to comment.