|
| 1 | +# J26 Web Components |
| 2 | + |
| 3 | +A monorepo containing Stencil web components, design tokens, and Astro Starlight documentation. |
| 4 | + |
| 5 | +## Prerequisites |
| 6 | + |
| 7 | +- Node.js (v18 or higher) |
| 8 | +- pnpm (v10.7.0 or higher) |
| 9 | + |
| 10 | +## Getting Started |
| 11 | + |
| 12 | +```bash |
| 13 | +# Install dependencies |
| 14 | +pnpm install |
| 15 | + |
| 16 | +# Start development (builds tokens & components, starts hot reload for all packages) |
| 17 | +pnpm dev |
| 18 | +``` |
| 19 | + |
| 20 | +The dev server will start: |
| 21 | +- Design tokens watch mode (rebuilds on changes) |
| 22 | +- Components watch mode (rebuilds on changes) |
| 23 | +- Astro Starlight docs (http://localhost:4321) |
| 24 | + |
| 25 | +## Available Scripts |
| 26 | + |
| 27 | +All commands should be run from the **root directory**. |
| 28 | + |
| 29 | +### Development |
| 30 | + |
| 31 | +```bash |
| 32 | +# Start full development environment with hot reloading |
| 33 | +# (Builds tokens & components, then starts watch mode for all) |
| 34 | +pnpm dev |
| 35 | + |
| 36 | +# Fast component-only dev with Stencil's built-in HMR server |
| 37 | +# (Faster rebuilds, but components shown in Stencil's UI, not Astro) |
| 38 | +pnpm dev:components |
| 39 | + |
| 40 | +# Start only docs (components must be built first) |
| 41 | +pnpm docs:dev |
| 42 | + |
| 43 | +# Start Storybook (legacy, use docs instead) |
| 44 | +pnpm storybook |
| 45 | +``` |
| 46 | + |
| 47 | +**Hot Reloading Performance:** |
| 48 | +- **Token changes**: ~50-200ms rebuild time |
| 49 | +- **Component changes**: ~1-3s rebuild time (optimized with incremental builds) |
| 50 | +- **Astro doc changes**: Instant HMR |
| 51 | +- Use `pnpm dev:components` for fastest component iteration (Stencil's dev server with native HMR) |
| 52 | + |
| 53 | +### Building |
| 54 | + |
| 55 | +```bash |
| 56 | +# Build tokens and components only |
| 57 | +pnpm build |
| 58 | + |
| 59 | +# Build everything (tokens, components, and docs) |
| 60 | +pnpm build:all |
| 61 | + |
| 62 | +# Build specific packages |
| 63 | +pnpm tokens:build |
| 64 | +pnpm components:build |
| 65 | +pnpm docs:build |
| 66 | + |
| 67 | +# Preview production docs build |
| 68 | +pnpm docs:preview |
| 69 | +``` |
| 70 | + |
| 71 | +### Testing |
| 72 | + |
| 73 | +```bash |
| 74 | +# Run unit tests |
| 75 | +pnpm test |
| 76 | + |
| 77 | +# Run tests in watch mode |
| 78 | +pnpm test:watch |
| 79 | + |
| 80 | +# Run E2E tests |
| 81 | +pnpm test:e2e |
| 82 | +``` |
| 83 | + |
| 84 | +### Code Quality |
| 85 | + |
| 86 | +```bash |
| 87 | +# Check code with Biome |
| 88 | +pnpm lint |
| 89 | + |
| 90 | +# Fix linting issues |
| 91 | +pnpm lint:fix |
| 92 | + |
| 93 | +# Format code |
| 94 | +pnpm format |
| 95 | +``` |
| 96 | + |
| 97 | +### Generating Components |
| 98 | + |
| 99 | +```bash |
| 100 | +# Generate a new component with plop |
| 101 | +pnpm plop |
| 102 | + |
| 103 | +# Or use Stencil's generator |
| 104 | +pnpm generate |
| 105 | +``` |
| 106 | + |
| 107 | +The plop generator will: |
| 108 | +- Create component files (.tsx, .css, .spec.ts, .e2e.ts, .stories.tsx) |
| 109 | +- Generate Starlight documentation (with consistent structure) |
| 110 | +- Update package.json exports automatically |
| 111 | + |
| 112 | +### Cleanup |
| 113 | + |
| 114 | +```bash |
| 115 | +# Remove all node_modules and build artifacts |
| 116 | +pnpm clean |
| 117 | + |
| 118 | +# Clean and reinstall dependencies |
| 119 | +pnpm clean:install |
| 120 | + |
| 121 | +# Clean build artifacts and rebuild |
| 122 | +pnpm clean:build |
| 123 | +``` |
| 124 | + |
| 125 | +## Project Structure |
| 126 | + |
| 127 | +``` |
| 128 | +j26-web-components/ |
| 129 | +├── packages/ |
| 130 | +│ ├── design-tokens/ # Design tokens (CSS custom properties) |
| 131 | +│ ├── ui-webc/ # Stencil web components |
| 132 | +│ └── docs/ # Astro Starlight documentation |
| 133 | +├── package.json # Root package with scripts |
| 134 | +└── pnpm-workspace.yaml # Workspace configuration |
| 135 | +``` |
| 136 | + |
| 137 | +## Creating a New Component |
| 138 | + |
| 139 | +1. Run the plop generator: |
| 140 | + ```bash |
| 141 | + pnpm plop |
| 142 | + ``` |
| 143 | + |
| 144 | +2. Follow the prompts: |
| 145 | + - Component name (e.g., `my-button`) |
| 146 | + - Component description |
| 147 | + |
| 148 | +3. The generator creates: |
| 149 | + - Component files in `packages/ui-webc/src/components/` |
| 150 | + - Documentation in `packages/docs/src/content/docs/components/` |
| 151 | + |
| 152 | +4. Customize the generated files: |
| 153 | + - Update component logic in `.tsx` file |
| 154 | + - Add styles in `.css` file |
| 155 | + - Update documentation with real examples |
| 156 | + - Customize API reference (props, events) |
| 157 | + - Add variants and examples |
| 158 | + |
| 159 | +5. Test your component: |
| 160 | + ```bash |
| 161 | + pnpm dev |
| 162 | + ``` |
| 163 | + Navigate to http://localhost:4321 to see your component documentation. |
| 164 | + |
| 165 | +## Documentation Structure |
| 166 | + |
| 167 | +All component documentation follows this structure: |
| 168 | + |
| 169 | +1. **Overview** - Brief description of the component |
| 170 | +2. **Installation** - How to install the package |
| 171 | +3. **Usage** - TypeScript and HTML examples |
| 172 | +4. **API Reference** - Properties and Events tables |
| 173 | +5. **Examples** - Default example with preview |
| 174 | +6. **Variants** - Different component variations |
| 175 | + |
| 176 | +## Development Workflow |
| 177 | + |
| 178 | +1. **Start development**: `pnpm dev` |
| 179 | +2. **Make changes** to components in `packages/ui-webc/src/components/` |
| 180 | +3. **View changes** in Astro docs at http://localhost:4321 |
| 181 | +4. **Add/update documentation** in `packages/docs/src/content/docs/` |
| 182 | +5. **Test** with `pnpm test` |
| 183 | +6. **Lint** with `pnpm lint:fix` |
| 184 | +7. **Build** with `pnpm build` before committing |
| 185 | + |
| 186 | +## Using Components |
| 187 | + |
| 188 | +### Installation |
| 189 | + |
| 190 | +```bash |
| 191 | +npm install @scouterna/ui-webc |
| 192 | +``` |
| 193 | + |
| 194 | +### Usage |
| 195 | + |
| 196 | +```typescript |
| 197 | +// Import and register the components |
| 198 | +import { defineCustomElements } from '@scouterna/ui-webc/loader'; |
| 199 | + |
| 200 | +defineCustomElements(); |
| 201 | +``` |
| 202 | + |
| 203 | +```html |
| 204 | +<!-- Use components in your HTML --> |
| 205 | +<scout-button variant="primary">Click me</scout-button> |
| 206 | +``` |
| 207 | + |
| 208 | +## Troubleshooting |
| 209 | + |
| 210 | +### Components not loading in docs |
| 211 | + |
| 212 | +Make sure you've built the components: |
| 213 | +```bash |
| 214 | +pnpm components:build |
| 215 | +``` |
| 216 | + |
| 217 | +### Design tokens not found |
| 218 | + |
| 219 | +Build tokens first: |
| 220 | +```bash |
| 221 | +pnpm tokens:build |
| 222 | +``` |
| 223 | + |
| 224 | +### Clean start |
| 225 | + |
| 226 | +If you encounter issues, try a clean rebuild: |
| 227 | +```bash |
| 228 | +pnpm clean:install |
| 229 | +pnpm dev |
| 230 | +``` |
| 231 | + |
| 232 | +## Contributing |
| 233 | + |
| 234 | +1. Create a new component with `pnpm plop` |
| 235 | +2. Follow the existing component structure |
| 236 | +3. Update documentation with real examples |
| 237 | +4. Add tests for your component |
| 238 | +5. Run `pnpm lint:fix` before committing |
| 239 | +6. Ensure `pnpm build` succeeds |
0 commit comments