Initial commit
This commit is contained in:
34
src/digicode.ts
Normal file
34
src/digicode.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import './style.css'
|
||||
|
||||
const code = '1234';
|
||||
|
||||
const display = document.getElementById('display') as HTMLDivElement;
|
||||
const light = document.getElementById('light') as HTMLDivElement;
|
||||
const keypad = document.getElementById('keypad') as HTMLDivElement;
|
||||
|
||||
function resetCode() {
|
||||
display.innerText = '';
|
||||
light.classList.remove('is-success', 'is-error');
|
||||
}
|
||||
|
||||
function composeDigit(digit: number) {
|
||||
const output = display.innerText + digit.toString();
|
||||
display.innerText = output;
|
||||
if (!code.startsWith(output)) {
|
||||
light.classList.add('is-error');
|
||||
setTimeout(resetCode, 1000)
|
||||
return;
|
||||
}
|
||||
if (code === output) {
|
||||
light.classList.add('is-success');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 1; i < 11; i++) {
|
||||
const digit = i % 10;
|
||||
const button = document.createElement('button');
|
||||
button.innerText = digit.toString();
|
||||
button.onclick = () => composeDigit(digit);
|
||||
keypad.appendChild(button);
|
||||
}
|
96
src/style.css
Normal file
96
src/style.css
Normal file
@@ -0,0 +1,96 @@
|
||||
:root {
|
||||
font-family: Inter, system-ui, Avenir, Helvetica, Arial, sans-serif;
|
||||
line-height: 1.5;
|
||||
font-weight: 400;
|
||||
|
||||
color-scheme: light dark;
|
||||
color: rgba(255, 255, 255, 0.87);
|
||||
background-color: #242424;
|
||||
|
||||
font-synthesis: none;
|
||||
text-rendering: optimizeLegibility;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
-webkit-text-size-adjust: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
display: flex;
|
||||
place-items: center;
|
||||
min-width: 320px;
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
h1 {
|
||||
font-size: 3.2em;
|
||||
line-height: 1.1;
|
||||
}
|
||||
|
||||
#app {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 2rem;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
button {
|
||||
border-radius: 8px;
|
||||
border: 1px solid transparent;
|
||||
padding: 0.6em 1.2em;
|
||||
font-size: 1em;
|
||||
font-weight: 500;
|
||||
font-family: inherit;
|
||||
background-color: #1a1a1a;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.25s;
|
||||
}
|
||||
button:hover {
|
||||
border-color: #646cff;
|
||||
}
|
||||
button:focus,
|
||||
button:focus-visible {
|
||||
outline: 4px auto -webkit-focus-ring-color;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
color: #213547;
|
||||
background-color: #ffffff;
|
||||
}
|
||||
a:hover {
|
||||
color: #747bff;
|
||||
}
|
||||
button, #light {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
}
|
||||
|
||||
#output {
|
||||
display: flex;
|
||||
}
|
||||
#display {
|
||||
flex-grow: 1;
|
||||
}
|
||||
|
||||
#light {
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border-radius: 50%;
|
||||
background-color: #1a1a1a;
|
||||
}
|
||||
#light.is-error {
|
||||
background-color: #fd3838;
|
||||
}
|
||||
#light.is-success {
|
||||
background-color: #46fd46;
|
||||
}
|
||||
|
||||
#keypad {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
}
|
||||
|
||||
#keypad > button:last-child {
|
||||
grid-column: 2;
|
||||
}
|
Reference in New Issue
Block a user