Skip to content

Commit 4b69b3e

Browse files
committed
main 🧊 add new demos
1 parent bcd89a6 commit 4b69b3e

4 files changed

Lines changed: 45 additions & 43 deletions

File tree

β€Žpackages/core/src/hooks/useList/useList.demo.tsxβ€Ž

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { SubmitEvent } from 'react';
2+
13
import { useList } from '@siberiacancode/reactuse';
24
import { CheckIcon, XIcon } from 'lucide-react';
35
import { useState } from 'react';
@@ -19,7 +21,8 @@ const Demo = () => {
1921

2022
const [value, setValue] = useState('');
2123

22-
const onAdd = () => {
24+
const onSubmit = (event: SubmitEvent<HTMLFormElement>) => {
25+
event.preventDefault();
2326
const text = value.trim();
2427
if (!text) return;
2528
todos.push({ id: crypto.randomUUID(), text, done: false });
@@ -36,26 +39,25 @@ const Demo = () => {
3639
<section className='flex w-full max-w-sm flex-col gap-3 p-4'>
3740
<h2 className='text-foreground text-sm font-semibold'>Today's tasks</h2>
3841

39-
<div className='flex items-center gap-2'>
40-
<input
41-
className='border-border bg-card text-foreground placeholder:text-muted-foreground flex-1 rounded-md border px-3 py-2 text-sm outline-none'
42-
placeholder='What needs to be done?'
43-
value={value}
44-
onChange={(event) => setValue(event.target.value)}
45-
onKeyDown={(event) => {
46-
if (event.key === 'Enter') onAdd();
47-
}}
48-
/>
49-
<button disabled={!value.trim()} type='button' onClick={onAdd}>
50-
Add
51-
</button>
52-
</div>
42+
<form onSubmit={onSubmit}>
43+
<div className='flex items-center gap-2'>
44+
<input
45+
className='border-border bg-card text-foreground placeholder:text-muted-foreground flex-1 rounded-md border px-3 py-2 text-sm outline-none'
46+
placeholder='What needs to be done?'
47+
value={value}
48+
onChange={(event) => setValue(event.target.value)}
49+
/>
50+
<button disabled={!value.trim()} type='submit'>
51+
Add
52+
</button>
53+
</div>
54+
</form>
5355

5456
<div className='flex flex-col'>
5557
{todos.value.map((todo, index) => (
5658
<div
5759
key={todo.id}
58-
className='group hover:bg-muted/40 -mx-2 flex items-center gap-3 rounded-md px-2 py-2 transition-colors'
60+
className='group hover:bg-muted/40 -mx-2 flex items-center gap-3 rounded-md px-1 py-2 transition-colors'
5961
>
6062
<label className='flex shrink-0 cursor-pointer items-center'>
6163
<input
@@ -84,7 +86,7 @@ const Demo = () => {
8486

8587
<button
8688
aria-label='Remove'
87-
className='rounded-full! opacity-0 transition-opacity group-hover:opacity-100'
89+
className='opacity-0 transition-opacity group-hover:opacity-100'
8890
data-size='icon'
8991
data-variant='ghost'
9092
type='button'
@@ -97,9 +99,8 @@ const Demo = () => {
9799
</div>
98100

99101
<span className='text-muted-foreground px-1 text-[10px]'>
100-
{remaining === 0
101-
? 'All done β€” nice work ✨'
102-
: `${remaining} ${remaining === 1 ? 'task' : 'tasks'} left`}
102+
{!remaining && 'All done β€” nice work ✨'}
103+
{remaining && `${remaining} ${remaining === 1 ? 'task' : 'tasks'} left`}
103104
</span>
104105
</section>
105106
);

β€Žpackages/newdocs/content/functions/hooks/useList.meta.jsonβ€Ž

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

β€Žpackages/newdocs/generated/demos/hooks/useList.demo.tsxβ€Ž

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use client'
22

3+
import type { SubmitEvent } from 'react';
4+
35
import { useList } from '@siberiacancode/reactuse';
46
import { CheckIcon, XIcon } from 'lucide-react';
57
import { 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
);

β€Žpackages/newdocs/styles/global.cssβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@
518518
@apply text-sm font-semibold tracking-tight;
519519
}
520520

521-
.demo-ui input {
521+
.demo-ui input:not([type='checkbox']):not([type='radio']):not([type='range']) {
522522
@apply border-input h-8 w-full min-w-0 rounded-lg border bg-transparent px-2.5 py-1 text-base transition-colors outline-none;
523523
@apply file:text-foreground file:inline-flex file:h-6 file:border-0 file:bg-transparent file:text-sm file:font-medium;
524524
@apply placeholder:text-muted-foreground;
@@ -540,7 +540,7 @@
540540
.demo-ui button {
541541
@apply inline-flex shrink-0 items-center justify-center gap-1.5 rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-all outline-none select-none;
542542
@apply focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-3;
543-
@apply active:not-aria-[haspopup]:translate-y-px;
543+
@apply active:not-aria-[haspopup]:[translate:0_1px];
544544
@apply disabled:pointer-events-none disabled:opacity-50;
545545
@apply aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 aria-invalid:ring-3;
546546
}

0 commit comments

Comments
Β (0)