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

              
                <div id="main" class="pomodoroPage">
	<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
	<main id="pomodoro" role="main"></main>
</div>
              
            
!

CSS

              
                #main,.sidenav{overflow-x:hidden}.button,.center{text-align:center}:root{--black-one:#131112;--black-two:#011627;--grey-one:#60656f;--grey-two:#786c72;--white-one:#f7f7ff;--white-two:#fdfffc;--red:#ff0022;--orange:#f2994a;--gold:#f2c94c;--brown:#c49991;--green:#27ae60;--teal:#41ead4;--blue-one:#279af1;--blue-two:#2d53db;--magenta:#b91372;--purple-one:#9B51E0;--purple-two:#bb6bd9;--headingsFont:"Quicksand",sans-serif;--bodyFont:"Montserrat",serif}html{font-size:21px;font-family:var(--bodyFont);background-color:var(--white-two);color:var(--black-one)}h1,h2,h3,h4,h5,h6,ul.navbar a{font-family:var(--headingsFont)}#main{transition:margin-left .5s;width:100%;display:flex;flex-direction:column}h1,h2,h3,h4,h5,h6{margin:0;font-weight:400}h1{font-size:2.25rem}h2{font-size:1.75rem}h3{font-size:1.3rem}h4{font-size:1.05rem}h5{font-size:.9rem}h6{font-size:.75rem}a{color:var(--blue-one);text-decoration:none}a:hover{color:var(--magenta)}.sidenav .closebtn,ul.navbar a{color:var(--white-one);text-decoration:none}.sidenav{height:100%;width:0;position:fixed;z-index:1;top:0;left:0;background-color:var(--black-one);padding-top:10vh;transition:.5s}.sidenav .closebtn{position:absolute;top:0;right:25px;font-size:36px;margin-left:50px}ul.navbar{display:block;list-style:none;height:35px;margin:auto;font-size:.85rem}ul.navbar li{display:block;white-space:nowrap}#topNav a{float:left;padding:14px 16px}ul.navbar a{display:block;padding:10px}ul.navbar a:hover{background-color:var(--white-one);color:var(--black-one);transition:.3s}#icoClose,#icoOpen{background-color:transparent;border:none}#icoOpen{opacity:1;transition:opacity .5s;padding:10px 0 0 10px}#icoOpen.fade{opacity:0}.openNavSide{width:250px}.openNavMain{margin-left:250px}.italic{font-style:italic}.button{display:block;line-height:1.42857143;width:70vw;max-width:300px;white-space:nowrap;background-color:var(--blue-one);border-radius:20px;border:1px solid transparent;font-size:1.3rem;padding:9px 25px;color:var(--white-one);margin:2% auto}#ah:hover,#fr:hover,.button:hover{transition:.3s;color:var(--black-one);background-color:var(--gold)}#footer,#footer a{color:var(--white-one)}#footer{background:url(../images/cleveland-blur_600x339.jpg) center;background-size:cover;width:100vw;height:234px;padding:1% 2%;display:flex;flex-direction:column}#footer h2{display:flex;justify-content:flex-end}#footer a:hover{color:var(--gold);transition:.3s}.footerRow{display:flex;flex-direction:row}#contact,#social{justify-content:space-between;display:flex}#contact{align-items:center}#myEmail{font-size:1.15rem}#social{margin-top:auto;align-items:flex-end}#icons{width:55%;display:flex;justify-content:space-between}#builtByMe{font-size:.8rem;display:flex;align-items:flex-end}@media only screen and (min-width:850px){#topNav,.closebtn{display:none}.sidenav{height:45px;width:100%;background-color:var(--white-two);overflow-y:hidden;padding-top:0;display:block;position:static}ul.navbar{font-size:.9rem}ul.navbar li{display:inline-block}ul.navbar a{color:var(--black-one)}ul.navbar a:hover{background-color:var(--black-one);color:var(--white-one)}}@media only screen and (min-width:1024px){#footer,#footer a{color:var(--black-one)}h1{font-size:64px}h2{font-size:46px}h3{font-size:32px}h4{font-size:30px}h5{font-size:26px}h6{font-size:24px}#footer{background-image:none;background-color:var(--white-one)}#contact{justify-content:flex-end}#myEmail{margin-right:10px}#icons{width:30%}}@media only screen and (min-width:1800px){#icons{width:20%}}
