4.5.8 • Published 2 days ago

ssw.megamenu v4.5.8

Weekly downloads
-
License
-
Repository
-
Last release
2 days ago

How to use the Mega Menu

Installation

  1. Install package
npm install ssw.megamenu
yarn add ssw.megamenu
pnpm add ssw.megamenu
  1. Import the generated styles
import "ssw.megamenu/dist/style.css";

NOTE: If you have TailwindCSS installed in your project, you can instead list the ssw.megamenu package in your tailwind.config.js content array and add the SSW colors like so:

// tailwind.config.js

// ...

module.exports = {
  // ...
  content: [
    // ...
    "node_modules/ssw.megamenu/**/*.js",
  ],
  // ...
  theme: {
    extend: {
      colors: {
        ssw: {
          red: "#cc4141",
          light: {
            red: "#d26e6e",
          },
          gray: "#797979",
          black: "#333333",
        },
      },
    }
  }
};
  1. You can then use the components in your React app like so:
// CommonJS
const { Menu, MobileMenu, MenuBar } = require('ssw.megamenu');

// ESM
import { MegaMenuLayout } from 'ssw.megamenu';

Basic Usage

The ssw.megamenu NPM package provides you with the <MegaMenuLayout /> component, which can be used in both client-side and server-side rendered React apps.

Example:

import { MegaMenuLayout } from 'ssw.megamenu';

function App() {
  return (
    <MegaMenuLayout />
    /* {{ CONTENT_HERE }} */
  );
}

Usage with SSR

The <MegaMenuLayout /> component can be used with SSG (Static Site Generation) and SSR (Server Side Rendering) frameworks like Next.js and Gatsby. This is achieved by providing an optional prop in the <MegaMenuLayout /> component called menuBarItems, which is an array of objects that represent the menu bar items.

Example usage with SSR (Next.js):

import { MegaMenuLayout } from 'ssw.megamenu';

function App(props) {
  return (
    <MegaMenuLayout menuBarItems={props.menuBarItems} />
    /* {{ CONTENT_HERE }} */
  );
}

export function getStaticProps() {
  const menuItems = await getMenuItems();

  return {
    props: {
      menuItems,
    },
  };
}

Available Props

Prop NameTypeDescriptionRequired
menuBarItemsMenuBarItem[]An array of objects that represent the menu bar items provided by SSR or other data fetching mechanisms. If this prop isn't supplied, the component will fetch the data from the Next.js API route.No
titlestringThe title text displayed next to the SSW logo.Yes (If there is no tagline provided)
subtitlestringThe text displayed underneath the SSW logoNo
taglinestringThe text displayed next the SSW Logo.No
urlstringThe URL of the menu bar item.No
searchUrlstringThe absolute URL the search takes you to. If not provided, will default to the host address. i.e. for SSW <www.ssw.com.au>No
rightSideActionsOverride() => JSX.ElementThe component to replace the "Call Us" and search buttons that are displayed by default on the right side of the menu.No
linkComponentReact.FC<{ href: string; className?: string; title?: string; onClick?: () => void; children?: React.ReactNode;}>The component to use for the links in the menu. i.e. <Link> from next/link or gatsbyNo
callback(seachTerm: string) => voidCallback run on search. If provided, the search will not open a google tab.No

Testing

When using pnpm link on the SSW.Website project, we encountered some issues with using ssw.megamenu, so instead use file: in the package.json file to link the package like so:

{
  "dependencies": {
    "ssw.megamenu": "file:../SSW.MegaMenu"
  }
}

Replace ../SSW.MegaMenu with the path to the SSW.MegaMenu project on your local machine.

How to contribute?

In the project directory, you can run:

pnpm dev

Runs the app in the development mode.

Open http://localhost:5173 to view it in the browser.

The page will reload if you make edits.

pnpm build

Builds the lib for production to the dist folder.

How to publish?

  1. Important: Before to push your changes, you need to increment the version number in the file package.json using semver
  2. Make a pull request to add your code into the main branch.
  3. Get the pull request approved
  4. Merge your code into the main branch
  5. Publish a GitHub release with the same version number as the one you incremented in the file package.json at https://github.com/SSWConsulting/SSW.MegaMenu/releases
4.5.8

2 days ago

4.5.7

2 days ago

4.5.6

29 days ago

4.5.5

29 days ago

4.5.4

1 month ago

4.5.3

2 months ago

4.5.2

2 months ago

4.5.0

2 months ago

4.5.1

2 months ago

4.4.0

2 months ago

4.3.2

2 months ago

4.2.2

3 months ago

4.2.1

3 months ago

4.1.2

3 months ago

4.2.0

3 months ago

4.1.1

3 months ago

4.1.0

3 months ago

4.0.1

4 months ago

4.0.0

4 months ago

3.2.2

8 months ago

3.1.3

11 months ago

3.2.1

8 months ago

3.2.0

8 months ago

3.2.3

8 months ago

3.1.4

10 months ago

3.1.2

1 year ago

3.1.1

1 year ago

3.1.0

1 year ago

3.0.5

1 year ago

3.0.4

1 year ago

2.2.8-beta3

1 year ago

2.2.8-beta2

1 year ago

2.2.8-beta1

1 year ago

2.2.8

1 year ago

2.2.7

1 year ago

2.2.6

1 year ago

2.2.5

1 year ago