Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
Saleor 6298/footer tailwind theme (saleor#179)
Browse files Browse the repository at this point in the history
* Taliwnd config and <Box /> component

* Added footer menu query and refactor max-w to container

* Code review fixes

* Removed unused comment line and import

* Removed null return in footer
  • Loading branch information
adrian-potepa authored Apr 25, 2022
1 parent 3e9ff1f commit 918f913
Show file tree
Hide file tree
Showing 27 changed files with 332 additions and 64 deletions.
2 changes: 1 addition & 1 deletion components/AccountLayout/AccountLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function AccountLayout({ children }: AccountLayoutProps) {
return (
<Layout>
<div className="py-10">
<main className="flex flex-col md:flex-row max-w-7xl mx-auto px-8">
<main className="flex flex-col md:flex-row container px-8">
<div className="mb-2 flex-initial md:w-3/5">
<NavigationPanel />
</div>
Expand Down
11 changes: 11 additions & 0 deletions components/Box/Box.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.box {
@apply bg-white border-2 border-main shadow-decorative-center sm:shadow-decorative;
padding: calc(theme("spacing.10") - theme("borderWidth.2"))
calc(theme("spacing.6") - theme("borderWidth.2"));
}

@screen sm {
.box {
padding: calc(theme("spacing.10") - theme("borderWidth.2"));
}
}
14 changes: 14 additions & 0 deletions components/Box/Box.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import clsx from "clsx";
import { HTMLAttributes } from "react";

import styles from "./Box.module.css";

export interface BoxProps extends HTMLAttributes<HTMLDivElement> {
shadowless?: boolean;
}

export function Box({ className, ...rest }: BoxProps) {
return <div className={clsx(styles.box, className)} {...rest} />;
}

export default Box;
3 changes: 3 additions & 0 deletions components/Box/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export type { BoxProps } from "./Box";
export { Box } from "./Box";
export { default } from "./Box";
25 changes: 25 additions & 0 deletions components/Footer/Footer.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.footer {
@apply sm:container mb-18 sm:mb-15 mt-16;
}

.footer-inner {
@apply px-6 border-l-0 border-r-0 sm:border-l-2 sm:border-r-2;
}

@screen sm {
.footer-inner {
padding: calc(theme("spacing.10") - theme("borderWidth.2"));
}
}

.menu {
@apply list-none mb-8;
}

.menu li + li {
@apply mt-2;
}

.menu-link {
@apply text-base cursor-pointer hover:underline;
}
73 changes: 73 additions & 0 deletions components/Footer/Footer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import clsx from "clsx";
import Image from "next/image";
import Link from "next/link";
import { HTMLAttributes } from "react";

import { getLinkPath } from "@/lib/menus";
import { usePaths } from "@/lib/paths";
import { useFooterMenuQuery } from "@/saleor/api";

import { Box } from "../Box";
import { useRegions } from "../RegionsProvider";
import styles from "./Footer.module.css";

export type FooterProps = HTMLAttributes<HTMLElement>;

export function Footer({ className, ...rest }: FooterProps) {
const paths = usePaths();
const { query, currentChannel, currentLocale } = useRegions();

const { data, error } = useFooterMenuQuery({ variables: { ...query } });

if (error) {
console.error("Footer component error", error.message);
}

const menu = data?.menu?.items || [];

return (
<footer className={clsx(styles.footer, className)} {...rest}>
<Box className={styles["footer-inner"]}>
<div className="flex mb-14 sm:mb-10">
<Link href={paths.$url()} passHref>
<a href="pass" className="hidden sm:inline-block">
<div className="mt-px group block h-16 w-28 relative grayscale">
<Image src="/saleor.svg" alt="Saleor logo" layout="fill" />
</div>
</a>
</Link>
<div className="grid grid-cols-2 gap-[2rem] w-full sm:w-auto sm:flex sm:flex-wrap sm:justify-end sm:ml-auto">
{menu.map((item) => (
<div className="sm:ml-14" key={item?.id}>
<Link href={getLinkPath(item!, currentChannel.slug, currentLocale)} passHref>
<a
href="pass"
className="block text-md font-bold mb-4 cursor-pointer hover:underline"
>
{item?.name}
</a>
</Link>
<ul className={styles.menu}>
{item?.children?.map((sub) => (
<li key={sub?.id}>
<Link href={getLinkPath(sub!, currentChannel.slug, currentLocale)} passHref>
<a href="pass" className={styles["menu-link"]}>
{sub?.name}
</a>
</Link>
</li>
))}
</ul>
</div>
))}
</div>
</div>
<p className="text-sm text-main-3">
© Copyright 2018 - {new Date().getFullYear()} Saleor Commerce
</p>
</Box>
</footer>
);
}

export default Footer;
2 changes: 2 additions & 0 deletions components/Footer/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./Footer";
export { default } from "./Footer";
6 changes: 3 additions & 3 deletions components/Layout/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Footer } from "../Footer";
import { Navbar } from "../Navbar";

export interface LayoutProps {
Expand All @@ -8,9 +9,8 @@ export function Layout({ children }: LayoutProps) {
return (
<>
<Navbar />
<div className="min-h-screen bg-gray-100 align-middle flex flex-col flex-grow">
{children}
</div>
<div className="align-middle flex flex-col flex-grow">{children}</div>
<Footer />
</>
);
}
Expand Down
24 changes: 7 additions & 17 deletions components/MainMenu/MainMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@ import clsx from "clsx";
import Link from "next/link";
import React from "react";

import { getLinkPath } from "@/lib/menus";
import { translate } from "@/lib/translations";
import { notNullable } from "@/lib/util";
import { MenuItemFragment, useMainMenuQuery } from "@/saleor/api";
import { useMainMenuQuery } from "@/saleor/api";

import { usePaths } from "../../lib/paths";
import { HamburgerButton } from "../HamburgerButton";
import { useRegions } from "../RegionsProvider";

export function MainMenu() {
const paths = usePaths();
const { query } = useRegions();
const { query, currentChannel, currentLocale } = useRegions();

const { loading, error, data } = useMainMenuQuery({
variables: { ...query },
Expand All @@ -38,18 +37,6 @@ export function MainMenu() {
return null;
}
const menu = data?.menu?.items || [];
const menuLink = (item: MenuItemFragment) => {
if (item.category) {
return paths.category._slug(item.category?.slug).$url();
}
if (item.collection) {
return paths.collection._slug(item.collection?.slug).$url();
}
if (item.page) {
return paths.page._slug(item.page?.slug).$url();
}
return paths.$url();
};

return (
<div className="group relative justify-center flex flex-col">
Expand Down Expand Up @@ -77,7 +64,10 @@ export function MainMenu() {
}
return (
<li key={child.id}>
<Link href={menuLink(child)} passHref>
<Link
href={getLinkPath(child, currentChannel.slug, currentLocale)}
passHref
>
<a
onClick={() => setOpenDropdown(false)}
href="pass"
Expand Down
2 changes: 1 addition & 1 deletion components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function Navbar() {
return (
<>
<div className="bg-white shadow-sm">
<div className="max-w-7xl mx-auto px-4">
<div className="container">
<div className="flex justify-between h-16">
<div className="flex justify-between items-center">
<MainMenu />
Expand Down
2 changes: 2 additions & 0 deletions components/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
export { AccountLayout } from "./AccountLayout";
export { AddressBookCard } from "./AddressBookCard";
export { Box } from "./Box";
export { CartSummary } from "./CartSummary";
export { CheckoutForm } from "./checkout/CheckoutForm";
export { SavedAddressSelectionList } from "./checkout/SavedAddressSelectionList";
export { CheckoutPriceEntry } from "./checkout/sidebar/CheckoutPriceEntry";
export { CheckoutProductList } from "./checkout/sidebar/CheckoutProductList";
export { CheckoutSidebar } from "./checkout/sidebar/CheckoutSidebar";
export { CheckoutLineItem } from "./CheckoutLineItem";
export { Footer } from "./Footer";
export { HomepageBlock } from "./HomepageBlock";
export { Layout } from "./Layout";
export { Navbar } from "./Navbar";
Expand Down
18 changes: 9 additions & 9 deletions graphql.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -9444,7 +9444,7 @@
"inputFields": [
{
"name": "channel",
"description": "Specifies the channel in which to sort the data.\n\nDEPRECATED: this field will be removed in Saleor 4.0. Use root-level channel argument instead.",
"description": "Specifies the channel in which to sort the data. \n\nDEPRECATED: this field will be removed in Saleor 4.0. Use root-level channel argument instead.",
"type": {
"kind": "SCALAR",
"name": "String",
Expand Down Expand Up @@ -15009,7 +15009,7 @@
"inputFields": [
{
"name": "channel",
"description": "Specifies the channel in which to sort the data.\n\nDEPRECATED: this field will be removed in Saleor 4.0. Use root-level channel argument instead.",
"description": "Specifies the channel in which to sort the data. \n\nDEPRECATED: this field will be removed in Saleor 4.0. Use root-level channel argument instead.",
"type": {
"kind": "SCALAR",
"name": "String",
Expand Down Expand Up @@ -39526,7 +39526,7 @@
},
{
"name": "input",
"description": "Input for External Notification Trigger.",
"description": "Input for External Notification Trigger. ",
"type": {
"kind": "NON_NULL",
"name": null,
Expand Down Expand Up @@ -44967,7 +44967,7 @@
"args": [
{
"name": "id",
"description": "ShippingMethodType ID or ShippingMethodTranslatableContent ID.",
"description": "('ShippingMethodType ID or ShippingMethodTranslatableContent ID.',)",
"type": {
"kind": "NON_NULL",
"name": null,
Expand Down Expand Up @@ -54426,7 +54426,7 @@
},
{
"name": "page",
"description": "A static page that can be manually added by a shop operator through the dashboard.",
"description": "('A static page that can be manually added by a shop operator ', 'through the dashboard.')",
"args": [],
"type": {
"kind": "OBJECT",
Expand Down Expand Up @@ -58947,7 +58947,7 @@
},
{
"name": "availableForPurchase",
"description": "Date when product is available for purchase.",
"description": "Date when product is available for purchase. ",
"args": [],
"type": {
"kind": "SCALAR",
Expand Down Expand Up @@ -62327,7 +62327,7 @@
},
{
"name": "channel",
"description": "Specifies the channel in which to sort the data.\n\nDEPRECATED: this field will be removed in Saleor 4.0. Use root-level channel argument instead.",
"description": "Specifies the channel in which to sort the data. \n\nDEPRECATED: this field will be removed in Saleor 4.0. Use root-level channel argument instead.",
"type": {
"kind": "SCALAR",
"name": "String",
Expand Down Expand Up @@ -72903,7 +72903,7 @@
"inputFields": [
{
"name": "channel",
"description": "Specifies the channel in which to sort the data.\n\nDEPRECATED: this field will be removed in Saleor 4.0. Use root-level channel argument instead.",
"description": "Specifies the channel in which to sort the data. \n\nDEPRECATED: this field will be removed in Saleor 4.0. Use root-level channel argument instead.",
"type": {
"kind": "SCALAR",
"name": "String",
Expand Down Expand Up @@ -83947,7 +83947,7 @@
"inputFields": [
{
"name": "channel",
"description": "Specifies the channel in which to sort the data.\n\nDEPRECATED: this field will be removed in Saleor 4.0. Use root-level channel argument instead.",
"description": "Specifies the channel in which to sort the data. \n\nDEPRECATED: this field will be removed in Saleor 4.0. Use root-level channel argument instead.",
"type": {
"kind": "SCALAR",
"name": "String",
Expand Down
11 changes: 11 additions & 0 deletions graphql/queries/FooterMenu.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
query FooterMenu($locale: LanguageCodeEnum!, $channel: String!) {
menu(slug: "footer", channel: $channel) {
id
items {
children {
...MenuItemFragment
}
...MenuItemFragment
}
}
}
19 changes: 19 additions & 0 deletions lib/menus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { pagesPath } from "@/lib/$path";
import { MenuItemFragment } from "@/saleor/api";

export const getLinkPath = (item: MenuItemFragment, channel: string, locale: string) => {
const paths = pagesPath._channel(channel)._locale(locale);

if (item.category) {
return paths.category._slug(item.category?.slug).$url();
}
if (item.collection) {
return paths.collection._slug(item.collection?.slug).$url();
}
if (item.page) {
return paths.page._slug(item.page?.slug).$url();
}
return paths.$url();
};

export default getLinkPath;
4 changes: 2 additions & 2 deletions pages/404.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ function Custom404() {

<div className="py-10">
<header className="mb-4">
<div className="max-w-7xl mx-auto px-8">Page not found</div>
<div className="container px-8">Page not found</div>
</header>
<main>
<div className="max-w-7xl mx-auto px-8">
<div className="container px-8">
<Link href={paths.$url()} passHref>
<a href="pass">Go back home</a>
</Link>
Expand Down
4 changes: 2 additions & 2 deletions pages/[channel]/[locale]/cart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function Cart() {

<div className="py-10">
<header className="mb-4">
<div className="max-w-7xl mx-auto px-8">
<div className="container px-8">
<div className="flex justify-between">
<h1 className="text-3xl font-extrabold tracking-tight text-gray-900">
{t.formatMessage(messages.cartPageHeader)}
Expand All @@ -40,7 +40,7 @@ function Cart() {
</div>
</header>
<main>
<div className="grid grid-cols-1 md:grid-cols-3 gap-8 max-w-7xl mx-auto px-8">
<div className="grid grid-cols-1 md:grid-cols-3 gap-8 container px-8">
<section className="col-span-2">
<ul className="divide-y divide-gray-200">
{isCheckoutLoading ? (
Expand Down
4 changes: 2 additions & 2 deletions pages/[channel]/[locale]/category/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ function CategoryPage({ category }: InferGetStaticPropsType<typeof getStaticProp
<>
<CategoryPageSeo category={category} />
<header className="mb-4 pt-4">
<div className="max-w-7xl mx-auto px-8">
<div className="container px-8">
<PageHero entity={category} />
</div>
</header>
<main>
<div className="max-w-7xl mx-auto px-8">
<div className="container px-8">
<ProductCollection filter={{ categories: [category?.id] }} />
</div>
</main>
Expand Down
Loading

0 comments on commit 918f913

Please sign in to comment.