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

@crave/farmblocks-sidenav

v3.2.9

Published

![Farmblocks logo](https://user-images.githubusercontent.com/7760/31051341-4d280118-a63c-11e7-9e8f-3b375ca8f9a0.png)

Downloads

17

Readme

Farmblocks logo

Farmblocks SideNav

A React Sidebar Navigation component

Table of Contents

Installation

npm install @crave/farmblocks-sidenav

or with yarn

yarn add @crave/farmblocks-sidenav

Usage

Basic example

import React from "react";
import { render } from "react-dom";
import SideNav from "@crave/farmblocks-sidenav";

const App = () => <SideNav render={() => <div>Sidebar Content</div>} />;

render(<App />, document.getElementById("root"));

Basic example with NavItem and PageWrapper

import React from "react";
import { render } from "react-dom";
import SideNav, { NavItem, PageWrapper } from "@crave/farmblocks-sidenav";

const App = () => (
  <>
    <SideNav
      render={() => (
        <>
          <NavItem active>Item 1 (active)</NavItem>
          <NavItem>Item 2</NavItem>
          <NavItem>Item 3</NavItem>
        </>
      )}
    />
    <PageWrapper expanded>
      <h1>Page Content</h1>
    </PageWrapper>
  </>
);

render(<App />, document.getElementById("root"));

Complete Example

import React from "react";
import { render } from "react-dom";
import SideNav, { NavItem, PageWrapper } from "@crave/farmblocks-sidenav";

const App = () => {
  const [expanded, { toggle, collapse }] = useToggle(false);
  const [selected, setSelected] = useState(tabs[0]);
  const tabs = ["purveyor", "order", "search", "meat"];
  const icons = {
    purveyor: <MdVendors />,
    order: <MdOrders />,
    search: <MdSearch />,
    meat: <LgMeats />,
  };

  return (
    <>
      <SideNav
        expanded={expanded}
        onToggle={toggle}
        onClose={collapse}
        render={props => (
          <>
            <NavHeader />
            {tabs.map(tab => (
              <NavItem
                key={tab}
                onClick={() => setSelected(tab)}
                active={tab === selected}
                icon={icons[tab]}
                {...props}
              >
                {tab}
              </NavItem>
            ))}
          </>
        )}
      />

      <PageWrapper expanded={expanded}>
        <LoremIpsumBlock />
      </PageWrapper>
    </>
  );
};

render(<App />, document.getElementById("root"));

To see these and more examples running, visit our storybook

API

SideNav

  • expanded (Boolean) = true

    Whether the sidebar is expanded or collapsed.

  • variant ("push" | "fullScreen" | "overlay") = "push"

    Style variant.

  • expandedWidth (String) = "270px"

    Width on expanded false state. (only applied on "push" || "overlay" variant)

  • collapsedWidth (String) = "56px"

    Width on expanded true state. (only applied on "push" variant)

  • onToggle (Function)

    Passing this prop will render a hamburguer button on the page top/left corner, that will trigger this function on click.

  • onClose (Function)

    Passing this prop will render a close button on the sidebar top/right corner when expanded. (only applied on "fullScreen" || "overlay" variant)

  • render (Function)

    Render the sidebar content, passing as args the following props: highlightColor, variant.

  • highlightColor (String) = farmblocks.theme.colors.RED_ORANGE

    Color used to highlight active/hover nav item and close button.

  • backgroundColor (String) = farmblocks.theme.colors.SUGAR

    Sidebar background color.

  • offsetTop (String) = "0"

    Top spacing gap.

  • zIndex (Number ) = 100

    The sidebar z-index

NavItem

  • active (Boolean)

    Whether the item is with active style or not.

  • variant ("push" | "fullScreen" | "overlay") = "push"

    On "fullScreen" variant set rounded style, the other ones don't affect this component.

  • children (Node)

    Text content.

  • highlightColor (String) = farmblocks.theme.colors.RED_ORANGE

    Color used to highlight active/hover items.

  • backgroundColor (String)

    NavItem background color.

  • icon (Node)

    Icon node (don't use icon prop along with image prop)

  • iconSize (String | Number)

    Font size for the icon

  • image (String)

    Image src url (don't use image prop along with icon prop)

  • imageProps (Object)

    Props for image component, accept any farmblocks-image prop

  • textProps (Object)

    Props for children(text) component, accept any farmblocks-text prop

Helpers

PageWrapper

Wrapper to help your page follow sidenav variants.

import React from "react";
import { render } from "react-dom";
import SideNav, {
  NavItem,
  PageWrapper,
  variants,
} from "@crave/farmblocks-sidenav";

const App = () => (
  <>
    <SideNav variant={variants.OVERLAY} expanded />
    <PageWrapper variant={variants.OVERLAY} expanded>
      <h1>Page Content</h1>
    </PageWrapper>
  </>
);

render(<App />, document.getElementById("root"));

API

  • expanded (Boolean) = false

    Whether the sidebar is expanded or collapsed.

  • variant ("push" | "fullScreen" | "overlay") = "push"

    Sidebar variant style.

  • expandedWidth (String) = "270px"

    Width on expanded false state. (only applied on "push" || "overlay" variant)

  • collapsedWidth (String) = "56px"

    Width on expanded true state. (only applied on "push" variant)

  • offsetTop (String) = "0"

    Top spacing gap.

  • overlayProps (Object)

    Props passed to overlay component

License

MIT