import createEmotion from 'create-emotion'; import * as React from 'react'; import createEmotionStyled, { StyledComponent } from '../'; const context = { name: 'emotion', }; const emotion = createEmotion(context); const createStyled = createEmotionStyled(emotion, React); interface TestClassProps { readonly some: number; partial?: boolean; } class TestClassComp extends React.Component { render() { return (
{this.props.some}
); } } interface TestFunProps0 { complex: { readonly id: number; name: string; friends: Array; }; } const TestFunComp0 = (props: TestFunProps0) => (
{props.complex.friends.map((fid) =>
{fid}
)}
); interface TestFunProps1 extends TestFunProps0 { world: number; } const TestFunComp1 = (props: TestFunProps1) => (
{props.world}
); const StyledClassComp0 = createStyled(TestClassComp)({ width: '200px', }, (props) => ({ height: props.theme.long ? '200px' : '100px', })); const StyledClassComp1 = createStyled(TestClassComp) ` width: 200px; height: ${(props) => props.theme ? '200px' : '100px'}; `; ; { }} />; ; { }} />; { }} />; interface StyledFunProps { color: string; } const StyledFunComp0 = createStyled(TestFunComp0)([{ display: 'inline', position: 'fixed', }, { flexGrow: 20, }], (props, context) => ({ content: context.name, color: props.color, })); const StyledFunComp1 = createStyled(TestFunComp0) ` display: inline; position: fixed; flexGrow: 20; ${(props: StyledFunProps, context) => emotion.css` content: ${context.name}; color: ${props.color}; `} `; ; // $ExpectError ; interface StyledTagProps { typing: number; } const StyledTag0 = createStyled('div')({ margin: 20, marginBottom: '30px', }, (props) => ({ display: Number.isFinite(props.typing) ? 'flex' : 'block', })); const StyledTag1 = createStyled('label')` width: 20px; height: 50px; background-color: green; display: ${(props: StyledTagProps) => { return Number.isFinite(props.typing) ? 'flex' : 'block'; }}; `; ; { ref = ref; }} />; ''} />; ; { ref = ref; }} />; ''} />; const StyledCompWithButton = StyledClassComp0.withComponent('button'); const StyledCompWithFunComp2 = StyledFunComp0.withComponent(TestFunComp1); ; ''} />; ''} innerRef={(ref: HTMLButtonElement) => { }} />; ; // $ExpectError ''} />; const StyledCompShorthand0 = createStyled.a({ textAlign: 'center', }); const StyledCompShorthand1 = createStyled.label` display: block; width: 200px; height: 130px; `; ; ; ; // $ExpectError ; interface ShorthandProps { editor: 'vscode' | 'emacs' | 'sublime'; } const getEditorLogoColor = (editor: 'vscode' | 'emacs' | 'sublime') => { switch (editor) { case 'vscode': return '007bcd'; case 'emacs': return '5e5ba8'; case 'sublime': return 'ff9800'; } }; const StyledCompShorthandWithProps0 = createStyled.div(props => ({ backgroundColor: getEditorLogoColor(props.editor), })); const StyledCompShorthandWithProps1 = createStyled.section` backgroundColor: ${(props: ShorthandProps) => getEditorLogoColor(props.editor)}; `; ; {}} />; ; // $ExpectError ; // $ExpectError createStyled.asdf; const ComposingComp = createStyled.div` ${StyledCompShorthand0} { color: black; } `; const CSSPropComp = createStyled.div(); ; ; interface TestComponentTypeProps { value: number; } declare const TestComponentType: React.ComponentType; const StyledComponentType0 = createStyled(TestComponentType)({ color: 'red', }); const StyledComponentType1 = createStyled(TestComponentType)` color: red; `; const ComposingCompType = createStyled.div` ${StyledComponentType1} { background-color: green; } `; ; ; ;