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="root">
</div>
              
            
!

CSS

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

$lightGrey: whitesmoke;
$onix: #343E3D;

* {
    box-sizing: border-box;
}
body, html {
    font-family: Roboto;
    height: 100%;
}
#root {
    align-items: center;
    background: $lightGrey;
    display: flex;
    height: 100%;
    justify-content: center;
    position: relative;
    width: 100%;
}
.container {
    background: #fff;
    box-shadow: 0 0 35px rgba($onix,0.4);
    display: flex;
    flex-direction: row;
    height: 300px;
    overflow: hidden;
    position: relative;
    transition: box-shadow 350ms;
    width: 600px;
    &:hover {
        box-shadow: 0 0 10px rgba($onix,0.4);
    }
    .image {
        background-repeat: no-repeat;
        background-size: cover;
        height: 100%;
        position: relative;
        width: 60%;
        z-index: 1;
        // wave effect      
				&:after {
            background: #fff;
            border-radius: 50%;
            content: '';
            height: 200px;
            opacity: 0.3;
            position: absolute;
            position: absolute;
            right: -18px;
            top: -5px;
            transform: rotate(-6deg);
            width: 30px;
            z-index: 2;
        }
        &:before {
            background: transparent;
            border-radius: 50%;
            bottom: -60px;
            box-shadow: 15px 15px 0 0 #fff;
            content: '';
            height: 300px;
            position: absolute;
            position: absolute;
            right: -2px;
            transform: rotate(8deg);
            width: 100px;
            z-index: 2;
        }
        //preloader         
				.overlay {
            align-items: center;
            background: $onix;
            display: flex;
            height: 100%;
            justify-content: center;
            opacity: 0.5;
            position: absolute;
            width: 100%;
            .loader {
                animation: spin 2s ease-in infinite alternate;
                height: 64px;
                width: 64px;
            }
        }
    }
    .info {
        align-items: center;
        display: flex;
        flex-direction: column;
        justify-content: space-between;
        padding: 50px;
        position: relative;
        width: 50%;
        .temp {
            align-items: center;
            color: $onix;
            display: flex;
            flex-direction: column;
            .value {
                font-size: 60px;
            }
        }
        .hr {
            background: $onix;
            border-radius: 2px;
            height: 2px;
            width: 90%;
						margin-bottom: 15px;
					  margin-top: 15px;
        }
        .location {
            align-items: center;
            color: $onix;
            display: flex;
            flex-direction: column;
            height: auto;
            justify-content: space-between;
            .city {
                font-size: 24px;
                margin-bottom: 15px;
                text-align: center;
            }
        }
        // wave effect      
					&:after {
            background: #fff;
            border-radius: 50%;
            content: '';
            height: 200px;
            left: -8px;
            position: absolute;
            position: absolute;
            top: -10px;
            transform: rotate(-5deg);
            width: 30px;
            z-index: 2;
        }
        &:before {
            background: transparent;
            border-radius: 44%;
            bottom: -60px;
            box-shadow: 15px 15px 0 0 #fff;
            content: '';
            height: 240px;
            left: -108px;
            opacity: 0.3;
            position: absolute;
            position: absolute;
            transform: rotate(14deg);
            width: 100px;
            z-index: 2;
        }
    }
}
.input {
    display: flex;
    height: 30px;
    justify-content: center;
    margin-top: 30px;
    width: 100%;
    .search {
        background: transparent;
        border: none;
        border-bottom: 1px solid $onix;
        color: $onix;
        font-size: 16px;
        outline: none;
        text-align: center;
        transition: width 200ms;
        width: 160px;
        &:focus {
            width: 220px;
        }
    }
}
input[type="search"]::-webkit-search-decoration, input[type="search"]::-webkit-search-cancel-button, input[type="search"]::-webkit-search-results-button, input[type="search"]::-webkit-search-results-decoration {
    display: none;
}
@keyframes spin {
    from {
        transform: rotate(0deg);
    }
    to {
        transform: rotate(360deg);
    }
}
              
            
!

JS

              
                //Weather Widget Component
