Skip to content

Commit

Permalink
remove @radix-ui/react-icons & lazy load navbar components & load sch…
Browse files Browse the repository at this point in the history
…eherazade font only in reader
  • Loading branch information
ahmedriad1 committed Dec 27, 2024
1 parent 255652d commit 25ea473
Show file tree
Hide file tree
Showing 14 changed files with 67 additions and 68 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"@radix-ui/react-direction": "^1.0.1",
"@radix-ui/react-dropdown-menu": "^2.0.6",
"@radix-ui/react-hover-card": "^1.0.7",
"@radix-ui/react-icons": "^1.3.0",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-navigation-menu": "^1.1.4",
"@radix-ui/react-popover": "^1.0.7",
Expand Down
12 changes: 0 additions & 12 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 17 additions & 1 deletion src/app/[locale]/t/[bookId]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import Providers from "./providers";
import { cn } from "@/lib/utils";
import { Scheherazade_New } from "next/font/google";

const scheherazade = Scheherazade_New({
subsets: ["arabic"],
style: "normal",
variable: "--font-scheherazade",
weight: ["400", "700"],
});

function ReaderLayout({ children }: { children: React.ReactNode }) {
return (
<Providers>
<div className="max-h-screen overflow-hidden bg-reader">{children}</div>
<div
className={cn(
"max-h-screen overflow-hidden bg-reader",
scheherazade.variable,
)}
>
{children}
</div>
</Providers>
);
}
Expand Down
15 changes: 13 additions & 2 deletions src/app/_components/navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,26 @@ import {

import React, { useEffect, useState } from "react";
import { ThemeToggle } from "./theme-toggle";
import SearchBar from "./search-bar";
import { useNavbarStore } from "@/stores/navbar";
import { useReaderScroller } from "../../[locale]/t/[bookId]/_components/context";
import HomepageNavigationMenu from "./navigation-menu";

// import HomepageNavigationMenu from "./navigation-menu";
// import SearchBar from "./search-bar";

const SearchBar = dynamic(() => import("./search-bar"), {
ssr: false,
});

const HomepageNavigationMenu = dynamic(() => import("./navigation-menu"), {
ssr: false,
});

import LocaleSwitcher from "./locale-switcher";
import MobileMenu from "./mobile-menu";
import MobileNavigationMenu from "./mobile-navigation-menu";
import { useTranslations } from "next-intl";
import { useDirection } from "@/lib/locale/utils";
import dynamic from "next/dynamic";

interface NavbarProps {
layout?: "home" | "reader";
Expand Down
28 changes: 14 additions & 14 deletions src/components/ui/accordion/index.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"use client"
"use client";

import * as React from "react"
import * as AccordionPrimitive from "@radix-ui/react-accordion"
import { ChevronDownIcon } from "@radix-ui/react-icons"
import * as React from "react";
import * as AccordionPrimitive from "@radix-ui/react-accordion";

import { cn } from "@/lib/utils"
import { cn } from "@/lib/utils";
import { ChevronDownIcon } from "lucide-react";

const Accordion = AccordionPrimitive.Root
const Accordion = AccordionPrimitive.Root;

const AccordionItem = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Item>,
Expand All @@ -17,8 +17,8 @@ const AccordionItem = React.forwardRef<
className={cn("border-b", className)}
{...props}
/>
))
AccordionItem.displayName = "AccordionItem"
));
AccordionItem.displayName = "AccordionItem";

const AccordionTrigger = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Trigger>,
Expand All @@ -29,16 +29,16 @@ const AccordionTrigger = React.forwardRef<
ref={ref}
className={cn(
"flex flex-1 items-center justify-between py-4 text-sm font-medium transition-all hover:underline [&[data-state=open]>svg]:rotate-180",
className
className,
)}
{...props}
>
{children}
<ChevronDownIcon className="h-4 w-4 shrink-0 text-muted-foreground transition-transform duration-200" />
</AccordionPrimitive.Trigger>
</AccordionPrimitive.Header>
))
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName
));
AccordionTrigger.displayName = AccordionPrimitive.Trigger.displayName;

