Skip to content

Commit

Permalink
feat: make sure clear button works. make sure text cleared if lost fo…
Browse files Browse the repository at this point in the history
…cus with invalid data.
  • Loading branch information
rabbitism committed Jul 18, 2024
1 parent 7b3b18a commit 35933eb
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 70 deletions.
4 changes: 2 additions & 2 deletions demo/Ursa.Demo/Pages/DatePickerDemo.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<StackPanel Margin="20" HorizontalAlignment="Left">
<u:CalendarView DateSelected="CalendarView_OnOnDateSelected" DatePreviewed="CalendarView_OnOnDatePreviewed"/>
<TextBlock Text="{Binding #singlePicker.SelectedDate}" ></TextBlock>
<u:DatePicker Name="singlePicker" Width="200" />
<u:DateRangePicker Width="300" DisplayFormat="yyyyMMdd" />
<u:DatePicker Name="singlePicker" Width="200" Classes="ClearButton" />
<u:DateRangePicker Width="300" DisplayFormat="yyyyMMdd" Classes="ClearButton" />
</StackPanel>
</UserControl>
14 changes: 11 additions & 3 deletions src/Ursa.Themes.Semi/Controls/DatePicker.axaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<ResourceDictionary
xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:contracts="https://irihi.tech/shared"
xmlns:u="https://irihi.tech/ursa">
<!-- Add Resources Here -->
<ControlTheme x:Key="{x:Type u:DatePicker}" TargetType="u:DatePicker">
Expand Down Expand Up @@ -30,7 +31,7 @@
<Grid
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ColumnDefinitions="*, Auto, Auto">
ColumnDefinitions="*, Auto">
<TextBox
Name="PART_TextBox"
Grid.Column="0"
Expand Down Expand Up @@ -59,8 +60,9 @@
Theme="{DynamicResource InnerIconButton}" />
<Button
Name="PART_Button"
Grid.Column="2"
Grid.Column="1"
Padding="0,0,8,0"
IsVisible="{Binding !#ClearButton.IsVisible}"
Content="{DynamicResource CalendarDatePickerIconGlyph}"
Focusable="False"
Theme="{DynamicResource InnerIconButton}" />
Expand All @@ -83,9 +85,9 @@
<u:CalendarView
Name="PART_Calendar"
BorderThickness="0"
FontSize="{DynamicResource DefaultFontSize}"
CornerRadius="{Binding $parent[Border].CornerRadius}"
FirstDayOfWeek="{TemplateBinding FirstDayOfWeek}"
FontSize="{DynamicResource DefaultFontSize}"
IsTodayHighlighted="{TemplateBinding IsTodayHighlighted}" />
</Border>
</Popup>
Expand All @@ -95,6 +97,12 @@
</DataValidationErrors>
</ControlTemplate>
</Setter>

<Style Selector="^.clearButton, ^.ClearButton">
<Style Selector="^:pointerover /template/ Button#ClearButton">
<Setter Property="IsVisible" Value="{Binding $parent[u:DatePicker].SelectedDate, Converter={x:Static ObjectConverters.IsNotNull}}" />
</Style>
</Style>

<Style Selector="^:pointerover">
<Style Selector="^ /template/ Border#Background">
Expand Down
8 changes: 3 additions & 5 deletions src/Ursa.Themes.Semi/Controls/DateRangePicker.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
Name="{x:Static u:DateRangePicker.PART_Button}"
Grid.Column="3"
Padding="8,0"
IsVisible="{Binding !#ClearButton.IsVisible}"
Content="{DynamicResource CalendarDatePickerIconGlyph}"
Focusable="False"
Theme="{DynamicResource InnerIconButton}" />
Expand Down Expand Up @@ -142,11 +143,8 @@
</Setter>

<Style Selector="^.clearButton, ^.ClearButton">
<Style Selector="^:pointerover /template/ Button#ClearButton">
<Setter Property="IsVisible" Value="{Binding $parent[u:TimePicker].SelectedTime, Converter={x:Static ObjectConverters.IsNotNull}}" />
</Style>
<Style Selector="^:pointerover /template/ Button#PART_Button">
<Setter Property="IsVisible" Value="{Binding $parent[u:TimePicker].SelectedTime, Converter={x:Static ObjectConverters.IsNull}}" />
<Style Selector="^:not(:empty):pointerover /template/ Button#ClearButton">
<Setter Property="IsVisible" Value="{Binding $parent[u:DatePicker].start, Converter={x:Static ObjectConverters.IsNotNull}}" />
</Style>
</Style>

Expand Down
Loading

0 comments on commit 35933eb

Please sign in to comment.