Skip to content
This repository has been archived by the owner on Jun 27, 2022. It is now read-only.

New PersonItem component. #17

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/components/PersonItem.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { html, css, LitElement } from "lit";

export class PersonItem extends LitElement {
static get styles() {
return css`
div {
text-align: center;
border: 1px solid white;
border-radius: 5px;
padding: 10px;
}
span {
font-size: 8px;
}
`;
}
static get properties() {
return {
val: { type: Object },
};
}

render() {
return html`
<div>
<h3>${this.val.name}</h3>
<p>Skin color: ${this.val.skin_color}</p>
<p>Birth of year: ${this.val.birth_year}</p>
<p>Number of films: ${this.val.films.length}</p>
<span>Gender: ${this.val.gender}</span>
<p></p>
</div>
`;
}
}

window.customElements.define("person-item", PersonItem);
24 changes: 22 additions & 2 deletions src/pages/people.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,26 @@
import { html, LitElement } from "lit";
import { html, css, LitElement } from "lit";
import { customElement } from "lit/decorators.js";
import "/components/PersonItem.js";
import { fetchPeople } from "/api.js";

export class PagePeople extends LitElement {
static get styles() {
return css`
ul {
display: grid;
gap: 15px;
justify-content: center;
grid-template-columns: 1fr 1fr 1fr;
list-style: none;
padding-left: 0;
margin: 0;
}
h2 {
text-align: center;
}
`;
}

static properties = {
_people: { state: true, type: Array },
_loading: { state: true, type: Boolean },
Expand Down Expand Up @@ -36,7 +54,9 @@ export class PagePeople extends LitElement {
${this._loading ? html`<p>Loading...</p>` : null}
${this._error ? html`<p>${this._error}</p>` : null}
<ul>
${this._people.map((person) => html`<li>${person.name}</li>`)}
${this._people.map(
(person) => html`<li><person-item .val=${person}></person-item></li>`
)}
</ul>
`;
}
Expand Down