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 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.
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 esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM 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.
<!DOCTYPE html>
<html lang="en">
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root" style="height: 100%"></div>
</body>
</html>
<script src="https://cdn.freecodecamp.org/testable-projects-fcc/v1/bundle.js"></script>
@import url('https://fonts.googleapis.com/css?family=Quicksand:500|Sarpanch:700|Kaushan+Script|Source+Code+Pro:600|Abril+Fatface|Audiowide|Comfortaa:700|Kelly+Slab&display=swap');
$bootstrap-sass-asset-helper: false !default;
body,
html {
height: 100%;
margin: 0px;
font-family: "Raleway", sans-serif;
@extends .themeThree;
}
.themeOne {
--shade1: #f4f1af;
--shade2: #e7e283;
--shade3: #dbd55b;
--shade4: #dedede;
}
.themeTwo {
--shade1: #aadff6;
--shade2: #7ec9e9;
--shade3: #57b5dd;
--shade4: #32a1d0;
--grey1: #dedede;
}
.themeThree {
--shade1: #c3cacf;
--shade2: #9ab1c2;
--shade3: #e88f00;
--shade3-font: #120b00;
--shade4: #5385a9;
--grey1: #dedede;
--background: #121212;
--foreground: #d4bfa6;
}
.themeFour {
--shade1: #e6e6e6;
--shade2: #dedede;
--shade3: #d1d1d1;
--shade4: #c7c7c7;
--grey1: #dedede;
}
.themeFive {
--shade1: #466b8c;
--shade2: #8c5f46;
--shade3: #8c8346;
--shade4: #79468c;
--grey1: #dedede;
}
@mixin border-radius($a, $b, $c, $d) {
-webkit-border-radius: $a $b $c $d;
-moz-border-radius: $a $b $c $d;
-ms-border-radius: $a $b $c $d;
border-radius: $a $b $c $d;
}
@mixin height-calc($percentage, $value) {
height: -moz-calc(#{$percentage} - #{$value});
/* WebKit */
height: -webkit-calc(#{$percentage} - #{$value});
/* Opera */
height: -o-calc(#{$percentage} - #{$value});
/* Standard */
height: calc(#{$percentage} - #{$value});
}
.outerDiv {
height: 100%;
width: 100%;
background-color: var(--background);
overflow: hidden;
transition: all .3s ease-in-out;
}
.innerDiv {
background: var(--background);
height: 100%;
margin-top: 0px;
}
.header {
padding-top: 7px;
background-color: var(--shade3);
transition: all .3s ease-in-out;
}
.mytitle {
padding-left: 3pt;
font-size: 60px;
font-family: 'Kaushan Script', cursive;
color: var(--shade3-font);
}
.lengthButton {
border: 0px;
background: none;
font-size: 10vw;
color: var(--shade3);
}
.clockButton {
border: 0px;
border-radius: 50%;
background: var(--shade3);
font-size: 20vw;
width: 32vw;
height: 32vw;
color: var(--background);
display: flex;
justify-content: center;
align-content: center;
}
.fa-play {
margin-left: 3vw;
}
.button {
padding: 0;
padding-top: auto;
}
.button:focus {
outline: none;
}
.button:hover{
cursor: default;
filter:brightness(1.25);
}
.lengthContainer {
text-transform: capitalize;
}
.textField {
text-align: right;
font-size: 5em;
font-family: 'Sarpanch', sans-serif;
color: var(--shade3);
filter: hue-rotate(280deg);
}
.lengthField {
font-size: 20vw;
line-height: 14vw;
}
.decrementButton {
margin-right: -10px;
}
.label {
color: var(--foreground);
}
.clockField {
}
@media (min-width: 576px){
.mytitle{
font-size: 30px;
}
.textField {
font-size: 50px;
text-align: center;
}
.clockButton {
font-size: .8em;
padding: .3em;
width: auto;
height: auto;
}
.clockField{
font-size: 2em;
line-height: .7em;
}
.fa-play {
margin-left: 5px;
}
.fa-redo {
margin-right: 5px;
margin-top: 2px;
}
.label {
font-size: .4em;
}
.lengthContainer {
}
.lengthButton {
font-size: 1em;
}
.lengthField {
line-height: .7em;
}
}
const {render} = ReactDOM
const {Provider, connect} = ReactRedux;
const {createStore} = Redux;
const INC_BREAK = 1;
const INC_SESSION = 2;
const DEC_BREAK = 3;
const DEC_SESSION = 4;
const RESET = 5;
const DEC_TIMER = 7;
const SWITCH_CLOCKS = 8;
const TIMER = 9;
const SESSION = 100;
const BREAK = 200;
const interval = 100;
// Section for setting up state
const defaultState = {
message: "Hello world with my redux",
sessionLength: 25,
breakLength: 5,
time: 1500,
clockState: SESSION,
timing: false
}
const messageReducer = (state=defaultState, action) => {
let holder = {...state};
// console.log("in message reducer, state is " + JSON.stringify(state) + " action is " + JSON.stringify(action))
switch(action.type){
case INC_SESSION:
if(holder.sessionLength < 60)
holder.sessionLength ++;
if(holder.clockState == SESSION)
holder.time = holder.sessionLength *60
break;
case INC_BREAK:
if(holder.breakLength <60)
holder.breakLength ++;
if(holder.clockState == BREAK)
holder.time = holder.breakLength *60
break;
case DEC_SESSION:
if(holder.sessionLength > 1)
holder.sessionLength --;
if(holder.clockState == SESSION)
holder.time = holder.sessionLength *60
break;
case DEC_BREAK:
if(holder.breakLength > 1)
holder.breakLength--;
if(holder.clockState == BREAK)
holder.time = holder.breakLength *60
break;
case RESET:
holder.sessionLength = 25;
holder.breakLength = 5;
holder.time = holder.sessionLength * 60
holder.clockState = SESSION;
holder.timing = false;
break;
case DEC_TIMER:
if(holder.time > 0)
holder.time--;
// console.log("decrementing timer with interval " + action.interval + " time is " + holder.time);
break;
case SWITCH_CLOCKS:
holder.clockState = holder.clockState == SESSION ? BREAK: SESSION;
let time = holder.clockState == SESSION? holder.sessionLength: holder.breakLength
holder.time = time * 60;
break;
case TIMER:
holder.timing = ! holder.timing;
break;
default:
break;
}
return holder;
}
const store = createStore(messageReducer);
// end section for setting up redux
/// HEADER stateless component
/////// setup for Header
const Header = (props) =>{
return(
<div className="col " style={{padding: "0px"}}>
<div className="header " >
<div className="mytitle" >{props.title}</div>
</div>
</div>
)
}
/// end HEADER
const TimingButton = (props)=>{
let className = "fa-"+props.label+"-circle"
return(<button className="button lengthButton "
id={props.name}
disabled={props.timing}
onClick={props.action}>
<i className={"fas " + className}></i>
</button>)};
const SessionDecrementButton = connect(
state =>({timing: state.timing, label: "minus"}),
dispatch => ({action: () => { dispatch({type:DEC_SESSION})}})
)(TimingButton)
const SessionIncrementButton = connect(
state =>({timing: state.timing, label: "plus"}),
dispatch => ({action: () => { dispatch({type:INC_SESSION})}})
)(TimingButton)
const BreakDecrementButton = connect(
state =>({timing: state.timing, label: "minus"}),
dispatch => ({action: () => { dispatch({type:DEC_BREAK})}})
)(TimingButton)
const BreakIncrementButton = connect(
state =>({timing: state.timing, label: "plus"}),
dispatch => ({action: () => { dispatch({type:INC_BREAK})}})
)(TimingButton)
const LengthContainer = (props) => {
// console.log("in render for " + props.name);
return(
<div className="lengthContainer col-sm-5">
<div className="row justify-content-center">
<div className="col-auto decrementButton align-self-center" >
{props.decrement}
</div>
<div className="col-4 col-sm-5 justify-content-center ">
<div id={props.name +"-label"} className="col d-flex justify-content-center label">{props.name} Length</div>
<div className="textField lengthField " id={props.name +'-length'}>
{props.length}
</div>
</div>
<div className="col-auto incrementButton align-self-center">
{props.increment}
</div>
</div>
</div>
)
}
const BreakLengthContainer = connect (
state => ({length: state.breakLength}),
null
)(LengthContainer);
const SessionLengthContainer = connect (
state => ({length: state.sessionLength}),
null
)(LengthContainer);
class ClockComponent extends React.Component {
constructor(props){
super(props)
this.state = {};
this.timer = "";
this.triggerTimer = this.triggerTimer.bind(this);
this.clockTick = this.clockTick.bind(this);
this.reset = this.reset.bind(this);
this.playAudio = this.playAudio.bind(this);
}
triggerTimer(){
if(this.timer){
// console.log('trigger timer stopping clock');
clearInterval(this.timer);
this.timer = "";
}
else{
// console.log('trigger timer starting clock ');
this.timer = setInterval(this.clockTick, interval);
}
this.props.toggleTimer();
}
clockTick(){
if(this.props.time == 0){
clearInterval(this.timer);
let sound = document.getElementById("beep");
sound.play();
this.timer = "";
this.props.toggleTimer();
this.props.switchClocks();
setTimeout(this.triggerTimer(), interval*2);
}
else{
this.props.decrementTimer(interval);
}
}
reset(){
clearInterval(this.timer);
let sound = document.getElementById("beep");
sound.pause();
sound.currentTime = 0;
this.timer = "";
this.props.reset();
}
playAudio(){
document.getElementById('beep').play();
}
render(){
let minutes = Math.floor(this.props.time / 60);
let seconds = this.props.time - minutes * 60;
minutes = ("00" + minutes).slice (-2);
seconds = ("00" + seconds).slice (-2);
return(
<div className="textField d-flex justify-content-center clockField" id='time-left'> {minutes + ":" + seconds} </div>
)
}
}
ClockComponent = connect(
function mapStateToProps(state, ownState){
return { time: state.time}
},
function mapDispatchToProps(dispatch, ownProps){
return {
reset: ()=> {
dispatch({type: RESET});
},
decrementTimer: (interval) =>{
dispatch({type: DEC_TIMER, interval: interval});
},
switchClocks : () => {
dispatch({type: SWITCH_CLOCKS});
},
toggleTimer: () => {
dispatch({type: TIMER});
}
}
},null, {forwardRef: true})(ClockComponent)
class App extends React.Component{
constructor(props){
super(props)
this.state ={
}
this.reset = this.reset.bind(this);
this.triggerTimer = this.triggerTimer.bind(this);
this.clockRef = React.createRef();
}
reset(){
this.refs.clockRef.reset();
}
triggerTimer(){
this.refs.clockRef.triggerTimer();
}
render(){
// console.log("in render for app ");
let title = this.props.clockState == SESSION ? "Session": "Break";
return (
<div className="outerDiv themeThree container-fluid " style={{backgroundColor: "green"}}>
<div className="innerDiv row " >
<Header title="Pomodoro Clock" />
<div className="col-12 col-sm-12" >
<div className="row justify-content-sm-center align-items-sm-end">
<div className="col-12 col-sm-4 order-sm-2 align-items-end" >
<div id="timer-label" className="d-flex justify-content-center label">{title}</div>
<ClockComponent ref="clockRef"/>
<audio preload="auto" id="beep" src="https://goo.gl/65cBl1" style={{width: "100%"}}></audio>
</div>
<div className="col-6 col-sm-auto order-sm-1 align-self-sm-end d-flex justify-content-end">
<button className="button clockButton" id="reset" onClick={this.reset}>
<i className="fas fa-redo " ></i>
</button>
</div>
<div className="col-6 col-sm-auto order-sm-3 align-self-sm-end d-flex justify-content-start">
<button className="button clockButton" id="start_stop" onClick={this.triggerTimer}>
<i className="fas fa-play " ></i>
</button>
</div>
</div>
</div>
<div className="col-12 col-sm-12 ">
<div className="row justify-content-center">
<SessionLengthContainer name="session" decrement={<SessionDecrementButton name="session-decrement"/>} increment={<SessionIncrementButton name="session-increment"/>}/>
<BreakLengthContainer name="break" decrement={<BreakDecrementButton name="break-decrement"/>} increment={<BreakIncrementButton name="break-increment"/>}/>
</div>
</div>
</div>
</div>
)
}
}
App = connect(
function mapStateToProps(state, ownProps){
let myState = {
clockState: state.clockState
}
return myState;
},
null
)(App);
// End App component
render(
<Provider store={store}>
<App />
</Provider>
, document.getElementById('root'));
Also see: Tab Triggers