2022-01-21 13:07:13 -06:00
const categories = [
{
id : 'typography' ,
name : 'Typography' ,
description : 'HTML, being a markup language, has abundantly clear semantics for basic typography. Water.css leaves those semantics untouched.' ,
snippets : [
{
id : 'copy' ,
name : 'Headings and copy' ,
code : `
< h1 > Heading 1 < / h 1 >
< p >
This is a paragraph that could contain long - form text . Heck , < a href = "#" > here ' s a link < / a > .
< strong > This is important , < / s t r o n g > t h i s i s n o r m a l , < e m > a n d t h i s i s e m p h a s i z e d ! < / e m >
< / p >
< p > This is another paragraph that could contain long - form text . < / p >
< h2 > Heading 2 < / h 2 >
< p > You probably get the idea by now ! < / p >
< h3 > Heading 3 < / h 3 >
< h4 > Heading 4 < / h 4 >
< h5 > Heading 5 < / h 5 >
< h5 > Heading 6 < / h 5 >
`
} ,
{
id : 'quotes' ,
name : 'Quotes' ,
code : `
< blockquote cite = "https://developer.mozilla.org/en-US/docs/Web/HTML/Element/blockquote" >
"The HTML blockquote Element (or HTML Block Quotation Element) indicates that the enclosed text is an extended quotation. Usually, this is rendered visually by indentation (see <a href=" https : //developer.mozilla.org/en-US/docs/Web/HTML/Element/blockquote#Usage_notes">Notes</a> for how to change it). A URL for the source of the quotation may be given using the <code>cite</code> attribute, while a text representation of the source can be given using the <code><cite></code> cite element."
< footer >
< cite > MDN , "The Block Quotation element" < / c i t e >
< / f o o t e r >
< / b l o c k q u o t e >
< p >
Did you know HTML supports inline quotes ? I didn ' t , until I read that
< q cite = "https://developer.mozilla.org/en-US/docs/Web/HTML/Element/q" >
the < code > & lt ; q & gt ; < / c o d e > H T M L e l e m e n t i n d i c a t e s t h a t t h e e n c l o s e d t e x t i s a s h o r t i n l i n e q u o t a t i o n
< / q > .
< / p >
`
} ,
{
id : 'lists' ,
name : 'Lists' ,
code : `
< ul >
< li > Unordered list item 1 < / l i >
< li > Unordered list item 2 < / l i >
< li > Unordered list item 3 < / l i >
< / u l >
< ol >
< li > Ordered list item 1 < / l i >
< li > Ordered list item 2 < / l i >
< li > Ordered list item 3 < / l i >
< / o l >
< dl >
< dt > Unordered lists < / d t >
< dd > Represents an unordered list of items , typically rendered as a bulleted list < / d d >
< dt > Ordered lists < / d t >
< dd > Represents an ordered list of items , typically rendered as a numbered list < / d d >
< dt > Description lists < / d t >
< dd > Encloses a list of groups of terms and descriptions < / d d >
< dd > Not commonly used , but still nifty < / d d >
< / d l >
`
} ,
{
id : 'code-etc' ,
name : 'Code samples, keyboard shortcuts, oh my' ,
code : `
< p >
Below is some code . If you select it , you can copy using < kbd > Ctrl - C < / k b d > .
Did you know that < code > alert ( 1 ) < / c o d e > c a n s h o w a n a l e r t i n J a v a S c r i p t ?
< / p >
< pre > < code > // This logs a message to the console and check out the scrollbar.
console . log ( 'Hello, world!' ) < / c o d e > < / p r e >
< p > HTML also has elements for < var > variables < / v a r > a n d s a m p l e o u t p u t : < s a m p > H e l l o , w o r l d ! < / s a m p > < / p >
`
}
]
} ,
{
id : 'forms' ,
name : 'Form controls' ,
description : 'Water.css provides a set of styles for form controls, including text inputs, select boxes, buttons, and more.' ,
snippets : [
{
id : 'text-inputs' ,
name : 'Text inputs' ,
code : `
< form onsubmit = "return false;" >
< label for = "email" > Email < / l a b e l >
< input type = "email" name = "email" id = "email" placeholder = "john.doe@gmail.com" / >
< label for = "id" > User id ( read only ) < / l a b e l >
< input readonly name = "id" id = "id" value = "04D6H89Z" / >
< label for = "disabled" > Random disabled input < / l a b e l >
< input disabled name = "disabled" id = "disabled" placeholder = "Because why not?" / >
< label for = "about" > About me < / l a b e l >
< textarea name = "about" id = "about" placeholder = "I am a textarea..." > < / t e x t a r e a >
< / f o r m >
`
} ,
{
id : 'buttons' ,
name : 'Buttons' ,
code : `
< button onclick = "alert('Clicked!')" > Hey look , a button ! < / b u t t o n >
< br >
< form onsubmit = "alert('Form submitted!'); return false;" >
< label for = "name-field" > Your name < / l a b e l >
< input type = "text" id = "name-field" name = "name" / >
< input type = "submit" value = "Submit" / >
< input type = "reset" value = "Reset" / >
< / f o r m >
`
} ,
{
id : 'assorted-inputs' ,
name : 'Assorted other controls' ,
code : `
< form onsubmit = "return false;" >
< label for = "rating" > Rate this site < / l a b e l >
< input name = "rating" id = "rating" type = "range" min = "1" max = "10" > < / i n p u t >
< label for = "flavor" > Choose a flavor < / l a b e l >
< select name = "flavor" id = "flavor" >
< option > Chocolate < / o p t i o n >
< option > Strawberry < / o p t i o n >
< option > Vanilla < / o p t i o n >
< / s e l e c t >
< fieldset >
< legend > Choose a Doe < / l e g e n d >
< div >
< input type = "radio" id = "john" name = "drone" value = "john" checked / >
< label for = "john" > John Doe < / l a b e l >
< / d i v >
< div >
< input type = "radio" id = "jane" name = "drone" value = "jane" / >
< label for = "jane" > Jane Doe < / l a b e l >
< / d i v >
< div >
< input type = "radio" id = "johnny" name = "drone" value = "johnny" / >
< label for = "johnny" > Johnny Doe < / l a b e l >
< / d i v >
< / f i e l d s e t >
< input type = "checkbox" name = "remember" id = "remember" checked / >
< label for = "remember" > Remember me < / l a b e l >
< / f o r m >
`
} ,
{
id : 'dialogs' ,
name : 'Dialogs' ,
caniuse : 'https://caniuse.com/dialog' ,
code : `
< div >
< button type = "button" id = "dialog-trigger" >
Show me the dialog !
< / b u t t o n >
< span id = "dialog-result" > < / s p a n >
< / d i v >
< dialog id = "dialog" >
< header > This is a sample dialog < / h e a d e r >
< form method = "dialog" >
< p > What is your favorite pet animal ? < / p >
< menu >
< button value = "feline" > Cats < / b u t t o n >
< button value = "canine" > Dogs < / b u t t o n >
< button value = "other" > Others < / b u t t o n >
< / m e n u >
< / f o r m >
< / d i a l o g >
< script >
document . getElementById ( 'dialog-trigger' ) . addEventListener ( 'click' , ( ) => {
document . getElementById ( 'dialog-result' ) . innerText = ''
document . getElementById ( 'dialog' ) . showModal ( )
} )
document . getElementById ( 'dialog' ) . addEventListener ( 'close' , ( event ) => {
document . getElementById ( 'dialog-result' ) . innerText = \ ` Your answer: \$ {event.target.returnValue} \`
} )
< / s c r i p t >
` ,
realCode : `
< div >
< button type = "button" id = "dialog-trigger" >
Show me the dialog !
< / b u t t o n >
< span id = "dialog-result" > < / s p a n >
< / d i v >
`
}
]
} ,
{
id : 'misc' ,
name : 'Miscellaneous' ,
description : 'Styles are also provided for various other elements that don\'t strictly fit into the other categories. These include tables, dialogs, and images.' ,
snippets : [
{
id : 'tables' ,
name : 'Tables' ,
code : `
< table >
< thead >
< tr >
< th > Name < / t h >
< th > Quantity < / t h >
< th > Price < / t h >
< / t r >
< / t h e a d >
< tbody >
< tr >
< td > Godzilla < / t d >
< td > 2 < / t d >
< td > $299 . 99 < / t d >
< / t r >
< tr >
< td > Mozilla < / t d >
< td > 10 < / t d >
< td > $100 , 000.00 < / t d >
< / t r >
< tr >
< td > Quesadilla < / t d >
< td > 1 < / t d >
< td > $2 . 22 < / t d >
< / t r >
< / t b o d y >
< / t a b l e >
`
} ,
{
id : 'details' ,
name : 'Summary/details' ,
caniuse : 'https://caniuse.com/details' ,
code : `
< details >
< summary > Some summary / details can ' t hurt ! < / s u m m a r y >
< p > Lorem ipsum dolor sit blah blah . < / p >
< / d e t a i l s >
`
} ,
{
id : 'rules-etc' ,
name : 'Rules, images, and addresses' ,
code : `
< p > Here 's a horizontal rule and image because I don' t know where else to put them . < / p >
< img src = "https://placekitten.com/408/287" alt = "Example kitten" / >
< hr / >
< p > Addresses are also styled to be < strong > awesome < / s t r o n g > ! < / p >
< address >
< a href = "mailto:john.doe@example.com" > john . doe @ example . com < / a > < b r >
< a href = "tel:778-330-2389" > 778 - 330 - 2389 < / a > < b r >
< a href = "sms:666-666-6666" > 666 - 666 - 6666 < / a > < b r >
< / a d d r e s s >
`
}
]
}
]
const tocContainer = document . getElementById ( 'toc' )
for ( const category of categories ) {
const li = document . createElement ( 'li' )
const a = document . createElement ( 'a' )
a . href = ` # ${ category . id } `
a . innerText = category . name
li . appendChild ( a )
const ul = document . createElement ( 'ul' )
for ( const snippet of category . snippets ) {
const li = document . createElement ( 'li' )
const a = document . createElement ( 'a' )
a . href = ` # ${ snippet . id } `
a . innerText = snippet . name
li . appendChild ( a )
ul . appendChild ( li )
}
li . appendChild ( ul )
tocContainer . appendChild ( li )
}
const demosContainer = document . getElementById ( 'demos' )
let first = true
for ( const category of categories ) {
const h2 = document . createElement ( 'h2' )
h2 . id = category . id
h2 . innerText = category . name
demosContainer . appendChild ( h2 )
const p = document . createElement ( 'p' )
p . innerText = category . description
demosContainer . appendChild ( p )
for ( const snippet of category . snippets ) {
const h3 = document . createElement ( 'h3' )
h3 . id = snippet . id
h3 . innerText = snippet . name
demosContainer . appendChild ( h3 )
if ( snippet . caniuse ) {
const p = document . createElement ( 'p' )
p . innerText = '⚠️ This may not be supported in all browsers. '
const a = document . createElement ( 'a' )
a . href = snippet . caniuse
a . target = '_blank'
a . rel = 'noopener noreferrer'
a . innerText = 'See caniuse for more info.'
p . appendChild ( a )
demosContainer . appendChild ( p )
}
const pre = document . createElement ( 'pre' )
const code = document . createElement ( 'code' )
code . innerText = snippet . code . trim ( )
2022-01-22 12:58:18 -06:00
pre . style . position = 'relative'
pre . appendChild ( code )
2022-01-21 13:07:13 -06:00
const button = document . createElement ( 'button' )
button . innerText = 'Copy'
2022-01-22 12:58:18 -06:00
button . className = 'snippet-copy'
2022-01-21 13:07:13 -06:00
let timeout = null
button . addEventListener ( 'click' , ( ) => {
navigator . clipboard . writeText ( snippet . code . trim ( ) )
button . innerText = 'Copied!'
clearTimeout ( timeout )
timeout = setTimeout ( ( ) => { button . innerText = 'Copy' } , 1000 )
} )
2022-01-22 12:58:18 -06:00
pre . appendChild ( button )
2022-01-21 13:07:13 -06:00
demosContainer . appendChild ( pre )
const details = document . createElement ( 'details' )
details . id = ` ${ snippet . id } -details `
details . innerHTML = snippet . realCode || snippet . code
// Execute any scripts in the HTML.
Array . from ( details . querySelectorAll ( 'script' ) ) . forEach ( ( oldScript ) => {
const newScript = document . createElement ( 'script' )
for ( const { name , value } of oldScript . attributes ) { newScript . setAttribute ( name , value ) }
newScript . appendChild ( document . createTextNode ( oldScript . innerHTML ) )
oldScript . parentNode . replaceChild ( newScript , oldScript )
} )
const summary = document . createElement ( 'summary' )
summary . innerText = 'Show output'
details . prepend ( summary )
demosContainer . appendChild ( details )
if ( first ) {
details . open = true
first = false
let firstToggle = true
details . addEventListener ( 'toggle' , ( ) => {
if ( ! details . open || firstToggle ) return
firstToggle = false
history . pushState ( { } , '' , '#' + snippet . id )
} )
} else {
details . addEventListener ( 'toggle' , ( ) => {
if ( ! details . open ) return
history . pushState ( { } , '' , '#' + snippet . id )
} )
}
}
}
const hashChange = ( ) => {
const details = document . getElementById ( ` ${ window . location . hash . slice ( 1 ) } -details ` )
if ( ! details ) return
details . open = true
}
window . addEventListener ( 'hashchange' , hashChange , false )
hashChange ( )
// Dialog demo scripting.
document . getElementById ( 'dialog-trigger' ) . addEventListener ( 'click' , ( ) => {
document . getElementById ( 'dialog-result' ) . innerText = ''
document . getElementById ( 'dialog' ) . showModal ( )
} )
document . getElementById ( 'dialog' ) . addEventListener ( 'close' , ( event ) => {
document . getElementById ( 'dialog-result' ) . innerText = ` Your answer: ${ event . target . returnValue } `
} )