Skip to content

Commit 62084a0

Browse files
Initial setup
1 parent b95434a commit 62084a0

14 files changed

Lines changed: 127 additions & 717 deletions

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Contributing to COMPONENT-NAME
1+
# Contributing to table-sortable
22

33
Thank you for your interest in contributing! This document provides guidelines for contributing to this project.
44

README.md

Lines changed: 70 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -1,220 +1,122 @@
1-
# Web Component Starter Template
1+
# table-sortable Web Component
22

3-
A comprehensive, production-ready starter template for creating Web Components. This template is based on the architecture and best practices from my web components work.
3+
[![npm version](https://img.shields.io/npm/v/@aarongustafson/table-sortable.svg)](https://www.npmjs.com/package/@aarongustafson/table-sortable) [![Build Status](https://img.shields.io/github/actions/workflow/status/aarongustafson/table-sortable/ci.yml?branch=main)](https://github.com/aarongustafson/table-sortable/actions)
44

5-
## ✨ Features
5+
A web component to enable users to sort the data in a table based on table cell values.
66

7-
- **Modern Tooling**: Vitest, ESLint, Prettier, Happy DOM
8-
- **Best Practices**: Shadow DOM, Custom Elements v1, proper encapsulation
9-
- **Multiple Import Options**: Auto-define, manual definition, or both
10-
- **Testing**: Comprehensive test setup with coverage reporting
11-
- **CI/CD**: GitHub Actions workflows included
12-
- **Developer Experience**: Demo page, interactive setup, extensive documentation
13-
- **Publishing Ready**: npm package configuration and automated publishing workflow
7+
## Demo
148

15-
## 🚀 Quick Start
9+
[Live Demo](https://aarongustafson.github.io/table-sortable/demo/) ([Source](./demo/index.html))
1610

17-
### Use This Template
18-
19-
1. Click "Use this template" on GitHub, or:
20-
21-
```bash
22-
git clone https://github.com/aarongustafson/web-component-starter.git my-component
23-
cd my-component
24-
```
25-
26-
2. Run the interactive setup:
11+
## Installation
2712

2813
```bash
29-
npm install
30-
npm run setup
14+
npm install @aarongustafson/table-sortable
3115
```
3216

33-
The setup wizard will:
34-
- Ask for your component name (e.g., `my-awesome-component`)
35-
- Ask for a description
36-
- Rename all files automatically
37-
- Replace all placeholders in code and configuration
38-
- **Generate your component's README from template**
39-
- **Clean up template setup files** (SETUP.md, README.tpl, scripts/)
40-
- Install dependencies
41-
- Initialize git repository
17+
## Usage
4218

43-
### Manual Setup
19+
### Option 1: Auto-define the custom element (easiest)
4420

45-
If you prefer manual setup, see [SETUP.md](SETUP.md) for detailed instructions.
21+
Import the package to automatically define the `<table-sortable>` custom element:
4622

47-
## 📁 What's Included
48-
49-
```
50-
web-component-starter/
51-
├── COMPONENT-NAME.js # Component implementation
52-
├── index.js # Main entry (class + auto-define)
53-
├── define.js # Auto-define only
54-
├── custom-elements.json # Custom Elements Manifest
55-
├── package.json # Package config with scripts
56-
├── LICENSE # MIT License
57-
├── README.md # This file (replaced after setup)
58-
├── README.tpl # Template for your component's README
59-
├── .gitignore # Git ignore
60-
├── .npmignore # npm ignore
61-
├── .prettierrc # Prettier config
62-
├── .editorconfig # Editor config
63-
├── eslint.config.js # ESLint config
64-
├── vitest.config.js # Vitest config
65-
├── .github/
66-
│ ├── workflows/
67-
│ │ ├── ci.yml # Continuous integration
68-
│ │ └── publish.yml # Auto-publish to npm
69-
│ └── ISSUE_TEMPLATE/ # Bug & feature templates
70-
├── scripts/
71-
│ └── setup.js # Interactive setup wizard (removed after setup)
72-
├── test/
73-
│ ├── setup.js # Test configuration
74-
│ └── COMPONENT-NAME.test.js # Test suite
75-
├── demo/
76-
│ └── index.html # Live demo page
77-
├── SETUP.md # Manual setup guide (removed after setup)
78-
└── CONTRIBUTING.md # Contribution guidelines
23+
```javascript
24+
import '@aarongustafson/table-sortable';
7925
```
8026

81-
## 🛠️ Development
82-
83-
### Available Scripts
27+
Or use the define-only script in HTML:
8428

85-
```bash
86-
npm run setup # Interactive setup wizard
87-
npm test # Run tests in watch mode
88-
npm run test:run # Run tests once
89-
npm run test:ui # Open Vitest UI
90-
npm run test:coverage # Generate coverage report
91-
npm run lint # Lint with ESLint + Prettier
92-
npm run format # Auto-fix linting issues
29+
```html
30+
<script src="./node_modules/@aarongustafson/table-sortable/define.js" type="module"></script>
9331
```
9432

95-
### Component Architecture
96-
97-
This template provides three flexible import options:
33+
### Option 2: Import the class and define manually
9834

99-
**Option 1: Auto-define (easiest)**
100-
```javascript
101-
import '@yourscope/component-name';
102-
// Element is automatically registered
103-
```
35+
Import the class and define the custom element with your preferred tag name:
10436

105-
**Option 2: Manual registration**
10637
```javascript
107-
import { ComponentNameElement } from '@yourscope/component-name/component-name.js';
108-
customElements.define('my-custom-name', ComponentNameElement);
109-
```
38+
import { TableSortableElement } from '@aarongustafson/table-sortable/table-sortable.js';
11039

111-
**Option 3: Both**
112-
```javascript
113-
import { ComponentNameElement } from '@yourscope/component-name';
114-
// Element is registered AND class is available for extension
40+
customElements.define('my-custom-name', TableSortableElement);
11541
```
11642

117-
## 🧪 Testing
43+
### Basic Example
11844

119-
Includes:
120-
- **Vitest**: Fast, modern test runner
121-
- **Happy DOM**: Lightweight browser environment
122-
- **Testing Library**: DOM testing utilities
123-
- **Coverage**: V8 coverage reporting
124-
- **UI**: Interactive test debugging
125-
126-
Example:
127-
```javascript
128-
import { describe, it, expect } from 'vitest';
129-
130-
describe('MyComponent', () => {
131-
it('should render', () => {
132-
const el = document.createElement('my-component');
133-
expect(el).toBeInstanceOf(HTMLElement);
134-
});
135-
});
45+
```html
46+
<table-sortable>
47+
<!-- Your content here -->
48+
</table-sortable>
13649
```
13750

138-
## 📦 Publishing
51+
## Attributes
13952

140-
### Setup Automated Publishing with OIDC (Recommended)
53+
| Attribute | Type | Default | Description |
54+
|-----------|------|---------|-------------|
55+
| `example-attribute` | `string` | `""` | Description of the attribute |
14156

142-
This template is configured to publish to npm using OpenID Connect (OIDC), which is more secure than using long-lived NPM tokens.
57+
## Events
14358

144-
**Initial Setup:**
59+
The component fires custom events that you can listen to:
14560

146-
1. Publish your package to npm manually the first time:
147-
```bash
148-
npm run test:run # Ensure tests pass
149-
npm run lint # Ensure code is clean
150-
npm publish # First publish must be manual
151-
```
61+
| Event | Description | Detail |
62+
|-------|-------------|--------|
63+
| `table-sortable:event` | Fired when something happens | `{ data }` |
15264

153-
2. Configure OIDC on npm:
154-
- Visit your package's access page: `https://www.npmjs.com/package/@yourscope/your-component-name/access`
155-
- Under "Publishing Access", click "Configure OIDC"
156-
- Add GitHub Actions as a trusted publisher with these settings:
157-
- **Provider**: GitHub
158-
- **Organization/Username**: Your GitHub username or organization
159-
- **Repository**: Your repository name
160-
- **Workflow**: `.github/workflows/publish.yml`
161-
- **Environment**: Leave blank (unless you use GitHub environments)
65+
### Example Event Handling
16266

163-
3. Create a GitHub release to trigger automated publishing:
164-
- Use `npm version` to update version and create a tag: `npm version patch` (or `minor`/`major`)
165-
- Push with tags: `git push --follow-tags`
166-
- Or create a release through GitHub's UI
67+
```javascript
68+
const element = document.querySelector('table-sortable');
16769

168-
The GitHub Actions workflow (`.github/workflows/publish.yml`) will automatically publish to npm when you create a new version tag.
70+
element.addEventListener('table-sortable:event', (event) => {
71+
console.log('Event fired:', event.detail);
72+
});
73+
```
16974

170-
### Manual Publishing
75+
## CSS Custom Properties
17176

172-
If you prefer to publish manually without automation:
77+
| Property | Default | Description |
78+
|----------|---------|-------------|
79+
| `--example-color` | `#000` | Example color property |
17380

174-
```bash
175-
npm run test:run # Ensure tests pass
176-
npm run lint # Ensure code is clean
177-
npm publish # Publish to npm
81+
### Example Styling
82+
83+
```css
84+
table-sortable {
85+
--example-color: #ff0000;
86+
}
17887
```
17988

180-
## 🌐 Browser Support
89+
## Browser Support
18190

182-
Works in all modern browsers supporting:
91+
This component uses modern web standards:
18392
- Custom Elements v1
18493
- Shadow DOM v1
18594
- ES Modules
18695

187-
For legacy browsers, use polyfills.
188-
189-
## 📚 Documentation
190-
191-
- [SETUP.md](SETUP.md) - Detailed setup instructions (removed after setup)
192-
- [CONTRIBUTING.md](CONTRIBUTING.md) - Contribution guidelines
193-
- [LICENSE](LICENSE) - MIT License
194-
195-
## 🎯 Use Cases
96+
For older browsers, you may need polyfills.
19697

197-
Perfect for:
198-
- Reusable UI components
199-
- Design system elements
200-
- Form controls and widgets
201-
- Interactive content blocks
202-
- Accessibility-enhanced components
98+
## Development
20399

204-
## 🙏 Credits
100+
```bash
101+
# Install dependencies
102+
npm install
205103

206-
Based on best practices from:
207-
- [form-obfuscator](https://github.com/aarongustafson/form-obfuscator) by Aaron Gustafson
208-
- [Open Web Components](https://open-wc.org/)
104+
# Run tests
105+
npm test
209106

210-
## 📄 License
107+
# Run tests with coverage
108+
npm run test:coverage
211109

212-
MIT - See [LICENSE](LICENSE)
110+
# Lint code
111+
npm run lint
213112

214-
## 🤝 Contributing
113+
# Format code
114+
npm run format
215115

216-
Contributions welcome! See [CONTRIBUTING.md](CONTRIBUTING.md)
116+
# View demo
117+
open demo/index.html
118+
```
217119

218-
---
120+
## License
219121

220-
**Ready to build your web component?** Run `npm run setup` to get started! 🚀
122+
MIT © [Aaron Gustafson](https://www.aaron-gustafson.com/)

0 commit comments

Comments
 (0)