Files
dees-wcctools/readme.md

398 lines
11 KiB
Markdown
Raw Normal View History

2024-04-20 23:19:59 +02:00
# @design.estate/dees-wcctools
🛠️ **Web Component Development Tools** — A powerful framework for building, testing, documenting, and recording web components
2020-05-10 23:14:17 +00:00
## Overview
`@design.estate/dees-wcctools` provides a comprehensive development environment for web components, featuring:
- 🎨 **Interactive Component Catalogue** — Live preview with sidebar navigation
- 🔧 **Real-time Property Editing** — Modify component props on the fly with auto-detected editors
- 🌓 **Theme Switching** — Test light/dark modes instantly
- 📱 **Responsive Viewport Testing** — Phone, phablet, tablet, and desktop views
- 🎬 **Screen Recording** — Record component demos with audio support and video trimming
- 🧪 **Advanced Demo Tools** — Post-render hooks for interactive testing
- 🚀 **Zero-config Setup** — TypeScript and Lit support out of the box
2025-12-11 11:14:37 +00:00
## Issue Reporting and Security
For reporting bugs, issues, or security vulnerabilities, please visit [community.foss.global/](https://community.foss.global/). This is the central community hub for all issue reporting. Developers who sign and comply with our contribution agreement and go through identification can also get a [code.foss.global/](https://code.foss.global/) account to submit Pull Requests directly.
## Installation
2024-04-20 23:19:59 +02:00
```bash
# Using pnpm (recommended)
pnpm add -D @design.estate/dees-wcctools
# Using npm
npm install @design.estate/dees-wcctools --save-dev
2024-04-20 23:19:59 +02:00
```
2020-05-10 23:14:17 +00:00
## Quick Start
2024-04-20 23:19:59 +02:00
### 1. Create Your Component
2024-04-20 23:19:59 +02:00
```typescript
import { DeesElement, customElement, html, css, property } from '@design.estate/dees-element';
@customElement('my-button')
export class MyButton extends DeesElement {
// Define a demo for the catalogue
public static demo = () => html`
<my-button .label=${'Click me!'} .variant=${'primary'}></my-button>
`;
@property({ type: String })
2025-12-11 11:23:02 +00:00
accessor label: string = 'Button';
@property({ type: String })
2025-12-11 11:23:02 +00:00
accessor variant: 'primary' | 'secondary' = 'primary';
public static styles = [
css`
:host {
display: inline-block;
}
button {
padding: 8px 16px;
border-radius: 4px;
border: none;
font-size: 14px;
cursor: pointer;
transition: all 0.3s;
}
button.primary {
background: #007bff;
color: white;
}
button.secondary {
background: #6c757d;
color: white;
}
button:hover {
opacity: 0.9;
}
`
];
public render() {
return html`
<button class="${this.variant}">
${this.label}
</button>
`;
}
}
```
### 2. Set Up Your Catalogue
2024-04-20 23:19:59 +02:00
```typescript
// catalogue.ts
2024-04-20 23:19:59 +02:00
import { setupWccTools } from '@design.estate/dees-wcctools';
import { html } from 'lit';
// Import your components
import { MyButton } from './components/my-button.js';
import { MyCard } from './components/my-card.js';
// Define elements for the catalogue
const elements = {
'my-button': MyButton,
'my-card': MyCard,
};
// Optionally define pages
const pages = {
'home': () => html`
<div style="padding: 20px;">
<h1>Welcome to My Component Library</h1>
<p>Browse components using the sidebar.</p>
</div>
`,
'getting-started': () => html`
<div style="padding: 20px;">
<h2>Getting Started</h2>
<p>Installation and usage instructions...</p>
</div>
`,
};
// Initialize the catalogue
setupWccTools(elements, pages);
2024-04-20 23:19:59 +02:00
```
### 3. Create an HTML Entry Point
```html
<!DOCTYPE html>
<html>
<head>
<title>Component Catalogue</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body style="margin: 0; padding: 0;">
<script type="module" src="./catalogue.js"></script>
</body>
</html>
```
2024-04-20 23:19:59 +02:00
## Features
2024-04-20 23:19:59 +02:00
### 🎯 Live Property Editing
The properties panel automatically detects and allows editing of:
| Property Type | Editor |
|--------------|--------|
| **String** | Text input |
| **Number** | Number input |
| **Boolean** | Checkbox |
| **Enum** | Select dropdown |
| **Object/Array** | JSON editor modal |
### 📱 Viewport Testing
Test your components across different screen sizes:
- **Phone** — 320px width
- **Phablet** — 600px width
- **Tablet** — 768px width
- **Desktop** — Full width (native)
### 🌓 Theme Support
Components automatically adapt to light/dark themes using the `goBright` property:
```typescript
public render() {
return html`
<div class="${this.goBright ? 'light-theme' : 'dark-theme'}">
<!-- Your component content -->
</div>
`;
2024-04-20 23:19:59 +02:00
}
```
Or use CSS custom properties with the theme manager:
```typescript
import { cssManager } from '@design.estate/dees-element';
public static styles = [
css`
:host {
color: ${cssManager.bdTheme('#000', '#fff')};
background: ${cssManager.bdTheme('#fff', '#000')};
}
`
];
```
### 🎬 Screen Recording
Record component demos directly from the catalogue! The built-in recorder supports:
- **Viewport Recording** — Record just the component viewport
- **Full Screen Recording** — Capture the entire screen
- **Audio Support** — Add microphone commentary with live level monitoring
- **Video Trimming** — Trim start/end before export with visual timeline
- **WebM Export** — High-quality video output
2024-04-20 23:19:59 +02:00
Click the red record button in the bottom toolbar to start.
### 🧪 Demo Tools
The demotools module provides enhanced testing capabilities with `dees-demowrapper`:
2024-04-20 23:19:59 +02:00
```typescript
import '@design.estate/dees-wcctools/demotools';
@customElement('my-component')
export class MyComponent extends DeesElement {
public static demo = () => html`
<dees-demowrapper .runAfterRender=${async (wrapper) => {
// Find elements using standard DOM APIs
const myComponent = wrapper.querySelector('my-component');
// Simulate user interactions
myComponent.value = 'Test value';
await myComponent.updateComplete;
// Work with multiple elements
wrapper.querySelectorAll('.item').forEach((el, i) => {
console.log(`Item ${i}:`, el.textContent);
});
}}>
<my-component></my-component>
<div class="item">Item 1</div>
<div class="item">Item 2</div>
</dees-demowrapper>
`;
2024-04-20 23:19:59 +02:00
}
```
### ⏳ Async Demos
Return a `Promise` from `demo` for async setup. The dashboard waits for resolution:
```typescript
public static demo = async () => {
const data = await fetchSomeData();
return html`<my-component .data=${data}></my-component>`;
};
```
### 🎭 Container Queries
Components can respond to their container size using the `wccToolsViewport` container:
```typescript
public static styles = [
css`
@container wccToolsViewport (min-width: 768px) {
:host {
flex-direction: row;
}
}
@container wccToolsViewport (max-width: 767px) {
:host {
flex-direction: column;
}
}
`
];
```
## Component Guidelines
2024-04-20 23:19:59 +02:00
### Required for Catalogue Display
1. Components must expose a static `demo` property returning a Lit template
2. Use `@property()` decorators with the `accessor` keyword for editable properties
3. Export component classes for proper detection
### Best Practices
2024-04-20 23:19:59 +02:00
```typescript
@customElement('best-practice-component')
export class BestPracticeComponent extends DeesElement {
// ✅ Static demo property
public static demo = () => html`
2025-12-11 11:23:02 +00:00
<best-practice-component
.complexProp=${{ key: 'value' }}
simpleAttribute="test"
></best-practice-component>
`;
// ✅ Typed properties with defaults (TC39 decorators)
@property({ type: String })
2025-12-11 11:23:02 +00:00
accessor title: string = 'Default Title';
// ✅ Complex property without attribute
@property({ attribute: false })
2025-12-11 11:23:02 +00:00
accessor complexProp: { key: string } = { key: 'default' };
// ✅ Enum with proper typing
@property({ type: String })
2025-12-11 11:23:02 +00:00
accessor variant: 'small' | 'medium' | 'large' = 'medium';
}
```
## URL Routing
The catalogue uses URL routing for deep linking:
2024-04-20 23:19:59 +02:00
```
/wcctools-route/:type/:name/:viewport/:theme
2024-04-20 23:19:59 +02:00
Examples:
/wcctools-route/element/my-button/desktop/dark
/wcctools-route/page/home/tablet/bright
```
2024-04-20 23:19:59 +02:00
## API Reference
2024-04-20 23:19:59 +02:00
### `setupWccTools(elements, pages?)`
Initialize the WCC Tools dashboard.
| Parameter | Type | Description |
|-----------|------|-------------|
| `elements` | `Record<string, typeof LitElement>` | Map of element names to classes |
| `pages` | `Record<string, TTemplateFactory>` | Optional map of page names to template functions |
### `DeesDemoWrapper`
Component for wrapping demos with post-render logic.
| Property | Type | Description |
|----------|------|-------------|
| `runAfterRender` | `(wrapper) => void \| Promise<void>` | Callback after wrapped elements render |
The wrapper provides full DOM API access:
- `wrapper.querySelector()` — Find single element
- `wrapper.querySelectorAll()` — Find multiple elements
- `wrapper.children` — Access child elements directly
### Recording Components (Advanced)
For custom recording integrations:
```typescript
import { RecorderService } from '@design.estate/dees-wcctools';
const recorder = new RecorderService({
onDurationUpdate: (duration) => console.log(`${duration}s`),
onRecordingComplete: (blob) => console.log('Recording done!', blob),
onAudioLevelUpdate: (level) => console.log(`Audio: ${level}%`),
});
await recorder.startRecording({ mode: 'viewport' });
// ... later
recorder.stopRecording();
```
## Project Structure
```
my-components/
├── src/
│ ├── components/
│ │ ├── my-button.ts
│ │ └── my-card.ts
│ └── catalogue.ts
├── dist/
├── index.html
└── package.json
```
2024-04-20 23:19:59 +02:00
## Browser Support
- ✅ Chrome/Edge (latest)
- ✅ Firefox (latest)
- ✅ Safari (latest)
- ✅ Mobile browsers with Web Components support
2024-04-20 23:19:59 +02:00
## License and Legal Information
2025-12-11 11:23:02 +00:00
This repository contains open-source code licensed under the MIT License. A copy of the license can be found in the [LICENSE](./LICENSE) file.
2024-04-20 23:19:59 +02:00
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
2020-05-10 23:14:17 +00:00
2024-04-20 23:19:59 +02:00
### Trademarks
2020-05-23 14:00:49 +00:00
2025-12-11 11:23:02 +00:00
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH or third parties, and are not included within the scope of the MIT license granted herein.
Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines or the guidelines of the respective third-party owners, and any usage must be approved in writing. Third-party trademarks used herein are the property of their respective owners and used only in a descriptive manner, e.g. for an implementation of an API or similar.
2020-05-23 14:00:49 +00:00
2024-04-20 23:19:59 +02:00
### Company Information
2020-05-10 23:14:17 +00:00
2025-12-11 11:23:02 +00:00
Task Venture Capital GmbH
Registered at District Court Bremen HRB 35230 HB, Germany
2020-05-10 23:14:17 +00:00
2025-12-11 11:23:02 +00:00
For any legal inquiries or further information, please contact us via email at hello@task.vc.
2020-05-10 23:14:17 +00:00
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.