Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

web-components-custom-elements

/web-components-custom-elements

Tworzy niezależne od frameworka Custom Elements, Shadow DOM i szablony HTML zgodnie ze standardem Web Components.

Licencja
MIT
Ostatnia zmiana repozytorium
28.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
0
Przestarzałość

Brak sygnałów. Repozytorium zmienione 28.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Tworzy niezależne od frameworka Custom Elements, Shadow DOM i szablony HTML zgodnie ze standardem Web Components.

Oryginalny opis (EN)

Use this skill when authoring framework-agnostic Custom Elements, Shadow DOM encapsulations, and HTML templates using the Web Components standard.

Jak działa

  1. When to use
  2. Prerequisites
  3. Step-by-step workflow
  4. Commands / code examples
  5. Common mistakes & pitfalls
  6. Verification checklist
  7. Related skills
Sekcje z nagłówków SKILL.md, w oryginale · 82 linii, 370 słów
Podgląd SKILL.md
---
name: web-components-custom-elements
description: Use this skill when authoring framework-agnostic Custom Elements, Shadow DOM encapsulations, and HTML templates using the Web Components standard.
---
# Web Components and Custom Elements

## When to use
Use this skill when building reusable, framework-independent UI widgets, micro-frontend building blocks, or shared enterprise component libraries.

## Prerequisites
- Deep familiarity with modern JavaScript (ES6+ classes, lifecycle callbacks).
- Understanding of the DOM tree, events, and CSS encapsulation.

## Step-by-step workflow
1. **Extend HTMLElement**: Create an ES6 class extending `HTMLElement`.
2. **Attach Shadow DOM**: In the `constructor`, call `super()` and attach a shadow root using `this.attachShadow({ mode: 'open' })`.
3. **Implement lifecycle methods**: Connect behaviors inside `connectedCallback`, `disconnectedCallback`, and `attributeChangedCallback`.
4. **Declare observed attributes**: Provide a static `get observedAttributes()` getter returning an array of tracked attribute strings.
5. **Register the custom element**: Call `customElements.define('my-element', MyElement)` ensuring the tag name contains a mandatory hyphen.

## Commands / code examples
```ts
class StatusBadge extends HTMLElement {
  static get observedAttributes() {
    return ['status'];
  }

  constructor() {
    super();
    this.attachShadow({ mode: 'open' });
  }

  connectedCallback() {
    this.render();
  }

  attributeChangedCallback(name: string, oldValue: string, newValue: string) {
    if (oldValue !== newValue) {
      this.render();
    }
  }

  render() {
    if (!this.shadowRoot) return;
    const status = this.getAttribute('status') || 'offline';
    const isOnline = status === 'online';

    this.shadowRoot.innerHTML = `
      <style>
        :host { display: inline-block; font-family: system-ui, sans-serif; }
        .badge {
          display: inline-flex; align-items: center; gap: 0.375rem;
          padding: 0.25rem 0.5rem; border-radius: 9999px; font-size: 0.75rem; font-weight: 500;
          background: ${isOnline ? '#dcfce7' : '#f3f4f6'};
          color: ${isOnline ? '#166534' : '#374151'};
        }
        .dot { width: 6px; height: 6px; border-radius: 50%; background: ${isOnline ? '#22c55e' : '#9ca3af'}; }
      </style>
      <span class="badge">
        <span class="dot"></span>
        <slot>${status}</slot>
      </span>
    `;
  }
}

customElements.define('status-badge', StatusBadge);
```

## Common mistakes & pitfalls
- Forgetting the required hyphen in custom element tag names (e.g., using `<badge>` instead of `<status-badge>`).
- Performing DOM rendering or accessing child elements inside the `constructor` instead of `connectedCallback`.
- Forgetting to clean up global event listeners attached outside the shadow root in `disconnectedCallback`.

## Verification checklist
- [ ] Element tag name contains at least one hyphen (`-`).
- [ ] Shadow DOM is initialized in `constructor` and rendered in `connectedCallback`.
- [ ] Tracked attributes are listed in `static get observedAttributes()`.
- [ ] Component cleans up timers and listeners when disconnected from the DOM.

## Related skills
- browser-dom-manipulation-events
- html5-semantic-web
- micro-frontends-module-federation
- javascript-es2024-deep-dive

Wersje

W bazie nie ma innych skilli o nazwie web-components-custom-elements.

Migawka bazy z 13.11.2026 · wersja paczki 4cee9b31d1f8 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 90frontend-web-components
    Pomaga tworzyć Web Components: custom elements, shadow DOM, sloty i formularze przez ElementInternals.
  • 90fe-web-components
    Pisze i przegląda elementy niestandardowe, zwykłe albo w Lit 3, z nazwami, cyklem życia, atrybutami, stylami Shadow DOM i kontrolkami formularzy.
  • 90frontend-lit
    Buduje komponenty Lit i web components: LitElement z reaktywnymi właściwościami, szablony lit-html, shadow DOM i renderowanie po stronie serwera.
  • 100html5-semantic-elements
    Przegląda szablony i wyrenderowany HTML pod kątem użycia semantycznych elementów HTML, sprawdzając końcowy znacznik w przeglądarce.
  • 100lit-doctor
    Sprawdza i naprawia kod korzystający z bibliotek lit i lit-html, w tym renderowanie, shadow DOM i wydajność.
  • 95migrate-swc-gen1-to-gen2
    Migruje komponenty Spectrum 1, czyli elementy sp-* i pakiety @spectrum-web-components, na Spectrum 2.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.