1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00
2020-07-05 17:20:10 -07:00

40 lines
986 B
JavaScript

import * as React from "react";
import Countdown, { zeroPad } from "react-countdown";
import { Text, useColorMode } from "@chakra-ui/core";
const bg = { dark: "white", light: "black" };
const Renderer = ({ hours, minutes, seconds, completed, props }) => {
if (completed) {
return <Text fontSize="xs" />;
} else {
let time = [zeroPad(seconds)];
minutes !== 0 && time.unshift(zeroPad(minutes));
hours !== 0 && time.unshift(zeroPad(hours));
return (
<Text fontSize="xs" color="gray.500">
{props.text}
<Text as="span" fontSize="xs" color={bg[props.colorMode]}>
{time.join(":")}
</Text>
</Text>
);
}
};
const CacheTimeout = ({ timeout, text }) => {
const then = timeout * 1000;
const { colorMode } = useColorMode();
return (
<Countdown
date={Date.now() + then}
renderer={Renderer}
daysInHours
text={text}
colorMode={colorMode}
/>
);
};
export default CacheTimeout;