DefinitelyTyped/types/react-flag-icon-css/react-flag-icon-css-tests.tsx
Jessica Franco 7c28be5245 Fix packages depending on React so React's tests pass (#30331)
* Fix tests of packages that depend on react

* Hack to pass next's tests in TS@next

* Remove dummy type added to force tests

* Revert "Hack to pass next's tests in TS@next"

This reverts commit 01cc013fd42ec395ac63048e9ff865e23a437014.

* Workaround for TS@3.1 error that is not an error in TS@next

* Revert redux-form changes

* Fix redux-form error like reactstrap was fixed

It's the same problem with inference, and avoids breaking more things.

* Bump TS version for redux-form as it's needed for tests to pass
2018-11-08 12:44:16 -08:00

87 lines
2.2 KiB
TypeScript

import * as React from 'react';
import * as ReactDOM from 'react-dom';
import FlagIconFactory, { CustomFlagIconFactory, FlagIconSize } from 'react-flag-icon-css';
const FlagIcon = FlagIconFactory(React, {useCssModules: false});
/**
* based on https://github.com/matteocng/react-flag-icon-css#basic-usage
*/
interface SimpleFlagComponentProps {
code: string;
size: FlagIconSize;
}
export class SimpleFlagComponent extends React.PureComponent<SimpleFlagComponentProps> {
render() {
return (
<FlagIcon code={this.props.code} size={this.props.size}/>
);
}
}
const rootEL = document.getElementById('react-app') as HTMLElement;
const appProps: SimpleFlagComponentProps = {
code: 'it',
size: '3x'
};
ReactDOM.render(<SimpleFlagComponent {...appProps} />, rootEL);
/**
* based on https://github.com/matteocng/react-flag-icon-css#exampleCustomFlagsIndex
*/
const styles = {
['.flag-icon-ex1']: {
'background-image': '../images/4x3/ex1.svg'
},
['.flag-icon-ex1.flag-icon-squared']: {
'background-image': '../images/1x1/ex1.svg'
}
};
const codes = {
ex1: 'Example 1 country'
};
const optionsCssModules = {customCodes: codes, themeStyles: styles};
const FlagIconCssModules = CustomFlagIconFactory(React, optionsCssModules);
export class CustomFlagComponent extends React.PureComponent<SimpleFlagComponentProps> {
render() {
return (
<FlagIconCssModules code={this.props.code} size={this.props.size}/>
);
}
}
const appCustomProps: SimpleFlagComponentProps = {
code: 'ex1',
size: 'lg'
};
ReactDOM.render(<CustomFlagComponent {...appCustomProps} />, rootEL);
/**
* based on 'props:children' test
*/
interface ChildrenFlagComponentProps {
code: string;
size: FlagIconSize;
children: React.ReactNode;
}
export class ChildrenFlagComponent extends React.PureComponent<ChildrenFlagComponentProps> {
render() {
return (
<FlagIcon code={this.props.code} size={this.props.size} children={this.props.children}/>
);
}
}
const appChildrenProps: ChildrenFlagComponentProps = {
code: 'ex1',
size: 'lg',
children: <FlagIcon code='it'/>
};
ReactDOM.render(<ChildrenFlagComponent {...appChildrenProps} />, rootEL);