From 6bc55814c44bcbd78f8d693c83688ec357785073 Mon Sep 17 00:00:00 2001 From: Derek Sifford Date: Wed, 10 Jul 2019 17:26:39 -0400 Subject: [PATCH] [@wordpress/nux] add new definitions (#36693) --- types/wordpress__nux/components/dot-tip.d.ts | 19 ++++++++++ types/wordpress__nux/index.d.ts | 14 +++++++ types/wordpress__nux/store/actions.d.ts | 24 ++++++++++++ types/wordpress__nux/store/selectors.d.ts | 34 +++++++++++++++++ types/wordpress__nux/tsconfig.json | 28 ++++++++++++++ types/wordpress__nux/tslint.json | 1 + types/wordpress__nux/wordpress__nux-tests.tsx | 38 +++++++++++++++++++ 7 files changed, 158 insertions(+) create mode 100644 types/wordpress__nux/components/dot-tip.d.ts create mode 100644 types/wordpress__nux/index.d.ts create mode 100644 types/wordpress__nux/store/actions.d.ts create mode 100644 types/wordpress__nux/store/selectors.d.ts create mode 100644 types/wordpress__nux/tsconfig.json create mode 100644 types/wordpress__nux/tslint.json create mode 100644 types/wordpress__nux/wordpress__nux-tests.tsx diff --git a/types/wordpress__nux/components/dot-tip.d.ts b/types/wordpress__nux/components/dot-tip.d.ts new file mode 100644 index 0000000000..60bd982a82 --- /dev/null +++ b/types/wordpress__nux/components/dot-tip.d.ts @@ -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; + +export default DotTip; diff --git a/types/wordpress__nux/index.d.ts b/types/wordpress__nux/index.d.ts new file mode 100644 index 0000000000..81bf690149 --- /dev/null +++ b/types/wordpress__nux/index.d.ts @@ -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 +// 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'; diff --git a/types/wordpress__nux/store/actions.d.ts b/types/wordpress__nux/store/actions.d.ts new file mode 100644 index 0000000000..51d8b6bd53 --- /dev/null +++ b/types/wordpress__nux/store/actions.d.ts @@ -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; diff --git a/types/wordpress__nux/store/selectors.d.ts b/types/wordpress__nux/store/selectors.d.ts new file mode 100644 index 0000000000..4a23d92ef7 --- /dev/null +++ b/types/wordpress__nux/store/selectors.d.ts @@ -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; diff --git a/types/wordpress__nux/tsconfig.json b/types/wordpress__nux/tsconfig.json new file mode 100644 index 0000000000..8878180090 --- /dev/null +++ b/types/wordpress__nux/tsconfig.json @@ -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" + ] +} diff --git a/types/wordpress__nux/tslint.json b/types/wordpress__nux/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/wordpress__nux/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } diff --git a/types/wordpress__nux/wordpress__nux-tests.tsx b/types/wordpress__nux/wordpress__nux-tests.tsx new file mode 100644 index 0000000000..967e5b8728 --- /dev/null +++ b/types/wordpress__nux/wordpress__nux-tests.tsx @@ -0,0 +1,38 @@ +import { dispatch, select } from '@wordpress/data'; +import * as nux from '@wordpress/nux'; + +// +// components/dot-tip +// +foobar; + + <> +

foo

+

bar

+ +
; + +// +// 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');