1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00
2020-04-16 23:43:02 -07:00

42 lines
1.1 KiB
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}
/>
);
};
CacheTimeout.displayName = "CacheTimeout";
export default CacheTimeout;