From ac1bb8a78cd2fc8217b9960c33f3809106265664 Mon Sep 17 00:00:00 2001 From: Aaron Jensen Date: Tue, 26 Jun 2018 00:26:00 -0700 Subject: [PATCH] Enable css prop in Preact with TypeScript (#729) **What**: This adds typescript tests for the css prop for both React and Preact. The Preact tests are currently failing, so they'd need to be fixed before this can be merged. See https://github.com/emotion-js/emotion/issues/693#issuecomment-397858379 **Why**: The tests weren't there before and the css prop only worked with React. **How**: I'm not sure how to answer this question. **Checklist**: - [ ] Documentation N/A - [x] Tests - [x] Code complete --- .../create-emotion-styled/types/common.d.ts | 2 +- packages/create-emotion-styled/types/test.tsx | 7 +++++++ packages/create-emotion/types/index.d.ts | 15 +++++++++++++++ packages/emotion/types/index.d.ts | 6 ------ packages/preact-emotion/types/test.tsx | 19 +++++++++++++++++++ packages/react-emotion/types/tests.tsx | 19 +++++++++++++++++++ 6 files changed, 61 insertions(+), 7 deletions(-) diff --git a/packages/create-emotion-styled/types/common.d.ts b/packages/create-emotion-styled/types/common.d.ts index 52fbea3a8..11cb5abcd 100644 --- a/packages/create-emotion-styled/types/common.d.ts +++ b/packages/create-emotion-styled/types/common.d.ts @@ -1,7 +1,7 @@ // Definitions by: Junyoung Clare Jang // TypeScript Version: 2.3 -import { Emotion, Interpolation as BaseInterpolation } from 'create-emotion'; +import { Emotion, Interpolation as BaseInterpolation, CSSObject } from 'create-emotion'; export interface ArrayInterpolation extends Array> {} export type FunctionInterpolation = (props: Props, context: any) => Interpolation; diff --git a/packages/create-emotion-styled/types/test.tsx b/packages/create-emotion-styled/types/test.tsx index dfd29f3b6..ec8a9c076 100644 --- a/packages/create-emotion-styled/types/test.tsx +++ b/packages/create-emotion-styled/types/test.tsx @@ -191,3 +191,10 @@ const ComposingComp = createStyled.div` color: black; } `; + +const CSSPropComp = createStyled.div(); +; +; diff --git a/packages/create-emotion/types/index.d.ts b/packages/create-emotion/types/index.d.ts index 2b0331f14..9a8b87f75 100644 --- a/packages/create-emotion/types/index.d.ts +++ b/packages/create-emotion/types/index.d.ts @@ -90,3 +90,18 @@ export interface EmotionOptions { } export default function createEmotion(context: EmotionContext, options?: EmotionOptions): Emotion; + +declare module 'react' { + interface HTMLAttributes { + css?: Interpolation; + } +} + +// Preact support for css prop +declare global { + namespace JSX { + interface HTMLAttributes { + css?: Interpolation; + } + } +} diff --git a/packages/emotion/types/index.d.ts b/packages/emotion/types/index.d.ts index a186a17c4..6b912f9b4 100644 --- a/packages/emotion/types/index.d.ts +++ b/packages/emotion/types/index.d.ts @@ -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 { - css?: Interpolation; - } -} diff --git a/packages/preact-emotion/types/test.tsx b/packages/preact-emotion/types/test.tsx index d31a33654..389f6ab15 100644 --- a/packages/preact-emotion/types/test.tsx +++ b/packages/preact-emotion/types/test.tsx @@ -157,6 +157,25 @@ mount = {}} />; Component = Component.withComponent('input'); mount = {}} />; +/** + * css prop + */ +Component = styled.div({ color: 'red' }); +mount = ; +mount = ( + +); +mount =
; +mount = ( +
+); + /* * Reference to other styled component */ diff --git a/packages/react-emotion/types/tests.tsx b/packages/react-emotion/types/tests.tsx index 82e68a4cd..2f6b953d4 100644 --- a/packages/react-emotion/types/tests.tsx +++ b/packages/react-emotion/types/tests.tsx @@ -153,6 +153,25 @@ mount = {}} />; Component = Component.withComponent('input'); mount = {}} />; +/** + * css prop + */ +Component = styled.div({ color: 'red' }); +mount = ; +mount = ( + +); +mount =
; +mount = ( +
+); + /* * Reference to other styled component */