npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-swiper-sidenav

v1.1.9

Published

react-swiper-sidenav is a React component for creating responsive, swipeable side navigation menus. It allows you to display submenus in a way that the component slides forward, and you can go back to the previous parent menu by sliding backward with a sm

Downloads

42

Readme

react-swiper-sidenav

react-swiper-sidenav is a React component for creating responsive, swipeable side navigation menus. It allows you to display submenus in a way that the component slides forward, and you can go back to the previous parent menu by sliding backward with a smooth animation. You can also customize the style of the component by passing a style object or using CSS classes.

Installation

To install react-swiper-sidenav, you can use npm or yarn:

npm install react-swiper-sidenav
# or
yarn add react-swiper-sidenav

Usage

To use react-swiper-sidenav, you need to import the SideNav component and pass it an object of type NavItems that defines the structure of your menus. You also need to provide an onClose function that handles the closing of the side navigation. Optionally, you can customize the appearance and behavior of the component by passing other props such as open, placement, zIndex, navProps, variant, etc. Here is an example of usage:

import { SideNav, NavItems } from 'react-swiper-sidenav';
import { Link } from "react-router-dom";

type CustomLinkProps = {
  to: string;
  label?: string;
};

const CustomLink = ({ to, label }: CustomLinkProps) => {
  return <Link to={to}>{label}</Link>;
};

const navItems: NavItems = {
  name: "Main",
  childrenItems: [
    {
      name: "Computers",
      childrenItems: [
        {
          name: "Desktops",
          childrenItems: [
            {
              itemProps: {
                to: "/gaming",
                label: "Gaming",
              },
            },
            {
              itemProps: {
                to: "/workstations",
                label: "Workstations",
              },
            },
            {
              itemProps: {
                to: "/all-in-one",
                label: "All-in-One",
              },
            },
          ],
        },
      ],
    },
  ],
};

function App() {
  return (
    <SideNav
      navItems={navItems}
      open={open}
      onClose={onClose}
      renderLink={CustomLink}
    />
  )
}

Live demo

You can see a live demo of the component here: live demo.

Props

The SideNav component accepts the following props:

| Name | Type | Default | Description | | ---------------- | --------------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | navItems | NavItems | required | An object that defines the structure of the menus. The object can have the following properties: name, childrenItems, itemProps, renderItem, disableClose, className, classes. Where childrenItems is an array of NavItems. See the Types section for more details. | | onClose | () => void | required | A function that handles the closing of the side navigation. | | open | boolean | false | A boolean value that indicates whether the side navigation is open or not. | | zIndex | number | 500 | A number that specifies the z-index of the side navigation. | | children | React.ReactNode | null | A React node that can be rendered inside the side navigation. | | placement | Placement | 'left' | A string that specifies the placement of the side navigation. It can be either 'left' or 'right'. | | hideBackdrop | boolean | false | A boolean value that indicates whether to hide the backdrop behind the side navigation or not. | | variant | Variant | 'temporary' | A string that specifies the variant of the side navigation. It can be either 'temporary' or 'permanent'. The temporary variant will close the side navigation when the backdrop is clicked, while the permanent variant will keep it open. | | style | React.CSSProperties | {} | A style object that can be applied to the side navigation container. | | navProps | React.HTMLAttributes | {} | An object that can be passed as props to the side navigation element. | | spreadCssClasses | boolean | true | A boolean value that indicates whether to spread the css classes of the navItems to their children or not. | | renderLink | (props: any) => React.JSX.Element | undefined | A function that can be used to render a custom link component for the navItems. |

Types

The SideNav component uses the following types:

export type Classes = {
  container?: string
  back?: string
  head?: string
  items?: string
}

export type NavItems = {
  name?: string
  childrenItems?: NavItems[]
  itemProps?: React.AllHTMLAttributes<HTMLAnchorElement | HTMLButtonElement | HTMLLIElement> | any
  renderItem?: React.ReactNode
  disableClose?: boolean
  className?: string
  classes?: Classes
}

export type Variant = 'temporary' | 'permanent'
export type Placement = 'left' | 'right'

export interface ISideNavProps {
  navItems: NavItems
  onClose: () => void
  open?: boolean
  zIndex?: number
  children?: React.ReactNode
  placement?: Placement
  hideBackdrop?: boolean
  variant?: Variant
  style?: React.CSSProperties
  navProps?: React.HTMLAttributes<HTMLElement>
  spreadCssClasses?: boolean
  renderLink?: (props: any) => React.JSX.Element
}

NavItems

The type NavItems is an object that defines the structure of the menus. The object can have the following properties:

| Property | Type | Description | | ------------- | --------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | name | string | The name of the menu item. It will be displayed as a text or a link, depending on whether the item has children or not. | | childrenItems | NavItems[] | An array of objects that defines the submenus of the menu item. If the item has children, it will be displayed as a link that opens the submenus when clicked. | | itemProps | React.AllHTMLAttributes<HTMLAnchorElement | HTMLButtonElement | HTMLLIElement> | any | An object that can be passed as props to the menu item element. It can be any HTML attribute or a custom prop. | | renderItem | React.ReactNode | A React node that can be used to render a custom menu item. It will override the default rendering of the name and the itemProps. | | disableClose | boolean | A boolean value that indicates whether to disable the closing of the side navigation when the menu item is clicked or not. | | className | string | A string that specifies the CSS class name of the menu item. | | classes | Classes | An object that specifies the CSS class names of the menu item container, the back button, the head element, and the items element. See the Classes type for more details. |

License

ISC