Skip to content

Commit 2dc87bd

Browse files
Merge pull request #1034 from sghoweri/feature/no-viewall-links
Feature: Add The Ability To Hide Viewall Links
2 parents b78b3b4 + 6dbbd6a commit 2dc87bd

File tree

13 files changed

+229
-103
lines changed

13 files changed

+229
-103
lines changed

packages/development-edition-engine-handlebars/patternlab-config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@
7878
"theme": {
7979
"color": "dark",
8080
"density": "compact",
81-
"layout": "horizontal"
81+
"layout": "horizontal",
82+
"noViewAll": false
8283
},
8384
"uikits": [
8485
{
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module.exports = {
2-
buildDir: __dirname + '/public',
3-
wwwDir: __dirname + '/public/',
4-
publicPath: '/public/styleguide/',
2+
// target the UIKit installed / symlinked under node_modules
3+
buildDir: __dirname + '/node_modules/@pattern-lab/uikit-workshop/dist',
4+
// noViewAll: true,
55
};

packages/edition-twig/package-lock.json

Lines changed: 51 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/edition-twig/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
"main": "patternlab-config.json",
1515
"scripts": {
16-
"build:uikit": "npm run build --prefix node_modules/@pattern-lab/uikit-workshop -- --patternlabrc $INIT_CWD/.patternlabrc.js",
16+
"build:uikit": "cross-env-shell PL_CONFIG_PATH='${INIT_CWD}/.patternlabrc.js' npm run build --prefix node_modules/@pattern-lab/uikit-workshop -- --patternlabrc '$PL_CONFIG_PATH'",
1717
"build": "patternlab build --config ./patternlab-config.json",
1818
"help": "patternlab --help",
1919
"install": "patternlab install --config ./patternlab-config.json",

packages/edition-twig/patternlab-config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@
147147
"theme": {
148148
"color": "light",
149149
"density": "compact",
150-
"layout": "horizontal"
150+
"layout": "horizontal",
151+
"noViewAll": false
151152
},
152153
"uikits": [
153154
{

packages/uikit-workshop/build-tools.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ patternlab.build({
1212

1313
webpackServer.serve(
1414
patternlab,
15+
configFilePath,
1516
path.resolve(process.cwd(), config.paths.public.root)
1617
);

packages/uikit-workshop/build/webpack-server.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ const portfinder = require('portfinder');
1212

1313
const fileHashes = {};
1414

15-
async function serve(patternlab, buildDir = 'public') {
15+
async function serve(patternlab, configPath, buildDir = 'public') {
1616
// @todo: move these configs + make customizable?
1717
const root = path.resolve(__dirname, `${buildDir}`);
1818
const preferredPort = 3000;
1919
portfinder.basePort = preferredPort;
2020

2121
const webpackConfigs = await webpackConfig({
22-
watch: false,
22+
watch: true,
2323
prod: false,
2424
buildDir: root,
2525
rootDir: process.cwd(),
@@ -37,6 +37,24 @@ async function serve(patternlab, buildDir = 'public') {
3737

3838
// customize bs reload behavior based on the type of asset that's changed
3939
const filesToWatch = [
40+
{
41+
match: [`${process.cwd()}/patternlab-config.json`],
42+
fn: async function(event, filePath) {
43+
// when the main PL config changes, clear Node's cache (so the JSON config is re-read) and trigger another PL build
44+
// this allows config changes to show up without restarting the build!
45+
Object.keys(require.cache).forEach(function(key) {
46+
delete require.cache[key];
47+
});
48+
49+
const config = require(configPath);
50+
const pl = require('@pattern-lab/core')(config);
51+
52+
pl.build({
53+
watch: false,
54+
cleanPublic: true,
55+
});
56+
},
57+
},
4058
`${root}/**/*.css`,
4159
`${root}/**/*.js`,
4260
{
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export const getParents = (elem, selector) => {
2+
// Element.matches() polyfill
3+
if (!Element.prototype.matches) {
4+
Element.prototype.matches =
5+
Element.prototype.matchesSelector ||
6+
Element.prototype.mozMatchesSelector ||
7+
Element.prototype.msMatchesSelector ||
8+
Element.prototype.oMatchesSelector ||
9+
Element.prototype.webkitMatchesSelector ||
10+
function(s) {
11+
var matches = (this.document || this.ownerDocument).querySelectorAll(s),
12+
i = matches.length;
13+
while (--i >= 0 && matches.item(i) !== this) {}
14+
return i > -1;
15+
};
16+
}
17+
18+
// Set up a parent array
19+
var parents = [];
20+
21+
// Push each parent element to the array
22+
for (; elem && elem !== document; elem = elem.parentNode) {
23+
if (selector) {
24+
if (elem.matches(selector)) {
25+
parents.push(elem);
26+
}
27+
continue;
28+
}
29+
parents.push(elem);
30+
}
31+
32+
// Return our parent array
33+
return parents;
34+
};

packages/uikit-workshop/src/scripts/components/pl-nav/pl-nav.js

Lines changed: 44 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { h } from 'preact';
44

55
const classNames = require('classnames');
66

7+
import { getParents } from './get-parents';
78
import { store } from '../../store.js'; // redux store
89
import { BaseComponent } from '../base-component.js';
910
import Mousetrap from 'mousetrap';
@@ -13,12 +14,15 @@ const SubSubList = props => {
1314
const { children, category, elem } = props;
1415
const reorderedChildren = [];
1516

16-
const nonViewAllItems = children.filter(
17-
item =>
18-
item.patternName !== 'View All' && !item.patternName.includes(' Docs')
19-
);
20-
// const nonViewAllItems = children.filter((item => (item.patternName !== 'View All')));
21-
const viewAllItems = children.filter(item => item.patternName === 'View All');
17+
const nonViewAllItems = elem.noViewAll
18+
? children.filter(item => item.patternName !== 'View All')
19+
: children.filter(
20+
item =>
21+
item.patternName !== 'View All' && !item.patternName.includes(' Docs')
22+
);
23+
const viewAllItems = elem.noViewAll
24+
? []
25+
: children.filter(item => item.patternName === 'View All');
2226

2327
reorderedChildren.push(...viewAllItems, ...nonViewAllItems);
2428

@@ -227,16 +231,12 @@ class Nav extends BaseComponent {
227231
this.layoutMode = state.app.layoutMode || '';
228232
}
229233

230-
if (this.currentPattern !== state.app.currentPattern) {
231-
if (
232-
state.app.currentPattern !== '' &&
233-
this.currentPattern !== state.app.currentPattern &&
234-
this._hasInitiallyRendered === true
235-
) {
236-
this.handleURLChange(); // so the nav logic is always correct (ex. layout changes)
237-
}
238-
234+
if (
235+
state.app.currentPattern &&
236+
this.currentPattern !== state.app.currentPattern
237+
) {
239238
this.currentPattern = state.app.currentPattern;
239+
this.handleURLChange(); // so the nav logic is always correct (ex. layout changes)
240240
}
241241
}
242242

@@ -314,70 +314,35 @@ class Nav extends BaseComponent {
314314
}
315315

316316
handleURLChange() {
317-
const shouldAutoOpenNav = true;
318-
319317
const currentPattern = this.currentPattern;
320-
const activeLink = document.querySelector(
318+
this.activeLink = document.querySelector(
321319
`[data-patternpartial="${currentPattern}"]`
322320
);
323-
const self = this;
324321

325322
if (this.previousActiveLinks) {
326-
this.previousActiveLinks.forEach(function(link, index) {
327-
self.previousActiveLinks[index].classList.remove('pl-is-active');
323+
this.previousActiveLinks.forEach((link, index) => {
324+
this.previousActiveLinks[index].classList.remove('pl-is-active');
328325
});
329326
}
330327
this.previousActiveLinks = [];
331328

332-
if (activeLink) {
333-
activeLink.classList.add('pl-is-active');
334-
this.previousActiveLinks.push(activeLink);
335-
336-
if (
337-
activeLink.parentNode.classList.contains(
338-
'pl-c-nav__link--overview-wrapper'
339-
)
340-
) {
341-
activeLink.parentNode.classList.add('pl-is-active');
342-
this.previousActiveLinks.push(activeLink.parentNode);
343-
}
329+
if (this.activeLink) {
330+
const triggers = [this.activeLink];
331+
const panels = Array.from(
332+
getParents(this.activeLink, '.pl-js-acc-panel')
333+
);
344334

345-
const parentDropdown = activeLink.closest('.pl-js-acc-panel');
346-
let parentDropdownTrigger;
347-
348-
if (parentDropdown) {
349-
if (parentDropdown.previousSibling) {
350-
parentDropdownTrigger = parentDropdown.previousSibling;
351-
352-
if (
353-
parentDropdown.previousSibling.classList.contains(
354-
'pl-c-nav__link--overview-wrapper'
355-
) &&
356-
shouldAutoOpenNav
357-
) {
358-
parentDropdown.previousSibling.classList.add('pl-is-active');
359-
this.previousActiveLinks.push(parentDropdown.previousSibling);
360-
parentDropdownTrigger = parentDropdown.previousSibling.querySelector(
361-
'.pl-js-acc-handle'
362-
);
363-
}
364-
365-
const grandparentDropdown = parentDropdown.closest(
366-
'.pl-c-nav__sublist--dropdown'
367-
);
368-
const grandparentDropdownTrigger =
369-
grandparentDropdown.previousSibling;
370-
371-
if (grandparentDropdownTrigger && shouldAutoOpenNav) {
372-
if (shouldAutoOpenNav) {
373-
grandparentDropdownTrigger.classList.add('pl-is-active');
374-
}
375-
this.previousActiveLinks.push(grandparentDropdownTrigger);
376-
}
335+
panels.forEach(panel => {
336+
const panelTrigger = panel.previousSibling;
337+
if (panelTrigger) {
338+
triggers.push(panelTrigger);
377339
}
378-
}
379-
} else {
380-
this.cleanupActiveNav();
340+
});
341+
342+
triggers.forEach(trigger => {
343+
trigger.classList.add('pl-is-active');
344+
this.previousActiveLinks.push(trigger);
345+
});
381346
}
382347
}
383348

@@ -392,6 +357,10 @@ class Nav extends BaseComponent {
392357
...props.boolean,
393358
...{ default: true },
394359
},
360+
noViewAll: {
361+
...props.boolean,
362+
...{ default: window.config?.theme?.noViewAll || false },
363+
},
395364
};
396365

397366
toggleSpecialNavPanel(e) {
@@ -409,7 +378,9 @@ class Nav extends BaseComponent {
409378
this._hasInitiallyRendered = true;
410379
}
411380

412-
this.handleURLChange();
381+
if (!this.activeLink) {
382+
this.handleURLChange();
383+
}
413384

414385
if (this.layoutMode !== 'vertical' && window.innerWidth > 670) {
415386
this.cleanupActiveNav(true);
@@ -436,7 +407,6 @@ class Nav extends BaseComponent {
436407
>
437408
{item.patternTypeUC}
438409
</ButtonTitle>
439-
440410
<ol
441411
id={item.patternSubtypeUC}
442412
className={`pl-c-nav__sublist pl-c-nav__sublist--dropdown pl-js-acc-panel`}
@@ -454,7 +424,10 @@ class Nav extends BaseComponent {
454424

455425
{patternItems &&
456426
patternItems.map((patternItem, i) => {
457-
return (
427+
return this.noViewAll &&
428+
patternItem.patternPartial.includes('viewall') ? (
429+
''
430+
) : (
458431
<li class="pl-c-nav__item">
459432
<a
460433
href={`patterns/${patternItem.patternPath}`}

packages/uikit-workshop/src/scripts/components/pl-nav/pl-nav.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ pl-nav {
199199
width: 100%;
200200
}
201201

202-
&:not(.pl-c-nav__link--title).pl-is-active {
202+
&:not(.pl-c-nav__link--title):not(.pl-c-nav__link--dropdown).pl-is-active {
203203
box-shadow: inset 4px 0 0 #6c79d9;
204204

205205
// move the "active" border style to the bottom on ONLY the top level links (ex. "All")

0 commit comments

Comments
 (0)