@zohodesk/dot
Version:
In this Library, we Provide Some Basic Components to Build Your Application
67 lines (61 loc) • 1.72 kB
JavaScript
import React from 'react';
import { Timer_propTypes } from "./propTypes/propTypes";
import { Timer_defaultProps } from "./propTypes/defaultProps";
import { Container } from '@zohodesk/components/lib/Layout';
import { addLeadingZeros } from "../utils/utils";
import style from "./Timer.module.css";
export default class Timer extends React.Component {
constructor(props) {
super(props);
this.constructTimer = this.constructTimer.bind(this);
}
constructTimer() {
let {
hour,
minute,
second,
amPm,
separator,
timerFormat,
needCharacter
} = this.props;
const timeSeparator = separator == 'space' ? ' ' : ':';
let timerValue = '';
const format = timerFormat.toLowerCase().split(':');
hour = addLeadingZeros(hour);
minute = addLeadingZeros(minute);
second = addLeadingZeros(second);
if (needCharacter) {
hour = `${hour}h`;
minute = `${minute}m`;
second = `${second}s`;
}
format.map(type => {
if (type == 'hh') {
timerValue += hour;
} else if (type == 'mm') {
timerValue += minute;
} else if (type == 'ss') {
timerValue += second;
}
timerValue += timeSeparator;
});
timerValue = timerValue.slice(0, -1);
amPm && (timerValue = `${timerValue} ${amPm}`);
return timerValue;
}
render() {
const {
dataId
} = this.props;
const timerValue = this.constructTimer();
return /*#__PURE__*/React.createElement(Container, {
dataId: dataId,
alignBox: "row",
className: style.container,
flexible: true
}, timerValue);
}
}
Timer.defaultProps = Timer_defaultProps;
Timer.propTypes = Timer_propTypes;