Skip to content

Commit

Permalink
Basic BE setup for contrast themes
Browse files Browse the repository at this point in the history
  • Loading branch information
albinazs committed Sep 23, 2024
1 parent 5aa0673 commit 87b4ef1
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 2 deletions.
4 changes: 4 additions & 0 deletions client/scss/components/_button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@
}
}
}

.w-contrast-high & {
border: 1px solid theme('colors.border-button-outline-default');
}
}

.w-header-button {
Expand Down
2 changes: 1 addition & 1 deletion wagtail/admin/forms/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,4 @@ class Meta:
class ThemePreferencesForm(forms.ModelForm):
class Meta:
model = UserProfile
fields = ["theme", "density"]
fields = ["theme", "contrast", "density"]
8 changes: 7 additions & 1 deletion wagtail/admin/templatetags/wagtailadmin_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 23 additions & 0 deletions wagtail/users/migrations/0014_userprofile_contrast.py
Original file line number Diff line number Diff line change
@@ -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",
),
),
]
11 changes: 11 additions & 0 deletions wagtail/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 87b4ef1

Please sign in to comment.