-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Table update #44
Table update #44
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
import React, {Component, PropTypes} from 'react'; | ||
import SEMANTIC_TYPES from 'docs/app/utils/SemanticTypes'; | ||
import STARDUST_TYPES from 'docs/app/utils/StardustTypes'; | ||
import {Segment} from 'stardust'; | ||
|
||
class ComponentDescription extends Component { | ||
export default class ComponentDescription extends Component { | ||
static propTypes = { | ||
/** | ||
* String describing the Stardust component. | ||
|
@@ -48,7 +49,7 @@ class ComponentDescription extends Component { | |
</a> | ||
); | ||
return ( | ||
<div> | ||
<Segment className='basic vertical'> | ||
<div className='ui large header'> | ||
{_.capitalize(this.props.name)} | ||
<code className='sub header' style={{float: 'right'}}> | ||
|
@@ -59,9 +60,7 @@ class ComponentDescription extends Component { | |
</code> | ||
</div> | ||
{this.isSemanticComponent && semanticDocsLink} | ||
</div> | ||
</Segment> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The |
||
); | ||
} | ||
} | ||
|
||
export default ComponentDescription; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ export default class ComponentList extends Component { | |
.map(name => { | ||
let doc = new ComponentDoc(name); | ||
return ( | ||
<Segment key={doc.name} id={doc.name} className='vertical'> | ||
<Segment key={doc.name} id={doc.name}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
<ComponentDescription | ||
path={doc.path} | ||
name={doc.name} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import _ from 'lodash'; | ||
import React, {Component, PropTypes} from 'react'; | ||
import {Segment} from 'stardust'; | ||
import {Segment, Table, TableColumn} from 'stardust'; | ||
|
||
/** | ||
* Displays a table of a Component's PropTypes. | ||
|
@@ -14,13 +14,27 @@ export default class ComponentProps extends Component { | |
props: PropTypes.object | ||
}; | ||
|
||
nameRenderer(item) { | ||
let required = item.required && <span className='ui mini red circular label'>required</span>; | ||
return <div>{item.name} {required}</div>; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The name column also includes a |
||
|
||
defaultValueRenderer(item) { | ||
let defaultValue = _.get(item, 'defaultValue.value'); | ||
let defaultIsComputed = <span className='ui mini gray circular label'>computed</span>; | ||
|
||
return ( | ||
<div> | ||
{defaultValue} {_.get(item, 'defaultValue.computed') && defaultIsComputed} | ||
</div> | ||
); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Default Value column includes a |
||
|
||
render() { | ||
var propsDefinition = this.props.props; | ||
var content = _.map(propsDefinition, (propConfig, propName) => { | ||
let name = propName; | ||
let defaultValue; | ||
let defaultIsComputed; | ||
let description = propConfig.docBlock; | ||
let description = _.get(propConfig, 'docBlock.description'); | ||
|
||
let type = _.get(propConfig, 'type.name'); | ||
let value = _.get(propConfig, 'type.value'); | ||
|
@@ -29,42 +43,28 @@ export default class ComponentProps extends Component { | |
} | ||
type = type && `{${type}}`; | ||
|
||
let required = propConfig.required && ( | ||
<span className='ui mini red circular label'>required</span> | ||
); | ||
|
||
// default value | ||
if (propConfig.defaultValue) { | ||
defaultValue = ( | ||
<span>{propConfig.defaultValue.value}</span> | ||
); | ||
defaultIsComputed = propConfig.defaultValue.computed && ( | ||
<span className='ui mini gray circular label'>computed</span> | ||
); | ||
} | ||
let required = propConfig.required; | ||
let defaultValue = propConfig.defaultValue; | ||
|
||
return ( | ||
<div key={propName}> | ||
<div style={{display: 'flex'}}> | ||
<div style={{flex: '4'}}>{name} {required}</div> | ||
<div style={{flex: '2'}}>{type}</div> | ||
<div style={{flex: '4'}}>{defaultValue} {defaultIsComputed}</div> | ||
<div style={{flex: '8'}}>{description}</div> | ||
</div> | ||
</div> | ||
); | ||
return { | ||
name, | ||
type, | ||
value, | ||
required, | ||
defaultValue, | ||
description, | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We now return an array of objects describing each property. The table will use this array of PropType objects creating a row for every object. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. +1 |
||
}); | ||
|
||
return ( | ||
<Segment className='basic vertical'> | ||
<Segment className='vertical'> | ||
<div className='ui header'>Props</div> | ||
<div style={{display: 'flex'}}> | ||
<b style={{flex: '4'}}>name</b> | ||
<b style={{flex: '2'}}>type</b> | ||
<b style={{flex: '4'}}>default</b> | ||
<b style={{flex: '8'}}>description</b> | ||
</div> | ||
{content} | ||
<Table data={content} className='very basic'> | ||
<TableColumn dataKey='name' cellRenderer={this.nameRenderer} /> | ||
<TableColumn dataKey='type' /> | ||
<TableColumn dataKey='defaultValue' cellRenderer={this.defaultValueRenderer} /> | ||
<TableColumn dataKey='description' /> | ||
</Table> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here is the new PropTypes table, each column uses some key from each object in the array of PropTypes. Columns with renderer functions (defined above) are combining multiple properties (like |
||
</Segment> | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ import TableHeader from './TableHeader'; | |
import TableRow from './TableRow'; | ||
import TableCell from './TableCell'; | ||
|
||
class Table extends Component { | ||
export default class Table extends Component { | ||
static propTypes = { | ||
basic: PropTypes.bool, | ||
children: function(props, propName, componentName) { | ||
|
@@ -20,8 +20,8 @@ class Table extends Component { | |
return new Error('`Table` must only have `TableColumn` children.'); | ||
} | ||
}, | ||
className: PropTypes.string, | ||
data: PropTypes.array.isRequired, | ||
striped: PropTypes.bool, | ||
}; | ||
|
||
static getSafeCellContents(content) { | ||
|
@@ -65,16 +65,11 @@ class Table extends Component { | |
let classes = classNames( | ||
'sd-table', | ||
'ui', | ||
{'very basic': this.props.basic}, | ||
'selectable', | ||
'fixed', | ||
'compact', | ||
'small', | ||
{striped: this.props.striped}, | ||
this.props.className, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Table now inherits classes. |
||
'table', | ||
); | ||
return ( | ||
<table className={classes}> | ||
<table {...this.props} className={classes}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Table also now spreads props. |
||
<thead> | ||
<tr> | ||
{this._getHeaders()} | ||
|
@@ -87,5 +82,3 @@ class Table extends Component { | |
); | ||
} | ||
} | ||
|
||
export default Table; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updating old export syntax to our new standard.