// tslint:disable-next-line:no-implicit-dependencies import * as Preact from 'preact'; import styled, { flush, CreateStyled } from '../'; const h = Preact.h; let Component; let mount; /* * Inference HTML Tag Props */ const Component0 = styled.div({ color: 'red' }); mount = event} />; Component = styled('div')({ color: 'red' }); mount = event} />; Component = styled.div`color: red;`; mount = event} />; Component = styled('div')`color: red;`; mount = event} />; Component = styled.a({ color: 'red' }); mount = ; Component = styled('a')({ color: 'red' }); mount = ; /* * Passing custom props */ interface CustomProps { lookColor: string; } Component = styled.div( { color: 'blue' }, props => ({ background: props.lookColor, }), props => ({ border: `1px solid ${props.lookColor}`, }), ); mount = ; Component = styled('div')( { color: 'blue' }, props => ({ background: props.lookColor, }), ); mount = ; const anotherColor = 'blue'; Component = styled('div')` background: ${(props: CustomProps) => props.lookColor}; color: ${anotherColor}; `; mount = ; /* * With other components */ interface CustomProps2 { customProp: string; } interface SFCComponentProps { className?: string; foo: string; } const SFCComponent: Preact.FunctionalComponent = props => (
{props.children} {props.foo}
); declare class MyClassC extends Preact.Component { render(): JSX.Element; } // infer SFCComponentProps Component = styled(SFCComponent)({ color: 'red' }); mount = ; // infer SFCComponentProps Component = styled(SFCComponent)`color: red`; mount = ; Component = styled(MyClassC)``; mount = ; // do not infer SFCComponentProps with pass CustomProps, need to pass both Component = styled(SFCComponent)({ color: 'red', }, props => ({ background: props.customProp, })); mount = ; // do not infer SFCComponentProps with pass CustomProps, need to pass both Component = styled(SFCComponent)` color: red; background: ${(props: CustomProps2) => props.customProp}; `; mount = ; /* * With explicit theme */ interface Theme { color: { primary: string; secondary: string; }; } const _styled = styled as CreateStyled; Component = _styled.div` color: ${props => props.theme.color.primary} `; mount = event} />; /* * withComponent */ interface CustomProps3 { bgColor: string; } Component = styled.div(props => ({ bgColor: props.bgColor, })); const Link = Component.withComponent('a'); mount = ; const Button = Component.withComponent('button'); mount =