Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              body {
  height: 100vh;
  padding: 2rem;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
  background-color: #eff2f7;
  font-size: 16px;
}

#app {
  max-width: 30rem;
  margin: 0 auto;
}

.accordion-item {
  margin-bottom: 1rem;
  border-radius: 4px;
  background-color: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.accordion-header {
  margin: 0;
  padding: 1rem;
  line-height: 0;
}

.accordion-header button {
  width: 100%;
  padding: 0;
  border: 0;
  outline: 0;
  background-color: transparent;
  font-size: 16px;
  text-align: left;
  cursor: pointer;
}

.accordion-panel {
  display: none;
}

.accordion-panel.expanded {
  display: block;
  padding: 1rem;
  border-top: 1px solid #eee;
}
            
          
!
            
              const Accordion = (props) => {
  return (
    <div className="accordion">{ props.children }</div>
  )
}

const AccordionItemContext = React.createContext({
  expanded: false,
  toggleExpansion: () => {}
});

class AccordionItem extends React.Component {
  constructor (props) {
    super(props)
    
    this.toggleExpansion = () => {
      this.setState({ expanded: !this.state.expanded })
    }
    
    this.state = {
      expanded: false,
      toggleExpansion: this.toggleExpansion
    }
  }
  render () {
    return (
      <AccordionItemContext.Provider value={this.state}>
        <div className="accordion-item">
          {this.props.children}
        </div>
      </AccordionItemContext.Provider>
    )
  }
}

const AccordionHeader = (props) => {
  return (
    <AccordionItemContext.Consumer>
      {({ expanded, toggleExpansion }) => (
        <h2 className="accordion-header">
          <button onClick={toggleExpansion}>
            { expanded ? '▼ ' : '► ' } 
            { props.children }
          </button>
        </h2>
      )}
    </AccordionItemContext.Consumer>
  )
}

const AccordionPanel = (props) => {
  return (
    <AccordionItemContext.Consumer>
      {({ expanded }) => <div className={"accordion-panel " + (expanded ? 'expanded' : '')}>{props.children}</div>}
    </AccordionItemContext.Consumer>
  )
}

class App extends React.Component {
  constructor(props) {
    super(props)
  }
  
  render() {
    return (
      <Accordion>
        <AccordionItem>
          <AccordionHeader>
            Section 1
          </AccordionHeader>
          <AccordionPanel>
            Mauris mauris ante, blandit et, ultrices a, suscipit eget, quam. Integer ut neque. Vivamus nisi metus, molestie vel, gravida in, condimentum sit amet, nunc. Nam a nibh. Donec suscipit eros. Nam mi. Proin viverra leo ut odio. Curabitur malesuada. Vestibulum a velit eu ante scelerisque vulputate.
          </AccordionPanel>
        </AccordionItem>
        <AccordionItem>
          <AccordionHeader>
            Section 2
          </AccordionHeader>
          <AccordionPanel>
            Sed non urna. Donec et ante. Phasellus eu ligula. Vestibulum sit amet purus. Vivamus hendrerit, dolor at aliquet laoreet, mauris turpis porttitor velit, faucibus interdum tellus libero ac justo. Vivamus non quam. In suscipit faucibus urna.
          </AccordionPanel>
        </AccordionItem>
        <AccordionItem>
          <AccordionHeader>
            Section 3
          </AccordionHeader>
          <AccordionPanel>
            Nam enim risus, molestie et, porta ac, aliquam ac, risus. Quisque lobortis. Phasellus pellentesque purus in massa. Aenean in pede. Phasellus ac libero ac tellus pellentesque semper. Sed ac felis. Sed commodo, magna quis lacinia ornare, quam ante aliquam nisi, eu iaculis leo purus venenatis dui.
            <ul>
              <li>List item one</li>
              <li>List item two</li>
              <li>List item three</li>
            </ul>
          </AccordionPanel>
        </AccordionItem>
      </Accordion>
    )
  }
}

ReactDOM.render(
  <App />,
  document.getElementById('app')
)
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console