diff options
| author | Jason McCormick <jason@mfamily.org> | 2026-11-27 11:59:34 -0500 |
|---|---|---|
| committer | Jason McCormick <jason@mfamily.org> | 2026-11-27 11:59:34 -0500 |
| commit | 707ff20900a282968c9c816ded4fe5b7e18d09aa (patch) | |
| tree | c9053e37a8f7f86c463c3270908665438e4d0f22 /styleguide.js | |
initial add
Diffstat (limited to 'styleguide.js')
| -rw-r--r-- | styleguide.js | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/styleguide.js b/styleguide.js new file mode 100644 index 0000000..c50f143 --- /dev/null +++ b/styleguide.js @@ -0,0 +1,113 @@ +const PW_TOKENS = { + "version": "1.0.0", + "brand": { + "carbon": "#171715", + "graphite": "#2E2E2A", + "pewter": "#B8B5AB", + "porcelain": "#F2EFE9", + "signal": "#C12735", + "signal-bright": "#D32939", + "signal-deep": "#861E28", + "amber": "#DAB16B", + "jade": "#50B39A", + "copper": "#C79A80" + }, + "light": { + "canvas": "#F2EFE9", + "surface": "#FFFCF7", + "raised": "#E1DED5", + "inset": "#F8F5EF", + "text": "#272620", + "muted": "#615F56", + "border": "#CBC7BD", + "control-border": "#817D72", + "focus": "#A52C36", + "link": "#A52C36", + "primary": "#C12735", + "on-primary": "#FFFFFF", + "primary-hover": "#A51F2C", + "primary-active": "#861E28", + "firefly": "#8A5D20", + "on-firefly": "#FFFFFF", + "firefly-hover": "#704A17", + "firefly-active": "#593B13", + "success": "#186950", + "success-bg": "#DFEDE6", + "warning": "#785018", + "warning-bg": "#EEE5D3", + "danger": "#A52C36", + "danger-bg": "#F2DDDD", + "info": "#615F56", + "info-bg": "#E7E4DC", + "inactive": "#615F56", + "selection": "#EFD8D7", + "on-selection": "#272620", + "hover": "#EEEAE1", + "disabled": "#77736A", + "disabled-bg": "#E7E3DA" + }, + "dark": { + "canvas": "#171715", + "surface": "#22221F", + "raised": "#2E2E2A", + "inset": "#141412", + "text": "#E8E6DF", + "muted": "#ADA99F", + "border": "#484840", + "control-border": "#7A7971", + "focus": "#DAB16B", + "link": "#D8D4C9", + "primary": "#C12735", + "on-primary": "#FFFFFF", + "primary-hover": "#D32939", + "primary-active": "#A82330", + "firefly": "#DAB16B", + "on-firefly": "#171715", + "firefly-hover": "#E6C28A", + "firefly-active": "#C39955", + "success": "#50B39A", + "success-bg": "#1C332D", + "warning": "#DAB16B", + "warning-bg": "#352C1D", + "danger": "#F1989C", + "danger-bg": "#3C2225", + "info": "#B8B5AB", + "info-bg": "#30302C", + "inactive": "#ADA99F", + "selection": "#48272A", + "on-selection": "#E8E6DF", + "hover": "#30302C", + "disabled": "#918E85", + "disabled-bg": "#30302C" + } +}; +'use strict'; +const root=document.documentElement, $=s=>document.querySelector(s), $$=s=>Array.from(document.querySelectorAll(s)); +const titleCase=s=>s.replace(/-/g,' ').replace(/\b\w/g,c=>c.toUpperCase()); +let toastTimeout; +function notify(msg){const t=$('#toast');t.textContent=msg;t.hidden=false;clearTimeout(toastTimeout);toastTimeout=setTimeout(()=>t.hidden=true,3000)} +async function copy(value){try{await navigator.clipboard.writeText(value);notify('Copied to clipboard');}catch{try{const e=document.createElement('textarea');e.value=value;e.style.position='fixed';e.style.opacity='0';document.body.append(e);e.select();const ok=document.execCommand('copy');e.remove();if(!ok)throw Error();notify('Copied to clipboard');}catch{notify('Copy unavailable. Select the text manually.')}}} +const stored=(()=>{try{return localStorage.getItem('pw-styleguide-mode')}catch{return null}})(); +const mode=['light','dark','auto'].includes(stored)?stored:'dark'; +function setMode(value){root.dataset.pwTheme=value;$$('[data-mode]').forEach(b=>b.setAttribute('aria-pressed',String(b.dataset.mode===value)));try{localStorage.setItem('pw-styleguide-mode',value)}catch{}} +setMode(mode); +$$('[data-mode]').forEach(b=>b.addEventListener('click',()=>setMode(b.dataset.mode))); +$('#nav-toggle').addEventListener('click',()=>{const open=$('#side-nav').classList.toggle('open');$('#nav-toggle').setAttribute('aria-expanded',String(open))}); +const navLinks=$$('.nav-group a'); +navLinks.forEach(a=>a.addEventListener('click',()=>{$('#side-nav').classList.remove('open');$('#nav-toggle').setAttribute('aria-expanded','false')})); +$('#nav-search').addEventListener('input',e=>{const q=e.target.value.trim().toLowerCase();let visible=0;for(const a of navLinks){const match=!q||a.textContent.toLowerCase().includes(q)||($(a.hash)?.textContent.toLowerCase().includes(q));a.hidden=!match;if(match)visible++}$$('.nav-group').forEach(g=>g.hidden=Array.from(g.querySelectorAll('a')).every(a=>a.hidden));$('#nav-count').hidden=!q;$('#nav-count').textContent=visible+' matching sections'}); +let activeId=''; +function updateNav(){const sections=$$('main section[id]');let current=sections[0].id;for(const s of sections)if(s.getBoundingClientRect().top<160)current=s.id;if(activeId!==current){activeId=current;navLinks.forEach(a=>{const active=a.hash==='#'+current;a.classList.toggle('active',active);if(active)a.setAttribute('aria-current','location');else a.removeAttribute('aria-current')})}} +let scheduled=false;addEventListener('scroll',()=>{if(!scheduled){scheduled=true;requestAnimationFrame(()=>{updateNav();scheduled=false})}},{passive:true});addEventListener('resize',updateNav);updateNav(); +const descriptions={canvas:'Page foundation',surface:'Panels and cards',raised:'Title bars and elevated areas',inset:'Recessed fields and code',text:'Main text',muted:'Secondary text',border:'Decorative separators','control-border':'Interactive control boundaries',focus:'Keyboard focus',link:'Ordinary links',primary:'Master primary action','on-primary':'Primary action text','primary-hover':'Primary hover','primary-active':'Primary pressed',firefly:'Firefly product action','on-firefly':'Amber action text','firefly-hover':'Firefly hover','firefly-active':'Firefly pressed',success:'Connected / success','success-bg':'Positive callout background',warning:'Attention / pending','warning-bg':'Warning callout background',danger:'Error / destructive','danger-bg':'Error callout background',info:'Information','info-bg':'Informational callout',inactive:'Idle / offline',selection:'Selected surface','on-selection':'Selected text',hover:'Hover surface',disabled:'Disabled text','disabled-bg':'Disabled surface'}; +function makeCopy(hex){return '<button type="button" class="token-copy" data-hex="'+hex+'" aria-label="Copy '+hex+'"><span style="background:'+hex+'"></span>'+hex+'</button>'} +$('#brand-swatches').innerHTML=Object.entries(PW_TOKENS.brand).map(([n,c])=>'<button class="swatch" type="button" data-hex="'+c+'" aria-label="Copy '+titleCase(n)+' '+c+'"><span class="swatch-color" style="background:'+c+'"></span><span class="swatch-info"><strong>'+titleCase(n)+'</strong><code>'+c+'</code></span></button>').join(''); +function tokens(q=''){const items=Object.entries(PW_TOKENS.light).filter(([k,v])=>[k,v,PW_TOKENS.dark[k],descriptions[k]].join(' ').toLowerCase().includes(q.toLowerCase()));$('#token-rows').innerHTML=items.map(([k,v])=>'<tr><td>--pw-'+k+'</td><td>'+descriptions[k]+'</td><td>'+makeCopy(v)+'</td><td>'+makeCopy(PW_TOKENS.dark[k])+'</td></tr>').join('');$('#token-count').textContent=items.length+' of '+Object.keys(PW_TOKENS.light).length+' functional tokens'} +tokens();$('#token-filter').addEventListener('input',e=>tokens(e.target.value)); +$('#space-demo').innerHTML=[4,8,12,16,24,32].map(n=>'<div><span>'+n+'px</span><b style="width:'+n*3+'px"></b></div>').join(''); +document.addEventListener('click',e=>{const c=e.target.closest('[data-hex],[data-copy-target]');if(!c)return;if(c.dataset.hex)copy(c.dataset.hex);else copy(document.getElementById(c.dataset.copyTarget).textContent.trim())}); +$$('[data-product]').forEach(b=>b.addEventListener('click',()=>{$('#component-sandbox').dataset.pwProduct=b.dataset.product;$$('[data-product]').forEach(x=>x.setAttribute('aria-pressed',String(x===b)))})); +$$('[data-demo]').forEach(b=>b.addEventListener('click',()=>$('#button-result').textContent=b.dataset.demo+' selected. No real action performed.')); +$('#form-demo').addEventListener('submit',e=>{e.preventDefault();$('#form-state').textContent='✓ Sample saved: '+$('#samplecall').value.toUpperCase()+' / '+$('#samplemode').value+'. No live submission.';$('#form-state').style.color='var(--pw-success)'}); +const rows={Users:[['N8EI','A','DMR','success','On air','18:42:07'],['W8WKY','B','D-Star','inactive','Idle','18:40:12']],Nodes:[['K8OH','A','YSF','success','Connected','18:41:00'],['W1AW','B','DMR','inactive','Idle','18:35:20']],Peers:[['XLX720','A','XLX','success','Connected','18:42:12'],['XLX123','C','XLX','warning','Pending','18:37:05']]}; +$$('[data-tab]').forEach(b=>b.addEventListener('click',()=>{$$('[data-tab]').forEach(x=>{x.classList.toggle('active',x===b);x.setAttribute('aria-pressed',String(x===b))});$('#sample-table-heading').textContent='Recently heard '+b.dataset.tab.toLowerCase();$('#sample-table-body').innerHTML=rows[b.dataset.tab].map(([call,mod,protocol,state,status,t])=>'<tr><td class="mono">'+call+'</td><td>'+mod+'</td><td>'+protocol+'</td><td><span class="pw-status pw-'+state+'">'+status+'</span></td><td class="mono">'+t+'</td></tr>').join('')})); |
