Skip to content

Framework-agnostic suite of highly customizable and type-safe web components, designed with modularity and scalability in mind ✨

License

Notifications You must be signed in to change notification settings

lucafoscili/lf-widgets

Repository files navigation

LF Widgets

Components npm Package

LF Widgets Logo

Development Deployment Production Deployment

GitHub last commit GitHub Actions Workflow Status - Cypress Tests

LF Widgets is a lightweight and versatile Web Components library designed to enhance your web development experience.

Built with modern standards and best practices in mind, LF Widgets offers a collection of reusable components that can seamlessly integrate into any web project, regardless of the framework or vanilla JavaScript setup.

Next.js-deployed showcase

Table of Contents

Features

  • Framework Agnostic: Use with React, Vue, Angular, or just plain JavaScript.
  • Cross-Browser Compatible: Works across all major browsers without additional polyfills.
  • Customizable: The components are highly customizable, giving you the necessary tools to match your project's design system.
  • Glassmorphism Look: LF Widgets incorporates a glassmorphism aesthetic throughout its components. This gives a modern, transparent, and sleek appearance to the UI elements, enhancing the visual appeal of personal projects.
  • Single Event Management: Each component emits a single generic event that encapsulates various actions.

Getting Started

Quick Start

1. Install Yarn

If you haven't installed Yarn yet, get it done with:

npm install -g yarn

Or check out Yarn's installation guide for more options.

2. Clone the Repository & Install Dependencies

Clone this repo and install everything in one go:

git clone https://github.com/lucafoscili/lf-widgets.git
cd lf-widgets
yarn install

3. Run the Showcase

Fire up the showcase to view the webcomponents:

yarn dev:setup

That's it!


Usage

After installing, you can import and use LF Widgets components in your project. Here's a quick example of how to use the <lf-button> component directly in your HTML file:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>LF Widgets Example</title>
    <script
      type="module"
      src="./path/to/@lf-widgets/foundations/dist/index.js"
    ></script>
    <script
      type="module"
      src="./path/to/@lf-widgets/framework/dist/index.js"
    ></script>
    <script
      type="module"
      src="./path/to/@lf-widgets/core/dist/esm/lf-widgets.js"
    ></script>
  </head>
  <body>
    <lf-button lf-label="Click me!" />
  </body>
</html>

Make sure to replace the paths with the actual locations of the LF Widgets packages in your project.

The event handling is wrapped in a single event, emitted by the root element. In this small example we add a listener to the button component, performing different actions for different situations:

const myButton = document.createElement("lf-button");

myButton.addEventListener("lf-button-event", (e) => {
  const { eventType } = e.detail;

  switch (eventType) {
    case "click":
      console.log("Click!");
      break;
    case "blur":
      console.log("Blur!");
      break;
    case "ready":
      console.log("The button is ready!");
      break;
    case "unmount":
      console.log("The button has been removed from the DOM!");
      break;
  }

  document.body.appendChild(myButton);
});

Initializing LfFramework

LF Widgets ships with a small singleton “core” (LfFramework) that underpins theming, portals, debugging features, and more. The singleton must be initialized manually. This is an architectural choice to avoid global state and ensure that the core is only created when needed. In addition, by initializing the core early, you can set up theming and other features before components are rendered to avoid flickering.

Below is the recommended pattern, using this function exported by the @lf-widgets/framework package:

  • getLfFramework()
    Returns the LfFramework instance, initializing it if necessary.

Example

// In your top-level code or a dedicated file
import { getLfFramework } from "@lf-widgets/core";

// Elsewhere, in a component or function:
function doSomething() {
  const framework = getLfFramework();
  framework.assets.set("https://example.com/assets");
  framework.theme.set("dark");
  // ...
}

Key components

LfChart

LfChart

Description:
Provides an advanced charting solution built on top of the Echarts library. It supports various chart types, including line, bar, bubble, and candlestick charts, as well as unique options like dual-axis and heatmap calendars.

Features:

  • Multiple chart types (e.g., line, bar, bubble, candlestick).
  • Highly customizable with Echarts options.
  • Responsive and interactive visuals.
  • Ideal for dashboards, analytics, and data visualizations.

Use Case Highlight:
Perfect for building real-time dashboards, financial data visualizations, and multi-dimensional analytics with polished and professional aesthetics.

