diff --git a/src/counter.ts b/src/counter.ts index 82e2408..a03fa67 100644 --- a/src/counter.ts +++ b/src/counter.ts @@ -2,6 +2,7 @@ import { createEffect, createSignal } from './signals'; export function setupCounter(element: HTMLDivElement) { const [count, setCount] = createSignal(0); + const [name, setName] = createSignal('StyleShit'); const doubled = () => count() * 2; @@ -10,11 +11,28 @@ export function setupCounter(element: HTMLDivElement) { const countEl = element.querySelector('#count')!; const doubledEl = element.querySelector('#count-doubled')!; + const nameInput = element.querySelector('#name')!; + const nameOutput = element.querySelector('#name-output')!; + createEffect(() => { countEl.innerHTML = `Count is ${count()}`; doubledEl.innerHTML = `Doubled is ${doubled()}`; }); + createEffect(() => { + const value = name().trim(); + + if (value === '') { + nameOutput.innerHTML = 'Please enter your name'; + return; + } + + nameOutput.innerHTML = `Hello, ${value}`; + }); + increment.addEventListener('click', () => setCount(count() + 1)); reset.addEventListener('click', () => setCount(0)); + nameInput.addEventListener('input', () => setName(nameInput.value)); + + nameInput.value = name(); } diff --git a/src/main.ts b/src/main.ts index 3fc710d..266299d 100644 --- a/src/main.ts +++ b/src/main.ts @@ -16,9 +16,17 @@ document.querySelector('#app')!.innerHTML = `
+

+
+ +
+ + +

+
diff --git a/src/style.css b/src/style.css index ed817f8..98455bf 100644 --- a/src/style.css +++ b/src/style.css @@ -63,7 +63,8 @@ h1 { color: #888; } -button { +button, +input { border-radius: 8px; border: 1px solid transparent; padding: 0.6em 1.2em; @@ -71,12 +72,17 @@ button { font-weight: 500; font-family: inherit; background-color: #1a1a1a; - cursor: pointer; transition: border-color 0.25s; } + +button { + cursor: pointer; +} + button:hover { border-color: #646cff; } + button:focus, button:focus-visible { outline: 4px auto -webkit-focus-ring-color;