Pen Settings

HTML

CSS

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

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

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.

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

              
                        <meta name=viewport content="width=device-width, initial-scale=1">
        <div id="container">
        </div>
       
              
            
!

CSS

              
                /*----- structure-----------  */
*{
    box-sizing:border-box;
    font-size:16px;
}
html,container{
    font-size:16px;
    background-color:#87B094;
    width:100%;
}
body{
    margin:0 auto;
    width:80%;
    max-width: 900px;
    text-align:center;
    background-color:white;
}

.topbar{
    background-color:#456DA9;
    padding:10px;
    color:white;
}
.btn{
  border:1px solid green;
  margin-right:20px;
  padding:2px;
  min-width:40px;
  min-height:40px;
  font-size: 1rem;
  
}
.btn.on{
  background-color:red;
  color:white;
}
.banner{
    padding-top:2px;
    margin:0 auto;
    width:100%;
    display:flex;
    align-items:center;
    flex-direction:column;
    background-color:white;
}

.banner-img{


    height:300px;
    overflow: hidden;
    width:100%;
}
.fixed{
    position:fixed;
    z-index:999;
    top:-10px;
    width:80%;
    max-width:900px;
}

.hidden{
    visibility: hidden;
}
.top-margin{
    margin-top:430px;
}

.channelList {
    color:#16780D;
}
.channelList .nodes{
    display:flex;
    flex-wrap:wrap;
    justify-content:center;

}
img{
    max-width:90%;

}
h1,h2{
    font-weight:normal;
    margin:0;
    font-size:40px;

}

.tooltip {
    position: relative;
    display: inline-block;

}

/* Tooltip text */
.tooltip .tooltiptext {
    visibility: hidden;
    width:100%;
    background-color: black;
    color: #fff;
    text-align: center;
    padding: 5px 0;
    border-radius: 6px;

    /* Position the tooltip text - see examples below! */
    position: absolute;
    top:70%;
    margin-left:-10px;
    z-index: 1;
}

/* Show the tooltip text when you mouse over the tooltip container */
.tooltip:hover .tooltiptext {
    visibility: visible;
}


/* Individual Channel items */
.channel{


    border: 1px solid black;
    float:left;
    margin:3px ;
    min-width:220px;
    padding:10px;
    width:20% ;
}
.logo{
    border-radius:50%;
    height:60px;
    width:60px;

}
.header{

    align-items:center;
    display:flex;
    margin:10px;
}

.header> h3{
    display:inline;
    font-size:18px;
    font-weight:normal;
}


/* Active twitch streams */
.active{
    background-color:#09031D;
}

.active > .header{
    background-color:#09031D;
    color:white;

}

.active:hover ,.active:hover .header {
    background-color:#1C1E56;
}

/* offline streams */

.offline{

    background-color:#570C0C;
}

.offline > .header{
    background-color:#570C0C;
    color:white;

}

.offline:hover ,.offline:hover .header {
    background-color:#8B1A1A;
}


@media (max-width:519px){
  body{
    width:100vw;
    font-size:18px;
  }
  
  .banner{
    display:none;
  }
  .top-margin{
    margin-top:0;
  }
  .hidden{
    visibility:visible;
  }
  .topbar{
    position:fixed;
    top:0px;
    width:100%;
    z-index:1;
  }
  .channelList{
    margin-top:60px;
  }
  img{
        max-width:100%;
        width:100%;
        height:100px;

    }
    .channel{
        width:100%;

    }

}
@media (min-width:520px) and (max-width:768px){
  .top-margin{
    margin-top:0;
  }
  .hidden{
    visibility:visible;
  }
  .fixed{
    position:relative;
    width:100%;
  }
   body{
    width:100vw;
  }
    .channel{
        width:42%;
        min-width:200px;

    }

}
@media screen(min-width:970px){
  body{
    width:60%;
  }
  
  fixed{
    width:60%;
  }
  
}

              
            
!

JS

              
                
class Layout extends React.Component {

