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

payload-admin-bar

v1.0.6

Published

An admin bar for React apps using Payload CMS

Downloads

35,934

Readme

Payload Admin Bar

An admin bar for React apps using Payload as a headless CMS.

Installation

$ npm i payload-admin-bar
$ # or
$ yarn add payload-admin-bar

Basic Usage

import { PayloadAdminBar } from "payload-admin-bar";

export const App = () => {
  return (
    <PayloadAdminBar
      cmsURL="https://cms.website.com"
      collection="pages"
      id="12345"
    />
  );
};

Checks for authentication with Payload CMS by hitting the /me route. If authenticated, renders an admin bar with simple controls to do the following:

  • Navigate to the admin dashboard
  • Navigate to the currently logged-in user's account
  • Edit the current collection
  • Create a new collection of the same type
  • Logout
  • Indicate and exit preview mode

The admin bar ships with very little style and is fully customizable.

Dynamic props

With client-side routing, we need to update the admin bar with a new collection type and document id on each route change. This will depend on your app's specific setup, but here are a some common examples:

NextJS

For NextJS apps using dynamic-routes, use getStaticProps:

export const getStaticProps = async ({ params: { slug } }) => {
  const props = {};

  const pageReq = await fetch(`https://cms.website.com/api/pages?where[slug][equals]=${slug}&depth=1`);
  const pageData = await pageReq.json();

  if (pageReq.ok) {
    const { docs } = pageData;
    const [doc] = docs;

    props = {
      ...doc,
      collection: 'pages',
      collectionLabels: {
        singular: 'page',
        plural: 'pages',
      }
    };
  }

  return props;
}

Now your app can forward these props onto the admin bar. Something like this:

import { PayloadAdminBar } from 'payload-admin-bar';

export const App = (appProps) => {
  const {
    pageProps: {
      collection,
      collectionLabels,
      id
    }
  } = appProps;

  return (
    <PayloadAdminBar
      {...{
        cmsURL: 'https://cms.website.com',
        collection,
        collectionLabels,
        id
      }}
    />
  )
}

Props

| Property | Type | Required | Default | Description | | ---------------- | ------------------------------------------------------------------------------------------------------------------------ | -------- | ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | | cmsURL | string | true | http://localhost:8000 | serverURL as defined in your Payload config | | adminPath | string | false | /admin | routes as defined in your Payload config | | apiPath | string | false | /api | routes as defined in your Payload config | | collection | string | true | undefined | Slug of your collection | | collectionLabels | { singular?: string, plural?: string } | false | undefined | Labels of your collection | | id | string | true | undefined | id of the document | | logo | ReactElement | false | undefined | Custom logo | | classNames | { logo?: string, user?: string, controls?: string, create?: string, logout?: string, edit?: string, preview?: string } | false | undefined | Custom class names, one for each rendered element | | logoProps | {[key: string]?: unknown} | false | undefined | Custom props | | userProps | {[key: string]?: unknown} | false | undefined | Custom props | | divProps | {[key: string]?: unknown} | false | undefined | Custom props | | createProps | {[key: string]?: unknown} | false | undefined | Custom props | | logoutProps | {[key: string]?: unknown} | false | undefined | Custom props | | editProps | {[key: string]?: unknown} | false | undefined | Custom props | | previewProps | {[key: string]?: unknown} | false | undefined | Custom props | | style | CSSProperties | false | undefined | Custom inline style | | unstyled | boolean | false | undefined | If true, renders no inline style | | onAuthChange | (user: PayloadMeUser) => void | false | undefined | Fired on each auth change | | devMode | boolean | false | undefined | If true, fakes authentication (useful when dealing with SameSite cookies) | | preview | boolean | false | undefined | If true, renders an exit button with your onPreviewExit handler) | | onPreviewExit | function | false | undefined | Callback for the preview button onClick event) |