mirror of https://github.com/almqv/wych.dev
parent
39ae3b8af3
commit
97c2f65eb8
@ -0,0 +1,47 @@ |
||||
"use client"; |
||||
|
||||
import { useCallback, useEffect, useRef, useState } from "react"; |
||||
|
||||
type AgeDisplayProps = { |
||||
className?: string; |
||||
precision?: number; |
||||
}; |
||||
|
||||
function getAge() { |
||||
let birth = 1050019200; |
||||
let now = Math.floor(Date.now() / 1000); |
||||
return now - birth; |
||||
} |
||||
|
||||
function secondsToYears(secs: number, precision: number) { |
||||
let years = secs / 31556952; |
||||
return years.toFixed(precision); |
||||
} |
||||
|
||||
const AgeDisplay: React.FC<AgeDisplayProps> = ({ |
||||
className, |
||||
precision = 2, |
||||
}) => { |
||||
const ref = useRef<HTMLSpanElement>(null); |
||||
|
||||
const anim = useCallback(() => { |
||||
if (!ref.current) { |
||||
return; |
||||
} |
||||
ref.current.textContent = secondsToYears(getAge(), precision); |
||||
}, []) |
||||
|
||||
useEffect(() => { |
||||
const animFrame = requestAnimationFrame(() => { |
||||
anim(); |
||||
}); |
||||
|
||||
return () => { |
||||
cancelAnimationFrame(animFrame); |
||||
}; |
||||
}, [getAge, ref.current]); |
||||
|
||||
return <span ref={ref} className={className}>??</span>; |
||||
}; |
||||
|
||||
export default AgeDisplay; |
@ -0,0 +1,79 @@ |
||||
import * as React from "react" |
||||
|
||||
import { cn } from "@/lib/utils" |
||||
|
||||
const Card = React.forwardRef< |
||||
HTMLDivElement, |
||||
React.HTMLAttributes<HTMLDivElement> |
||||
>(({ className, ...props }, ref) => ( |
||||
<div |
||||
ref={ref} |
||||
className={cn( |
||||
"rounded-lg border bg-card text-card-foreground shadow-sm", |
||||
className |
||||
)} |
||||
{...props} |
||||
/> |
||||
)) |
||||
Card.displayName = "Card" |
||||
|
||||
const CardHeader = React.forwardRef< |
||||
HTMLDivElement, |
||||
React.HTMLAttributes<HTMLDivElement> |
||||
>(({ className, ...props }, ref) => ( |
||||
<div |
||||
ref={ref} |
||||
className={cn("flex flex-col space-y-1.5 p-6", className)} |
||||
{...props} |
||||
/> |
||||
)) |
||||
CardHeader.displayName = "CardHeader" |
||||
|
||||
const CardTitle = React.forwardRef< |
||||
HTMLParagraphElement, |
||||
React.HTMLAttributes<HTMLHeadingElement> |
||||
>(({ className, ...props }, ref) => ( |
||||
<h3 |
||||
ref={ref} |
||||
className={cn( |
||||
"text-2xl font-semibold leading-none tracking-tight", |
||||
className |
||||
)} |
||||
{...props} |
||||
/> |
||||
)) |
||||
CardTitle.displayName = "CardTitle" |
||||
|
||||
const CardDescription = React.forwardRef< |
||||
HTMLParagraphElement, |
||||
React.HTMLAttributes<HTMLParagraphElement> |
||||
>(({ className, ...props }, ref) => ( |
||||
<p |
||||
ref={ref} |
||||
className={cn("text-sm text-muted-foreground", className)} |
||||
{...props} |
||||
/> |
||||
)) |
||||
CardDescription.displayName = "CardDescription" |
||||
|
||||
const CardContent = React.forwardRef< |
||||
HTMLDivElement, |
||||
React.HTMLAttributes<HTMLDivElement> |
||||
>(({ className, ...props }, ref) => ( |
||||
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} /> |
||||
)) |
||||
CardContent.displayName = "CardContent" |
||||
|
||||
const CardFooter = React.forwardRef< |
||||
HTMLDivElement, |
||||
React.HTMLAttributes<HTMLDivElement> |
||||
>(({ className, ...props }, ref) => ( |
||||
<div |
||||
ref={ref} |
||||
className={cn("flex items-center p-6 pt-0", className)} |
||||
{...props} |
||||
/> |
||||
)) |
||||
CardFooter.displayName = "CardFooter" |
||||
|
||||
export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent } |
Loading…
Reference in new issue