    constructor() {
        super();
        this.state = {mode:"All",
            channels: ["iTzYoHero","WackyMackie","stingsempai","gouki2304","onex64","TSM_WildTurtle","swaglul","TSM_Bjergsen","Meteos","yoonie","Trick2g","ImaBlondeGoat","Quendal43","mattzillla","Melorian","gurlsrbadatvidyagaems","Wingsofdeath","Scarra","PhreakStream","HarukaShinigami4","Deathlylove","amberplays","presidentjacky","DarkFaith93","riotgames","TSM_TheOddOne","flosd","TSM_Xpecial","riotgamesbrazil","RAIDERRRLoL","Chrono_Frost","Sojirox","TSM_Dyrus","secretagentthai","wheresswaldo","Bacon_Donut","Soaryn","dotastarladder_en","TwitchPlaysPokemon","SHYLIZZLE","tx9_vanilla","djinn4583","die4frags","cyb3r_tech","DeAxiom","Too_malicious","MegaCarlos50","SynergyDrink","Entosian","HibubTv","Crs_saintvicious","HaiL9","arenix320","Nightblue3","Bischulol","BrandoPB","Trollbaltz","zzang18nom","hir0shisan","Skunkodor","screamingpikachu","GarenaEsports","GarenaTW","wraithxzz","SuNolol","RiotGamesLatino","ICanFindDiamond","naxious_magnus","xenadiscord","cathiesousa","Tharnambular","wuppo1","mkay299","WordlessHope","Killboy520","support_heroftw","enlightenwolf","TolkinNA","Winteruo","TheOddLeeSin","Synren","robjeah","2DaMaxx","WearyStreams","ido1994","Dirtsensei","brunofin","comster404","wizardworldcreative","starcitizen","lirik","OgamingSC2", "ESL_SC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas", "fuzzyness", "stray228", "imaqtpie", "jacksofamerica"],
            channelData: [],
            displayData:[],
            header:true
        };


    }


    componentDidMount() {
        this.fetchData();
        this.updateBanner();
        window.addEventListener("scroll", this.onScroll.bind(this));
        this.scrollBreak = document.getElementsByClassName("banner")[0].getBoundingClientRect().top;
    }

    updateBanner(props){
        props = props||{title:"Check channel status",status:"Check Twitch gaming streams !" ,preview:"http://i2.wp.com/pmcvariety.files.wordpress.com/2013/08/twitch-to-livestream-the-e3-event.jpg?crop=0px%2C2px%2C600px%2C334px&resize=670%2C377&ssl=1"};
        console.log("updating banner");
        this.setState({banner:props});
    }

    displayChannels(mode){
        mode  = mode|| this.state.mode;
        var data = this.state.channelData;
        if(mode=="All"){
            this.setState({mode:mode,displayData:data});
        }if(mode=="Active"){
            var active = data.filter((channel)=>{
                if(channel.status){
                  return channel.status!=="Offline" 
                }
            });
            this.setState({mode:mode,displayData:active});
        }if(mode=="Offline"){
            var offline = data.filter((channel)=>{
                if(channel.status){
                  return channel.status==="Offline" 
                }
            });
            this.setState({mode:mode,displayData:offline});
        }

    }


    onScroll(event){
        var doc = document.documentElement;
        var top = (window.pageYOffset || doc.scrollTop)  - (doc.clientTop || 0);
        var scrollBreak = this.scrollBreak;
        if(top>scrollBreak){
            if(this.state.header!==false){
                this.setState({header:false});
            }
        }if(top<scrollBreak){
            if(this.state.header!==true){
                this.setState({header:true});
            }
        }
        console.log(top);
    }

    fetchData() {
        var that = this;



        this.state.channels.forEach(function(channel,index) {

            $.ajax({
                url: "https://api.twitch.tv/kraken/streams/" + channel,
                type: "GET",
                cache: false,
                success: function(data) {
                    var channelInfo = {
                        username: channel,
                        key:index
                    };

                    channelInfo.game = data.stream ? data.stream.game : "";
                    channelInfo.url = "https://www.twitch.tv/" + channel;
                    channelInfo.status = data.stream ? data.stream.channel.status : "Offline";
                    if (channelInfo.status === "Offline") {
                        $.ajax({
                            url: data._links.channel,
                            type: "GET",
                            cache: false,

                            success: function(json) {
                                channelInfo.title = json.display_name||channel;
                                channelInfo.logo = json.logo||"https://dummyimage.com/50x50/ecf0e7/5c5457.jpg&text=0x3F";
                                channelInfo.preview = json.profile_banner||"http://i2.wp.com/pmcvariety.files.wordpress.com/2013/08/twitch-to-livestream-the-e3-event.jpg?crop=0px%2C2px%2C600px%2C334px&resize=670%2C377&ssl=1";
                                channelInfo.changeBanner = that.updateBanner.bind(that);
                                var dataobj = that.state.channelData.slice();
                                dataobj[index]=channelInfo;
                                that.setState({
                                    channelData: dataobj

                                });
                              that.displayChannels();
                            }

                        });
                    } else {
                        channelInfo.title = data.stream.channel.display_name;
                        channelInfo.preview = data.stream ? data.stream.preview.large : "";
                        channelInfo.logo = data.stream ? data.stream.channel.logo : "";
                        channelInfo.changeBanner = that.updateBanner.bind(that);
                        var dataobj = that.state.channelData.slice();
                        dataobj.push(channelInfo);
                        that.setState({
                            channelData: dataobj,
                           
                        });
                        that.displayChannels();
                    }





                },
                error: function(data){

                    var channelInfo = {
                        username: channel,
                        key:index
                    };
                    channelInfo.title = channel;
                    channelInfo.game = data.stream ? data.stream.game : "";
                    channelInfo.url = "https://www.twitch.tv/" + channel;
                    channelInfo.status = "Offline";
                    channelInfo.logo ="https://dummyimage.com/50x50/ecf0e7/5c5457.jpg&text=0x3F";
                    channelInfo.preview = "http://i2.wp.com/pmcvariety.files.wordpress.com/2013/08/twitch-to-livestream-the-e3-event.jpg?crop=0px%2C2px%2C600px%2C334px&resize=670%2C377&ssl=1";
                    channelInfo.changeBanner = that.updateBanner.bind(that);
                    var dataobj = that.state.channelData.slice();
                    dataobj[index]=channelInfo;
                    that.setState({
                        channelData: dataobj,
                       

                    });
                    that.displayChannels();


                }
            });

        });


    }

