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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
---
// 地域センター・公民館・図書館・市役所支所・文化施設の一覧。
// トイレは市の公共施設として基本的に利用できる。給水は公式ページに明記が少ないため「未確認」が多い。
import facilitiesData from "@/data/kodaira-facilities.json";
type Facility = {
name: string;
type: string;
address: string;
hours: string;
closed: string;
toilet: string;
water: string;
note: string;
source: string;
};
const facilities = facilitiesData as Facility[];
const types = ["地域センター", "公民館", "図書館", "市役所支所", "文化施設"];
const mapsUrl = (name: string) =>
`https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(`小平市${name}`)}`;
---
<div class="facilities" data-fac-root>
<div class="fac-controls">
<label>
種別
<select data-fac-type>
<option value="">すべて</option>
{types.map((type) => <option value={type}>{type}</option>)}
</select>
</label>
<label>
キーワード
<input type="search" data-fac-search placeholder="施設名・住所・備考" />
</label>
<label><input type="checkbox" data-fac-toilet /> トイレ○</label>
<label><input type="checkbox" data-fac-water /> 給水○</label>
<span class="fac-count" data-fac-count>{facilities.length}件</span>
</div>
<div class="fac-table-wrap">
<table>
<thead>
<tr>
<th scope="col">施設名</th>
<th scope="col">種別</th>
<th scope="col">住所</th>
<th scope="col">開館時間</th>
<th scope="col">休館日</th>
<th scope="col">トイレ</th>
<th scope="col">給水</th>
<th scope="col">備考</th>
</tr>
</thead>
<tbody>
{facilities.map((f) => (
<tr
data-fac-row
data-type={f.type}
data-toilet={f.toilet || ""}
data-water={f.water || ""}
data-search={`${f.name} ${f.type} ${f.address} ${f.note}`.toLowerCase()}
>
<td>
{f.source ? (
<a href={f.source} target="_blank" rel="noopener">{f.name}</a>
) : (
f.name
)}
</td>
<td>{f.type}</td>
<td>
<a href={mapsUrl(f.name)} target="_blank" rel="noopener">
{f.address || "—"}
</a>
</td>
<td>{f.hours || "未確認"}</td>
<td>{f.closed || "未確認"}</td>
<td
class:list={[
"fac-status",
f.toilet === "○" ? "is-yes" : f.toilet === "×" ? "is-no" : "",
]}
>{f.toilet || "未確認"}</td>
<td
class:list={[
"fac-status",
f.water === "○" ? "is-yes" : f.water === "×" ? "is-no" : "",
]}
>{f.water || "未確認"}</td>
<td>{f.note}</td>
</tr>
))}
</tbody>
</table>
</div>
<p class="fac-note">
トイレは市の公共施設として基本的に利用できます(○)。給水は公式ページに明記が少ないため「未確認」が多いです。最新の情報は各施設の公式ページで確認してください。地図の位置は住所・名称からの概略です。
</p>
</div>
<script>
const root = document.querySelector<HTMLElement>("[data-fac-root]");
if (root) {
const rows = Array.from(root.querySelectorAll<HTMLTableRowElement>("[data-fac-row]"));
const search = root.querySelector<HTMLInputElement>("[data-fac-search]");
const type = root.querySelector<HTMLSelectElement>("[data-fac-type]");
const toilet = root.querySelector<HTMLInputElement>("[data-fac-toilet]");
const water = root.querySelector<HTMLInputElement>("[data-fac-water]");
const count = root.querySelector<HTMLElement>("[data-fac-count]");
const apply = () => {
const q = (search?.value || "").trim().toLowerCase();
const t = type?.value || "";
const needToilet = Boolean(toilet?.checked);
const needWater = Boolean(water?.checked);
let shown = 0;
rows.forEach((row) => {
const okType = !t || row.dataset.type === t;
const okText = !q || (row.dataset.search || "").includes(q);
const okToilet = !needToilet || row.dataset.toilet === "○";
const okWater = !needWater || row.dataset.water === "○";
const ok = okType && okText && okToilet && okWater;
row.hidden = !ok;
if (ok) shown += 1;
});
if (count) count.textContent = `${shown} / ${rows.length}件`;
};
search?.addEventListener("input", apply);
type?.addEventListener("change", apply);
toilet?.addEventListener("change", apply);
water?.addEventListener("change", apply);
apply();
}
</script>
<style>
.fac-controls {
display: flex;
flex-wrap: wrap;
gap: 0.75rem;
align-items: center;
margin: 0.75rem 0;
font-size: 0.9em;
}
.fac-controls label {
display: flex;
gap: 0.35rem;
align-items: center;
}
.fac-controls input,
.fac-controls select {
padding: 0.3rem 0.5rem;
border: 1px solid var(--sl-color-gray-5);
border-radius: 4px;
background: var(--sl-color-bg);
color: var(--sl-color-text);
}
.fac-count {
color: var(--sl-color-gray-2);
font-size: 0.85em;
}
.fac-table-wrap {
overflow-x: auto;
}
.fac-table-wrap table {
font-size: 0.85em;
}
.fac-status {
text-align: center;
white-space: nowrap;
}
.fac-status.is-yes {
color: #1b5e20;
font-weight: 700;
}
.fac-status.is-no {
color: #b71c1c;
}
.fac-note {
margin-top: 0.5rem;
color: var(--sl-color-gray-2);
font-size: 0.82em;
}
</style>
|