Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf06ec07ca |
@@ -8,13 +8,10 @@ export function AnimatedNumber({
|
|||||||
value,
|
value,
|
||||||
format = defaultFormat,
|
format = defaultFormat,
|
||||||
className,
|
className,
|
||||||
immediate = false,
|
|
||||||
}: {
|
}: {
|
||||||
value: number;
|
value: number;
|
||||||
format?: (n: number) => string;
|
format?: (n: number) => string;
|
||||||
className?: string;
|
className?: string;
|
||||||
/** Count up on mount instead of waiting to scroll into view. Dashboards. */
|
|
||||||
immediate?: boolean;
|
|
||||||
}) {
|
}) {
|
||||||
const ref = React.useRef<HTMLSpanElement>(null);
|
const ref = React.useRef<HTMLSpanElement>(null);
|
||||||
const inView = useInView(ref, { once: true, margin: "-20% 0px" });
|
const inView = useInView(ref, { once: true, margin: "-20% 0px" });
|
||||||
@@ -22,12 +19,11 @@ export function AnimatedNumber({
|
|||||||
const mv = useMotionValue(0);
|
const mv = useMotionValue(0);
|
||||||
const spring = useSpring(mv, { stiffness: 90, damping: 20 });
|
const spring = useSpring(mv, { stiffness: 90, damping: 20 });
|
||||||
const [display, setDisplay] = React.useState(format(0));
|
const [display, setDisplay] = React.useState(format(0));
|
||||||
const active = immediate || inView;
|
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (reduce) { setDisplay(format(value)); return; }
|
if (reduce) { setDisplay(format(value)); return; }
|
||||||
if (active) mv.set(value);
|
if (inView) mv.set(value);
|
||||||
}, [active, value, reduce, mv, format]);
|
}, [inView, value, reduce, mv, format]);
|
||||||
|
|
||||||
React.useEffect(() => spring.on("change", (v) => setDisplay(format(v))), [spring, format]);
|
React.useEffect(() => spring.on("change", (v) => setDisplay(format(v))), [spring, format]);
|
||||||
|
|
||||||
|
|||||||
@@ -59,7 +59,16 @@ export function CommandPalette({
|
|||||||
<Command.List className="max-h-80 overflow-auto p-2">
|
<Command.List className="max-h-80 overflow-auto p-2">
|
||||||
<Command.Empty className="py-6 text-center text-sm text-muted">No results.</Command.Empty>
|
<Command.Empty className="py-6 text-center text-sm text-muted">No results.</Command.Empty>
|
||||||
{groups.map(([group, items]) => (
|
{groups.map(([group, items]) => (
|
||||||
<Command.Group key={group} heading={group} className="px-1 py-1 text-xs font-semibold uppercase tracking-wide text-muted [&_[cmdk-group-items]]:mt-1">
|
<Command.Group
|
||||||
|
key={group}
|
||||||
|
heading={group}
|
||||||
|
className={cn(
|
||||||
|
"px-1 py-1 [&_[cmdk-group-items]]:mt-1",
|
||||||
|
"[&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-semibold",
|
||||||
|
"[&_[cmdk-group-heading]]:uppercase [&_[cmdk-group-heading]]:tracking-wide",
|
||||||
|
"[&_[cmdk-group-heading]]:text-muted"
|
||||||
|
)}
|
||||||
|
>
|
||||||
{items.map((a) => (
|
{items.map((a) => (
|
||||||
<Command.Item
|
<Command.Item
|
||||||
key={a.id}
|
key={a.id}
|
||||||
|
|||||||
@@ -24,8 +24,6 @@ export interface StatCardProps {
|
|||||||
intent?: StatIntent;
|
intent?: StatIntent;
|
||||||
icon?: React.ReactNode;
|
icon?: React.ReactNode;
|
||||||
className?: string;
|
className?: string;
|
||||||
/** Count up on mount. Pass through to AnimatedNumber. */
|
|
||||||
immediate?: boolean;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Dashboard metric tile. Pass `animate` for a count-up, or `value` for static. */
|
/** Dashboard metric tile. Pass `animate` for a count-up, or `value` for static. */
|
||||||
@@ -38,7 +36,6 @@ export function StatCard({
|
|||||||
intent = "default",
|
intent = "default",
|
||||||
icon,
|
icon,
|
||||||
className,
|
className,
|
||||||
immediate,
|
|
||||||
}: StatCardProps) {
|
}: StatCardProps) {
|
||||||
return (
|
return (
|
||||||
<div className={cn("rounded-lg border border-border bg-surface p-4 shadow-sm", className)}>
|
<div className={cn("rounded-lg border border-border bg-surface p-4 shadow-sm", className)}>
|
||||||
@@ -47,7 +44,7 @@ export function StatCard({
|
|||||||
{icon && <span className="text-muted [&_svg]:size-4">{icon}</span>}
|
{icon && <span className="text-muted [&_svg]:size-4">{icon}</span>}
|
||||||
</div>
|
</div>
|
||||||
<p className={cn("mt-1 font-display text-2xl font-bold", INTENT[intent])}>
|
<p className={cn("mt-1 font-display text-2xl font-bold", INTENT[intent])}>
|
||||||
{animate != null ? <AnimatedNumber value={animate} format={format} immediate={immediate} /> : value}
|
{animate != null ? <AnimatedNumber value={animate} format={format} /> : value}
|
||||||
</p>
|
</p>
|
||||||
{sub && <p className="mt-0.5 text-xs text-muted">{sub}</p>}
|
{sub && <p className="mt-0.5 text-xs text-muted">{sub}</p>}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -9,24 +9,19 @@ export function FadeIn({
|
|||||||
delay = 0,
|
delay = 0,
|
||||||
y = 8,
|
y = 8,
|
||||||
className,
|
className,
|
||||||
immediate = false,
|
|
||||||
}: {
|
}: {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
delay?: number;
|
delay?: number;
|
||||||
y?: number;
|
y?: number;
|
||||||
className?: string;
|
className?: string;
|
||||||
/** Animate on mount instead of waiting to scroll into view. Dashboards. */
|
|
||||||
immediate?: boolean;
|
|
||||||
}) {
|
}) {
|
||||||
const reduce = useReducedMotion();
|
const reduce = useReducedMotion();
|
||||||
const visible = { opacity: 1, y: 0 };
|
|
||||||
return (
|
return (
|
||||||
<motion.div
|
<motion.div
|
||||||
className={className}
|
className={className}
|
||||||
initial={reduce ? false : { opacity: 0, y }}
|
initial={reduce ? false : { opacity: 0, y }}
|
||||||
{...(immediate
|
whileInView={{ opacity: 1, y: 0 }}
|
||||||
? { animate: visible }
|
viewport={{ once: true, margin: "-10% 0px" }}
|
||||||
: { whileInView: visible, viewport: { once: true, margin: "-10% 0px" as const } })}
|
|
||||||
transition={reduce ? { duration: 0 } : { duration: 0.4, ease: easeOut, delay }}
|
transition={reduce ? { duration: 0 } : { duration: 0.4, ease: easeOut, delay }}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
|||||||
Reference in New Issue
Block a user