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

CSS

              
                @font-face 
  font-family: "ScottSoft"
  src: url("//db.onlinewebfonts.com/t/a2dac3f13aa71eb9db6904720c325c7c.eot") 
  src: url("//db.onlinewebfonts.com/t/a2dac3f13aa71eb9db6904720c325c7c.eot?#iefix") format("embedded-opentype"), url("//db.onlinewebfonts.com/t/a2dac3f13aa71eb9db6904720c325c7c.woff2") format("woff2"), url("//db.onlinewebfonts.com/t/a2dac3f13aa71eb9db6904720c325c7c.woff") format("woff"), url("//db.onlinewebfonts.com/t/a2dac3f13aa71eb9db6904720c325c7c.ttf") format("truetype"), url("//db.onlinewebfonts.com/t/a2dac3f13aa71eb9db6904720c325c7c.svg#ScottSoft") format("svg")


$primary-color: black
$secondary-color: white
$highlight-color: #333333
$break-color: red

$circle-stroke: white
$circle-stroke-alternate: black

body 
    background: $primary-color
    color: $secondary-color
    text-align: center
    padding: 60px
    font-family: sans-serif

    h1
        font-family: "ScottSoft"
        font-size: 3em

    .clock
        width: 256px
        margin: auto

        .clock-timer
            background: $secondary-color
            color: $primary-color
            position: relative
            border-radius: 50px

            &.break-start
                background: $break-color
                color: $secondary-color
                
                circle 
                    stroke: $break-color

            svg
                position: absolute
                width: 150px
                height: 150px
                top: -30px
                right: -18px

                circle
                    cx: 75
                    cy: 75
                    r: 70
                    stroke: $circle-stroke
                    stroke-dasharray: 5
                    stroke-dashoffset: 0
                    stroke-width: 8

                    &.rotate
                        animation-iteration-count: infinite
                        animation-name: rotate
                        animation-duration: 1s
                        animation-timing-function: linear

        h1
            position: relative
            z-index: 1
            font-size: 72px
            margin: 0

            span
                color: #fff
                padding-left: 32px
        
        h2
            text-align: left
            font-size: 1.2em
            font-weight: 100
            text-transform: uppercase
            margin: 0
            padding: 0 0 0 24px
            font-weight: 100

    

    button
        background: $primary-color
        color: $secondary-color
        &.active, &:hover
            background: $secondary-color
            color: $primary-color
            

    .controllerWrapper
        display: flex
        margin: auto
        width: 300px
        padding-top: 60px

        .controller
            flex: 1
            margin: 5px

            h3
                text-transform: uppercase
                margin: 0

            div
                display: flex
                border: 1px solid $highlight-color
                align-items: center
                justify-content: center
                padding: 2px

                span, h5
                    flex: 1
                    font-size: 2em
                h5
                    padding: 0 12px
                    margin: 0
                    
                    

                span
                    display: inline-block
                    padding: 10px
                    background: $highlight-color
                    cursor: pointer
                    &:hover
                        @extend button
                        

    .timer-controller
        padding-top: 20px

        button
            border: 1px solid $highlight-color
            margin: 5px
            font-size: 1em
            text-transform: uppercase
            padding: 5px 10px
            cursor: pointer
            @extend button

    @keyframes rotate 
        100% 
            stroke-dashoffset: 20
        
    
              
            
!

JS

              
                const MIN_MIN = 1;
const MAX_MIN = 60;
const STATUS = {
    break: "break",
    session: "session",
    play: "play",
    pause: "pause",
    reset: "reset",
    switch: "switch"
}

const DEFAULTS = {
    break: 5,
    session: 25,
    minutes:25,
    seconds:0,
    active: STATUS.session,
    isplay: false,
}

Object.freeze(STATUS);
Object.freeze(DEFAULTS);

let breakAlarmAudio;
class PomodoroClock extends React.Component{
    constructor(){
        super();
        this.state = JSON.parse(JSON.stringify(DEFAULTS));
        this.timerInterval = 0;
        this.deadline = 0;
        this.pausedAt = 0;
    }

    componentDidMount(){
        breakAlarmAudio = document.getElementById("alert")
    }

    setTimerDeadline = (type)=>{
        let endtime = this.state.active === STATUS.session?this.state.session:this.state.break;
        if(type === STATUS.pause){
            this.pausedAt = Date.parse(this.deadline) - Date.now();
            clearInterval(this.timerInterval);
            return;
        }
        if(this.pausedAt === 0){
            this.deadline =  new Date(Date.now() + ( endtime * 60000));
        }else{
            //1000 added to match the 1 sencond difference
            this.deadline = new Date(Date.now() + (this.pausedAt+1000));
            this.pausedAt = 0;
        }
    }

