@3t-transform/threeteeui 0.0.15 → 0.0.17
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/dist/cjs/index-864b7110.js +1531 -0
- package/dist/cjs/index.cjs.js +2 -0
- package/dist/cjs/loader.cjs.js +22 -0
- package/dist/cjs/tttx-button.cjs.entry.js +34 -0
- package/dist/cjs/tttx-checkbox.cjs.entry.js +28 -0
- package/dist/cjs/tttx-form.cjs.entry.js +374 -0
- package/dist/cjs/tttx-icon.cjs.entry.js +21 -0
- package/dist/cjs/tttx-input-calendar.cjs.entry.js +125 -0
- package/dist/cjs/tttx-keyvalue-block.cjs.entry.js +33 -0
- package/dist/cjs/tttx-list.cjs.entry.js +198 -0
- package/dist/cjs/tttx-loading-spinner.cjs.entry.js +26 -0
- package/dist/cjs/tttx-popover-content.cjs.entry.js +23 -0
- package/dist/cjs/tttx-standalone-input.cjs.entry.js +136 -0
- package/dist/cjs/tttx-table.cjs.entry.js +60 -0
- package/dist/cjs/tttx.cjs.js +23 -0
- package/dist/collection/collection-manifest.json +22 -0
- package/dist/collection/components/atoms/tttx-button/tttx-button.css +138 -0
- package/dist/collection/components/atoms/tttx-button/tttx-button.js +110 -0
- package/dist/collection/components/atoms/tttx-button/tttx-button.stories.js +74 -0
- package/dist/collection/components/atoms/tttx-icon/tttx-icon.css +108 -0
- package/dist/collection/components/atoms/tttx-icon/tttx-icon.js +62 -0
- package/dist/collection/components/atoms/tttx-icon/tttx-icon.stories.js +22 -0
- package/dist/collection/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.css +26 -0
- package/dist/collection/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.js +56 -0
- package/dist/collection/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.stories.js +12 -0
- package/dist/collection/components/atoms/tttx-loading-spinner/tttx-loading-spinner.css +48 -0
- package/dist/collection/components/atoms/tttx-loading-spinner/tttx-loading-spinner.js +67 -0
- package/dist/collection/components/atoms/tttx-loading-spinner/tttx-loading-spinner.stories.js +17 -0
- package/dist/collection/components/atoms/tttx-popover-content/tttx-popover-content.css +30 -0
- package/dist/collection/components/atoms/tttx-popover-content/tttx-popover-content.js +97 -0
- package/dist/collection/components/atoms/tttx-popover-content/tttx-popover-content.stories.js +23 -0
- package/dist/collection/components/atoms/ttx-checkbox/tttx-checkbox.css +181 -0
- package/dist/collection/components/atoms/ttx-checkbox/tttx-checkbox.js +102 -0
- package/dist/collection/components/atoms/ttx-checkbox/tttx-checkbox.stories.js +13 -0
- package/dist/collection/components/molecules/tttx-form/tttx-form.css +314 -0
- package/dist/collection/components/molecules/tttx-form/tttx-form.js +452 -0
- package/dist/collection/components/molecules/tttx-form/tttx-form.stories.js +109 -0
- package/dist/collection/components/molecules/tttx-input-calendar/tttx-input-calendar.css +93 -0
- package/dist/collection/components/molecules/tttx-input-calendar/tttx-input-calendar.js +174 -0
- package/dist/collection/components/molecules/tttx-input-calendar/tttx-input-calendar.stories.js +27 -0
- package/dist/collection/components/molecules/tttx-list/tttx-list.css +56 -0
- package/dist/collection/components/molecules/tttx-list/tttx-list.js +312 -0
- package/dist/collection/components/molecules/tttx-list/tttx-list.stories.js +37 -0
- package/dist/collection/components/molecules/tttx-standalone-input/tttx-standalone-input.css +177 -0
- package/dist/collection/components/molecules/tttx-standalone-input/tttx-standalone-input.js +570 -0
- package/dist/collection/components/molecules/tttx-standalone-input/tttx-standalone-input.stories.js +156 -0
- package/dist/collection/components/molecules/tttx-table/tttx-table.css +166 -0
- package/dist/collection/components/molecules/tttx-table/tttx-table.js +174 -0
- package/dist/collection/components/molecules/tttx-table/tttx-table.stories.js +81 -0
- package/dist/collection/components/palette.stories.js +88 -0
- package/dist/collection/docs/gettingstarted-developer.stories.js +9 -0
- package/dist/collection/icons.js +2838 -0
- package/dist/collection/index.js +1 -0
- package/dist/components/index.d.ts +41 -0
- package/dist/components/index.js +12 -0
- package/dist/components/tttx-button.d.ts +11 -0
- package/dist/components/tttx-button.js +6 -0
- package/dist/components/tttx-button2.js +56 -0
- package/dist/components/tttx-checkbox.d.ts +11 -0
- package/dist/components/tttx-checkbox.js +46 -0
- package/dist/components/tttx-form.d.ts +11 -0
- package/dist/components/tttx-form.js +391 -0
- package/dist/components/tttx-icon.d.ts +11 -0
- package/dist/components/tttx-icon.js +6 -0
- package/dist/components/tttx-icon2.js +35 -0
- package/dist/components/tttx-input-calendar.d.ts +11 -0
- package/dist/components/tttx-input-calendar.js +157 -0
- package/dist/components/tttx-keyvalue-block.d.ts +11 -0
- package/dist/components/tttx-keyvalue-block.js +49 -0
- package/dist/components/tttx-list.d.ts +11 -0
- package/dist/components/tttx-list.js +225 -0
- package/dist/components/tttx-loading-spinner.d.ts +11 -0
- package/dist/components/tttx-loading-spinner.js +6 -0
- package/dist/components/tttx-loading-spinner2.js +40 -0
- package/dist/components/tttx-popover-content.d.ts +11 -0
- package/dist/components/tttx-popover-content.js +6 -0
- package/dist/components/tttx-popover-content2.js +39 -0
- package/dist/components/tttx-standalone-input.d.ts +11 -0
- package/dist/components/tttx-standalone-input.js +179 -0
- package/dist/components/tttx-table.d.ts +11 -0
- package/dist/components/tttx-table.js +91 -0
- package/dist/esm/index-232e347b.js +1502 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/loader.js +18 -0
- package/dist/esm/polyfills/core-js.js +11 -0
- package/dist/esm/polyfills/css-shim.js +1 -0
- package/dist/esm/polyfills/dom.js +79 -0
- package/dist/esm/polyfills/es5-html-element.js +1 -0
- package/dist/esm/polyfills/index.js +34 -0
- package/dist/esm/polyfills/system.js +6 -0
- package/dist/esm/tttx-button.entry.js +30 -0
- package/dist/esm/tttx-checkbox.entry.js +24 -0
- package/dist/esm/tttx-form.entry.js +370 -0
- package/dist/esm/tttx-icon.entry.js +17 -0
- package/dist/esm/tttx-input-calendar.entry.js +121 -0
- package/dist/esm/tttx-keyvalue-block.entry.js +29 -0
- package/dist/esm/tttx-list.entry.js +194 -0
- package/dist/esm/tttx-loading-spinner.entry.js +22 -0
- package/dist/esm/tttx-popover-content.entry.js +19 -0
- package/dist/esm/tttx-standalone-input.entry.js +132 -0
- package/dist/esm/tttx-table.entry.js +56 -0
- package/dist/esm/tttx.js +18 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.js +1 -0
- package/dist/tttx/index.esm.js +0 -0
- package/dist/tttx/p-01e1894e.entry.js +1 -0
- package/dist/tttx/p-184c4fae.js +2 -0
- package/dist/tttx/p-1bc3dfee.entry.js +1 -0
- package/dist/tttx/p-1cf8f9e8.entry.js +1 -0
- package/dist/tttx/p-220f7519.entry.js +1 -0
- package/dist/tttx/p-3973b7dd.entry.js +1 -0
- package/dist/tttx/p-5247e827.entry.js +1 -0
- package/dist/tttx/p-6828fe6f.entry.js +1 -0
- package/dist/tttx/p-81904eed.entry.js +1 -0
- package/dist/tttx/p-cf107fb6.entry.js +1 -0
- package/dist/tttx/p-f56fe662.entry.js +1 -0
- package/dist/tttx/p-fe4c70b2.entry.js +1 -0
- package/dist/tttx/tttx.esm.js +1 -0
- package/dist/types/components/atoms/tttx-button/tttx-button.d.ts +10 -0
- package/dist/types/components/atoms/tttx-button/tttx-button.stories.d.ts +10 -0
- package/dist/types/components/atoms/tttx-icon/tttx-icon.d.ts +5 -0
- package/dist/types/components/atoms/tttx-icon/tttx-icon.stories.d.ts +20 -0
- package/dist/types/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.d.ts +4 -0
- package/dist/types/components/atoms/tttx-keyvalue-block/tttx-keyvalue-block.stories.d.ts +6 -0
- package/dist/types/components/atoms/tttx-loading-spinner/tttx-loading-spinner.d.ts +6 -0
- package/dist/types/components/atoms/tttx-loading-spinner/tttx-loading-spinner.stories.d.ts +17 -0
- package/dist/types/components/atoms/tttx-popover-content/tttx-popover-content.d.ts +7 -0
- package/dist/types/components/atoms/tttx-popover-content/tttx-popover-content.stories.d.ts +18 -0
- package/dist/types/components/atoms/ttx-checkbox/tttx-checkbox.d.ts +9 -0
- package/dist/types/components/atoms/ttx-checkbox/tttx-checkbox.stories.d.ts +6 -0
- package/dist/types/components/molecules/tttx-form/tttx-form.d.ts +134 -0
- package/dist/types/components/molecules/tttx-form/tttx-form.stories.d.ts +12 -0
- package/dist/types/components/molecules/tttx-input-calendar/tttx-input-calendar.d.ts +19 -0
- package/dist/types/components/molecules/tttx-input-calendar/tttx-input-calendar.stories.d.ts +26 -0
- package/dist/types/components/molecules/tttx-list/tttx-list.d.ts +51 -0
- package/dist/types/components/molecules/tttx-list/tttx-list.stories.d.ts +13 -0
- package/dist/types/components/molecules/tttx-standalone-input/tttx-standalone-input.d.ts +38 -0
- package/dist/types/components/molecules/tttx-standalone-input/tttx-standalone-input.stories.d.ts +106 -0
- package/dist/types/components/molecules/tttx-table/tttx-table.d.ts +15 -0
- package/dist/types/components/molecules/tttx-table/tttx-table.stories.d.ts +21 -0
- package/dist/types/components/palette.stories.d.ts +6 -0
- package/dist/types/components.d.ts +295 -0
- package/dist/types/docs/gettingstarted-developer.stories.d.ts +5 -0
- package/dist/types/icons.d.ts +2 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/stencil-public-runtime.d.ts +1637 -0
- package/loader/cdn.js +3 -0
- package/loader/index.cjs.js +3 -0
- package/loader/index.d.ts +21 -0
- package/loader/index.es2017.js +3 -0
- package/loader/index.js +4 -0
- package/loader/package.json +11 -0
- package/package.json +4 -4
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2
|
+
import { Host, h } from '@stencil/core';
|
|
3
|
+
export class TttxInputCalendar {
|
|
4
|
+
constructor() {
|
|
5
|
+
// an array of month numbers mapped to their names
|
|
6
|
+
this.monthNames = Array.from({ length: 12 }, (_, i) => i + 1).map((month) => {
|
|
7
|
+
const date = new Date(0);
|
|
8
|
+
date.setUTCMonth(month - 1);
|
|
9
|
+
return date.toLocaleString('default', { month: 'long' });
|
|
10
|
+
});
|
|
11
|
+
this.onClickOutside = (event) => {
|
|
12
|
+
if (!this.el.contains(event.target) && this.showCalendar) {
|
|
13
|
+
this.showCalendar = false;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
this.onFocusIn = (event) => {
|
|
17
|
+
if (!this.el.contains(event.target) && this.showCalendar) {
|
|
18
|
+
this.showCalendar = false;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
this.previousHandler = () => {
|
|
22
|
+
if (this.selectedMonth === 1) {
|
|
23
|
+
this.selectedMonth = 12;
|
|
24
|
+
this.selectedYear--;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this.selectedMonth--;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
this.nextHandler = () => {
|
|
31
|
+
if (this.selectedMonth === 12) {
|
|
32
|
+
this.selectedMonth = 1;
|
|
33
|
+
this.selectedYear++;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
this.selectedMonth++;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
this.months = false;
|
|
40
|
+
this.years = false;
|
|
41
|
+
this.showCalendar = false;
|
|
42
|
+
this.selectedYear = new Date().getFullYear();
|
|
43
|
+
this.selectedMonth = new Date().getMonth() + 1;
|
|
44
|
+
}
|
|
45
|
+
componentDidLoad() {
|
|
46
|
+
const slot = this.el.shadowRoot.querySelector('slot');
|
|
47
|
+
if (slot) {
|
|
48
|
+
const assignedElements = slot.assignedElements();
|
|
49
|
+
if (assignedElements[0]) {
|
|
50
|
+
assignedElements[0].addEventListener('click', (event) => {
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
this.showCalendar = !this.showCalendar;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
document.addEventListener('click', this.onClickOutside);
|
|
57
|
+
}
|
|
58
|
+
disconnectedCallback() {
|
|
59
|
+
document.removeEventListener('click', this.onClickOutside);
|
|
60
|
+
}
|
|
61
|
+
getDaysAndDates(year, month) {
|
|
62
|
+
const firstDayOfMonth = new Date(year, month - 1, 1);
|
|
63
|
+
const lastDayOfMonth = new Date(year, month, 0);
|
|
64
|
+
const daysAndDates = [];
|
|
65
|
+
for (let day = firstDayOfMonth; day <= lastDayOfMonth; day.setDate(day.getDate() + 1)) {
|
|
66
|
+
const weekDay = day.getDay();
|
|
67
|
+
const date = day.getDate();
|
|
68
|
+
const dayAndDate = {
|
|
69
|
+
day: weekDay,
|
|
70
|
+
date: date
|
|
71
|
+
};
|
|
72
|
+
daysAndDates.push(dayAndDate);
|
|
73
|
+
}
|
|
74
|
+
return daysAndDates;
|
|
75
|
+
}
|
|
76
|
+
clickDateHandler(event) {
|
|
77
|
+
const { year, month, day } = event;
|
|
78
|
+
const selectedDate = new Date(year, month - 1, day + 1);
|
|
79
|
+
this.inputElement.valueAsDate = selectedDate;
|
|
80
|
+
this.showCalendar = false;
|
|
81
|
+
}
|
|
82
|
+
render() {
|
|
83
|
+
const daysOfWeek = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
|
|
84
|
+
const daysAndDates = this.getDaysAndDates(this.selectedYear, this.selectedMonth);
|
|
85
|
+
const currentYear = new Date().getFullYear();
|
|
86
|
+
const years = Array.from({ length: 11 }, (_, i) => currentYear - 5 + i);
|
|
87
|
+
const calendarGrid = [];
|
|
88
|
+
let currentWeek = [];
|
|
89
|
+
// Fill empty days before the first day of the month
|
|
90
|
+
for (let i = 0; i < daysAndDates[0].day; i++) {
|
|
91
|
+
currentWeek.push(h("td", null));
|
|
92
|
+
}
|
|
93
|
+
// Fill the calendar with days and dates
|
|
94
|
+
daysAndDates.forEach(({ day, date }) => {
|
|
95
|
+
currentWeek.push(h("td", null, h("span", { onClick: () => this.clickDateHandler({ year: this.selectedYear, month: this.selectedMonth, day: date }) }, date)));
|
|
96
|
+
if (day === 6) {
|
|
97
|
+
calendarGrid.push(h("tr", null, currentWeek));
|
|
98
|
+
currentWeek = [];
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
// Fill the remaining empty days in the last week
|
|
102
|
+
if (currentWeek.length > 0) {
|
|
103
|
+
while (currentWeek.length < 7) {
|
|
104
|
+
currentWeek.push(h("td", null));
|
|
105
|
+
}
|
|
106
|
+
calendarGrid.push(h("tr", null, currentWeek));
|
|
107
|
+
}
|
|
108
|
+
return (h(Host, null, h("div", { class: "calcontainer" }, h("slot", null), h("div", { class: `calendar ${this.showCalendar ? 'calendar-visible' : ''}` }, h("div", { class: "calendar-header" }, h("tttx-button", { onClick: this.previousHandler, design: "borderless", icon: "chevron_left", notext: true }), this.months && h("select", { id: "month-select", onInput: (event) => {
|
|
109
|
+
this.selectedMonth = parseInt(event.target.value);
|
|
110
|
+
} }, Array.from({ length: 12 }, (_, i) => i + 1).map((month) => (h("option", { value: month, selected: month === this.selectedMonth }, this.monthNames[month - 1])))), this.years && h("select", { id: "year-select", onInput: (event) => {
|
|
111
|
+
this.selectedYear = parseInt(event.target.value);
|
|
112
|
+
} }, years.map((year) => (h("option", { value: year, selected: year === this.selectedYear }, year)))), h("div", { class: "date-display" }, this.monthNames[this.selectedMonth - 1], " ", this.selectedYear), h("tttx-button", { onClick: this.nextHandler, design: "borderless", icon: "chevron_right", notext: true })), h("table", { class: "calendar-table" }, h("thead", null, h("tr", null, daysOfWeek.map((day) => (h("th", null, day))))), h("tbody", null, calendarGrid))))));
|
|
113
|
+
}
|
|
114
|
+
static get is() { return "tttx-input-calendar"; }
|
|
115
|
+
static get encapsulation() { return "shadow"; }
|
|
116
|
+
static get originalStyleUrls() {
|
|
117
|
+
return {
|
|
118
|
+
"$": ["tttx-input-calendar.scss"]
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
static get styleUrls() {
|
|
122
|
+
return {
|
|
123
|
+
"$": ["tttx-input-calendar.css"]
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
static get properties() {
|
|
127
|
+
return {
|
|
128
|
+
"months": {
|
|
129
|
+
"type": "boolean",
|
|
130
|
+
"mutable": false,
|
|
131
|
+
"complexType": {
|
|
132
|
+
"original": "boolean",
|
|
133
|
+
"resolved": "boolean",
|
|
134
|
+
"references": {}
|
|
135
|
+
},
|
|
136
|
+
"required": false,
|
|
137
|
+
"optional": false,
|
|
138
|
+
"docs": {
|
|
139
|
+
"tags": [],
|
|
140
|
+
"text": ""
|
|
141
|
+
},
|
|
142
|
+
"attribute": "months",
|
|
143
|
+
"reflect": false,
|
|
144
|
+
"defaultValue": "false"
|
|
145
|
+
},
|
|
146
|
+
"years": {
|
|
147
|
+
"type": "boolean",
|
|
148
|
+
"mutable": false,
|
|
149
|
+
"complexType": {
|
|
150
|
+
"original": "boolean",
|
|
151
|
+
"resolved": "boolean",
|
|
152
|
+
"references": {}
|
|
153
|
+
},
|
|
154
|
+
"required": false,
|
|
155
|
+
"optional": false,
|
|
156
|
+
"docs": {
|
|
157
|
+
"tags": [],
|
|
158
|
+
"text": ""
|
|
159
|
+
},
|
|
160
|
+
"attribute": "years",
|
|
161
|
+
"reflect": false,
|
|
162
|
+
"defaultValue": "false"
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
static get states() {
|
|
167
|
+
return {
|
|
168
|
+
"showCalendar": {},
|
|
169
|
+
"selectedYear": {},
|
|
170
|
+
"selectedMonth": {}
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
static get elementRef() { return "el"; }
|
|
174
|
+
}
|
package/dist/collection/components/molecules/tttx-input-calendar/tttx-input-calendar.stories.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { withActions } from '@storybook/addon-actions/decorator';
|
|
2
|
+
export default {
|
|
3
|
+
title: 'molecules/Calendar',
|
|
4
|
+
component: 'tttx-input-calendar',
|
|
5
|
+
argTypes: {
|
|
6
|
+
required: {
|
|
7
|
+
control: {
|
|
8
|
+
type: 'boolean'
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
parameters: {
|
|
13
|
+
actions: {
|
|
14
|
+
handles: ['valueChanged', 'focusChanged', 'blurChanged'],
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
decorators: [withActions],
|
|
18
|
+
};
|
|
19
|
+
export const BasicCalendar = ({ required }) => {
|
|
20
|
+
return `<tttx-input-calendar>
|
|
21
|
+
<tttx-standalone-input ${required ? 'required' : ''} label="Choose a date" type="date" />
|
|
22
|
+
</tttx-input-calendar>
|
|
23
|
+
`;
|
|
24
|
+
};
|
|
25
|
+
BasicCalendar.args = {
|
|
26
|
+
required: true
|
|
27
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
.material-symbols-rounded {
|
|
2
|
+
font-variation-settings: "FILL" 1, "wght" 400, "GRAD" 0, "opsz" 24;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.material-symbols-rounded {
|
|
6
|
+
font-family: "Material Symbols Rounded", sans-serif;
|
|
7
|
+
font-weight: 400;
|
|
8
|
+
font-style: normal;
|
|
9
|
+
font-size: 24px;
|
|
10
|
+
line-height: 1;
|
|
11
|
+
letter-spacing: normal;
|
|
12
|
+
text-transform: none;
|
|
13
|
+
display: inline-block;
|
|
14
|
+
white-space: nowrap;
|
|
15
|
+
word-wrap: normal;
|
|
16
|
+
direction: ltr;
|
|
17
|
+
text-rendering: optimizeLegibility;
|
|
18
|
+
-webkit-font-smoothing: antialiased;
|
|
19
|
+
color: #9e9e9e;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
:host {
|
|
23
|
+
display: flex;
|
|
24
|
+
flex-direction: column;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.tttx-list__row {
|
|
28
|
+
min-height: 52px;
|
|
29
|
+
line-height: 36px;
|
|
30
|
+
padding: 8px;
|
|
31
|
+
display: flex;
|
|
32
|
+
flex-direction: row;
|
|
33
|
+
align-items: center;
|
|
34
|
+
cursor: pointer;
|
|
35
|
+
border-bottom: 1px solid #d5d5d5;
|
|
36
|
+
}
|
|
37
|
+
.tttx-list__row .generic-template__content {
|
|
38
|
+
width: 100%;
|
|
39
|
+
display: flex;
|
|
40
|
+
align-items: center;
|
|
41
|
+
gap: 8px;
|
|
42
|
+
}
|
|
43
|
+
.tttx-list__row:first-of-type {
|
|
44
|
+
border-top: 1px solid #d5d5d5;
|
|
45
|
+
}
|
|
46
|
+
.tttx-list__row:focus, .tttx-list__row:active {
|
|
47
|
+
background-color: #e6e6e6;
|
|
48
|
+
}
|
|
49
|
+
.tttx-list__row.selected {
|
|
50
|
+
background-color: #e7f1f9;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.load-indicator {
|
|
54
|
+
display: flex;
|
|
55
|
+
justify-content: center;
|
|
56
|
+
}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
2
|
+
import { h, Host } from '@stencil/core';
|
|
3
|
+
export class TttxList {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.rowCount = 0;
|
|
6
|
+
this.name = undefined;
|
|
7
|
+
this.selectable = undefined;
|
|
8
|
+
this.items = [];
|
|
9
|
+
this.selectedIds = [];
|
|
10
|
+
this.loading = true;
|
|
11
|
+
this.lastPage = false;
|
|
12
|
+
}
|
|
13
|
+
listLoadHandler(event) {
|
|
14
|
+
if (event.detail.name !== this.name)
|
|
15
|
+
return;
|
|
16
|
+
this.items = [...this.items, ...event.detail.items];
|
|
17
|
+
this.loading = false;
|
|
18
|
+
this.lastPage = event.detail.lastPage;
|
|
19
|
+
this.renderRows(event.detail.items);
|
|
20
|
+
if (this.scrollableParent.clientHeight === this.scrollableParent.scrollHeight)
|
|
21
|
+
this.listPaginateHandler();
|
|
22
|
+
}
|
|
23
|
+
listPaginateHandler() {
|
|
24
|
+
// We don't want to emit an event to load the next page if this is the last page, or if we're already loading
|
|
25
|
+
if (this.lastPage || this.loading)
|
|
26
|
+
return;
|
|
27
|
+
this.loading = true;
|
|
28
|
+
this.listPaginate.emit({ name: this.name });
|
|
29
|
+
}
|
|
30
|
+
listClearDataCacheHandler(event) {
|
|
31
|
+
if (event.detail.name !== this.name)
|
|
32
|
+
return;
|
|
33
|
+
this.items = [];
|
|
34
|
+
this.selectedIds = [];
|
|
35
|
+
this.listItemContainer()
|
|
36
|
+
.querySelectorAll('.tttx-list__row')
|
|
37
|
+
.forEach((node) => {
|
|
38
|
+
node.remove();
|
|
39
|
+
});
|
|
40
|
+
this.rowCount = 0;
|
|
41
|
+
this.lastPage = false;
|
|
42
|
+
this.loading = false;
|
|
43
|
+
}
|
|
44
|
+
listActionSelectedEventHandler(event) {
|
|
45
|
+
if (event.detail.name !== this.name || !this.selectable || this.selectedIds.length === 0)
|
|
46
|
+
return;
|
|
47
|
+
const selectedRows = this.selectedIds.map(id => {
|
|
48
|
+
return this.items[id];
|
|
49
|
+
});
|
|
50
|
+
if (event.detail.removeRows)
|
|
51
|
+
this.removeSelectedRows();
|
|
52
|
+
this.listSelectedEvent.emit({
|
|
53
|
+
name: this.name,
|
|
54
|
+
eventName: event.detail.eventName,
|
|
55
|
+
selectedRows,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
removeSelectedRows() {
|
|
59
|
+
const orderedSelectedIds = [...this.selectedIds].sort((a, b) => {
|
|
60
|
+
return b - a;
|
|
61
|
+
});
|
|
62
|
+
orderedSelectedIds.forEach(itemIndex => {
|
|
63
|
+
this.items.splice(itemIndex, 1);
|
|
64
|
+
this.listItemContainer().removeChild(this.listItemContainer().querySelector(`[data-row-id="${itemIndex}"]`));
|
|
65
|
+
// If this removes the scrollbar and we're not on the last page, load in a new page
|
|
66
|
+
if (this.scrollableParent.clientHeight === this.scrollableParent.scrollHeight)
|
|
67
|
+
this.listPaginateHandler();
|
|
68
|
+
});
|
|
69
|
+
// Empty selected ids with mutation rather than assignment to avoid unecessary component rerender
|
|
70
|
+
this.selectedIds.splice(0, this.selectedIds.length);
|
|
71
|
+
}
|
|
72
|
+
listItemClickHandler(itemData) {
|
|
73
|
+
if (this.selectedIds.length !== 0)
|
|
74
|
+
return;
|
|
75
|
+
this.listItemClick.emit({ itemData, name: this.name });
|
|
76
|
+
}
|
|
77
|
+
componentWillLoad() {
|
|
78
|
+
this.template = this.host.querySelector('template');
|
|
79
|
+
this.scrollableParent = this.getScrollableParent(this.host);
|
|
80
|
+
const scrollableContext = this.scrollableParent === document.scrollingElement ? document : this.scrollableParent;
|
|
81
|
+
scrollableContext.addEventListener('scroll', this.scrollHandler.bind(this));
|
|
82
|
+
window.addEventListener('resize', this.scrollHandler.bind(this));
|
|
83
|
+
}
|
|
84
|
+
componentDidLoad() {
|
|
85
|
+
// Emit event to load first page
|
|
86
|
+
this.listPaginate.emit({ name: this.name });
|
|
87
|
+
}
|
|
88
|
+
listItemContainer() {
|
|
89
|
+
return this.host.shadowRoot.querySelector('.list-item-container');
|
|
90
|
+
}
|
|
91
|
+
async scrollHandler() {
|
|
92
|
+
const { clientHeight, scrollTop, scrollHeight } = this.scrollableParent;
|
|
93
|
+
if (Math.abs(scrollHeight - clientHeight - scrollTop) < 26)
|
|
94
|
+
this.listPaginateHandler();
|
|
95
|
+
}
|
|
96
|
+
isScrollable(node) {
|
|
97
|
+
const hasScrollbar = ['scroll', 'auto'].includes(node.style.overflowY);
|
|
98
|
+
return hasScrollbar;
|
|
99
|
+
}
|
|
100
|
+
getScrollableParent(node) {
|
|
101
|
+
if (!node || node === document.body) {
|
|
102
|
+
return document.scrollingElement;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
return this.isScrollable(node) ? node : this.getScrollableParent(node.parentElement);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
appendRowCheckbox(rowContainer) {
|
|
109
|
+
if (!this.selectable)
|
|
110
|
+
return;
|
|
111
|
+
const rowId = this.rowCount;
|
|
112
|
+
const checkbox = document.createElement('input');
|
|
113
|
+
checkbox.setAttribute('type', 'checkbox');
|
|
114
|
+
checkbox.addEventListener('click', e => {
|
|
115
|
+
e.stopPropagation();
|
|
116
|
+
if (e.target.checked) {
|
|
117
|
+
this.selectedIds = [...this.selectedIds, rowId];
|
|
118
|
+
rowContainer.classList.add('selected');
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
this.selectedIds = this.selectedIds.filter(id => {
|
|
122
|
+
return id !== rowId;
|
|
123
|
+
});
|
|
124
|
+
rowContainer.classList.remove('selected');
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
rowContainer.setAttribute('data-row-id', `${rowId}`);
|
|
128
|
+
this.rowCount++;
|
|
129
|
+
rowContainer.appendChild(checkbox);
|
|
130
|
+
}
|
|
131
|
+
appendSeededTemplate(rowData, rowContainer) {
|
|
132
|
+
this.template.childNodes.forEach(child => {
|
|
133
|
+
const clone = child.cloneNode(false);
|
|
134
|
+
if (clone.getAttribute('data-fields')) {
|
|
135
|
+
const fields = clone.getAttribute('data-fields').replace(/\s/g, '').split(',');
|
|
136
|
+
const filteredRowData = Object.fromEntries(fields.map((field) => {
|
|
137
|
+
return [field, rowData[field]];
|
|
138
|
+
}));
|
|
139
|
+
clone.setAttribute('row-data', JSON.stringify(filteredRowData));
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
clone.setAttribute('row-data', JSON.stringify(rowData));
|
|
143
|
+
}
|
|
144
|
+
rowContainer.appendChild(clone);
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
appendGenericTemplate(rowData, rowContainer) {
|
|
148
|
+
const row = document.createElement('div');
|
|
149
|
+
row.classList.add('generic-template__content');
|
|
150
|
+
row.textContent = rowData.text;
|
|
151
|
+
rowContainer.appendChild(row);
|
|
152
|
+
if (!rowData.icon)
|
|
153
|
+
return;
|
|
154
|
+
const icon = document.createElement('span');
|
|
155
|
+
icon.classList.add('material-symbols-rounded');
|
|
156
|
+
icon.textContent = rowData.icon;
|
|
157
|
+
if (rowData.iconColor)
|
|
158
|
+
icon.style['color'] = rowData.iconColor;
|
|
159
|
+
row.prepend(icon);
|
|
160
|
+
}
|
|
161
|
+
row(rowData) {
|
|
162
|
+
const rowContainer = document.createElement('div');
|
|
163
|
+
rowContainer.classList.add('tttx-list__row');
|
|
164
|
+
rowContainer.addEventListener('click', () => {
|
|
165
|
+
this.listItemClickHandler(rowData);
|
|
166
|
+
});
|
|
167
|
+
this.appendRowCheckbox(rowContainer);
|
|
168
|
+
this.template ? this.appendSeededTemplate(rowData, rowContainer) : this.appendGenericTemplate(rowData, rowContainer);
|
|
169
|
+
return rowContainer;
|
|
170
|
+
}
|
|
171
|
+
renderRows(batchData) {
|
|
172
|
+
batchData.forEach(rowData => {
|
|
173
|
+
this.listItemContainer().appendChild(this.row(rowData));
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
loadIndicator() {
|
|
177
|
+
if (!this.loading)
|
|
178
|
+
return;
|
|
179
|
+
return h("div", { class: "load-indicator" }, h("tttx-loading-spinner", { size: 'large' }));
|
|
180
|
+
}
|
|
181
|
+
render() {
|
|
182
|
+
return (h(Host, null, h("div", { class: "list-item-container", tabindex: "0" }, !this.loading && this.items.length === 0 ? 'No data to display' : undefined), this.loadIndicator()));
|
|
183
|
+
}
|
|
184
|
+
static get is() { return "tttx-list"; }
|
|
185
|
+
static get encapsulation() { return "shadow"; }
|
|
186
|
+
static get originalStyleUrls() {
|
|
187
|
+
return {
|
|
188
|
+
"$": ["tttx-list.scss"]
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
static get styleUrls() {
|
|
192
|
+
return {
|
|
193
|
+
"$": ["tttx-list.css"]
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
static get properties() {
|
|
197
|
+
return {
|
|
198
|
+
"name": {
|
|
199
|
+
"type": "string",
|
|
200
|
+
"mutable": false,
|
|
201
|
+
"complexType": {
|
|
202
|
+
"original": "string",
|
|
203
|
+
"resolved": "string",
|
|
204
|
+
"references": {}
|
|
205
|
+
},
|
|
206
|
+
"required": false,
|
|
207
|
+
"optional": false,
|
|
208
|
+
"docs": {
|
|
209
|
+
"tags": [],
|
|
210
|
+
"text": ""
|
|
211
|
+
},
|
|
212
|
+
"attribute": "name",
|
|
213
|
+
"reflect": false
|
|
214
|
+
},
|
|
215
|
+
"selectable": {
|
|
216
|
+
"type": "boolean",
|
|
217
|
+
"mutable": false,
|
|
218
|
+
"complexType": {
|
|
219
|
+
"original": "boolean",
|
|
220
|
+
"resolved": "boolean",
|
|
221
|
+
"references": {}
|
|
222
|
+
},
|
|
223
|
+
"required": false,
|
|
224
|
+
"optional": false,
|
|
225
|
+
"docs": {
|
|
226
|
+
"tags": [],
|
|
227
|
+
"text": ""
|
|
228
|
+
},
|
|
229
|
+
"attribute": "selectable",
|
|
230
|
+
"reflect": false
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
static get states() {
|
|
235
|
+
return {
|
|
236
|
+
"items": {},
|
|
237
|
+
"selectedIds": {},
|
|
238
|
+
"loading": {},
|
|
239
|
+
"lastPage": {}
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
static get events() {
|
|
243
|
+
return [{
|
|
244
|
+
"method": "listPaginate",
|
|
245
|
+
"name": "listPaginate",
|
|
246
|
+
"bubbles": true,
|
|
247
|
+
"cancelable": true,
|
|
248
|
+
"composed": true,
|
|
249
|
+
"docs": {
|
|
250
|
+
"tags": [],
|
|
251
|
+
"text": ""
|
|
252
|
+
},
|
|
253
|
+
"complexType": {
|
|
254
|
+
"original": "any",
|
|
255
|
+
"resolved": "any",
|
|
256
|
+
"references": {}
|
|
257
|
+
}
|
|
258
|
+
}, {
|
|
259
|
+
"method": "listSelectedEvent",
|
|
260
|
+
"name": "listSelectedEvent",
|
|
261
|
+
"bubbles": true,
|
|
262
|
+
"cancelable": true,
|
|
263
|
+
"composed": true,
|
|
264
|
+
"docs": {
|
|
265
|
+
"tags": [],
|
|
266
|
+
"text": ""
|
|
267
|
+
},
|
|
268
|
+
"complexType": {
|
|
269
|
+
"original": "any",
|
|
270
|
+
"resolved": "any",
|
|
271
|
+
"references": {}
|
|
272
|
+
}
|
|
273
|
+
}, {
|
|
274
|
+
"method": "listItemClick",
|
|
275
|
+
"name": "listItemClick",
|
|
276
|
+
"bubbles": true,
|
|
277
|
+
"cancelable": true,
|
|
278
|
+
"composed": true,
|
|
279
|
+
"docs": {
|
|
280
|
+
"tags": [],
|
|
281
|
+
"text": ""
|
|
282
|
+
},
|
|
283
|
+
"complexType": {
|
|
284
|
+
"original": "any",
|
|
285
|
+
"resolved": "any",
|
|
286
|
+
"references": {}
|
|
287
|
+
}
|
|
288
|
+
}];
|
|
289
|
+
}
|
|
290
|
+
static get elementRef() { return "host"; }
|
|
291
|
+
static get listeners() {
|
|
292
|
+
return [{
|
|
293
|
+
"name": "listPageLoad",
|
|
294
|
+
"method": "listLoadHandler",
|
|
295
|
+
"target": "document",
|
|
296
|
+
"capture": false,
|
|
297
|
+
"passive": false
|
|
298
|
+
}, {
|
|
299
|
+
"name": "listClearDataCache",
|
|
300
|
+
"method": "listClearDataCacheHandler",
|
|
301
|
+
"target": "document",
|
|
302
|
+
"capture": false,
|
|
303
|
+
"passive": false
|
|
304
|
+
}, {
|
|
305
|
+
"name": "listActionSelectedEvent",
|
|
306
|
+
"method": "listActionSelectedEventHandler",
|
|
307
|
+
"target": "document",
|
|
308
|
+
"capture": false,
|
|
309
|
+
"passive": false
|
|
310
|
+
}];
|
|
311
|
+
}
|
|
312
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
title: 'molecules/List',
|
|
3
|
+
component: 'tttx-list',
|
|
4
|
+
argTypes: {
|
|
5
|
+
selectable: {
|
|
6
|
+
control: {
|
|
7
|
+
type: 'boolean'
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
export const ListWithGenericTemplate = (args) => {
|
|
13
|
+
return `
|
|
14
|
+
<script>
|
|
15
|
+
function loadPage (event) {
|
|
16
|
+
const page = new CustomEvent('listPageLoad', {
|
|
17
|
+
detail: {
|
|
18
|
+
name: 'listWithGenericTemplate',
|
|
19
|
+
lastPage: true,
|
|
20
|
+
items: [
|
|
21
|
+
{ text: 'Row with only text' },
|
|
22
|
+
{ text: 'Row with text and an icon', icon: 'sentiment_calm' },
|
|
23
|
+
{ text: 'Row with text and a coloured icon', icon: 'check_circle', iconColor: 'blue' },
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
document.dispatchEvent(page);
|
|
28
|
+
|
|
29
|
+
// Stop this event handler from being duplicated every time the storybook iframe is reloaded
|
|
30
|
+
document.removeEventListener("listPaginate", loadPage);
|
|
31
|
+
}
|
|
32
|
+
document.addEventListener("listPaginate", loadPage);
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<tttx-list ${args.selectable ? 'selectable' : ''} name='listWithGenericTemplate' />
|
|
36
|
+
`;
|
|
37
|
+
};
|