Add interactive day selection to calendar
- Added click handlers to calendar days for user interaction - Implemented selected day state tracking in calendar component - Added CSS styling for selected days with green highlight - Selected days show distinct visual feedback with borders and shadows - Supports combination states (selected+today, selected+events) 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -12,6 +12,7 @@ pub struct CalendarProps {
|
||||
pub fn Calendar(props: &CalendarProps) -> Html {
|
||||
let today = Local::now().date_naive();
|
||||
let current_month = use_state(|| today);
|
||||
let selected_day = use_state(|| today);
|
||||
|
||||
let first_day_of_month = current_month.with_day(1).unwrap();
|
||||
let days_in_month = get_days_in_month(*current_month);
|
||||
@@ -71,18 +72,27 @@ pub fn Calendar(props: &CalendarProps) -> Html {
|
||||
(1..=days_in_month).map(|day| {
|
||||
let date = current_month.with_day(day).unwrap();
|
||||
let is_today = date == today;
|
||||
let is_selected = date == *selected_day;
|
||||
let events = props.events.get(&date).cloned().unwrap_or_default();
|
||||
|
||||
let mut classes = vec!["calendar-day", "current-month"];
|
||||
if is_today {
|
||||
classes.push("today");
|
||||
}
|
||||
if is_selected {
|
||||
classes.push("selected");
|
||||
}
|
||||
if !events.is_empty() {
|
||||
classes.push("has-events");
|
||||
}
|
||||
|
||||
let selected_day_clone = selected_day.clone();
|
||||
let on_click = Callback::from(move |_| {
|
||||
selected_day_clone.set(date);
|
||||
});
|
||||
|
||||
html! {
|
||||
<div class={classes!(classes)}>
|
||||
<div class={classes!(classes)} onclick={on_click}>
|
||||
<div class="day-number">{day}</div>
|
||||
{
|
||||
if !events.is_empty() {
|
||||
|
||||
Reference in New Issue
Block a user