kempo-ui 0.0.81 → 0.0.83
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -13,12 +13,13 @@ Use this skill any time you are asked to create a new component or add a new cus
|
|
|
13
13
|
|
|
14
14
|
## Overview
|
|
15
15
|
|
|
16
|
-
Creating a component involves
|
|
16
|
+
Creating a component involves five steps:
|
|
17
17
|
|
|
18
18
|
1. **Choose the base component** — pick the right rendering strategy
|
|
19
19
|
2. **Write the source file** in `src/components/`
|
|
20
20
|
3. **Register the custom element** at the bottom of the source file
|
|
21
21
|
4. **Add documentation** in `docs/components/`
|
|
22
|
+
5. **Write and run unit tests** in `tests/components/`
|
|
22
23
|
|
|
23
24
|
---
|
|
24
25
|
|
|
@@ -193,6 +194,72 @@ Key requirements:
|
|
|
193
194
|
|
|
194
195
|
---
|
|
195
196
|
|
|
197
|
+
## Step 5: Write and Run Unit Tests
|
|
198
|
+
|
|
199
|
+
Create `tests/components/MyComponent.browser-test.js`. Use an existing test file (e.g. `tests/components/Toggle.browser-test.js`) as a reference.
|
|
200
|
+
|
|
201
|
+
Key conventions:
|
|
202
|
+
- Import the component class at the top.
|
|
203
|
+
- Define an async `createMyComponent()` helper that builds the DOM, appends it to `document.body`, awaits `el.updateComplete`, and returns `{ container, el }`.
|
|
204
|
+
- Define a `cleanup(container)` helper that removes the container from the DOM.
|
|
205
|
+
- Export a default plain object where each key is a test description and each value is an `async ({pass, fail}) => {}` function.
|
|
206
|
+
- Always call `cleanup(container)` before every `pass()` or `fail()` call.
|
|
207
|
+
- Use multi-line comments to group related tests (e.g. `/* Element Creation */`, `/* Properties */`).
|
|
208
|
+
|
|
209
|
+
Tests to include at minimum:
|
|
210
|
+
- Element is created and is an instance of the component class
|
|
211
|
+
- Element has a shadow root
|
|
212
|
+
- Default property values are correct
|
|
213
|
+
- Attribute reflection works (if applicable)
|
|
214
|
+
- Public methods behave correctly
|
|
215
|
+
- Events are dispatched correctly (if applicable)
|
|
216
|
+
|
|
217
|
+
Example skeleton:
|
|
218
|
+
|
|
219
|
+
```javascript
|
|
220
|
+
import MyComponent from '../../src/components/MyComponent.js';
|
|
221
|
+
|
|
222
|
+
const createMyComponent = async () => {
|
|
223
|
+
const container = document.createElement('div');
|
|
224
|
+
container.innerHTML = `<k-my-component></k-my-component>`;
|
|
225
|
+
document.body.appendChild(container);
|
|
226
|
+
const el = container.querySelector('k-my-component');
|
|
227
|
+
await el.updateComplete;
|
|
228
|
+
return { container, el };
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
const cleanup = (container) => {
|
|
232
|
+
if(container && container.parentNode){
|
|
233
|
+
container.parentNode.removeChild(container);
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
export default {
|
|
238
|
+
/*
|
|
239
|
+
Element Creation
|
|
240
|
+
*/
|
|
241
|
+
'should create my-component element': async ({pass, fail}) => {
|
|
242
|
+
const { container, el } = await createMyComponent();
|
|
243
|
+
if(!(el instanceof MyComponent)){
|
|
244
|
+
cleanup(container);
|
|
245
|
+
return fail('Element should be instance of MyComponent');
|
|
246
|
+
}
|
|
247
|
+
cleanup(container);
|
|
248
|
+
pass('MyComponent element created correctly');
|
|
249
|
+
},
|
|
250
|
+
};
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
After writing the tests, run them to confirm they all pass:
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
npm run test -- MyComponent
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
The partial string `MyComponent` will match any test file whose path contains that string. Fix any failures before considering the component complete.
|
|
260
|
+
|
|
261
|
+
---
|
|
262
|
+
|
|
196
263
|
## Component Architecture and Communication
|
|
197
264
|
|
|
198
265
|
- Use **methods** to trigger actions. Events notify that something already happened; they should not be used to trigger logic.
|
package/package.json
CHANGED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import FilterItem from '../../src/components/FilterItem.js';
|
|
2
|
+
|
|
3
|
+
const createFilterItem = async (content = 'item') => {
|
|
4
|
+
const container = document.createElement('div');
|
|
5
|
+
container.innerHTML = `<k-filter-item>${content}</k-filter-item>`;
|
|
6
|
+
document.body.appendChild(container);
|
|
7
|
+
const el = container.querySelector('k-filter-item');
|
|
8
|
+
await el.updateComplete;
|
|
9
|
+
return { container, el };
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const cleanup = (container) => {
|
|
13
|
+
if(container && container.parentNode){
|
|
14
|
+
container.parentNode.removeChild(container);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default {
|
|
19
|
+
/*
|
|
20
|
+
Element Creation
|
|
21
|
+
*/
|
|
22
|
+
'should create filter-item element': async ({pass, fail}) => {
|
|
23
|
+
const { container, el } = await createFilterItem();
|
|
24
|
+
if(!el){
|
|
25
|
+
cleanup(container);
|
|
26
|
+
return fail('k-filter-item element should be created');
|
|
27
|
+
}
|
|
28
|
+
if(!(el instanceof FilterItem)){
|
|
29
|
+
cleanup(container);
|
|
30
|
+
return fail('Element should be instance of FilterItem');
|
|
31
|
+
}
|
|
32
|
+
cleanup(container);
|
|
33
|
+
pass('FilterItem element created correctly');
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
'should have shadow root': async ({pass, fail}) => {
|
|
37
|
+
const { container, el } = await createFilterItem();
|
|
38
|
+
if(!el.shadowRoot){
|
|
39
|
+
cleanup(container);
|
|
40
|
+
return fail('FilterItem should have shadow root');
|
|
41
|
+
}
|
|
42
|
+
cleanup(container);
|
|
43
|
+
pass('FilterItem has shadow root');
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
/*
|
|
47
|
+
Visibility
|
|
48
|
+
*/
|
|
49
|
+
'should be visible by default': async ({pass, fail}) => {
|
|
50
|
+
const { container, el } = await createFilterItem();
|
|
51
|
+
if(el.hidden){
|
|
52
|
+
cleanup(container);
|
|
53
|
+
return fail('FilterItem should be visible by default');
|
|
54
|
+
}
|
|
55
|
+
cleanup(container);
|
|
56
|
+
pass('FilterItem is visible by default');
|
|
57
|
+
},
|
|
58
|
+
|
|
59
|
+
'setting hidden should hide the element': async ({pass, fail}) => {
|
|
60
|
+
const { container, el } = await createFilterItem();
|
|
61
|
+
el.hidden = true;
|
|
62
|
+
await el.updateComplete;
|
|
63
|
+
const style = getComputedStyle(el);
|
|
64
|
+
if(style.display !== 'none'){
|
|
65
|
+
cleanup(container);
|
|
66
|
+
return fail(`Expected display:none when hidden, got ${style.display}`);
|
|
67
|
+
}
|
|
68
|
+
cleanup(container);
|
|
69
|
+
pass('FilterItem is hidden when hidden attribute is set');
|
|
70
|
+
},
|
|
71
|
+
|
|
72
|
+
'removing hidden should show the element': async ({pass, fail}) => {
|
|
73
|
+
const { container, el } = await createFilterItem();
|
|
74
|
+
el.hidden = true;
|
|
75
|
+
await el.updateComplete;
|
|
76
|
+
el.hidden = false;
|
|
77
|
+
await el.updateComplete;
|
|
78
|
+
const style = getComputedStyle(el);
|
|
79
|
+
if(style.display === 'none'){
|
|
80
|
+
cleanup(container);
|
|
81
|
+
return fail('FilterItem should be visible after removing hidden');
|
|
82
|
+
}
|
|
83
|
+
cleanup(container);
|
|
84
|
+
pass('FilterItem is visible after removing hidden');
|
|
85
|
+
},
|
|
86
|
+
|
|
87
|
+
/*
|
|
88
|
+
filter-keywords attribute
|
|
89
|
+
*/
|
|
90
|
+
'should accept filter-keywords attribute': async ({pass, fail}) => {
|
|
91
|
+
const container = document.createElement('div');
|
|
92
|
+
container.innerHTML = `<k-filter-item filter-keywords="foo bar">content</k-filter-item>`;
|
|
93
|
+
document.body.appendChild(container);
|
|
94
|
+
const el = container.querySelector('k-filter-item');
|
|
95
|
+
await el.updateComplete;
|
|
96
|
+
const kw = el.getAttribute('filter-keywords');
|
|
97
|
+
if(kw !== 'foo bar'){
|
|
98
|
+
cleanup(container);
|
|
99
|
+
return fail(`Expected filter-keywords "foo bar", got "${kw}"`);
|
|
100
|
+
}
|
|
101
|
+
cleanup(container);
|
|
102
|
+
pass('filter-keywords attribute set correctly');
|
|
103
|
+
},
|
|
104
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import FilterList from '../../src/components/FilterList.js';
|
|
2
|
+
import '../../src/components/FilterItem.js';
|
|
3
|
+
|
|
4
|
+
const createFilterList = async (items = []) => {
|
|
5
|
+
const container = document.createElement('div');
|
|
6
|
+
container.innerHTML = `<k-filter-list>${items.map(kw => `<k-filter-item filter-keywords="${kw}">${kw}</k-filter-item>`).join('')}</k-filter-list>`;
|
|
7
|
+
document.body.appendChild(container);
|
|
8
|
+
const el = container.querySelector('k-filter-list');
|
|
9
|
+
await el.updateComplete;
|
|
10
|
+
return { container, el };
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const cleanup = (container) => {
|
|
14
|
+
if(container && container.parentNode){
|
|
15
|
+
container.parentNode.removeChild(container);
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export default {
|
|
20
|
+
/*
|
|
21
|
+
Element Creation
|
|
22
|
+
*/
|
|
23
|
+
'should create filter-list element': async ({pass, fail}) => {
|
|
24
|
+
const { container, el } = await createFilterList();
|
|
25
|
+
if(!el){
|
|
26
|
+
cleanup(container);
|
|
27
|
+
return fail('k-filter-list element should be created');
|
|
28
|
+
}
|
|
29
|
+
if(!(el instanceof FilterList)){
|
|
30
|
+
cleanup(container);
|
|
31
|
+
return fail('Element should be instance of FilterList');
|
|
32
|
+
}
|
|
33
|
+
cleanup(container);
|
|
34
|
+
pass('FilterList element created correctly');
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
'should have shadow root': async ({pass, fail}) => {
|
|
38
|
+
const { container, el } = await createFilterList();
|
|
39
|
+
if(!el.shadowRoot){
|
|
40
|
+
cleanup(container);
|
|
41
|
+
return fail('FilterList should have shadow root');
|
|
42
|
+
}
|
|
43
|
+
cleanup(container);
|
|
44
|
+
pass('FilterList has shadow root');
|
|
45
|
+
},
|
|
46
|
+
|
|
47
|
+
/*
|
|
48
|
+
filter() — empty term
|
|
49
|
+
*/
|
|
50
|
+
'filter("") should show all items': async ({pass, fail}) => {
|
|
51
|
+
const { container, el } = await createFilterList(['apple', 'banana', 'cherry']);
|
|
52
|
+
el.filter('');
|
|
53
|
+
const items = [...el.querySelectorAll('k-filter-item')];
|
|
54
|
+
const hidden = items.filter(i => i.hidden);
|
|
55
|
+
if(hidden.length !== 0){
|
|
56
|
+
cleanup(container);
|
|
57
|
+
return fail(`Expected 0 hidden items, got ${hidden.length}`);
|
|
58
|
+
}
|
|
59
|
+
cleanup(container);
|
|
60
|
+
pass('All items visible when term is empty');
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
/*
|
|
64
|
+
filter() — single word
|
|
65
|
+
*/
|
|
66
|
+
'filter("apple") should hide non-matching items': async ({pass, fail}) => {
|
|
67
|
+
const { container, el } = await createFilterList(['apple', 'banana', 'cherry']);
|
|
68
|
+
el.filter('apple');
|
|
69
|
+
const banana = el.querySelector('[filter-keywords="banana"]');
|
|
70
|
+
const cherry = el.querySelector('[filter-keywords="cherry"]');
|
|
71
|
+
if(!banana.hidden || !cherry.hidden){
|
|
72
|
+
cleanup(container);
|
|
73
|
+
return fail('Non-matching items should be hidden');
|
|
74
|
+
}
|
|
75
|
+
cleanup(container);
|
|
76
|
+
pass('Non-matching items are hidden');
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
'filter("apple") should show matching item': async ({pass, fail}) => {
|
|
80
|
+
const { container, el } = await createFilterList(['apple', 'banana', 'cherry']);
|
|
81
|
+
el.filter('apple');
|
|
82
|
+
const apple = el.querySelector('[filter-keywords="apple"]');
|
|
83
|
+
if(apple.hidden){
|
|
84
|
+
cleanup(container);
|
|
85
|
+
return fail('Matching item should not be hidden');
|
|
86
|
+
}
|
|
87
|
+
cleanup(container);
|
|
88
|
+
pass('Matching item is visible');
|
|
89
|
+
},
|
|
90
|
+
|
|
91
|
+
/*
|
|
92
|
+
filter() — multi-word (AND logic)
|
|
93
|
+
*/
|
|
94
|
+
'filter("apple pie") should require all words to match': async ({pass, fail}) => {
|
|
95
|
+
const { container, el } = await createFilterList(['apple pie', 'apple', 'pie']);
|
|
96
|
+
el.filter('apple pie');
|
|
97
|
+
const applePie = el.querySelector('[filter-keywords="apple pie"]');
|
|
98
|
+
const appleOnly = el.querySelector('[filter-keywords="apple"]');
|
|
99
|
+
const pieOnly = el.querySelector('[filter-keywords="pie"]');
|
|
100
|
+
if(applePie.hidden){
|
|
101
|
+
cleanup(container);
|
|
102
|
+
return fail('Item matching all words should be visible');
|
|
103
|
+
}
|
|
104
|
+
if(!appleOnly.hidden || !pieOnly.hidden){
|
|
105
|
+
cleanup(container);
|
|
106
|
+
return fail('Items matching only one word should be hidden');
|
|
107
|
+
}
|
|
108
|
+
cleanup(container);
|
|
109
|
+
pass('Multi-word filter requires all words to match');
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
/*
|
|
113
|
+
filter() — case insensitivity
|
|
114
|
+
*/
|
|
115
|
+
'filter() should be case-insensitive': async ({pass, fail}) => {
|
|
116
|
+
const { container, el } = await createFilterList(['Apple', 'banana']);
|
|
117
|
+
el.filter('APPLE');
|
|
118
|
+
const apple = el.querySelector('[filter-keywords="Apple"]');
|
|
119
|
+
if(apple.hidden){
|
|
120
|
+
cleanup(container);
|
|
121
|
+
return fail('Matching should be case-insensitive');
|
|
122
|
+
}
|
|
123
|
+
cleanup(container);
|
|
124
|
+
pass('filter() is case-insensitive');
|
|
125
|
+
},
|
|
126
|
+
|
|
127
|
+
/*
|
|
128
|
+
filter() — no keywords attribute
|
|
129
|
+
*/
|
|
130
|
+
'items with no filter-keywords should be hidden when term is provided': async ({pass, fail}) => {
|
|
131
|
+
const container = document.createElement('div');
|
|
132
|
+
container.innerHTML = `<k-filter-list><k-filter-item>no keywords</k-filter-item></k-filter-list>`;
|
|
133
|
+
document.body.appendChild(container);
|
|
134
|
+
const el = container.querySelector('k-filter-list');
|
|
135
|
+
await el.updateComplete;
|
|
136
|
+
el.filter('something');
|
|
137
|
+
const item = el.querySelector('k-filter-item');
|
|
138
|
+
if(!item.hidden){
|
|
139
|
+
cleanup(container);
|
|
140
|
+
return fail('Item with no keywords should be hidden when term is given');
|
|
141
|
+
}
|
|
142
|
+
cleanup(container);
|
|
143
|
+
pass('Item with no keywords is hidden when term is provided');
|
|
144
|
+
},
|
|
145
|
+
|
|
146
|
+
/*
|
|
147
|
+
filter() — restore all after filtering
|
|
148
|
+
*/
|
|
149
|
+
'filter("") after filtering should restore all items': async ({pass, fail}) => {
|
|
150
|
+
const { container, el } = await createFilterList(['apple', 'banana']);
|
|
151
|
+
el.filter('apple');
|
|
152
|
+
el.filter('');
|
|
153
|
+
const items = [...el.querySelectorAll('k-filter-item')];
|
|
154
|
+
const hidden = items.filter(i => i.hidden);
|
|
155
|
+
if(hidden.length !== 0){
|
|
156
|
+
cleanup(container);
|
|
157
|
+
return fail(`Expected all items visible after clearing filter, got ${hidden.length} hidden`);
|
|
158
|
+
}
|
|
159
|
+
cleanup(container);
|
|
160
|
+
pass('All items restored after clearing filter');
|
|
161
|
+
},
|
|
162
|
+
};
|
package/CONTRIBUTING.md
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
# Code Contribution Guidelines
|
|
2
|
-
|
|
3
|
-
## Project Structure
|
|
4
|
-
|
|
5
|
-
- All code should be in the `src/` directory, with the exception of npm scripts.
|
|
6
|
-
- All components should be in the `src/components/` directory.
|
|
7
|
-
- All utility function module files should be in the `src/utils/` directory.
|
|
8
|
-
- All documnentation should be in the `docs/` directory. This directory is used by GitHub as the "GitHub Pages", so all links need to be relative, and there will be a build script which copies all code to the `docs/` directory.
|
|
9
|
-
|
|
10
|
-
## Coding Style Guidelines
|
|
11
|
-
|
|
12
|
-
### Code Organization
|
|
13
|
-
Use multi-line comments to separate code into logical sections. Group related functionality together.
|
|
14
|
-
- Example: In Lit components, group lifecycle callbacks, event handlers, public methods, utility functions, and rendering logic separately.
|
|
15
|
-
|
|
16
|
-
```javascript
|
|
17
|
-
/*
|
|
18
|
-
Lifecycle Callbacks
|
|
19
|
-
*/
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
### Avoid single-use variables/functions
|
|
23
|
-
Avoid defining a variable or function to only use it once; inline the logic where needed. Some exceptions include:
|
|
24
|
-
- recursion
|
|
25
|
-
- scope encapsulation (IIFE)
|
|
26
|
-
- context changes
|
|
27
|
-
|
|
28
|
-
### Minimal Comments, Empty Lines, and Spacing
|
|
29
|
-
|
|
30
|
-
Use minimal comments. Assume readers understand the language. Some exceptions include:
|
|
31
|
-
- complex logic
|
|
32
|
-
- anti-patterns
|
|
33
|
-
- code organization
|
|
34
|
-
|
|
35
|
-
Do not put random empty lines within code; put them where they make sense for readability, for example:
|
|
36
|
-
- above and below definitions for functions and classes.
|
|
37
|
-
- to help break up large sections of logic to be more readable. If there are 100 lines of code with no breaks, it gets hard to read.
|
|
38
|
-
- above multi-line comments to indicate the comment belongs to the code below
|
|
39
|
-
|
|
40
|
-
No empty lines in css.
|
|
41
|
-
|
|
42
|
-
End each file with an empty line.
|
|
43
|
-
|
|
44
|
-
End each line with a `;` when possible, even if it is optional.
|
|
45
|
-
|
|
46
|
-
Avoid unnecessary spacing, for example:
|
|
47
|
-
- after the word `if`
|
|
48
|
-
- within parentheses for conditional statements
|
|
49
|
-
|
|
50
|
-
```javascript
|
|
51
|
-
let count = 1;
|
|
52
|
-
|
|
53
|
-
const incrementOdd = (n) => {
|
|
54
|
-
if(n % 2 !== 0){
|
|
55
|
-
return n++;
|
|
56
|
-
}
|
|
57
|
-
return n;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
count = incrementOdd(count);
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
### Prefer Arrow Functions
|
|
64
|
-
Prefer the use of arrow functions when possible, especially for class methods to avoid binding. Use normal functions if needed for preserving the proper context.
|
|
65
|
-
- For very basic logic, use implicit returns
|
|
66
|
-
- If there is a single parameter, omit the parentheses.
|
|
67
|
-
```javascript
|
|
68
|
-
const addOne = n => n + 1;
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### Module Exports
|
|
72
|
-
- If a module has only one export, use the "default" export, not a named export.
|
|
73
|
-
- Do not declare the default export as a const or give it a name; just export the value.
|
|
74
|
-
|
|
75
|
-
```javascript
|
|
76
|
-
export default (n) => n + 1;
|
|
77
|
-
```
|
|
78
|
-
- If a module has multiple exports, use named exports and do not use a "default" export.
|
|
79
|
-
|
|
80
|
-
### Code Reuse
|
|
81
|
-
Create utility functions for shared logic.
|
|
82
|
-
- If the shared logic is used in a single file, define a utility function in that file.
|
|
83
|
-
- If the shared logic is used in multiple files, create a utility function module file in `src/utils/`.
|
|
84
|
-
|
|
85
|
-
### Naming
|
|
86
|
-
Do not prefix identifiers with underscores.
|
|
87
|
-
- Never use leading underscores (`_`) for variable, property, method, or function names.
|
|
88
|
-
- Use clear, descriptive names without prefixes.
|
|
89
|
-
- When true privacy is needed inside classes, prefer native JavaScript private fields (e.g., `#myField`) instead of simulated privacy via underscores.
|
|
90
|
-
|
|
91
|
-
## Components
|
|
92
|
-
|
|
93
|
-
### Base Component Architecture
|
|
94
|
-
|
|
95
|
-
The project provides three base components for different rendering strategies. Choose the appropriate base component and extend it:
|
|
96
|
-
|
|
97
|
-
#### ShadowComponent
|
|
98
|
-
For components that need shadow DOM encapsulation and automatic `/kempo.css` stylesheet injection.
|
|
99
|
-
|
|
100
|
-
```javascript
|
|
101
|
-
import ShadowComponent from './ShadowComponent.js';
|
|
102
|
-
|
|
103
|
-
export default class MyComponent extends ShadowComponent {
|
|
104
|
-
render() {
|
|
105
|
-
return html`<p>Shadow DOM content with scoped styles</p>`;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
```
|
|
109
|
-
|
|
110
|
-
#### LightComponent
|
|
111
|
-
For components that render directly to light DOM without shadow DOM encapsulation.
|
|
112
|
-
|
|
113
|
-
```javascript
|
|
114
|
-
import LightComponent from './LightComponent.js';
|
|
115
|
-
|
|
116
|
-
export default class MyComponent extends LightComponent {
|
|
117
|
-
renderLightDom() {
|
|
118
|
-
return html`<p>Light DOM content</p>`;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
#### HybridComponent
|
|
124
|
-
For components that need both shadow DOM (with automatic `/kempo.css`) and light DOM rendering.
|
|
125
|
-
|
|
126
|
-
```javascript
|
|
127
|
-
import HybridComponent from './HybridComponent.js';
|
|
128
|
-
|
|
129
|
-
export default class MyComponent extends HybridComponent {
|
|
130
|
-
render() {
|
|
131
|
-
return html`<p>Shadow DOM content</p>`;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
renderLightDom() {
|
|
135
|
-
return html`<p>Light DOM content alongside natural children</p>`;
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
**Important:** Always call `super.updated()` when overriding the `updated()` method in LightComponent or HybridComponent to ensure proper rendering.
|
|
141
|
-
|
|
142
|
-
### Component Architecture and Communication
|
|
143
|
-
|
|
144
|
-
- Use methods to cause actions; do not emit events to trigger logic. Events are for notifying that something already happened.
|
|
145
|
-
- Prefer `el.closest('ktf-test-framework')?.enqueueSuite({...})` over firing an `enqueue` event.
|
|
146
|
-
|
|
147
|
-
- Wrap dependent components inside a parent `ktf-test-framework` element. Children find it via `closest('ktf-test-framework')` and call its methods. The framework can query its subtree to orchestrate children.
|
|
148
|
-
|
|
149
|
-
- Avoid `window` globals and global custom events for coordination. If broadcast is needed, scope events to the framework element; reserve window events for global, non-visual concerns (e.g., settings changes).
|
|
150
|
-
|
|
151
|
-
## Development Workflow
|
|
152
|
-
|
|
153
|
-
### NPM Scripts
|
|
154
|
-
|
|
155
|
-
#### Build
|
|
156
|
-
```bash
|
|
157
|
-
npm run build
|
|
158
|
-
```
|
|
159
|
-
Compiles and minifies source files from `src/` and copies all necessary files to the `docs/` directory for GitHub Pages deployment.
|
|
160
|
-
|
|
161
|
-
#### Documentation Server
|
|
162
|
-
```bash
|
|
163
|
-
npm run docs
|
|
164
|
-
```
|
|
165
|
-
Starts a local development server and opens the documentation site. Automatically runs the build script first.
|
|
166
|
-
|
|
167
|
-
**Variants:**
|
|
168
|
-
- `npm run docs:src` - Serves from `src/` instead of `docs/` for development
|
|
169
|
-
- `npm run docs:no-build` - Skips the build step and serves existing `docs/`
|
|
170
|
-
|
|
171
|
-
#### Testing
|
|
172
|
-
```bash
|
|
173
|
-
npm test # Run all tests
|
|
174
|
-
npm run test:gui # Run tests with GUI interface
|
|
175
|
-
npm run test:browser # Run browser-only tests
|
|
176
|
-
npm run test:node # Run Node.js-only tests
|
|
177
|
-
```
|
|
178
|
-
|
|
179
|
-
#### Update Kempo CSS
|
|
180
|
-
```bash
|
|
181
|
-
npm run update-kempo-css
|
|
182
|
-
```
|
|
183
|
-
Downloads the latest version of Kempo CSS from the CDN and updates local files.
|
|
184
|
-
|
|
185
|
-
### Adding Icons
|
|
186
|
-
|
|
187
|
-
Use the `geticon` script to download icons from [Google Material Symbols](https://fonts.google.com/icons). The script automatically formats icons and triggers a build.
|
|
188
|
-
|
|
189
|
-
#### Basic Usage
|
|
190
|
-
```bash
|
|
191
|
-
npm run geticon <icon_name>
|
|
192
|
-
```
|
|
193
|
-
|
|
194
|
-
Example:
|
|
195
|
-
```bash
|
|
196
|
-
npm run geticon format_bold
|
|
197
|
-
```
|
|
198
|
-
|
|
199
|
-
This downloads the icon and saves it as `format_bold.svg` in the `icons/` directory.
|
|
200
|
-
|
|
201
|
-
#### Custom Naming
|
|
202
|
-
|
|
203
|
-
Rename icons when downloading by providing a second argument:
|
|
204
|
-
```bash
|
|
205
|
-
npm run geticon <icon_name> <custom_name>
|
|
206
|
-
```
|
|
207
|
-
|
|
208
|
-
Example - download `content_copy` but save as `copy.svg`:
|
|
209
|
-
```bash
|
|
210
|
-
npm run geticon content_copy copy
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
#### What the Script Does
|
|
214
|
-
|
|
215
|
-
- Downloads the specified icon from Google's Material Symbols CDN
|
|
216
|
-
- Removes `width` and `height` attributes
|
|
217
|
-
- Adds `fill="currentColor"` to all `<path>` elements
|
|
218
|
-
- Saves the formatted SVG to the `icons/` directory
|
|
219
|
-
- Automatically runs the build script to copy the icon to `docs/`
|