Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <div id="app"></div>
              
            
!

CSS

              
                @import url('https://fonts.googleapis.com/css?family=Lato');

body {
  background: #38394D;
}

.container {
  width: 600px;
  height: 400px;
  position: relative;
  margin: auto;
  display: block;
  background: none;
  margin-top: 6%;
}

.tile-1, .tile-2, .tile-3 {
  cursor: pointer;
}

.tile-1 {
  position: absolute;
  height: 30%;
  top: 35%;
  left: 5%;
  width: 25%;
}

.tile-2 {
  position: absolute;
  height: 30%;
  top: 35%;
  left: 37.5%;
  width: 25%;
}

.tile-3 {
  position: absolute;
  height: 30%;
  top: 35%;
  right: 5%;
  width: 25%;
}

.color-text-box{
  position: absolute;
  height: 30%;
  width: 100%;
  bottom: -30%;
  background: #f9f9f9;
}

.color-text {
  position: absolute;
  top: 15%;
  color: #333333;
  font-family: "Lato";
  font-size: 20px;
  left: 5%;
  -webkit-user-select: none; /* Chrome/Safari */        
  -moz-user-select: none; /* Firefox */
  -ms-user-select: none; /* IE10+ */
}
              
            
!

JS

              
                const config = {
    apiKey: "AIzaSyBmaoA1nVF3xqZ-_gtINZR86ub_hEN-_5s",
    authDomain: "react-test-1b3de.firebaseapp.com",
    databaseURL: "https://react-test-1b3de.firebaseio.com",
    projectId: "react-test-1b3de",
    storageBucket: "react-test-1b3de.appspot.com",
    messagingSenderId: "568077550139"
  };
  firebase.initializeApp(config);

const database = firebase.database();
const colors = database.ref('colors');

//App
class App extends React.Component {
  
  render() {
    return (
      <div className="container">
        <Tile class={"tile-1"}/>
        <Tile class={"tile-2"}/>
        <Tile class={"tile-3"}/>
      </div>
    )
  }
}

//components (not using village design)
class Tile extends React.Component {
  
  state = {color: "#FFFFFF"};

  updateTile() {
    //get random number between 1 and 3
    const random = Math.floor((Math.random() * 3) + 1);
    
    //empty variable for selectedColor
    let selectedColor;
    
    //retrieve color depending on random number
    let promise = new Promise((resolve, reject) => {
      colors.on('value', function(snapshot) {
        if(random === 1) {
          selectedColor = snapshot.val().mint;
        } else if (random === 2) {
          selectedColor = snapshot.val().pink;
        } else {
          selectedColor = snapshot.val().purple;
        }
        resolve(selectedColor);
      }); 
    });
    
    //setState of color property to selected color
    promise.then((resolvedColor) => {
      this.setState({color: resolvedColor});
    });
  }

  render() {
    return (
      <div onClick={this.updateTile.bind(this)} style={{background: this.state.color}} className={this.props.class}>
        <div className="color-text-box">
          <div className="color-text">
            {this.state.color}
          </div>
        </div>
      </div>
    )
  }
}

//"inject" to DOM
ReactDOM.render(
  <App/>,
  document.getElementById('app')
);
              
            
!
999px

Console