22
33module RubyUI
44 class CalendarDays < Base
5- BASE_CLASS = "inline-flex items-center justify-center rounded-md text-sm ring-offset-background transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 h-8 w-8 p-0 font-normal aria-selected:opacity-100"
5+ DEFAULT_CLASSES = "inline-flex items-center justify-center rounded-md text-sm ring-offset-background transition-colors h-8 w-8 p-0 font-normal"
6+ DISABLED_CLASSES = "disabled:pointer-events-none disabled:opacity-50"
7+ FOCUS_VISIBLE_CLASSES = "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"
8+ ARIA_SELECTED_CLASSES = "aria-selected:opacity-100"
9+ ARIA_DISABLED_CLASSES = "aria-disabled:pointer-events-none aria-disabled:opacity-50 aria-disabled:cursor-not-allowed"
610
711 def view_template
812 render_selected_date_template
@@ -19,11 +23,16 @@ def render_selected_date_template
1923 data_day : "{{day}}" ,
2024 data_action : "click->ruby-ui--calendar#selectDay" ,
2125 name : "day" ,
22- class :
23- [
24- BASE_CLASS ,
25- "bg-primary text-primary-foreground hover:bg-primary hover:text-primary-foreground focus:bg-primary focus:text-primary-foreground"
26- ] ,
26+ class : [
27+ DEFAULT_CLASSES ,
28+ DISABLED_CLASSES ,
29+ FOCUS_VISIBLE_CLASSES ,
30+ ARIA_SELECTED_CLASSES ,
31+ ARIA_DISABLED_CLASSES ,
32+ "bg-primary text-primary-foreground" ,
33+ "hover:bg-primary hover:text-primary-foreground" ,
34+ "focus:bg-primary focus:text-primary-foreground"
35+ ] ,
2736 role : "gridcell" ,
2837 tabindex : "0" ,
2938 type : "button" ,
@@ -38,11 +47,16 @@ def render_today_date_template
3847 data_day : "{{day}}" ,
3948 data_action : "click->ruby-ui--calendar#selectDay" ,
4049 name : "day" ,
41- class :
42- [
43- BASE_CLASS ,
44- "bg-accent text-accent-foreground hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground"
45- ] ,
50+ class : [
51+ DEFAULT_CLASSES ,
52+ DISABLED_CLASSES ,
53+ FOCUS_VISIBLE_CLASSES ,
54+ ARIA_SELECTED_CLASSES ,
55+ ARIA_DISABLED_CLASSES ,
56+ "bg-accent text-accent-foreground" ,
57+ "hover:bg-accent hover:text-accent-foreground" ,
58+ "focus:bg-accent focus:text-accent-foreground"
59+ ] ,
4660 role : "gridcell" ,
4761 tabindex : "-1" ,
4862 type : "button"
@@ -56,11 +70,16 @@ def render_current_month_date_template
5670 data_day : "{{day}}" ,
5771 data_action : "click->ruby-ui--calendar#selectDay" ,
5872 name : "day" ,
59- class :
60- [
61- BASE_CLASS ,
62- "bg-background text-foreground hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground"
63- ] ,
73+ class : [
74+ DEFAULT_CLASSES ,
75+ DISABLED_CLASSES ,
76+ FOCUS_VISIBLE_CLASSES ,
77+ ARIA_SELECTED_CLASSES ,
78+ ARIA_DISABLED_CLASSES ,
79+ "bg-background text-foreground" ,
80+ "hover:bg-accent hover:text-accent-foreground" ,
81+ "focus:bg-accent focus:text-accent-foreground"
82+ ] ,
6483 role : "gridcell" ,
6584 tabindex : "-1" ,
6685 type : "button"
@@ -72,13 +91,18 @@ def render_other_month_date_template
7291 date_template ( "otherMonthDateTemplate" ) do
7392 button (
7493 data_day : "{{day}}" ,
75- data_action : " click->ruby-ui--calendar#selectDay" ,
94+ data_action : "click->ruby-ui--calendar#selectDay" ,
7695 name : "day" ,
77- class :
78- [
79- BASE_CLASS ,
80- "bg-background text-muted-foreground hover:bg-accent hover:text-accent-foreground focus:bg-accent focus:text-accent-foreground"
81- ] ,
96+ class : [
97+ DEFAULT_CLASSES ,
98+ DISABLED_CLASSES ,
99+ FOCUS_VISIBLE_CLASSES ,
100+ ARIA_SELECTED_CLASSES ,
101+ ARIA_DISABLED_CLASSES ,
102+ "bg-background text-muted-foreground" ,
103+ "hover:bg-accent hover:text-accent-foreground" ,
104+ "focus:bg-accent focus:text-accent-foreground"
105+ ] ,
82106 role : "gridcell" ,
83107 tabindex : "-1" ,
84108 type : "button"
@@ -89,8 +113,11 @@ def render_other_month_date_template
89113 def date_template ( target , &block )
90114 template ( data : { ruby_ui__calendar_target : target } ) do
91115 td (
92- class :
93- "relative p-0 text-center text-sm focus-within:relative focus-within:z-20 [&:has([aria-selected])]:bg-accent [&:has([aria-selected])]:rounded-md" ,
116+ class : [
117+ "relative p-0 text-center text-sm" ,
118+ "focus-within:relative focus-within:z-20" ,
119+ "[&:has([aria-selected])]:bg-accent [&:has([aria-selected])]:rounded-md"
120+ ] ,
94121 role : "presentation" ,
95122 &block
96123 )
0 commit comments