Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced "alertVariant" with "variant" for Toasts #6914

Merged
merged 8 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const InternalToast = ({ key, onClose, onRef, toastState }: Props) => {
_level={0}
_hasCloser={true}
_type={toastState.toast.type}
_variant={toastState.toast.alertVariant || 'card'}
_variant={toastState.toast.alertVariant || toastState.toast.variant || 'card'}
_on={{ onClose }}
>
<div ref={onRef}>{typeof toastState.toast.description === 'string' ? toastState.toast.description : null}</div>
Expand Down
8 changes: 4 additions & 4 deletions packages/components/src/components/toaster/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ toaster.enqueue({
label: 'This is the title',
description: 'Magna eu sit adipisicing cillum amet esse in aute quis in dolore.',
type: 'info',
alertType: 'msg', // Standard: 'card'
variant: 'msg', // Standard: 'card'
});
```

Expand Down Expand Up @@ -90,9 +90,9 @@ Type: `Promise<void>`

#### Parameters

| Name | Type | Description |
| ------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| `toast` | `{ description?: string \| undefined; render?: ToastRenderFunction \| undefined; label: string; type: "default" \| "info" \| "success" \| "warning" \| "error"; alertVariant?: "card" \| "msg" \| undefined; }` | |
| Name | Type | Description |
| ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| `toast` | `{ description?: string \| undefined; render?: ToastRenderFunction \| undefined; label: string; type: "default" \| "info" \| "success" \| "warning" \| "error"; variant?: "card" \| "msg" \| undefined; }` | |

#### Returns

Expand Down
6 changes: 4 additions & 2 deletions packages/components/src/components/toaster/toaster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ export class ToasterService {
* so we can't enqueue toasts.
*/
if (this.toastContainerElement && typeof this.toastContainerElement.enqueue === 'function') {
sdvg marked this conversation as resolved.
Show resolved Hide resolved
if (!toast.alertVariant && this.options?.defaultAlertVariant) {
toast.alertVariant = this.options?.defaultAlertVariant;
const defaultVariant = this.options?.defaultVariant ?? undefined;
const defaultAlertVariant = this.options?.defaultAlertVariant ?? undefined;
if (!toast.alertVariant && !toast.variant && this.options) {
toast.variant = defaultAlertVariant ?? defaultVariant;
}

return this.toastContainerElement.enqueue(toast);
Expand Down
8 changes: 8 additions & 0 deletions packages/components/src/schema/components/toaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export type Toast = {
render?: ToastRenderFunction;
label: LabelPropType;
type: AlertType;
/**
* @deprecated Use variant instead
*/
alertVariant?: AlertVariant;
variant?: AlertVariant;
};

export type ToastState = {
Expand All @@ -23,7 +27,11 @@ export type ToastState = {
};

export type ToasterOptions = {
/**
* @deprecated Use defaultVariant instead
*/
defaultAlertVariant: AlertVariant;
defaultVariant: AlertVariant;
AlexanderSchmidtCE marked this conversation as resolved.
Show resolved Hide resolved
};

type RequiredProps = NonNullable<unknown>;
Expand Down
2 changes: 1 addition & 1 deletion packages/samples/react/src/components/toast/basic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const ToastBasic: FC = () => {
description: 'Toasty',
label: `Toast with variant 'msg'`,
type: 'warning',
alertVariant: 'msg',
variant: 'msg',
});
};

Expand Down
Loading