move patterns and javascript to core directories

This commit is contained in:
2024-07-13 10:16:32 -04:00
parent 426f92cfd0
commit 4532389e3d
50 changed files with 55 additions and 1006 deletions

View File

@@ -0,0 +1,100 @@
<html>
<head>
<title>Pattern</title>
</head>
<body data-prismjs-copy-timeout="1500">
<h2>What is it</h2>
<h2>When to use it</h2>
<h2>How to use it</h2>
<p>When using this, use the default break points as they are set to the same as the Bootstrap framework. The grid for the design system at large break point has been widened to accompdate 3 colour cards across. </p>
<div class="tab-group" id="breakpoints">
<pre class="language-css" data-tab="scss">//- DS2 core (c) 2024 Alexander McIlwraith
//- Licensed under CC BY-SA 4.0
$grid-breakpoints: ( xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px ) !default;
@mixin breakpoint-debug {
body::before, body::after {
background-color: #555;
color: white;
content: "bigger than extra large";
display: grid;
font-size: 25px;
grid-template-columns: auto;
padding: 25px;
place-content: center;
// text-align: center;
@include break(-xl) {
content: "extra large";
}
@include break(-lg) {
content: "large";
}
@include break(-md) {
content: "medium";
}
@include break(-sm) {
content: "small";
}
}
}
@mixin break($bps, $points: $grid-breakpoints) {
@each $bp in $bps {
$min: 0;
$max: 0;
@if str-length($bp) == 2 {
// only a single break point was received
$min: map-get($points, $bp);
$max: map-get($points, nth(map-keys($points), index(map-keys($points), $bp) + 1));
} @else {
@if str-slice($bp, 0, 1) == "-" {
// no lower breakpoint was received
$min: null;
$max: map-get($points, str-slice($bp, 2, 3));
} @else {
$min: map-get($points, unquote(str-slice($bp, 0, 2)));
@if str-length($bp) == 3 {
// no upper break point was received
$max: null;
} @else {
$max: map-get($points, str-slice($bp, 4, 5));
}
}
}
@if $min != null and $max != null {
// Makes the @content apply between the min and max breakpoints
@media (min-width: $min) and (max-width: $max) {
@content;
}
} @else if $min == null {
// Makes the @content apply to the given breakpoint and narrower.
@media (max-width: $max) {
@content;
}
} @else if $max == null {
// Makes the @content apply to the given breakpoint and wider.
@media (min-width: $min) {
@content;
}
} @else {
@content;
}
}
}</pre>
</div>
</body>
</html>

View File

