-
-
Notifications
You must be signed in to change notification settings - Fork 289
Expand file tree
/
Copy pathmanage-users-list-item.html
More file actions
109 lines (94 loc) · 2.48 KB
/
manage-users-list-item.html
File metadata and controls
109 lines (94 loc) · 2.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<template id="manage-users-list-item-template">
<style>
@import "css/style.css";
:host {
display: flex;
align-items: center;
background-color: white;
border-color: #333;
border-style: solid;
border-width: 0 0 1px;
padding: 0.75rem 1rem;
}
:host(:not([is-current-user])) #current-user-indicator {
display: none;
}
#username {
font-family: "Overpass Mono", monospace;
}
.indicator {
font-weight: 600;
margin-left: 0.7em;
font-size: 0.9em;
}
.indicator:before {
content: "(";
}
.indicator:after {
content: ")";
}
#current-user-indicator {
color: var(--brand-green);
}
button {
margin: 0 0 0 auto;
}
</style>
<span id="username"></span>
<span id="current-user-indicator" class="indicator">You</span>
<button type="button" id="edit-btn">Edit</button>
</template>
<script type="module">
class ClickEditEvent extends CustomEvent {
/**
* An event indicating that the user has clicked the "edit" button on the UI.
*/
constructor() {
super("click-edit", {
bubbles: true,
composed: true,
});
}
}
(function () {
const template = document.querySelector("#manage-users-list-item-template");
customElements.define(
"manage-users-list-item",
class extends HTMLElement {
constructor() {
super();
}
connectedCallback() {
this.attachShadow({ mode: "open" }).appendChild(
template.content.cloneNode(true)
);
this.role = "listitem";
this._elements = {
username: this.shadowRoot.querySelector("#username"),
editButton: this.shadowRoot.querySelector("#edit-btn"),
};
this._elements.editButton.addEventListener("click", () => {
this.dispatchEvent(new ClickEditEvent());
});
}
/**
* @param {Object} user - (As returned by the backend.)
* @param {string} user.username
*/
init(user) {
this._elements.username.textContent = user.username;
}
get isCurrentUser() {
return this.hasAttribute("is-current-user");
}
set isCurrentUser(enabled) {
if (enabled) {
this.setAttribute("is-current-user", "");
} else {
this.removeAttribute("is-current-user");
}
}
}
);
})();
</script>