-
Notifications
You must be signed in to change notification settings - Fork 414
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #197
- Loading branch information
Showing
10 changed files
with
323 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// TypeScript Version: 2.8 | ||
|
||
declare module 'linaria' { | ||
type Falsy = false | undefined | null | 0; | ||
|
||
function css( | ||
strings: TemplateStringsArray, | ||
...exprs: Array<string | number | object> | ||
): string; | ||
|
||
function cx(...classNames: Array<string | Falsy>): string; | ||
} | ||
|
||
declare module 'linaria/react' { | ||
import * as React from 'react'; | ||
|
||
type Overwrite<T1, T2> = { [P in Exclude<keyof T1, keyof T2>]: T1[P] } & T2; | ||
|
||
type InterpolationFunction<T> = (props: T) => string | number; | ||
|
||
type StyledComponent<T> = React.StatelessComponent< | ||
T & { as?: React.ReactType } | ||
>; | ||
|
||
type StyledTag<T> = ( | ||
strings: TemplateStringsArray, | ||
...exprs: Array<string | number | object | InterpolationFunction<T>> | ||
) => StyledComponent<T>; | ||
|
||
type StyledJSXIntrinsics = { | ||
[P in keyof JSX.IntrinsicElements]: StyledTag< | ||
JSX.IntrinsicElements[P] & { [key: string]: any } | ||
> | ||
}; | ||
|
||
const styled: StyledJSXIntrinsics & { | ||
<T>(component: React.ReactType<T>): StyledTag<T>; | ||
|
||
[key: string]: StyledTag<{ | ||
children?: React.ReactNode; | ||
[key: string]: any; | ||
}>; | ||
}; | ||
} | ||
|
||
declare module 'linaria/server' { | ||
function collect( | ||
html: string, | ||
css: string | ||
): { critical: string; other: string }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { css, cx } from 'linaria'; | ||
|
||
const tomato = 'tomato'; | ||
const border = 1; | ||
|
||
const absoluteFill = { | ||
position: 'absolute', | ||
top: 0, | ||
left: 0, | ||
bottom: 0, | ||
right: 0, | ||
}; | ||
|
||
// $ExpectType string | ||
css` | ||
color: ${tomato}; | ||
border-width: ${border}px; | ||
&.abs { | ||
${absoluteFill}; | ||
} | ||
`; | ||
|
||
// $ExpectType string | ||
css`font-family: sans-serif`; | ||
|
||
// $ExpectError | ||
css`color: ${true}`; | ||
|
||
// $ExpectError | ||
css`color: ${undefined}`; | ||
|
||
// $ExpectError | ||
css`color: ${null}`; | ||
|
||
// $ExpectType string | ||
cx('test', false, undefined, null, 0); | ||
|
||
// $ExpectError | ||
cx('test', 42); | ||
|
||
// $ExpectError | ||
cx('test', true); | ||
|
||
// $ExpectError | ||
cx('test', {}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import * as React from 'react'; | ||
import { styled } from 'linaria/react'; | ||
|
||
const white = 'white'; | ||
const tomato = 'tomato'; | ||
const border = 1; | ||
|
||
const absoluteFill = { | ||
position: 'absolute', | ||
top: 0, | ||
left: 0, | ||
bottom: 0, | ||
right: 0, | ||
}; | ||
|
||
const Button = styled.button` | ||
color: ${white}; | ||
background-color: ${props => props.background}; | ||
border-width: ${border}px; | ||
&.abs { | ||
${absoluteFill}; | ||
} | ||
`; | ||
|
||
const CustomButton = styled(Button)` | ||
&:hover { | ||
background-color: ${tomato}; | ||
} | ||
`; | ||
|
||
class Title extends React.Component<{ label: string; className?: string }> { | ||
render() { | ||
return <h1 className={this.props.className}>{this.props.label}</h1>; | ||
} | ||
} | ||
|
||
const CustomTitle = styled(Title)` | ||
font-family: sans-serif; | ||
`; | ||
|
||
// $Expect Element | ||
<Button as="a">Hello world</Button>; | ||
|
||
// $ExpectError | ||
<Button onClick={42}>Hello world</Button>; | ||
|
||
// $Expect Element | ||
<CustomButton onClick={() => alert('Clicked')}>Hello world</CustomButton>; | ||
|
||
// $Expect Element | ||
<CustomTitle label="Hello world" />; | ||
|
||
// $Expect Element | ||
<CustomTitle label="Hello world" className="primary" />; | ||
|
||
// $ExpectError | ||
<CustomTitle />; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { collect } from 'linaria/server'; | ||
|
||
// $ExpectType { critical: string; other: string; } | ||
collect( | ||
'<div class="foo">Hello</div>', | ||
'.foo { color: blue; }' | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": ["es6", "dom"], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictNullChecks": true, | ||
"strictFunctionTypes": true, | ||
"noEmit": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"jsx": "react" | ||
} | ||
} |
Oops, something went wrong.