@neo4j-ndl/react
Version:
React implementation of Neo4j Design System
88 lines (87 loc) • 4.22 kB
TypeScript
/**
*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { type ReactNode } from 'react';
import { type ExternalToast as SonnerExternalToast, toast as sonnerToast, type ToasterProps as SonnerToasterProps } from 'sonner';
import { type CommonProps } from '../_common/types';
type ToastVariants = 'neutral' | 'success' | 'danger' | 'progress-bar';
type ToastCommandVariants = 'neutral' | 'success' | 'danger' | 'progressBar';
type ToastId = string | number;
type BaseToastProps = CommonProps<'div', {
/** If `true` a close button will be displayed in the toast. */
isCloseable?: boolean;
/** If `true` the toast will close when the action button is triggered. */
shouldCloseOnAction?: boolean;
/** Function that will be called when the toast is closed. */
onClose?: (id: ToastId) => void;
/** If true the toast will close automatically after a certain time. */
shouldAutoClose?: boolean;
/** Function that will be called when the toast is automatically closed. */
onAutoClose?: (id: ToastId) => void;
/** If set an action button will be displayed. The value here will be displayed
* in the action button. If this is set the toast property `shouldAutoClose` will
* automatically be set to `false` unless overridden. */
actionLabel?: string;
/** Function that will be called when the action button is clicked. */
onAction?: (id: ToastId) => void;
/** If a dev wishes to set the underlying framework props (Sonner Toast).
* https://sonner.emilkowal.ski/toast#api-reference */
sonnerToastProps?: SonnerExternalToast;
/** If true the toast is controlled by the parent. */
isControlled?: boolean;
}>;
interface ToastNeutralProps extends BaseToastProps {
icon?: ReactNode;
}
interface ToastSuccessProps extends BaseToastProps {
}
interface ToastDangerProps extends BaseToastProps {
}
interface ToastProgressBarProps extends BaseToastProps {
icon?: ReactNode;
initialProgressBarValue?: number;
}
type ToastVariantsProps = ToastNeutralProps | ToastSuccessProps | ToastDangerProps | ToastProgressBarProps;
interface ToasterProps extends Pick<SonnerToasterProps, 'position' | 'visibleToasts' | 'className'> {
sonnerToasterProps?: SonnerToasterProps;
}
declare const Toaster: (props: ToasterProps) => import("react/jsx-runtime").JSX.Element;
type ToastElement = ToastVariantsProps & {
icon: ReactNode;
id: ToastId;
variant: ToastVariants;
text: ReactNode;
initialProgressBarValue?: number;
isControlled?: boolean;
};
declare const Toast: ({ icon, id, text, variant, isCloseable, onClose, actionLabel, onAction, shouldCloseOnAction, initialProgressBarValue, isControlled, htmlAttributes, ref, ...restProps }: ToastElement) => import("react/jsx-runtime").JSX.Element;
interface Toast {
neutral: (text: ReactNode, props?: ToastNeutralProps) => ToastId;
success: (text: ReactNode, props?: ToastSuccessProps) => ToastId;
danger: (text: ReactNode, props?: ToastDangerProps) => ToastId;
progressBar: (text: ReactNode, props?: ToastProgressBarProps) => ToastId;
updateProgressBarValue: (id: ToastId, value: number) => void;
close: (id: ToastId) => void;
sonnerToast: typeof sonnerToast;
}
declare const toast: Toast;
export { Toaster, toast };
export type { ToasterProps, ToastVariants, ToastCommandVariants, ToastNeutralProps, ToastSuccessProps, ToastDangerProps, ToastProgressBarProps, ToastVariantsProps, ToastElement, ToastId, };
//# sourceMappingURL=Toast.d.ts.map