[@wordpress/nux] add new definitions (#36693)

This commit is contained in:
Derek Sifford
2019-07-10 17:26:39 -04:00
committed by Armando Aguirre
parent 3f28071fcb
commit 6bc55814c4
7 changed files with 158 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
import { ComponentType, ReactNode } from '@wordpress/element';
declare namespace DotTip {
interface Props {
/**
* A string that uniquely identifies the tip. Identifiers should be prefixed with the name
* of the plugin, followed by a `/`. For example, `acme/add-to-cart`.
*/
tipId: string;
/**
* Any React element or elements can be passed as children. They will be rendered within the
* tip bubble.
*/
children: ReactNode;
}
}
declare const DotTip: ComponentType<DotTip.Props>;
export default DotTip;

14
types/wordpress__nux/index.d.ts vendored Normal file
View File

@@ -0,0 +1,14 @@
// Type definitions for @wordpress/nux 3.4
// Project: https://github.com/WordPress/gutenberg/tree/master/packages/nux/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';
declare module '@wordpress/data' {
function dispatch(key: 'core/nux'): typeof import('./store/actions');
function select(key: 'core/nux'): typeof import('./store/selectors');
}
export { default as DotTip } from './components/dot-tip';

24
types/wordpress__nux/store/actions.d.ts vendored Normal file
View File

@@ -0,0 +1,24 @@
/**
* When dispatched, this action makes all tips show again.
*/
export function enableTips(): void;
/**
* When dispatched, this action prevents all tips from showing again.
*/
export function disableTips(): void;
/**
* When dispatched, this action dismisses the given tip. A dismissed tip will not show again.
*
* @param id - The tip to dismiss.
*/
export function dismissTip(id: string): void;
/**
* When dispatched, this action presents a guide that takes the user through a series of tips step
* by step.
*
* @param tipIds - Which tips to show in the guide.
*/
export function triggerGuide(tipIds: string[]): void;

View File

@@ -0,0 +1,34 @@
export interface GuideInfo {
/**
* Which tips the guide contains.
*/
tipIds: string[];
/**
* The guide's currently showing tip.
*/
currentTipId?: string;
/**
* The guide's next tip to show.
*/
nextTipId?: string;
}
/**
* Returns whether or not tips are globally enabled.
*/
export function areTipsEnabled(): boolean;
/**
* Returns an object describing the guide, if any, that the given tip is a part of.
*
* @param tipId - The tip to query.
*/
export function getAssociatedGuide(tipId: string): GuideInfo | undefined;
/**
* Determines whether or not the given tip is showing. Tips are hidden if they are disabled, have
* been dismissed, or are not the current tip in any guide that they have been added to.
*
* @param tipId - The tip to query.
*/
export function isTipVisible(tipId: string): boolean;

View File

@@ -0,0 +1,28 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["dom", "es6"],
"jsx": "preserve",
"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/nux": ["wordpress__nux"]
}
},
"files": [
"components/dot-tip.d.ts",
"index.d.ts",
"store/actions.d.ts",
"store/selectors.d.ts",
"wordpress__nux-tests.tsx"
]
}

View File

@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }

View File

@@ -0,0 +1,38 @@
import { dispatch, select } from '@wordpress/data';
import * as nux from '@wordpress/nux';
//
// components/dot-tip
//
<nux.DotTip tipId="foo/bar">foobar</nux.DotTip>;
<nux.DotTip tipId="foo/bar">
<>
<h1>foo</h1>
<h1>bar</h1>
</>
</nux.DotTip>;
//
// store
//
// $ExpectType void
dispatch('core/nux').disableTips();
// $ExpectType void
dispatch('core/nux').dismissTip('foo/bar');
// $ExpectType void
dispatch('core/nux').enableTips();
// $ExpectType void
dispatch('core/nux').triggerGuide(['foo/bar', 'foo/baz']);
// $ExpectType boolean
select('core/nux').areTipsEnabled();
// $ExpectType GuideInfo | undefined
select('core/nux').getAssociatedGuide('foo/bar');
// $ExpectType boolean
select('core/nux').isTipVisible('foo/bar');