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

ladle-inject-custom-addons

v0.2.0

Published

Adds a button to the Ladle addon bar

Downloads

1,403

Readme

ladle-inject-custom-addons

Ladle doesn't officially support third party addons yet. Now we can pretend it does!

Quick Start

Installation

pnpm add ladle-inject-custom-addons

Note Replace pnpm with yarn or npm to match what you use for your project. 😉

Basic Usage

Add your custom button components to your global provider. You'll use the provided AddonButton components to make buttons that match the existing Ladle addon bar buttons.

// .ladle/components.tsx

import type { GlobalProvider } from "@ladle/react"
import {
  AddonButton,
  AddonDialogButton,
  ExampleLadleIcon,
} from "ladle-inject-custom-addons"

export const Provider: GlobalProvider = ({ children }) => (
  <>
    <HelloAddon />
    <DialogExampleAddon />
    {children}
  </>
)

const HelloAddon = () => (
  <AddonButton
    icon={<ExampleLadleIcon />}
    onClick={() => alert("hello!")}
    tooltip="Shows an alert to say hello."
  />
)

const DialogExampleAddon = () => (
  <AddonDialogButton icon={<ExampleLadleIcon />} tooltip="Opens a dialog box.">
    <p>Custom text, or more advanced components, will show up in a dialog.</p>
  </AddonDialogButton>
)

Customization

Icons

Most icon libraries will work for your addon buttons. Check out react-feather if you're not sure where to start!

You can also add your own SVGs for your icons. Use currentColor for the stroke or fill on the icon to have it use the default hover and active colors. The icons are expected to be 24 by 24 pixels in size.

const MyIcon = () => (
  <svg
    width={24}
    height={24}
    strokeWidth={2}
    viewport="0 0 24 24"
    stroke="currentcolor"
  >
    <ellipse cx="12" cy="12" rx="10" ry="10" />
  </svg>
)

Button order

If you would like to put your custom addons at a different place in the list, you can pass the position property.

// .ladle/components.tsx

export const Provider = ({ children }) => (
  <>
    <AddonButton
      icon={<ExampleLadleIcon />}
      onClick={() => alert("hello!")}
      tooltip="Shows an alert to say hello."
      // This button will be third in the addon panel list:
      position={3}
    />
    {children}
  </>
)

How this package works

AddonButton utilizes a React Portal to mount your buttons within the existing Ladle addon list.

Warning This method of injecting components may not be very stable. Changes to the Ladle package could easily break this in future updates.

Questions or contributions

Feel free to create a new issue if you run into any problems using this package!

Contributions are also welcome. I recommend opening an issue before starting work on your addition, just mention that you're working on an addition or fix.

🫶🏻 Thanks for reading!