gwt.react.client.api.React Maven / Gradle / Ivy
package gwt.react.client.api;
/* The MIT License (MIT)
Copyright (c) 2016 GWT React
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. */
import gwt.react.client.components.*;
import gwt.react.client.elements.DOMElement;
import gwt.react.client.elements.ReactElement;
import gwt.react.client.elements.ReactElementChildren;
import gwt.react.client.proptypes.*;
import gwt.react.client.proptypes.html.*;
import gwt.react.shared.utils.Array;
import gwt.react.client.utils.ObjLiteral;
import jsinterop.annotations.JsMethod;
import jsinterop.annotations.JsOverlay;
import jsinterop.annotations.JsPackage;
import jsinterop.annotations.JsType;
import static gwt.react.client.api.GwtReact.makeSpec;
@SuppressWarnings("unused")
@JsType(isNative = true, namespace = JsPackage.GLOBAL)
public class React {
/**
* Create a component class, given a specification. A component implements a render method which returns
* one single child. That child may have an arbitrarily deep child structure.
*
* @param component A class derived from {@link ReactClassSpec} to create the class from
* @param The type of Props the component accepts
* @return A component class that can be passed to {@link React#createElement} or
* {@link React#createFactory}
*/
@JsOverlay
public static
ReactClass
createClass(ReactClassSpec
component) {
return _createClass(makeSpec(component));
}
@JsMethod(name="createClass")
private static native
ReactClass
_createClass(InternalClassSpec spec);
/**
*
Create and return a new ReactElement of the given type.
*
* @param type a HTML tag name (eg. 'div', 'span', etc)
* @param props the props to pass to the element
* @return a {@link DOMElement}
*/
public static native
DOMElement
createElement(String type, P props);
public static native
DOMElement
createElement(String type, P props, String value);
public static native
DOMElement
createElement(String type, P props, ReactElement ...child);
/**
* Create and return a new ReactElement of the given type.
*
* @param type a ReactClass (created via React.createClass).
* @param props
* @return a {@link ReactElement}
*/
public static native
ReactElement
> createElement(ReactClass
type, P props);
public static native
ReactElement
> createElement(ReactClass
type, P props, ReactElement ...child);
//Create Stateless Components
public static native
ReactElement
createElement(StatelessComponent type, P props);
public static native
ReactElement
createElement(StatelessComponent type, P props, String value);
public static native
ReactElement
createElement(StatelessComponent type, P props, ReactElement ...child);
//Create ES6 Components (NOT SUPPORTED CURRENTLY)
/**
* Return a function that produces ReactElements of a given type. Like React.createElement,
* the type argument can be either an html tag name string (eg. 'div', 'span', etc), or a
* ReactClass.
*
* @param componentClass The class of the compoment to create the factory for
* @return
*/
public static native
ElementFactory
createFactory(ReactClass
componentClass);
/**
*
Clone and return a new ReactElement using element as the starting point. The resulting
* element will have the original element's props with the new props merged in shallowly.
* New children will replace existing children. Unlike React.addons.cloneWithProps, key and
* ref from the original element will be preserved. There is no special behavior for merging
* any props (unlike cloneWithProps). See the v0.13 RC2 blog post for additional details.
*
* @param element the element to clone
* @param props the props to merge
* @return the cloned element
*/
public static native ReactElement cloneElement(ReactElement element, P props);
public static native boolean isValidElement(Object object);
/**
* React.DOM provides convenience wrappers around React.createElement for DOM components.
* For example React.DOM.div(null, 'Hello World!')
*/
@JsType(isNative = true)
public static class DOM {
public static native DOMElement a(AnchorProps props, String value);
public static native DOMElement a(AnchorProps props, ReactElement ...child);
public static native DOMElement article(HtmlProps props, ReactElement ...child);
public static native DOMElement audio(AudioProps props, ReactElement ...child);
public static native DOMElement br(HtmlProps props);
public static native DOMElement button(BtnProps props);
public static native DOMElement button(BtnProps props, String value);
public static native DOMElement canvas(HtmlProps props);
public static native DOMElement caption(HtmlProps props, String value);
public static native DOMElement caption(HtmlProps props, ReactElement ...child);
public static native DOMElement col(ColProps props, ReactElement ...child);
public static native DOMElement colgroup(HtmlProps props, ReactElement ...child);
public static native DOMElement div(HtmlProps props, String value);
public static native DOMElement div(HtmlProps props, ReactElement ...child);
public static native DOMElement footer(HtmlProps props, ReactElement ...child);
public static native DOMElement form(FormProps props, ReactElement ...child);
public static native DOMElement header(HtmlProps props, ReactElement ...child);
public static native DOMElement h1(HtmlProps props, String value);
public static native DOMElement h2(HtmlProps props, String value);
public static native DOMElement h3(HtmlProps props, String value);
public static native DOMElement h4(HtmlProps props, String value);
public static native DOMElement h5(HtmlProps props, String value);
public static native DOMElement h6(HtmlProps props, String value);
public static native DOMElement iframe(IFrameProps props);
public static native DOMElement img(ImgProps props);
public static native DOMElement input(InputProps props);
public static native DOMElement label(LabelProps props, String value);
public static native DOMElement li(HtmlProps props, String value);
public static native DOMElement li(HtmlProps props, ReactElement ...child);
public static native DOMElement ol(HtmlProps props, ReactElement ...child);
public static native DOMElement option(OptionProps props, String value);
public static native DOMElement optgroup(OptGroupProps props, ReactElement ...child);
public static native DOMElement p(HtmlProps props, String value);
public static native DOMElement p(HtmlProps props, ReactElement ...child);
public static native DOMElement span(HtmlProps props, String value);
public static native DOMElement span(HtmlProps props, ReactElement child1);
public static native DOMElement span(HtmlProps props, ReactElement child1, String value);
public static native DOMElement select(SelectProps props, ReactElement ...child);
public static native DOMElement section(HtmlProps props, ReactElement ...child);
public static native DOMElement strong(HtmlProps props, String value);
public static native DOMElement source(SourceProps props);
public static native DOMElement table(HtmlProps props, ReactElement ...child);
public static native DOMElement td(TdProps props, String value);
public static native DOMElement td(TdProps props, ReactElement ...child);
public static native DOMElement th(ThProps props, String value);
public static native DOMElement th(ThProps props, ReactElement ...child);
public static native DOMElement tr(HtmlProps props, ReactElement ...child);
public static native DOMElement ul(HtmlProps props, ReactElement ...child);
}
/**
* React.Children provides utilities for dealing with the this.props.children opaque data
* structure.
*/
@JsType(isNative = true)
public static class Children {
/**
* Invoke fn on every immediate child contained within children. If children is a nested
* object or array it will be traversed: fn will never be passed the container objects.
* If children is null returns null rather than an array.
*
* @param children The opaque children structure to iterate over
* @param Fn The function to execute
* @return
*/
public final static native Array map(ReactElementChildren children, ChildrenMapFn Fn); // Object thisArg);
/**
* Like React.Children.map() but does not return an array.
*
* @param children The opaque children structure to iterate over
* @param fn The function to execute
*/
public final static native void forEach(ReactElementChildren children, ChildrenForEachFn fn); // [, object thisArg]);
/**
* Return the total number of components in children, equal to the number of times that a
* callback passed to map or forEach would be invoked.
*
* @param children The opaque children structure to count
* @return the number of child components
*/
public final static native int count(ReactElementChildren children);
/**
* Return the only child in children. Throws otherwise.
*
* @param children The opaque children structure to access
* @return the first and only child. Throws an exception if more than one exis
*/
public final static native ReactElement only(ReactElementChildren children);
/**
* Return the children opaque data structure as a flat array with keys assigned to
* each child. Useful if you want to manipulate collections of children in your render
* methods, especially if you want to reorder or slice this.props.children before passing
* it down.
*
* @param children The opaque children structure to iterate over
* @return a {@link Array} of {@link ReactElement}
*/
public final static native Array toArray(ReactElementChildren children);
}
@JsType(isNative = true, name="Component")
public static class Component {
}
}