-
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
Feature/add sd item #65
Changes from 7 commits
f738da2
97c7210
51e859c
d6a5dfc
41b6509
6eb37fa
e4e05a6
ab61e3c
845b51d
b4d68b3
551270a
2916c00
0798ddc
394ee41
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import _ from 'lodash'; | ||
|
||
let customPropTypes = { | ||
mutuallyExclusive: (exclusives, props, propName, componentName) => { | ||
_.forEach(exclusives, exclusiveProp => { | ||
if (props[propName] && props[exclusiveProp]) { | ||
throw new Error(`\`${componentName}\` should only have one of type \`${propName}\` or \`${exclusiveProp}\`, ` + | ||
`not both.`); | ||
} | ||
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. In order to compare the specific propType to the exclusive props passed in, I had to take advantage React's custom validation function found in this article - so we have to bind the This way, we have the current prop to compare the |
||
|
||
return null; | ||
}); | ||
}, | ||
}; | ||
|
||
export default customPropTypes; | ||
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. new utility to be used with customPropType validation and checking. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React, {Component, PropTypes} from 'react'; | ||
import classNames from 'classnames'; | ||
import customPropTypes from '../../utils/customPropTypes'; | ||
|
||
export default class Item extends Component { | ||
static propTypes = { | ||
children: PropTypes.node, | ||
className: PropTypes.string, | ||
description: customPropTypes.mutuallyExclusive.bind(null, ['children']), | ||
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. Binding the exclusive props to the mutuallyExclusive utility function here. |
||
extra: PropTypes.node, | ||
heading: PropTypes.node.isRequired, | ||
image: PropTypes.node, | ||
meta: PropTypes.node, | ||
}; | ||
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. Pass in all "pieces" of the component as props to make sure that all content matches semantic's markup. |
||
|
||
render() { | ||
let heading = <div className='header'>{this.props.heading}</div>; | ||
let meta = <div className='meta'>{this.props.meta}</div>; | ||
let description = <div className='description'>{this.props.children || this.props.description}</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. By default, will render children before the default property if they both exist on the component. |
||
let extra = <div className='extra'>{this.props.extra}</div>; | ||
let content = ( | ||
<div className='middle aligned content'> | ||
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. Stardust should not add default style classes that are not configurable. Perhaps exposing a EDIT fixed sd-* class name typo. |
||
{this.props.heading && heading} | ||
{this.props.meta && meta} | ||
{this.props.children && description || this.props.description && description} | ||
{this.props.extra && extra} | ||
</div> | ||
); | ||
let hasContent = !!this.props.heading || !!this.props.meta || !!this.props.extra || !!this.props.children | ||
|| !!this.props.description; | ||
|
||
let classes = classNames( | ||
'sd-item', | ||
this.props.className, | ||
'item', | ||
); | ||
return ( | ||
<div {...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. Component props used for Stardust purposes should be removed from
We should remove those props before spreading them onto the let props = _.clone(this.props);
delete props.children;
delete props.className;
delete props.description;
delete props.extra;
delete props.heading;
delete props.image;
delete props.meta;
// then
<div {...props} ... Thinking about this, I believe we should always remove For now, add the clone/delete step before spreading. |
||
{this.props.image} | ||
{hasContent && content} | ||
</div> | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React, {Component, PropTypes} from 'react'; | ||
import classNames from 'classnames'; | ||
|
||
export default class Items extends Component { | ||
static propTypes = { | ||
children: PropTypes.node, | ||
className: PropTypes.string, | ||
}; | ||
|
||
render() { | ||
let classes = classNames( | ||
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. Parent items div if more than one item needs to exist. |
||
'sd-items', | ||
'ui', | ||
this.props.className, | ||
'items', | ||
); | ||
return ( | ||
<div {...this.props} className={classes}> | ||
{this.props.children} | ||
</div> | ||
); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import React from 'react'; | ||
import {Item} from 'stardust'; | ||
import faker from 'faker'; | ||
|
||
describe('Item', () => { | ||
it('has children', () => { | ||
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. Small semantic request here. This test isn't testing that |
||
let child = faker.hacker.phrase(); | ||
render(<Item description='foo'>{child}</Item>).findText(child); | ||
}); | ||
}); |
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.
Had to
throw
error as opposed toreturn
because the new Error needed to attach itself to the prop, not the utility propertymutuallyExclusive