@@ -0,0 +1,131 @@
<html>
<head>
<title>Pattern</title>
</head>
<body data-prismjs-copy-timeout="1500">
<div class="tab-group" id="header">
<pre class="language-html" data-tab="html">
<!-- create temp variables and store the design system values-->
<header>
<!-- The headline banner area -->
<svg height="5.5rem" width="100%" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
<text>[site name]</text>
</svg>
<div>
<div class="header-title">
<h1> <a href="[site root]">[site name]</a></h1>
</div>
<!-- Other sections can go here, such as search and directory-->
</div>
</header></pre>
<pre class="language-sass" data-tab="scss">//- DS2 core (c) 2024 Alexander McIlwraith
//- Licensed under CC BY-SA 4.0
$header-bg-color: var(--colour-grey-xxl) !default;
$font-heading: sans-serif !default;
$font-weight: 700 !default;
@mixin header {
header {
display: grid;
grid-template-rows: 1.75rem 3.5rem;
grid-column: 2 / 4;
overflow: hidden;
svg {
grid-column: 1 / -1;
grid-row: 1 / -1;
place-self: stretch;
text {
transform: translate(-1rem, 7.25rem);
font-size: 10rem;
font-weight: 1000;
font-family: $font-heading;
fill: $header-bg-color;
}
}
> div {
grid-row: 2;
grid-column: 1 / -1;
display: grid;
grid-column-gap: 1rem;
grid-template-columns: auto max-content max-content;
.header-title {
h1 {
margin: 0;
padding: 0 1rem;
a, a:visited {
border-bottom: none;
color: var(--colour-black);
font-family: $font-heading;
font-size: 2.5rem;
font-size: 32px;
font-weight: $font-weight;
margin: 0;
padding: 0;
text-decoration: none;
}
}
}
}
}
}</pre>
<pre class="language-css" data-tab="css">header {
display: -ms-grid;
display: grid;
-ms-grid-rows: 1.75rem 3.5rem;
grid-template-rows: 1.75rem 3.5rem;
-ms-grid-column: 2;
-ms-grid-column-span: 2;
grid-column: 2/4;
overflow: hidden;
}
header svg {
grid-column: 1/-1;
grid-row: 1/-1;
-ms-grid-row-align: stretch;
-ms-grid-column-align: stretch;
place-self: stretch;
}
header svg text {
-webkit-transform: translate(-1rem, 7.25rem);
-ms-transform: translate(-1rem, 7.25rem);
transform: translate(-1rem, 7.25rem);
font-size: 10rem;
font-weight: 1000;
font-family: sans-serif;
fill: var(--colour-grey-xxl);
}
header > div {
-ms-grid-row: 2;
grid-row: 2;
grid-column: 1/-1;
display: -ms-grid;
display: grid;
grid-column-gap: 1rem;
-ms-grid-columns: auto -webkit-max-content -webkit-max-content;
-ms-grid-columns: auto max-content max-content;
grid-template-columns: auto -webkit-max-content -webkit-max-content;
grid-template-columns: auto max-content max-content;
}
header > div .header-title h1 {
margin: 0;
padding: 0 1rem;
}
header > div .header-title h1 a, header > div .header-title h1 a:visited {
border-bottom: none;
color: var(--colour-black);
font-family: sans-serif;
font-size: 2.5rem;
font-size: 32px;
font-weight: 700;
margin: 0;
padding: 0;
text-decoration: none;
}</pre>
</div>
</body>
</html>

View File

