Skip to content

Commit

Permalink
#28
Browse files Browse the repository at this point in the history
  • Loading branch information
spelkey-ucd committed Aug 30, 2021
1 parent 6c3c452 commit 2590619
Show file tree
Hide file tree
Showing 18 changed files with 501 additions and 88 deletions.
9 changes: 6 additions & 3 deletions docs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ const jsdoc2md = require('jsdoc-to-markdown');
const path = require('path');
const fs = require('fs');

const ELE_ROOT = path.join(__dirname, 'elements', 'brand');
const ELE_ROOTS = [
path.join(__dirname, 'elements', 'brand'),
path.join(__dirname, 'elements', 'ucdlib')
];
const DOC_ROOT = path.join(__dirname, 'test-app', 'pages');

console.log('Generating docs for:');
(async function() {
ELE_ROOTS.forEach(async function(ELE_ROOT) {
let elements = fs.readdirSync(ELE_ROOT);
for( let element of elements ) {
if( !fs.statSync(path.join(ELE_ROOT, element)).isDirectory() ) continue;
Expand All @@ -19,4 +22,4 @@ console.log('Generating docs for:');
"heading-depth" : 3});
fs.writeFileSync(path.join(DOC_ROOT, element+'.md'), md);
}
})();
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { LitElement, html } from 'lit';
import {render, styles} from "./ucd-theme-primary-nav.tpl.js";
import { styleMap } from 'lit/directives/style-map.js';
import { classMap } from 'lit/directives/class-map.js';
import { ifDefined } from 'lit/directives/if-defined.js';

import { Mixin, MutationObserverElement, BreakPoints } from "../../utils/index.js";

