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

astro-custom-elements-docgen

v0.1.1

Published

An Astro integration to automatically generate documentation for your custom elements.- [Custom Elements Docgen (Astro Integration)](#custom-elements-docgen-astro-integration)

Downloads

3

Readme

Custom Elements Docgen (Astro Integration)

An Astro integration to automatically generate documentation for your custom elements.- Custom Elements Docgen (Astro Integration)

Installation

If you haven't created an Astro project yet, you can do so by following the official Astro documentation.

Once you've got your Astro project up and running, you can install the custom-elements-docgen package by running the following command:

npm install astro-custom-elements-docgen --save-dev

Jump over to your astro.config.mjs file and add the integration:

export default defineConfig({
  integrations: [
    customElementsDocgen({
      componentsDir: "../path-to-your-web-components-folder",
    }),
  ],
});

If you provide a link to your components directory, the integration will generate documentation for your custom elements.

The integration won't automatically generate examples. Instead you will need to create an adjacent "[component-name].examples.js" file to provide examples for your custom elements.

See providing examples for more information.

To see the integration in action, you can navigate to the example directory

Options

componentsDir (required)

type string

This sets the path to your web components directory.

astroComponents

type Record<string, string>

The integration automatically generates documentation for your custom elements. If you don't like the default appearance of the components, you can provide paths to your own components.

You can override the following components:

  • Layout
  • Head
  • Sidebar
  • Usage
  • Page
customElementsDocgen({
  astroComponents: {
    Layout: "./components/Layout.astro",
    Sidebar: "./components/Sidebar.astro",
    Usage: "./components/Usage.astro",
    Head: "./components/Head.astro",
    Page: "./components/Page.astro",
  },
});

Note: Head is a great place to import any styles or scripts you need for your components.

Every component receives the following props:

type AstroProps = {
    component: CustomElement
    navigation: {
      items: {
        label: string,
        slug: string
      }[],
    },
    usage: {
      tag: string,
      registerPaths: string,
      usages: {
        name: string;
        description: string;
        snippet: string;
      }[]
    }
}

type CustomElement is defined in the custom-elements-manifest schema.

Providing Examples

To provide examples for your custom elements, you will need to create an adjacent "[component-name].examples.js" file.

The file will export the examples in the following format:

type Example = {
  tag: string,
  registerPaths: string | string[],
  usages: {
    name: string;
    description: string;
    snippet: string;
  }[] 
}

A simple button example may look like this:

export default {
  tag: 'my-button',
  registerPaths: './button.js',
  usages: [
    {
      name: 'Basic Button',
      description: "Button with disabled attributes",
      snippet: `
<my-button></my-button>
<my-button disabled></my-button>
      `,
    }]
}

tag (required)

type string

The tag name of the custom element.

registerPaths (required)

type string | string[]

The path to the file that registers the custom element.

This can be a string or an array of strings if you need to register multiple components for your examples.

You can provide a relative path to the file, or a path to a node module.

usages (required)

type Array<{name: string, description: string, snippet: string}>

An array of objects that describe the examples.

  • name - The name of the example
  • description - A description of the example
  • snippet - The HTML snippet of the example

TODOs

  • [ ] Handle libraries with existing manifests
  • [ ] Support TS for the example files
  • [ ] Support compiled web component tools, like Stencil