-
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
9 changed files
with
181 additions
and
7 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
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" | ||
} | ||
} |
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,30 @@ | ||
/// <reference path="../index.d.ts" /> | ||
|
||
import * as React from 'react'; | ||
import { css, cx } from 'linaria'; | ||
|
||
const tomato = 'tomato'; | ||
const border = 1; | ||
|
||
const absoluteFill = { | ||
position: 'absolute', | ||
top: 0, | ||
left: 0, | ||
bottom: 0, | ||
right: 0, | ||
}; | ||
|
||
const title = css` | ||
color: ${tomato}; | ||
border-width: ${border}px; | ||
&.abs { | ||
${absoluteFill}; | ||
} | ||
`; | ||
|
||
const heading = css` | ||
font-family: sans-serif; | ||
`; | ||
|
||
<h1 className={cx(title, heading, false, undefined, null, 0)}>Hello world</h1>; |
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 @@ | ||
/// <reference path="../index.d.ts" /> | ||
|
||
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; | ||
`; | ||
|
||
<Button as="a">Hello world</Button>; | ||
<CustomButton onClick={() => alert('Clicked')}>Hello world</CustomButton>; | ||
<CustomTitle label="Hello world" />; |
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,11 @@ | ||
/// <reference path="../index.d.ts" /> | ||
|
||
import { collect } from 'linaria/server'; | ||
|
||
const { critical, other } = collect( | ||
'<div class="foo">Hello</div>', | ||
'.foo { color: blue; }' | ||
); | ||
|
||
critical.toLowerCase(); | ||
other.toLowerCase(); |
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,49 @@ | ||
declare module 'linaria' { | ||
export const css: ( | ||
strings: TemplateStringsArray, | ||
...exprs: Array<string | number | object> | ||
) => string; | ||
|
||
export const cx: ( | ||
...classNames: Array<string | false | undefined | null | 0> | ||
) => 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.ComponentType< | ||
Overwrite<T, { as?: React.ReactType<any>; className?: string }> | ||
>; | ||
|
||
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 } | ||
> | ||
}; | ||
|
||
export const styled: StyledJSXIntrinsics & { | ||
<T>(component: React.ReactType<T>): StyledTag<T>; | ||
|
||
[key: string]: StyledTag<{ | ||
children?: React.ReactNode; | ||
[key: string]: any; | ||
}>; | ||
}; | ||
} | ||
|
||
declare module 'linaria/server' { | ||
export const 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