#Writing Cards
import React from 'react'
import cards from 'reactcards'
import {Foo, Bar} from './components'
const demo = cards('demo')
demo.card(
`## markdown doc
you can use markdown for card documentation
- foo
- bar`,
<Foo message="hello"/>
)
demo.card(<Foo message="hello world"/>)
demo.card(<Bar/>, {title: 'a bar card'})
import React from 'react'
import cards from 'reactcards'
import {StatefulCounter} from './components'
const demo = cards('demo')
demo.card(
`## Counter
This is a stateful counter. If you change the value prop
in the source file it will not update because the new prop will be ignored
and instead the component local state is rendered.
Implement *componentWillReceiveProps* and override the component local state
if you want this to work as expected.`,
<StatefulCounter value={42}/>
)
import React from 'react'
import cards from 'reactcards'
import {StatelessCounter} from './components'
const demo = cards('demo')
demo.card(
`## Undo/Redo
Same example as before but with undo/redo controls added by the card.`,
(state) =>
<StatelessCounter
value={state.get()}
inc={() => state.update(x => x + 1)}
dec={() => state.update(x => x - 1)}/>,
{
init: 1337,
history:true,
}
)
// your test file...
import {assert} from 'chai'
export function testAdd() {
assert.equal(1 + 1, 2)
}
export function testFail() {
assert.isTrue(false)
}
// your reactcards file
import React from 'react'
import cards from 'reactcards'
import someTests from './testFile'
const demo = cards('demo')
demo.test(someTests, {title:'simple tests'})
You can write tests in a separate folder or write them directly inside a card. The first enables us to reuse the test in a different setting. More information regarding testing very soon.