expanded the test file to use all of the library correctly. corrected LoopableProps definition.

This commit is contained in:
Chris Gervang
2017-03-25 17:44:29 -07:00
parent 5c64371d89
commit 48032bc9c4
2 changed files with 63 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
// Type definitions for ReactCSS v1.2.0
// Type definitions for ReactCSS 1.2.0
// Project: http://reactcss.com/
// Definitions by: Chris Gervang <https://github.com/chrisgervang>, Karol Janyst <https://github.com/LKay>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
@@ -6,15 +6,15 @@
import * as React from "react"
interface LoopableProps {
interface LoopableProps extends React.Props<any> {
"nth-child": number
"first-child"?: boolean
"last-child"?: boolean
even?: boolean
odd?: boolean
[nthChild: string]: boolean
}
interface HoverProps {
interface HoverProps<T> extends React.Props<T> {
hover?: boolean
}
@@ -25,5 +25,5 @@ interface Classes<T> {
export type CSS = React.CSSProperties
export function hover<A>(component: React.ComponentClass<A> | React.StatelessComponent<A>): React.ComponentClass<A>
export function loop(i: number, length: number): LoopableProps
export function loop(index: number, length: number): LoopableProps
export default function reactCSS<T>(classes: Classes<T>, ...activations: Array<any>): T

View File

@@ -1,19 +1,67 @@
import * as React from "react"
import { StatelessComponent } from "react"
import { SFC } from "react"
import { render } from "react-dom"
import { default as reactCSS, hover, loop, LoopableProps, HoverProps } from "reactcss"
import { default as reactCSS, hover, loop, LoopableProps, HoverProps, CSS } from "reactcss"
interface TestProps extends HoverProps { }
interface TestHoverProps extends HoverProps<any> { }
var styles: any = reactCSS({
default: {},
hover: {}
}, { hover: true })
const TestHover: SFC<TestHoverProps> = ({hover}) => {
const styles = reactCSS<{title: CSS}>({
default: {
title: {
color: "black"
}
},
hover: {
title: {
color: "blue"
}
}
}, { hover })
var loopProps: LoopableProps = loop(1, 10)
const list = ["First!", "Second!", "Third!"]
var TestComponent: StatelessComponent<TestProps>
var Test = hover(TestComponent)
return (
<div>
<div style={ styles.title }>
Cool Title!
</div>
{list.map((item, index) => (
<TestLoop key={index} {...loop(index, list.length)}>{item}</TestLoop>
))}
</div>
)
}
interface TestLoopProps extends LoopableProps { }
const TestLoop: SFC<TestLoopProps> = (props) => {
const styles = reactCSS<{element: CSS}>({
default: {
element: {
width: "200px",
border: "1px solid black"
}
},
first: {
element: {
borderTopLeftRadius: "2px",
borderTopRightRadius: "2px"
}
},
last: {
element: {
borderBottomLeftRadius: "2px",
borderBottomRightRadius: "2px"
}
}
}, { first: props["first-child"], last: props["last-child"] })
return <div style={styles.element}>{props.children}</div>
}
const Test = hover(TestHover)
render(
<Test />,