import * as React from "react";
import styled from "../..";
interface OptionalProps {
text?: string;
}
interface ThemedOptionalProps extends OptionalProps {
theme: any;
}
interface RequiredProps {
text: string;
}
interface ThemedRequiredProps extends 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
}
}
// 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
}
}
// 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
}
}