-
Notifications
You must be signed in to change notification settings - Fork 227
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
feat(chips): Add new component #117
Conversation
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.
Can you add tests for adapter methods for both chip and chipset por favor
packages/chips/chip-set/index.js
Outdated
classList: new Set(), | ||
chips: this.props.labels.map((label) => { | ||
return { | ||
label: label, |
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.
change this to just
{
label,
...
}
packages/chips/chip-set/index.js
Outdated
this.maxId = 0; | ||
this.state = { | ||
classList: new Set(), | ||
chips: this.props.labels.map((label) => { |
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.
Since you're passed props
, just reference that:
chips: props.labels.map...
packages/chips/chip-set/index.js
Outdated
render() { | ||
return ( | ||
<div className={this.classes}> | ||
{this.state.chips.map(this.renderInputChip.bind(this))} |
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.
Do you need to bind this
. You don't use it in renderInputChip. I actually think render methods always have a reference to this
.
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.
Oops, copied this over from an experimental branch. Later when we add input chips this
will be used in the render method so we can bind it then.
packages/chips/chip-set/index.js
Outdated
} | ||
|
||
get classes() { | ||
const {classList} = this.state; |
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.
you actually don't need classList. You don't have an add/remove.
packages/chips/chip/index.js
Outdated
|
||
constructor(props) { | ||
super(props); | ||
this.state = { |
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.
move this as a class property (not in the constructor)
packages/chips/package.json
Outdated
@@ -0,0 +1,29 @@ | |||
{ | |||
"name": "@material/react-chips", | |||
"version": "0.2.0", |
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.
Since this is new I think lerna wants it to be 0.0.0. When we publish again it'll auto generate the version.
packages/chips/package.json
Outdated
"url": "https://github.com/material-components/material-components-web-react.git" | ||
}, | ||
"dependencies": { | ||
"@material/chips": "^0.35.0", |
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.
I need to update the docs when adding a new component (actually need a doc), but please add chips to the webpack config for building: https://github.com/material-components/material-components-web-react/blob/master/packages/webpack.config.js#L72
test/unit/chips/index.test.js
Outdated
|
||
test('renders chip set and chip', () => { | ||
const wrapper = shallow(<ChipSet labels={['Hello']} />); | ||
assert.isOk(wrapper.find('.mdc-chip-set')); |
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.
I think there is an assert.exists()
Codecov Report
@@ Coverage Diff @@
## master #117 +/- ##
==========================================
- Coverage 99.05% 97.77% -1.29%
==========================================
Files 18 20 +2
Lines 637 673 +36
Branches 53 53
==========================================
+ Hits 631 658 +27
- Misses 6 15 +9
Continue to review full report at Codecov.
|
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.
Please add some adapter method tests. Gotta keep up the coverage :)
@@ -45,6 +45,7 @@ | |||
"@google-cloud/storage": "^1.6.0", | |||
"@material/button": "^0.36.0", | |||
"@material/card": "^0.36.0", | |||
"@material/chips": "^0.36.0", |
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.
does chips have a version 0.36.0? It is 0.35.x in package-lock
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.
I had a few cycles and thought I'd take a crack at the ol' open source. This looks so sweet. :)
Just a few nit picky details that caught my eye. Super jeal of how famous y'all are now with Dan Abramov
packages/chips/README.md
Outdated
## Installation | ||
|
||
``` | ||
npm install @material/react-chips |
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.
Do we want to include --save
? For completeness?
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.
No, --save
has not existed for several major versions of npm.
packages/chips/README.md
Outdated
Prop Name | Type | Description | ||
--- | --- | --- | ||
className | String | Classes to be applied to the chip set element. | ||
labels | Array | Array of text to be displayed in each chip. |
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.
Language in the description is a little ambiguous. Maybe "An array of strings. Each string has a corresponding chip whose label will be set to the value of that string."
|
||
import Chip from '../chip'; | ||
|
||
export default class ChipSet extends Component { |
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.
In the README
's example, you use a different import style for Component
, e.g.:
import React from 'react';
class Foo extends React.Component {...}
Suggest changing the example in the README
to use this code style instead.
packages/chips/chip-set/index.js
Outdated
super(props); | ||
this.maxId = 0; | ||
this.state = { | ||
chips: props.labels.map((label) => { |
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.
It is an anti-pattern to set props
that will never change to state
. Consider using props directly in the render
method.
packages/chips/chip-set/index.js
Outdated
|
||
constructor(props) { | ||
super(props); | ||
this.maxId = 0; |
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.
What is this used for?
packages/chips/chip-set/index.js
Outdated
}; | ||
|
||
ChipSet.defaultProps = { | ||
className: '', |
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.
Is this necessary?
packages/chips/chip/index.js
Outdated
import {MDCChipFoundation} from '@material/chips'; | ||
|
||
export class Chip extends Component { | ||
|
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.
Did eslint complain about starting this with an empty line?
packages/chips/chip/index.js
Outdated
children: PropTypes.string, | ||
}; | ||
|
||
Chip.defaultProps = { |
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.
I'm not sure you'll need all of these. Possibly initRipple, because I don't know the internals of it.
"dependencies": { | ||
"@material/chips": "^0.36.0", | ||
"@material/react-ripple": "^0.2.0", | ||
"classnames": "^2.2.5", |
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.
Do we have a way of making sure that minor version changes to these will not cause problems for the components?
|
||
test('#adapter.addClass adds class to state.classList', () => { | ||
const wrapper = mount(<Chip>Jane Doe</Chip>); | ||
wrapper.instance().foundation_.adapter_.addClass('test-class-name'); |
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.
Should we be accessing private properties in a test? Is there a way to spy on addClass
? I'm seeing this pattern here, in the next test, and one of the ChipSet
tests.
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.
Changed the ChipSet
test to use its public adapter getter, but I'm not sure if there's a way to do the same for Chip
since it's an HOC wrapped in withRipple
.
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.
Are you using Jest to run the tests? If so, there are some handy automatic mocking functions you can use and pass arbitrary props down to Chip and check its className
property.
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.
We're not using Jest :( we're using Karma like in the MDC Web repo
packages/chips/chip-set/index.js
Outdated
render() { | ||
return ( | ||
<div className={this.classes}> | ||
{this.props.labels.map((label, index) => this.renderChip(label, index))} |
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.
this can reduce to: this.props.labels.map(this.renderChip)
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.
Looks good pending screenshot tests and single comment.
Add basic working component for Chips, including Chip and ChipSet. Does not include any variants.