mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 10:56:53 +00:00
[@wordpress/element] add new definitions (#35877)
This commit is contained in:
parent
94061c1de4
commit
ab96f30acf
59
types/wordpress__element/index.d.ts
vendored
Normal file
59
types/wordpress__element/index.d.ts
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
// Type definitions for @wordpress/element 2.4
|
||||
// Project: https://github.com/WordPress/gutenberg/tree/master/packages/element/README.md
|
||||
// Definitions by: Derek Sifford <https://github.com/dsifford>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 3.4
|
||||
|
||||
import * as R from "react";
|
||||
import * as RD from "react-dom";
|
||||
|
||||
declare global {
|
||||
namespace React {
|
||||
//
|
||||
// ReactDOM re-exports
|
||||
//
|
||||
const createPortal: typeof RD.createPortal;
|
||||
const findDOMNode: typeof RD.findDOMNode;
|
||||
const render: typeof RD.render;
|
||||
const unmountComponentAtNode: typeof RD.unmountComponentAtNode;
|
||||
|
||||
/**
|
||||
* Component used as equivalent of Fragment with unescaped HTML, in cases where
|
||||
* it is desirable to render dangerous HTML without needing a wrapper element.
|
||||
* To preserve additional props, a `div` wrapper _will_ be created if any props
|
||||
* aside from `children` are passed.
|
||||
*
|
||||
* @param props.children - HTML to render.
|
||||
*
|
||||
* @return Dangerously-rendering element.
|
||||
*/
|
||||
function RawHTML(
|
||||
props: { children: string } & HTMLProps<HTMLDivElement>
|
||||
): JSX.Element;
|
||||
|
||||
/**
|
||||
* Checks if the provided WP element is empty.
|
||||
*
|
||||
* @param element - WP element to check.
|
||||
* @return True when an element is considered empty.
|
||||
*/
|
||||
function isEmptyElement(element: ReactNode): boolean;
|
||||
|
||||
/**
|
||||
* Serializes a React element to string.
|
||||
*
|
||||
* @param element - Element to serialize.
|
||||
* @param context - Context object.
|
||||
* @param legacyContext - Legacy context object.
|
||||
*
|
||||
* @return Serialized element.
|
||||
*/
|
||||
function renderToString(
|
||||
element: ReactNode,
|
||||
context?: any,
|
||||
legacyContext?: any
|
||||
): string;
|
||||
}
|
||||
}
|
||||
|
||||
export = React;
|
||||
6
types/wordpress__element/package.json
Normal file
6
types/wordpress__element/package.json
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"csstype": "^2.2.0"
|
||||
}
|
||||
}
|
||||
19
types/wordpress__element/tsconfig.json
Normal file
19
types/wordpress__element/tsconfig.json
Normal file
@ -0,0 +1,19 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"module": "commonjs",
|
||||
"lib": ["es6", "dom"],
|
||||
"noImplicitAny": true,
|
||||
"noImplicitThis": true,
|
||||
"strictNullChecks": true,
|
||||
"strictFunctionTypes": true,
|
||||
"baseUrl": "../",
|
||||
"typeRoots": ["../"],
|
||||
"types": [],
|
||||
"noEmit": true,
|
||||
"forceConsistentCasingInFileNames": true,
|
||||
"paths": {
|
||||
"@wordpress/element": ["wordpress__element"]
|
||||
}
|
||||
},
|
||||
"files": ["index.d.ts", "wordpress__element-tests.ts"]
|
||||
}
|
||||
1
types/wordpress__element/tslint.json
Normal file
1
types/wordpress__element/tslint.json
Normal file
@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
23
types/wordpress__element/wordpress__element-tests.ts
Normal file
23
types/wordpress__element/wordpress__element-tests.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import * as WPElement from "@wordpress/element";
|
||||
|
||||
const testElement = WPElement.createElement(
|
||||
"div",
|
||||
{ className: "foobar" },
|
||||
"hello world"
|
||||
);
|
||||
|
||||
WPElement.createRef();
|
||||
|
||||
WPElement.createPortal(testElement, document.createElement("div"));
|
||||
|
||||
WPElement.findDOMNode(null);
|
||||
|
||||
WPElement.render(testElement, document.createElement("div"));
|
||||
|
||||
WPElement.unmountComponentAtNode(document.createElement("div"));
|
||||
|
||||
WPElement.RawHTML({ children: "<h1>Hello world</h1>" });
|
||||
|
||||
WPElement.isEmptyElement("hello world");
|
||||
|
||||
WPElement.renderToString(WPElement.createElement("div", {}, "hello world"));
|
||||
Loading…
Reference in New Issue
Block a user