Expand Down Expand Up @@ -357,7 +358,7 @@ export default class UcdThemePrimaryNav extends Mixin(LitElement)
class=${classMap(this._makeLiClassMap(navItem, depth))}>
<div class="submenu-toggle__wrapper ${depth === 0 ? `${this._classPrefix}__top-link` : ''}">
<a
href=${navItem.href}
href=${ifDefined(navItem.href ? navItem.href : null)}
tabindex=${this._setTabIndex(depth)}
@focus=${this._onItemFocus}>
${navItem.linkText}<span class="${this._classPrefix}__submenu-indicator"></span>
Expand Down
1 change: 1 addition & 0 deletions elements/ucdlib/ucdlib-icon/ucdlib-icon.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ export default class UcdlibIcon extends LitElement {
* @method _getIconset
* @description Return the specified ucdlib-iconset element from the head
* @returns {Element}
* @private
*/
_getIconset(){
return document.head.querySelector(`ucdlib-iconset[name=${this._iconsetName}]`);
Expand Down
16 changes: 13 additions & 3 deletions elements/ucdlib/ucdlib-iconset/ucdlib-iconset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ import { LitElement } from 'lit';
import { Mixin, MutationObserverElement, MainDomElement} from "../../utils";

/**
* @class UCdlibIconset
* @class UcdlibIconset
* @classdesc Component for creating svg iconsets to be consumed by the 'icon' attribute of ucdlib-icon
*
* @property {String} name - Name of the icon set. Usage: <ucdlib-icon icon="{thisProperty}:{icon}"></ucdlib-icon>
* @property {Number} size - The size of an individual icon. Note that icons must be square.
* @example
* <ucdlib-iconset name="arrows">
<svg>
<defs>
<g id="back"><path d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"></path></g>
<g id="downward"><path d="M20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8 8-8z"></path></g>
</defs>
</svg>
</ucdlib-iconset>
*/
export default class UcdlibIconset extends Mixin(LitElement)
.with(MutationObserverElement, MainDomElement) {
Expand Down Expand Up @@ -47,7 +56,7 @@ export default class UcdlibIconset extends Mixin(LitElement)
* @description Adds icon to ucdlib-icon element from iconset
* @param {Element} element - A ucdlib-icon element
* @param {String} iconName - The icon identifier
* @returns
* @returns {Boolean}
*/
applyIcon(element, iconName){
this.removeIcon(element);
Expand All @@ -57,7 +66,7 @@ export default class UcdlibIconset extends Mixin(LitElement)
eleRoot.insertBefore(svg, eleRoot.childNodes[0]);
return element._svgIcon = svg;
}
return null;
return null;
}

/**
Expand Down Expand Up @@ -130,6 +139,7 @@ export default class UcdlibIconset extends Mixin(LitElement)
/**
* @method _updateIconMap
* @description Sets the _iconMap property with object: {icon_id: icon}
* @private
*/
_updateIconMap(){
let iconMap = {};
Expand Down
12 changes: 7 additions & 5 deletions elements/ucdlib/ucdlib-pages/ucdlib-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ import {Mixin, MutationObserverElement} from '../../utils/index.js';
* @class UcdlibPages
* @description similar to the old iron-pages element, allows you to control which element is visible
* based on child index or tag attribute
* @property {String} selected - Denotes which child is currently displayed.
* If numeric, refers to index of child. Else, refers to child id.
* If attrForSelected is used, refers to the value of that attribute instead of id.
* @property {String} attrForSelected - Use a custom attribute instead of id for matching 'selected'
* @property {String} selectedAttribute - Will assign attribute to selected child.
*
* <ucdlib-pages selected="page2" attr-for-selected="id">
* <div id="page1">Test 1</div>
Expand All @@ -30,7 +35,6 @@ export default class UcdlibPages extends Mixin(LitElement)

constructor() {
super();
// this.render = render.bind(this);
}

/**
Expand All @@ -52,10 +56,8 @@ export default class UcdlibPages extends Mixin(LitElement)
/**
* @method _onChildListMutation
* @description called when children change via MutationObserverElement
*
* @param {ElementList} children
*/
_onChildListMutation(children) {
_onChildListMutation() {
this._onChange();
}

Expand All @@ -69,7 +71,7 @@ export default class UcdlibPages extends Mixin(LitElement)

// find what the selected attribute is
if( this.selected !== undefined || this.selected !== null ) {
if( typeof this.selected === 'string' && this.selected.match(/\d+/) ) {
if( typeof this.selected === 'string' && /^\d+$/.test(this.selected) ) {
selected = parseInt(this.selected);
} else {
selected = this.selected;
Expand Down
12 changes: 10 additions & 2 deletions test-app/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
import "./ucdlib-theme-test-app.js";

// PAGES
// IMPORT APP PAGES HERE

// guides
import "./pages/page-brand-colors";

// brand components
import "./pages/page-ucd-theme-primary-nav.js";
import "./pages/page-ucd-theme-pagination.js";
import "./pages/page-ucd-theme-quick-links";
import "./pages/page-ucd-theme-header";
import "./pages/page-ucd-theme-search-form";
import "./pages/page-ucd-theme-search-popup";

// ucdlib components
import "./pages/page-ucdlib-icon";
import "./pages/page-brand-colors";
import "./pages/page-ucdlib-iconset";
import "./pages/page-ucdlib-pages";
43 changes: 2 additions & 41 deletions test-app/pages/page-ucdlib-icon.tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,51 +13,12 @@ export function styles() {
export function render() {
return html`
${this.pageTitle("UC Davis Library Icons")}
<p>Icons can be inserted into a site by using a combination of three custom elements:
<ul>
<li><code>ucdlib-icon</code> displays the actual icon</li>
<li><code>ucdlib-icons</code> loads the standard UC Davis Library iconset into your site</li>
<li><code>ucdlib-iconset</code> allows you to create a custom svg iconset for your site.</li>
</ul>
</p>
${this.pageTitle("Inserting an Icon")}
<p>The <code>ucdlib-icon</code> element display brand icons.</p>
<h2>Using the default icon set</h2>
TODO!
<h2>Defining a custom set</h2>
<p>
If your site needs icons beyond the standard set, create a custom set by placing your icons inside svg <code>g</code> tags.
Each group should have an id that corresponds to the name of the icon.
</p>
${this.examplePanel(html`
<ucdlib-iconset name="arrows">
<svg>
<defs>
<g id="back"><path d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"></path></g>
<g id="downward"><path d="M20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8 8-8z"></path></g>
<g id="drop-down"><path d="M7 10l5 5 5-5z"></path></g>
<g id="drop-down-circle"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 12l-4-4h8l-4 4z"></path></g>
<g id="drop-up"><path d="M7 14l5-5 5 5z"></path></g>
<g id="forward"><path d="M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z"></path></g>
<g id="upward"><path d="M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z"></path></g>
</defs>
</svg>
</ucdlib-iconset>
`, true)}
<p>Move it to the document head: </p>
${this.jsPanel(`
const iconset = document.querySelector('ucdlib-iconset');
document.head.appendChild(iconset);
`)}
<p>Now pass a colon-delimited value into the <code>icon</code> attribute of the <code>ucdlib-icon</code> element as follows:</p>
${this.examplePanel(html`
<div style="display:flex;">
<ucdlib-icon icon="arrows:back"></ucdlib-icon>
<ucdlib-icon icon="arrows:forward"></ucdlib-icon>
<ucdlib-icon icon="arrows:drop-down-circle" class="category-brand--secondary category-brand__text"></ucdlib-icon>
</div>
`)}
<h2>Using src</h2>
<p>
Expand Down
37 changes: 37 additions & 0 deletions test-app/pages/page-ucdlib-iconset.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { LitElement } from 'lit';
import {render, styles} from "./page-ucdlib-iconset.tpl.js";

import {Mixin, MainDomElement} from '../../elements/utils/index.js';
import {BrandedPageElement, MdElement} from "../utils/index.js";

import "../../elements/ucdlib/ucdlib-iconset/ucdlib-iconset";
import "../../elements/ucdlib/ucdlib-icon/ucdlib-icon";

export default class PageUcdlibIconset extends Mixin(LitElement)
.with(MainDomElement, BrandedPageElement, MdElement) {

static get properties() {
return {

};
}

static get styles() {
return styles();
}

constructor() {
super();
this.render = render.bind(this);
}

firstUpdated(){
const iconsets = this.renderRoot.querySelectorAll('ucdlib-iconset');
Array.from(iconsets).forEach(iconset => {
document.head.appendChild(iconset);
});
}

}

customElements.define('page-ucdlib-iconset', PageUcdlibIconset);
57 changes: 57 additions & 0 deletions test-app/pages/page-ucdlib-iconset.tpl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { html, css } from 'lit';

export function styles() {
const elementStyles = css`
:host {
display: block;
}
`;

return [elementStyles];
}

export function render() {
return html`
${this.pageTitle("Custom Iconsets")}
<p>The <code>ucdlib-iconset</code> element allows you to create a custom iconset,
which can then be used by <a href="#ucdlib-icon">the ucdlib-icon element</a></p>
<h2>Defining a custom set</h2>
<p>
You can create a custom set by placing your icons inside svg <code>g</code> tags within <code>ucdlib-iconset</code>.
Each group should have an id that corresponds to the name of the icon.
</p>
${this.examplePanel(html`
<ucdlib-iconset name="arrows">
<svg>
<defs>
<g id="back"><path d="M20 11H7.83l5.59-5.59L12 4l-8 8 8 8 1.41-1.41L7.83 13H20v-2z"></path></g>
<g id="downward"><path d="M20 12l-1.41-1.41L13 16.17V4h-2v12.17l-5.58-5.59L4 12l8 8 8-8z"></path></g>
<g id="drop-down"><path d="M7 10l5 5 5-5z"></path></g>
<g id="drop-down-circle"><path d="M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm0 12l-4-4h8l-4 4z"></path></g>
<g id="drop-up"><path d="M7 14l5-5 5 5z"></path></g>
<g id="forward"><path d="M12 4l-1.41 1.41L16.17 11H4v2h12.17l-5.58 5.59L12 20l8-8z"></path></g>
<g id="upward"><path d="M4 12l1.41 1.41L11 7.83V20h2V7.83l5.58 5.59L20 12l-8-8-8 8z"></path></g>
</defs>
</svg>
</ucdlib-iconset>
`, true)}
<p>Move it to the document head: </p>
${this.jsPanel(`
const iconset = document.querySelector('ucdlib-iconset');
document.head.appendChild(iconset);
`)}
<p>Now pass a colon-delimited value into the <code>icon</code> attribute of the <code>ucdlib-icon</code> element as follows:</p>
${this.examplePanel(html`
<div style="display:flex;">
<ucdlib-icon icon="arrows:back"></ucdlib-icon>
<ucdlib-icon icon="arrows:forward"></ucdlib-icon>
<ucdlib-icon icon="arrows:drop-down-circle" class="category-brand--secondary category-brand__text"></ucdlib-icon>
</div>
`)}
<h2>Using cork-icon-set-generator</h2>
<p>Todo</p>
`;}
39 changes: 39 additions & 0 deletions test-app/pages/page-ucdlib-pages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { LitElement } from 'lit';
import {render, styles} from "./page-ucdlib-pages.tpl.js";

import {Mixin, MainDomElement} from '../../elements/utils/index.js';
import {BrandedPageElement, MdElement} from "../utils/index.js";

import "../../elements/ucdlib/ucdlib-pages/ucdlib-pages";

export default class PageUcdlibPages extends Mixin(LitElement)
.with(MainDomElement, BrandedPageElement, MdElement) {

static get properties() {
return {
example1Selected: {type: String}
};
}

static get styles() {
return styles();
}

constructor() {
super();
this.render = render.bind(this);

this._example1Pages = ["page1", "page2", "page3"];
this.example1Selected = this._example1Pages[0];
}

_example1Click(){
const prefix="page";
let n = parseInt(this.example1Selected.split(prefix)[1]);
if ( n >= this._example1Pages.length) n = 0;
this.example1Selected = this._example1Pages[n];
}

}

customElements.define('page-ucdlib-pages', PageUcdlibPages);
42 changes: 42 additions & 0 deletions test-app/pages/page-ucdlib-pages.tpl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { html, css } from 'lit';

export function styles() {
const elementStyles = css`
:host {
display: block;
}
`;

return [elementStyles];
}

export function render() {
return html`
${this.pageTitle("Pages")}
<p>The <code>ucdlib-pages</code> element is used to select one of its children to show.
In a typical library application, it is used by the "application element" to display defined routes/pages.
</p>
${this.examplePanel(html`
<ucdlib-pages selected="${this.example1Selected}" id="example-pages">
<div id="page1" class="category-brand--tahoe category-brand__background">Test 1</div>
<div id="page2" class="category-brand--farmers-market category-brand__background">Test 2</div>
<div id="page3" class="category-brand--redbud category-brand__background">Test 3</div>
</ucdlib-pages>
<div class="u-space-mt">
<button @click="${this._example1Click}" class="btn">Change Page</button>
</div>
<style>
#example-pages > div {
width: 100%;
height: 200px;
}
#example-pages~div{
display: flex;
justify-content: center;
}
</style>
`)}
`;}
Loading

0 comments on commit 2590619

Please sign in to comment.