html, body {height: 100%; font-size: 10px; font-family: "Montserrat"}
h1 {font-size: 3.5rem;}
h2 {font-size: 2rem;}
h3 {font-size: 5rem;}
span {font-size: 1.8rem;}
button {
	font-size: 1.8rem;
	font-weight: bold;
	padding: 5px 10px;
	margin: 0 10px;
	box-shadow: 0px 0px 5px var(--black-one);
}

.pomodoroPage {
	height: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	background: radial-gradient(circle, rgba(253,255,252,0) 38%, rgba(39,154,241,1) 100%);
}

#pomodoro {
	display: flex;
	flex-direction: column;
	width: 90vw;
	max-width: 800px;
	box-shadow: 0px 10px 10px var(--black-two);
	padding: 20px;
}

.timers {
	display: grid;
	grid-template-columns: 1fr 1fr;
	
	.timer {
		margin: 10px auto 20px;
	}
}

.sessionButtons {
	margin: 10px 0px 0px;
	
	button {
		margin: 0px 15px;
		background-color: transparent;
		border: none;
		box-shadow: none;
		font-size: 1rem;
	}
}

@media only screen and (max-width: 400px) {
	.timers {
		display: flex;
		flex-direction: column;
	}
}
              
            
!

JS

              
                // Accurate_Interval.js from the original example because my times kept messing up
(function() {
  window.accurateInterval = function(fn, time) {
    var cancel, nextAt, timeout, wrapper;
    nextAt = new Date().getTime() + time;
    timeout = null;
    wrapper = function() {
      nextAt += time;
      timeout = setTimeout(wrapper, nextAt - new Date().getTime());
      return fn();
    };
    cancel = function() {
      return clearTimeout(timeout);
    };
    timeout = setTimeout(wrapper, nextAt - new Date().getTime());
    return {
      cancel: cancel
    };
  };
}).call(this);


// Timer
class Timer extends React.Component {
	constructor(props) {
		super(props);
	}
	render() {
		return (
			<div className={this.props.labelClass}>
				<h2 id={this.props.labelId}>{this.props.type}</h2>
				<div className="timer">
					<button id={this.props.decrement} onClick={this.props.onClick} value="-">
						<i className="fa fa-arrow-down"></i>
					</button>
					<span id={this.props.typeLength}>{this.props.time}</span>
					<button id={this.props.increment} onClick={this.props.onClick} value="+">
						<i className="fa fa-arrow-up"></i>
					</button>
				</div>
			</div>
		)
	}
}


// Counter
class Counter extends React.Component {
	constructor(props) {
		super(props);
	}
	render() {
		return (
			<div className="counter center">
				<h2 id="timer-label">{this.props.label}</h2>
				<h3 id="time-left">{this.props.timer}</h3>
				<div class="sessionButtons">
					<button id="start_stop" onClick={this.props.handlePausePlay}>
						<i class={this.props.icon}></i>
					</button>
					<button id="reset" onClick={this.props.handleReset}>
						<i class="fas fa-redo-alt fa-3x"></i>
					</button>
				</div>
			</div>
		)
	}
}

// Clock
class Pomodoro extends React.Component {
	constructor(props) {
		super(props);
		this.state = {
			breakTime: 5,
			sessionTime: 25,
			timer: 1500,
			label: 'Session',
			timerState: 'paused',
			icon: 'fas fa-play fa-3x',
			interval: '',
		};
	}
	
	handleBreakTime = (e) => {this.changeTime(e.currentTarget.value, 'breakTime', this.state.breakTime, 'Break');}
	handleSessionTime = (e) => {this.changeTime(e.currentTarget.value, 'sessionTime', this.state.sessionTime, 'Session');}
	
