# gutenify/0.0.3/src/components/blocks/count-down/Block.js

Gutenify – Visual Site Builder Blocks &amp; Starter Templates, version 0.0.3. 134 lines.

- Page: https://pluginprobe.com/plugins/gutenify/0.0.3/code/src/components/blocks/count-down/Block.js
- Raw: https://pluginprobe.com/plugins/gutenify/0.0.3/raw/src/components/blocks/count-down/Block.js
- Modified: 2020-01-05T17:14:44+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/gutenify/0.0.3/code/src/components/blocks/count-down/Block.js#L10-L20`.

```javascript
import { Component } from '@wordpress/element';

class GutenifyCountDownBlock extends Component {
    getViewPortStyle(attrs,viewPort) {
        if('frontend' === this.state.screen){
            return {};
        }
        let style = {
            color: attrs.color,
            fontSize: attrs.typography['size'][viewPort]['value'] + attrs.typography['size'][viewPort]['unit']
        }

        if (attrs.typography['size'][viewPort]['value']) {
            style = { ...style, ...{ fontSize: attrs.typography['size'][viewPort]['value'] + attrs.typography['size'][viewPort]['unit'] } };
        }

        if (attrs.typography['fontFamily']) {
            style = { ...style, ...{ fontFamily:`"${attrs.typography['fontFamily']}", Sans-serif` } };
        }

        if (attrs.typography['weight']) {
            style = { ...style, ...{ fontWeight: attrs.typography['weight'] } };
        }

        if (attrs.typography['transform']) {
            style = { ...style, ...{ textTransform: attrs.typography['transform'] } };
        }

        if (attrs.typography['style']) {
            style = { ...style, ...{ fontStyle: attrs.typography['style'] } };
        }

        if (attrs.typography['decoration']) {
            style = { ...style, ...{ textDecoration: attrs.typography['decoration'] } };
        }

        if (attrs.typography['lineHeight'][viewPort]['value']) {
            style = { ...style, ...{ lineHeight: attrs.typography['lineHeight'][viewPort]['value'] + attrs.typography['lineHeight'][viewPort]['unit'] } };
        }

        if (attrs.typography['letterSpacing'][viewPort]['value']) {
            style = { ...style, ...{ letterSpacing: attrs.typography['letterSpacing'][viewPort]['value'] } };
        }

        return style;
    }
    getStyle(attrs, windowWidth) {
        let viewPort = 'desktop';
        let style = this.getViewPortStyle(attrs,viewPort);
        
        if( windowWidth>=361 && windowWidth<=768){
            viewPort = 'tablet'
            style = { ...style, ...this.getViewPortStyle(attrs,viewPort)};
        }
        

        if( windowWidth<=360){
            viewPort = 'mobile'
            style = { ...style, ...this.getViewPortStyle(attrs,viewPort)};
        }
        

        return style;
    }

    constructor(props){
        super(props);
        // this.mediaMatch = window.matchMedia('(min-width: 361px) and (max-width: 768px)');
        this.mediaMatch = window.matchMedia('(min-width: 361px) and (max-width: 768px)');
        this.mediaMobile = window.matchMedia('(max-width: 360px)');
        this.state = {
            windowWidth:window.innerWidth,
            screen: props.screen?props.screen:'admin'
        }

        // this.getStyle = this.getStyle.bind(this);
    }

    componentDidMount(){
        
        const handler = e => {
            console.log(window.innerWidth);
            this.setState({
                windowWidth:window.innerWidth
            })
        };
        this.mediaMatch.addListener(handler);
        this.mediaMobile.addListener(handler);
        console.log(this.state.windowWidth);
        
    }


    render() {
        const { showDays, showHour, showMinute, showSecond, showLabel, customLabel, customLabelDays, customLabelHours, customLabelMinutes, customLabelSeconds, digitAttrs, titleAttrs, borderAttrs, backgroundAttrs,boxSpacing } = this.props.attributes;
        let cellWrapStyle = {};
        if('frontend' !==this.state.screen){
            cellWrapStyle = {
                backgroundColor: backgroundAttrs.color,
                borderColor: borderAttrs.color,
                borderWidth: borderAttrs.width + 'px',
                marginLeft: boxSpacing.desktop.value + 'px',
            }
        }

        const digitStyle = this.getStyle(digitAttrs, this.state.windowWidth);
        const titleStyle = this.getStyle(titleAttrs, this.state.windowWidth);

        return <div className="timer-info">
            <div className="timer-count-down" id="clockdiv">
                {showDays && <>
                    <div className="time-part" style={cellWrapStyle}><span className="days" style={digitStyle}>{this.props.timerDays}</span>
                        {showLabel && <div className="days-label smalltext" style={titleStyle}>{customLabel ? customLabelDays : 'Days'}</div>}
                    </div></>}
                {showHour && <>
                    <div className="time-part" style={cellWrapStyle}><span className="hours" style={digitStyle}>{this.props.timerHour}</span>
                        {showLabel && <div className="hours-label smalltext" style={titleStyle}>{customLabel ? customLabelHours : 'Hours'}</div>}
                    </div> </>}

                {showMinute && <>
                    <div className="time-part" style={cellWrapStyle}><span className="minutes" style={digitStyle}>{this.props.timerMinute}</span>
                        {showLabel && <div className="minutes-label smalltext" style={titleStyle}>{customLabel ? customLabelMinutes : 'Minutes'}</div>}
                    </div></>}

                {showSecond &&
                    <div className="time-part" style={cellWrapStyle}><span className="seconds" style={digitStyle}>{this.props.timerSecond}</span>
                        {showLabel && <div className="seconds-label smalltext" style={titleStyle}>{customLabel ? customLabelSeconds : 'Seconds'}</div>}
                    </div>}
            </div>
        </div>;
    }
}

export default GutenifyCountDownBlock;
```
