Skip to content

Attractive Element - #115

Merged
eelcoj merged 1 commit into
mainfrom
attractive-element
Aug 15, 2026
Merged

eelcoj merged 1 commit into
mainfrom
attractive-element

Conversation

@eelcoj

@eelcoj eelcoj commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Make custom elements great again…

AttractiveElement is a base class for custom elements. It scopes Attractive to the component, so @click, @target, gates and triggers work inside the component.

Simple example:

class Tabs extends AttractiveElement {
  connect() {
    this.#show("details");
  }

  select(element, { dataset }) {
    this.#show(dataset.panel);
  }

  #show(name) {
    this.targets(".panel").forEach((panel) => (panel.hidden = true));

    this.target(name).hidden = false;
  }
}

customElements.define("ui-tabs", Tabs);

Usage:

<ui-tabs>
  <nav>
    <button @click="select" data-panel="details">Details</button>
    <button @click="select" data-panel="settings">Settings</button>
  </nav>

  <div id="details" class="panel"></div>
  <div id="settings" class="panel" hidden></div>
</ui-tabs>

@eelcoj
eelcoj force-pushed the attractive-element branch from 7d3a40e to ca554bc Compare August 15, 2026 18:25
@eelcoj
eelcoj force-pushed the attractive-element branch from ca554bc to abc726d Compare August 15, 2026 18:47
@eelcoj
eelcoj merged commit a67bac2 into main Aug 15, 2026
1 check passed
@eelcoj
eelcoj deleted the attractive-element branch August 15, 2026 18:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant