web-components-conventions

Standardize web component conventions with nosto- prefix tags and TypeScript typing.

Updated Jan 20, 2025
One-click install
npx skills add https://github.com/Nosto/web-components --skill web-components-conventions
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: web-components-conventions
Source: https://github.com/Nosto/web-components/tree/main/.agents/skills/web-components-conventions
Command: npx skills add https://github.com/Nosto/web-components --skill web-components-conventions

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Web components often suffer from inconsistent conventions across projects, making maintenance and collaboration harder.

Core Features & Use Cases

  • Use nosto- prefix for custom element tags to avoid conflicts
  • Register classes via the customElement decorator for reliable registration
  • Define attributes via the @property(...) decorator; attribute names derive from property names and map to kebab-case
  • Prefer connectedCallback and disconnectedCallback lifecycle methods
  • Use private instance methods (#) for element instance logic
  • Use module-level functions for pure logic
  • Include HTMLElementTagNameMap declaration for TypeScript JSX support

Quick Start

Apply these conventions to all files under src/components to ensure consistency.

Frequently Asked Questions about web-components-conventions

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
What are the standard conventions for writing web components in TypeScript?

Standard web component conventions require using a customElement decorator for class registration and a @property decorator for attributes. Attribute names map to kebab-case, while developers prefer connectedCallback and disconnectedCallback for lifecycle management.

How do I enforce consistent custom element naming and avoid tag conflicts?

To enforce consistent custom element naming and avoid conflicts, apply a nosto- prefix to all custom element tags. This standardizes tag registration across frontend projects, ensuring elements remain uniquely identified and preventing DOM naming collisions.

How do I get TypeScript JSX support for custom elements in my frontend project?

To get TypeScript JSX support for custom elements, declare your tags in the HTMLElementTagNameMap. This allows the TypeScript compiler to recognize custom elements in JSX syntax, providing type checking and autocompletion for your web components.

When structuring custom element logic, should I use private methods or module-level functions?

When structuring custom element logic, use private instance methods (#) for element-specific behavior and module-level functions for pure logic. This separates stateful component interactions from reusable computations, keeping web component architecture clean and maintainable.

Does this web component convention guide require any specific frontend libraries?

No, this web component convention guide does not require specific frontend libraries. It applies to frontend projects implementing custom elements natively, relying only on TypeScript decorators and standard HTMLElement lifecycle methods without external dependencies.