1
mirror of https://github.com/jakejarvis/jarv.is.git synced 2026-04-22 04:15:31 -04:00

simplify theme provider

This commit is contained in:
2025-03-01 16:08:12 -05:00
parent 9c4d14fa45
commit 36faa6c234
11 changed files with 99 additions and 120 deletions
+3 -4
View File
@@ -1,11 +1,10 @@
import CodeBlock from "../CodeBlock";
import CodeInline from "../CodeInline";
import type { PropsWithChildren } from "react";
import type { ComponentPropsWithoutRef } from "react";
export type CodeProps = PropsWithChildren<{
export type CodeProps = ComponentPropsWithoutRef<"code"> & {
forceBlock?: boolean;
className?: string;
}>;
};
// a simple wrapper component that "intelligently" picks between inline code and code blocks (w/ optional syntax
// highlighting & a clipboard button)
+2 -2
View File
@@ -14,7 +14,7 @@ export type CommentsProps = ComponentPropsWithoutRef<"div"> & {
};
const Comments = ({ title, className, ...rest }: CommentsProps) => {
const { activeTheme } = useTheme();
const { theme } = useTheme();
// fail silently if giscus isn't configured
if (!config.giscusConfig) {
@@ -36,7 +36,7 @@ const Comments = ({ title, className, ...rest }: CommentsProps) => {
emitMetadata="0"
inputPosition="top"
loading="lazy"
theme={activeTheme === "dark" ? activeTheme : "light"}
theme={theme === "dark" ? theme : "light"}
/>
</div>
);
+3 -3
View File
@@ -14,13 +14,13 @@ export type ThemeToggleProps = {
const ThemeToggle = ({ className }: ThemeToggleProps) => {
const hasMounted = useHasMounted();
const { activeTheme, setTheme } = useTheme();
const { theme, setTheme } = useTheme();
const isFirstMount = useFirstMountState();
const prefersReducedMotion = useReducedMotion() ?? false;
const maskId = useId(); // SSR-safe ID to cross-reference areas of the SVG
// default to light since `activeTheme` might be undefined
const safeTheme = activeTheme === "dark" ? activeTheme : "light";
// default to light since `theme` might be undefined
const safeTheme = theme === "dark" ? theme : "light";
// accessibility: disable animation if user prefers reduced motion
useEffect(() => {
+4 -4
View File
@@ -1,14 +1,14 @@
import { formatDate } from "../../lib/helpers/format-date";
import type { ComponentPropsWithoutRef } from "react";
export type TimeProps = {
export type TimeProps = ComponentPropsWithoutRef<"time"> & {
date: string | number | Date;
format?: string;
className?: string;
};
const Time = ({ date, format = "MMM D", className }: TimeProps) => {
const Time = ({ date, format = "MMM D", ...rest }: TimeProps) => {
return (
<time dateTime={formatDate(date)} title={formatDate(date, "MMM D, YYYY, h:mm A z")} className={className}>
<time dateTime={formatDate(date)} title={formatDate(date, "MMM D, YYYY, h:mm A z")} {...rest}>
{formatDate(date, format)}
</time>
);