|
20 | 20 | import { html, render } from "lit";
|
21 | 21 | import "../../dist/components/collection/index.js";
|
22 | 22 |
|
23 |
| - let items = []; |
| 23 | + // const items = []; |
24 | 24 | let search = "";
|
25 | 25 | let tag = "";
|
26 | 26 |
|
|
34 | 34 | return data;
|
35 | 35 | };
|
36 | 36 |
|
37 |
| - const dataInitial = await fetchDummyData(1, 5); |
| 37 | + // const dataInitial = await fetchDummyData(1, 5); |
38 | 38 |
|
39 |
| - items = dataInitial.map((item, index) => ({ |
40 |
| - index: index + 1, |
41 |
| - name: item.title, |
42 |
| - key: `item-${item.id}`, |
43 |
| - lazy: true, |
44 |
| - tag: { |
45 |
| - name: item.completed ? "SUCCESS" : "ERROR", |
46 |
| - type: item.completed ? "success" : "danger", |
47 |
| - }, |
48 |
| - })); |
| 39 | + // items = dataInitial.map((item, index) => ({ |
| 40 | + // index: index + 1, |
| 41 | + // name: item.title, |
| 42 | + // key: `item-${item.id}`, |
| 43 | + // lazy: true, |
| 44 | + // tag: { |
| 45 | + // name: item.completed ? "SUCCESS" : "ERROR", |
| 46 | + // type: item.completed ? "success" : "danger", |
| 47 | + // }, |
| 48 | + // })); |
49 | 49 |
|
50 |
| - const filters = [ |
51 |
| - { |
52 |
| - key: "title", |
53 |
| - type: "search", |
54 |
| - placeholder: "Search", |
55 |
| - }, |
56 |
| - { |
57 |
| - key: "tag", |
58 |
| - type: "select", |
59 |
| - options: ["SUCCESS", "WARNING", "ERROR", "DEFAULT", "PRIMARY"], |
60 |
| - placeholder: "Filter by tag", |
61 |
| - selectConfig: { |
62 |
| - // multiple: true, |
63 |
| - }, |
64 |
| - }, |
65 |
| - ]; |
| 50 | + // const filters = [ |
| 51 | + // { |
| 52 | + // key: "title", |
| 53 | + // type: "search", |
| 54 | + // placeholder: "Search", |
| 55 | + // }, |
| 56 | + // { |
| 57 | + // key: "tag", |
| 58 | + // type: "select", |
| 59 | + // options: ["SUCCESS", "WARNING", "ERROR", "DEFAULT", "PRIMARY"], |
| 60 | + // placeholder: "Filter by tag", |
| 61 | + // selectConfig: { |
| 62 | + // // multiple: true, |
| 63 | + // }, |
| 64 | + // }, |
| 65 | + // ]; |
66 | 66 |
|
67 | 67 | render(
|
68 |
| - html`<ecc-utils-design-collection |
69 |
| - .items=${items} |
70 |
| - .filters=${filters} |
| 68 | + html`<ecc-d-collection |
| 69 | + filter |
| 70 | + search |
| 71 | + page-length="2" |
71 | 72 | @ecc-utils-expand=${async (e) => {
|
72 | 73 | // Check if child already exists
|
73 | 74 | const children = e.target.querySelectorAll(
|
|
87 | 88 | e.target.appendChild(child);
|
88 | 89 | }
|
89 | 90 | }}
|
| 91 | + // inspect how this filter works and implement the fnuctionality |
90 | 92 | @ecc-utils-filter=${async (e) => {
|
91 | 93 | if (e.detail.key === "title") {
|
92 | 94 | search = e.detail.value;
|
|
140 | 142 | }
|
141 | 143 | const data = await fetchDummyData(e.detail.page, 5, search, tag);
|
142 | 144 | for (let i = 0; i < data.length; i += 1) {
|
143 |
| - const element = data[i]; |
144 |
| - const existingItem = e.target.items.find( |
145 |
| - (item) => item.key === `item-${element.id}` |
146 |
| - ); |
147 |
| - if (existingItem) { |
148 |
| - e.target.items = e.target.items.filter( |
149 |
| - (item) => item.key !== `item-${element.id}` |
150 |
| - ); |
151 |
| - } |
152 |
| - e.target.items = [ |
153 |
| - ...e.target.items, |
154 |
| - { |
155 |
| - index: (e.detail.page - 1) * 5 + i + 1, |
156 |
| - name: element.title, |
157 |
| - key: `item-${element.id}`, |
158 |
| - lazy: true, |
159 |
| - tag: { |
160 |
| - name: element.completed ? "SUCCESS" : "ERROR", |
161 |
| - type: element.completed ? "success" : "danger", |
162 |
| - }, |
163 |
| - }, |
164 |
| - ]; |
| 145 | + // const element = data[i]; |
| 146 | + // const existingItem = e.target.items.find( |
| 147 | + // (item) => item.key === `item-${element.id}` |
| 148 | + // ); |
| 149 | + // if (existingItem) { |
| 150 | + // e.target.items = e.target.items.filter( |
| 151 | + // (item) => item.key !== `item-${element.id}` |
| 152 | + // ); |
| 153 | + // } |
| 154 | + // e.target.items = [ |
| 155 | + // ...e.target.items, |
| 156 | + // { |
| 157 | + // index: (e.detail.page - 1) * 5 + i + 1, |
| 158 | + // name: element.title, |
| 159 | + // key: `item-${element.id}`, |
| 160 | + // lazy: true, |
| 161 | + // tag: { |
| 162 | + // name: element.completed ? "SUCCESS" : "ERROR", |
| 163 | + // type: element.completed ? "success" : "danger", |
| 164 | + // }, |
| 165 | + // }, |
| 166 | + // ]; |
165 | 167 | }
|
166 | 168 | if (data.length < 5) {
|
167 | 169 | e.target.totalItems = (e.detail.page - 1) * 5 + data.length;
|
168 | 170 | }
|
169 | 171 | }}
|
170 | 172 | >
|
171 | 173 | <div slot="item-5">Child item-5 without lazy loading</div>
|
172 |
| - </ecc-utils-design-collection>`, |
| 174 | + <ecc-d-collection-header> |
| 175 | + <ecc-d-collection-filter |
| 176 | + multiple |
| 177 | + type="select" |
| 178 | + options='["item", "work"]' |
| 179 | + @ecc-input=${(e) => { |
| 180 | + console.log("changing from the top", e); |
| 181 | + }} |
| 182 | + ></ecc-d-collection-filter> |
| 183 | + </ecc-d-collection-header> |
| 184 | +
|
| 185 | + <div ecc-collection-body> |
| 186 | + <ecc-d-collection-item |
| 187 | + lazy |
| 188 | + key="item" |
| 189 | + name="item" |
| 190 | + tag="ERROR" |
| 191 | + @ecc-expand=${(e) => { |
| 192 | + e.target.renderContent(); |
| 193 | + }} |
| 194 | + > |
| 195 | + Title: Item content written here |
| 196 | + </ecc-d-collection-item> |
| 197 | + <ecc-d-collection-item |
| 198 | + lazy |
| 199 | + key="work" |
| 200 | + name="work" |
| 201 | + tag="DANGER" |
| 202 | + ></ecc-d-collection-item> |
| 203 | + <ecc-d-collection-item |
| 204 | + lazy |
| 205 | + key="work-item" |
| 206 | + name="work-item" |
| 207 | + tag="DANGER" |
| 208 | + ></ecc-d-collection-item> |
| 209 | + </div> |
| 210 | + <ecc-d-collection-footer |
| 211 | + page="2" |
| 212 | + @ecc-utils-page-change=${() => { |
| 213 | + console.log("page changed"); |
| 214 | + }} |
| 215 | + ></ecc-d-collection-footer> |
| 216 | + </ecc-d-collection>`, |
173 | 217 | document.querySelector("#demo")
|
174 | 218 | );
|
175 | 219 | </script>
|
|
0 commit comments