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

Add support for chips #1119

Closed
jimbojetlag opened this issue Jul 10, 2015 · 11 comments · Fixed by #3870
Closed

Add support for chips #1119

jimbojetlag opened this issue Jul 10, 2015 · 11 comments · Fixed by #3870
Labels
component: chip This is the name of the generic UI component, not the React module!

Comments

@jimbojetlag
Copy link

https://www.google.com/design/spec/components/chips.html
https://material.angularjs.org/latest/#/demo/material.components.chips

@jimbojetlag
Copy link
Author

Can https://github.com/JedWatson/react-select be wrapped to implement chips, or is it too deviated from the material specs?

@kodermax
Copy link
Contributor

has anyone started doing?

@mbrookes
Copy link
Member

No, but PRs are always welcome! 😉

@izziaraffaele
Copy link
Contributor

👍 for this!!!!! And an integration with TextField/Autocomplete would be really appreciated I think

@ffxsam
Copy link
Contributor

ffxsam commented Feb 28, 2016

I think I'm gonna take a stab at chips. I'm building a SaaS that has a tagging system, and either way, I'm gonna spend the hours building a tag/chip system, so I might as well do it in a way that benefits the community!

@ffxsam
Copy link
Contributor

ffxsam commented Feb 28, 2016

Actually this might take a long time as it's probably more complex than I'm thinking. :) For instance, chips can go into an AutoComplete field, correct? Which means that AutoComplete would have to get an overhaul to handle chips. I suppose this warrants more of a discussion here. How do you see chips working in MUI?

@newoga
Copy link
Contributor

newoga commented Feb 28, 2016

@ffxsam Thanks for your interest in taking a stab here! I would design the chip component as simple as possible and not worry about necessary integrating it with other components like AutoComplete yet. We can handle that separately.

I think the <Chip /> component could possibly be a stateless component that just renders consistently given props. If you have an API in mind you can write a mini proposal / code examples from end user perspective (not implementation) here and we can take a look and discuss.

Thanks!

@nathanmarks
Copy link
Member

@newoga @ffxsam Let's make chips completely decoupled from AutoComplete.

The <Chip /> component is a good start, but we should also start considering the components it will need to integrate with as they may be up for a refactor soon. The <Chip /> probably won't take too long to implement as a basic, stateless controlled component. It's adding all the state helpers that takes ages 👍

The important thing is to make sure the basic <Chip /> supports the design in the spec and other common implementations in the simplest way possible.

@ffxsam
Copy link
Contributor

ffxsam commented Mar 15, 2016

I actually might wait until you guys change directions with how you style your components. Not to mention I also have zero time at the moment.. :)

@adrianmcli
Copy link

Hey guys! I've made a Chip component for my own projects and I wanted to share it here. It's pretty ugly/sloppy but maybe someone here can use this as a good starting point. I've included a hover state because I wanted to make the close button change colour on hover (just like the material design docs).

import React from 'react';

import Avatar from 'material-ui/lib/avatar';
import CloseIcon from 'material-ui/lib/svg-icons/navigation/cancel';

export default class Chip extends React.Component {

  constructor(props) {
    super(props);
    this.state = {
      hover: false
    };
  }

  renderRemoveButton() {
    const iconStyle = {
      height: '20px',
      width: '20px',
      margin: '4px -6px 4px 4px',
      transition: 'none',
      cursor: 'pointer',
    };
    const iconColorDefault = 'rgba(0,0,0,0.3)';
    const iconColorHover = 'white';
    const iconColor = this.state.hover ? iconColorHover : iconColorDefault;
    return (
      <CloseIcon
        style={iconStyle}
        color={iconColor}
        size={20}
        onClick={this._handleClick.bind(this)}
      />
    );
  }

  _handleClick() {
    this.props.onRemoveClick.bind(this)();
  }

  _handleOnMouseEnter() {
    this.setState({hover: true});
  }

  _handleOnMouseLeave() {
    this.setState({hover: false});
  }

  render() {
    const { avatarSrc, username, noCloseButton } = this.props;
    const chipStyle = {
      height: '32px',
      lineHeight: '32px',
      padding: '0 12px',
      fontSize: '13px',
      fontWeight: '500',
      backgroundColor: this.state.hover ? '#aaa' : '#efefef',
      borderRadius: '16px',
      display: 'inline-flex',
      alignItems: 'center',
      cursor: 'default',
    };
    const avatarStyle = {
      margin: '0 8px 0 -12px',
      height: '32px',
      width: '32px',
      borderRadius: '50%',
    };

    const textStyle = {
      fontSize: '13px',
      fontWeight: '400',
      lineHeight: '16px',
      color: this.state.hover ? 'white' : 'rgba(0,0,0,0.87)',
    };
    return (
      <div
        style={chipStyle}
        onMouseEnter={this._handleOnMouseEnter.bind(this)}
        onMouseLeave={this._handleOnMouseLeave.bind(this)}
      >

        <Avatar
          src={avatarSrc}
          size={32}
          style={avatarStyle}
        />

        <span style={textStyle}>
          {username}
        </span>

        { noCloseButton ? null : this.renderRemoveButton() }

      </div>
    );
  }
}

Chip.defaultProps = {
  onRemoveClick: () => {alert(`remove ${this.props.username}`);},
  username: 'UserName',
  noCloseButton: false,
};

Here's a link to the Gist: https://gist.github.com/adrianmc/501f2fa087e96fdd816d

@ffxsam
Copy link
Contributor

ffxsam commented May 13, 2016

@mbrookes @oliviertassinari Awesome, nice work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: chip This is the name of the generic UI component, not the React module!
Projects
None yet
Development

Successfully merging a pull request may close this issue.