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

Add a dyslexia-friendly theme #812

Draft
wants to merge 4 commits into
base: develop
Choose a base branch
from
Draft
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
3 changes: 3 additions & 0 deletions docs/_includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
<!-- Twitter -->
<meta name="twitter:card" content="summary_large_image">

<!-- Fonts -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/index.css">

<!-- CSS -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css" />
<link rel="stylesheet" type="text/css" href="{{ "/assets/css/stacks-documentation.min.css" | relative_url }}?{{page.date | date: '%s%N'}}">
Expand Down
11 changes: 10 additions & 1 deletion docs/_includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,22 @@
</div>
<div class="flex--item">
<div class="d-flex ai-center jc-space-between gs8">
<label class="flex--item s-label fs-body1 fw-normal js-highcontrast-btn" for="toggle-theme-highcontrast">High contrast mode</label>
<label class="flex--item s-label fs-body1 fw-normal" for="toggle-theme-highcontrast">High contrast mode</label>
<div class="flex--item s-toggle-switch">
<input id="toggle-theme-highcontrast" type="checkbox">
<div class="s-toggle-switch--indicator"></div>
</div>
</div>
</div>
<div class="flex--item">
<div class="d-flex ai-center jc-space-between gs8">
<label class="flex--item s-label fs-body1 fw-normal" for="toggle-theme-dyslexic">Dyslexic-friendly fonts</label>
<div class="flex--item s-toggle-switch">
<input id="toggle-theme-dyslexic" type="checkbox">
<div class="s-toggle-switch--indicator"></div>
</div>
</div>
</div>
</div>
</div>
</div>
Expand Down
9 changes: 9 additions & 0 deletions docs/_includes/layouts/home.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@
</div>
</div>
</div>
<div class="flex--item">
<div class="d-flex ai-center jc-space-between gs8">
<label class="flex--item s-label fs-body1 fw-normal" for="toggle-theme-dyslexic">Dyslexic-friendly fonts</label>
<div class="flex--item s-toggle-switch">
<input id="toggle-theme-dyslexic" type="checkbox">
<div class="s-toggle-switch--indicator"></div>
</div>
</div>
</div>
</div>
</div>
</div>
Expand Down
8 changes: 8 additions & 0 deletions docs/_includes/theme.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,13 @@
} else {
document.body.classList.remove("theme-highcontrast");
}

var dyslexic = localStorage.getItem("dyslexicTheme");

if (dyslexic === "true") {
document.body.classList.add("theme-dyslexic");
} else {
document.body.classList.remove("theme-dyslexic");
}
}());
</script>
17 changes: 17 additions & 0 deletions docs/assets/js/feature.theming.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@ $(document).ready(function () {
var themeDarkToggleSwitch = $("#toggle-theme-dark");
var themeCustomToggleSwitch = $("#toggle-theme-custom");
var themeHighcontrastToggleSwitch = $("#toggle-theme-highcontrast");
var themeDyslexicToggleSwitch = $("#toggle-theme-dyslexic");
var body = $("body");
var browserPrefersDark = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches;
var isCustom = body.hasClass("theme-custom");
var isDyslexic = body.hasClass("theme-dyslexic");
var isDark = body.hasClass("theme-dark") || browserPrefersDark && body.hasClass("theme-system");
var isHighcontrast = body.hasClass("theme-highcontrast");

themeCustomToggleSwitch.prop("checked", isCustom);
themeDarkToggleSwitch.prop("checked", isDark);
themeHighcontrastToggleSwitch.prop("checked", isHighcontrast);
themeDyslexicToggleSwitch.prop("checked", isDyslexic);

themeDarkToggleSwitch.change(function (e) {
e.preventDefault();
Expand Down Expand Up @@ -48,6 +51,20 @@ $(document).ready(function () {
return false;
});

themeDyslexicToggleSwitch.change(function (e) {
e.preventDefault();
e.stopPropagation();

var isDyslexic = body.hasClass("theme-dyslexic");

$(this).prop("checked", !isDyslexic);
body.toggleClass("theme-dyslexic", !isDyslexic);

localStorage.setItem("dyslexicTheme", !isDyslexic);

return false;
});

themeHighcontrastToggleSwitch.change(function (e) {
e.preventDefault();
e.stopPropagation();
Expand Down
31 changes: 20 additions & 11 deletions lib/css/exports/_stacks-constants-type.less
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,21 @@
// ============================================================================
// $ FONT FAMILY (ff-)
// ----------------------------------------------------------------------------
@ff-sans:
-apple-system, BlinkMacSystemFont, // San Francisco on macOS and iOS
"Segoe UI", // Windows
"Liberation Sans", // Linux
sans-serif; // The final fallback for rendering in sans-serif.
// -apple-system, BlinkMacSystemFont, // San Francisco on macOS and iOS
// "Segoe UI", // Windows
// "Liberation Sans", // Linux
// sans-serif; // The final fallback for rendering in sans-serif.

// ui-monospace, // San Francisco Mono on macOS and iOS
// "Cascadia Mono", "Segoe UI Mono", // Newer Windows monospace fonts that are optionally installed. Most likely to be rendered in Consolas
// "Liberation Mono", // Linux
// Menlo, Monaco, Consolas, // A few sensible system font choices
// monospace; // The final fallback for rendering in monospace.

@ff-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", "Liberation Sans", sans-serif;
@ff-serif: Georgia, Cambria, "Times New Roman", Times, serif;
@ff-mono:
ui-monospace, // San Francisco Mono on macOS and iOS
"Cascadia Mono", "Segoe UI Mono", // Newer Windows monospace fonts that are optionally installed. Most likely to be rendered in Consolas
"Liberation Mono", // Linux
Menlo, Monaco, Consolas, // A few sensible system font choices
monospace; // The final fallback for rendering in monospace.
@ff-mono: ui-monospace, "Cascadia Mono", "Segoe UI Mono", "Liberation Mono", Menlo, Monaco, Consolas, monospace;
@ff-dyslexic: "Comic Sans", "Comic Sans MS", "Chalkboard", "ChalkboardSE-Regular", "TSCu_Comic";

body {
--ff-sans: @ff-sans;
Expand All @@ -33,6 +36,12 @@ body {
--theme-body-font-family: var(--ff-sans);
}

body.theme-dyslexic {
--ff-sans: @ff-dyslexic, @ff-sans;
--ff-serif: @ff-dyslexic, @ff-sans;
--ff-mono: Comic Mono;
}

// ============================================================================
// $ FONT SIZES (fs-)
// Base font-size is 13px.
Expand Down