@@ -0,0 +1,202 @@
<html>
<head>
<title>Pattern</title>
</head>
<body data-prismjs-copy-timeout="1500">
<h2>What is it</h2>
<h2>When to use it</h2>
<h2>How to use it</h2>
<p>The tabbed user interface enables users to jump to their target section quickly. Tabs present like logically group information on the same page. Information should </p>
<ul>
<li>be logically chunked and ordered</li>
<li>be arallel in nature</li>
<li>show user's context</li>
<li>obvious where they begin and end </li>
</ul>
<p>Users should not need to see content of multiple tabs simultaneously and the user should be able to easily recognise where they are within the content. </p>
<p>The tab module can be initialised by importing a file with the javascript module using import * as tabs from "../pg/patterns/layouts/tabs/_tabs.js"; contains a modularized version of the jQuery code, so that it can be called on demand. It is what is used in the design system so that the JavaScript can be called at run time (after loading content).</p>
<tabset id="tabs">
<pre class="language-html" tab="html">
<div class="tab-group" id="uniqueID">
<div data-tab="[tab title]"></div>
<div data-tab="[tab title]"></div>
</div></pre>
<pre class="language-css" tab="css">tabset, .tab-group {
margin: 2rem 0 1rem 0;
}
tabset > ul, .tab-group > ul {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
margin: 0;
padding: 0;
}
tabset > ul li.separator, .tab-group > ul li.separator {
border-bottom: 1px solid var(--colour-grey);
border-left: 1px solid var(--colour-grey);
display: inline-block;
margin: 0.45rem 0 0 0;
width: 100%;
}
tabset .tab-hidden, .tab-group .tab-hidden {
display: none;
}
tabset [role=tab], .tab-group [role=tab] {
background-color: var(--colour-white);
border-left: 1px solid var(--colour-grey);
border-top: 1px solid var(--colour-grey);
border-radius: 0.5rem 0.5rem 0 0;
cursor: pointer;
margin: 0;
display: inline;
padding: 1rem 1.5rem 0.14rem 1.5rem;
z-index: 2;
}
tabset [role=tab]:last-of-type, .tab-group [role=tab]:last-of-type {
border-right: 1px solid var(--colour-grey);
}
tabset [role=tab]:not(.selected), .tab-group [role=tab]:not(.selected) {
background-color: var(--colour-grey-xxl);
border-bottom: 1px solid var(--colour-grey);
}
tabset [role=tab] span, .tab-group [role=tab] span {
display: block;
margin: 0 0 0.5rem 0;
}
tabset [role=tabpanel], .tab-group [role=tabpanel] {
background-color: var(--colour-white);
border: 1px solid var(--colour-grey);
border-top: none;
padding: 1rem;
z-index: 1;
}
tabset [role=tabpanel]:not(.open), .tab-group [role=tabpanel]:not(.open) {
display: none;
}</pre>
<pre class="language-css" tab="scss">// DS2 core (c) 2024 Alexander McIlwraith
// Licensed under CC BY-SA 4.0
$tab-border: var(--colour-grey) !default;
$tab-selected: var(--colour-white) !default;
$tab-notselected: var(--colour-grey-xxl) !default;
@mixin tabs {
tabset, .tab-group {
margin: 2rem 0 1rem 0;
> ul {
display: flex;
margin: 0;
padding: 0;
li.separator {
border-bottom: 1px solid $tab-border;
border-left: 1px solid $tab-border;
display: inline-block;
margin: .45rem 0 0 0;
width: 100%;
}
}
.tab-hidden {
display: none;
}
[role="tab"] {
background-color: $tab-selected;
border-left: 1px solid $tab-border;
border-top: 1px solid $tab-border;
border-radius: .5rem .5rem 0 0;
cursor:pointer;
margin: 0;
display: inline;
padding: 1rem 1.5rem .14rem 1.5rem;
z-index: 2;
&:last-of-type {
border-right: 1px solid $tab-border;
}
&:not(.selected) {
background-color: $tab-notselected;
border-bottom: 1px solid $tab-border;
}
span {
display: block;
margin: 0 0 .5rem 0;
}
}
[role="tabpanel"] {
background-color: $tab-selected;
border: 1px solid $tab-border;
border-top: none;
padding: 1rem;
z-index: 1;
&:not(.open) {
display: none;
}
@content;
}
}
}</pre>
<pre class="language-css" tab="js">/* DS2 core (c) 2024 Alexander McIlwraith
import * as tabs from "../pg/patterns/layouts/tabs/_tabs.js";
tabs.init();
*/
export function init(p = document) {
p.querySelectorAll(".tab-group, tabset").forEach(tabGroup => {
if (tabGroup.querySelector("[role=tablist]") === null) {
const tabgroup = tabGroup.getAttribute("id");
let tablist = "";
Array.from(tabGroup.children).forEach(child => {
const tab = child.getAttribute("tab") || child.getAttribute("data-tab");
if (tab !== null) {
const tabID = tab.replace(/\W+/g, "-").toLowerCase();
const tabPanel = document.createElement('div');
tabPanel.id = `tab-panel-${tabgroup}-${tabID}`;
tabPanel.className = tablist === "" ? "open" : "";
tabPanel.setAttribute("role", "tabpanel");
tabPanel.setAttribute("tabindex", "0");
tabPanel.setAttribute("aria-labelledby", `tab-${tabgroup}-${tabID}`);
tabPanel.appendChild(child.cloneNode(true));
child.parentNode.replaceChild(tabPanel, child);
tablist += `<li tabindex="0" role="tab" ${tablist === "" ? "class='selected'" : ""} id="tab-${tabgroup}-${tabID}"><span>${tab}</span></li>`;
} else {
child.classList.add("tab-hidden");
}
});
const ul = document.createElement('ul');
ul.setAttribute("role", "tablist");
ul.innerHTML = `${tablist}<li role="separator" class="separator"></li>`;
tabGroup.insertBefore(ul, tabGroup.firstChild);
tabGroup.querySelectorAll('[role="tab"]').forEach(tab => {
tab.addEventListener("click", () => {
const siblings = Array.from(tab.parentNode.children);
siblings.forEach(sibling => sibling.classList.remove("selected"));
tab.classList.add("selected");
const tabPanels = Array.from(tab.parentNode.parentNode.children)
.filter(child => child.getAttribute("role") === "tabpanel");
tabPanels.forEach(panel => panel.classList.remove("open"));
const tabPanelId = tab.getAttribute("id").replace("tab", "tab-panel");
document.getElementById(tabPanelId).classList.add("open");
});
});
}
});
}
</pre>
</tabset>
</body>
</html>