React-Toolbox 为 table 撰写故事
React-Toolbox write story for table
我正在为 React Table 写一个故事,我遇到了以下错误:
React-toolbox 文档未更新。我认为。因为我在 the source code
中找不到 model
和 source
属性
有我的组件源
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import {Table as RTTable} from 'react-toolbox/lib/table'
const Table = ({
...props
})=>
<RTTable {...props}></RTTable>
Table.propTypes = {
source: PropTypes.array,
model: PropTypes.object,
}
export default styled(Table)`
border: 1px solid;
`
我的故事来源:
import React from 'react'
import {storiesOf} from '@storybook/react'
import Table from 'Table'
const UserModel = {
name: {
type: String,
},
twitter: {
type: String,
},
birthdate: {
type: Date,
title: 'Date of Birth',
},
cats: {
type: Number,
},
dogs: {
type: Number,
},
active: {
type: Boolean,
},
}
const users = [
{
name: 'Javi Jimenez',
twitter: '@soyjavi',
birthdate: new Date(1980, 3, 11),
cats: 1,
}, {
name: 'Javi Velasco',
twitter: '@javivelasco',
birthdate: new Date(1987, 1, 1),
dogs: 1,
active: true,
},
]
storiesOf('Table', module).add('with source', ()=> <Table model={UserModel} source={users} />)
谁能帮帮我?非常感谢。
我更新了组件代码:
import React from 'react'
import PropTypes from 'prop-types'
import {Table as RTTable, TableHead, TableCell} from 'react-toolbox/lib/table'
const Table = props=> {
const headerKeys = Object.keys(props.model)
return (
<RTTable>
<TableHead>
{
headerKeys.map((headerKey, index)=> <TableCell key={index}>{headerKey}</TableCell>)
}
</TableHead>
</RTTable>
)
}
Table.propTypes = {
model: PropTypes.object,
}
export default Table
对于故事书:
import React from 'react'
import {storiesOf} from '@storybook/react'
import Table from 'Table'
const UserModel = {
name: {
type: String,
},
age: {
type: Number,
},
}
storiesOf('Table', module).add('Init table', ()=> <Table model={UserModel}/>)
然后就可以了。
我正在为 React Table 写一个故事,我遇到了以下错误:
React-toolbox 文档未更新。我认为。因为我在 the source code
中找不到model
和 source
属性
有我的组件源
import React from 'react'
import PropTypes from 'prop-types'
import styled from 'styled-components'
import {Table as RTTable} from 'react-toolbox/lib/table'
const Table = ({
...props
})=>
<RTTable {...props}></RTTable>
Table.propTypes = {
source: PropTypes.array,
model: PropTypes.object,
}
export default styled(Table)`
border: 1px solid;
`
我的故事来源:
import React from 'react'
import {storiesOf} from '@storybook/react'
import Table from 'Table'
const UserModel = {
name: {
type: String,
},
twitter: {
type: String,
},
birthdate: {
type: Date,
title: 'Date of Birth',
},
cats: {
type: Number,
},
dogs: {
type: Number,
},
active: {
type: Boolean,
},
}
const users = [
{
name: 'Javi Jimenez',
twitter: '@soyjavi',
birthdate: new Date(1980, 3, 11),
cats: 1,
}, {
name: 'Javi Velasco',
twitter: '@javivelasco',
birthdate: new Date(1987, 1, 1),
dogs: 1,
active: true,
},
]
storiesOf('Table', module).add('with source', ()=> <Table model={UserModel} source={users} />)
谁能帮帮我?非常感谢。
我更新了组件代码:
import React from 'react'
import PropTypes from 'prop-types'
import {Table as RTTable, TableHead, TableCell} from 'react-toolbox/lib/table'
const Table = props=> {
const headerKeys = Object.keys(props.model)
return (
<RTTable>
<TableHead>
{
headerKeys.map((headerKey, index)=> <TableCell key={index}>{headerKey}</TableCell>)
}
</TableHead>
</RTTable>
)
}
Table.propTypes = {
model: PropTypes.object,
}
export default Table
对于故事书:
import React from 'react'
import {storiesOf} from '@storybook/react'
import Table from 'Table'
const UserModel = {
name: {
type: String,
},
age: {
type: Number,
},
}
storiesOf('Table', module).add('Init table', ()=> <Table model={UserModel}/>)
然后就可以了。