From 87b4ef119a262dcdfc3f6d3c8bcd9c2d085a8882 Mon Sep 17 00:00:00 2001 From: Albina Starykova Date: Mon, 23 Sep 2024 18:39:21 +0200 Subject: [PATCH] Basic BE setup for contrast themes --- client/scss/components/_button.scss | 4 ++++ wagtail/admin/forms/account.py | 2 +- .../admin/templatetags/wagtailadmin_tags.py | 8 ++++++- .../migrations/0014_userprofile_contrast.py | 23 +++++++++++++++++++ wagtail/users/models.py | 11 +++++++++ 5 files changed, 46 insertions(+), 2 deletions(-) create mode 100644 wagtail/users/migrations/0014_userprofile_contrast.py diff --git a/client/scss/components/_button.scss b/client/scss/components/_button.scss index 89e4e68cd320..135a40007d94 100644 --- a/client/scss/components/_button.scss +++ b/client/scss/components/_button.scss @@ -318,6 +318,10 @@ } } } + + .w-contrast-high & { + border: 1px solid theme('colors.border-button-outline-default'); + } } .w-header-button { diff --git a/wagtail/admin/forms/account.py b/wagtail/admin/forms/account.py index 343f62ba68aa..9733595c3d57 100644 --- a/wagtail/admin/forms/account.py +++ b/wagtail/admin/forms/account.py @@ -140,4 +140,4 @@ class Meta: class ThemePreferencesForm(forms.ModelForm): class Meta: model = UserProfile - fields = ["theme", "density"] + fields = ["theme", "contrast", "density"] diff --git a/wagtail/admin/templatetags/wagtailadmin_tags.py b/wagtail/admin/templatetags/wagtailadmin_tags.py index 5c4cb7e6f646..46fc2e16eb23 100644 --- a/wagtail/admin/templatetags/wagtailadmin_tags.py +++ b/wagtail/admin/templatetags/wagtailadmin_tags.py @@ -674,12 +674,18 @@ def admin_theme_classname(context): if hasattr(user, "wagtail_userprofile") else "system" ) + contrast_name = ( + user.wagtail_userprofile.contrast + if hasattr(user, "wagtail_userprofile") + else "default" + ) density_name = ( user.wagtail_userprofile.density if hasattr(user, "wagtail_userprofile") else "default" ) - return f"w-theme-{theme_name} w-density-{density_name}" + contrast_name = contrast_name.split("_")[0] + return f"w-theme-{theme_name} w-density-{density_name} w-contrast-{contrast_name}" @register.simple_tag diff --git a/wagtail/users/migrations/0014_userprofile_contrast.py b/wagtail/users/migrations/0014_userprofile_contrast.py new file mode 100644 index 000000000000..bf7fd26a2a9a --- /dev/null +++ b/wagtail/users/migrations/0014_userprofile_contrast.py @@ -0,0 +1,23 @@ +# Generated by Django 5.0.6 on 2024-09-23 15:33 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("wagtailusers", "0013_userprofile_density"), + ] + + operations = [ + migrations.AddField( + model_name="userprofile", + name="contrast", + field=models.CharField( + choices=[("default", "Default"), ("high_contrast", "High contrast")], + default="default", + max_length=40, + verbose_name="contrast", + ), + ), + ] diff --git a/wagtail/users/models.py b/wagtail/users/models.py index 3891a7c492f7..dd07004d0f36 100644 --- a/wagtail/users/models.py +++ b/wagtail/users/models.py @@ -84,6 +84,17 @@ class AdminColorThemes(models.TextChoices): max_length=40, ) + class AdminContrastThemes(models.TextChoices): + DEFAULT = "default", _("Default") + HIGH_CONTRAST = "high_contrast", _("High contrast") + + contrast = models.CharField( + verbose_name=_("contrast"), + choices=AdminContrastThemes.choices, + default=AdminContrastThemes.DEFAULT, + max_length=40, + ) + class AdminDensityThemes(models.TextChoices): DEFAULT = "default", _("Default") SNUG = "snug", _("Snug")