LfMasonry

LfMasonry

Description:
Perfect for creating visually appealing layouts with items of varying sizes. It supports a dynamic masonry or waterfall grid style, making it ideal for galleries, portfolios, and content-heavy applications.

Features:

  • Dynamically arranges items for an optimized layout.
  • Supports responsive behavior for various screen sizes.
  • Ideal for showcasing images, cards, or any visual elements.

Use Case Highlight:
Display dynamic content, such as photo galleries or portfolio showcases, where items vary in size and need an elegant, responsive layout.

LfMessenger

LfMessenger

Description:
Provides a customizable chat interface for interactive roleplay or AI-driven conversations. Users can define a JSON dataset of characters and initiate dynamic dialogues through a third-party API (OpenAI compatible endpoint required).

Features:

  • Dynamic list of characters generated from a JSON dataset.
  • Interactive chat interface.
  • Supports integration with custom LLM endpoints for advanced interactions.
  • Configurable visuals and metadata for each character.

Use Case Highlight:
Perfect for creating immersive role-playing experiences, educational tools, or conversational agents where users can interact with pre-defined characters.

Note:
A functional local endpoint is required for chat functionality. If the endpoint is offline, the chat interface will remain static.

Contributing

If you discover a new bug or have an exciting idea for a new component, feel free to open an issue or a discussion! Check out the issues or discussions tabs to see how you can get involved.

Pull requests are also welcome if you want to contribute firsthand. Just clone the repository and run from the root:

yarn install

Then you can launch the development environment with the command:

yarn dev

A Comfy Marriage

LF Widgets forms the backbone of LF Nodes for ComfyUI, a suite of custom nodes designed for ComfyUI workflows. This integration showcases the power and flexibility of web components, making it clear just how effortless it is to introduce new widgets into complex systems.

Why it works:

  • Simplicity: Adding a new widget feels as natural as snapping pieces together.
  • Style: The sleek design of LF Widgets components enhances any workflow.
  • Scalability: The flexibility of web components ensures seamless integration, even as workflows grow more complex.

And… they look fantastic in action!

LoRA Tester Workflow

Documentation

For detailed information about LF Widgets, including architecture, framework, and individual components, please refer to the following documentation:

For detailed information about each component, including available properties, events, and methods, please refer to the showcase.

Credits

Tool Purpose License
Cypress E2E tests engine MIT
Echarts Data visualization components Apache 2.0
Google Fonts Typography for various components OFL
Next.js Engine behind the showcase application MIT
Prism.js Syntax highlighting for code blocks MIT
Stencil.js Web Components engine MIT
Tabler Icons Icon library for UI elements MIT
Vite Development server for the showcase MIT

For detailed licensing information, see the NOTICE file.

Transition from Ketchup Lite

LF Widgets originates from a fork of Ketchup. While Ketchup provided a strong foundation, LF Widgets has been completely reimagined with a focus on:

  • Modern Aesthetics: Adopting a sleek, glassmorphism-inspired design.
  • Enhanced Usability: Simplified components with streamlined theming and events.
  • Unique data structure: Each component relies on the same JSON structure.

Icon Attribution

This project uses Tabler Icons under the MIT License. Icons have been customized for this project.

Adding Custom Icons

To add custom SVGs:

  1. Ensure the SVG is neutralized (remove width, height and hardwired colors).
  2. Place the SVG in the src/assets/svg folder.

Font Attribution

This project uses several fonts from Google Fonts, including:

  • BebasNeue-Regular
  • Cinzel-Regular
  • IMFellEnglishSC-Regular
  • Lato-Regular
  • Merriweather-Regular
  • Montserrat-Regular
  • Orbitron-Regular
  • Oswald-Regular
  • Raleway-Regular
  • SawarabiMincho-Regular
  • ShareTechMono-Regular
  • SourceCodePro-Regular
  • Staatliches-Regular
  • UncialAntiqua-Regular
  • VT323-Regular
  • XanhMono-Regular

Adding Custom Fonts

To add custom fonts:

  1. Ensure the font is in WOFF2 format.
  2. Place the woff file in the src/assets/fonts folder.
  3. Create or edit an existing theme to use the specified font.

About

Framework-agnostic suite of highly customizable and type-safe web components, designed with modularity and scalability in mind ✨

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages