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 🙏

© 2026 – Pkg Stats / Ryan Hefner

lit-feature

v1.0.4

Published

Core functionalities and components for integrating with the Lit framework.

Readme

LitFeature

A composable feature system for Lit that enables clean, declarative composition of component behaviors without the complexity of deep mixin stacks.

Features are small, single-responsibility units of behavior that can be provided by base classes and configured or disabled by subclasses, while participating in Lit's reactive property system and lifecycle.

Why LitFeature?

Building large design systems with Lit requires:

  • Composing multiple independent behaviors (ripple effects, themes, dismissal logic, etc.)
  • Enabling/disabling behaviors per component
  • Overriding defaults at different inheritance levels
  • Avoiding complex, brittle mixin stacks

LitFeature provides a declarative, inheritance-aware model for composing behaviors that feels natural to Lit developers.

Installation

npm install lit-feature

Quick Start

Using Decorators (Recommended)

import { LitCore } from 'lit-feature';
import { provide, configure } from 'lit-feature/decorators';
import { RippleFeature } from './features/ripple-feature.js';
import { ThemeFeature } from './features/theme-feature.js';

// Provide features with default configuration
@provide('Ripple', { class: RippleFeature, config: { rippleDurationMs: 600 } })
@provide('Theme', { class: ThemeFeature, config: { variant: 'primary' } })
export class MyButton extends LitCore {
  declare Ripple: RippleFeature;
  declare Theme: ThemeFeature;
}

// Extend and override configuration
@configure('Theme', { config: { variant: 'secondary' } })
export class SecondaryButton extends MyButton {}

// Disable inherited features
@configure('Ripple', 'disable')
export class StaticButton extends MyButton {}

Using Static Properties

import { LitCore } from 'lit-feature';
import { RippleFeature } from './features/ripple-feature.js';

export class MyButton extends LitCore {
  static provide = {
    Ripple: {
      class: RippleFeature,
      config: { rippleDurationMs: 600 }
    }
  };
}

export class SlowRippleButton extends MyButton {
  static configure = {
    Ripple: {
      config: { rippleDurationMs: 1200 }
    }
  };
}

Creating a Feature

Features extend LitFeature and can define reactive properties, lifecycle methods, and styles:

import { LitFeature } from 'lit-feature';
import { property } from 'lit-feature/decorators';
import { css } from 'lit';

export class RippleFeature extends LitFeature {
  @property({ type: Boolean, reflect: true })
  rippling = false;

  @property({ type: Number, attribute: 'ripple-duration' })
  rippleDurationMs = 600;

  connectedCallback() {
    super.connectedCallback();

    // Host is automatically available in the feature scope
    this.host.addEventListener('click', this.#handleClick);
  }

  #handleClick = (e: MouseEvent) => {
    this.rippling = true;
    setTimeout(() => {
      this.rippling = false;
    }, this.rippleDurationMs);
  };

  static styles = css`
    :host([rippling]) {
      animation: ripple-effect var(--ripple-duration, 600ms) ease-out;
    }
    
    @keyframes ripple-effect {
      0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, 0.6); }
      100% { box-shadow: 0 0 0 20px rgba(255, 255, 255, 0); }
    }
  `;
}

Core Concepts

Providing Features

Use @provide(name, definition) or static provide to make features available on a class and its subclasses:

@provide('MyFeature', { 
  class: MyFeatureClass, 
  config: { /* default config */ } 
})
export class BaseElement extends LitCore {}

Configuring Features

Use @configure(name, options) or static configure to override inherited feature configuration or disable features:

// Override configuration
@configure('MyFeature', { config: { /* updated config */ } })
export class CustomElement extends BaseElement {}

// Disable a feature
@configure('MyFeature', 'disable')
export class NoFeatureElement extends BaseElement {}

Feature Inheritance

Features themselves can extend other features, inheriting properties, styles, and lifecycle methods:

export class BaseDismissFeature extends LitFeature {
  @property({ type: Boolean }) dismissed = false;
  
  dismiss() {
    this.dismissed = true;
  }
}

export class AutoDismissFeature extends BaseDismissFeature {
  @property({ type: Number }) timeout = 3000;
  
  connectedCallback() {
    super.connectedCallback();
    setTimeout(() => this.dismiss(), this.timeout);
  }
}

API Reference

Core Classes

  • LitCore - Base class for components that support features (extends LitElement)
  • LitFeature - Base class for creating features
  • FeatureManager - Internal manager for feature instantiation and lifecycle

Decorators

  • @provide(name, definition) - Declare a feature on a class
  • @configure(name, options) - Configure or disable an inherited feature
  • @property(options) - Re-exported Lit property decorator for use in features

Lifecycle Methods

Features can implement any of these lifecycle hooks:

  • connectedCallback() / disconnectedCallback()
  • firstUpdated(changedProperties) / updated(changedProperties)
  • attributeChangedCallback(name, oldValue, newValue)

And "around" hooks:

  • beforeConnectedCallback() / afterConnectedCallback()
  • beforeDisconnectedCallback() / afterDisconnectedCallback()
  • beforeFirstUpdated() / afterFirstUpdated()
  • beforeUpdated() / afterUpdated()
  • beforeAttributeChangedCallback() / afterAttributeChangedCallback()

Documentation

For detailed documentation, advanced patterns, and interactive examples, visit:

https://StephenRiosDev.github.io/LitFeature/#docs

Dependencies

  • lit - The Lit library
  • lodash.merge - Deep merging for configuration

Relationship to Lit Concepts

  • Mixins - Great for small numbers of behaviors, but complex at scale
  • Reactive Controllers - Strong composition primitive; LitFeature extends this pattern with inheritance-aware configuration and declarative property contribution
  • Context - Solves dependency injection; LitFeature focuses on behavior composition and lifecycle

License

Licensed under the Apache License, Version 2.0. See LICENSE for details.

If you reuse or redistribute this code, please retain the NOTICE file to preserve attribution.

Contributing

This is an early proof-of-concept exploring compositional patterns for Lit. Feedback and contributions are welcome!

For questions, issues, or feature requests, please visit the GitHub repository.