    render() {
        
        return (

            <div >

                <Header visible={this.state.header} changeMode={this.displayChannels.bind(this)}/>
                <Banner {...this.state.banner} fixed={!this.state.header}/>
                <ChannelList margin={!this.state.header} channels={this.state.channels} channelData={this.state.displayData}/>
            </div>
        );
    }
}


class ChannelList extends React.Component {



    render() {
        var classname = this.props.margin?"top-margin":"" ;
        classname +=" channelList";

        if (this.props.channelData) {
            var sorted = this.props.channelData.sort((a,b)=>{
                if(a.status){
                var one = a.status=="Offline"?1:2;
                var two  = b.status=="Offline"?1:2;
                return two>one ;
            }

            });
            var channelNodes = sorted.map((props) => {
                return React.createElement(Channel,props);
            });
            return (<div className={classname}>
                <h2>Channel List</h2>
                <div className="nodes">
                    {channelNodes}

                </div>
            </div>);
        } else {
            console.log("Awaiting ajax");
            return (<div>Awaiting AJAX response</div>);
        }

    }
}

class Channel extends React.Component {

    openChannel(){

        window.open(this.props.url,"_blank");

    }
    updateBanner(){
        var obj = {};
        obj.logo = this.props.logo;
        obj.status = this.props.status;
        obj.preview = this.props.preview;
        obj.url = this.props.url;
        obj.title = this.props.title;
        this.props.changeBanner(obj);
    }

    render() {
        var isActive = this.props.status !== "Offline";
        var className = isActive ? "active" : "offline";
        className = "channel tooltip " + className;
        return (


            <div className={className} onClick={this.openChannel.bind(this)} onMouseEnter={this.updateBanner.bind(this)} >

                <div className="tooltiptext">
                    {this.props.status}
                </div>
                <div className="header">
                    <img className="logo" src={this.props.logo} alt=""/>
                    <h3> {this.props.title}</h3>
                </div>


            </div>

        );
    }




}
class Banner extends React.Component{


    render(){
        var classname = this.props.fixed?"fixed":"" ;
        classname +=" banner";

        return(<div className={classname} >

            <div className="header">
                <img className="logo" src={this.props.logo} alt=""/>
                <h3> {this.props.title}</h3>
            </div>
            <img className="banner-img" src={this.props.preview}/>
            <p> {this.props.status} </p>
        </div>
        );



    }




}
class Header extends React.Component {
   constructor(){
     super();
     this.state = {btn_all:"btn on",btn_active:"btn",btn_offline:"btn"};
   }
    toggleMode(e){
      var mode = e.target.innerHTML;
      mode = mode.trim();
      if(mode=="All"){
        this.setState({btn_all:"btn on",btn_active:"btn",btn_offline:"btn"});
      }else if(mode=="Active"){
        this.setState({btn_all:"btn",btn_active:"btn on",btn_offline:"btn"});
      }else if(mode=="Offline"){
        this.setState({btn_all:"btn",btn_active:"btn",btn_offline:"btn on"});
      }
      
      console.log(mode);
      this.props.changeMode(mode);
      
    }
    render() {
        var classname = this.props.visible?"":"hidden" ;
        classname +=" topbar";
        return(
            <div className={classname}>
              
                <h1> Twitch Streamers </h1>
            <div class="toggle-btns">
              <button className={this.state.btn_all} onClick={this.toggleMode.bind(this)}> All  </button>
               <button className={this.state.btn_active} onClick={this.toggleMode.bind(this)}>  Active </button>
              <button className={this.state.btn_offline}onClick={this.toggleMode.bind(this)}>  Offline </button>
              </div>
            </div>
        );
    }
}


React.render(<Layout/>, document.getElementById("container"));


              
            
!
999px

Console