Path: blob/master/src/packages/frontend/editors/stopwatch/time.tsx
1691 views
import { CSSProperties } from "react";12import { Icon } from "@cocalc/frontend/components/icon";34function zpad(n: number): string {5let s = `${n}`;6if (s.length === 1) {7s = `0${s}`;8}9return s;10}1112interface TimeProps {13amount: number;14compact?: boolean;15style?: CSSProperties;16showIcon?: boolean;17countdown?: number;18}1920export function TimeAmount(props: TimeProps) {21let t = Math.round(props.amount / 1000);22const hours = Math.floor(t / 3600);23t -= 3600 * hours;24const minutes = Math.floor(t / 60);25t -= 60 * minutes;26const seconds = t;27return (28<span29style={{30fontSize: !props.compact ? "50pt" : undefined,31fontFamily: "courier",32...props.style,33}}34>35{props.showIcon && (36<TimerIcon countdown={props.countdown} style={{ marginRight: "5px" }} />37)}38{zpad(hours)}:{zpad(minutes)}:{zpad(seconds)}39</span>40);41}4243export function TimerIcon({44countdown,45style,46}: {47countdown?: number;48style?: CSSProperties;49}) {50return (51<Icon name={countdown ? "hourglass-half" : "stopwatch"} style={style} />52);53}545556