Skip to content

Commit

Permalink
use mobile/desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
tlgimenes committed Feb 29, 2024
1 parent 27bf368 commit f86704e
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 86 deletions.
10 changes: 9 additions & 1 deletion components/header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { AppContext } from "$store/apps/site.ts";
import type { Props as SearchbarProps } from "$store/components/search/Searchbar.tsx";
import Drawers from "$store/islands/Header/Drawers.tsx";
import { usePlatform } from "$store/sdk/usePlatform.tsx";
import type { ImageWidget } from "apps/admin/widgets.ts";
import type { SiteNavigationElement } from "apps/commerce/types.ts";
import type { SectionProps } from "deco/types.ts";
import Alert from "./Alert.tsx";
import Navbar from "./Navbar.tsx";
import { headerHeight } from "./constants.ts";
Expand Down Expand Up @@ -74,7 +76,8 @@ function Header({
},
logoPosition = "center",
buttons,
}: Props) {
device,
}: SectionProps<typeof loader>) {
const platform = usePlatform();
const items = navItems ?? [];

Expand All @@ -89,6 +92,7 @@ function Header({
<div class="bg-base-100 fixed w-full z-50">
{alerts && alerts.length > 0 && <Alert alerts={alerts} />}
<Navbar
device={device}
items={items}
searchbar={searchbar && { ...searchbar, platform }}
logo={logo}
Expand All @@ -102,4 +106,8 @@ function Header({
);
}

export const loader = (props: Props, req: Request, ctx: AppContext) => {
return { ...props, device: ctx.device };
};

export default Header;
171 changes: 86 additions & 85 deletions components/header/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@ import NavItem from "./NavItem.tsx";
import { navbarHeight } from "./constants.ts";
import { Buttons, Logo } from "$store/components/header/Header.tsx";

function Navbar({ items, searchbar, logo, buttons, logoPosition = "left" }: {
items: SiteNavigationElement[];
searchbar?: SearchbarProps;
logo?: Logo;
buttons?: Buttons;
logoPosition?: "left" | "center";
}) {
function Navbar(
{ items, searchbar, logo, buttons, logoPosition = "left", device }: {
items: SiteNavigationElement[];
searchbar?: SearchbarProps;
logo?: Logo;
buttons?: Buttons;
logoPosition?: "left" | "center";
device: "mobile" | "desktop" | "tablet";
},
) {
const platform = usePlatform();

return (
<>
{/* Mobile Version */}
if (device === "mobile") {
return (
<div
style={{ height: navbarHeight }}
class="lg:hidden grid grid-cols-3 justify-between items-center border-b border-base-200 w-full px-6 pb-6 gap-2"
Expand Down Expand Up @@ -58,86 +60,85 @@ function Navbar({ items, searchbar, logo, buttons, logoPosition = "left" }: {
{platform === "nuvemshop" && <CartButtonNuvemshop />}
</div>
</div>
);
}

{/* Desktop Version */}
<div class="hidden lg:grid lg:grid-cols-3 items-center border-b border-base-200 w-full px-6">
<ul
class={`flex gap-6 col-span-1 ${
logoPosition === "left" ? "justify-center" : "justify-start"
}`}
>
{items.map((item) => <NavItem item={item} />)}
</ul>
<div
class={`flex ${
logoPosition === "left"
? "justify-start -order-1"
: "justify-center"
}`}
>
{logo && (
<a
href="/"
aria-label="Store logo"
class="block"
>
<Image
src={logo.src}
alt={logo.alt}
width={logo.width || 100}
height={logo.height || 13}
/>
</a>
)}
</div>
<div class="flex-none flex items-center justify-end gap-6 col-span-1">
{!buttons?.hideSearchButton && (
<div class="flex items-center text-xs font-thin gap-1">
<SearchButton />SEARCH
</div>
)}
return (
<div class="hidden lg:grid lg:grid-cols-3 items-center border-b border-base-200 w-full px-6">
<ul
class={`flex gap-6 col-span-1 ${
logoPosition === "left" ? "justify-center" : "justify-start"
}`}
>
{items.map((item) => <NavItem item={item} />)}
</ul>
<div
class={`flex ${
logoPosition === "left" ? "justify-start -order-1" : "justify-center"
}`}
>
{logo && (
<a
href="/"
aria-label="Store logo"
class="block"
>
<Image
src={logo.src}
alt={logo.alt}
width={logo.width || 100}
height={logo.height || 13}
/>
</a>
)}
</div>
<div class="flex-none flex items-center justify-end gap-6 col-span-1">
{!buttons?.hideSearchButton && (
<div class="flex items-center text-xs font-thin gap-1">
<SearchButton />SEARCH
</div>
)}

<Searchbar searchbar={searchbar} />
{!buttons?.hideAccountButton && (
<a
class="flex items-center text-xs font-thin"
href="/account"
aria-label="Account"
>
<div class="flex btn btn-circle btn-sm btn-ghost gap-1">
<Icon id="User" size={20} strokeWidth={0.4} />
</div>
ACCOUNT
</a>
)}
{!buttons?.hideWishlistButton && (
<a
class="flex items-center text-xs font-thin"
href="/wishlist"
<Searchbar searchbar={searchbar} />
{!buttons?.hideAccountButton && (
<a
class="flex items-center text-xs font-thin"
href="/account"
aria-label="Account"
>
<div class="flex btn btn-circle btn-sm btn-ghost gap-1">
<Icon id="User" size={20} strokeWidth={0.4} />
</div>
ACCOUNT
</a>
)}
{!buttons?.hideWishlistButton && (
<a
class="flex items-center text-xs font-thin"
href="/wishlist"
aria-label="Wishlist"
>
<button
class="flex btn btn-circle btn-sm btn-ghost gap-1"
aria-label="Wishlist"
>
<button
class="flex btn btn-circle btn-sm btn-ghost gap-1"
aria-label="Wishlist"
>
<Icon id="Heart" size={24} strokeWidth={0.4} />
</button>
WISHLIST
</a>
)}
{!buttons?.hideCartButton && (
<div class="flex items-center text-xs font-thin">
{platform === "vtex" && <CartButtonVTEX />}
{platform === "vnda" && <CartButtonVDNA />}
{platform === "wake" && <CartButtonWake />}
{platform === "linx" && <CartButtonLinx />}
{platform === "shopify" && <CartButtonShopify />}
{platform === "nuvemshop" && <CartButtonNuvemshop />}
</div>
)}
</div>
<Icon id="Heart" size={24} strokeWidth={0.4} />
</button>
WISHLIST
</a>
)}
{!buttons?.hideCartButton && (
<div class="flex items-center text-xs font-thin">
{platform === "vtex" && <CartButtonVTEX />}
{platform === "vnda" && <CartButtonVDNA />}
{platform === "wake" && <CartButtonWake />}
{platform === "linx" && <CartButtonLinx />}
{platform === "shopify" && <CartButtonShopify />}
{platform === "nuvemshop" && <CartButtonNuvemshop />}
</div>
)}
</div>
</>
</div>
);
}

Expand Down

3 comments on commit f86704e

@deno-deploy
Copy link
Contributor

@deno-deploy deno-deploy bot commented on f86704e Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to deploy:

500: Internal Server Error (INTERNAL_SERVER_ERROR_3)

An error has occurred inside of a Deno Deploy system (code 3).

@deno-deploy
Copy link
Contributor

@deno-deploy deno-deploy bot commented on f86704e Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to deploy:

REQUEST_TIMED_OUT

@deno-deploy
Copy link
Contributor

@deno-deploy deno-deploy bot commented on f86704e Feb 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failed to deploy:

TIME_LIMIT

Please sign in to comment.