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

justin-test-component-library-template

v1.2.5

Published

This is a demo of building a library with multiple entrypoints

Downloads

2

Readme

Tailwind web components starter kit

This is a starter kit to develop web components using Tailwind CSS.

Tailwind and web components do not play well together.

We managed to find a way to make them work without hacks or weird tech: just common technologies combined in a elegant way.

No dependencies, based on lit-element.

How will you create a tailwind component?

Here is a sample code:

import {html} from 'lit';
import {customElement, property} from 'lit/decorators.js';
import {TailwindElement} from '../shared/tailwind.element';

import style from './test.component.scss'; // #1

@customElement('test-component')
export class TestComponent extends TailwindElement(style) { // #2

  @property()
  name?: string = 'World';

  render() {
    return html`
      <p>
        Hello,
        <b>${this.name}</b>
        !
      </p>
      <button class="bg-blue-200 text-yellow-200 p-2 rounded-full text-2xl">Hello world!</button>
    `;
  }
}

It is based on the lit element technology: if you wrote a lit component before, you'll find it familiar.

There are only two differences to a standard LitElement:

  1. You must import your styles from a separate file. And this is good for two reasons:
    • it separate the CSS from the logic
    • you can decide to use CSS or SCSS
  2. the class extends a TailwindElement rather than a LitElement

A TailwindElement extends a LitElmement (see below) and adds the logic to integrate tailwind and your style.

Get started

To run the project:

  1. pnpm install (only the first time)
  2. pnpm start to run the server
  3. to develop the library, run pnpm build and copy the static assets where you need them.

You may clone this repo and start developing your components by looking at the test.component as reference.

As an alternative, and if you like to have control over every piece, do the following:

  1. copy the files in the shared folder:
    • tailwind.element.ts extends LitElement by adding the tailwind support
    • tailwind.global.css includes tha Tailwind base classes into each component
    • globals.d.ts is used to avoid TypeScript errors whe nimporting CSS/Scss files in typescript files (thanks @emaant96)
  2. copy the package.json or the devDependencies inside into your own package.json (there are no dependencies)
  3. copy postcss.config.js, tailwind.config.js and tsconfig.js

That's all.

Show me the pieces

If you want to understand how it works, it's simple:

  • the package.json integrates these technolgies:
"autoprefixer": "^10.4.12",
"postcss": "^8.4.18",
"lit": "^2.4.0",
"tailwindcss": "^3.2.0",
"typescript": "^4.8.4",
"vite": "^3.1.8",
"sass": "^1.55.0"
  • vite does almost all the work automatically
  • to integrate tailwind, the most important file is in src/shared/tailwind.element.ts
import {LitElement, unsafeCSS} from "lit";

import style from "./tailwind.global.css";

const tailwindElement = unsafeCSS(style);

export const TailwindElement = (style) =>
    class extends LitElement {

        static styles = [tailwindElement, unsafeCSS(style)];
    
    };

It extends a LitElement class at runtime and adds the component tailwind classes.

The style variable comes from your component, where it is imported from an external CSS (or SCSS) file.

Then it is combined with the default tailwind classes.

If you add more components, the common parts are reused.

Who uses it?

We developed this starter kit to implement a web session player for our open source SaaS browserbot.

If you want to contribute or share soem thoughts, just get in touch with us.

Enjoy.