From 8484d6ad868fd3a23cb695675e1c1da890a9d44f Mon Sep 17 00:00:00 2001
From: Zhang Dian <54255897+zdpcdt@users.noreply.github.com>
Date: Fri, 15 Nov 2024 02:20:32 +0800
Subject: [PATCH] feat: add Shadow part to PaletteDemo.
---
.../FunctionalColorGroupControl.axaml | 10 +--
.../Controls/ShadowGroupControl.axaml | 88 +++++++++++++++++++
.../Controls/ShadowGroupControl.cs | 41 +++++++++
.../Pages/PaletteDemo.axaml | 16 +++-
.../ViewModels/PaletteDemoViewModel.cs | 86 ++++++++++++++++++
5 files changed, 234 insertions(+), 7 deletions(-)
create mode 100644 demo/Semi.Avalonia.Demo/Controls/ShadowGroupControl.axaml
create mode 100644 demo/Semi.Avalonia.Demo/Controls/ShadowGroupControl.cs
diff --git a/demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.axaml b/demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.axaml
index b3d46be..2c74653 100644
--- a/demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.axaml
+++ b/demo/Semi.Avalonia.Demo/Controls/FunctionalColorGroupControl.axaml
@@ -6,15 +6,15 @@
x:CompileBindings="True"
x:DataType="viewModels:FunctionalColorGroupViewModel">
-
-
+
+
-
+ Theme="{DynamicResource TitleSelectableTextBlock}" />
@@ -129,4 +129,4 @@
-
+
\ No newline at end of file
diff --git a/demo/Semi.Avalonia.Demo/Controls/ShadowGroupControl.axaml b/demo/Semi.Avalonia.Demo/Controls/ShadowGroupControl.axaml
new file mode 100644
index 0000000..d06aea4
--- /dev/null
+++ b/demo/Semi.Avalonia.Demo/Controls/ShadowGroupControl.axaml
@@ -0,0 +1,88 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/demo/Semi.Avalonia.Demo/Controls/ShadowGroupControl.cs b/demo/Semi.Avalonia.Demo/Controls/ShadowGroupControl.cs
new file mode 100644
index 0000000..bb59ab1
--- /dev/null
+++ b/demo/Semi.Avalonia.Demo/Controls/ShadowGroupControl.cs
@@ -0,0 +1,41 @@
+using System.Collections;
+using Avalonia;
+using Avalonia.Controls.Primitives;
+
+namespace Semi.Avalonia.Demo.Controls;
+
+public class ShadowGroupControl : TemplatedControl
+{
+ public static readonly StyledProperty TitleProperty =
+ AvaloniaProperty.Register(nameof(Title));
+
+ public string? Title
+ {
+ get => GetValue(TitleProperty);
+ set => SetValue(TitleProperty, value);
+ }
+
+ private IEnumerable? _lightShadows;
+
+ public static readonly DirectProperty LightShadowsProperty =
+ AvaloniaProperty.RegisterDirect(nameof(LightShadows),
+ o => o.LightShadows, (o, v) => o.LightShadows = v);
+
+ public IEnumerable? LightShadows
+ {
+ get => _lightShadows;
+ set => SetAndRaise(LightShadowsProperty, ref _lightShadows, value);
+ }
+
+ private IEnumerable? _darkShadows;
+
+ public static readonly DirectProperty DarkShadowsProperty =
+ AvaloniaProperty.RegisterDirect(nameof(DarkShadows),
+ o => o.DarkShadows, (o, v) => o.DarkShadows = v);
+
+ public IEnumerable? DarkShadows
+ {
+ get => _darkShadows;
+ set => SetAndRaise(DarkShadowsProperty, ref _darkShadows, value);
+ }
+}
\ No newline at end of file
diff --git a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml
index 8293c53..64fdd52 100644
--- a/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml
+++ b/demo/Semi.Avalonia.Demo/Pages/PaletteDemo.axaml
@@ -21,6 +21,7 @@
+
@@ -115,7 +116,6 @@
-
+
+
+
+
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs b/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs
index 4a53cb7..cf23454 100644
--- a/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs
+++ b/demo/Semi.Avalonia.Demo/ViewModels/PaletteDemoViewModel.cs
@@ -47,6 +47,7 @@ public class PaletteDemoViewModel : ObservableObject
}
public ObservableCollection FunctionalColors { get; set; } = [];
+ public ObservableCollection Shadows { get; set; } = [];
public PaletteDemoViewModel()
{
@@ -59,6 +60,7 @@ public class PaletteDemoViewModel : ObservableObject
{
InitializePalette();
InitializeFunctionalColors();
+ InitializeShadows();
}
private void InitializePalette()
@@ -97,6 +99,11 @@ public class PaletteDemoViewModel : ObservableObject
FunctionalColors.Add(new FunctionalColorGroupViewModel("Disabled", _lightResourceDictionary, _darkResourceDictionary, ColorTokens.DisabledTokens));
}
+ private void InitializeShadows()
+ {
+ Shadows.Add(new ShadowGroupViewModel("Shadow", _lightResourceDictionary, _darkResourceDictionary, ColorTokens.ShadowTokens));
+ }
+
private void OnClickColorItem(PaletteDemoViewModel vm, ColorItemViewModel item)
{
SelectedColor = item;
@@ -254,6 +261,79 @@ public class FunctionalColorGroupViewModel : ObservableObject
}
}
+public class ShadowItemViewModel : ObservableObject
+{
+ private string _shadowDisplayName = null!;
+
+ public string ShadowDisplayName
+ {
+ get => _shadowDisplayName;
+ set => SetProperty(ref _shadowDisplayName, value);
+ }
+
+ private string _resourceKey = null!;
+
+ public string ResourceKey
+ {
+ get => _resourceKey;
+ set => SetProperty(ref _resourceKey, value);
+ }
+
+ private string _boxShadowValue = null!;
+
+ public string BoxShadowValue
+ {
+ get => _boxShadowValue;
+ set => SetProperty(ref _boxShadowValue, value);
+ }
+
+ public ShadowItemViewModel(string shadowDisplayName, BoxShadows boxShadows, string resourceKey)
+ {
+ ShadowDisplayName = shadowDisplayName;
+ ResourceKey = resourceKey;
+ BoxShadowValue = boxShadows.ToString();
+ }
+}
+
+public class ShadowGroupViewModel : ObservableObject
+{
+ private string _title = null!;
+
+ public string Title
+ {
+ get => _title;
+ set => SetProperty(ref _title, value);
+ }
+
+ public ObservableCollection LightShadows { get; set; } = [];
+ public ObservableCollection DarkShadows { get; set; } = [];
+
+
+ public ShadowGroupViewModel(string title, IResourceDictionary? lightDictionary,
+ IResourceDictionary? darkDictionary, IReadOnlyList> tokens)
+ {
+ Title = title;
+ foreach (var (key, name) in tokens)
+ {
+ if (lightDictionary?.TryGetValue(key, out var lightValue) ?? false)
+ {
+ if (lightValue is BoxShadows lightShadow)
+ {
+ LightShadows.Add(new ShadowItemViewModel(name, lightShadow, key));
+ }
+ }
+
+ if (darkDictionary?.TryGetValue(key, out var darkValue) ?? false)
+ {
+ if (darkValue is BoxShadows darkShadow)
+ {
+ DarkShadows.Add(new ShadowItemViewModel(name, darkShadow, key));
+ }
+ }
+ }
+ }
+}
+
public static class ColorTokens
{
public static IReadOnlyList> PrimaryTokens { get; } = new List>
@@ -374,4 +454,10 @@ public static class ColorTokens
new("SemiColorDisabledBackground", "Disabled Background"),
new("SemiColorDisabledFill", "Disabled Fill"),
};
+
+ public static IReadOnlyList> ShadowTokens { get; } = new List>
+ {
+ new("SemiColorShadow", "Shadow"),
+ new("SemiShadowElevated", "Shadow Elevated"),
+ };
}
\ No newline at end of file