Add a level selector
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
987388b714
commit
b68f84bc98
@ -0,0 +1,31 @@
|
|||||||
|
import { AUTOMATONS } from './examples.js';
|
||||||
|
import { selectAutomaton } from './fsm.js';
|
||||||
|
|
||||||
|
const automatonSelector = /** @type {HTMLDivElement} */ (document.getElementById('automaton-selector'));
|
||||||
|
const automatonCollection = /** @type {HTMLDivElement} */ (document.getElementById('automaton-collection'));
|
||||||
|
const app = /** @type {HTMLDivElement} */ (document.getElementById('app'));
|
||||||
|
|
||||||
|
for (const [displayName, automaton] of Object.entries(AUTOMATONS)) {
|
||||||
|
const card = document.createElement('div');
|
||||||
|
card.setAttribute('tabindex', '0');
|
||||||
|
card.setAttribute('role', 'button');
|
||||||
|
card.classList.add('card');
|
||||||
|
card.innerHTML = `
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">${displayName}</h5>
|
||||||
|
<p class="card-text">${automaton.length} states</p>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
async function handleEvent() {
|
||||||
|
automatonSelector.setAttribute('hidden', 'hidden');
|
||||||
|
app.removeAttribute('hidden');
|
||||||
|
await selectAutomaton(automaton);
|
||||||
|
}
|
||||||
|
card.addEventListener('click', handleEvent);
|
||||||
|
card.addEventListener('keydown', async (event) => {
|
||||||
|
if (event.key === 'Enter' || event.key === ' ') {
|
||||||
|
await handleEvent();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
automatonCollection.appendChild(card);
|
||||||
|
}
|
Loading…
Reference in new issue