Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: split mobile/desktop #151

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
174 changes: 89 additions & 85 deletions components/header/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,22 @@ 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";
}) {
// Make it sure to render it on the server only. DO NOT render it on an island
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 */}
// Mobile header
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 +62,86 @@ 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>
)}
// Desktop header
return (
<div class="hidden sm:grid sm: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
2 changes: 1 addition & 1 deletion sections/Header/Header.tsx
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { default } from "$store/components/header/Header.tsx";
export { default, loader } from "$store/components/header/Header.tsx";
Loading