feat: add date button theme.
This commit is contained in:
@@ -30,22 +30,22 @@ public class Calendar: TemplatedControl
|
||||
set => SetValue(IsTodayHighlightedProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<AvaloniaList<DateRange>?> DisabledDatesProperty =
|
||||
public static readonly StyledProperty<AvaloniaList<DateRange>?> BlackoutDatesProperty =
|
||||
AvaloniaProperty.Register<Calendar, AvaloniaList<DateRange>?>(
|
||||
nameof(DisabledDates));
|
||||
nameof(BlackoutDates));
|
||||
|
||||
public AvaloniaList<DateRange>? DisabledDates
|
||||
public AvaloniaList<DateRange>? BlackoutDates
|
||||
{
|
||||
get => GetValue(DisabledDatesProperty);
|
||||
set => SetValue(DisabledDatesProperty, value);
|
||||
get => GetValue(BlackoutDatesProperty);
|
||||
set => SetValue(BlackoutDatesProperty, value);
|
||||
}
|
||||
|
||||
public static readonly StyledProperty<IDateSelector?> DisabledDateRuleProperty = AvaloniaProperty.Register<Calendar, IDateSelector?>(
|
||||
nameof(DisabledDateRule));
|
||||
public static readonly StyledProperty<IDateSelector?> BlackoutDateRuleProperty = AvaloniaProperty.Register<Calendar, IDateSelector?>(
|
||||
nameof(BlackoutDateRule));
|
||||
|
||||
public IDateSelector? DisabledDateRule
|
||||
public IDateSelector? BlackoutDateRule
|
||||
{
|
||||
get => GetValue(DisabledDateRuleProperty);
|
||||
set => SetValue(DisabledDateRuleProperty, value);
|
||||
get => GetValue(BlackoutDateRuleProperty);
|
||||
set => SetValue(BlackoutDateRuleProperty, value);
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,130 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Mixins;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Input;
|
||||
using Irihi.Avalonia.Shared.Common;
|
||||
using Irihi.Avalonia.Shared.Helpers;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
public class CalendarDayButton: Button
|
||||
[PseudoClasses(PseudoClassName.PC_Pressed, PseudoClassName.PC_Selected,
|
||||
PC_StartDate, PC_EndDate, PC_PreviewStartDate, PC_PreviewEndDate, PC_InRange, PC_Today, PC_Blackout)]
|
||||
public class CalendarDayButton: ContentControl
|
||||
{
|
||||
public const string PC_StartDate = ":start-date";
|
||||
public const string PC_EndDate = ":end-date";
|
||||
public const string PC_PreviewStartDate = ":preview-start-date";
|
||||
public const string PC_PreviewEndDate = ":preview-end-date";
|
||||
public const string PC_InRange = ":in-range";
|
||||
public const string PC_Today = ":today";
|
||||
public const string PC_Blackout = ":blackout";
|
||||
|
||||
private bool _isToday;
|
||||
public bool IsToday
|
||||
{
|
||||
get => _isToday;
|
||||
set
|
||||
{
|
||||
_isToday = value;
|
||||
PseudoClasses.Set(PC_Today, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isStartDate;
|
||||
public bool IsStartDate
|
||||
{
|
||||
get => _isStartDate;
|
||||
set
|
||||
{
|
||||
_isStartDate = value;
|
||||
PseudoClasses.Set(PC_StartDate, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isEndDate;
|
||||
public bool IsEndDate
|
||||
{
|
||||
get => _isEndDate;
|
||||
set
|
||||
{
|
||||
_isEndDate = value;
|
||||
PseudoClasses.Set(PC_EndDate, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isPreviewStartDate;
|
||||
public bool IsPreviewStartDate
|
||||
{
|
||||
get => _isPreviewStartDate;
|
||||
set
|
||||
{
|
||||
_isPreviewStartDate = value;
|
||||
PseudoClasses.Set(PC_PreviewStartDate, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isPreviewEndDate;
|
||||
public bool IsPreviewEndDate
|
||||
{
|
||||
get => _isPreviewEndDate;
|
||||
set
|
||||
{
|
||||
_isPreviewEndDate = value;
|
||||
PseudoClasses.Set(PC_PreviewEndDate, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isInRange;
|
||||
public bool IsInRange
|
||||
{
|
||||
get => _isInRange;
|
||||
set
|
||||
{
|
||||
_isInRange = value;
|
||||
PseudoClasses.Set(PC_InRange, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isSelected;
|
||||
public bool IsSelected
|
||||
{
|
||||
get => _isSelected;
|
||||
set
|
||||
{
|
||||
_isSelected = value;
|
||||
PseudoClasses.Set(PseudoClassName.PC_Selected, value);
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isBlackout;
|
||||
public bool IsBlackout
|
||||
{
|
||||
get => _isBlackout;
|
||||
set
|
||||
{
|
||||
_isBlackout = value;
|
||||
PseudoClasses.Set(PC_Blackout, value);
|
||||
}
|
||||
}
|
||||
|
||||
static CalendarDayButton()
|
||||
{
|
||||
PressedMixin.Attach<CalendarDayButton>();
|
||||
}
|
||||
|
||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||
{
|
||||
base.OnApplyTemplate(e);
|
||||
PseudoClasses.Set(PseudoClassName.PC_Disabled, IsEnabled);
|
||||
PseudoClasses.Set(PC_Today, IsToday);
|
||||
PseudoClasses.Set(PC_StartDate, IsStartDate);
|
||||
PseudoClasses.Set(PC_EndDate, IsEndDate);
|
||||
PseudoClasses.Set(PC_PreviewStartDate, IsPreviewStartDate);
|
||||
PseudoClasses.Set(PC_PreviewEndDate, IsPreviewEndDate);
|
||||
PseudoClasses.Set(PC_InRange, IsInRange);
|
||||
PseudoClasses.Set(PseudoClassName.PC_Selected, IsSelected);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -33,4 +33,13 @@ public sealed record DateRange
|
||||
if (date is null) return false;
|
||||
return date >= Start && date <= End;
|
||||
}
|
||||
}
|
||||
|
||||
internal static class DateRangeExtension
|
||||
{
|
||||
public static bool Contains(this IEnumerable<DateRange>? ranges, DateTime? date)
|
||||
{
|
||||
if (date is null || ranges is null) return false;
|
||||
return ranges.Any(range => range.Contains(date));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user