    timerAction = (type)=>{
        switch (type) {
            case STATUS.play:
                this.setTimerDeadline(STATUS.play);
                this.timerCountDown(this.deadline);
                break;
            case STATUS.pause:
                this.setTimerDeadline(STATUS.pause);
                break;
            case STATUS.reset:
                clearInterval(this.timerInterval);
                this.setState(JSON.parse(JSON.stringify(DEFAULTS)));
                break;
            case STATUS.switch:
                let activate = this.state.active === STATUS.session? STATUS.break:STATUS.session;
                this.setState({active:activate},()=>{
                    this.timerAction(STATUS.play);
                });
                break;
            default:
                break;
        }
    }

    timerCountDown = (timerend) =>{
        let _this = this;
        clearInterval(this.timerInterval);
        
        this.timerInterval = setInterval(function(){
            let t = Date.parse(timerend) - Date.parse(new Date());
            let seconds = Math.floor( (t/1000) % 60 );
            let minutes = Math.floor( (t/1000/60) % 60 );
            _this.setState({
                minutes,
                seconds
            })
            if(minutes <= 0 && seconds <= 0){
                
                clearInterval(_this.timerInterval)
                _this.timerAction(STATUS.switch);
            }
            if(minutes===0 && seconds<30){
                breakAlarmAudio.play();
                return;
            }
            breakAlarmAudio.pause();
            //console.log("Sec",((60 + start.getSeconds()) + step.getSeconds())-60);
        }, 1000);
    }

    togglePlayPause = () =>{
        if(!this.state.isplay){
            this.timerAction(STATUS.play);
        }else{
            this.timerAction(STATUS.pause);
        }
        this.setState({
            isplay:!this.state.isplay
        });
    }

    resetTimer= () => {
        this.timerAction(STATUS.reset);
    }

    timeSetup = (isIncrement, setFor) => {
        if(this.state.isplay)
            return
        this.setState(prevState=>{
            let currentCount = prevState[setFor];
            let minutes = prevState.minutes;
            prevState.seconds = 0;
            if(isIncrement){
                currentCount = currentCount + 1;
                if(setFor === STATUS.session)
                    minutes = minutes + 1
            }else{
                currentCount = currentCount - 1;
                if(setFor === STATUS.session)
                    minutes = minutes - 1
            }
            if(currentCount>=MIN_MIN && currentCount<=MAX_MIN){
                prevState[setFor] = currentCount;
                prevState.minutes = minutes;
                //return prevState;
            }
            return false;
        });
       //console.log(this);
    } 

    render(){
        return(
            <div className="pomodoro">
                <h1>Pomodoro Clock</h1>
                <Clock options={{title:this.state.active, isplay:this.state.isplay, min:this.state.minutes, sec: this.state.seconds}}/>
                <div className="controllerWrapper">
                    <LengthController title={STATUS.session} time={this.state.session} action={this.timeSetup}  />
                    <LengthController title={STATUS.break} time={this.state.break} action={this.timeSetup} />
                </div>
                <TimerController toggle={this.togglePlayPause} isplay={this.state.isplay} reset={this.resetTimer} />
                <audio id="alert" loop >
                    <source src="http://soundbible.com/mp3/Woop%20Woop-SoundBible.com-198943467.mp3" />   
                </audio>
                <p>The pomodoro clock is realtime and acurate with sound alert.</p>
                <h6>Design &amp; Code by Dhaval Patel</h6>
                {/* <div>Font made from <a href="http://www.onlinewebfonts.com">oNline Web Fonts</a>is licensed by CC BY 3.0</div> */}
            </div>
        )
    }
}

class TimerController extends React.Component {
    render() { 
        return (  
            <div className="timer-controller">
                <button id="start_stop" className="active" onClick={()=>this.props.toggle()}>
                    {this.props.isplay?"Pause":"Play"}
                </button>
                <button id="reset" onClick={()=>this.props.reset()}>Reset</button> 
            </div>
        );
    }
}
 
function Clock(props){
    return(
        <div className="clock">
            <h2 id="timer-label">{props.options.title}</h2>
            <div className={props.options.title===STATUS.session?"clock-timer":"clock-timer break-start"}>
                <svg>
                    <circle className={props.options.isplay?"rotate":""}  />
                </svg>
                <h1 id="time-left">
                    {(props.options.min).toLocaleString('en-US', {minimumIntegerDigits: 2})}:<span>{(props.options.sec).toLocaleString('en-US', {minimumIntegerDigits: 2})}</span>
                </h1>
            </div>
        </div>
    )
}

function LengthController(props){
    return(
        <div className="controller">
            <h3 id={props.title+"-label"}>{props.title}</h3>
            <div>
                <span id={props.title+"-increment"} onClick={()=>props.action(true, props.title)}>+</span>
                <h5 id={props.title+"-length"}>{props.time}</h5>
                <span id={props.title+"-decrement"} onClick={()=>props.action(false, props.title)}>-</span>
            </div>
        </div>
    );
}


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

Console