Generate Lit Component from Angular Implementation
Generate a Lit web component in @swimlane/swim-ui that mirrors the design and behavior of an Angular component from @swimlane/ngx-ui. The output must match existing Lit patterns and design system parity.
/generate-swim-from-angular checkbox), use that as the target..component.ts), template (.html), and styles (.scss) when converting.projects/swimlane/swim-ui/src/components/<name>/.<name>.component.ts – main Lit class<name>.styles.ts – component styles (Lit template)cssindex.ts – re-exports for the component and any enums/interfaces*.enum.ts, *.interface.ts when the Angular component defines enums or shared typesprojects/swimlane/swim-ui/src/index.ts to export the new component (add export * from './components/<name>';).Follow these existing Lit components for structure, patterns, and style:
projects/swimlane/swim-ui/src/components/button/ – props, state, promise handling, stylesprojects/swimlane/swim-ui/src/components/input/ – form-associated, validation, slots, ElementInternalsprojects/swimlane/swim-ui/src/components/select/ – options, dropdown, filter, form associationRead their .component.ts, .styles.ts, and index.ts to match style and API documentation.
Apply these mappings consistently:
| Angular | Lit |
|---|---|
@Input() | @property() with correct type, reflect: true where needed, attribute for kebab-case |
@Output() x = new EventEmitter<T>() | In handlers: this.dispatchEvent(new CustomEvent('x', { detail: value, bubbles: true })) and document with JSDoc @fires x |
<ng-content> / <ng-content select="..."> | <slot></slot> / <slot name="..."></slot> |
@ContentChild / @ViewChild | @query('selector') for DOM refs; use slots for content projection |
Template (.html) | render() returning html template literal |
Styles (.scss) | Separate *.styles.ts with css tagged template; compose baseStyles and component styles in static styles = [baseStyles, componentStyles]. Use BEM for class names (see CSS section below). |
Host classes (e.g. [class.in-progress]) | :host([state='in-progress']) in styles and/or reflected attributes on the host |
ngOnInit / ngOnChanges | connectedCallback(), updated(), firstUpdated() as appropriate |
Angular coercion (@angular/cdk/coercion, etc.) | Use projects/swimlane/swim-ui/src/utils/coerce.ts: coerceBooleanProperty, coerceNumberProperty |
Enums (e.g. in button-state.enum.ts) | Keep as *.enum.ts in the component folder and export from index.ts |
projects/swimlane/swim-ui/src/styles/base.ts (and tokens) and mirror ngx-ui (e.g. var(--blue-500), var(--grey-600), var(--red-500), var(--radius-4), var(--font-size-m)). Refer to ngx-ui's SCSS variables/tokens to pick the correct variable names.#..., rgb(...), or rgba(...) for design tokens; use var(--...) so theming and consistency are preserved.swim-button → class like swim-button or a short block name).block__element (e.g. swim-button__content, swim-button__icon).block__element--modifier or block--modifier (e.g. swim-button--primary, swim-button__icon--spinning).render() template and style them in *.styles.ts so selectors are clear and predictable.baseStyles from projects/swimlane/swim-ui/src/styles/ (and styles/base.ts). Rely on CSS variables (see above); do not introduce new hardcoded colors or spacing that contradict ngx-ui.ngx-<name> to swim-<name> (e.g. ngx-button → swim-button). Use @customElement('swim-<name>').@slot, @fires, and @csspart where applicable.static formAssociated = true and use ElementInternals for value and validation (see input and select).Components must meet WCAG 2.1 expectations so they are usable by keyboard, screen readers, and assistive tech. Apply these consistently:
role="button" only when not a <button>, role="tablist" / role="tab" / role="tabpanel", role="combobox", role="listbox").aria-label, aria-labelledby, aria-describedby, aria-expanded, aria-selected, aria-controls, aria-disabled, aria-invalid, aria-required, aria-hidden where they convey state or relationships. Keep id / aria-controls / aria-labelledby links valid and stable.:focus-visible with outline) and no outline: none without a visible replacement. When opening overlays or changing active item, move focus as needed (e.g. to first focusable or selected item).aria-label, or aria-labelledby). Use <label> + id or ElementInternals for form-associated controls.aria-selected, aria-checked, aria-expanded, aria-disabled) and keep it in sync with the component.Keep components efficient and avoid unnecessary work:
@property() for public API and @state() for internal UI state. Avoid reflecting internal state as attributes unless needed for styling or accessibility.requestUpdate() or change properties when data actually changes. In setters, guard with if (this._x !== next) before assigning and dispatching.slot.assignedElements() / slot.assignedNodes() in firstUpdated() or in response to slotchange; avoid querying on every render() or in tight loops.firstUpdated() or connectedCallback(); always remove in disconnectedCallback() (e.g. slotchange, document/window click-outside, resize, drag). Use bound handler references (e.g. this._slotChangeBound = () => this._onSlotChange();) so the same reference can be passed to removeEventListener. Prefer one delegated listener over many per-item listeners where practical.requestAnimationFrame, setTimeout(..., 0)) so initial render stays fast. Avoid synchronous layout thrash (e.g. reading then writing layout properties repeatedly).static styles as shared css template literals; avoid defining new style objects per instance. Reuse baseStyles and component-level css blocks.updated(changedProperties) to run logic only when specific properties change; avoid side effects in render().To avoid leaks when components are removed from the DOM (e.g. navigation, conditional rendering), every component must clean up in disconnectedCallback():
Event listeners
addEventListener and removeEventListener.slotchange, handle drag/dblclick, panel mouseenter/mouseleave.firstUpdated() to a slot or element from @query, store the element and the bound handler so you can remove in disconnectedCallback().Timers
setTimeout or setInterval (and requestAnimationFrame if recurring): call clearTimeout / clearInterval and set the stored id to undefined.Pattern
private _slotChangeBound = () => this._onSlotChange();) so the same reference is used for add and remove.disconnectedCallback(), remove listeners and clear timers before calling super.disconnectedCallback().Components that add listeners on other elements
firstUpdated() (e.g. overlay panel), keep a reference to that element and the bound handlers, and remove them in disconnectedCallback() (and optionally when the overlay closes, to avoid duplicate listeners on re-open).Before writing the Lit demo, read the corresponding Angular demo page under the repo root src/app/ so the Lit demo is very close to how the Angular demo is designed.
<ngx-tabs> with "Examples" and "API"; Lit uses <swim-section section-title="..."> for each logical block. Use the same section titles where applicable (e.g. "Demo", "Disabled", "Events and FormGroup", "Usage").Finding the Angular demo (do this dynamically):
Do not rely on a fixed list of component paths. For the component you are converting (e.g. button, checkbox, tooltip):
src/app/ for directories named *-page (e.g. src/app/forms/, src/app/components/, src/app/dialogs/, src/app/elements/ contain such folders).checkbox → checkbox-page, button → buttons-page, button-group → button-group-page, tooltip → tooltip-page), orngx-<name> (e.g. ngx-checkbox, ngx-button) in *.component.html files under src/app/ and opening the file that contains it.*-page.component.html) as the single source for section structure, titles, and example content.This way every component's demo is found the same way and the command stays valid as new Angular demo pages are added.
projects/swimlane/swim-ui/src/components/<name>/.index.ts exports and update projects/swimlane/swim-ui/src/index.ts.declare global { interface HTMLElementTagNameMap { 'swim-<name>': ComponentClass; } } block for TypeScript.index.html (e.g. .section-divider, .page-title, .section-desc, .demo-row--column, .demo-label--after, .demo-pre).<swim-section section-title="..."> with the same titles as the Angular demo's <ngx-section sectionTitle="..."> blocks. Wrap each <section class="section"> content in <swim-section section-title="...">. Use section-collapsible="false" only when the Angular demo does. Ensure section component is imported in demo/src/main.ts if used.projects/swimlane/swim-ui/demo/public/sections/<name>.html. Start the file with <hr class="section-divider"> then <h1 id="component-id" class="page-title">...</h1> and <p class="subtitle">...</p> so the nav link (e.g. href="#checkbox") works. Add <name> to the SECTION_FILES array in demo/src/main.ts. Add a nav link in demo/index.html (e.g. <a class="sub-nav-item" href="#component-id">Label</a> under the appropriate group). Structure of the section file:
<section class="section"> with <swim-section section-title="..."> matching Angular section titles, showing: basic usage, all variants/sizes, states (e.g. disabled), interactive example, then Usage with <pre class="demo-pre"><code>...</code></pre> (import + minimal HTML).<name> to SECTION_FILES if using section files; add any DOMContentLoaded setup (e.g. event listeners, option data) so every interactive demo works.Produce a complete, usable Lit component that mirrors the Angular implementation with best quality. Components must be accessible (WCAG 2.1) and efficient in performance; the demo must match the Angular demo design and all demo functionality must work after validation.
After generating the component and demo:
projects/swimlane/swim-ui/demo). If you have a way to open or inspect a browser tab (e.g. Cursor's browser tools or user opening the page), use it.demo/src/main.ts (e.g. buttons that set promise, select options, event handlers) is wired correctly and runs without errors in the console.getElementById), event names, property names, or component API usage so the demo behaves as in the Angular version.