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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@okam/directus-next-component

v2.1.6

Published

This library was generated with [Nx](https://nx.dev).

Readme

directus-next-component

This library was generated with Nx.

directusRouteMiddleware usage

Create a middleware.ts file in the project, in the /src/app directory of the next application, and add the following code to it.

// middleware.ts

import {
  directusRouteMiddleware,
  config as directusRouteMiddlewareConfig,
} from '@okam/directus-next-component/src/server'
import type { NextRequest } from 'next/server'

export function middleware(request: NextRequest) {
  const { locale } = request.nextUrl
  return directusRouteMiddleware(request, [locale])
}

export const config = {
  ...directusRouteMiddlewareConfig,
}

After, modify the next.config.js file to add withDirectus in the plugins.

useDirectusLink hook

The role of the directus link hook is to dispatch different props according to the type of the directus link. The configuration for the dispatching is overridable using the propsConfig prop

DirectusLink component

The role of the directus link component is to wrap next/link and dispatch the props to different components according to a configuration. The configuration for dispatching different components is overridable using the componentsConfig prop.

The directus link component uses the directus link hook, which means it can be passed both componentsConfig and propsConfig for both dispatching uses.

By default, the following are included:

  • collection: Render a link using a page_settings relation
  • anchor: Render a link pointing to an element's id on the page (always starts with #)
  • external-link: Render a link with an external URL (e.g.: https://google.com)
  • file: Render a link for a downloadable file

The mentionned configuration can be overwritten by passing a componentsConfig prop to the directus link component

const overrideConfig = {
  'external-link': (props) => <CustomExternalLinkComponent {...props} />
}

const BrandLink = (props) => {
  return <DirectusLink config={overrideConfig} {...props} />
}

useNavigationItems hook

The useNavigationItems hook allows to build recursively a navigation structure using the DirectusLink component.

The tokens passed to link and linkProps include also include, in order of priority:

  • The tokens passed from onNavigationItem
  • The variant of the navigation item, passed as the type token
  • The tokens of the navigation item

Props

Returned props of each parsed navigation item in the tree

  • link: A rendered react node of the DirectusLink component
  • linkProps: The props that were passed to the link
  • children: The navigation items containing link, linkProps, children
  • parent: A single navigation item containing link, linkProps, parent
  • depth: The current depth of the recursion. For each level of parent, the depth will go down by one. For each level of children, the depth will go up by one. The depth starts at zero

Example usage

// Any styling could go here
const depthMap: Record<number, object> = {
  0: { backgroundColor: 'red' },
  1: { backgroundColor: 'blue' },
  2: { backgroundColor: 'green' },
}

// Loop recursively through navigation items and assign style based on depth
function renderTree(tree: Nullable<TTNavigationItemsTree>): React.ReactNode {
  if (!tree) return null
  const { children, link, linkProps, depth } = tree
  const style = depthMap[depth]

  if (!link && !children) return null
  if (!children) {
    return (
      <li style={style} key={link.id}>
        {
          /*
           * Here, `link` represents a rendered version of `DirectusLink` for quick use
           * Use `linkProps` for custom rendering needs
           */
        }
        {link}
      </li>
    )
  }
  return (
    <ul key={link.id}>
      <li style={style}>{link}</li>
      {children.map((child) => renderTree(child))}
    </ul>
  )
}

const NavigationComponent = (props) => {
  // Depth and links type cannot be inferred directly, they must be passed
  const navigation = useNavigationItems<3, { link?: LinksFragment }>(
    props.navigationItems, 

    // Use `onNavigationItem` to parse the fragments
    (item) => {
      const { link } = item ?? {}
      const collection = getFragment(PageSettingsFragmentDoc, link?.collection)
      const file = getFragment(FilesFragmentDoc, link?.file)
      return {
        ...link,
        collection,
        file,
    }
  })

  return (
    <nav>
      {navigation.map((item) => renderTree(item))}
    </nav>
  )
}