Compare commits

..

No commits in common. "main" and "v1.02" have entirely different histories.
main ... v1.02

16 changed files with 223 additions and 400 deletions

View File

@ -1,14 +1,4 @@
# DS2-core # DS2 Core
DS2-core is a lightweight PugJS-based framework for building design systems.
The design system compiles to mostly pure HTML, SCSS and JavaScript. There are a few enhanced parts that use PHP in order to handle non-critical tasks Zip files on the fly to collect component JavaScript and SCSS. PugJS is used because it can handle some of the automation such as creating includes making components extremely modular.
## Requirements
The requirements for ds2-core are pretty light. You'll want to be able to process [PugJS](https://pugjs.org/api/getting-started.html) (formerly Jade) and [SCSS](https://sass-lang.com/documentation/) -- and that's about it.
For our own design system, we use ds2-core with [Prepros](https://prepros.io) (which you can use the Free Unlimited Trial for, but why not splurge and spend the $30USD to support the developer and skip the nags). On MacOS, you could also use [CodeKit](https://codekitapp.com/).
Alternatively, if you have pre-processor pipelines for Pug and SCSS, which you can install using npm, or any other language you decide to pull in, you can use those to compile if that ends up being easier for you. The framework isn't too picky, so long as things go into the right place.
## "Installation" ## "Installation"
@ -21,23 +11,20 @@ src/pg/core/download.php.pug | public
All other pug files should compile to from src/pg/ to a relative path of public/* All other pug files should compile to from src/pg/ to a relative path of public/*
## Running the core ## Running the core
### Callback functions functions
Callback functions can be used in
- beforeArticleLoad - called before any patterns have started to load beforeArticleLoad - called before any patterns are started to load
- success - called when loading a pattern is successful if the result is an HTTP 200 success - called when loading a pattern is successful if the result is an HTTP 200
- afterArticleLoad - called after any patterns have started to load afterArticleLoad - called after any patterns are started to load
- done - called when the ajax for any pattern is done, whether successful or not. This is a useful place to load any javascript initializations that pattern. done - called when the ajax for any pattern is done, whether successful or not. This is a useful place to load any javascript initializations that pattern.
## Creating an item ## About the content variable
The content variable in \_config.pug defines your array of patterns. It is made up of the following attributes:
## The content object
The content variable in \/src\/pg\/_config.pug defines your array of patterns. It is made up of the following attributes:
- name - the hypenated name of the pattern - name - the hypenated name of the pattern
- status - this should be one of the statuses from your status array - status - this should be one of the statuses from your status array
- display - (optional) if present this will be displayed, as is, instead of the name - display - (optional) if present this will be displayed, as is, instead of the name
@ -62,42 +49,6 @@ In your design system implementation,
This will ensure that the .pug file will get processed and the .pp file will be handled as text will get compiled, but they should display correctly and remain in sync while maintaining the minimum number of files. This will ensure that the .pug file will get processed and the .pp file will be handled as text will get compiled, but they should display correctly and remain in sync while maintaining the minimum number of files.
## Using core code with your own pattern documentation.
Using
---
Creating a new pattern
Begin by creating a folder within your strucutre to hold the pattern. Add the folder to your config file.
Generating css
You've likely created your component's css as an include file beginning with an underscore. create a second file named the same that includes any dependencies (such as breakpoints) that are required to generate your valid css.
You can now include the css in your pattern's index file.
Generating pug
Create a custom tool in prepros, give it a name such as "PP to Pug" set the input extension to .pp and the output extension to .pug and check Process Automatically . The command should be
Mac / Linux
cp {{input}} {{output}}
Windows
copy {{input}} {{output}}
Once you've added the tool, set the output to "relative path" and set the output extension to pug. For each .pp file you may have to check process automatically as it doesn't always identify the new extension.
You will now be able to include the .pp file in your pattern's index file while including the .pug file which will give a compiled version of your component's html.
---
## Troubleshooting
## Credits ## Credits
This framework includes [PrismJS](https://prismjs.com/) for code syntax highlighting. PrismJS is released under the [MIT license](https://opensource.org/licenses/MIT)> This framework includes [PrismJS](https://prismjs.com/) for code syntax highlighting. PrismJS is released under the [MIT license](https://opensource.org/licenses/MIT)>

View File

@ -191,6 +191,25 @@
}, },
"buffers": "buffers":
[ [
{
"file": "src/js/scaffolding.js",
"settings":
{
"buffer_size": 2622,
"line_ending": "Unix"
},
"undo_stack":
[
[
1,
1,
"revert",
null,
"AgAAAAAAAAAAAAAAAAAAAAAAAAA+CgAALy8gY29yZSBhbmQgcHJpc20KaW1wb3J0ICogYXMgY29yZSBmcm9tICcuL2NvcmUvX2NvcmUuanMnOwppbXBvcnQgKiBhcyBQcmlzbSBmcm9tICIuLi8uLi9ub2RlX21vZHVsZXMvcHJpc21qcy9wcmlzbSI7CmltcG9ydCAiLi4vLi4vbm9kZV9tb2R1bGVzL3ByaXNtanMvcGx1Z2lucy9saW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i0iKX1gKS5jbGFzc0xpc3QuYWRkKCJzaG93LWRlcHJlY2F0ZWQiKTsKAAAAAAAAAAA+CgAAAAAAAAAAAAA",
"AQAAAAAAAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAPC/"
]
]
}
], ],
"build_system": "", "build_system": "",
"build_system_choices": "build_system_choices":
@ -281,14 +300,12 @@
"expanded_folders": "expanded_folders":
[ [
"/Users/am/Desktop/ds2-core", "/Users/am/Desktop/ds2-core",
"/Users/am/Desktop/ds2-core/src/pg/patterns" "/Users/am/Desktop/ds2-core/src/pg/patterns",
"/Users/am/Desktop/ds2-core/src/pg/patterns/core"
], ],
"file_history": "file_history":
[ [
"/Users/am/Desktop/ds2-core/src/js/scaffolding.js",
"/Users/am/Desktop/ds2-core/src/js/core/_core.js", "/Users/am/Desktop/ds2-core/src/js/core/_core.js",
"/Users/am/Desktop/ds2-core/Readme.md",
"/Users/am/Desktop/ds2-core/src/pg/core/_colour-samples.pug",
"/Users/am/Desktop/ds2-core/src/pg/patterns/core/components/switch/index.pug", "/Users/am/Desktop/ds2-core/src/pg/patterns/core/components/switch/index.pug",
"/Users/am/Desktop/ds2-core/src/pg/patterns/core/components/sticky-note/index.pug", "/Users/am/Desktop/ds2-core/src/pg/patterns/core/components/sticky-note/index.pug",
"/Users/am/Desktop/ds2-core/src/pg/patterns/core/layouts/breakpoints/index.pug", "/Users/am/Desktop/ds2-core/src/pg/patterns/core/layouts/breakpoints/index.pug",
@ -412,7 +429,10 @@
"/Users/am/Desktop/my DS2/src/pg/patterns/components/tooltip/index.pug", "/Users/am/Desktop/my DS2/src/pg/patterns/components/tooltip/index.pug",
"/Users/am/Desktop/my DS2/src/pg/patterns/components/link/index.pug", "/Users/am/Desktop/my DS2/src/pg/patterns/components/link/index.pug",
"/Users/am/Desktop/my DS2/src/pg/patterns/components/progress-bar/index.pug", "/Users/am/Desktop/my DS2/src/pg/patterns/components/progress-bar/index.pug",
"/Users/am/Desktop/my DS2/src/pg/patterns/layouts/main-navigation/index.pug" "/Users/am/Desktop/my DS2/src/pg/patterns/layouts/main-navigation/index.pug",
"/Users/am/Desktop/my DS2/src/pg/patterns/layouts/breakpoints/index.pug",
"/Users/am/Desktop/my DS2/src/pg/patterns/visual-design/notifications/index.pug",
"/Users/am/Desktop/my DS2/src/pg/patterns/visual-design/spacing/spacing.css"
], ],
"find": "find":
{ {
@ -431,7 +451,6 @@
"case_sensitive": false, "case_sensitive": false,
"find_history": "find_history":
[ [
"oneClickSelect",
"../core/_master-pattern.pug", "../core/_master-pattern.pug",
"../core", "../core",
"hide-deprecated", "hide-deprecated",
@ -500,6 +519,38 @@
{ {
"sheets": "sheets":
[ [
{
"buffer": 0,
"file": "src/js/scaffolding.js",
"selected": true,
"semi_transient": false,
"settings":
{
"buffer_size": 2622,
"regions":
{
},
"selection":
[
[
0,
0
]
],
"settings":
{
"syntax": "Packages/JavaScript/JavaScript.sublime-syntax",
"tab_size": 4,
"translate_tabs_to_spaces": false
},
"translation.x": 0.0,
"translation.y": 365.0,
"zoom_level": 1.0
},
"stack_index": 0,
"stack_multiselect": false,
"type": "text"
}
] ]
} }
], ],

View File

@ -30,7 +30,7 @@ String.prototype.toPath = function () {
var font = { var font = {
size: 0 size: 0
}; };
var copyFallback = function copyFallback(copyInfo, attr) { var copyColourFallback = function copyColourFallback(copyInfo, attr) {
console.log("fallback"); console.log("fallback");
var textArea = document.createElement('textarea'); var textArea = document.createElement('textarea');
textArea.value = copyInfo; textArea.value = copyInfo;
@ -75,6 +75,22 @@ var showMessage = function showMessage(m, s) {
status.remove(); status.remove();
}, 1000); }, 1000);
}; };
var oneClickSelect = function oneClickSelect(e) {
var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : e.currentTarget;
// In here, "this" is the element
var range, selection;
if (window.getSelection) {
selection = window.getSelection();
range = document.createRange();
range.selectNodeContents(t);
selection.removeAllRanges();
selection.addRange(range);
} else if (document.body.createTextRange) {
range = document.body.createTextRange();
range.moveToElementText(t);
range.select();
}
};
var getURLVars = function getURLVars() { var getURLVars = function getURLVars() {
var oResult = {}; var oResult = {};
if (location.search.length > 0) { if (location.search.length > 0) {
@ -128,24 +144,8 @@ module.exports = {
} }
return ""; return "";
}, },
remove: function remove(cname) { remove: function remove(cnane) {
module.exports.cookie.set(cname, null, new Date(null)); setCookie(cname, "", -1);
}
},
oneClickSelect: function oneClickSelect(e) {
var t = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : e.currentTarget;
// In here, "this" is the element
var range, selection;
if (window.getSelection) {
selection = window.getSelection();
range = document.createRange();
range.selectNodeContents(t);
selection.removeAllRanges();
selection.addRange(range);
} else if (document.body.createTextRange) {
range = document.body.createTextRange();
range.moveToElementText(t);
range.select();
} }
}, },
colour: { colour: {
@ -156,10 +156,10 @@ module.exports = {
navigator.clipboard.writeText(c).then(function () { navigator.clipboard.writeText(c).then(function () {
showMessage("Copied ".concat(w, ".")); showMessage("Copied ".concat(w, "."));
}, function (e) { }, function (e) {
copyFallback(c, w); copyColourFallback(c, w);
}); });
} else { } else {
copyFallback(c, w); copyColourFallback(c, w);
} }
}, },
positionTooltip: function positionTooltip() { positionTooltip: function positionTooltip() {
@ -174,25 +174,9 @@ module.exports = {
}); });
} }
}, },
getCSS: function getCSS(el, prop) { // getCSS: (el, prop, b = false) {
var b = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; // return window.getComputedStyle(el, null).getPropertyValue(prop);
return window.getComputedStyle(el, null).getPropertyValue(prop); // },
},
getTabPath: function getTabPath(t) {
var url = window.location.toString();
url = url.indexOf("?") > 0 ? url.substring(0, url.indexOf("?")) : url;
url = "".concat(url, "?p=").concat(t.closest("article").getAttribute("data-path"), "#").concat(t.getAttribute("id"));
var type = "URL";
if (navigator.clipboard) {
navigator.clipboard.writeText(url).then(function () {
showMessage("Copied ".concat(type, "."));
}, function (e) {
copyFallback(url, type);
});
} else {
copyFallback(url, type);
}
},
init: function init() { init: function init() {
var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; var args = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var url = getURLVars(); var url = getURLVars();
@ -220,6 +204,11 @@ module.exports = {
var observer = new IntersectionObserver(function (articles) { var observer = new IntersectionObserver(function (articles) {
articles.forEach(function (article) { articles.forEach(function (article) {
var a = article.target; var a = article.target;
// console.log("observing: ", { id: a.getAttribute("id"), intersecting: a.isIntersecting } )
// if (article.intersectionRatio > 0) {
// console.log("Is interesecting: ", { id: article.target.getAttribute("id"), intersecting: article.isIntersecting, ratio: article.intersectionRatio } )
if (article.isIntersecting == true) { if (article.isIntersecting == true) {
var path = a.getAttribute("data-path"); var path = a.getAttribute("data-path");
path = "patterns/" + (a.getAttribute("data-core") == "true" ? "core/" + path.substring(path.lastIndexOf("/") + 1) : a.getAttribute("data-path")) + "/index.html"; path = "patterns/" + (a.getAttribute("data-core") == "true" ? "core/" + path.substring(path.lastIndexOf("/") + 1) : a.getAttribute("data-path")) + "/index.html";
@ -253,7 +242,7 @@ module.exports = {
Prism.highlightAll(); Prism.highlightAll();
a.querySelectorAll("code").forEach(function (c) { a.querySelectorAll("code").forEach(function (c) {
c.onclick = function (e) { c.onclick = function (e) {
module.exports.oneClickSelect(e); oneClickSelect(e);
}; };
}); });
module.exports.colour.positionTooltip(); module.exports.colour.positionTooltip();
@ -3174,17 +3163,13 @@ function flip(e) {
module.exports = { module.exports = {
init: function init() { init: function init() {
var p = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document; var p = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
try { p.querySelectorAll("[role='switch']").forEach(function (sw) {
p.querySelectorAll("[role='switch']").forEach(function (sw) { sw.innerHTML = "<span></span>";
sw.innerHTML = "<span></span>"; sw.setAttribute("aria-checked", "false");
sw.setAttribute("aria-checked", "false"); sw.setAttribute("tabindex", "0");
sw.setAttribute("tabindex", "0"); sw.addEventListener("click", flip, false);
sw.addEventListener("click", flip, false); sw.addEventListener("keypress", flip, false);
sw.addEventListener("keypress", flip, false); });
});
} catch (e) {
console.warn("Cannot initialise switches.", e);
}
} }
}; };
@ -3207,30 +3192,10 @@ var click = new MouseEvent('click', {
bubbles: false, bubbles: false,
cancelable: true cancelable: true
}); });
var waitForElement = function waitForElement(selector) {
return new Promise(function (resolve) {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
var observer = new MutationObserver(function (mutations) {
if (document.querySelector(selector)) {
observer.disconnect();
resolve(document.querySelector(selector));
}
});
// If you get "parameter 1 is not of type 'Node'" error, see https://stackoverflow.com/a/77855838/492336
observer.observe(document.body, {
childList: true,
subtree: true
});
});
};
function init() { function init() {
var container = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document; var p = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : document;
var spacer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; var s = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
var args = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}; p.querySelectorAll(".tab-group, tabset").forEach(function (tabGroup) {
container.querySelectorAll(".tab-group, tabset").forEach(function (tabGroup) {
if (tabGroup.querySelector("[role=tablist]") === null) { if (tabGroup.querySelector("[role=tablist]") === null) {
var tabgroup = tabGroup.getAttribute("id"); var tabgroup = tabGroup.getAttribute("id");
var tablist = ""; var tablist = "";
@ -3253,31 +3218,23 @@ function init() {
}); });
var ul = document.createElement('ul'); var ul = document.createElement('ul');
ul.setAttribute("role", "tablist"); ul.setAttribute("role", "tablist");
ul.innerHTML = spacer != true ? "".concat(tablist) : "".concat(tablist, "<li role=\"separator\" class=\"separator\"></li>"); ul.innerHTML = s != true ? "".concat(tablist) : "".concat(tablist, "<li role=\"separator\" class=\"separator\"></li>");
tabGroup.insertBefore(ul, tabGroup.firstChild); tabGroup.insertBefore(ul, tabGroup.firstChild);
tabGroup.querySelectorAll('[role="tab"]').forEach(function (tab) { tabGroup.querySelectorAll('[role="tab"]').forEach(function (tab) {
tab.addEventListener("click", function (e) { tab.addEventListener("click", function () {
if (e.altKey && typeof args.altModifier == "function") { var siblings = Array.from(tab.parentNode.children);
args.altModifier(tab); siblings.forEach(function (sibling) {
} else if (e.shiftKey && typeof args.shiftModifier == "function") { return sibling.classList.remove("selected");
args.shiftModifier(tab); });
} else if (e.metaKey && typeof args.metaModifier == "function") { tab.classList.add("selected");
args.metaModifier(tab); var tabPanels = Array.from(tab.parentNode.parentNode.children).filter(function (child) {
} else { return child.getAttribute("role") === "tabpanel";
var siblings = Array.from(tab.parentNode.children); });
siblings.forEach(function (sibling) { tabPanels.forEach(function (panel) {
return sibling.classList.remove("selected"); return panel.classList.remove("open");
}); });
tab.classList.add("selected"); var tabPanelId = tab.getAttribute("id").replace("tab", "tab-panel");
var tabPanels = Array.from(tab.parentNode.parentNode.children).filter(function (child) { document.getElementById(tabPanelId).classList.add("open");
return child.getAttribute("role") === "tabpanel";
});
tabPanels.forEach(function (panel) {
return panel.classList.remove("open");
});
var tabPanelId = tab.getAttribute("id").replace("tab", "tab-panel");
document.getElementById(tabPanelId).classList.add("open");
}
}); });
tab.addEventListener("keypress", function (e) { tab.addEventListener("keypress", function (e) {
e.preventDefault(); e.preventDefault();
@ -3287,12 +3244,6 @@ function init() {
}); });
}); });
} }
if (document.location.hash != "" && document.location.hash.substring(0, 5) == "#tab-") {
waitForElement(document.location.hash).then(function (el) {
el.scrollIntoView();
el.dispatchEvent(click);
});
}
}); });
} }
@ -3414,12 +3365,10 @@ __webpack_require__.r(__webpack_exports__);
// init c // init core
_core_core_js__WEBPACK_IMPORTED_MODULE_0__.init({ _core_core_js__WEBPACK_IMPORTED_MODULE_0__.init({
success: function success(a) { success: function success(a) {
_pg_patterns_core_tabs_tabs_js__WEBPACK_IMPORTED_MODULE_9__.init(a, true, { _pg_patterns_core_tabs_tabs_js__WEBPACK_IMPORTED_MODULE_9__.init(a);
shiftModifier: _core_core_js__WEBPACK_IMPORTED_MODULE_0__.getTabPath
});
_pg_patterns_core_switch_switch_js__WEBPACK_IMPORTED_MODULE_8__.init(a); _pg_patterns_core_switch_switch_js__WEBPACK_IMPORTED_MODULE_8__.init(a);
_pg_patterns_core_sticky_note_sticky_note_js__WEBPACK_IMPORTED_MODULE_7__.init(a); _pg_patterns_core_sticky_note_sticky_note_js__WEBPACK_IMPORTED_MODULE_7__.init(a);
}, },
@ -3439,6 +3388,7 @@ var flipInfoSwitch = function flipInfoSwitch(e) {
}); });
break; break;
case "breakpoints": case "breakpoints":
console.log("here");
_core_core_js__WEBPACK_IMPORTED_MODULE_0__.cookie.set("show-breakpoints", s.getAttribute("aria-checked"), 30, "/"); _core_core_js__WEBPACK_IMPORTED_MODULE_0__.cookie.set("show-breakpoints", s.getAttribute("aria-checked"), 30, "/");
document.querySelector("html").classList[s.getAttribute("aria-checked") == "true" ? "add" : "remove"]("show-breakpoints"); document.querySelector("html").classList[s.getAttribute("aria-checked") == "true" ? "add" : "remove"]("show-breakpoints");
break; break;

File diff suppressed because one or more lines are too long

View File

@ -287,23 +287,23 @@
<div class="tab-group" id="colors"> <div class="tab-group" id="colors">
<div data-tab="css"> <div data-tab="css">
<pre class="language-css">:root { <pre class="language-css">:root {
--colour-blue: #2e51a1; --colour-blue: #2e51a1,
--colour-blue-l: #5c7abf; --colour-blue-l: #5c7abf,
--colour-blue-xl: #b2c3ec; --colour-blue-xl: #b2c3ec,
--colour-blue-d: #133176; --colour-blue-d: #133176,
--colour-blue-xd: #031235; --colour-blue-xd: #031235,
--colour-grey: #7f7f7f; --colour-grey: #7f7f7f,
--colour-grey-l: #b2b2b2; --colour-grey-l: #b2b2b2,
--colour-grey-xl: #d8d8d8; --colour-grey-xl: #d8d8d8,
--colour-grey-xxl: #f0f0f0; --colour-grey-xxl: #f0f0f0,
--colour-white: #fff; --colour-white: #fff,
--colour-page: #fff; --colour-page: #fff,
--colour-light: #fff; --colour-light: #fff,
--colour-grey-d: #4c4c4c; --colour-grey-d: #4c4c4c,
--colour-grey-xd: #4c4c4c; --colour-grey-xd: #4c4c4c,
--colour-black: #000; --colour-black: #000,
--colour-dark: #000; --colour-dark: #000,
}</pre> }</pre>
</div> </div>
<div data-tab="scss"> <div data-tab="scss">

View File

@ -82,17 +82,13 @@ function flip(e) {
module.exports = { module.exports = {
init: (p = document) => { init: (p = document) => {
try { p.querySelectorAll("[role='switch']").forEach((sw) => {
p.querySelectorAll("[role='switch']").forEach((sw) => { sw.innerHTML = "<span></span>";
sw.innerHTML = "<span></span>"; sw.setAttribute("aria-checked", "false");
sw.setAttribute("aria-checked", "false"); sw.setAttribute("tabindex", "0");
sw.setAttribute("tabindex", "0"); sw.addEventListener("click", flip, false);
sw.addEventListener("click", flip, false); sw.addEventListener("keypress", flip, false);
sw.addEventListener("keypress", flip, false); })
})
} catch (e) {
console.warn("Cannot initialise switches.", e);
}
} }
} }
</pre> </pre>

View File

@ -2,13 +2,6 @@
<html> <html>
<head> <head>
<title>Pattern</title> <title>Pattern</title>
<script>
let u = document.location.href.substring(0, document.location.href.search(/patterns/i));
let p = document.location.pathname.substring(document.location.pathname.search(/patterns/i));
p = p.replace(/\/$|\/index\.html/i, "").substring(9);
window.location = u + "?p=" + p;
</script>
</head> </head>
<body data-prismjs-copy-timeout="1500"> <body data-prismjs-copy-timeout="1500">
<h2>What is it</h2> <h2>What is it</h2>
@ -24,14 +17,6 @@
<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>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>
<h2>How to use it</h2> <h2>How to use it</h2>
<p>The structure of the tab set is defined in html. There are two forms supported. Adding a class of <code class="inline">.tab-group</code> to the container element will work in place of the <code class="inline">tabset</code> tag, and the tab panels can be defined using either <code class="inline">tab=""</code> or <code class="inline">data-tab=""</code>. Passing an optional element to the init function will initialise tabs within that element. </p> <p>The structure of the tab set is defined in html. There are two forms supported. Adding a class of <code class="inline">.tab-group</code> to the container element will work in place of the <code class="inline">tabset</code> tag, and the tab panels can be defined using either <code class="inline">tab=""</code> or <code class="inline">data-tab=""</code>. Passing an optional element to the init function will initialise tabs within that element. </p>
<p>The tab initalize function now takes a new function parameter in the form of an third argument is an object that can take the following callbacks: </p>
<ul>
<li>altModifer (When the altKey is used)</li>
<li>shiftModifier (When the shift key is used)</li>
<li>metaModifier (When the Windows key or Apple key is used)</li>
</ul>
<p>You can use these callbacks to create a custom event to get the tab information. </p>
<p>Note: There is a new core function (core.getTabPath) that will generate the query string and url hash for use in DS2 Core. You may wish to update your scaffolding.js file to make use of this functionality. </p>
<tabset id="tabs"> <tabset id="tabs">
<pre class="language-html" tab="html"> <pre class="language-html" tab="html">
<tabset id="uniqueID"> <tabset id="uniqueID">
@ -184,31 +169,8 @@ const click = new MouseEvent('click', {
cancelable: true cancelable: true
}); });
const waitForElement = (selector) => { export function init(p = document, s = true) {
return new Promise(resolve => { p.querySelectorAll(".tab-group, tabset").forEach(tabGroup => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
observer.disconnect();
resolve(document.querySelector(selector));
}
});
// If you get "parameter 1 is not of type 'Node'" error, see https://stackoverflow.com/a/77855838/492336
observer.observe(document.body, {
childList: true,
subtree: true
});
});
}
export function init(container = document, spacer = true, args = {}) {
container.querySelectorAll(".tab-group, tabset").forEach(tabGroup => {
if (tabGroup.querySelector("[role=tablist]") === null) { if (tabGroup.querySelector("[role=tablist]") === null) {
const tabgroup = tabGroup.getAttribute("id"); const tabgroup = tabGroup.getAttribute("id");
@ -234,29 +196,21 @@ export function init(container = document, spacer = true, args = {}) {
const ul = document.createElement('ul'); const ul = document.createElement('ul');
ul.setAttribute("role", "tablist"); ul.setAttribute("role", "tablist");
ul.innerHTML = spacer != true ? `${tablist}` : `${tablist}<li role="separator" class="separator"></li>`; ul.innerHTML = s != true ? `${tablist}` : `${tablist}<li role="separator" class="separator"></li>`;
tabGroup.insertBefore(ul, tabGroup.firstChild); tabGroup.insertBefore(ul, tabGroup.firstChild);
tabGroup.querySelectorAll('[role="tab"]').forEach(tab => { tabGroup.querySelectorAll('[role="tab"]').forEach(tab => {
tab.addEventListener("click", (e) => { tab.addEventListener("click", () => {
if (e.altKey && typeof args.altModifier == "function") { const siblings = Array.from(tab.parentNode.children);
args.altModifier(tab); siblings.forEach(sibling => sibling.classList.remove("selected"));
} else if (e.shiftKey && typeof args.shiftModifier == "function") { tab.classList.add("selected");
args.shiftModifier(tab);
} else if (e.metaKey && typeof args.metaModifier == "function") {
args.metaModifier(tab);
} else {
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) const tabPanels = Array.from(tab.parentNode.parentNode.children)
.filter(child => child.getAttribute("role") === "tabpanel"); .filter(child => child.getAttribute("role") === "tabpanel");
tabPanels.forEach(panel => panel.classList.remove("open")); tabPanels.forEach(panel => panel.classList.remove("open"));
const tabPanelId = tab.getAttribute("id").replace("tab", "tab-panel"); const tabPanelId = tab.getAttribute("id").replace("tab", "tab-panel");
document.getElementById(tabPanelId).classList.add("open"); document.getElementById(tabPanelId).classList.add("open");
}
}); });
@ -268,14 +222,6 @@ export function init(container = document, spacer = true, args = {}) {
}) })
}); });
} }
if (document.location.hash != "" && document.location.hash.substring(0,5) == "#tab-") {
waitForElement(document.location.hash).then((el) => {
el.scrollIntoView();
el.dispatchEvent(click);
});
}
}); });
} }
</pre> </pre>

View File

@ -21,7 +21,7 @@ const font = {
size: 0 size: 0
} }
const copyFallback = (copyInfo, attr) => { const copyColourFallback = (copyInfo, attr) => {
console.log("fallback") console.log("fallback")
var textArea = document.createElement('textarea'); var textArea = document.createElement('textarea');
textArea.value = copyInfo; textArea.value = copyInfo;
@ -71,6 +71,22 @@ const showMessage = (m, s) => {
}, 1000); }, 1000);
} }
const oneClickSelect = (e, t = e.currentTarget) => {
// In here, "this" is the element
var range, selection;
if (window.getSelection) {
selection = window.getSelection();
range = document.createRange();
range.selectNodeContents(t);
selection.removeAllRanges();
selection.addRange(range);
} else if (document.body.createTextRange) {
range = document.body.createTextRange();
range.moveToElementText(t);
range.select();
}
}
const getURLVars = () => { const getURLVars = () => {
var oResult = {}; var oResult = {};
if (location.search.length > 0) { if (location.search.length > 0) {
@ -129,26 +145,12 @@ module.exports = {
} }
return ""; return "";
}, },
remove: (cname) => { remove: (cnane) => {
module.exports.cookie.set(cname, null, new Date(null)); setCookie(cname, "", -1);
}, },
}, },
oneClickSelect: (e, t = e.currentTarget) => {
// In here, "this" is the element
var range, selection;
if (window.getSelection) {
selection = window.getSelection();
range = document.createRange();
range.selectNodeContents(t);
selection.removeAllRanges();
selection.addRange(range);
} else if (document.body.createTextRange) {
range = document.body.createTextRange();
range.moveToElementText(t);
range.select();
}
},
colour: { colour: {
copy: (w, t) => { copy: (w, t) => {
let c = t.parentNode.getAttribute("data-" + (w=="var" ? "token" : w)); let c = t.parentNode.getAttribute("data-" + (w=="var" ? "token" : w));
c = w == "var" ? `var(${c})` : c; c = w == "var" ? `var(${c})` : c;
@ -157,10 +159,10 @@ module.exports = {
navigator.clipboard.writeText(c).then(function() { navigator.clipboard.writeText(c).then(function() {
showMessage(`Copied ${w}.`); showMessage(`Copied ${w}.`);
}, function(e) { }, function(e) {
copyFallback(c,w); copyColourFallback(c,w);
}); });
} else { } else {
copyFallback(c, w); copyColourFallback(c, w);
} }
}, },
@ -176,26 +178,9 @@ module.exports = {
}) })
} }
}, },
getCSS: (el, prop, b = false) => { // getCSS: (el, prop, b = false) {
return window.getComputedStyle(el, null).getPropertyValue(prop); // return window.getComputedStyle(el, null).getPropertyValue(prop);
}, // },
getTabPath: (t) => {
let url = window.location.toString();
url = url.indexOf("?") > 0 ? url.substring(0,url.indexOf("?")) : url;
url = `${url}?p=${t.closest("article").getAttribute("data-path")}#${t.getAttribute("id")}`
let type = "URL";
if (navigator.clipboard) {
navigator.clipboard.writeText(url).then(function() {
showMessage(`Copied ${type}.`);
}, function(e) {
copyFallback(url,type);
});
} else {
copyFallback(url, type);
}
},
init: (args = {}) => { init: (args = {}) => {
const url = getURLVars(); const url = getURLVars();
font.size = parseFloat(getComputedStyle(document.documentElement).fontSize.replace("px","")); font.size = parseFloat(getComputedStyle(document.documentElement).fontSize.replace("px",""));
@ -226,6 +211,10 @@ module.exports = {
articles.forEach(article => { articles.forEach(article => {
let a = article.target; let a = article.target;
// console.log("observing: ", { id: a.getAttribute("id"), intersecting: a.isIntersecting } )
// if (article.intersectionRatio > 0) {
// console.log("Is interesecting: ", { id: article.target.getAttribute("id"), intersecting: article.isIntersecting, ratio: article.intersectionRatio } )
if (article.isIntersecting == true) { if (article.isIntersecting == true) {
let path = a.getAttribute("data-path"); let path = a.getAttribute("data-path");
path = "patterns/" + path = "patterns/" +
@ -266,7 +255,7 @@ module.exports = {
a.querySelectorAll("code").forEach((c)=> { a.querySelectorAll("code").forEach((c)=> {
c.onclick = (e) => { c.onclick = (e) => {
module.exports.oneClickSelect(e); oneClickSelect(e);
} }
}) })

View File

@ -12,12 +12,10 @@ import * as stickynote from "../pg/patterns/core/sticky-note/_sticky-note.js";
import * as swtch from "../pg/patterns/core/switch/_switch.js"; import * as swtch from "../pg/patterns/core/switch/_switch.js";
import * as tabs from "../pg/patterns/core/tabs/_tabs.js"; import * as tabs from "../pg/patterns/core/tabs/_tabs.js";
// init c // init core
core.init({ core.init({
success: (a) => { success: (a) => {
tabs.init(a, true, { tabs.init(a);
shiftModifier: core.getTabPath,
});
swtch.init(a); swtch.init(a);
stickynote.init(a); stickynote.init(a);
}, },
@ -26,7 +24,6 @@ core.init({
} }
}); });
// deprecated switch handler // deprecated switch handler
const flipInfoSwitch = (e, s = e.currentTarget) => { const flipInfoSwitch = (e, s = e.currentTarget) => {
@ -40,10 +37,12 @@ const flipInfoSwitch = (e, s = e.currentTarget) => {
break; break;
case "breakpoints" : case "breakpoints" :
console.log("here")
core.cookie.set("show-breakpoints", s.getAttribute("aria-checked"), 30, "/"); core.cookie.set("show-breakpoints", s.getAttribute("aria-checked"), 30, "/");
document.querySelector("html").classList[( s.getAttribute("aria-checked") == "true" ? "add" : "remove" )]("show-breakpoints"); document.querySelector("html").classList[( s.getAttribute("aria-checked") == "true" ? "add" : "remove" )]("show-breakpoints");
break; break;
} }
} }
// create a pure JS mouse click event // create a pure JS mouse click event

View File

@ -128,12 +128,12 @@
- function generateCSS(c, p) { - function generateCSS(c, p) {
- let o = ""; - let o = "";
- for (let i = 0; i < c.length; i++) { - for (let i = 0; i < c.length; i++) {
- o += `\n\t--${p}-${c[i].name.toLowerCase()}: ${ color(c[i].color, "hex").toLowerCase() };\n`; - o += `\n\t--${p}-${c[i].name.toLowerCase()}: ${ color(c[i].color, "hex").toLowerCase() },\n`;
- for (let ii = 0; ii < c[i].grad.l.length; ii++) { - for (let ii = 0; ii < c[i].grad.l.length; ii++) {
- o += `\t--${p}-${c[i].grad.l[ii].n.toLowerCase()}: ${ color(c[i].grad.l[ii].c, "hex").toLowerCase() };\n`; - o += `\t--${p}-${c[i].grad.l[ii].n.toLowerCase()}: ${ color(c[i].grad.l[ii].c, "hex").toLowerCase() },\n`;
- } - }
- for (let ii = 0; ii < c[i].grad.d.length; ii++) { - for (let ii = 0; ii < c[i].grad.d.length; ii++) {
- o += `\t--${p}-${c[i].grad.d[ii].n.toLowerCase()}: ${ color(c[i].grad.d[ii].c, "hex").toLowerCase() };\n`; - o += `\t--${p}-${c[i].grad.d[ii].n.toLowerCase()}: ${ color(c[i].grad.d[ii].c, "hex").toLowerCase() },\n`;
- } - }
- } - }
- return o; - return o;

View File

@ -37,11 +37,6 @@ html
head head
title Pattern title Pattern
script.
let u = document.location.href.substring(0, document.location.href.search(/patterns/i));
let p = document.location.pathname.substring(document.location.pathname.search(/patterns/i));
p = p.replace(/\/$|\/index\.html/i, "").substring(9);
window.location = u + "?p=" + p;
body(data-assetpath= assetpath data-prismjs-copy-timeout="1500") body(data-assetpath= assetpath data-prismjs-copy-timeout="1500")

View File

@ -75,7 +75,7 @@ include _colour-samples
"lighter lighter lighter darker darker darker" "lighter lighter lighter darker darker darker"
"notes notes notes notes notes notes"; "notes notes notes notes notes notes";
grid-template-columns: repeat(6, 1fr); grid-template-columns: repeat(6, 1fr);
grid-template-rows: repeat(2, 1.5rem) repeat(4, max-content); // 3rem repeat(2, 2rem) 1.5rem repeat(3, max-content); grid-template-rows: repeat(2, 1.5rem) 10rem repeat(3, max-content); // 3rem repeat(2, 2rem) 1.5rem repeat(3, max-content);
padding: 1rem; padding: 1rem;
width: 20rem; width: 20rem;
max-width: 318px; max-width: 318px;
@ -115,7 +115,7 @@ include _colour-samples
display: grid; display: grid;
gap: .5rem; gap: .5rem;
grid-template-columns: repeat(3, 1fr); grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, max-content); grid-template-rows: 2.5rem repeat(2, max-content);
.result { .result {
align-items: center; align-items: center;
border-radius: .5rem; border-radius: .5rem;
@ -188,7 +188,7 @@ include _colour-samples
padding: .5rem; padding: .5rem;
width: 20rem; width: 20rem;
max-width: 318px; max-width: 318px;
height: max-contents; height: 10.5rem;
display: grid; display: grid;
gap: .5rem; gap: .5rem;
@ -231,7 +231,6 @@ include _colour-samples
display: block; display: block;
width: 100%; width: 100%;
place-self: stretch; place-self: stretch;
text-align: center;
span { span {
border: none; border: none;
font-size: .9rem; font-size: .9rem;

View File

@ -15,16 +15,12 @@ function flip(e) {
module.exports = { module.exports = {
init: (p = document) => { init: (p = document) => {
try { p.querySelectorAll("[role='switch']").forEach((sw) => {
p.querySelectorAll("[role='switch']").forEach((sw) => { sw.innerHTML = "<span></span>";
sw.innerHTML = "<span></span>"; sw.setAttribute("aria-checked", "false");
sw.setAttribute("aria-checked", "false"); sw.setAttribute("tabindex", "0");
sw.setAttribute("tabindex", "0"); sw.addEventListener("click", flip, false);
sw.addEventListener("click", flip, false); sw.addEventListener("keypress", flip, false);
sw.addEventListener("keypress", flip, false); })
})
} catch (e) {
console.warn("Cannot initialise switches.", e);
}
} }
} }

View File

@ -9,31 +9,8 @@ const click = new MouseEvent('click', {
cancelable: true cancelable: true
}); });
const waitForElement = (selector) => { export function init(p = document, s = true) {
return new Promise(resolve => { p.querySelectorAll(".tab-group, tabset").forEach(tabGroup => {
if (document.querySelector(selector)) {
return resolve(document.querySelector(selector));
}
const observer = new MutationObserver(mutations => {
if (document.querySelector(selector)) {
observer.disconnect();
resolve(document.querySelector(selector));
}
});
// If you get "parameter 1 is not of type 'Node'" error, see https://stackoverflow.com/a/77855838/492336
observer.observe(document.body, {
childList: true,
subtree: true
});
});
}
export function init(container = document, spacer = true, args = {}) {
container.querySelectorAll(".tab-group, tabset").forEach(tabGroup => {
if (tabGroup.querySelector("[role=tablist]") === null) { if (tabGroup.querySelector("[role=tablist]") === null) {
const tabgroup = tabGroup.getAttribute("id"); const tabgroup = tabGroup.getAttribute("id");
@ -59,29 +36,21 @@ export function init(container = document, spacer = true, args = {}) {
const ul = document.createElement('ul'); const ul = document.createElement('ul');
ul.setAttribute("role", "tablist"); ul.setAttribute("role", "tablist");
ul.innerHTML = spacer != true ? `${tablist}` : `${tablist}<li role="separator" class="separator"></li>`; ul.innerHTML = s != true ? `${tablist}` : `${tablist}<li role="separator" class="separator"></li>`;
tabGroup.insertBefore(ul, tabGroup.firstChild); tabGroup.insertBefore(ul, tabGroup.firstChild);
tabGroup.querySelectorAll('[role="tab"]').forEach(tab => { tabGroup.querySelectorAll('[role="tab"]').forEach(tab => {
tab.addEventListener("click", (e) => { tab.addEventListener("click", () => {
if (e.altKey && typeof args.altModifier == "function") { const siblings = Array.from(tab.parentNode.children);
args.altModifier(tab); siblings.forEach(sibling => sibling.classList.remove("selected"));
} else if (e.shiftKey && typeof args.shiftModifier == "function") { tab.classList.add("selected");
args.shiftModifier(tab);
} else if (e.metaKey && typeof args.metaModifier == "function") {
args.metaModifier(tab);
} else {
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) const tabPanels = Array.from(tab.parentNode.parentNode.children)
.filter(child => child.getAttribute("role") === "tabpanel"); .filter(child => child.getAttribute("role") === "tabpanel");
tabPanels.forEach(panel => panel.classList.remove("open")); tabPanels.forEach(panel => panel.classList.remove("open"));
const tabPanelId = tab.getAttribute("id").replace("tab", "tab-panel"); const tabPanelId = tab.getAttribute("id").replace("tab", "tab-panel");
document.getElementById(tabPanelId).classList.add("open"); document.getElementById(tabPanelId).classList.add("open");
}
}); });
@ -93,13 +62,5 @@ export function init(container = document, spacer = true, args = {}) {
}) })
}); });
} }
if (document.location.hash != "" && document.location.hash.substring(0,5) == "#tab-") {
waitForElement(document.location.hash).then((el) => {
el.scrollIntoView();
el.dispatchEvent(click);
});
}
}); });
} }

View File

@ -22,15 +22,6 @@ block content
+h(2) +h(2)
p The structure of the tab set is defined in html. There are two forms supported. Adding a class of #[code.inline .tab-group] to the container element will work in place of the #[code.inline tabset] tag, and the tab panels can be defined using either #[code.inline tab=""] or #[code.inline data-tab=""]. Passing an optional element to the init function will initialise tabs within that element. p The structure of the tab set is defined in html. There are two forms supported. Adding a class of #[code.inline .tab-group] to the container element will work in place of the #[code.inline tabset] tag, and the tab panels can be defined using either #[code.inline tab=""] or #[code.inline data-tab=""]. Passing an optional element to the init function will initialise tabs within that element.
p The tab initalize function now takes a new function parameter in the form of an third argument is an object that can take the following callbacks:
ul
li altModifer (When the altKey is used)
li shiftModifier (When the shift key is used)
li metaModifier (When the Windows key or Apple key is used)
p You can use these callbacks to create a custom event to get the tab information.
p Note: There is a new core function (core.getTabPath) that will generate the query string and url hash for use in DS2 Core. You may wish to update your scaffolding.js file to make use of this functionality.
tabset#tabs tabset#tabs
pre.language-html(tab="html") pre.language-html(tab="html")

View File

@ -74,7 +74,7 @@
"lighter lighter lighter darker darker darker" "lighter lighter lighter darker darker darker"
"notes notes notes notes notes notes"; "notes notes notes notes notes notes";
grid-template-columns: repeat(6, 1fr); grid-template-columns: repeat(6, 1fr);
grid-template-rows: repeat(2, 1.5rem) repeat(4, max-content); // 3rem repeat(2, 2rem) 1.5rem repeat(3, max-content); grid-template-rows: repeat(2, 1.5rem) 10rem repeat(3, max-content); // 3rem repeat(2, 2rem) 1.5rem repeat(3, max-content);
padding: 1rem; padding: 1rem;
width: 20rem; width: 20rem;
max-width: 318px; max-width: 318px;
@ -114,7 +114,7 @@
display: grid; display: grid;
gap: .5rem; gap: .5rem;
grid-template-columns: repeat(3, 1fr); grid-template-columns: repeat(3, 1fr);
grid-template-rows: repeat(3, max-content); grid-template-rows: 2.5rem repeat(2, max-content);
.result { .result {
align-items: center; align-items: center;
border-radius: .5rem; border-radius: .5rem;
@ -187,7 +187,7 @@
padding: .5rem; padding: .5rem;
width: 20rem; width: 20rem;
max-width: 318px; max-width: 318px;
height: max-contents; height: 10.5rem;
display: grid; display: grid;
gap: .5rem; gap: .5rem;
@ -230,7 +230,6 @@
display: block; display: block;
width: 100%; width: 100%;
place-self: stretch; place-self: stretch;
text-align: center;
span { span {
border: none; border: none;
font-size: .9rem; font-size: .9rem;