const AccordionContent = React.forwardRef<
React.ElementRef<typeof AccordionPrimitive.Content>,
Expand All @@ -51,7 +51,7 @@ const AccordionContent = React.forwardRef<
>
<div className={cn("pb-4 pt-0", className)}>{children}</div>
</AccordionPrimitive.Content>
))
AccordionContent.displayName = AccordionPrimitive.Content.displayName
));
AccordionContent.displayName = AccordionPrimitive.Content.displayName;

export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }
export { Accordion, AccordionItem, AccordionTrigger, AccordionContent };
4 changes: 2 additions & 2 deletions src/components/ui/command/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

import * as React from "react";
import { type DialogProps } from "@radix-ui/react-dialog";
import { MagnifyingGlassIcon } from "@radix-ui/react-icons";
import { Command as CommandPrimitive } from "cmdk";

import { cn } from "@/lib/utils";
import { Dialog, DialogContent } from "@/components/ui/dialog";
import Spinner from "../spinner";
import { SearchIcon } from "lucide-react";

const Command = React.forwardRef<
React.ElementRef<typeof CommandPrimitive>,
Expand Down Expand Up @@ -53,7 +53,7 @@ const CommandInput = React.forwardRef<
{isLoading ? (
<Spinner className="h-4 w-4 shrink-0" />
) : (
<MagnifyingGlassIcon className="h-4 w-4 shrink-0 opacity-50" />
<SearchIcon className="h-4 w-4 shrink-0 opacity-50" />
)}

<CommandPrimitive.Input
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import * as React from "react";
import * as DialogPrimitive from "@radix-ui/react-dialog";
import { Cross2Icon } from "@radix-ui/react-icons";

import { cn } from "@/lib/utils";
import { XIcon } from "lucide-react";

const Dialog = DialogPrimitive.Root;

Expand Down Expand Up @@ -51,7 +51,7 @@ const DialogContent = React.forwardRef<
>
{children}
<DialogPrimitive.Close className="absolute top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground ltr:right-4 rtl:left-4">
<Cross2Icon className="h-4 w-4" />
<XIcon className="h-4 w-4" />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
</DialogPrimitive.Content>
Expand Down
8 changes: 2 additions & 6 deletions src/components/ui/dropdown-menu/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,9 @@

import * as React from "react";
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
import {
CheckIcon,
ChevronRightIcon,
DotFilledIcon,
} from "@radix-ui/react-icons";

import { cn } from "@/lib/utils";
import { CheckIcon, ChevronRightIcon, DotIcon } from "lucide-react";

const DropdownMenu = DropdownMenuPrimitive.Root;

Expand Down Expand Up @@ -135,7 +131,7 @@ const DropdownMenuRadioItem = React.forwardRef<
>
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<DropdownMenuPrimitive.ItemIndicator>
<DotFilledIcon className="h-4 w-4 fill-current" />
<DotIcon className="h-4 w-4 fill-current" />
</DropdownMenuPrimitive.ItemIndicator>
</span>
{children}
Expand Down
2 changes: 1 addition & 1 deletion src/components/ui/navigation-menu.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as React from "react";
import { ChevronDownIcon } from "@radix-ui/react-icons";
import * as NavigationMenuPrimitive from "@radix-ui/react-navigation-menu";
import { cva } from "class-variance-authority";

import { cn } from "@/lib/utils";
import { ChevronDownIcon } from "lucide-react";

const NavigationMenu = React.forwardRef<
React.ElementRef<typeof NavigationMenuPrimitive.Root>,
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/resizable/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"use client";

import { DragHandleDots2Icon } from "@radix-ui/react-icons";
import * as ResizablePrimitive from "react-resizable-panels";

import { cn } from "@/lib/utils";
import { GripVerticalIcon } from "lucide-react";

