kempo 2.6.1 → 2.6.2

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.
@@ -177,7 +177,22 @@
177
177
  <p>An array of objects that represents the fields of the table, each object must contain a <code>name</code> and a <code>label</code>. If this parameter is omitted, the fields will be automatically generated from the first 100 records.</p>
178
178
 
179
179
  <h5><code><i>object</i> controls</code></h5>
180
- <p>An object containing arrays of controls to be displayed before and/or after each row. Each control is defined by an icon name and a callback function. The <code>controls</code> object can only contain the <code>before</code> and <code>after</code> properties, which are arrays of objects containing the <code>icon</code> (string) and <code>action</code> (function).</p>
180
+ <p>An object containing optional arrays of controls to be displayed before and/or after each row. Each control is defined by an icon name and a callback function. The <code>controls</code> object can contain the optional <code>before</code> and <code>after</code> properties, which are arrays of objects containing the <code>icon</code> (string) and <code>action</code> (function).</p>
181
+ <p>Example:</p>
182
+ <pre><code class="hljs javascript">{
183
+ before: [
184
+ {
185
+ icon: 'edit',
186
+ action: (record, table) => console.log('Edit', record, table)
187
+ }
188
+ ],
189
+ after: [
190
+ {
191
+ icon: 'delete',
192
+ action: (record, table) => console.log('Delete', record, table)
193
+ }
194
+ ]
195
+ }</code></pre>
181
196
 
182
197
  <h3 id="requirements"><a href="#requirements" class="no-link">Requirements</a></h3>
183
198
  <ul>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kempo",
3
- "version": "2.6.1",
3
+ "version": "2.6.2",
4
4
  "type": "module",
5
5
  "description": "A web component library",
6
6
  "main": "dist/index.js",
@@ -26,8 +26,8 @@ export default class Table extends Component {
26
26
  return false;
27
27
  }
28
28
  renderFields(){
29
- const beforeControls = this.controls.before.length ? '<th></th>' : '';
30
- const afterControls = this.controls.after.length ? '<th></th>' : '';
29
+ const beforeControls = this.controls.before?.length ? '<th></th>' : '';
30
+ const afterControls = this.controls.after?.length ? '<th></th>' : '';
31
31
  this.shadowRoot.getElementById('fields').innerHTML = `${beforeControls}${this.fields.map(({label})=>`<th>${label}</th>`).join('')}${afterControls}`;
32
32
  }
33
33
  renderRecords(){
@@ -42,7 +42,7 @@ export default class Table extends Component {
42
42
  }).join('');
43
43
  }
44
44
 
45
- renderControls(controls, record) {
45
+ renderControls(controls = [], record) {
46
46
  if (controls.length === 0) return '';
47
47
  return `<td>${controls.map(({ icon, action }) => {
48
48
  const button = document.createElement('button');