Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable css prop in Preact with TypeScript #729

Merged
merged 4 commits into from
Jun 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/create-emotion-styled/types/common.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Definitions by: Junyoung Clare Jang </~https://github.com/Ailrun>
// TypeScript Version: 2.3

import { Emotion, Interpolation as BaseInterpolation } from 'create-emotion';
import { Emotion, Interpolation as BaseInterpolation, CSSObject } from 'create-emotion';

export interface ArrayInterpolation<Props> extends Array<Interpolation<Props>> {}
export type FunctionInterpolation<Props> = (props: Props, context: any) => Interpolation<Props>;
Expand Down
7 changes: 7 additions & 0 deletions packages/create-emotion-styled/types/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,10 @@ const ComposingComp = createStyled.div`
color: black;
}
`;

const CSSPropComp = createStyled.div();
<CSSPropComp css={{ color: 'blue' }} />;
<CSSPropComp css={`
color: blue;
`}
/>;
15 changes: 15 additions & 0 deletions packages/create-emotion/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,18 @@ export interface EmotionOptions {
}

export default function createEmotion(context: EmotionContext, options?: EmotionOptions): Emotion;

declare module 'react' {
interface HTMLAttributes<T> {
css?: Interpolation;
}
}

// Preact support for css prop
declare global {
namespace JSX {
interface HTMLAttributes {
css?: Interpolation;
}
}
}
6 changes: 0 additions & 6 deletions packages/emotion/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,3 @@ export const injectGlobal: Emotion['injectGlobal'];
export const keyframes: Emotion['keyframes'];
export const sheet: Emotion['sheet'];
export const caches: Emotion['caches'];

declare module 'react' {
interface HTMLAttributes<T> {
css?: Interpolation;
}
}
19 changes: 19 additions & 0 deletions packages/preact-emotion/types/test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,25 @@ mount = <Component innerRef={(element: HTMLDivElement) => {}} />;
Component = Component.withComponent('input');
mount = <Component innerRef={(element: HTMLInputElement) => {}} />;

/**
* css prop
*/
Component = styled.div({ color: 'red' });
mount = <Component css={{color: 'blue'}} />;
mount = (
<Component css={`
color: blue;
`}
/>
);
mount = <div css={{ color: 'blue' }} />;
mount = (
<div css={`
color: blue;
`}
/>
);

/*
* Reference to other styled component
*/
Expand Down
19 changes: 19 additions & 0 deletions packages/react-emotion/types/tests.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,25 @@ mount = <Component innerRef={(element: HTMLDivElement) => {}} />;
Component = Component.withComponent('input');
mount = <Component innerRef={(element: HTMLInputElement) => {}} />;

/**
* css prop
*/
Component = styled.div({ color: 'red' });
mount = <Component css={{ color: 'blue' }} />;
mount = (
<Component css={`
color: blue;
`}
/>
);
mount = <div css={{ color: 'blue' }} />;
mount = (
<div css={`
color: blue;
`}
/>
);

/*
* Reference to other styled component
*/
Expand Down