Skip to content
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

Merged
merged 30 commits into from
Jul 2, 2018
Merged

feat(chips): Add new component #117

merged 30 commits into from
Jul 2, 2018

Conversation

bonniezhou
Copy link
Contributor

Add basic working component for Chips, including Chip and ChipSet. Does not include any variants.

@bonniezhou bonniezhou requested a review from moog16 June 25, 2018 23:36
Copy link

@moog16 moog16 left a 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

classList: new Set(),
chips: this.props.labels.map((label) => {
return {
label: label,
Copy link

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,
...
}

this.maxId = 0;
this.state = {
classList: new Set(),
chips: this.props.labels.map((label) => {
Copy link

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...

render() {
return (
<div className={this.classes}>
{this.state.chips.map(this.renderInputChip.bind(this))}
Copy link

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.

Copy link
Contributor Author

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.

}

get classes() {
const {classList} = this.state;
Copy link

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.


constructor(props) {
super(props);
this.state = {
Copy link

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)

@@ -0,0 +1,29 @@
{
"name": "@material/react-chips",
"version": "0.2.0",
Copy link

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.

"url": "https://github.com/material-components/material-components-web-react.git"
},
"dependencies": {
"@material/chips": "^0.35.0",
Copy link

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('renders chip set and chip', () => {
const wrapper = shallow(<ChipSet labels={['Hello']} />);
assert.isOk(wrapper.find('.mdc-chip-set'));
Copy link

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-io
Copy link

codecov-io commented Jun 27, 2018

Codecov Report

Merging #117 into master will decrease coverage by 1.28%.
The diff coverage is 75%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
packages/chips/chip/index.js 65% <65%> (ø)
packages/chips/chip-set/index.js 87.5% <87.5%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a53fc7d...15071f3. Read the comment docs.

Copy link

@moog16 moog16 left a 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",
Copy link

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

Copy link

@amsheehan amsheehan left a 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

## Installation

```
npm install @material/react-chips

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?

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.

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.

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 {

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.

super(props);
this.maxId = 0;
this.state = {
chips: props.labels.map((label) => {

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.


constructor(props) {
super(props);
this.maxId = 0;

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?

};

ChipSet.defaultProps = {
className: '',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary?

import {MDCChipFoundation} from '@material/chips';

export class Chip extends Component {

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?

children: PropTypes.string,
};

Chip.defaultProps = {

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",

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');

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.

Copy link
Contributor Author

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.

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.

http://jestjs.io/docs/en/es6-class-mocks#automatic-mock

Copy link
Contributor Author

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

render() {
return (
<div className={this.classes}>
{this.props.labels.map((label, index) => this.renderChip(label, index))}
Copy link

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)

Copy link

@moog16 moog16 left a 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.

@bonniezhou bonniezhou merged commit 410da30 into master Jul 2, 2018
@moog16 moog16 deleted the feat/chips-simple branch July 3, 2018 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants