import * as React from "react";
import styled from "../..";
interface OptionalProps {
text?: string;
}
interface IndexedProps {
[prop: string]: any;
}
interface ThemedOptionalProps extends OptionalProps {
theme: any;
}
interface RequiredProps {
text: string;
}
interface ThemedRequiredProps extends RequiredProps {
theme: any;
}
interface IndexedAndRequiredProps extends IndexedProps, RequiredProps { }
interface ThemedIndexedProps extends IndexedProps {
theme: any;
}
interface ThemedIndexedAndRequiredProps extends IndexedProps, RequiredProps {
theme: any;
}
declare const theme: any;
// Tests of stateless functional components
function statelessFunctionalComponents() {
function optionalProps() {
const Component = (props: OptionalProps) =>
{props.text}
;
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
;
;
;
; // theme is allowed
;
; // theme is allowed
}
function optionalPropsWithRequiredTheme() {
const Component = (props: ThemedOptionalProps) => {props.text}
;
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
; // theme is required
; // theme is required
; // theme is optional
; // theme is allowed
; // theme is optional
; // theme is allowed
}
function requiredProps() {
const Component = (props: RequiredProps) => {props.text}
;
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
// ; // text required
;
// ; // text required
;
; // theme is allowed
// ; // text allowed
;
; // theme is allowed
}
function requiredPropsWithRequiredTheme() {
const Component = (props: ThemedRequiredProps) => {props.text}
;
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
// ; // theme is required
; // theme is required
// ; // text required
; // theme is optional
; // theme is allowed
// ; // text required
; // theme is optional
; // theme is allowed
}
function indexedProps() {
const Component = (props: IndexedProps) => {props.text}
;
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
; // text is optional through index signature
; // text is allowed through index signature
; // text is optional through index signature
; // text is allowed through index signature; theme is optional
; // theme is allowed
; // text is optional through index signature
; // text is allowed through index signature; theme is optional
; // theme is allowed
}
function indexedAndRequiredProps() {
const Component = (props: IndexedAndRequiredProps) => {props.text}
;
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
// ; // text is required
; // text is required
; // text is required; foo is allowed through index signature
// ; // text is required
// ; // text is required; foo is indexed; theme is optional
; // text is required; theme is optional
; // text is required; foo is indexed; theme is optional
; // text is required; theme is allowed
; // text is required; foo is indexed; theme is allowed
// ; // text is required
// ; // text is required; foo is indexed; theme is optional
; // text is required; theme is optional
; // text is required; foo is indexed; theme is optional
; // text is required; theme is allowed
; // text is required; foo is indexed; theme is allowed
}
function indexedPropsWithRequiredTheme() {
const Component = (props: ThemedIndexedProps) => {props.text}
;
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
// ; // theme is required
; // theme is required
; // theme is required; foo is indexed prop
; // theme is optional
; // theme is optional; foo is indexed prop
; // theme is allowed; foo is indexed prop
; // theme is optional
; // theme is optional; foo is indexed prop
; // theme is allowed; foo is indexed prop
}
function indexedAndRequiredPropsWithRequiredTheme() {
const Component = (props: ThemedIndexedAndRequiredProps) => {props.text}
;
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
// ; // text and theme are required
// ; // theme is required
// ; theme is required
; // text is required; theme is required
; // text is required; foo is indexed; theme is required
// ; // text is required; theme is optional
// ; // text is required; theme is optional
; // text is required; theme is optional
; // text is required; theme is optional; foo is indexed
; // text is required; theme is allowed
; // text is required; foo is indexed; theme is allowed
// ; // text is required; theme is optional
// ; // text is required; theme is optional
; // text is indexed; theme is optional
; // theme is allowed
}
}
// Tests of pure components
function pureComponents() {
function optionalProps() {
class Component extends React.PureComponent {
render() { return {this.props.text}
; }
}
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
;
;
;
; // theme is allowed
;
; // theme is allowed
}
function optionalPropsWithRequiredTheme() {
class Component extends React.PureComponent {
render() { return {this.props.text}
; }
}
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
; // theme is required
; // theme is required
; // theme is optional
; // theme is allowed
; // theme is optional
; // theme is allowed
}
function requiredProps() {
class Component extends React.PureComponent {
render() { return {this.props.text}
; }
}
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
// ; // text required
;
// ; // text required
;
; // theme is allowed
// ; // text allowed
;
; // theme is allowed
}
function requiredPropsWithRequiredTheme() {
class Component extends React.PureComponent {
render() { return {this.props.text}
; }
}
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
// ; // theme is required
; // theme is required
// ; // text required
; // theme is optional
; // theme is allowed
// ; // text required
; // theme is optional
; // theme is allowed
}
function indexedProps() {
class Component extends React.PureComponent {
render() { return {this.props.text}
; }
}
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
; // text is optional through index signature
; // text is allowed through index signature
; // text is optional through index signature
; // text is allowed through index signature; theme is optional
; // theme is allowed
; // text is optional through index signature
; // text is allowed through index signature; theme is optional
; // theme is allowed
}
function indexedAndRequiredProps() {
class Component extends React.PureComponent {
render() { return {this.props.text}
; }
}
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
// ; // text is required
; // text is required
; // text is required; foo is allowed through index signature
// ; // text is required
// ; // text is required; foo is indexed; theme is optional
; // text is required; theme is optional
; // text is required; foo is indexed; theme is optional
; // text is required; theme is allowed
; // text is required; foo is indexed; theme is allowed
// ; // text is required
// ; // text is required; foo is indexed; theme is optional
; // text is required; theme is optional
; // text is required; foo is indexed; theme is optional
; // text is required; theme is allowed
; // text is required; foo is indexed; theme is allowed
}
function indexedPropsWithRequiredTheme() {
class Component extends React.PureComponent {
render() { return {this.props.text}
; }
}
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
// ; // theme is required
; // theme is required
; // theme is required; foo is indexed prop
; // theme is optional
; // theme is optional; foo is indexed prop
; // theme is allowed; foo is indexed prop
; // theme is optional
; // theme is optional; foo is indexed prop
; // theme is allowed; foo is indexed prop
}
function indexedAndRequiredPropsWithRequiredTheme() {
class Component extends React.PureComponent {
render() { return {this.props.text}
; }
}
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
// ; // text and theme are required
// ; // theme is required
// ; theme is required
; // text is required; theme is required
; // text is required; foo is indexed; theme is required
// ; // text is required; theme is optional
// ; // text is required; theme is optional
; // text is required; theme is optional
; // text is required; theme is optional; foo is indexed
; // text is required; theme is allowed
; // text is required; foo is indexed; theme is allowed
// ; // text is required; theme is optional
// ; // text is required; theme is optional
; // text is indexed; theme is optional
; // theme is allowed
}
}
// Tests of classic components
function classicComponents() {
function optionalProps() {
class Component extends React.Component {
render() { return {this.props.text}
; }
}
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
;
;
;
; // theme is allowed
;
; // theme is allowed
}
function optionalPropsWithRequiredTheme() {
class Component extends React.Component {
render() { return {this.props.text}
; }
}
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
; // theme is required
; // theme is required
; // theme is optional
; // theme is allowed
; // theme is optional
; // theme is allowed
}
function requiredProps() {
class Component extends React.Component {
render() { return {this.props.text}
; }
}
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
// ; // text required
;
// ; // text required
;
; // theme is allowed
// ; // text allowed
;
; // theme is allowed
}
function requiredPropsWithRequiredTheme() {
class Component extends React.Component {
render() { return {this.props.text}
; }
}
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
// ; // theme is required
; // theme is required
// ; // text required
; // theme is optional
; // theme is allowed
// ; // text required
; // theme is optional
; // theme is allowed
}
function indexedProps() {
class Component extends React.Component {
render() { return {this.props.text}
; }
}
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
; // text is optional through index signature
; // text is allowed through index signature
; // text is optional through index signature
; // text is allowed through index signature; theme is optional
; // theme is allowed
; // text is optional through index signature
; // text is allowed through index signature; theme is optional
; // theme is allowed
}
function indexedAndRequiredProps() {
class Component extends React.Component {
render() { return {this.props.text}
; }
}
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
// ; // text is required
; // text is required
; // text is required; foo is allowed through index signature
// ; // text is required
// ; // text is required; foo is indexed; theme is optional
; // text is required; theme is optional
; // text is required; foo is indexed; theme is optional
; // text is required; theme is allowed
; // text is required; foo is indexed; theme is allowed
// ; // text is required
// ; // text is required; foo is indexed; theme is optional
; // text is required; theme is optional
; // text is required; foo is indexed; theme is optional
; // text is required; theme is allowed
; // text is required; foo is indexed; theme is allowed
}
function indexedPropsWithRequiredTheme() {
class Component extends React.Component {
render() { return {this.props.text}
; }
}
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
// ; // theme is required
; // theme is required
; // theme is required; foo is indexed prop
; // theme is optional
; // theme is optional; foo is indexed prop
; // theme is allowed; foo is indexed prop
; // theme is optional
; // theme is optional; foo is indexed prop
; // theme is allowed; foo is indexed prop
}
function indexedAndRequiredPropsWithRequiredTheme() {
class Component extends React.Component {
render() { return {this.props.text}
; }
}
const StyledComponent = styled(Component)``;
const StyledStyledComponent = styled(StyledComponent)``;
// ; // text and theme are required
// ; // theme is required
// ; theme is required
; // text is required; theme is required
; // text is required; foo is indexed; theme is required
// ; // text is required; theme is optional
// ; // text is required; theme is optional
; // text is required; theme is optional
; // text is required; theme is optional; foo is indexed
; // text is required; theme is allowed
; // text is required; foo is indexed; theme is allowed
// ; // text is required; theme is optional
// ; // text is required; theme is optional
; // text is indexed; theme is optional
; // theme is allowed
}
}