cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              .shape-enter {
  transform: scale(0);
}

.shape-enter.shape-enter-active {
  transform: scale(1);
  transition: all .5s ease-in;
}

.shape-leave {
  transform: scale(1);
}

.shape-leave.shape-leave-active {
  transform: scale(0);
  transition: all .5s ease-in;
}

.shape-menu {
  display: block;
  width: 100%;
  margin:  30px 0;
}
.fa {
  width: 50px;
  margin: 0 20px;
  font-size: 2em;
}
            
          
!
            
              let ReactCSSTransitionGroup = React.addons.CSSTransitionGroup

class ShapeContainer extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      lazyKey: 0,
      elements: []
    };
    this.addTriangle = this.addTriangle.bind(this);
    this.addCircle = this.addCircle.bind(this);
    this.deleteShape = this.deleteShape.bind(this);
  }

  addTriangle() {
    const key = this.state.lazyKey;
    this.setState({lazyKey: this.state.lazyKey + 1});
    this.setState({ elements: [...this.state.elements, <Triangle key={key} id={key} handleDelete={this.deleteShape}/>]});
  }
  
  addCircle() {
    const key = this.state.lazyKey;
    this.setState({lazyKey: this.state.lazyKey + 1});
    this.setState({ elements: [...this.state.elements, <Circle key={key} id={key} handleDelete={this.deleteShape}/>]});
  }
  
  deleteShape(item) {
    const elements = this.state.elements.filter((element) => {
      return element.key != item;
    });
    this.setState({elements: elements})
  }
  
  render() {
    const elements = this.state.elements
    return ( 
      <div id = "shapes">
        <div className="shape-menu">
          <h1> Click icon to add shape. Click shape to remove.</h1>
          <i className = "fa fa-exclamation-triangle" onClick = { this.addTriangle }/> 
          <i className = "fa fa-circle" onClick = { this.addCircle }/> 
        </div>
        <ReactCSSTransitionGroup
          transitionName = "shape"
          transitionEnterTimeout={500}
          transitionLeaveTimeout={500}
         >
          {elements}
        </ReactCSSTransitionGroup>
      </div>
    )
  }
}

const Circle = ({id, handleDelete})  => (
<svg onClick={()=>handleDelete(id)} width="100px" height="100px" viewBox="124 128 100 100">
    <circle id="Oval" stroke="none" fill="#D8D8D8" fill-rule="evenodd" cx="174" cy="178" r="50"></circle>
</svg>
)

const Triangle = ({id, handleDelete}) => (
<svg onClick={()=>handleDelete(id)} width="100px" height="100px" viewBox="115 248 100 100">
    <polygon id="Triangle" stroke="none" fill="#f8e81c" fill-rule="evenodd" points="165 248 215 348 115 348"></polygon>
</svg>
)

ReactDOM.render(
  <ShapeContainer />,
    document.getElementById('menuContainer')
);
            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console