-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathme-profile-experiences-editor.ts
More file actions
149 lines (133 loc) · 4.32 KB
/
Copy pathme-profile-experiences-editor.ts
File metadata and controls
149 lines (133 loc) · 4.32 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import { css, html, LitElement } from 'lit'
import { customElement, property } from 'lit/decorators.js'
import { adminFormStyles } from '../../../admin/admin-form-styles.js'
import type { MeExperience } from '../../../admin/types.js'
import '../ui/me-admin-panel.js'
import '../ui/me-admin-section.js'
import '../ui/me-text-input.js'
@customElement('me-profile-experiences-editor')
export class MeProfileExperiencesEditor extends LitElement {
@property({ type: Array }) experiences: MeExperience[] = []
private dispatchChange(next: MeExperience[]) {
this.dispatchEvent(
new CustomEvent<MeExperience[]>('change', {
detail: next,
bubbles: true,
composed: true,
}),
)
}
private addItem = () => {
const next = [
...this.experiences,
{ company: '', url: '', startYear: new Date().getFullYear() },
]
this.dispatchChange(next)
}
private removeItem(index: number) {
const next = this.experiences.filter((_, i) => i !== index)
this.dispatchChange(next)
}
private updateItem(index: number, patch: Partial<MeExperience>) {
const next = [...this.experiences]
next[index] = { ...next[index], ...patch }
this.dispatchChange(next)
}
render() {
return html`
<me-admin-section
title="Experiences"
description="endYear を空にすると、継続中の経歴として扱えます。"
>
<button
slot="header-actions"
type="button"
class="subtle"
@click=${this.addItem}
>
経歴を追加
</button>
<div class="stack">
${
this.experiences.length === 0
? html`<p class="empty-text">経歴がまだありません。</p>`
: this.experiences.map(
(exp, index) => html`
<me-admin-panel title="経歴 ${index + 1}">
<button
slot="header-actions"
type="button"
class="subtle danger"
@click=${() => this.removeItem(index)}
>
削除
</button>
<div class="grid">
<me-text-input
label="Company"
.value=${exp.company}
@change=${(e: CustomEvent) =>
this.updateItem(index, { company: e.detail })}
></me-text-input>
<me-text-input
label="URL"
type="url"
.value=${exp.url}
@change=${(e: CustomEvent) =>
this.updateItem(index, { url: e.detail })}
></me-text-input>
<me-text-input
label="Start year"
type="number"
.value=${String(exp.startYear)}
@change=${(e: CustomEvent) =>
this.updateItem(index, {
startYear: Number(e.detail || '0'),
})}
></me-text-input>
<me-text-input
label="End year"
type="number"
.value=${exp.endYear ? String(exp.endYear) : ''}
@change=${(e: CustomEvent) =>
this.updateItem(index, {
endYear: e.detail ? Number(e.detail) : undefined,
})}
></me-text-input>
</div>
</me-admin-panel>
`,
)
}
</div>
</me-admin-section>
`
}
static styles = [
adminFormStyles,
css`
:host {
display: block;
}
.stack {
display: grid;
gap: 20px;
}
.grid {
display: grid;
gap: 16px;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}
.empty-text {
color: var(--color-text-tertiary);
font-size: 14px;
font-style: italic;
}
`,
]
}
declare global {
interface HTMLElementTagNameMap {
'me-profile-experiences-editor': MeProfileExperiencesEditor
}
}