Skip to content

Commit 156e609

Browse files
committed
feat: add the ability to disable Pattern Lab viewall links in the navigation
1 parent 385dbaa commit 156e609

3 files changed

Lines changed: 26 additions & 7 deletions

File tree

packages/uikit-workshop/.patternlabrc.example.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
module.exports = {
44
// buildDir: __dirname + '/www/pattern-lab',
5+
noViewAll: true, // uncomment to disable displaying viewAll links in Pattern Lab
56
};

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

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,15 @@ const SubSubList = props => {
1212
const { children, category, elem } = props;
1313
const reorderedChildren = [];
1414

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

2225
reorderedChildren.push(...viewAllItems, ...nonViewAllItems);
2326

@@ -419,6 +422,10 @@ class Nav extends BaseComponent {
419422
...props.boolean,
420423
...{ default: true },
421424
},
425+
noViewAll: {
426+
...props.boolean,
427+
...{ default: patternLab.noViewAll || false },
428+
},
422429
};
423430

424431
toggleSpecialNavPanel(e) {
@@ -542,7 +549,10 @@ class Nav extends BaseComponent {
542549

543550
{patternItems &&
544551
patternItems.map((patternItem, i) => {
545-
return (
552+
return this.noViewAll &&
553+
patternItem.patternPartial.includes('viewall') ? (
554+
''
555+
) : (
546556
<li class="pl-c-nav__item">
547557
<a
548558
href={`patterns/${patternItem.patternPath}`}

packages/uikit-workshop/webpack.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const HtmlWebpackPlugin = require('html-webpack-plugin');
99
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
1010
const selectorImporter = require('node-sass-selector-importer');
1111
const PrerenderSPAPlugin = require('prerender-spa-plugin');
12+
const webpack = require('webpack');
1213
const CopyPlugin = require('copy-webpack-plugin');
1314
const path = require('path');
1415
const argv = require('yargs').argv;
@@ -23,6 +24,8 @@ const defaultConfig = {
2324
sourceMaps: true,
2425
publicPath: './styleguide/',
2526
copy: [{ from: './src/images/**', to: 'images', flatten: true }],
27+
// noViewAll: false,
28+
noViewAll: false,
2629
};
2730

2831
module.exports = async function() {
@@ -254,6 +257,11 @@ module.exports = async function() {
254257
: [],
255258
},
256259
plugins: [
260+
new webpack.DefinePlugin({
261+
patternLab: {
262+
noViewAll: JSON.stringify(config.noViewAll),
263+
},
264+
}),
257265
new CopyPlugin(config.copy),
258266
new PrerenderSPAPlugin({
259267
// Required - The path to the webpack-outputted app to prerender.

0 commit comments

Comments
 (0)