HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URL's 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 it's URL and the proper URL extention.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Pomodoro Clock</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
</body>
</html>
$primary-btn-color: #85E673;
$secondary-btn-color: #FF4444;
$font-btn-size: 1.5em;
$btn-size: 100px;
$number-font: 'Bungee Inline', cursive;
$h2-font-size: 1.5em;
h2{
font-family: $number-font;
font-size: $h2-font-size;
text-decoration: underline;
}
#root{
height: 100%;
}
html, body{
height: 100%;
background: antiquewhite;
}
.text-center{
text-align: center;
}
.primary-button-style{
font-size: $font-btn-size;
width: $btn-size;
background-color: $primary-btn-color;
border: none;
border-radius: 10px;
margin: 10px;
}
.secondary-button-style{
font-size: $font-btn-size;
width: $btn-size;
background-color: $secondary-btn-color;
border: none;
border-radius: 10px;
margin: 10px;
}
.outer-border{
height: 300px;
width: 300px;
border: 15px solid #FF4444;
border-radius: 50%;
display: flex;
justify-content: center;
align-items: center;
}
#break-length, #session-length{
font-size: 1.3em;
font-family: $number-font;
}
#time-left{
font-size: 2.5em;
}
.inner-tomato{
font-family: $number-font;
}
class App extends React.Component {
constructor(props) {
super(props);
this.state = {
breakLength: 5,
sessionLength: 25,
timeLabel: "Session",
timeLeft: this.convertToTime(60 * 25),
initialStart: false,
isPaused: true
};
//bind methods
this.startTimer = this.startTimer.bind(this);
this.play = this.play.bind(this);
this.reset = this.reset.bind(this);
this.incrementSessionTime = this.incrementSessionTime.bind(this);
this.decrementSessionTime = this.decrementSessionTime.bind(this);
this.incrementBreakTime = this.incrementBreakTime.bind(this);
this.decrementBreakTime = this.decrementBreakTime.bind(this);
}
//reset to default states
async reset() {
this.audioBeep.pause();
this.audioBeep.currentTime = 0;
clearInterval(this.state.intervalID);
await this.setState({
breakLength: 5,
sessionLength: 25,
timeLabel: "Session",
timeLeft: this.convertToTime(60 * 25),
initialStart: false,
isPaused: true
});
}
//Session increment method
incrementSessionTime() {
if (!this.state.initialStart) {
if (this.state.sessionLength < 60) {
let newSessionLength = this.state.sessionLength + 1;
this.setState({
sessionLength: newSessionLength,
timeLeft: this.convertToTime(60 * newSessionLength)
});
}
}
}
//Session decrement method
decrementSessionTime() {
if (!this.state.initialStart) {
if (this.state.sessionLength > 1) {
let newSessionLength = this.state.sessionLength - 1;
this.setState({
sessionLength: newSessionLength,
timeLeft: this.convertToTime(60 * newSessionLength)
});
}
}
}
//Break increment method
incrementBreakTime() {
if (!this.state.initialStart) {
if (this.state.breakLength < 60) {
this.setState({
breakLength: this.state.breakLength + 1
});
}
}
}
//Session decrement method
decrementBreakTime() {
if (!this.state.initialStart) {
if (this.state.breakLength > 1) {
this.setState({
breakLength: this.state.breakLength - 1
});
}
}
}
//convert time to display minutes and seconds.
convertToTime(timer) {
var displayMinutes = parseInt(timer / 60, 10);
var displaySeconds = parseInt(timer % 60, 10);
if (displayMinutes < 10) {
displayMinutes = "0" + displayMinutes;
}
if (displaySeconds < 10) {
displaySeconds = "0" + displaySeconds;
}
return displayMinutes + ":" + displaySeconds;
}
//play start timer
async play() {
if (this.state.isPaused) {
this.setState({
isPaused: false
});
} else {
this.setState({
isPaused: true
});
}
//only start timer on the initial play hit, until reset.
if (!this.state.initialStart) {
this.setState({
initialStart: true
});
this.startTimer(this.state.sessionLength, this.state.breakLength);
}
}
//Start timer
startTimer(sessionDuration, breakDuration) {
let isSession = true;
let timer = 60 * sessionDuration;
let displayTime = this.convertToTime(timer);
let intervalID = setInterval(async () => {
if (!this.state.isPaused) {
timer -= 1;
}
displayTime = this.convertToTime(timer);
await this.setState({
timeLeft: displayTime
});
if (timer <= 0) {
if (isSession) {
isSession = false;
timer = (await 60) * breakDuration;
} else {
isSession = true;
timer = (await 60) * sessionDuration;
}
await this.setState({
timeLabel: isSession ? "Session" : "Break",
timeLeft: this.convertToTime(timer)
});
this.audioBeep.play();
}
}, 1000);
this.setState({
intervalID: intervalID
});
}
render() {
return (
<div className="App h-100">
<div className="container h-100">
<div className="row h-100 justify-content-center align-items-center">
<div className="col-md-5">
<SetTime
labelName="break-label"
labelContent="Break Length"
lengthName="break-length"
timeLength={this.state.breakLength}
decrementTime={this.decrementBreakTime}
decrementName="break-decrement"
incrementTime={this.incrementBreakTime}
incrementName="break-increment"
/>
<SetTime
labelName="session-label"
labelContent="Session Length"
lengthName="session-length"
timeLength={this.state.sessionLength}
decrementName="session-decrement"
decrementTime={this.decrementSessionTime}
incrementName="session-increment"
incrementTime={this.incrementSessionTime}
/>
</div>
<div className="col-md-7">
<Timer
timeLabel={this.state.timeLabel}
timeLeft={this.state.timeLeft}
playFunction={this.play}
resetFunction={this.reset}
/>
</div>
</div>
</div>
<audio
id="beep"
ref={audio => {
this.audioBeep = audio;
}}
src="https://res.cloudinary.com/dr5miqz3x/video/upload/v1567621615/Fire_pager_kntsrl.mp3"
/>
</div>
);
}
}
class SetTime extends React.Component {
render() {
return (
<div id="setTimer" className="text-center number-font">
<h2 id={this.props.labelName}>{this.props.labelContent}</h2>
<p className="" id={this.props.lengthName}>
{this.props.timeLength}
</p>
<button
onClick={this.props.decrementTime}
id={this.props.decrementName}
className="secondary-button-style"
>
-
</button>
<button
onClick={this.props.incrementTime}
id={this.props.incrementName}
className="primary-button-style"
>
+
</button>
</div>
);
}
}
class Timer extends React.Component {
render() {
return (
<div id="timer" className="text-center">
<div className="outer-border container ">
<div className="inner-tomato">
<h2 id="timer-label">{this.props.timeLabel}</h2>
<p id="time-left">{this.props.timeLeft}</p>
</div>
</div>
<button
id="start_stop"
className="primary-button-style material-icons"
onClick={this.props.playFunction}
>
play_arrow pause
</button>
<button
id="reset"
className="secondary-button-style material-icons"
onClick={this.props.resetFunction}
>
replay
</button>
</div>
);
}
}
ReactDOM.render(<App />, document.getElementById("root"));
Also see: Tab Triggers