btcpayserver/BTCPayServer/Services/ThemesSettings.cs
d11n 6972e8a3db
UI: Theme extensions (#4398)
* Theme extensions

Adds the ability to choose the themeing strategy: Extend one of the existing themes (light or dark) or go fully custom. The latter was the only option up to now, which isn't ideal:

- One had to provide a full-blown theme file overriding all variables
- Tedious, error prone and hard to maintain, because one has to keep track of updates

This PR makes it so that one can choose light or dark as base theme and do modifications on top.

Benefit: You can specify a limited set of variables and might get away with 5-20 lines of CSS.

* Ensure custom theme is present

* Update checkout test
2022-12-14 13:37:31 +09:00

54 lines
1.4 KiB
C#

using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Http;
using Newtonsoft.Json;
namespace BTCPayServer.Services;
public enum ThemeExtension
{
[Display(Name = "Does not extend a BTCPay Server theme, fully custom")]
Custom,
[Display(Name = "Extends the BTCPay Server Light theme")]
Light,
[Display(Name = "Extends the BTCPay Server Dark theme")]
Dark
}
public class ThemeSettings
{
[Display(Name = "Use custom theme")]
public bool CustomTheme { get; set; }
[Display(Name = "Custom Theme Extension Type")]
public ThemeExtension CustomThemeExtension { get; set; }
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Populate)]
[MaxLength(500)]
[Display(Name = "Custom Theme CSS URL")]
public string CustomThemeCssUri { get; set; }
[Display(Name = "Custom Theme File")]
[JsonIgnore]
public IFormFile CustomThemeFile { get; set; }
public string CustomThemeFileId { get; set; }
[Display(Name = "Logo")]
[JsonIgnore]
public IFormFile LogoFile { get; set; }
public string LogoFileId { get; set; }
public bool FirstRun { get; set; }
public override string ToString()
{
// no logs
return string.Empty;
}
public string CssUri
{
get => CustomTheme ? CustomThemeCssUri : "/main/themes/default.css";
}
}