Skip to content

Commit 91ede92

Browse files
maebealeclaude
andcommitted
Dynamic facilitator border and inactive button graying on affiliation rows
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d9dd677 commit 91ede92

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,43 @@
11
import { Controller } from "@hotwired/stimulus";
22

3+
const COLORS = "sky|emerald|indigo|purple|teal|violet|orange|rose|blue|pink|cyan|lime|yellow|fuchsia|amber|green|slate|red";
4+
const COLOR_RE = new RegExp(`\\b(hover:)?(bg|text|border)-(${COLORS})-\\d+\\b`, "g");
5+
6+
function grayOut(el) {
7+
el.className = el.className.replace(COLOR_RE, (_, hover, prop) => {
8+
if (hover) return "hover:bg-gray-200";
9+
if (prop === "bg") return "bg-gray-100";
10+
if (prop === "text") return "text-gray-400";
11+
if (prop === "border") return "border-gray-300";
12+
return _;
13+
});
14+
}
15+
316
export default class extends Controller {
417
connect() {
518
this.endDateInput = this.element.querySelector("input[type='date'][name*='end_date']");
6-
if (this.endDateInput) {
7-
this.apply();
8-
}
19+
this.titleInput = this.element.querySelector("textarea[name*='title']");
20+
21+
// Save original classes for profile buttons and their styled children
22+
this._savedClasses = [];
23+
this.element.querySelectorAll("a.group, a.group span").forEach((el) => {
24+
this._savedClasses.push({ el, className: el.className });
25+
});
26+
27+
if (this.endDateInput) this.apply();
28+
if (this.titleInput) this.updateBorder();
929
}
1030

1131
toggle() {
1232
this.apply();
1333
}
1434

35+
updateBorder() {
36+
if (!this.titleInput) return;
37+
const isFacilitator = this.titleInput.value.toLowerCase().includes("facilitator");
38+
this.element.style.borderLeft = `4px solid ${isFacilitator ? "#e879f9" : "#d1d5db"}`;
39+
}
40+
1541
apply() {
1642
if (!this.endDateInput) return;
1743
const value = this.endDateInput.value;
@@ -20,9 +46,11 @@ export default class extends Controller {
2046
if (isPast) {
2147
this.element.classList.add("bg-gray-100", "border-gray-300", "opacity-60");
2248
this.element.classList.remove("bg-white", "border-gray-200");
49+
this.element.querySelectorAll("a.group, a.group span").forEach((el) => grayOut(el));
2350
} else {
2451
this.element.classList.remove("bg-gray-100", "border-gray-300", "opacity-60");
2552
this.element.classList.add("bg-white", "border-gray-200");
53+
this._savedClasses.forEach(({ el, className }) => { el.className = className; });
2654
}
2755
}
2856
}

app/views/organizations/_affiliation_fields.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
rows: 1,
3333
value: f.object&.title || f.object&.position || "Facilitator",
3434
style: "height: 42px; min-height: 42px;",
35-
data: { action: "input->affiliation-dates#recalculate" }
35+
data: { action: "input->affiliation-dates#recalculate input->inactive-toggle#updateBorder" }
3636
} %>
3737
</div>
3838

app/views/people/_affiliation_fields.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
rows: 1,
3434
value: f.object.title || f.object.position || "Facilitator",
3535
style: "height: 42px; min-height: 42px;",
36-
data: { action: "input->affiliation-dates#recalculate" }
36+
data: { action: "input->affiliation-dates#recalculate input->inactive-toggle#updateBorder" }
3737
} %>
3838
</div>
3939
</div>

0 commit comments

Comments
 (0)