{
expect(getByText('hello world')).toHaveCompiledCss('font-size', '12px');
});
+ it('should not type error with nested selectors', () => {
+
+ hello world
+
;
+ });
+
it('should create css from string', () => {
const { getByText } = render(
hello world
);
diff --git a/packages/css-in-js/src/styled/__tests__/index.test.tsx b/packages/css-in-js/src/styled/__tests__/index.test.tsx
index 74af3d12d..b85f2421a 100644
--- a/packages/css-in-js/src/styled/__tests__/index.test.tsx
+++ b/packages/css-in-js/src/styled/__tests__/index.test.tsx
@@ -106,6 +106,49 @@ describe('styled component', () => {
expect(getByText('hello world').getAttribute('href')).toEqual('#');
});
+ it('should not type error with nested selectors', () => {
+ styled.div({
+ color: 'currentColor',
+ textDecoration: 'none',
+ position: 'relative',
+ ':before': {
+ opacity: 0,
+ content: '⚓',
+ position: 'absolute',
+ left: '-5rem',
+ fontSize: '3rem',
+ },
+ ':hover': {
+ ':before': {
+ opacity: 1,
+ },
+ },
+ });
+ });
+
+ it('should not type error with nested arrow funcs', () => {
+ styled.div<{ fontSize: string }>({
+ color: 'currentColor',
+ textDecoration: 'none',
+ position: 'relative',
+ fontSize: props => props.fontSize,
+ ':before': {
+ fontSize: props => props.fontSize,
+ opacity: 0,
+ content: '⚓',
+ position: 'absolute',
+ left: '-5rem',
+ },
+ ':hover': {
+ fontSize: props => props.fontSize,
+ ':before': {
+ fontSize: props => props.fontSize,
+ opacity: 1,
+ },
+ },
+ });
+ });
+
it('should forward ref', () => {
let ref: HTMLAnchorElement | null = null;
const Link = styled.a``;
@@ -162,6 +205,25 @@ describe('styled component', () => {
expect(getByText('Hello world').getAttribute('href')).toEqual('/world');
});
+ it('should compose from array', () => {
+ const extra = {
+ color: 'blue',
+ };
+ const StyledLink = styled.div([
+ {
+ fontSize: 12,
+ },
+ extra,
+ ]);
+
+ const { getByText } = render(
Hello world);
+
+ expect(getByText('Hello world')).toHaveCompiledCss({
+ color: 'blue',
+ 'font-size': '12px',
+ });
+ });
+
it('should create css from string', () => {
const StyledDiv = styled.div('font-size: 15px;');
diff --git a/packages/css-in-js/src/styled/index.tsx b/packages/css-in-js/src/styled/index.tsx
index 6a69c0ad8..e94e8da70 100644
--- a/packages/css-in-js/src/styled/index.tsx
+++ b/packages/css-in-js/src/styled/index.tsx
@@ -1,18 +1,15 @@
-import { CSSProperties, ComponentType } from 'react';
+import { ComponentType } from 'react';
import { createSetupError } from '../utils/error';
+import { CssFunction, TemplateInterpolations } from '../types';
-/**
- * Typing for the CSS object.
- */
-export type CssObject
=
- | CSSProperties
- | string
- | Record string | number) | string | number>;
+export interface FunctionIterpolation {
+ (props: TProps): string | number;
+}
/**
- * Typing for the interpolations.
+ * Typing for the CSS object.
*/
-export type Interpolations = string | number | ((props: TProps) => string | number);
+export type CssObject = CssFunction>;
/**
* Extra props added to the output Styled Component.
@@ -29,8 +26,8 @@ export interface StyledProps {
export interface StyledFunctionFromTag {
(
// Allows either string or object (`` or ({}))
- css: CssObject | CssObject[] | TemplateStringsArray,
- ...interpoltations: Interpolations[]
+ css: CssObject | CssObject[],
+ ...interpoltations: (TemplateInterpolations | FunctionIterpolation)[]
): React.ComponentType;
}
@@ -38,7 +35,7 @@ export interface StyledFunctionFromComponent {
(
// Allows either string or object (`` or ({}))
css: CssObject | TemplateStringsArray,
- ...interpoltations: Interpolations[]
+ ...interpoltations: (TemplateInterpolations | FunctionIterpolation)[]
): React.ComponentType;
}
diff --git a/packages/css-in-js/src/types.tsx b/packages/css-in-js/src/types.tsx
index fcd4f9c8e..19476fb28 100644
--- a/packages/css-in-js/src/types.tsx
+++ b/packages/css-in-js/src/types.tsx
@@ -1,4 +1,21 @@
-export type Unused = any;
+import * as CSS from 'csstype';
+
+/**
+ * Typing for the interpolations.
+ */
+export type TemplateInterpolations = string | number;
+
+export type CSSProps = CSS.Properties;
+
+export type AnyKeyCssProps = {
+ [key: string]: AnyKeyCssProps | CSSProps | TValue;
+};
+
+export type CssFunction =
+ | CSSProps
+ | AnyKeyCssProps
+ | TemplateStringsArray
+ | string;
declare global {
namespace jest {
diff --git a/yarn.lock b/yarn.lock
index b641480d3..cbe5f0f5e 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1868,13 +1868,14 @@
version "0.0.30"
resolved "https://registry.yarnpkg.com/@types/strip-json-comments/-/strip-json-comments-0.0.30.tgz#9aa30c04db212a9a0649d6ae6fd50accc40748a1"
-"@types/styled-components@4.1.8", "@types/styled-components@^5.0.1":
- version "4.1.8"
- resolved "https://registry.yarnpkg.com/@types/styled-components/-/styled-components-4.1.8.tgz#15c8a53bb4b9066e528fafb7558963dee5690ae0"
- integrity sha512-NrG0wmB9Rafy5i00GFxUM/uEge148bX2QPr+Q/MI2fXrew6WOp1hN2A3YEG0AeT45z47CMdJ3BEffPsdQCWayA==
+"@types/styled-components@^5.0.1":
+ version "5.1.0"
+ resolved "https://registry.yarnpkg.com/@types/styled-components/-/styled-components-5.1.0.tgz#24d3412ba5395aa06e14fbc93c52f9454cebd0d6"
+ integrity sha512-ZFlLCuwF5r+4Vb7JUmd+Yr2S0UBdBGmI7ctFTgJMypIp3xOHI4LCFVn2dKMvpk6xDB2hLRykrEWMBwJEpUAUIQ==
dependencies:
- "@types/node" "*"
+ "@types/hoist-non-react-statics" "*"
"@types/react" "*"
+ "@types/react-native" "*"
csstype "^2.2.0"
"@types/testing-library__dom@*", "@types/testing-library__dom@^6.0.0":
@@ -3822,6 +3823,11 @@ csstype@^2.2.0, csstype@^2.5.7:
version "2.6.8"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.8.tgz#0fb6fc2417ffd2816a418c9336da74d7f07db431"
+csstype@^2.6.10:
+ version "2.6.10"
+ resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.10.tgz#e63af50e66d7c266edb6b32909cfd0aabe03928b"
+ integrity sha512-D34BqZU4cIlMCY93rZHbrq9pjTAQJ3U8S8rfBqjwHxkGPThWFjzZDQpgMJY0QViLxth6ZKYiwFBo14RdN44U/w==
+
currently-unhandled@^0.4.1:
version "0.4.1"
resolved "https://registry.yarnpkg.com/currently-unhandled/-/currently-unhandled-0.4.1.tgz#988df33feab191ef799a61369dd76c17adf957ea"