	changeTime = (value, stateName, stateTime, timerType) => {
		if (this.state.timerState == 'running') return;
		if (this.state.label == timerType) {
			if (value == "-" && stateTime != 1 ) {
				this.setState({
					[stateName]: stateTime - 1,
					timer: stateTime * 60 - 60,
					label: timerType,
				});
			} else if (value == "+" && stateTime != 60) {
				this.setState({
					[stateName]: stateTime + 1,
					timer: stateTime * 60 + 60,
					label: timerType,
				});
			}
		} else {
			if (value == "-" && stateTime != 1 ) {
				this.setState({
					[stateName]: stateTime - 1,
					// TODO: add function to display break time on change and return to session time
					// timer: stateTime * 60 - 60,
					// label: timerType,
				});
			} else if (value == "+" && stateTime != 60) {
				this.setState({
					[stateName]: stateTime + 1,
					// TODO: add function to display break time on change and return to session time
					// timer: stateTime * 60 + 60,
					// label: timerType,
				});
			} 
		}
	}
	
	changeToClock = () => {
		let minutes = Math.floor(this.state.timer / 60);
		let seconds = this.state.timer - minutes * 60;
		seconds = seconds < 10 ? '0' + seconds : seconds;
		minutes = minutes < 10 ? '0' + minutes : minutes;
		return minutes + ':' + seconds;
	}
	
	sessionControl = () => {
		this.state.timerState == 'paused' ? (
			this.countDown(),
			this.setState({
				timerState: 'running',
				icon: 'fas fa-pause fa-3x',
			})
		) : (
			this.setState({
				timerState: 'paused',
				icon: 'fas fa-play fa-3x',
			}),
			this.state.interval && this.state.interval.cancel()
		);
	}
		countDown = () => {
			this.setState({
				interval: accurateInterval(() => {
					this.decrementTimer(); 
					this.timerSwapControl();
				}, 1000)
			})
		}
		decrementTimer = () => {
			this.setState({
				timer: this.state.timer - 1,
			});
		}
		
		timerSwapControl = () => {
			let time = this.state.timer;
			this.alarm(time);
			if (time < 0) {
				this.state.label == 'Session' ? (
					this.state.interval && this.state.interval.cancel(),
					this.countDown(),
					this.timerSwap(this.state.breakTime * 60, 'Break')
				) : (
					this.state.interval && this.state.interval.cancel(),
					this.countDown(),
					this.timerSwap(this.state.sessionTime * 60, 'Session')
				);
			}
		}
		alarm = (_time) => {
			if (_time === 0) {
				this.alarmSound.play()
			}
		}
		timerSwap = (newTime, label) => {
			this.setState({
				timer: newTime,
				label: label,
			});
		}
		
		resetTimer = () => {
			this.state.timerState == 'running' ? (
				this.sessionControl(),
				this.setState({
					breakTime: 5,
					sessionTime: 25,
					timer: 1500,
					label: 'Session',
					timerState: 'paused',
					icon: 'fas fa-play fa-3x',
					interval: '',
				})
			) : (
				this.setState({
					breakTime: 5,
					sessionTime: 25,
					timer: 1500,
					label: 'Session',
					timerState: 'paused',
					icon: 'fas fa-play fa-3x',
					interval: '',
				})
			);
			this.state.interval && this.state.interval.cancel();
			this.alarmSound.pause();
			this.alarmSound.currentTime = 0;
		}
	
	render() {
		return (
			<>
				<h1 className="center">Pomodoro Clock</h1>
				<div className="timers center">
					<Timer
						time={this.state.breakTime}
						labelClass="break" type="Break Length" labelId="break-label"
						decrement="break-decrement" increment="break-increment" typeLength="break-length"
						onClick={this.handleBreakTime}/>
					<Timer
						time={this.state.sessionTime}
						labelClass="session" type="Session Length" labelId="session-label"
						decrement="session-decrement" increment="session-increment" typeLength="session-length"
						onClick={this.handleSessionTime}/>
				</div>
				<Counter icon={this.state.icon} label={this.state.label} timer={this.changeToClock()} handlePausePlay={this.sessionControl} handleReset={this.resetTimer}/>
				<audio id="beep" src="https://goo.gl/65cBl1" ref={(audio => {this.alarmSound = audio;})} />
			</>
		)
	}
}

ReactDOM.render(<Pomodoro />, document.getElementById('pomodoro'));
              
            
!
999px

Console