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

@dbosoft/web-productdata

v0.1.0

Published

Product metadata utility for dbosoft next.js websites

Downloads

14

Readme

@dbosoft/platform-product-meta

This package contains helpers for accessing Product related metadata. This is specifically helpful with theme color overrides.

interface ProductMeta {
  name: string
  slug: string
  themeClass?: string // a class that resets `brand` css variables
}

The following are available functions and components for use:

  • useProductMeta: A hook for accessing Product Metadata
  • ProductMetaProvider: A provider component that sets the product for all child consumers.
  • withProductMeta: A Higher Order Component that passes Product Metadata as the product prop — helpful with class components.

useProductMeta

This function is designed to work both within and outside of a Product Context. Components can pass a product name directly and get metadata outside of context, or they can set the 'product' higher up in the tree via ProductProvider, call useProductMeta without passing a product argument, context will provide the correct metadata.

useProductMeta(product?: Products): ProductMeta

type Products =
  | 'dbosoft'
  | 'maxback'
  | 'eryph'
  | 'erp'

Defaults

If useProductMeta is passed undefined or a non-product string, the values will default to:

{
  name: 'dbosoft',
  slug: 'dbosoft',
  // themeClass is undefined, defaults to HC brand colors
}

Examples:

Consuming metadata by passing product directly (not within context)

export default function Content({ content, product }) {
  const { name, themeClass } = useProductMeta(product)

  return (
    <article className={`${themeClass || ''} `}>
      <h1>{name}</h1>
      {content}
    </article>
  )
}

ProductMetaProvider

Accessing metadata from a product set by a provider:

export default function SomeParent({ children }) {
  return (
    <ProductMetaProvider product="terraform">
      //... renders `Content` further down the tree
    </ProductMetaProvider>
  )
}

function Content({ content }) {
  const { name, theme } = useProductMeta()

  return (
    <article className={`${themeClass ?? ''} `}>
      <h1>{name}</h1>
      {content}
    </article>
  )
}

In this usecase, the child components don't need a product prop, because it is set within the parent context.

withProductMeta

Using the withProductMeta HOC to pass down product metadata.

class Content extends Component {
  constructor(props) {
    super(props)
  }

  render() {
    const { name, themeClass } = this.props.product

    return (
      <article className={`${themeClass ?? ''} `}>
        <h1>{name}</h1>
        {content}
      </article>
    )
  }
}

export default withProductMeta(Content)

Resetting Product Theme Variables

The final client usecase in Markdown or on a page for this Content component could look like:

<Content product="terraform" content="LoremIpsum">

And say the corresponding CSS is:

h1 {
  color: var(--brand);
}

This --brand value will be overridden to be --terraform purple.