@statistikzh/leu 0.0.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.
- package/.editorconfig +29 -0
- package/.eslintrc.json +27 -0
- package/.github/workflows/publish.yml +19 -0
- package/.github/workflows/release-please.yml +19 -0
- package/.github/workflows/test.yml +38 -0
- package/.husky/commit-msg +4 -0
- package/.husky/pre-commit +4 -0
- package/.prettierignore +1 -0
- package/.storybook/main.js +11 -0
- package/.storybook/preview-head.html +5 -0
- package/.storybook/preview.js +23 -0
- package/CHANGELOG.md +63 -0
- package/CODE_OF_CONDUCT.md +128 -0
- package/CONTRIBUTING.md +31 -0
- package/LICENSE +21 -0
- package/README.md +170 -0
- package/commitlint.config.cjs +1 -0
- package/dist/Button-83c6df93.js +403 -0
- package/dist/Checkbox.js +144 -0
- package/dist/CheckboxGroup.js +82 -0
- package/dist/Chip-60af1402.js +162 -0
- package/dist/ChipGroup.js +79 -0
- package/dist/ChipLink.js +46 -0
- package/dist/ChipRemovable.js +43 -0
- package/dist/ChipSelectable.js +92 -0
- package/dist/Input.js +686 -0
- package/dist/Radio.js +156 -0
- package/dist/RadioGroup.js +194 -0
- package/dist/Select.js +859 -0
- package/dist/Table-72d305d7.js +506 -0
- package/dist/Table.js +8 -0
- package/dist/defineElement-47d4f665.js +15 -0
- package/dist/icon-b68c7e1e.js +202 -0
- package/dist/index.js +21 -0
- package/dist/leu-checkbox-group.js +6 -0
- package/dist/leu-checkbox.js +6 -0
- package/dist/leu-chip-group.js +5 -0
- package/dist/leu-chip-link.js +6 -0
- package/dist/leu-chip-removable.js +7 -0
- package/dist/leu-chip-selectable.js +6 -0
- package/dist/leu-input.js +9 -0
- package/dist/leu-radio-group.js +6 -0
- package/dist/leu-radio.js +5 -0
- package/dist/leu-select.js +12 -0
- package/dist/leu-table.js +10 -0
- package/dist/theme.css +51 -0
- package/index.js +10 -0
- package/package.json +85 -0
- package/postcss.config.cjs +14 -0
- package/rollup.config.js +54 -0
- package/scripts/generate-component/generate.js +167 -0
- package/scripts/generate-component/templates/[Name].js +33 -0
- package/scripts/generate-component/templates/[name].css +11 -0
- package/scripts/generate-component/templates/[namespace]-[name].js +3 -0
- package/scripts/generate-component/templates/stories/[name].stories.js +13 -0
- package/scripts/generate-component/templates/test/[name].test.js +22 -0
- package/src/components/button/Button.js +150 -0
- package/src/components/button/button.css +232 -0
- package/src/components/button/leu-button.js +3 -0
- package/src/components/button/stories/button.stories.js +333 -0
- package/src/components/button/test/button.test.js +22 -0
- package/src/components/button-group/ButtonGroup.js +63 -0
- package/src/components/button-group/button-group.css +10 -0
- package/src/components/button-group/leu-button-group.js +3 -0
- package/src/components/button-group/stories/button-group.stories.js +41 -0
- package/src/components/button-group/test/button-group.test.js +22 -0
- package/src/components/checkbox/Checkbox.js +142 -0
- package/src/components/checkbox/CheckboxGroup.js +80 -0
- package/src/components/checkbox/leu-checkbox-group.js +3 -0
- package/src/components/checkbox/leu-checkbox.js +3 -0
- package/src/components/checkbox/stories/checkbox-group.stories.js +52 -0
- package/src/components/checkbox/stories/checkbox.stories.js +43 -0
- package/src/components/checkbox/test/checkbox.test.js +101 -0
- package/src/components/chip/Chip.js +24 -0
- package/src/components/chip/ChipGroup.js +71 -0
- package/src/components/chip/ChipLink.js +45 -0
- package/src/components/chip/ChipRemovable.js +42 -0
- package/src/components/chip/ChipSelectable.js +91 -0
- package/src/components/chip/chip-group.css +5 -0
- package/src/components/chip/chip.css +130 -0
- package/src/components/chip/exports.js +10 -0
- package/src/components/chip/leu-chip-group.js +3 -0
- package/src/components/chip/leu-chip-link.js +3 -0
- package/src/components/chip/leu-chip-removable.js +3 -0
- package/src/components/chip/leu-chip-selectable.js +3 -0
- package/src/components/chip/stories/chip-group.stories.js +99 -0
- package/src/components/chip/stories/chip-link.stories.js +37 -0
- package/src/components/chip/stories/chip-removable.stories.js +28 -0
- package/src/components/chip/stories/chip-selectable.stories.js +46 -0
- package/src/components/chip/test/chip.test.js +22 -0
- package/src/components/dropdown/Dropdown.js +55 -0
- package/src/components/dropdown/dropdown.css +17 -0
- package/src/components/dropdown/leu-dropdown.js +3 -0
- package/src/components/dropdown/stories/dropdown.stories.js +25 -0
- package/src/components/dropdown/test/dropdown.test.js +31 -0
- package/src/components/icon/icon.js +201 -0
- package/src/components/input/Input.js +421 -0
- package/src/components/input/input.css +231 -0
- package/src/components/input/leu-input.js +3 -0
- package/src/components/input/stories/input.stories.js +185 -0
- package/src/components/input/test/input.test.js +22 -0
- package/src/components/menu/Menu.js +18 -0
- package/src/components/menu/MenuItem.js +95 -0
- package/src/components/menu/leu-menu-item.js +3 -0
- package/src/components/menu/leu-menu.js +3 -0
- package/src/components/menu/menu-item.css +72 -0
- package/src/components/menu/menu.css +14 -0
- package/src/components/menu/stories/menu-item.stories.js +51 -0
- package/src/components/menu/stories/menu.stories.js +21 -0
- package/src/components/menu/test/menu.test.js +22 -0
- package/src/components/pagination/Pagination.js +152 -0
- package/src/components/pagination/leu-pagination.js +3 -0
- package/src/components/pagination/pagination.css +49 -0
- package/src/components/pagination/stories/pagination.stories.js +82 -0
- package/src/components/pagination/test/pagination.test.js +22 -0
- package/src/components/radio/Radio.js +62 -0
- package/src/components/radio/RadioGroup.js +193 -0
- package/src/components/radio/leu-radio-group.js +3 -0
- package/src/components/radio/leu-radio.js +3 -0
- package/src/components/radio/radio.css +76 -0
- package/src/components/radio/stories/radio-group.stories.js +49 -0
- package/src/components/radio/stories/radio.stories.js +48 -0
- package/src/components/radio/test/radio.test.js +38 -0
- package/src/components/select/Select.js +350 -0
- package/src/components/select/leu-select.js +3 -0
- package/src/components/select/select.css +215 -0
- package/src/components/select/stories/select.stories.js +302 -0
- package/src/components/select/test/select.test.js +29 -0
- package/src/components/table/Table.js +301 -0
- package/src/components/table/leu-table.js +3 -0
- package/src/components/table/stories/table.stories.js +116 -0
- package/src/components/table/test/table.test.js +36 -0
- package/src/lib/defineElement.js +13 -0
- package/src/lib/hasSlotController.js +85 -0
- package/src/styles/custom-media.css +5 -0
- package/src/styles/custom-properties.css +51 -0
- package/src/styles/theme.css +1 -0
- package/stat_zh.png +0 -0
- package/stylelint.config.mjs +21 -0
- package/web-dev-server-storybook.config.mjs +19 -0
- package/web-test-runner.config.mjs +49 -0
|
@@ -0,0 +1,506 @@
|
|
|
1
|
+
import { css, LitElement, html, nothing } from 'lit';
|
|
2
|
+
import { classMap } from 'lit/directives/class-map.js';
|
|
3
|
+
import { styleMap } from 'lit/directives/style-map.js';
|
|
4
|
+
import { createRef, ref } from 'lit/directives/ref.js';
|
|
5
|
+
import { I as Icon } from './icon-b68c7e1e.js';
|
|
6
|
+
import { d as defineElement } from './defineElement-47d4f665.js';
|
|
7
|
+
import { d as defineButtonElements } from './Button-83c6df93.js';
|
|
8
|
+
|
|
9
|
+
var css_248z = css`:host {
|
|
10
|
+
margin-top: 16px;
|
|
11
|
+
display: flex;
|
|
12
|
+
justify-content: end;
|
|
13
|
+
font-family: var(--leu-font-regular);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.input {
|
|
17
|
+
width: 50px;
|
|
18
|
+
padding: 0;
|
|
19
|
+
border: 2px solid var(--leu-color-black-40);
|
|
20
|
+
border-radius: 2px;
|
|
21
|
+
color: var(--leu-color-black-transp-60);
|
|
22
|
+
text-align: center;
|
|
23
|
+
font-size: 16px;
|
|
24
|
+
font-style: normal;
|
|
25
|
+
font-weight: 400;
|
|
26
|
+
line-height: 24px;
|
|
27
|
+
outline-offset: 2px;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/* no arrows: Chrome, Safari, Edge, Opera */
|
|
31
|
+
|
|
32
|
+
.input::-webkit-outer-spin-button,
|
|
33
|
+
.input::-webkit-inner-spin-button {
|
|
34
|
+
-webkit-appearance: none;
|
|
35
|
+
appearance: none;
|
|
36
|
+
margin: 0;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/* no arrows: Firefox */
|
|
40
|
+
|
|
41
|
+
.input[type="number"] {
|
|
42
|
+
-webkit-appearance: textfield;
|
|
43
|
+
-moz-appearance: textfield;
|
|
44
|
+
appearance: textfield;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.input:focus,
|
|
48
|
+
.input:hover {
|
|
49
|
+
border-color: var(--leu-color-func-cyan);
|
|
50
|
+
outline: none;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.input:focus-visible {
|
|
54
|
+
outline: 2px solid var(--leu-color-func-cyan);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.label {
|
|
58
|
+
margin: 0 16px;
|
|
59
|
+
line-height: 50px;
|
|
60
|
+
color: var(--leu-color-black-transp-60);
|
|
61
|
+
white-space: nowrap;
|
|
62
|
+
}
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
const MIN_PAGE = 1;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @tagname leu-pagination
|
|
69
|
+
*/
|
|
70
|
+
class LeuPagination extends LitElement {
|
|
71
|
+
static styles = css_248z
|
|
72
|
+
|
|
73
|
+
static events = {
|
|
74
|
+
range: {},
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
static properties = {
|
|
78
|
+
page: { type: Number, reflect: true },
|
|
79
|
+
itemsOnAPage: { type: Number },
|
|
80
|
+
dataLength: { type: Number },
|
|
81
|
+
|
|
82
|
+
_minPage: { type: Number, state: true },
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
constructor() {
|
|
86
|
+
super();
|
|
87
|
+
/** @type {number} */
|
|
88
|
+
this.page = 1;
|
|
89
|
+
/** @type {number} */
|
|
90
|
+
this.dataLength = 0;
|
|
91
|
+
/** @type {number} */
|
|
92
|
+
this.itemsOnAPage = 30;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
get maxPage() {
|
|
96
|
+
return Math.ceil(this.dataLength / this.itemsOnAPage)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
get firstPage() {
|
|
100
|
+
return this.page === MIN_PAGE
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
get lastPage() {
|
|
104
|
+
return this.page === this.maxPage
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
holdInRange(value) {
|
|
108
|
+
return Math.min(Math.max(value, MIN_PAGE), this.maxPage)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
numberUpdate(number) {
|
|
112
|
+
this.page = this.holdInRange(number);
|
|
113
|
+
|
|
114
|
+
const min = (this.page - 1) * this.itemsOnAPage;
|
|
115
|
+
const max = Math.min(min + this.itemsOnAPage, this.dataLength);
|
|
116
|
+
this.dispatchEvent(
|
|
117
|
+
new CustomEvent("range-updated", {
|
|
118
|
+
detail: {
|
|
119
|
+
min,
|
|
120
|
+
max,
|
|
121
|
+
},
|
|
122
|
+
bubbles: false,
|
|
123
|
+
})
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
change(event) {
|
|
128
|
+
// target.value = this.page // eslint-disable-line
|
|
129
|
+
this.numberUpdate(parseInt(event.target.value, 10) || 0);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
input(event) {
|
|
133
|
+
if (event.target.value !== "") {
|
|
134
|
+
event.preventDefault();
|
|
135
|
+
this.change(event);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
keydown(event) {
|
|
140
|
+
const specialKeys = [
|
|
141
|
+
"ArrowUp",
|
|
142
|
+
"ArrowDown",
|
|
143
|
+
"ArrowLeft",
|
|
144
|
+
"ArrowRight",
|
|
145
|
+
"Backspace",
|
|
146
|
+
"Enter",
|
|
147
|
+
"Tab",
|
|
148
|
+
];
|
|
149
|
+
const numberKeys = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9"];
|
|
150
|
+
if (!numberKeys.includes(event.key) && !specialKeys.includes(event.key)) {
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
} else {
|
|
153
|
+
if (event.key === "ArrowUp") {
|
|
154
|
+
event.preventDefault();
|
|
155
|
+
this.numberUpdate(this.page + 1);
|
|
156
|
+
}
|
|
157
|
+
if (event.key === "ArrowDown") {
|
|
158
|
+
event.preventDefault();
|
|
159
|
+
this.numberUpdate(this.page - 1);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
firstUpdated() {
|
|
165
|
+
this.numberUpdate(this.page);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
requestUpdate(name, oldValue, newValue) {
|
|
169
|
+
if (name === "itemsOnAPage") {
|
|
170
|
+
this.numberUpdate(this.page);
|
|
171
|
+
}
|
|
172
|
+
return super.requestUpdate(name, oldValue, newValue)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
render() {
|
|
176
|
+
return html`
|
|
177
|
+
<input
|
|
178
|
+
class="input"
|
|
179
|
+
.value=${this.page}
|
|
180
|
+
@input=${this.input}
|
|
181
|
+
@change=${this.change}
|
|
182
|
+
@keydown=${this.keydown}
|
|
183
|
+
type="number"
|
|
184
|
+
/>
|
|
185
|
+
<div class="label">von ${this.maxPage}</div>
|
|
186
|
+
<leu-button
|
|
187
|
+
icon="angleLeft"
|
|
188
|
+
variant="secondary"
|
|
189
|
+
@click=${(_) => {
|
|
190
|
+
this.numberUpdate(this.page - 1);
|
|
191
|
+
}}
|
|
192
|
+
?disabled=${this.firstPage}
|
|
193
|
+
></leu-button>
|
|
194
|
+
<leu-button
|
|
195
|
+
icon="angleRight"
|
|
196
|
+
variant="secondary"
|
|
197
|
+
@click=${(_) => {
|
|
198
|
+
this.numberUpdate(this.page + 1);
|
|
199
|
+
}}
|
|
200
|
+
?disabled=${this.lastPage}
|
|
201
|
+
style="margin-left:4px;"
|
|
202
|
+
></leu-button>
|
|
203
|
+
`
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function definePaginationElements() {
|
|
208
|
+
defineButtonElements();
|
|
209
|
+
defineElement("pagination", LeuPagination);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* @tagname leu-table
|
|
214
|
+
*/
|
|
215
|
+
class LeuTable extends LitElement {
|
|
216
|
+
static styles = css`
|
|
217
|
+
:host {
|
|
218
|
+
position: relative;
|
|
219
|
+
display: block;
|
|
220
|
+
}
|
|
221
|
+
div.scroll {
|
|
222
|
+
display: inline-block;
|
|
223
|
+
width: 100%;
|
|
224
|
+
overflow: auto;
|
|
225
|
+
}
|
|
226
|
+
div.shadow {
|
|
227
|
+
position: absolute;
|
|
228
|
+
left: 0;
|
|
229
|
+
top: 0;
|
|
230
|
+
width: 100%;
|
|
231
|
+
height: 100%;
|
|
232
|
+
pointer-events: none;
|
|
233
|
+
z-index: 1;
|
|
234
|
+
}
|
|
235
|
+
div.pagination {
|
|
236
|
+
height: calc(100% - 66px);
|
|
237
|
+
}
|
|
238
|
+
table {
|
|
239
|
+
width: 100%;
|
|
240
|
+
border-spacing: 0;
|
|
241
|
+
color: rgb(0 0 0 / 60%);
|
|
242
|
+
font-size: 16px;
|
|
243
|
+
font-family: var(--leu-font-regular);
|
|
244
|
+
line-height: 1.5;
|
|
245
|
+
}
|
|
246
|
+
td {
|
|
247
|
+
padding: 12px;
|
|
248
|
+
}
|
|
249
|
+
th {
|
|
250
|
+
padding: 16px 16px 8px;
|
|
251
|
+
text-align: left;
|
|
252
|
+
font-size: 12px;
|
|
253
|
+
font-weight: normal;
|
|
254
|
+
font-family: var(--leu-font-black);
|
|
255
|
+
background: var(--table-even-row-bg);
|
|
256
|
+
}
|
|
257
|
+
td:first-child,
|
|
258
|
+
th:first-child {
|
|
259
|
+
left: 0;
|
|
260
|
+
background: inherit;
|
|
261
|
+
z-index: 1;
|
|
262
|
+
}
|
|
263
|
+
tr {
|
|
264
|
+
background: #fff;
|
|
265
|
+
}
|
|
266
|
+
tbody tr:nth-child(odd) {
|
|
267
|
+
background: var(--leu-color-black-5);
|
|
268
|
+
}
|
|
269
|
+
button {
|
|
270
|
+
background: none;
|
|
271
|
+
cursor: pointer;
|
|
272
|
+
line-height: 1.5;
|
|
273
|
+
padding: 0;
|
|
274
|
+
border: 0;
|
|
275
|
+
width: 100%;
|
|
276
|
+
display: flex;
|
|
277
|
+
align-items: flex-center;
|
|
278
|
+
font-size: inherit;
|
|
279
|
+
font-family: inherit;
|
|
280
|
+
}
|
|
281
|
+
thead svg {
|
|
282
|
+
display: inline-block;
|
|
283
|
+
color: var(--leu-color-accent-blue);
|
|
284
|
+
padding: 0;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
table.sticky td:first-child,
|
|
288
|
+
table.sticky th:first-child {
|
|
289
|
+
position: sticky;
|
|
290
|
+
}
|
|
291
|
+
div.shadow-left table.sticky td:first-child,
|
|
292
|
+
div.shadow-left table.sticky th:first-child {
|
|
293
|
+
box-shadow: 0 0 5px rgb(0 0 0 / 50%);
|
|
294
|
+
clip-path: inset(0 -15px 0 0);
|
|
295
|
+
}
|
|
296
|
+
div.shadow-left {
|
|
297
|
+
box-shadow: inset 5px 0 5px -5px rgb(0 0 0 / 50%);
|
|
298
|
+
}
|
|
299
|
+
div.shadow-right {
|
|
300
|
+
box-shadow: inset -5px 0 5px -5px rgb(0 0 0 / 50%);
|
|
301
|
+
}
|
|
302
|
+
`
|
|
303
|
+
|
|
304
|
+
static properties = {
|
|
305
|
+
columns: { type: Array },
|
|
306
|
+
data: { type: Array },
|
|
307
|
+
firstColumnSticky: { type: Boolean },
|
|
308
|
+
itemsOnAPage: { type: Number },
|
|
309
|
+
sortIndex: { type: Number },
|
|
310
|
+
sortOrderAsc: { type: Boolean },
|
|
311
|
+
width: { type: Number },
|
|
312
|
+
|
|
313
|
+
_shadowLeft: { type: Boolean, state: true },
|
|
314
|
+
_shadowRight: { type: Boolean, state: true },
|
|
315
|
+
_min: { type: Number, state: true },
|
|
316
|
+
_max: { type: Number, state: true },
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
constructor() {
|
|
320
|
+
super();
|
|
321
|
+
/** @type {array} */
|
|
322
|
+
this.columns = [];
|
|
323
|
+
/** @type {array} */
|
|
324
|
+
this.data = [];
|
|
325
|
+
/** @type {boolean} */
|
|
326
|
+
this.firstColumnSticky = false;
|
|
327
|
+
/** @type {number} */
|
|
328
|
+
this.itemsOnAPage = null;
|
|
329
|
+
/** @type {number} */
|
|
330
|
+
this.sortIndex = null;
|
|
331
|
+
/** @type {boolean} */
|
|
332
|
+
this.sortOrderAsc = false;
|
|
333
|
+
/** @type {number} */
|
|
334
|
+
this.width = null;
|
|
335
|
+
|
|
336
|
+
/** @internal */
|
|
337
|
+
this._sortArrowDown = Icon("arrowDown", 20);
|
|
338
|
+
/** @internal */
|
|
339
|
+
this._sortArrowUp = Icon("arrowUp", 20);
|
|
340
|
+
/** @internal */
|
|
341
|
+
this._shadowLeft = false;
|
|
342
|
+
/** @internal */
|
|
343
|
+
this._shadowRight = false;
|
|
344
|
+
/** @internal */
|
|
345
|
+
this._scrollRef = createRef();
|
|
346
|
+
/** @internal */
|
|
347
|
+
this._min = 0;
|
|
348
|
+
/** @internal */
|
|
349
|
+
this._max = null;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
firstUpdated() {
|
|
353
|
+
this.shadowToggle(this._scrollRef.value);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
shadowToggle(target) {
|
|
357
|
+
this._shadowLeft = target.scrollLeftMax > 0 && target.scrollLeft > 0;
|
|
358
|
+
this._shadowRight =
|
|
359
|
+
target.scrollLeftMax > 0 && target.scrollLeft < target.scrollLeftMax;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
scrollEvent(event) {
|
|
363
|
+
this.shadowToggle(event.target);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
isOnePropNotValid() {
|
|
367
|
+
if (!this._columns) {
|
|
368
|
+
return "Der Parameter 'columns' ist erforderlich !"
|
|
369
|
+
}
|
|
370
|
+
if (!this._sortedData) {
|
|
371
|
+
return "Der Parameter 'data' ist erforderlich !"
|
|
372
|
+
}
|
|
373
|
+
return null
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
isSorted(col) {
|
|
377
|
+
return this.sortIndex === this._columns.indexOf(col)
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
sortClick(col) {
|
|
381
|
+
const index = this._columns.indexOf(col);
|
|
382
|
+
if (this.sortIndex === index) {
|
|
383
|
+
this.sortOrderAsc = !this.sortOrderAsc;
|
|
384
|
+
} else {
|
|
385
|
+
this.sortIndex = index;
|
|
386
|
+
this.sortOrder = "asc";
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
sortArrowIcon() {
|
|
391
|
+
return html`${this.sortOrderAsc ? this._sortArrowDown : this._sortArrowUp}`
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
sortArrow(col) {
|
|
395
|
+
return html` ${this.isSorted(col) ? this.sortArrowIcon() : nothing} `
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
get _columns() {
|
|
399
|
+
return this.columns
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
get _sortedData() {
|
|
403
|
+
if (this.sortIndex === null || this.sortIndex === undefined) {
|
|
404
|
+
return this.data
|
|
405
|
+
}
|
|
406
|
+
const col = this._columns[this.sortIndex];
|
|
407
|
+
return this.data.sort(this.sortOrderAsc ? col.sort.asc : col.sort.desc)
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
get _data() {
|
|
411
|
+
return this.itemsOnAPage && this.itemsOnAPage > 0
|
|
412
|
+
? this._sortedData.slice(this._min, this._max)
|
|
413
|
+
: this._sortedData
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
render() {
|
|
417
|
+
const scrollClasses = {
|
|
418
|
+
scroll: true,
|
|
419
|
+
"shadow-left": this.firstColumnSticky && this._shadowLeft,
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
const shadowClassesLeft = {
|
|
423
|
+
shadow: true,
|
|
424
|
+
"shadow-left": !this.firstColumnSticky && this._shadowLeft,
|
|
425
|
+
pagination: this.itemsOnAPage > 0,
|
|
426
|
+
};
|
|
427
|
+
|
|
428
|
+
const shadowClassesRight = {
|
|
429
|
+
shadow: true,
|
|
430
|
+
"shadow-right": this._shadowRight,
|
|
431
|
+
pagination: this.itemsOnAPage > 0,
|
|
432
|
+
};
|
|
433
|
+
|
|
434
|
+
const stickyClass = {
|
|
435
|
+
sticky: this.firstColumnSticky,
|
|
436
|
+
};
|
|
437
|
+
|
|
438
|
+
return html`
|
|
439
|
+
<div
|
|
440
|
+
class=${classMap(scrollClasses)}
|
|
441
|
+
@scroll="${this.scrollEvent}"
|
|
442
|
+
ref=${ref(this._scrollRef)}
|
|
443
|
+
>
|
|
444
|
+
<table class=${classMap(stickyClass)}>
|
|
445
|
+
<thead>
|
|
446
|
+
<tr>
|
|
447
|
+
${this._columns.map(
|
|
448
|
+
(col) =>
|
|
449
|
+
html`<th>
|
|
450
|
+
${col.sort
|
|
451
|
+
? html`<button @click=${(_) => this.sortClick(col)}>
|
|
452
|
+
<span>${col.name}</span>
|
|
453
|
+
${this.sortArrow(col)}
|
|
454
|
+
</button>`
|
|
455
|
+
: col.name}
|
|
456
|
+
</th>`
|
|
457
|
+
)}
|
|
458
|
+
</tr>
|
|
459
|
+
</thead>
|
|
460
|
+
<tbody>
|
|
461
|
+
${this._data.map(
|
|
462
|
+
(row) =>
|
|
463
|
+
html`<tr>
|
|
464
|
+
${this._columns.map(
|
|
465
|
+
(col) =>
|
|
466
|
+
html`<td
|
|
467
|
+
style=${col.style ? styleMap(col.style(row)) : nothing}
|
|
468
|
+
>
|
|
469
|
+
${col.value(row)}
|
|
470
|
+
</td>`
|
|
471
|
+
)}
|
|
472
|
+
</tr>`
|
|
473
|
+
)}
|
|
474
|
+
</tbody>
|
|
475
|
+
</table>
|
|
476
|
+
<div class=${classMap(shadowClassesLeft)}></div>
|
|
477
|
+
<div class=${classMap(shadowClassesRight)}></div>
|
|
478
|
+
</div>
|
|
479
|
+
|
|
480
|
+
${this.itemsOnAPage > 0
|
|
481
|
+
? html`
|
|
482
|
+
<leu-pagination
|
|
483
|
+
.dataLength=${this._sortedData.length}
|
|
484
|
+
.itemsOnAPage=${this.itemsOnAPage}
|
|
485
|
+
@range-updated=${(e) => {
|
|
486
|
+
this._min = e.detail.min;
|
|
487
|
+
this._max = e.detail.max;
|
|
488
|
+
// after render
|
|
489
|
+
setTimeout(() => {
|
|
490
|
+
this.shadowToggle(this._scrollRef.value);
|
|
491
|
+
}, 0);
|
|
492
|
+
}}
|
|
493
|
+
>
|
|
494
|
+
</leu-pagination>
|
|
495
|
+
`
|
|
496
|
+
: nothing}
|
|
497
|
+
`
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
function defineTableElements() {
|
|
502
|
+
definePaginationElements();
|
|
503
|
+
defineElement("table", LeuTable);
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
export { LeuPagination as L, LeuTable as a, defineTableElements as b, definePaginationElements as d };
|
package/dist/Table.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import 'lit';
|
|
2
|
+
import 'lit/directives/class-map.js';
|
|
3
|
+
import 'lit/directives/style-map.js';
|
|
4
|
+
import 'lit/directives/ref.js';
|
|
5
|
+
import './icon-b68c7e1e.js';
|
|
6
|
+
import './defineElement-47d4f665.js';
|
|
7
|
+
export { a as LeuTable, b as defineTableElements } from './Table-72d305d7.js';
|
|
8
|
+
import './Button-83c6df93.js';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Adds a definition for a custom element to the custom element
|
|
3
|
+
* registry if it isn't defined before. Prefixes the name with `leu-`.
|
|
4
|
+
* @param {string} name
|
|
5
|
+
* @param {HTMLElement} constructor
|
|
6
|
+
*/
|
|
7
|
+
function defineElement(name, constructor) {
|
|
8
|
+
if (!customElements.get(`leu-${name}`)) {
|
|
9
|
+
customElements.define(`leu-${name}`, constructor);
|
|
10
|
+
} else {
|
|
11
|
+
console.info(`leu-${name} is already defined`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { defineElement as d };
|