mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[@wordpress/notices] add new definitions (#36700)
* [@wordpress/notices] add new definitions * fix build failure
This commit is contained in:
parent
50159e04f0
commit
04bd0915e7
@ -17,6 +17,7 @@
|
||||
"@wordpress/components": ["wordpress__components"],
|
||||
"@wordpress/data": ["wordpress__data"],
|
||||
"@wordpress/element": ["wordpress__element"],
|
||||
"@wordpress/notices": ["wordpress__notices"],
|
||||
"@wordpress/rich-text": ["wordpress__rich-text"]
|
||||
}
|
||||
},
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
import { ComponentType, MouseEventHandler, ReactNode } from '@wordpress/element';
|
||||
import { Status } from '@wordpress/notices';
|
||||
|
||||
declare namespace Notice {
|
||||
interface Props {
|
||||
@ -16,7 +17,7 @@ declare namespace Notice {
|
||||
* @defaultValue true
|
||||
*/
|
||||
isDismissible?: boolean;
|
||||
status?: 'success' | 'warning' | 'error';
|
||||
status?: Status;
|
||||
/**
|
||||
* Function called when dismissing the notice.
|
||||
*/
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
"@wordpress/components": ["wordpress__components"],
|
||||
"@wordpress/data": ["wordpress__data"],
|
||||
"@wordpress/element": ["wordpress__element"],
|
||||
"@wordpress/notices": ["wordpress__notices"],
|
||||
"@wordpress/rich-text": ["wordpress__rich-text"]
|
||||
}
|
||||
},
|
||||
|
||||
61
types/wordpress__notices/index.d.ts
vendored
Normal file
61
types/wordpress__notices/index.d.ts
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
// Type definitions for @wordpress/notices 1.5
|
||||
// Project: https://github.com/WordPress/gutenberg/tree/master/packages/notices/README.md
|
||||
// Definitions by: Derek Sifford <https://github.com/dsifford>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.5
|
||||
|
||||
import { dispatch, select } from '@wordpress/data';
|
||||
import { MouseEventHandler } from '@wordpress/element';
|
||||
|
||||
declare module '@wordpress/data' {
|
||||
function dispatch(key: 'core/notices'): typeof import('./store/actions');
|
||||
function select(key: 'core/notices'): typeof import('./store/selectors');
|
||||
}
|
||||
|
||||
export type Status = 'error' | 'info' | 'success' | 'warning';
|
||||
|
||||
export interface Notice {
|
||||
id: string;
|
||||
status: Status;
|
||||
content: string;
|
||||
isDismissible: boolean;
|
||||
actions: readonly Action[];
|
||||
}
|
||||
|
||||
export interface URLAction {
|
||||
label: string;
|
||||
url: string;
|
||||
}
|
||||
|
||||
export interface CallbackAction {
|
||||
label: string;
|
||||
callback(): void;
|
||||
}
|
||||
|
||||
export type Action = URLAction | CallbackAction;
|
||||
|
||||
export interface Options {
|
||||
/**
|
||||
* User actions to be presented with notice.
|
||||
*/
|
||||
actions: readonly Action[];
|
||||
/**
|
||||
* Context under which to group notice.
|
||||
* @defaultValue `'global'`
|
||||
*/
|
||||
context: string;
|
||||
/**
|
||||
* Identifier for notice. Automatically assigned if not specified.
|
||||
*/
|
||||
id: string;
|
||||
/**
|
||||
* Whether the notice can be dismissed by user.
|
||||
* @defaultValue `true`
|
||||
*/
|
||||
isDismissible: boolean;
|
||||
/**
|
||||
* Whether the notice content should be announced to screen readers.
|
||||
* @defaultValue `true`
|
||||
*/
|
||||
speak: boolean;
|
||||
}
|
||||
50
types/wordpress__notices/store/actions.d.ts
vendored
Normal file
50
types/wordpress__notices/store/actions.d.ts
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
import { Status, Options } from '../';
|
||||
|
||||
/**
|
||||
* Yields action objects used in signalling that a notice is to be created.
|
||||
*
|
||||
* @param [status='info'] - Notice status.
|
||||
* @param content - Notice message.
|
||||
* @param [options={}] - Notice options.
|
||||
*/
|
||||
export function createNotice(status: Status | undefined, content: string, options?: Partial<Options>): void;
|
||||
|
||||
/**
|
||||
* Dispatches an action signalling that an error notice is to be created.
|
||||
*
|
||||
* @param content - Notice message.
|
||||
* @param [options] - Optional notice options.
|
||||
*/
|
||||
export function createErrorNotice(content: string, options?: Partial<Options>): void;
|
||||
|
||||
/**
|
||||
* Dispatches an action signalling that an info notice is to be created.
|
||||
*
|
||||
* @param content - Notice message.
|
||||
* @param [options] - Optional notice options.
|
||||
*/
|
||||
export function createInfoNotice(content: string, options?: Partial<Options>): void;
|
||||
|
||||
/**
|
||||
* Dispatches an action signalling that a success notice is to be created.
|
||||
*
|
||||
* @param content - Notice message.
|
||||
* @param [options] - Optional notice options.
|
||||
*/
|
||||
export function createSuccessNotice(content: string, options?: Partial<Options>): void;
|
||||
|
||||
/**
|
||||
* Dispatches an action signalling that a warning notice is to be created.
|
||||
*
|
||||
* @param content - Notice message.
|
||||
* @param [options] - Optional notice options.
|
||||
*/
|
||||
export function createWarningNotice(content: string, options?: Partial<Options>): void;
|
||||
|
||||
/**
|
||||
* Dispatches an action signalling that a notice is to be removed.
|
||||
*
|
||||
* @param id - Notice's unique identifier.
|
||||
* @param [context] - Optional context (grouping) in which the notice is intended to appear.
|
||||
*/
|
||||
export function removeNotice(id: string, context?: string): void;
|
||||
8
types/wordpress__notices/store/selectors.d.ts
vendored
Normal file
8
types/wordpress__notices/store/selectors.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
import { Notice } from '../';
|
||||
|
||||
/**
|
||||
* Returns all notices as an array, optionally for a given context.
|
||||
*
|
||||
* @param [context='global'] - Optional grouping context.
|
||||
*/
|
||||
export function getNotices(context?: string): Notice[];
|
||||
26
types/wordpress__notices/tsconfig.json
Normal file
26
types/wordpress__notices/tsconfig.json
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["dom", "es6"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"paths": {
|
||||
"@wordpress/data": ["wordpress__data"],
|
||||
"@wordpress/element": ["wordpress__element"],
|
||||
"@wordpress/notices": ["wordpress__notices"]
|
||||
}
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts",
|
||||
"store/actions.d.ts",
|
||||
"store/selectors.d.ts",
|
||||
"wordpress__notices-tests.ts"
|
||||
]
|
||||
}
|
||||
1
types/wordpress__notices/tslint.json
Normal file
1
types/wordpress__notices/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
39
types/wordpress__notices/wordpress__notices-tests.ts
Normal file
39
types/wordpress__notices/wordpress__notices-tests.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import { dispatch, select } from '@wordpress/data';
|
||||
|
||||
//
|
||||
// store
|
||||
//
|
||||
|
||||
dispatch('core/notices').createNotice('warning', 'hello world');
|
||||
dispatch('core/notices').createNotice(undefined, 'hello world', {});
|
||||
dispatch('core/notices').createNotice('info', 'hello world', {
|
||||
isDismissible: true,
|
||||
actions: [
|
||||
{
|
||||
label: 'foo',
|
||||
url: 'https://foo.bar',
|
||||
},
|
||||
{
|
||||
label: 'bar',
|
||||
callback: () => void 0,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
dispatch('core/notices').createErrorNotice('hello world');
|
||||
dispatch('core/notices').createErrorNotice('hello world', {});
|
||||
|
||||
dispatch('core/notices').createInfoNotice('hello world');
|
||||
dispatch('core/notices').createInfoNotice('hello world', { id: 'foo' });
|
||||
|
||||
dispatch('core/notices').createSuccessNotice('hello world');
|
||||
dispatch('core/notices').createSuccessNotice('hello world', { isDismissible: false });
|
||||
|
||||
dispatch('core/notices').createWarningNotice('hello world');
|
||||
dispatch('core/notices').createWarningNotice('hello world', undefined);
|
||||
|
||||
// $ExpectType Notice[]
|
||||
select('core/notices').getNotices();
|
||||
|
||||
// $ExpectType Notice[]
|
||||
select('core/notices').getNotices('foo');
|
||||
@ -16,6 +16,7 @@
|
||||
"@wordpress/data": ["wordpress__data"],
|
||||
"@wordpress/components": ["wordpress__components"],
|
||||
"@wordpress/element": ["wordpress__element"],
|
||||
"@wordpress/notices": ["wordpress__notices"],
|
||||
"@wordpress/plugins": ["wordpress__plugins"],
|
||||
"@wordpress/rich-text": ["wordpress__rich-text"]
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user