const ResizablePanelGroup = ({
className,
Expand Down Expand Up @@ -36,7 +36,7 @@ const ResizableHandle = ({
>
{withHandle && (
<div className="z-10 flex h-4 w-3 items-center justify-center rounded-sm border bg-border">
<DragHandleDots2Icon className="h-2.5 w-2.5" />
<GripVerticalIcon className="h-2.5 w-2.5" />
</div>
)}
</ResizablePrimitive.PanelResizeHandle>
Expand Down
15 changes: 8 additions & 7 deletions src/components/ui/select/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
"use client";

import * as React from "react";
import {
CaretSortIcon,
CheckIcon,
ChevronDownIcon,
ChevronUpIcon,
} from "@radix-ui/react-icons";

import * as SelectPrimitive from "@radix-ui/react-select";

import { cn } from "@/lib/utils";
import Spinner from "../spinner";
import {
CheckIcon,
ChevronDownIcon,
ChevronUpIcon,
ChevronsUpDownIcon,
} from "lucide-react";

const Select = SelectPrimitive.Root;

Expand Down Expand Up @@ -54,7 +55,7 @@ const SelectTrigger = React.forwardRef<
{isLoading ? (
<Spinner className="h-4 w-4" />
) : (
icon ?? <CaretSortIcon className="h-4 w-4 opacity-50" />
icon ?? <ChevronsUpDownIcon className="h-4 w-4 opacity-50" />
)}
</div>
</SelectPrimitive.Icon>
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/sheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

import * as React from "react";
import * as SheetPrimitive from "@radix-ui/react-dialog";
import { Cross2Icon } from "@radix-ui/react-icons";
import { cva, type VariantProps } from "class-variance-authority";

import { cn } from "@/lib/utils";
import { XIcon } from "lucide-react";

const Sheet = SheetPrimitive.Root;

Expand Down Expand Up @@ -66,7 +66,7 @@ const SheetContent = React.forwardRef<
>
{children}
<SheetPrimitive.Close className="absolute top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-secondary ltr:left-4 rtl:right-4">
<Cross2Icon className="h-5 w-5" />
<XIcon className="h-5 w-5" />
<span className="sr-only">Close</span>
</SheetPrimitive.Close>
</SheetPrimitive.Content>
Expand Down
4 changes: 2 additions & 2 deletions src/components/ui/toast.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"use client";

import * as React from "react";
import { Cross2Icon } from "@radix-ui/react-icons";
import * as ToastPrimitives from "@radix-ui/react-toast";
import { cva, type VariantProps } from "class-variance-authority";

import { cn } from "@/lib/utils";
import { XIcon } from "lucide-react";

const ToastProvider = ToastPrimitives.Provider;

Expand Down Expand Up @@ -86,7 +86,7 @@ const ToastClose = React.forwardRef<
toast-close=""
{...props}
>
<Cross2Icon className="h-4 w-4" />
<XIcon className="h-4 w-4" />
</ToastPrimitives.Close>
));
ToastClose.displayName = ToastPrimitives.Close.displayName;
Expand Down
16 changes: 2 additions & 14 deletions src/lib/fonts.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import { Plus_Jakarta_Sans, Scheherazade_New } from "next/font/google";
import { Plus_Jakarta_Sans } from "next/font/google";
import localFont from "next/font/local";

const scheherazade = Scheherazade_New({
subsets: ["arabic"],
style: "normal",
variable: "--font-scheherazade",
weight: ["400", "700"],
});

const plusJakartaSans = Plus_Jakarta_Sans({
subsets: ["latin"],
style: "normal",
Expand Down Expand Up @@ -78,9 +71,4 @@ const ibmPlexSansArabic = localFont({
// });

export const getFontsClassnames = () =>
[
plusJakartaSans.variable,
ibmPlexSansArabic.variable,
scheherazade.variable,
// uthmanicHafs.variable,
].join(" ");
[plusJakartaSans.variable, ibmPlexSansArabic.variable].join(" ");

0 comments on commit 25ea473

Please sign in to comment.