Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store Branding: Apply brand color to backend as well #5992

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions BTCPayServer/Models/StoreBrandingViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ public static async Task<StoreBrandingViewModel> CreateAsync(HttpRequest request
{
if (storeBlob == null)
return new StoreBrandingViewModel();
var result = new StoreBrandingViewModel(storeBlob);
result.LogoUrl = await uriResolver.Resolve(request.GetAbsoluteRootUri(), storeBlob.LogoUrl);
result.CssUrl = await uriResolver.Resolve(request.GetAbsoluteRootUri(), storeBlob.CssUrl);
var result = new StoreBrandingViewModel(storeBlob)
{
LogoUrl = await uriResolver.Resolve(request.GetAbsoluteRootUri(), storeBlob.LogoUrl),
CssUrl = await uriResolver.Resolve(request.GetAbsoluteRootUri(), storeBlob.CssUrl)
};
return result;
}
private StoreBrandingViewModel(StoreBlob storeBlob)
Expand Down
15 changes: 13 additions & 2 deletions BTCPayServer/Views/Shared/LayoutHead.cshtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
@inject BTCPayServer.Services.PoliciesSettings PoliciesSettings
@using BTCPayServer.Services
@using Microsoft.AspNetCore.Mvc.TagHelpers
@inject PoliciesSettings PoliciesSettings
@inject UriResolver UriResolver
@{
ViewData.TryGetValue("StoreBranding", out var storeBranding);
var store = Context.GetStoreData();
if (storeBranding == null && store != null)
{
storeBranding = await StoreBrandingViewModel.CreateAsync(Context.Request, UriResolver, store.GetStoreBlob());
}
}
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
@if (PoliciesSettings.DiscourageSearchEngines)
Expand All @@ -14,7 +25,7 @@
<link href="~/main/site.css" asp-append-version="true" rel="stylesheet" />

<partial name="LayoutHeadTheme" />
@if (ViewData.TryGetValue("StoreBranding", out var storeBranding) && storeBranding != null)
@if (storeBranding != null)
{
<partial name="LayoutHeadStoreBranding" model="storeBranding" />
}
Expand Down
97 changes: 89 additions & 8 deletions BTCPayServer/Views/Shared/LayoutHeadStoreBranding.cshtml
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
@using BTCPayServer.Services
@using Microsoft.AspNetCore.Mvc.TagHelpers
@model StoreBrandingViewModel
@inject ThemeSettings Theme
@if (!string.IsNullOrEmpty(Model.BrandColor))
{
var hasCustomeTheme = Theme.CustomTheme && Theme.CustomThemeCssUrl is not null;
var brand = Model.BrandColor;
var brandColor = ColorPalette.Default.FromHtml(brand);
var brandRgbValues = $"{brandColor.R}, {brandColor.G}, {brandColor.B}";
var accent = ColorPalette.Default.AdjustBrightness(brand, (float)-0.15);
var brightness = brandColor.GetBrightness();
var accent = ColorPalette.Default.AdjustBrightness(brand, (float)-.15);
var accentColor = ColorPalette.Default.FromHtml(accent);
var accentRgbValues = $"{accentColor.R}, {accentColor.G}, {accentColor.B}";
var complement = ColorPalette.Default.TextColor(brand);
var complementVar = $"var(--btcpay-{(complement == "black" ? "black" : "white")})";
<style>
Expand All @@ -14,19 +21,93 @@
--btcpay-primary-shadow: @brand;
--btcpay-primary-bg-hover: @accent;
--btcpay-primary-bg-active: @accent;
--btcpay-body-link: @brand;
--btcpay-body-link-accent: @accent;
--btcpay-body-link-accent-rgb: @accentRgbValues;
--btcpay-primary-text: @complementVar;
--btcpay-primary-text-hover: @complementVar;
--btcpay-primary-text-active: @complementVar;
}
a {
color: var(--btcpay-body-link);
}
a:hover {
color: var(--btcpay-body-link-accent);
}
</style>
@if (brightness > .5 || (Theme.CustomThemeExtension == ThemeExtension.Dark && brightness < .5))
{
var brandAdjusted = ColorPalette.Default.AdjustBrightness(brand, (float)(.35-brightness));
var brandColorAdjusted = ColorPalette.Default.FromHtml(brandAdjusted);
var brandRgbValuesAdjusted = $"{brandColorAdjusted.R}, {brandColorAdjusted.G}, {brandColorAdjusted.B}";
var accentAdjusted = ColorPalette.Default.AdjustBrightness(brandAdjusted, (float)-.15);
var accentColorAdjusted = ColorPalette.Default.FromHtml(accentAdjusted);
var accentRgbValuesAdjusted = $"{accentColorAdjusted.R}, {accentColorAdjusted.G}, {accentColorAdjusted.B}";
var complementAdjusted = ColorPalette.Default.TextColor(brandAdjusted);
var complementVarAdjusted = $"var(--btcpay-{(complementAdjusted == "black" ? "black" : "white")})";
<style>
:root[data-theme='light'],
:root[data-btcpay-theme='light'] {
--btcpay-primary: @brandAdjusted;
--btcpay-primary-rgb: @brandRgbValuesAdjusted;
--btcpay-primary-shadow: @brandAdjusted;
--btcpay-primary-bg-hover: @accentAdjusted;
--btcpay-primary-bg-active: @accentAdjusted;
--btcpay-body-link-accent: @accentAdjusted;
--btcpay-body-link-accent-rgb: @accentRgbValuesAdjusted;
--btcpay-primary-text: @complementVarAdjusted;
--btcpay-primary-text-hover: @complementVarAdjusted;
--btcpay-primary-text-active: @complementVarAdjusted;
}
@@media (prefers-color-scheme: light) {
:root:not([data-btcpay-theme], [data-theme]) {
--btcpay-primary: @brandAdjusted;
--btcpay-primary-rgb: @brandRgbValuesAdjusted;
--btcpay-primary-shadow: @brandAdjusted;
--btcpay-primary-bg-hover: @accentAdjusted;
--btcpay-primary-bg-active: @accentAdjusted;
--btcpay-body-link-accent: @accentAdjusted;
--btcpay-body-link-accent-rgb: @accentRgbValuesAdjusted;
--btcpay-primary-text: @complementVarAdjusted;
--btcpay-primary-text-hover: @complementVarAdjusted;
--btcpay-primary-text-active: @complementVarAdjusted;
}
}
</style>
}
@if (brightness < .5 && (!hasCustomeTheme || Theme.CustomThemeExtension == ThemeExtension.Dark))
{
var brandAdjusted = ColorPalette.Default.AdjustBrightness(brand, (float)(.5-brightness));
var brandColorAdjusted = ColorPalette.Default.FromHtml(brandAdjusted);
var brandRgbValuesAdjusted = $"{brandColorAdjusted.R}, {brandColorAdjusted.G}, {brandColorAdjusted.B}";
var accentAdjusted = ColorPalette.Default.AdjustBrightness(brandAdjusted, (float).15);
var accentColorAdjusted = ColorPalette.Default.FromHtml(accentAdjusted);
var accentRgbValuesAdjusted = $"{accentColorAdjusted.R}, {accentColorAdjusted.G}, {accentColorAdjusted.B}";
var complementAdjusted = ColorPalette.Default.TextColor(brandAdjusted);
var complementVarAdjusted = $"var(--btcpay-{(complementAdjusted == "black" ? "black" : "white")})";
<style>
:root[data-theme='dark'],
:root[data-btcpay-theme='dark'] {
--btcpay-primary: @brandAdjusted;
--btcpay-primary-rgb: @brandRgbValuesAdjusted;
--btcpay-primary-shadow: @brandAdjusted;
--btcpay-primary-bg-hover: @accentAdjusted;
--btcpay-primary-bg-active: @accentAdjusted;
--btcpay-body-link-accent: @accentAdjusted;
--btcpay-body-link-accent-rgb: @accentRgbValuesAdjusted;
--btcpay-primary-text: @complementVarAdjusted;
--btcpay-primary-text-hover: @complementVarAdjusted;
--btcpay-primary-text-active: @complementVarAdjusted;
}
@@media (prefers-color-scheme: dark) {
:root:not([data-btcpay-theme], [data-theme]) {
--btcpay-primary: @brandAdjusted;
--btcpay-primary-rgb: @brandRgbValuesAdjusted;
--btcpay-primary-shadow: @brandAdjusted;
--btcpay-primary-bg-hover: @accentAdjusted;
--btcpay-primary-bg-active: @accentAdjusted;
--btcpay-body-link-accent: @accentAdjusted;
--btcpay-body-link-accent-rgb: @accentRgbValuesAdjusted;
--btcpay-primary-text: @complementVarAdjusted;
--btcpay-primary-text-hover: @complementVarAdjusted;
--btcpay-primary-text-active: @complementVarAdjusted;
}
}
</style>
}
<meta name="theme-color" content="@brand">
}
@if (!string.IsNullOrEmpty(Model.CssUrl))
Expand Down
2 changes: 1 addition & 1 deletion BTCPayServer/wwwroot/main/site.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Variables */
:root {
--chart-main-rgb: 68, 164, 49;
--chart-main-rgb: var(--btcpay-primary-rgb);
--chart-series-a-rgb: var(--chart-main-rgb);
--chart-series-b-rgb: 245, 0, 0;
--chart-series-c-rgb: 0, 109, 242;
Expand Down