--- name: generate-swim-from-angular description: Generate Lit Component from Angular Implementation disable-model-invocation: true --- # 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. ## Input - Use the Angular component the user has provided, has open, or @-mentioned. If the user typed a component name or path after this command (e.g. `/generate-swim-from-angular checkbox`), use that as the target. - Include the component class file (`.component.ts`), template (`.html`), and styles (`.scss`) when converting. ## Output Location and Structure - All new files go under `projects/swimlane/swim-ui/src/components//`. - Generate: - `.component.ts` – main Lit class - `.styles.ts` – component styles (Lit `css` template) - `index.ts` – re-exports for the component and any enums/interfaces - Optional: `*.enum.ts`, `*.interface.ts` when the Angular component defines enums or shared types - Update `projects/swimlane/swim-ui/src/index.ts` to export the new component (add `export * from './components/';`). ## Reference Implementations (Quality Bar) Follow these existing Lit components for structure, patterns, and style: - **Button** (simpler): `projects/swimlane/swim-ui/src/components/button/` – props, state, promise handling, styles - **Input** (form control): `projects/swimlane/swim-ui/src/components/input/` – form-associated, validation, slots, ElementInternals - **Select** (complex): `projects/swimlane/swim-ui/src/components/select/` – options, dropdown, filter, form association Read their `.component.ts`, `.styles.ts`, and `index.ts` to match style and API documentation. ## Angular → Lit Mapping Apply these mappings consistently: | Angular | Lit | |---------|-----| | `@Input()` | `@property()` with correct `type`, `reflect: true` where needed, `attribute` for kebab-case | | `@Output() x = new EventEmitter()` | In handlers: `this.dispatchEvent(new CustomEvent('x', { detail: value, bubbles: true }))` and document with JSDoc `@fires x` | | `` / `` | `` / `` | | `@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` | ## CSS: Colors and Variables - **Do not copy hex or raw color values** from the Angular styles. Always use **CSS variables** from the ngx-ui design system. These are defined in `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. - Never hardcode `#...`, `rgb(...)`, or `rgba(...)` for design tokens; use `var(--...)` so theming and consistency are preserved. ## CSS: BEM Naming - Use **BEM** (Block__element--modifier) for class names in the Lit component template and styles. - **Block**: The component root (e.g. `swim-button` → class like `swim-button` or a short block name). - **Element**: Descendant, double underscore: `block__element` (e.g. `swim-button__content`, `swim-button__icon`). - **Modifier**: State/variant, double hyphen: `block__element--modifier` or `block--modifier` (e.g. `swim-button--primary`, `swim-button__icon--spinning`). - Apply BEM classes in the `render()` template and style them in `*.styles.ts` so selectors are clear and predictable. ## Design System and Quality - **Tokens and base**: Use design tokens and `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. - **Custom element name**: Map `ngx-` to `swim-` (e.g. `ngx-button` → `swim-button`). Use `@customElement('swim-')`. - **JSDoc**: Document public API with `@slot`, `@fires`, and `@csspart` where applicable. - **Form controls**: If the Angular component is used in forms, implement `static formAssociated = true` and use `ElementInternals` for value and validation (see input and select). - Follow **Accessibility (WCAG)** and **Performance** sections below. ## Accessibility (WCAG) Components must meet **WCAG 2.1** expectations so they are usable by keyboard, screen readers, and assistive tech. Apply these consistently: - **Semantics**: Use the correct HTML element or ARIA role (e.g. `role="button"` only when not a `