PluginProbe
Gutenify – Visual Site Builder Blocks & Starter Templates / 0.0.3
Gutenify – Visual Site Builder Blocks & Starter Templates v0.0.3
1.9.0 1.8.0 1.7.0 1.6.6 1.6.5 1.6.4 trunk 0.0.1 0.0.2 0.0.3 1.0.0 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 All 74 releases
gutenify / src / components / blocks / count-down / Block.js

Block.js in Gutenify – Visual Site Builder Blocks & Starter Templates 0.0.3, at src/components/blocks/count-down/Block.js

134 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Component } from '@wordpress/element';
2
3 class GutenifyCountDownBlock extends Component {
4 getViewPortStyle(attrs,viewPort) {
5 if('frontend' === this.state.screen){
6 return {};
7 }
8 let style = {
9 color: attrs.color,
10 fontSize: attrs.typography['size'][viewPort]['value'] + attrs.typography['size'][viewPort]['unit']
11 }
12
13 if (attrs.typography['size'][viewPort]['value']) {
14 style = { ...style, ...{ fontSize: attrs.typography['size'][viewPort]['value'] + attrs.typography['size'][viewPort]['unit'] } };
15 }
16
17 if (attrs.typography['fontFamily']) {
18 style = { ...style, ...{ fontFamily:`"${attrs.typography['fontFamily']}", Sans-serif` } };
19 }
20
21 if (attrs.typography['weight']) {
22 style = { ...style, ...{ fontWeight: attrs.typography['weight'] } };
23 }
24
25 if (attrs.typography['transform']) {
26 style = { ...style, ...{ textTransform: attrs.typography['transform'] } };
27 }
28
29 if (attrs.typography['style']) {
30 style = { ...style, ...{ fontStyle: attrs.typography['style'] } };
31 }
32
33 if (attrs.typography['decoration']) {
34 style = { ...style, ...{ textDecoration: attrs.typography['decoration'] } };
35 }
36
37 if (attrs.typography['lineHeight'][viewPort]['value']) {
38 style = { ...style, ...{ lineHeight: attrs.typography['lineHeight'][viewPort]['value'] + attrs.typography['lineHeight'][viewPort]['unit'] } };
39 }
40
41 if (attrs.typography['letterSpacing'][viewPort]['value']) {
42 style = { ...style, ...{ letterSpacing: attrs.typography['letterSpacing'][viewPort]['value'] } };
43 }
44
45 return style;
46 }
47 getStyle(attrs, windowWidth) {
48 let viewPort = 'desktop';
49 let style = this.getViewPortStyle(attrs,viewPort);
50
51 if( windowWidth>=361 && windowWidth<=768){
52 viewPort = 'tablet'
53 style = { ...style, ...this.getViewPortStyle(attrs,viewPort)};
54 }
55
56
57 if( windowWidth<=360){
58 viewPort = 'mobile'
59 style = { ...style, ...this.getViewPortStyle(attrs,viewPort)};
60 }
61
62
63 return style;
64 }
65
66 constructor(props){
67 super(props);
68 // this.mediaMatch = window.matchMedia('(min-width: 361px) and (max-width: 768px)');
69 this.mediaMatch = window.matchMedia('(min-width: 361px) and (max-width: 768px)');
70 this.mediaMobile = window.matchMedia('(max-width: 360px)');
71 this.state = {
72 windowWidth:window.innerWidth,
73 screen: props.screen?props.screen:'admin'
74 }
75
76 // this.getStyle = this.getStyle.bind(this);
77 }
78
79 componentDidMount(){
80
81 const handler = e => {
82 console.log(window.innerWidth);
83 this.setState({
84 windowWidth:window.innerWidth
85 })
86 };
87 this.mediaMatch.addListener(handler);
88 this.mediaMobile.addListener(handler);
89 console.log(this.state.windowWidth);
90
91 }
92
93
94 render() {
95 const { showDays, showHour, showMinute, showSecond, showLabel, customLabel, customLabelDays, customLabelHours, customLabelMinutes, customLabelSeconds, digitAttrs, titleAttrs, borderAttrs, backgroundAttrs,boxSpacing } = this.props.attributes;
96 let cellWrapStyle = {};
97 if('frontend' !==this.state.screen){
98 cellWrapStyle = {
99 backgroundColor: backgroundAttrs.color,
100 borderColor: borderAttrs.color,
101 borderWidth: borderAttrs.width + 'px',
102 marginLeft: boxSpacing.desktop.value + 'px',
103 }
104 }
105
106 const digitStyle = this.getStyle(digitAttrs, this.state.windowWidth);
107 const titleStyle = this.getStyle(titleAttrs, this.state.windowWidth);
108
109 return <div className="timer-info">
110 <div className="timer-count-down" id="clockdiv">
111 {showDays && <>
112 <div className="time-part" style={cellWrapStyle}><span className="days" style={digitStyle}>{this.props.timerDays}</span>
113 {showLabel && <div className="days-label smalltext" style={titleStyle}>{customLabel ? customLabelDays : 'Days'}</div>}
114 </div></>}
115 {showHour && <>
116 <div className="time-part" style={cellWrapStyle}><span className="hours" style={digitStyle}>{this.props.timerHour}</span>
117 {showLabel && <div className="hours-label smalltext" style={titleStyle}>{customLabel ? customLabelHours : 'Hours'}</div>}
118 </div> </>}
119
120 {showMinute && <>
121 <div className="time-part" style={cellWrapStyle}><span className="minutes" style={digitStyle}>{this.props.timerMinute}</span>
122 {showLabel && <div className="minutes-label smalltext" style={titleStyle}>{customLabel ? customLabelMinutes : 'Minutes'}</div>}
123 </div></>}
124
125 {showSecond &&
126 <div className="time-part" style={cellWrapStyle}><span className="seconds" style={digitStyle}>{this.props.timerSecond}</span>
127 {showLabel && <div className="seconds-label smalltext" style={titleStyle}>{customLabel ? customLabelSeconds : 'Seconds'}</div>}
128 </div>}
129 </div>
130 </div>;
131 }
132 }
133
134 export default GutenifyCountDownBlock;