@triptyk/ember-yeti-table 3.0.0
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.
- package/LICENSE.md +9 -0
- package/README.md +132 -0
- package/addon-main.cjs +4 -0
- package/declarations/themes/default-theme.d.ts +28 -0
- package/declarations/themes/default-theme.d.ts.map +1 -0
- package/declarations/utils/create-regex.d.ts +2 -0
- package/declarations/utils/create-regex.d.ts.map +1 -0
- package/declarations/utils/filtering-utils.d.ts +5 -0
- package/declarations/utils/filtering-utils.d.ts.map +1 -0
- package/declarations/utils/sorting-utils.d.ts +24 -0
- package/declarations/utils/sorting-utils.d.ts.map +1 -0
- package/dist/_app_/components/yeti-table/body.js +1 -0
- package/dist/_app_/components/yeti-table/header.js +1 -0
- package/dist/_app_/components/yeti-table/pagination.js +1 -0
- package/dist/_app_/components/yeti-table/table.js +1 -0
- package/dist/_app_/components/yeti-table/tbody/row/cell.js +1 -0
- package/dist/_app_/components/yeti-table/tbody/row.js +1 -0
- package/dist/_app_/components/yeti-table/tbody.js +1 -0
- package/dist/_app_/components/yeti-table/tfoot/row/cell.js +1 -0
- package/dist/_app_/components/yeti-table/tfoot/row.js +1 -0
- package/dist/_app_/components/yeti-table/tfoot.js +1 -0
- package/dist/_app_/components/yeti-table/thead/row/cell.js +1 -0
- package/dist/_app_/components/yeti-table/thead/row/column.js +1 -0
- package/dist/_app_/components/yeti-table/thead/row.js +1 -0
- package/dist/_app_/components/yeti-table/thead.js +1 -0
- package/dist/_app_/components/yeti-table.js +1 -0
- package/dist/_app_/themes/default-theme.js +1 -0
- package/dist/_app_/utils/create-regex.js +1 -0
- package/dist/_app_/utils/filtering-utils.js +1 -0
- package/dist/_app_/utils/sorting-utils.js +1 -0
- package/dist/components/yeti-table/body.js +37 -0
- package/dist/components/yeti-table/body.js.map +1 -0
- package/dist/components/yeti-table/header.js +30 -0
- package/dist/components/yeti-table/header.js.map +1 -0
- package/dist/components/yeti-table/pagination.js +86 -0
- package/dist/components/yeti-table/pagination.js.map +1 -0
- package/dist/components/yeti-table/table.js +38 -0
- package/dist/components/yeti-table/table.js.map +1 -0
- package/dist/components/yeti-table/tbody/row/cell.js +35 -0
- package/dist/components/yeti-table/tbody/row/cell.js.map +1 -0
- package/dist/components/yeti-table/tbody/row.js +47 -0
- package/dist/components/yeti-table/tbody/row.js.map +1 -0
- package/dist/components/yeti-table/tbody.js +20 -0
- package/dist/components/yeti-table/tbody.js.map +1 -0
- package/dist/components/yeti-table/tfoot/row/cell.js +31 -0
- package/dist/components/yeti-table/tfoot/row/cell.js.map +1 -0
- package/dist/components/yeti-table/tfoot/row.js +31 -0
- package/dist/components/yeti-table/tfoot/row.js.map +1 -0
- package/dist/components/yeti-table/tfoot.js +20 -0
- package/dist/components/yeti-table/tfoot.js.map +1 -0
- package/dist/components/yeti-table/thead/row/cell.js +24 -0
- package/dist/components/yeti-table/thead/row/cell.js.map +1 -0
- package/dist/components/yeti-table/thead/row/column.js +202 -0
- package/dist/components/yeti-table/thead/row/column.js.map +1 -0
- package/dist/components/yeti-table/thead/row.js +41 -0
- package/dist/components/yeti-table/thead/row.js.map +1 -0
- package/dist/components/yeti-table/thead.js +35 -0
- package/dist/components/yeti-table/thead.js.map +1 -0
- package/dist/components/yeti-table.js +618 -0
- package/dist/components/yeti-table.js.map +1 -0
- package/dist/themes/default-theme.js +51 -0
- package/dist/themes/default-theme.js.map +1 -0
- package/dist/utils/create-regex.js +34 -0
- package/dist/utils/create-regex.js.map +1 -0
- package/dist/utils/filtering-utils.js +55 -0
- package/dist/utils/filtering-utils.js.map +1 -0
- package/dist/utils/sorting-utils.js +93 -0
- package/dist/utils/sorting-utils.js.map +1 -0
- package/package.json +124 -0
- package/src/.gitkeep +0 -0
- package/src/components/yeti-table/body.gjs +94 -0
- package/src/components/yeti-table/header.gjs +54 -0
- package/src/components/yeti-table/pagination.gjs +155 -0
- package/src/components/yeti-table/table.gjs +34 -0
- package/src/components/yeti-table/tbody/row/cell.gjs +51 -0
- package/src/components/yeti-table/tbody/row.gjs +89 -0
- package/src/components/yeti-table/tbody.gjs +55 -0
- package/src/components/yeti-table/tfoot/row/cell.gjs +45 -0
- package/src/components/yeti-table/tfoot/row.gjs +44 -0
- package/src/components/yeti-table/tfoot.gjs +33 -0
- package/src/components/yeti-table/thead/row/cell.gjs +52 -0
- package/src/components/yeti-table/thead/row/column.gjs +260 -0
- package/src/components/yeti-table/thead/row.gjs +71 -0
- package/src/components/yeti-table/thead.gjs +45 -0
- package/src/components/yeti-table.gjs +780 -0
- package/src/themes/default-theme.js +53 -0
- package/src/utils/create-regex.js +65 -0
- package/src/utils/filtering-utils.js +75 -0
- package/src/utils/sorting-utils.js +108 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { action } from '@ember/object';
|
|
2
|
+
|
|
3
|
+
import Component from '@glimmer/component';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
Renders a `<thead>` element and yields the column component.
|
|
7
|
+
```hbs
|
|
8
|
+
<table.header as |header|>
|
|
9
|
+
<header.column @prop="firstName">
|
|
10
|
+
First name
|
|
11
|
+
</header.column>
|
|
12
|
+
<header.column @prop="lastName">
|
|
13
|
+
Last name
|
|
14
|
+
</header.column>
|
|
15
|
+
<header.column @prop="points">
|
|
16
|
+
Points
|
|
17
|
+
</header.column>
|
|
18
|
+
</table.header>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
@class Header
|
|
22
|
+
@yield {object} header
|
|
23
|
+
@yield {Component} header.column the column component
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
import THead from './thead/row/column.gjs';
|
|
27
|
+
import { hash } from '@ember/helper';
|
|
28
|
+
|
|
29
|
+
export default class Header extends Component {
|
|
30
|
+
<template>
|
|
31
|
+
<thead class={{@theme.thead}} ...attributes>
|
|
32
|
+
<tr class="{{@trClass}} {{@theme.theadRow}} {{@theme.row}}">
|
|
33
|
+
{{yield
|
|
34
|
+
(hash
|
|
35
|
+
column=(component
|
|
36
|
+
THead
|
|
37
|
+
sortable=@sortable
|
|
38
|
+
sortSequence=@sortSequence
|
|
39
|
+
onClick=this.onColumnClickHeader
|
|
40
|
+
parent=@parent
|
|
41
|
+
theme=@theme
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
}}
|
|
45
|
+
</tr>
|
|
46
|
+
</thead>
|
|
47
|
+
</template>
|
|
48
|
+
@action
|
|
49
|
+
onColumnClickHeader(column, e) {
|
|
50
|
+
if (this.args.onColumnClick && column.sortable) {
|
|
51
|
+
this.args.onColumnClick(column, e);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { action } from '@ember/object';
|
|
2
|
+
import { helper } from '@ember/component/helper';
|
|
3
|
+
import Component from '@glimmer/component';
|
|
4
|
+
import { localCopy } from 'tracked-toolbox';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
Simple pagination controls component that is included to help you get started quickly.
|
|
8
|
+
Yeti Table yields a lot of pagination data, so you shouldn't have a problem
|
|
9
|
+
creating your own pagination controls.
|
|
10
|
+
|
|
11
|
+
At any rate, this component tries to be as flexible as possible. Some arguments
|
|
12
|
+
are provided to customize how this component behaves.
|
|
13
|
+
|
|
14
|
+
If you want to render these controls on the table footer, you probably want
|
|
15
|
+
a footer row that always spans all rows. To do that you can use a `colspan` equal
|
|
16
|
+
to the yielded `visibleColumns.length` number. Example:
|
|
17
|
+
|
|
18
|
+
```hbs
|
|
19
|
+
<YetiTable @data={{this.data}} @pagination={{true}} as |table|>
|
|
20
|
+
...
|
|
21
|
+
<table.tfoot as |foot|>
|
|
22
|
+
<foot.row as |row|>
|
|
23
|
+
<row.cell colspan={{table.visibleColumns.length}}>
|
|
24
|
+
<table.pagination/>
|
|
25
|
+
</row.cell>
|
|
26
|
+
</foot.row>
|
|
27
|
+
</table.tfoot>
|
|
28
|
+
</YetiTable>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
@class Pagination
|
|
32
|
+
*/
|
|
33
|
+
import { on } from '@ember/modifier';
|
|
34
|
+
import { guidFor } from '@ember/object/internals';
|
|
35
|
+
|
|
36
|
+
export default class Pagination extends Component {
|
|
37
|
+
guid = guidFor(this);
|
|
38
|
+
|
|
39
|
+
<template>
|
|
40
|
+
<div class={{@theme.pagination.controls}} ...attributes>
|
|
41
|
+
{{#if this.showInfo}}
|
|
42
|
+
<div class={{@theme.pagination.info}}>
|
|
43
|
+
Showing
|
|
44
|
+
{{@paginationData.pageStart}}
|
|
45
|
+
to
|
|
46
|
+
{{@paginationData.pageEnd}}
|
|
47
|
+
of
|
|
48
|
+
{{@paginationData.totalRows}}
|
|
49
|
+
entries
|
|
50
|
+
</div>
|
|
51
|
+
{{/if}}
|
|
52
|
+
|
|
53
|
+
{{#if this.showPageSizeSelector}}
|
|
54
|
+
<div class={{@theme.pagination.pageSize}}>
|
|
55
|
+
<label for="page-size-select-{{this.guid}}">Rows per page:</label>
|
|
56
|
+
<select
|
|
57
|
+
id="page-size-select-{{this.guid}}"
|
|
58
|
+
disabled={{@disabled}}
|
|
59
|
+
{{on "change" this.changePageSize}}
|
|
60
|
+
>
|
|
61
|
+
{{#each this.pageSizes as |pageSize|}}
|
|
62
|
+
<option
|
|
63
|
+
value={{pageSize}}
|
|
64
|
+
selected={{this.isPaginationNumberSelected pageSize}}
|
|
65
|
+
>{{pageSize}}</option>
|
|
66
|
+
{{/each}}
|
|
67
|
+
</select>
|
|
68
|
+
</div>
|
|
69
|
+
{{/if}}
|
|
70
|
+
|
|
71
|
+
{{#if this.showButtons}}
|
|
72
|
+
<button
|
|
73
|
+
type="button"
|
|
74
|
+
class={{@theme.pagination.previous}}
|
|
75
|
+
disabled={{this.shouldDisablePrevious}}
|
|
76
|
+
{{on "click" @paginationActions.previousPage}}
|
|
77
|
+
>
|
|
78
|
+
Previous
|
|
79
|
+
</button>
|
|
80
|
+
|
|
81
|
+
<button
|
|
82
|
+
type="button"
|
|
83
|
+
class={{@theme.pagination.next}}
|
|
84
|
+
disabled={{this.shouldDisableNext}}
|
|
85
|
+
{{on "click" @paginationActions.nextPage}}
|
|
86
|
+
>
|
|
87
|
+
Next
|
|
88
|
+
</button>
|
|
89
|
+
{{/if}}
|
|
90
|
+
</div>
|
|
91
|
+
</template>
|
|
92
|
+
// theme;
|
|
93
|
+
|
|
94
|
+
// paginationData;
|
|
95
|
+
|
|
96
|
+
// paginationActions;
|
|
97
|
+
|
|
98
|
+
// disabled;
|
|
99
|
+
|
|
100
|
+
// helper function used, needed while working with ember <= 4.4. Works without helper function in ember > 4.4
|
|
101
|
+
isPaginationNumberSelected = helper(([number]) => {
|
|
102
|
+
return number === this.args.paginationData.pageSize;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
get shouldDisablePrevious() {
|
|
106
|
+
return this.args.paginationData.isFirstPage || this.args.disabled;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
get shouldDisableNext() {
|
|
110
|
+
return this.args.paginationData.isLastPage || this.args.disabled;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Array of page sizes to populate the page size `<select>`.
|
|
115
|
+
* Particularly useful with an array helper, e.g `@pageSizes={{array 10 12 23 50 100}}`
|
|
116
|
+
* Defaults to `[10, 15, 20, 25]`.
|
|
117
|
+
*
|
|
118
|
+
* @argument pageSizes
|
|
119
|
+
* @type {Number}
|
|
120
|
+
*/
|
|
121
|
+
@localCopy('args.pageSizes', [10, 15, 20, 25])
|
|
122
|
+
pageSizes;
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Used to show/hide some textual information about the current page. Defaults to `true`.
|
|
126
|
+
*
|
|
127
|
+
* @argument showInfo
|
|
128
|
+
* @type {Boolean}
|
|
129
|
+
*/
|
|
130
|
+
@localCopy('args.showInfo', true)
|
|
131
|
+
showInfo;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Used to show/hide the page size selector. Defaults to `true`.
|
|
135
|
+
*
|
|
136
|
+
* @argument showPageSizeSelector
|
|
137
|
+
* @type {Boolean}
|
|
138
|
+
*/
|
|
139
|
+
@localCopy('args.showPageSizeSelector', true)
|
|
140
|
+
showPageSizeSelector;
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Used to show/hide the previous and next page buttons. Defaults to `true`.
|
|
144
|
+
*
|
|
145
|
+
* @argument showButtons
|
|
146
|
+
* @type {Boolean}
|
|
147
|
+
*/
|
|
148
|
+
@localCopy('args.showButtons', true)
|
|
149
|
+
showButtons;
|
|
150
|
+
|
|
151
|
+
@action
|
|
152
|
+
changePageSize(ev) {
|
|
153
|
+
this.args.paginationActions.changePageSize(ev.target.value);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
A simple component that just renders the `<table>` element with the correct
|
|
3
|
+
theme classes.
|
|
4
|
+
|
|
5
|
+
This component should only be needed when using `@renderTableElement={{false}}` to render
|
|
6
|
+
the table element yourself. Please refer to the `@renderTableElement` documentation for
|
|
7
|
+
more information.
|
|
8
|
+
|
|
9
|
+
Example:
|
|
10
|
+
|
|
11
|
+
```hbs
|
|
12
|
+
<YetiTable @data={{this.data}} @pagination={{true}} @renderTableElement={{false}} as |t|>
|
|
13
|
+
|
|
14
|
+
<t.table> {{!-- we render the given table component ourselves --}}
|
|
15
|
+
<t.header as |header|>
|
|
16
|
+
...
|
|
17
|
+
</t.header>
|
|
18
|
+
|
|
19
|
+
<t.body/>
|
|
20
|
+
</t.table>
|
|
21
|
+
|
|
22
|
+
<t.pagination/> {{!-- pagination controls outside the <table> element --}}
|
|
23
|
+
|
|
24
|
+
</YetiTable>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
@class Table
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
<template>
|
|
31
|
+
<table class={{@theme.table}} ...attributes>
|
|
32
|
+
{{yield}}
|
|
33
|
+
</table>
|
|
34
|
+
</template>
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { tracked } from '@glimmer/tracking';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
@class TBodyCell
|
|
6
|
+
|
|
7
|
+
Renders a `<td>` element (if its corresponding column definition has `@visible={{true}}`).
|
|
8
|
+
```hbs
|
|
9
|
+
<row.cell>
|
|
10
|
+
{{person.firstName}}
|
|
11
|
+
</row.cell>
|
|
12
|
+
|
|
13
|
+
If the prop name was used when the column header was defined, it is yielded in a hash
|
|
14
|
+
```hbs
|
|
15
|
+
<row.cell as |column|>
|
|
16
|
+
{{get person column.prop}}
|
|
17
|
+
</row.cell>
|
|
18
|
+
```
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
import { hash } from '@ember/helper';
|
|
22
|
+
|
|
23
|
+
export default class TBodyCell extends Component {
|
|
24
|
+
<template>
|
|
25
|
+
{{#if this.column.visible}}
|
|
26
|
+
<td
|
|
27
|
+
class="{{@class}} {{this.column.columnClass}} {{@theme.tbodyCell}}"
|
|
28
|
+
...attributes
|
|
29
|
+
>
|
|
30
|
+
{{yield (hash prop=this.column.prop)}}
|
|
31
|
+
</td>
|
|
32
|
+
{{/if}}
|
|
33
|
+
</template>
|
|
34
|
+
|
|
35
|
+
@tracked
|
|
36
|
+
index;
|
|
37
|
+
|
|
38
|
+
get column() {
|
|
39
|
+
return this.args.columns[this.index] || {};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
constructor() {
|
|
43
|
+
super(...arguments);
|
|
44
|
+
this.index = this.args.parent?.registerCell(this);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
willDestroy() {
|
|
48
|
+
super.willDestroy(...arguments);
|
|
49
|
+
this.args.parent?.unregisterCell(this);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { action } from '@ember/object';
|
|
2
|
+
|
|
3
|
+
import Component from '@glimmer/component';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
Renders a `<tr>` element and yields the cell component.
|
|
7
|
+
```hbs
|
|
8
|
+
<body.row as |row|>
|
|
9
|
+
<row.cell>
|
|
10
|
+
{{person.firstName}} #{{index}}
|
|
11
|
+
</row.cell>
|
|
12
|
+
<row.cell>
|
|
13
|
+
{{person.lastName}}
|
|
14
|
+
</row.cell>
|
|
15
|
+
<row.cell>
|
|
16
|
+
{{person.points}}
|
|
17
|
+
</row.cell>
|
|
18
|
+
</body.row>
|
|
19
|
+
```
|
|
20
|
+
Remember you can customize each `<tr>` class or `@onClick` handler based on the row data
|
|
21
|
+
because you have access to it from the body component.
|
|
22
|
+
|
|
23
|
+
```hbs
|
|
24
|
+
<table.body as |body person|>
|
|
25
|
+
<body.row class={{if person.isInvalid "error"}} as |row|>
|
|
26
|
+
<row.cell>
|
|
27
|
+
{{person.firstName}}
|
|
28
|
+
</row.cell>
|
|
29
|
+
<row.cell>
|
|
30
|
+
{{person.lastName}}
|
|
31
|
+
</row.cell>
|
|
32
|
+
<row.cell>
|
|
33
|
+
{{person.points}}
|
|
34
|
+
</row.cell>
|
|
35
|
+
</body.row>
|
|
36
|
+
</table.body>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
@class TBodyRow
|
|
40
|
+
@yield {object} row
|
|
41
|
+
@yield {Component} row.cell - the cell component
|
|
42
|
+
*/
|
|
43
|
+
// template imports
|
|
44
|
+
import { hash } from '@ember/helper';
|
|
45
|
+
import { on } from '@ember/modifier';
|
|
46
|
+
import Cell from './row/cell.gjs';
|
|
47
|
+
|
|
48
|
+
export default class TBodyRow extends Component {
|
|
49
|
+
<template>
|
|
50
|
+
{{! template-lint-disable no-invalid-interactive }}
|
|
51
|
+
<tr
|
|
52
|
+
class="{{@theme.tbodyRow}} {{@theme.row}}"
|
|
53
|
+
{{on "click" this.handleClick}}
|
|
54
|
+
role={{if @onClick "button"}}
|
|
55
|
+
...attributes
|
|
56
|
+
>
|
|
57
|
+
{{yield
|
|
58
|
+
(hash cell=(component Cell theme=@theme parent=this columns=@columns))
|
|
59
|
+
}}
|
|
60
|
+
</tr>
|
|
61
|
+
</template>
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Adds a click action to the row.
|
|
65
|
+
*
|
|
66
|
+
* @argument onClick
|
|
67
|
+
* @type Function
|
|
68
|
+
*/
|
|
69
|
+
|
|
70
|
+
cells = [];
|
|
71
|
+
|
|
72
|
+
registerCell(cell) {
|
|
73
|
+
let index = this.cells.length;
|
|
74
|
+
this.cells.push(cell);
|
|
75
|
+
return index;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
unregisterCell(cell) {
|
|
79
|
+
let cells = this.cells;
|
|
80
|
+
let index = cells.indexOf(cell);
|
|
81
|
+
|
|
82
|
+
cells.splice(index, 1);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
@action
|
|
86
|
+
handleClick() {
|
|
87
|
+
this.args.onClick?.(...arguments);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Renders a `<tbody>` element and yields the row component and data. You must iterate each row
|
|
5
|
+
```hbs
|
|
6
|
+
<table.tbody as |body data|>
|
|
7
|
+
{{#each data as |person index|}}
|
|
8
|
+
<body.row as |row|>
|
|
9
|
+
<row.cell>
|
|
10
|
+
{{person.firstName}} #{{index}}
|
|
11
|
+
</row.cell>
|
|
12
|
+
<row.cell>
|
|
13
|
+
{{person.lastName}}
|
|
14
|
+
</row.cell>
|
|
15
|
+
<row.cell>
|
|
16
|
+
{{person.points}}
|
|
17
|
+
</row.cell>
|
|
18
|
+
</body.row>
|
|
19
|
+
{{/each}}
|
|
20
|
+
</table.tbody>
|
|
21
|
+
```
|
|
22
|
+
Remember that you must perform the {{#each}} to iterate over the `@data` array.
|
|
23
|
+
|
|
24
|
+
This component does not provide a blockless variation
|
|
25
|
+
|
|
26
|
+
@class TBody
|
|
27
|
+
@yield {object} body
|
|
28
|
+
@yield {Component} body.row - the row component
|
|
29
|
+
@yield {Array} data
|
|
30
|
+
*/
|
|
31
|
+
import { hash } from '@ember/helper';
|
|
32
|
+
import TBodyRow from './tbody/row.gjs';
|
|
33
|
+
|
|
34
|
+
// eslint-disable-next-line ember/no-empty-glimmer-component-classes
|
|
35
|
+
export default class TBody extends Component {
|
|
36
|
+
<template>
|
|
37
|
+
<tbody class={{@theme.tbody}} ...attributes>
|
|
38
|
+
{{yield
|
|
39
|
+
(hash
|
|
40
|
+
row=(component
|
|
41
|
+
TBodyRow theme=@theme onClick=@onRowClick columns=@columns
|
|
42
|
+
)
|
|
43
|
+
)
|
|
44
|
+
@data
|
|
45
|
+
}}
|
|
46
|
+
</tbody>
|
|
47
|
+
</template>
|
|
48
|
+
/**
|
|
49
|
+
* Adds a click action to each row, called with the clicked row's data as an argument.
|
|
50
|
+
* Can be used with both the blockless and block invocations.
|
|
51
|
+
*
|
|
52
|
+
* @argument onRowClick
|
|
53
|
+
* @type Function
|
|
54
|
+
*/
|
|
55
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
import { tracked } from '@glimmer/tracking';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
Renders a `<td>` element and yields for the developer to supply content.
|
|
6
|
+
|
|
7
|
+
```hbs
|
|
8
|
+
<table.tfoot as |foot|>
|
|
9
|
+
<foot.row as |row|>
|
|
10
|
+
<row.cell>
|
|
11
|
+
Footer content
|
|
12
|
+
</row.cell>
|
|
13
|
+
</foot.row>
|
|
14
|
+
</table.tfoot>
|
|
15
|
+
```
|
|
16
|
+
@class TFootCell
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
export default class TFootCell extends Component {
|
|
20
|
+
<template>
|
|
21
|
+
{{#if this.column.visible}}
|
|
22
|
+
<td class="{{@class}} {{@theme.tfootCell}}" ...attributes>
|
|
23
|
+
{{yield}}
|
|
24
|
+
</td>
|
|
25
|
+
{{/if}}
|
|
26
|
+
</template>
|
|
27
|
+
|
|
28
|
+
@tracked
|
|
29
|
+
index;
|
|
30
|
+
|
|
31
|
+
get column() {
|
|
32
|
+
return this.args.columns[this.index];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
constructor() {
|
|
36
|
+
super(...arguments);
|
|
37
|
+
|
|
38
|
+
this.index = this.args.parent?.registerCell(this);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
willDestroy() {
|
|
42
|
+
super.willDestroy(...arguments);
|
|
43
|
+
this.args.parent?.unregisterCell(this);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Renders a `<tr>` element and yields cell component.
|
|
5
|
+
```hbs
|
|
6
|
+
<table.tfoot as |foot|>
|
|
7
|
+
<foot.row as |row|>
|
|
8
|
+
<row.cell>
|
|
9
|
+
Footer content
|
|
10
|
+
</row.cell>
|
|
11
|
+
</foot.row>
|
|
12
|
+
</table.tfoot>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
@class TFootRow
|
|
16
|
+
@yield {object} row
|
|
17
|
+
@yield {Component} row.cell
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
import { hash } from '@ember/helper';
|
|
21
|
+
import Cell from './row/cell.gjs';
|
|
22
|
+
|
|
23
|
+
export default class TFootRow extends Component {
|
|
24
|
+
<template>
|
|
25
|
+
<tr class="{{@class}} {{@theme.tfootRow}} {{@theme.row}}" ...attributes>
|
|
26
|
+
{{yield
|
|
27
|
+
(hash cell=(component Cell theme=@theme parent=this columns=@columns))
|
|
28
|
+
}}
|
|
29
|
+
</tr>
|
|
30
|
+
</template>
|
|
31
|
+
cells = [];
|
|
32
|
+
|
|
33
|
+
registerCell(cell) {
|
|
34
|
+
let index = this.cells.length;
|
|
35
|
+
this.cells.push(cell);
|
|
36
|
+
return index;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
unregisterCell(cell) {
|
|
40
|
+
let cells = this.cells;
|
|
41
|
+
let index = cells.indexOf(cell);
|
|
42
|
+
cells.splice(index, 1);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
Renders a `<tfoot>` element and yields the row component.
|
|
5
|
+
```hbs
|
|
6
|
+
<table.tfoot as |foot|>
|
|
7
|
+
<foot.row as |row|>
|
|
8
|
+
<row.cell>
|
|
9
|
+
Footer content
|
|
10
|
+
</row.cell>
|
|
11
|
+
</foot.row>
|
|
12
|
+
</table.tfoot>
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
@class TTFoot
|
|
16
|
+
@yield {object} footer
|
|
17
|
+
@yield {Component} footer.row
|
|
18
|
+
*/
|
|
19
|
+
import { hash } from '@ember/helper';
|
|
20
|
+
import TFootRow from './tfoot/row.gjs';
|
|
21
|
+
|
|
22
|
+
// eslint-disable-next-line ember/no-empty-glimmer-component-classes
|
|
23
|
+
export default class TFoot extends Component {
|
|
24
|
+
<template>
|
|
25
|
+
<tfoot class={{@theme.tfoot}} ...attributes>
|
|
26
|
+
{{yield
|
|
27
|
+
(hash
|
|
28
|
+
row=(component TFootRow columns=@columns theme=@theme parent=@parent)
|
|
29
|
+
)
|
|
30
|
+
}}
|
|
31
|
+
</tfoot>
|
|
32
|
+
</template>
|
|
33
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import Component from '@glimmer/component';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
An component yielded from the head.row component that is used to define
|
|
5
|
+
a cell in a row of the head of the table. Would be used for filters or any other
|
|
6
|
+
additional information in the table head for a column
|
|
7
|
+
|
|
8
|
+
```hbs
|
|
9
|
+
<table.thead as |head|>
|
|
10
|
+
<head.row as |row|>
|
|
11
|
+
<row.cell>
|
|
12
|
+
<input
|
|
13
|
+
class="input" type="search" placeholder="Search last name"
|
|
14
|
+
value={{this.lastNameFilter}}
|
|
15
|
+
{{on "input"
|
|
16
|
+
(pipe
|
|
17
|
+
(pick "target.value")
|
|
18
|
+
(fn (mut this.lastNameFilter))
|
|
19
|
+
)
|
|
20
|
+
}}
|
|
21
|
+
>
|
|
22
|
+
</row.cell>
|
|
23
|
+
</head.row>
|
|
24
|
+
</table.thead>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
@class THeadCell
|
|
28
|
+
@yield {object} cell
|
|
29
|
+
|
|
30
|
+
*/
|
|
31
|
+
export default class THeadCell extends Component {
|
|
32
|
+
<template>
|
|
33
|
+
{{#if this.column.visible}}
|
|
34
|
+
<th class="{{@class}} {{@theme.theadCell}}" ...attributes>
|
|
35
|
+
{{yield}}
|
|
36
|
+
</th>
|
|
37
|
+
{{/if}}
|
|
38
|
+
</template>
|
|
39
|
+
|
|
40
|
+
// Assigned when the cell is registered
|
|
41
|
+
column = undefined;
|
|
42
|
+
|
|
43
|
+
constructor() {
|
|
44
|
+
super(...arguments);
|
|
45
|
+
this.column = this.args.parent?.registerCell(this);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
willDestroy() {
|
|
49
|
+
super.willDestroy(...arguments);
|
|
50
|
+
this.args.parent?.unregisterCell(this);
|
|
51
|
+
}
|
|
52
|
+
}
|