# UI Components Playbook This playbook provides comprehensive guidance for creating and maintaining UI components in the @design.estate/dees-catalog library. Follow these patterns and best practices to ensure consistency, maintainability, and quality. ## Table of Contents 1. [Component Creation Checklist](#component-creation-checklist) 2. [Architectural Patterns](#architectural-patterns) 3. [Component Types and Base Classes](#component-types-and-base-classes) 4. [Theming System](#theming-system) 5. [Event Handling](#event-handling) 6. [State Management](#state-management) 7. [Form Components](#form-components) 8. [Overlay Components](#overlay-components) 9. [Complex Components](#complex-components) 10. [Performance Optimization](#performance-optimization) 11. [Focus Management](#focus-management) 12. [Demo System](#demo-system) 13. [Common Pitfalls and Anti-patterns](#common-pitfalls-and-anti-patterns) 14. [Code Examples](#code-examples) ## Component Creation Checklist When creating a new component, follow this checklist: - [ ] Choose the appropriate base class (`DeesElement` or `DeesInputBase`) - [ ] Use `@customElement('dees-componentname')` decorator - [ ] Implement consistent theming with `cssManager.bdTheme()` - [ ] Create demo function in separate `.demo.ts` file - [ ] Export component from `ts_web/elements/index.ts` - [ ] Use proper TypeScript types and interfaces (prefix with `I` for interfaces, `T` for types) - [ ] Implement proper event handling with bubbling and composition - [ ] Consider mobile responsiveness - [ ] Add focus states for accessibility - [ ] Clean up resources in `destroy()` method - [ ] Follow lowercase naming convention for files - [ ] Add z-index registry support if it's an overlay component ## Architectural Patterns ### Base Component Structure ```typescript import { customElement, property, state, css, TemplateResult, html } from '@design.estate/dees-element'; import { DeesElement } from '@design.estate/dees-element'; import * as cssManager from './00colors.js'; import * as demoFunc from './dees-componentname.demo.js'; @customElement('dees-componentname') export class DeesComponentName extends DeesElement { // Static demo reference public static demo = demoFunc.demoFunc; // Public properties (reactive, can be set via attributes) @property({ type: String }) public label: string = ''; @property({ type: Boolean, reflect: true }) public disabled: boolean = false; // Internal state (reactive, but not exposed as attributes) @state() private internalState: string = ''; // Static styles with theme support public static styles = [ cssManager.defaultStyles, css` :host { display: block; background: ${cssManager.bdTheme('#ffffff', '#09090b')}; } ` ]; // Render method public render(): TemplateResult { return html`