-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathREADME.tpl
More file actions
126 lines (83 loc) · 2.78 KB
/
README.tpl
File metadata and controls
126 lines (83 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# COMPONENT-NAME Web Component
[](https://www.npmjs.com/package/@aarongustafson/COMPONENT-NAME) [](https://github.com/aarongustafson/COMPONENT-NAME/actions)
COMPONENT_DESCRIPTION
## Demo
[Live Demo](https://aarongustafson.github.io/COMPONENT-NAME/demo/) ([Source](./demo/index.html))
Additional demos:
- [ESM CDN Demo](https://aarongustafson.github.io/COMPONENT-NAME/demo/esm.html) ([Source](./demo/esm.html))
- [Unpkg CDN Demo](https://aarongustafson.github.io/COMPONENT-NAME/demo/unpkg.html) ([Source](./demo/unpkg.html))
## Installation
```bash
npm install @aarongustafson/COMPONENT-NAME
```
## Usage
### Option 1: Auto-define the custom element (easiest)
Import the package to automatically define the `<COMPONENT-NAME>` custom element:
```javascript
import '@aarongustafson/COMPONENT-NAME';
```
Or use the define-only script in HTML:
```html
<script src="./node_modules/@aarongustafson/COMPONENT-NAME/define.js" type="module"></script>
```
### Option 2: Import the class and define manually
Import the class and define the custom element with your preferred tag name:
```javascript
import { ComponentNameElement } from '@aarongustafson/COMPONENT-NAME/COMPONENT-NAME.js';
customElements.define('my-custom-name', ComponentNameElement);
```
### Basic Example
```html
<COMPONENT-NAME>
<!-- Your content here -->
</COMPONENT-NAME>
```
## Attributes
| Attribute | Type | Default | Description |
|-----------|------|---------|-------------|
| `example-attribute` | `string` | `""` | Description of the attribute |
## Events
The component fires custom events that you can listen to:
| Event | Description | Detail |
|-------|-------------|--------|
| `COMPONENT-NAME:event` | Fired when something happens | `{ data }` |
### Example Event Handling
```javascript
const element = document.querySelector('COMPONENT-NAME');
element.addEventListener('COMPONENT-NAME:event', (event) => {
console.log('Event fired:', event.detail);
});
```
## CSS Custom Properties
| Property | Default | Description |
|----------|---------|-------------|
| `--example-color` | `#000` | Example color property |
### Example Styling
```css
COMPONENT-NAME {
--example-color: #ff0000;
}
```
## Browser Support
This component uses modern web standards:
- Custom Elements v1
- Shadow DOM v1
- ES Modules
For older browsers, you may need polyfills.
## Development
```bash
# Install dependencies
npm install
# Run tests
npm test
# Run tests with coverage
npm run test:coverage
# Lint code
npm run lint
# Format code
npm run format
# View demo
open demo/index.html
```
## License
MIT © [Aaron Gustafson](https://www.aaron-gustafson.com/)