UNPKG

@wordpress/notices

Version:
331 lines 10 kB
import type { NoticeOptions, ReducerAction } from './types'; /** * Returns an action object used in signalling that a notice is to be created. * * @param status Notice status ("info" if undefined is passed). * @param content Notice message. * @param options Optional notice options. * * @example * ```js * import { __ } from '@wordpress/i18n'; * import { useDispatch } from '@wordpress/data'; * import { store as noticesStore } from '@wordpress/notices'; * import { Button } from '@wordpress/components'; * * const ExampleComponent = () => { * const { createNotice } = useDispatch( noticesStore ); * return ( * <Button * onClick={ () => createNotice( 'success', __( 'Notice message' ) ) } * > * { __( 'Generate a success notice!' ) } * </Button> * ); * }; * ``` * * @return Action object. */ export declare function createNotice(status: ("error" | "info" | "success" | "warning" | undefined) | undefined, content: string, options?: NoticeOptions): Extract<ReducerAction, { type: 'CREATE_NOTICE'; }>; /** * Returns an action object used in signalling that a success notice is to be * created. Refer to `createNotice` for options documentation. * * @see createNotice * * @param content Notice message. * @param options Optional notice options. * * @example * ```js * import { __ } from '@wordpress/i18n'; * import { useDispatch } from '@wordpress/data'; * import { store as noticesStore } from '@wordpress/notices'; * import { Button } from '@wordpress/components'; * * const ExampleComponent = () => { * const { createSuccessNotice } = useDispatch( noticesStore ); * return ( * <Button * onClick={ () => * createSuccessNotice( __( 'Success!' ), { * type: 'snackbar', * icon: '🔥', * } ) * } * > * { __( 'Generate a snackbar success notice!' ) } * </Button> * ); * }; * ``` * * @return Action object. */ export declare function createSuccessNotice(content: string, options?: NoticeOptions): { type: 'CREATE_NOTICE'; context: string; notice: import("./types").Notice; }; /** * Returns an action object used in signalling that an info notice is to be * created. Refer to `createNotice` for options documentation. * * @see createNotice * * @param content Notice message. * @param options Optional notice options. * * @example * ```js * import { __ } from '@wordpress/i18n'; * import { useDispatch } from '@wordpress/data'; * import { store as noticesStore } from '@wordpress/notices'; * import { Button } from '@wordpress/components'; * * const ExampleComponent = () => { * const { createInfoNotice } = useDispatch( noticesStore ); * return ( * <Button * onClick={ () => * createInfoNotice( __( 'Something happened!' ), { * isDismissible: false, * } ) * } * > * { __( 'Generate a notice that cannot be dismissed.' ) } * </Button> * ); * }; *``` * * @return Action object. */ export declare function createInfoNotice(content: string, options?: NoticeOptions): { type: 'CREATE_NOTICE'; context: string; notice: import("./types").Notice; }; /** * Returns an action object used in signalling that an error notice is to be * created. Refer to `createNotice` for options documentation. * * @see createNotice * * @param content Notice message. * @param options Optional notice options. * * @example * ```js * import { __ } from '@wordpress/i18n'; * import { useDispatch } from '@wordpress/data'; * import { store as noticesStore } from '@wordpress/notices'; * import { Button } from '@wordpress/components'; * * const ExampleComponent = () => { * const { createErrorNotice } = useDispatch( noticesStore ); * return ( * <Button * onClick={ () => * createErrorNotice( __( 'An error occurred!' ), { * type: 'snackbar', * explicitDismiss: true, * } ) * } * > * { __( * 'Generate a snackbar error notice with explicit dismiss button.' * ) } * </Button> * ); * }; * ``` * * @return Action object. */ export declare function createErrorNotice(content: string, options?: NoticeOptions): { type: 'CREATE_NOTICE'; context: string; notice: import("./types").Notice; }; /** * Returns an action object used in signalling that a warning notice is to be * created. Refer to `createNotice` for options documentation. * * @see createNotice * * @param content Notice message. * @param options Optional notice options. * * @example * ```js * import { __ } from '@wordpress/i18n'; * import { useDispatch } from '@wordpress/data'; * import { store as noticesStore } from '@wordpress/notices'; * import { Button } from '@wordpress/components'; * * const ExampleComponent = () => { * const { createWarningNotice, createInfoNotice } = useDispatch( noticesStore ); * return ( * <Button * onClick={ () => * createWarningNotice( __( 'Warning!' ), { * onDismiss: () => { * createInfoNotice( * __( 'The warning has been dismissed!' ) * ); * }, * } ) * } * > * { __( 'Generates a warning notice with onDismiss callback' ) } * </Button> * ); * }; * ``` * * @return Action object. */ export declare function createWarningNotice(content: string, options?: NoticeOptions): { type: 'CREATE_NOTICE'; context: string; notice: import("./types").Notice; }; /** * Returns an action object used in signalling that a notice is to be removed. * * @param id Notice unique identifier. * @param context Optional context (grouping) in which the notice is * intended to appear. Defaults to 'default' context. * * @example * ```js * import { __ } from '@wordpress/i18n'; * import { useDispatch } from '@wordpress/data'; * import { store as noticesStore } from '@wordpress/notices'; * import { Button } from '@wordpress/components'; * * const ExampleComponent = () => { * const notices = useSelect( ( select ) => select( noticesStore ).getNotices() ); * const { createWarningNotice, removeNotice } = useDispatch( noticesStore ); * * return ( * <> * <Button * onClick={ () => * createWarningNotice( __( 'Warning!' ), { * isDismissible: false, * } ) * } * > * { __( 'Generate a notice' ) } * </Button> * { notices.length > 0 && ( * <Button onClick={ () => removeNotice( notices[ 0 ].id ) }> * { __( 'Remove the notice' ) } * </Button> * ) } * </> * ); *}; * ``` * * @return Action object. */ export declare function removeNotice(id: string, context?: string): Extract<ReducerAction, { type: 'REMOVE_NOTICE'; }>; /** * Removes all notices from a given context. Defaults to the default context. * * @param noticeType The context to remove all notices from. * @param context The optional context to remove all notices from. * * @example * ```js * import { __ } from '@wordpress/i18n'; * import { useDispatch, useSelect } from '@wordpress/data'; * import { store as noticesStore } from '@wordpress/notices'; * import { Button } from '@wordpress/components'; * * export const ExampleComponent = () => { * const notices = useSelect( ( select ) => * select( noticesStore ).getNotices() * ); * const { removeAllNotices } = useDispatch( noticesStore ); * return ( * <> * <ul> * { notices.map( ( notice ) => ( * <li key={ notice.id }>{ notice.content }</li> * ) ) } * </ul> * <Button * onClick={ () => * removeAllNotices() * } * > * { __( 'Clear all notices', 'woo-gutenberg-products-block' ) } * </Button> * <Button * onClick={ () => * removeAllNotices( 'snackbar' ) * } * > * { __( 'Clear all snackbar notices', 'woo-gutenberg-products-block' ) } * </Button> * </> * ); * }; * ``` * * @return Action object. */ export declare function removeAllNotices(noticeType?: string, context?: string): Extract<ReducerAction, { type: 'REMOVE_ALL_NOTICES'; }>; /** * Returns an action object used in signalling that several notices are to be removed. * * @param ids List of unique notice identifiers. * @param context Optional context (grouping) in which the notices are * intended to appear. Defaults to 'default' context. * @example * ```js * import { __ } from '@wordpress/i18n'; * import { useDispatch, useSelect } from '@wordpress/data'; * import { store as noticesStore } from '@wordpress/notices'; * import { Button } from '@wordpress/components'; * * const ExampleComponent = () => { * const notices = useSelect( ( select ) => * select( noticesStore ).getNotices() * ); * const { removeNotices } = useDispatch( noticesStore ); * return ( * <> * <ul> * { notices.map( ( notice ) => ( * <li key={ notice.id }>{ notice.content }</li> * ) ) } * </ul> * <Button * onClick={ () => * removeNotices( notices.map( ( { id } ) => id ) ) * } * > * { __( 'Clear all notices' ) } * </Button> * </> * ); * }; * ``` * @return Action object. */ export declare function removeNotices(ids: Array<string>, context?: string): Extract<ReducerAction, { type: 'REMOVE_NOTICES'; }>; //# sourceMappingURL=actions.d.ts.map