const WEATHER_API_KEY = 'efbf03f38ab640c3bb2173254172509';
const PLACES_API_KEY = 'AIzaSyBiDPZbUq13joiGg4wxa-I7TcbX5G1Y6K4';
const proxyurl = "https://galvanize-cors-proxy.herokuapp.com/";

class WeatherWidget extends React.Component {
	constructor() {
		super();
		this.state = {
			location: '',
			country: '',
			temp: null,
			localTime: null,
			condition: '',
			icon: '',
			cloudPercentage: null,
			loading: false,
			imageUrl: 'https://cdn.dribbble.com/users/658839/screenshots/2015006/city-illustration.png',
		}
	}
	
	onCitySubmit(event) {
		if(event.keyCode == 13) {
			this.getPhotoForCity(event.target.value);
			this.getWeatherForCity(event.target.value);
		}
	}
	
	getWeatherForCity(city) {
		fetch(`https://api.apixu.com/v1/current.json?	key=${WEATHER_API_KEY}&q=${city}`)  
  .then((response) => {  
      if (response.status !== 200) {  
				console.log(`Error fetching data. Respons:${response.status}`);  
        return;  
      }
      response.json().then((data) => {  
        	this.setState({
						location: data.location.name,
						country: data.location.country,
						temp: data.current.temp_c,
						localTime: data.location.localtime,
						condition: data.current.condition.text,
						icon: data.current.condition.icon,
						cloudPercentage: data.current.cloud
					});
      });  
    }  
  )  
  .catch((err) => {  
    console.log('Fetch Error :-S', err);  
  });
 }
	
	getPhotoForCity(city) {
		this.setState({loading: true});
		const url = `${proxyurl}https://maps.googleapis.com/maps/api/place/textsearch/json?query=${city}&key=${PLACES_API_KEY}`;
		fetch(url)
  .then((response) => {
      if (response.status !== 200) {  
				console.log(`Error fetching data. Response places:${response.status}`); 
        return;  
      }
      response.json().then((data) => {
				const photoRef = data.results[0].photos[0].photo_reference;
				const url = `${proxyurl}https://maps.googleapis.com/maps/api/place/photo?maxheight=300&photoreference=${photoRef}&key=${PLACES_API_KEY}`;
		fetch(url)
  .then((response) => {
      if (response.status !== 200) {  
				console.log(`Error fetching data from places API. Response:${response.status}`); 
        return;  
      }
      response.blob().then((blob) => {
   		 const objectURL = URL.createObjectURL(blob);
			 this.setState({imageUrl: objectURL, loading: false });
      });  
    }  
  )  
  .catch((err) => {
			if (err) {
			    console.log('Fetch Error Photo', err.message);  	
			}
  });
      });  
    }  
  )  
  .catch((err) => {
			if (err) {
			    console.log('Fetch Error Places', err.message);  	
			}
  });
 }
	
	getPhotoContainer() {
		const preloader = this.state.loading ? (
			<div className="overlay">
				<div className='loader'>
					<img src='https://image.ibb.co/meRVm5/sun_1.png'/>
				</div>
			</div>
		) : null;
		return (
			<div className="image" style={{ backgroundImage: `url(${this.state.imageUrl})`}}>
				{preloader}
			</div>
		);
	}
	
	getInfoContainer() {
		const {condition, temp, location, localTime } = this.state;
		let content;
		if (this.state.location.length === 0) {
			content = null;
		} else {
			content = (
				<div>
					<div className="temp">
						<span className="value">{temp}&deg;</span>
						<span>{condition}</span>
					</div>
					<div className="hr"/>
					<div className="location">
						<span className="city">{location}</span>
						<span>{localTime}</span>
					</div>
				</div>
			);
		}
		return (
			<div className="info">
				{content}
			</div>
		);
	}
	
	getLocationInput() {
		return (
			<div className="input">
				<input className="search" type='search' placeholder='Search location' onKeyPress={() => this.onCitySubmit(event)}/>
			</div>
		);
	}
	
	render() {
		return (
			<div>
				<div className="container">
					{this.getPhotoContainer()}
					{this.getInfoContainer()}
				</div>
				{this.getLocationInput()}
				</div>
		);
	}
}

React.render(
<WeatherWidget />,
	document.getElementById('root')
);
              
            
!
999px

Console