UNPKG

3.62 kBJavaScriptView Raw
1var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2 var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3 if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4 else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5 return c > 3 && r && Object.defineProperty(target, key, r), r;
6};
7// TODO: implement infinite scroll
8import { adoptedStyle, customElement, property } from '@mantou/gem/lib/decorators';
9import { GemElement, html } from '@mantou/gem/lib/element';
10import { createCSSSheet, css } from '@mantou/gem/lib/utils';
11import { theme } from '../lib/theme';
12import './avatar';
13import './divider';
14const style = createCSSSheet(css `
15 :host(:where(:not([hidden]))) {
16 display: flex;
17 flex-direction: column;
18 gap: 0.5em;
19 font-size: 0.875em;
20 }
21`);
22/**
23 * @customElement dy-list
24 */
25let DuoyunListElement = class DuoyunListElement extends GemElement {
26 constructor() {
27 super();
28 this.render = () => {
29 var _a;
30 return html `${(_a = this.data) === null || _a === void 0 ? void 0 : _a.map((item) => html `
31 <dy-list-item .data=${item} .renderItem=${this.renderItem}></dy-list-item>
32 <dy-divider></dy-divider>
33 `)}`;
34 };
35 this.internals.role = 'list';
36 }
37};
38__decorate([
39 property
40], DuoyunListElement.prototype, "data", void 0);
41__decorate([
42 property
43], DuoyunListElement.prototype, "renderItem", void 0);
44DuoyunListElement = __decorate([
45 customElement('dy-list'),
46 adoptedStyle(style)
47], DuoyunListElement);
48export { DuoyunListElement };
49const itemStyle = createCSSSheet(css `
50 :host(:where(:not([hidden]))) {
51 display: flex;
52 align-items: center;
53 gap: 1em;
54 }
55 .content {
56 display: flex;
57 flex-direction: column;
58 gap: 0.2em;
59 min-width: 0;
60 }
61 .title,
62 .description {
63 overflow: hidden;
64 text-overflow: ellipsis;
65 white-space: nowrap;
66 }
67 .title {
68 font-weight: 500;
69 }
70 .description {
71 color: ${theme.describeColor};
72 }
73`);
74/**
75 * @customElement dy-list-item
76 */
77let DuoyunListItemElement = class DuoyunListItemElement extends GemElement {
78 constructor() {
79 super({ isAsync: true });
80 this.render = () => {
81 if (!this.data)
82 return html ``;
83 const { title, avatar, description, status } = this.data;
84 return this.renderItem
85 ? this.renderItem(this.data)
86 : html `
87 ${!avatar
88 ? ''
89 : html `
90 <div class="avatar">
91 ${typeof avatar === 'string'
92 ? html `<dy-avatar src=${avatar} alt="Avatar" .status=${status}></dy-avatar>`
93 : avatar}
94 </div>
95 `}
96 <div class="content">
97 <div class="title">${title}</div>
98 <div class="description">${description}</div>
99 </div>
100 `;
101 };
102 this.internals.role = 'listitem';
103 }
104};
105__decorate([
106 property
107], DuoyunListItemElement.prototype, "data", void 0);
108__decorate([
109 property
110], DuoyunListItemElement.prototype, "renderItem", void 0);
111DuoyunListItemElement = __decorate([
112 customElement('dy-list-item'),
113 adoptedStyle(itemStyle)
114], DuoyunListItemElement);
115export { DuoyunListItemElement };
116//# sourceMappingURL=list.js.map
\No newline at end of file