Skip to content

Commit

Permalink
Better skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
leerob committed Nov 28, 2023
1 parent ac10d46 commit c42470a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions components/layout/navbar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Menu } from 'lib/shopify/types';
import Link from 'next/link';
import { Suspense } from 'react';
import MobileMenu from './mobile-menu';
import Search from './search';
import Search, { SearchSkeleton } from './search';
const { SITE_NAME } = process.env;

export default async function Navbar() {
Expand Down Expand Up @@ -43,7 +43,7 @@ export default async function Navbar() {
) : null}
</div>
<div className="hidden justify-center md:flex md:w-1/3">
<Suspense fallback={null}>
<Suspense fallback={<SearchSkeleton />}>
<Search />
</Suspense>
</div>
Expand Down
4 changes: 2 additions & 2 deletions components/layout/navbar/mobile-menu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Fragment, Suspense, useEffect, useState } from 'react';

import { Bars3Icon, XMarkIcon } from '@heroicons/react/24/outline';
import { Menu } from 'lib/shopify/types';
import Search from './search';
import Search, { SearchSkeleton } from './search';

export default function MobileMenu({ menu }: { menu: Menu[] }) {
const pathname = usePathname();
Expand Down Expand Up @@ -72,7 +72,7 @@ export default function MobileMenu({ menu }: { menu: Menu[] }) {
</button>

<div className="mb-4 w-full">
<Suspense fallback={null}>
<Suspense fallback={<SearchSkeleton />}>
<Search />
</Suspense>
</div>
Expand Down
14 changes: 14 additions & 0 deletions components/layout/navbar/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,17 @@ export default function Search() {
</form>
);
}

export function SearchSkeleton() {
return (
<form className="w-max-[550px] relative w-full lg:w-80 xl:w-full">
<input
placeholder="Search for products..."
className="w-full rounded-lg border bg-white px-4 py-2 text-sm text-black placeholder:text-neutral-500 dark:border-neutral-800 dark:bg-transparent dark:text-white dark:placeholder:text-neutral-400"
/>
<div className="absolute right-0 top-0 mr-3 flex h-full items-center">
<MagnifyingGlassIcon className="h-4" />
</div>
</form>
);
}

0 comments on commit c42470a

Please sign in to comment.