11'use client'
22
3+ import type { SubmitEvent } from 'react' ;
4+
35import { useList } from '@siberiacancode/reactuse' ;
46import { CheckIcon , XIcon } from 'lucide-react' ;
57import { useState } from 'react' ;
@@ -21,7 +23,8 @@ const Demo = () => {
2123
2224 const [ value , setValue ] = useState ( '' ) ;
2325
24- const onAdd = ( ) => {
26+ const onSubmit = ( event : SubmitEvent < HTMLFormElement > ) => {
27+ event . preventDefault ( ) ;
2528 const text = value . trim ( ) ;
2629 if ( ! text ) return ;
2730 todos . push ( { id : crypto . randomUUID ( ) , text, done : false } ) ;
@@ -38,26 +41,25 @@ const Demo = () => {
3841 < section className = 'flex w-full max-w-sm flex-col gap-3 p-4' >
3942 < h2 className = 'text-foreground text-sm font-semibold' > Today's tasks</ h2 >
4043
41- < div className = 'flex items-center gap-2' >
42- < input
43- className = 'border-border bg-card text-foreground placeholder:text-muted-foreground flex-1 rounded-md border px-3 py-2 text-sm outline-none'
44- placeholder = 'What needs to be done?'
45- value = { value }
46- onChange = { ( event ) => setValue ( event . target . value ) }
47- onKeyDown = { ( event ) => {
48- if ( event . key === 'Enter' ) onAdd ( ) ;
49- } }
50- />
51- < button disabled = { ! value . trim ( ) } type = 'button' onClick = { onAdd } >
52- Add
53- </ button >
54- </ div >
44+ < form onSubmit = { onSubmit } >
45+ < div className = 'flex items-center gap-2' >
46+ < input
47+ className = 'border-border bg-card text-foreground placeholder:text-muted-foreground flex-1 rounded-md border px-3 py-2 text-sm outline-none'
48+ placeholder = 'What needs to be done?'
49+ value = { value }
50+ onChange = { ( event ) => setValue ( event . target . value ) }
51+ />
52+ < button disabled = { ! value . trim ( ) } type = 'submit' >
53+ Add
54+ </ button >
55+ </ div >
56+ </ form >
5557
5658 < div className = 'flex flex-col' >
5759 { todos . value . map ( ( todo , index ) => (
5860 < div
5961 key = { todo . id }
60- className = 'group hover:bg-muted/40 -mx-2 flex items-center gap-3 rounded-md px-2 py-2 transition-colors'
62+ className = 'group hover:bg-muted/40 -mx-2 flex items-center gap-3 rounded-md px-1 py-2 transition-colors'
6163 >
6264 < label className = 'flex shrink-0 cursor-pointer items-center' >
6365 < input
@@ -86,7 +88,7 @@ const Demo = () => {
8688
8789 < button
8890 aria-label = 'Remove'
89- className = 'rounded-full! opacity-0 transition-opacity group-hover:opacity-100'
91+ className = 'opacity-0 transition-opacity group-hover:opacity-100'
9092 data-size = 'icon'
9193 data-variant = 'ghost'
9294 type = 'button'
@@ -99,9 +101,8 @@ const Demo = () => {
99101 </ div >
100102
101103 < span className = 'text-muted-foreground px-1 text-[10px]' >
102- { remaining === 0
103- ? 'All done β nice work β¨'
104- : `${ remaining } ${ remaining === 1 ? 'task' : 'tasks' } left` }
104+ { ! remaining && 'All done β nice work β¨' }
105+ { remaining && `${ remaining } ${ remaining === 1 ? 'task' : 'tasks' } left` }
105106 </ span >
106107 </ section >
107108 ) ;
0 commit comments