-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* docs: stubbed icons page * docs: icons prose * chore: tslib * docs: max out the card * docs: icon page layout
- Loading branch information
1 parent
e9ceed3
commit 6f3d7b8
Showing
8 changed files
with
152 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// for editor highlighting | ||
const html = String.raw; | ||
|
||
module.exports = class IconsPage { | ||
async data() { | ||
return { | ||
permalink: '/icons/index.html', | ||
layout: 'layouts/pages/basic.njk', | ||
title: 'Icons', | ||
hasToc: true, | ||
icons: await import('@rhds/icons'), | ||
}; | ||
} | ||
|
||
render({ icons }) { | ||
return html` | ||
<script type="module" src="icons.js" data-helmet></script> | ||
<style data-helmet> | ||
.icon-set { | ||
padding: 0; | ||
list-style-type: none; | ||
display: grid; | ||
grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); | ||
gap: var(--rh-space-sm); | ||
} | ||
</style> | ||
<p>Click icons to copy their HTML elements</p> | ||
<section> | ||
<h2 id="social-icons">Social Icons</h2> | ||
<p>These icons represent or link to social media companies</p> | ||
<ul class="icon-set">${this.renderIcons('social', icons)}</ul> | ||
</section> | ||
<section> | ||
<h2 id="standard-icons">Standard Icons</h2> | ||
<p>Use these icons as graphics, and at large sizes</p> | ||
<rh-alert state="warning">Avoid using these for UI elements like buttons</rh-alert> | ||
<ul class="icon-set">${this.renderIcons('standard', icons)}</ul> | ||
</section> | ||
<section> | ||
<h2 id="ui-icons">UI Icons</h2> | ||
<p>Use these icons in UI controls like buttons and form fields</p> | ||
<ul class="icon-set">${this.renderIcons('ui', icons)}</ul> | ||
</section> | ||
<section> | ||
<h2 id="micron-icons">Microns</h2> | ||
<p>Microns is a funny word</p> | ||
<ul class="icon-set">${this.renderIcons('microns', icons)}</ul> | ||
</section> | ||
`; | ||
} | ||
|
||
renderIcons(set, icons) { | ||
return Array.from(icons[set].keys(), icon => this.renderIcon({ icon, set })).join(''); | ||
} | ||
|
||
renderIcon({ set, icon }) { | ||
return html` | ||
<li> | ||
<rh-button accessible-label="Copy icon HTML for ${set} ${icon}" | ||
icon="${icon}" | ||
icon-set="${set}" | ||
variant="tertiary">${icon}</rh-button> | ||
</li> | ||
`; | ||
} | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import '@rhds/elements/rh-icon/rh-icon.js'; | ||
import '@rhds/elements/rh-tooltip/rh-tooltip.js'; | ||
import { RhButton } from '@rhds/elements/rh-button/rh-button.js'; | ||
import { RhAlert } from '@rhds/elements/rh-alert/rh-alert.js'; | ||
|
||
document.addEventListener('click', async function(event) { | ||
const { icon, iconSet } = event.target; | ||
if (event.target instanceof RhButton && icon && iconSet) { | ||
const html = /* html*/`<rh-icon set="${iconSet}" icon="${icon}"></rh-icon>`; | ||
await navigator.clipboard.writeText(html); | ||
// TODO: syntax highlight this | ||
const message = html; | ||
await RhAlert.toast({ heading: 'Copied', message }); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,35 @@ | ||
import { join } from 'node:path'; | ||
import { readdir, stat } from 'node:fs/promises'; | ||
import { readdir } from 'node:fs/promises'; | ||
|
||
let iconSetsMap; | ||
|
||
/** | ||
* create a javascript map containing icon names | ||
*/ | ||
export async function getIconSetsMap() { | ||
if (!iconSetsMap) { | ||
// because the icon package exports DOM nodes, but this file runs in nodejs | ||
await import('@patternfly/pfe-core/ssr-shims.js'); | ||
const { standard, social, ui, microns } = await import('@rhds/icons'); | ||
iconSetsMap = new Map([ | ||
['social', [...social.keys()]], | ||
['standard', [...standard.keys()]], | ||
['ui', [...ui.keys()]], | ||
['microns', [...microns.keys()]], | ||
]); | ||
} | ||
return iconSetsMap; | ||
} | ||
|
||
/** | ||
* create a javascript module containing element and icon names | ||
*/ | ||
export async function makeDemoEnv() { | ||
const iconsDir = join(process.cwd(), 'node_modules', '@rhds', 'icons'); | ||
const dirContents = await readdir(iconsDir); | ||
const dirNamesOrNulls = await Promise.all(dirContents.map(async x => { | ||
const stats = await stat(join(iconsDir, x)); | ||
if (!x.startsWith('.') && stats.isDirectory()) { | ||
return x; | ||
} else { | ||
return null; | ||
} | ||
})); | ||
const iconSetNames = dirNamesOrNulls.filter(x => x != null); | ||
const iconSets = await Promise.all(iconSetNames.reverse().map(async set => { | ||
const files = await readdir(join(iconsDir, set)); | ||
return [set, [...new Set(files.map(x => x.replace(/\..*$/, '')))]]; | ||
})); | ||
iconSetsMap ??= await getIconSetsMap(); | ||
const javascript = String.raw; // for editor highlighting | ||
const allElements = (await readdir(join(process.cwd(), 'elements'))) | ||
.filter(path => !path.includes('.')); | ||
return javascript` | ||
export const elements = ${JSON.stringify(allElements)}; | ||
export const iconSets = new Map(${JSON.stringify(iconSets)});`; | ||
export const iconSets = new Map(${JSON.stringify(Object.fromEntries(iconSetsMap.entries()))});`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,6 +61,7 @@ | |
"es2015.iterable", | ||
"es2020", | ||
"es2022", | ||
"ESNext.Collection", | ||
"ESNext.Disposable", | ||
"es5", | ||
"es6", | ||
|