Skip to content

Commit

Permalink
#273 - Using accent color for foreground of category elements.
Browse files Browse the repository at this point in the history
  • Loading branch information
maraf committed Jun 11, 2020
1 parent b497caa commit b539e44
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Money.UI.Blazor/Components/OutcomeCard.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<h2 class="amount">@Context.CurrencyFormatter.Format(Model.Amount)</h2>
<p class="when">@Model.When.ToShortDateString()</p>
<p class="description">@Model.Description</p>
<p class="category">
<p class="category @CategoryColor.SelectAccent("back-dark", "back-light")">
<span class="badge" style="background-color: @CategoryColor.ToHashCode()">@CategoryName</span>
</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/Money.UI.Blazor/Components/OutcomeCreate.razor
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
{
@foreach (var category in Categories)
{
<button type="button" class="btn btn-block btn-selectable @(category.Key.Equals(CategoryKey) ? "btn-selectable-selected" : "") text-truncate" style="background-color: @category.Color.ToHashCode();" @onclick="@(() => CategoryKey = category.Key)">
<button type="button" class="btn btn-block btn-selectable @(category.Key.Equals(CategoryKey) ? "btn-selectable-selected" : "") text-truncate @category.Color.SelectAccent("back-dark", "back-light")" style="background-color: @category.Color.ToHashCode();" @onclick="@(() => CategoryKey = category.Key)">
<span>@category.Icon</span>
<strong>@category.Name</strong>
<span>@category.Description</span>
Expand Down
3 changes: 3 additions & 0 deletions src/Money.UI.Blazor/Models/ColorCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ namespace Money.Models
{
public class ColorCollection : List<Color>
{
public static readonly Color White = Color.FromArgb(255, 255, 255, 255);
public static readonly Color Black = Color.FromArgb(255, 0, 0, 0);

public ColorCollection()
{
Load();
Expand Down
11 changes: 11 additions & 0 deletions src/Money.UI.Blazor/Models/ColorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,16 @@ public static string ToHashCode(this Color color)

return "#" + BitConverter.ToString(data).Replace("-", string.Empty);
}

public static Color ToAccentColor(this Color color)
=> SelectAccent(color, ColorCollection.White, ColorCollection.Black);

public static T SelectAccent<T>(this Color color, T light, T dark)
{
if ((color.R + color.G + color.B) / 3 < 90)
return light;

return dark;
}
}
}
2 changes: 1 addition & 1 deletion src/Money.UI.Blazor/Pages/Categories.razor
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
{
@foreach (var item in Models)
{
<div class="alert" style="background-color: @item.Color.ToHashCode()">
<div class="alert @item.Color.SelectAccent("back-dark", "back-light")" style="background-color: @item.Color.ToHashCode()">
<div class="form-row">
@if (item.Icon != null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Money.UI.Blazor/wwwroot/css/site.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions src/Money.UI.Blazor/wwwroot/css/site.scss
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ h4 {
}
}

.back-dark {
color: #eee;

.btn-link {
color: #eee;
}
}

.btn-icon, .btn-color {
width: 48px;
height: 48px;
Expand Down

0 comments on commit b539e44

Please sign in to comment.