11import { 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+
316export 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}
0 commit comments