Skip to content
Merged
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
7 changes: 7 additions & 0 deletions pattern_library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@
("templates", ["patterns/templates"]),
("pages", ["patterns/pages"]),
),
# CUSTOM_CSS allows users to override pattern library styles by providing a path to a CSS file
# (relative to STATIC_URL) that contains CSS custom properties. This file will be included
# after the main bundle to override default styles.
# Example: "css/pattern-library-custom.css"
"CUSTOM_CSS": None,
# SITE_TITLE allows users to customize the pattern library title displayed in the header
"SITE_TITLE": "Django Pattern Library",
}


Expand Down
15 changes: 11 additions & 4 deletions pattern_library/static/pattern_library/src/scss/_config.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
// Overwrite the title, main colour and font family here
$site-title: 'Django Pattern Library';
$color-primary: #34b2b2;
$family-primary: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
// Configuration with support for runtime customization via CSS custom properties

// Default SCSS variables for compile-time usage (needed for Sass functions)
$color-primary: #34b2b2 !default;
$family-primary: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen-Sans, Ubuntu, Cantarell, 'Helvetica Neue', sans-serif !default;

// CSS Custom Properties for runtime customization
html, :root {
--color-primary: #{$color-primary};
--family-primary: #{$family-primary};
}

// $color--primary + $family--primary are in _config.scss
$white: #fff;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
html,
body {
margin: 0;
font-family: $family-primary;
font-family: var(--family-primary);
height: 100%;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
&:hover,
&.is-active {
background: $white;
border-left: 5px solid $color-primary;
border-left: 5px solid var(--color-primary);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@

&:hover {
color: #000;
background-color: $color-primary;
background-color: var(--color-primary);
}
}

&--active {
> a {
color: #000;
background-color: $color-primary;
background-color: var(--color-primary);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@use "../config" as *;

.header {
background-color: $color-primary;
background-color: var(--color-primary);
display: flex;
align-items: center;
height: 45px;
Expand All @@ -17,10 +17,8 @@
letter-spacing: 1px;
font-size: 16px;
margin-left: 15px;

&::after {
content: $site-title;
}
margin-top: 0;
margin-bottom: 0;

@media only screen and (min-width: 600px) {
font-size: 22px;
Expand Down
4 changes: 3 additions & 1 deletion pattern_library/templates/pattern_library/base.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{% load static %}
{% load pattern_library_tags %}

<!DOCTYPE html>
<html lang="en">
Expand All @@ -9,6 +10,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>♻️</text></svg>"/>
<script type="text/javascript" src="{% static 'pattern_library/dist/bundle.js' %}"></script>
{% pattern_library_custom_css %}
</head>

<body class="body">
Expand All @@ -19,7 +21,7 @@
</a>
<h1 class="header__title">
<span class="sr-only">Pattern Library</span>
{# Set in _config.scss #}
{% pattern_library_site_title %}
</h1>
</header>
<aside class="sidebar">
Expand Down
1 change: 1 addition & 0 deletions pattern_library/templatetags/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Template tags for django-pattern-library
51 changes: 51 additions & 0 deletions pattern_library/templatetags/pattern_library_tags.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from django import template
from django.templatetags.static import static
from django.utils.safestring import mark_safe

from pattern_library import get_setting

register = template.Library()


@register.simple_tag
def pattern_library_custom_css():
"""
Include custom CSS for pattern library customization.

This tag optionally includes an external CSS file for additional customization.

Usage in templates:
{% load pattern_library_tags %}
{% pattern_library_custom_css %}

Example PATTERN_LIBRARY setting:
PATTERN_LIBRARY = {
"CUSTOM_CSS": "css/pattern-library-custom.css" # relative to STATIC_URL
}
"""
css_content = []

# Include external CSS file if specified
custom_css_path = get_setting("CUSTOM_CSS")
if custom_css_path:
try:
css_url = static(custom_css_path)
css_content.append(
f'<link rel="stylesheet" type="text/css" href="{css_url}">'
)
except Exception:
pass # If static file handling fails, just skip the external file

return mark_safe("\n".join(css_content))


@register.simple_tag
def pattern_library_site_title():
"""
Get the site title for the pattern library.

Usage in templates:
{% load pattern_library_tags %}
{% pattern_library_site_title %}
"""
return get_setting("SITE_TITLE")