askrobots / dbbasic-web-native
Public
100+ copy-paste UI components in plain HTML and CSS: no dependencies, no build step.
danq9
Add canonical.html v1.0 - The single source of truth for usability standards
fb6e650
1 year ago
History
standards-toolbar.html · 4.8 KB · 134 lines
| 1 | <!-- DBBasic Usability Standards Toolbar --> |
| 2 | <!-- Include this snippet in any demo page to enable standards visualization --> |
| 3 | |
| 4 | <!-- Toolbar Container --> |
| 5 | <div class="standards-toolbar" id="standards-toolbar"> |
| 6 | <div class="toolbar-header"> |
| 7 | <div class="toolbar-title">📐 Usability Standards</div> |
| 8 | <button class="toolbar-collapse-btn" onclick="toggleToolbar()">−</button> |
| 9 | </div> |
| 10 | |
| 11 | <div class="toolbar-buttons"> |
| 12 | <button class="toolbar-btn" onclick="window.standardsOverlay.toggle('grid')" data-type="grid"> |
| 13 | <span class="toolbar-btn-icon">📊</span> |
| 14 | <span>Layout Grid</span> |
| 15 | </button> |
| 16 | |
| 17 | <button class="toolbar-btn" onclick="window.standardsOverlay.toggle('touch')" data-type="touch"> |
| 18 | <span class="toolbar-btn-icon">👆</span> |
| 19 | <span>Touch Zones</span> |
| 20 | </button> |
| 21 | |
| 22 | <button class="toolbar-btn" onclick="window.standardsOverlay.toggle('spacing')" data-type="spacing"> |
| 23 | <span class="toolbar-btn-icon">📏</span> |
| 24 | <span>Spacing</span> |
| 25 | </button> |
| 26 | |
| 27 | <button class="toolbar-btn" onclick="window.standardsOverlay.toggle('flow')" data-type="flow"> |
| 28 | <span class="toolbar-btn-icon">👁️</span> |
| 29 | <span>Visual Flow</span> |
| 30 | </button> |
| 31 | |
| 32 | <button class="toolbar-btn" onclick="window.standardsOverlay.toggle('targets')" data-type="targets"> |
| 33 | <span class="toolbar-btn-icon">🎯</span> |
| 34 | <span>Touch Targets</span> |
| 35 | </button> |
| 36 | |
| 37 | <button class="toolbar-btn" onclick="window.standardsOverlay.toggle('boundaries')" data-type="boundaries"> |
| 38 | <span class="toolbar-btn-icon">📦</span> |
| 39 | <span>Boundaries</span> |
| 40 | </button> |
| 41 | </div> |
| 42 | |
| 43 | <div class="toolbar-actions"> |
| 44 | <button class="toolbar-action-btn" onclick="window.standardsOverlay.showAll()"> |
| 45 | Show All |
| 46 | </button> |
| 47 | <button class="toolbar-action-btn" onclick="window.standardsOverlay.hideAll()"> |
| 48 | Hide All |
| 49 | </button> |
| 50 | </div> |
| 51 | </div> |
| 52 | |
| 53 | <!-- Keyboard Shortcut Hint --> |
| 54 | <div class="standards-keyboard-hint" id="keyboard-hint"> |
| 55 | Press <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>S</kbd> to toggle overlays |
| 56 | </div> |
| 57 | |
| 58 | <!-- Toolbar Interaction Script --> |
| 59 | <script> |
| 60 | // Toggle toolbar collapsed state |
| 61 | function toggleToolbar() { |
| 62 | const toolbar = document.getElementById('standards-toolbar'); |
| 63 | const btn = toolbar.querySelector('.toolbar-collapse-btn'); |
| 64 | toolbar.classList.toggle('collapsed'); |
| 65 | btn.textContent = toolbar.classList.contains('collapsed') ? '+' : '−'; |
| 66 | } |
| 67 | |
| 68 | // Update button active states when overlays change |
| 69 | function updateToolbarButtons() { |
| 70 | const buttons = document.querySelectorAll('.toolbar-btn[data-type]'); |
| 71 | buttons.forEach(btn => { |
| 72 | const type = btn.dataset.type; |
| 73 | if (window.standardsOverlay && window.standardsOverlay.activeOverlays.has(type)) { |
| 74 | btn.classList.add('active'); |
| 75 | } else { |
| 76 | btn.classList.remove('active'); |
| 77 | } |
| 78 | }); |
| 79 | } |
| 80 | |
| 81 | // Override toggle method to update button states |
| 82 | if (window.standardsOverlay) { |
| 83 | const originalToggle = window.standardsOverlay.toggle.bind(window.standardsOverlay); |
| 84 | window.standardsOverlay.toggle = function(type) { |
| 85 | originalToggle(type); |
| 86 | updateToolbarButtons(); |
| 87 | }; |
| 88 | |
| 89 | const originalShowAll = window.standardsOverlay.showAll.bind(window.standardsOverlay); |
| 90 | window.standardsOverlay.showAll = function() { |
| 91 | originalShowAll(); |
| 92 | updateToolbarButtons(); |
| 93 | }; |
| 94 | |
| 95 | const originalHideAll = window.standardsOverlay.hideAll.bind(window.standardsOverlay); |
| 96 | window.standardsOverlay.hideAll = function() { |
| 97 | originalHideAll(); |
| 98 | updateToolbarButtons(); |
| 99 | }; |
| 100 | } |
| 101 | |
| 102 | // Show keyboard hint briefly on page load |
| 103 | window.addEventListener('load', () => { |
| 104 | const hint = document.getElementById('keyboard-hint'); |
| 105 | setTimeout(() => { |
| 106 | hint.classList.add('show'); |
| 107 | setTimeout(() => { |
| 108 | hint.classList.remove('show'); |
| 109 | }, 3000); |
| 110 | }, 1000); |
| 111 | }); |
| 112 | |
| 113 | // Show hint again when user presses Ctrl or Shift |
| 114 | let ctrlPressed = false; |
| 115 | let shiftPressed = false; |
| 116 | |
| 117 | document.addEventListener('keydown', (e) => { |
| 118 | if (e.ctrlKey) ctrlPressed = true; |
| 119 | if (e.shiftKey) shiftPressed = true; |
| 120 | |
| 121 | if (ctrlPressed && shiftPressed) { |
| 122 | document.getElementById('keyboard-hint').classList.add('show'); |
| 123 | } |
| 124 | }); |
| 125 | |
| 126 | document.addEventListener('keyup', (e) => { |
| 127 | if (!e.ctrlKey) ctrlPressed = false; |
| 128 | if (!e.shiftKey) shiftPressed = false; |
| 129 | |
| 130 | if (!ctrlPressed || !shiftPressed) { |
| 131 | document.getElementById('keyboard-hint').classList.remove('show'); |
| 132 | } |
| 133 | }); |
| 134 | </script> |