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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@cas-smartdesign/element-preview

v0.3.0

Published

An element which encapsulates the look and feel for all element previews in the documentation

Readme

@cas-smartdesign/element-preview

A helper library that can be used to include examples in elements documentation with preview and source code(s).

Disclaimer

The tool is made for internal use, its API may change in the future.

Please keep this in mind when using it.

Usage

  • Install @cas-smartdesign/element-preview as devDependency
  • Add the path alias. See more below.
  • Create the source code for the example
    • Readme (with a brief description)
    • HTML
    • CSS (optional)
    • Typescript (optional)
  • Create an index.ts that describes the example and its components
  • Create a <div> with examples id or have an ## Examples section in the readme.md. This will be the container for the examples
  • Call initializeExamples of element-preview

Package and module resolution

By default the documented package and its modules cannot be referenced as the end user would do it:

import { ComboBox } from "@cas-smartdesign/combobox"

In order to make this work, the tsconfig.json should be extended with baseUrl and paths aliases:

{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@cas-smartdesign/combo-box": [
        "./combo-box.ts"
      ]
    }
  }
}

For other use cases, the /// character sequence can be used to replace lines on the UI

const s = "Runtime code"; /// const s = "Code for the UI";

It can be also used to show something only in the documentation or execute only when generating the preview.

const s = "This will be executed when generating the preview"; ///

/// const s = "This will be shown only in the documentation";

Example

Folder structure

docs
 ├ examples
 |  └ sample-usage
 |     ├ example.css
 |     ├ example.html
 |     ├ example.md
 |     ├ example.ts
 |     └ index.ts
 ├ doc.html
 └ doc.ts

doc.ts

import "!style-loader!css-loader!github-markdown-css/github-markdown-light.css";
import { initializeExamples } from "@cas-smartdesign/element-preview";

document.querySelector("#markdown-container").innerHTML = require("../readme.md").default as string;
initializeExamples(require.context("./examples", true, /index.ts/, "eager"), document.body);

index.ts

import { ExampleDescription } from "@cas-smartdesign/element-preview";

const example: ExampleDescription = {
    mainContent: require("./example.html?raw")
    description: require("./example.md").default as string,
    initializer: {
        content: require("!raw-loader!./example.ts").default,
        type: "typescript",
        initialize: () => require("./example.ts"),
    },
    css: require("!raw-loader!./example.css").default,
};

export default example;

example.md

### Basic usage of the Button element

example.css

.grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  column-gap: 16px;
  row-gap: 16px;
}

example.html

<div id="sample-buttons" class="grid">
  <sd-button primary>Primary button</sd-button>
  <sd-button>Simple button</sd-button>
  <sd-button primary>Disabled primary button</sd-button>
  <sd-button>Disabled simple button</sd-button>
</div>

example.ts

import "@cas-smartdesign/button";
import { Button } from "@cas-smartdesign/button";

document.querySelectorAll("#sample-buttons sd-button").forEach((element) => {
  const button = element as Button;
  button.addEventListener("click", () =>
    console.log(`Clicked on${button.disabled ? " disabled" : ""}${button.primary ? " primary" : ""} button!`),
  );
});