moi-computer 0.11.1-next.0 → 0.11.1-next.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/AGENTS.md +2 -2
- package/client/components/ui/button.tsx +1 -53
- package/client/components/ui/collapsible.tsx +1 -15
- package/client/components/ui/dialog.tsx +1 -58
- package/client/components/ui/dropdown-menu.tsx +1 -254
- package/client/components/ui/hover-card.tsx +1 -44
- package/client/components/ui/input.tsx +1 -21
- package/client/components/ui/popover.tsx +1 -88
- package/client/components/ui/resizable.tsx +1 -40
- package/client/components/ui/skeleton.tsx +1 -13
- package/client/components/ui/slider.tsx +1 -70
- package/client/components/ui/spinner.tsx +1 -18
- package/client/components/ui/switch.tsx +1 -23
- package/client/components/ui/tabs.tsx +1 -0
- package/client/components/ui/textarea.tsx +1 -18
- package/client/components/ui/tooltip.tsx +1 -51
- package/client/features/chat/ChatPanel.tsx +6 -6
- package/client/features/chat/ChatPopup.tsx +3 -4
- package/client/features/chat/TurnView.tsx +5 -4
- package/client/features/chat/api.ts +5 -14
- package/client/features/chat/chat-frames.ts +9 -7
- package/client/features/chat/chat-send.ts +13 -2
- package/client/features/chat/chat-store.ts +1 -3
- package/client/features/chat/composer/ChatComposer.tsx +5 -1
- package/client/features/chat/composer/ModelPicker.tsx +44 -44
- package/client/features/chat/composer/banners/ErrorBanner.tsx +20 -12
- package/client/features/chat/composer/model-order.ts +15 -0
- package/client/features/chat/composer/useWorkspaceComposerState.tsx +15 -7
- package/client/features/chat/group-turns.ts +12 -0
- package/client/features/chat/interleave-notices.ts +7 -11
- package/client/features/chat/session-view.ts +53 -0
- package/client/features/chat/tool-group/ToolCallGroup.tsx +1 -4
- package/client/features/chat/tool-group/format/codex.ts +4 -1
- package/client/features/chat/useChat.ts +10 -9
- package/client/features/dev/ChatStatesPage.tsx +3 -1
- package/client/features/dev/DevIndexPage.tsx +5 -0
- package/client/features/dev/DevRoutes.tsx +2 -0
- package/client/features/dev/HarnessDebugPage.tsx +1 -1
- package/client/features/dev/UiComponentPreviews.tsx +834 -0
- package/client/features/dev/UiComponentsPage.tsx +60 -0
- package/client/features/home/WorkspacePreview.tsx +1 -1
- package/client/features/home/workspace-setup/DemoDialog.tsx +3 -2
- package/client/features/home/workspace-setup/ImportWorkspaceDialog.tsx +5 -8
- package/client/features/home/workspace-setup/WorkspaceDialogContent.tsx +7 -20
- package/client/features/settings/SettingsLayout.tsx +1 -1
- package/client/features/settings/WorkspaceSettings.tsx +4 -1
- package/client/features/views/ViewManager.tsx +14 -9
- package/client/features/widgets/WidgetFrame.tsx +1 -1
- package/client/features/widgets/Widgets.tsx +1 -3
- package/client/features/workspace/WorkspaceScreen.tsx +5 -1
- package/client/features/workspace/WorkspaceSplitLayout.tsx +6 -1
- package/client/features/workspace/api.ts +2 -4
- package/client/index.css +22 -29
- package/dist/chunk-245wt82v.css +1 -0
- package/dist/{chunk-tny85yt2.js → chunk-4s15axjs.js} +2 -2
- package/dist/{chunk-c9pjqx9m.js → chunk-53a7pxcz.js} +1 -1
- package/dist/{chunk-104m57qw.js → chunk-87thzbtw.js} +2 -2
- package/dist/chunk-a6jad1a6.js +1 -0
- package/dist/chunk-dghwstd2.js +9 -0
- package/dist/chunk-eg120aca.js +1 -0
- package/dist/{chunk-v7wr1df4.js → chunk-j3wvxjr7.js} +1 -1
- package/dist/chunk-j7hh2ab4.js +70 -0
- package/dist/chunk-w482ew2c.js +546 -0
- package/dist/chunk-y8eyahwx.js +1 -0
- package/dist/index.html +1 -1
- package/lib/format.ts +55 -6
- package/lib/themes.ts +6 -6
- package/lib/types.ts +10 -9
- package/package.json +12 -5
- package/registry.json +643 -0
- package/server/agent.ts +1 -1
- package/server/api.ts +26 -30
- package/server/applets.ts +30 -29
- package/server/bundler/applet-css.ts +7 -107
- package/server/bundler/build-applet.ts +5 -1
- package/server/bundler/build-worker.ts +178 -0
- package/server/cli-ui-components.ts +28 -33
- package/server/cli.ts +6 -11
- package/server/data-dir.ts +1 -1
- package/server/harness/README.md +41 -48
- package/server/harness/acp/NOTES.md +426 -0
- package/server/harness/acp/discovery.ts +27 -30
- package/server/harness/acp/model-state.ts +57 -0
- package/server/harness/acp/session.ts +18 -6
- package/server/harness/claude-code/NOTES.md +47 -12
- package/server/harness/claude-code/cli.ts +40 -0
- package/server/harness/claude-code/index.ts +11 -5
- package/server/harness/claude-code/models.ts +72 -19
- package/server/harness/claude-code/session.ts +408 -299
- package/server/harness/codex/NOTES.md +222 -350
- package/server/harness/codex/adapter.ts +94 -45
- package/server/harness/codex/auth.ts +1 -3
- package/server/harness/codex/client.ts +169 -249
- package/server/harness/codex/discovery.ts +9 -17
- package/server/harness/codex/index.ts +2 -1
- package/server/harness/codex/pagination.ts +24 -0
- package/server/harness/codex/permissions.ts +31 -7
- package/server/harness/codex/probe.ts +10 -13
- package/server/harness/codex/session.ts +549 -136
- package/server/harness/codex/transport.ts +184 -0
- package/server/harness/debug.ts +1 -1
- package/server/harness/hermes/NOTES.md +18 -0
- package/server/harness/hermes/discovery.ts +20 -0
- package/server/harness/hermes/index.ts +9 -0
- package/server/harness/hermes/models.ts +28 -8
- package/server/harness/types.ts +4 -2
- package/server/moi-scaffold.ts +1 -1
- package/server/preview.ts +3 -1
- package/server/registry.ts +63 -41
- package/server/tldraw-package.d.ts +4 -0
- package/server/ui-components.ts +101 -434
- package/server/view-builders.ts +2 -1
- package/server/web.ts +12 -5
- package/server/workspace-env.ts +3 -2
- package/tsconfig.json +0 -1
- package/ui-components/accordion.tsx +71 -0
- package/ui-components/alert-dialog.tsx +165 -0
- package/ui-components/alert.tsx +68 -0
- package/ui-components/attachment.tsx +195 -0
- package/ui-components/avatar.tsx +90 -0
- package/ui-components/badge.tsx +49 -0
- package/ui-components/button-group.tsx +78 -0
- package/ui-components/button.tsx +55 -0
- package/ui-components/calendar.tsx +180 -0
- package/ui-components/card.tsx +84 -0
- package/ui-components/carousel.tsx +235 -0
- package/ui-components/chart.tsx +338 -0
- package/ui-components/checkbox.tsx +28 -0
- package/ui-components/collapsible.tsx +15 -0
- package/ui-components/combobox.tsx +267 -0
- package/ui-components/context-menu.tsx +244 -0
- package/ui-components/dialog.tsx +138 -0
- package/ui-components/docs/accordion.md +463 -0
- package/ui-components/docs/alert-dialog.md +481 -0
- package/ui-components/docs/alert.md +301 -0
- package/ui-components/docs/attachment.md +689 -0
- package/ui-components/docs/avatar.md +495 -0
- package/ui-components/docs/badge.md +258 -0
- package/ui-components/docs/button-group.md +879 -0
- package/ui-components/docs/button.md +26 -0
- package/ui-components/docs/calendar.md +862 -0
- package/ui-components/docs/card.md +265 -0
- package/ui-components/docs/carousel.md +627 -0
- package/ui-components/docs/chart.md +1256 -0
- package/ui-components/docs/checkbox.md +477 -0
- package/ui-components/docs/collapsible.md +446 -0
- package/ui-components/docs/combobox.md +1003 -0
- package/ui-components/docs/context-menu.md +860 -0
- package/ui-components/docs/data-table.md +1580 -0
- package/ui-components/docs/date-picker.md +614 -0
- package/ui-components/docs/dialog.md +414 -0
- package/ui-components/docs/drawer.md +51 -0
- package/ui-components/docs/dropdown-menu.md +1000 -0
- package/ui-components/docs/field.md +1192 -0
- package/ui-components/docs/hover-card.md +275 -0
- package/ui-components/docs/input-group.md +866 -0
- package/ui-components/docs/input.md +456 -0
- package/ui-components/docs/label.md +295 -0
- package/ui-components/docs/pagination.md +416 -0
- package/ui-components/docs/popover.md +348 -0
- package/ui-components/docs/progress.md +214 -0
- package/ui-components/docs/radio-group.md +389 -0
- package/ui-components/docs/resizable.md +265 -0
- package/ui-components/docs/select.md +616 -0
- package/ui-components/docs/separator.md +216 -0
- package/ui-components/docs/skeleton.md +205 -0
- package/ui-components/docs/slider.md +226 -0
- package/ui-components/docs/spinner.md +332 -0
- package/ui-components/docs/switch.md +236 -0
- package/ui-components/docs/table.md +551 -0
- package/ui-components/docs/tabs.md +379 -0
- package/ui-components/docs/textarea.md +187 -0
- package/ui-components/docs/toggle-group.md +370 -0
- package/ui-components/docs/toggle.md +91 -0
- package/ui-components/docs/tooltip.md +290 -0
- package/ui-components/drawer.tsx +213 -0
- package/ui-components/dropdown-menu.tsx +263 -0
- package/ui-components/field.tsx +224 -0
- package/ui-components/hover-card.tsx +46 -0
- package/ui-components/input-group.tsx +146 -0
- package/ui-components/input.tsx +20 -0
- package/ui-components/label.tsx +17 -0
- package/ui-components/pagination.tsx +124 -0
- package/ui-components/popover.tsx +81 -0
- package/ui-components/progress.tsx +63 -0
- package/ui-components/radio-group.tsx +38 -0
- package/ui-components/resizable.tsx +40 -0
- package/ui-components/scoped-portal.tsx +31 -0
- package/ui-components/select.tsx +195 -0
- package/ui-components/separator.tsx +18 -0
- package/ui-components/skeleton.tsx +15 -0
- package/ui-components/slider.tsx +75 -0
- package/ui-components/spinner.tsx +20 -0
- package/ui-components/switch.tsx +27 -0
- package/ui-components/table.tsx +86 -0
- package/ui-components/tabs.tsx +75 -0
- package/ui-components/textarea.tsx +17 -0
- package/ui-components/toggle-group.tsx +85 -0
- package/ui-components/toggle.tsx +42 -0
- package/ui-components/tooltip.tsx +61 -0
- package/ui-components/utils.ts +8 -0
- package/workspace/.claude/skills/moi-workspace/SKILL.md +11 -20
- package/workspace/.claude/skills/moi-workspace/references/DESIGN.md +4 -3
- package/workspace/.claude/skills/moi-workspace/references/UI-COMPONENTS.md +67 -203
- package/dist/chunk-59zf0m6n.js +0 -1
- package/dist/chunk-bj3akjs2.js +0 -1
- package/dist/chunk-j2w2vak4.js +0 -546
- package/dist/chunk-k2r9c95m.js +0 -10
- package/dist/chunk-kmbxhgwv.js +0 -1
- package/dist/chunk-p1yqa71k.js +0 -83
- package/dist/chunk-r5xrenjy.css +0 -1
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Date Picker
|
|
3
|
+
description: A date picker component with range and presets.
|
|
4
|
+
base: base
|
|
5
|
+
component: true
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
```tsx
|
|
9
|
+
'use client'
|
|
10
|
+
|
|
11
|
+
import * as React from 'react'
|
|
12
|
+
import { format } from 'date-fns'
|
|
13
|
+
import { IconChevronDown } from '@tabler/icons-react'
|
|
14
|
+
|
|
15
|
+
import { Button } from '@/components/ui/button'
|
|
16
|
+
import { Calendar } from '@/components/ui/calendar'
|
|
17
|
+
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
|
18
|
+
|
|
19
|
+
export function DatePickerDemo() {
|
|
20
|
+
const [date, setDate] = React.useState<Date>()
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<Popover>
|
|
24
|
+
<PopoverTrigger
|
|
25
|
+
render={
|
|
26
|
+
<Button
|
|
27
|
+
variant={'outline'}
|
|
28
|
+
data-empty={!date}
|
|
29
|
+
className="w-[212px] justify-between text-left font-normal data-[empty=true]:text-muted-foreground"
|
|
30
|
+
/>
|
|
31
|
+
}
|
|
32
|
+
>
|
|
33
|
+
{date ? format(date, 'PPP') : <span>Pick a date</span>}
|
|
34
|
+
<IconChevronDown stroke={1.5} data-icon="inline-end" />
|
|
35
|
+
</PopoverTrigger>
|
|
36
|
+
<PopoverContent className="w-auto p-0" align="start">
|
|
37
|
+
<Calendar mode="single" selected={date} onSelect={setDate} defaultMonth={date} />
|
|
38
|
+
</PopoverContent>
|
|
39
|
+
</Popover>
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Installation
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
moi ui-components add date-picker
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
This recipe installs the `Popover`, `Calendar`, and `Button` components it uses.
|
|
51
|
+
|
|
52
|
+
## Usage
|
|
53
|
+
|
|
54
|
+
```tsx showLineNumbers title="components/example-date-picker.tsx"
|
|
55
|
+
'use client'
|
|
56
|
+
|
|
57
|
+
import * as React from 'react'
|
|
58
|
+
import { cn } from 'cn'
|
|
59
|
+
import { format } from 'date-fns'
|
|
60
|
+
import { IconCalendar } from '@tabler/icons-react'
|
|
61
|
+
|
|
62
|
+
import { Button } from '@/components/ui/button'
|
|
63
|
+
import { Calendar } from '@/components/ui/calendar'
|
|
64
|
+
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
|
65
|
+
|
|
66
|
+
export function DatePickerDemo() {
|
|
67
|
+
const [date, setDate] = React.useState<Date>()
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<Popover>
|
|
71
|
+
<PopoverTrigger
|
|
72
|
+
render={
|
|
73
|
+
<Button
|
|
74
|
+
variant="outline"
|
|
75
|
+
data-empty={!date}
|
|
76
|
+
className="justify-start text-left font-normal data-[empty=true]:text-muted-foreground"
|
|
77
|
+
/>
|
|
78
|
+
}
|
|
79
|
+
>
|
|
80
|
+
<IconCalendar stroke={1.5} />
|
|
81
|
+
{date ? format(date, 'PPP') : <span>Pick a date</span>}
|
|
82
|
+
</PopoverTrigger>
|
|
83
|
+
<PopoverContent className="w-auto p-0">
|
|
84
|
+
<Calendar mode="single" selected={date} onSelect={setDate} />
|
|
85
|
+
</PopoverContent>
|
|
86
|
+
</Popover>
|
|
87
|
+
)
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
See the [React DayPicker](https://react-day-picker.js.org) documentation for more information.
|
|
92
|
+
|
|
93
|
+
## Composition
|
|
94
|
+
|
|
95
|
+
A date picker is built from `Popover` and `Calendar` (there is no `DatePicker` root component):
|
|
96
|
+
|
|
97
|
+
```text
|
|
98
|
+
Popover
|
|
99
|
+
├── PopoverTrigger
|
|
100
|
+
└── PopoverContent
|
|
101
|
+
└── Calendar
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## Basic
|
|
105
|
+
|
|
106
|
+
A basic date picker component.
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
'use client'
|
|
110
|
+
|
|
111
|
+
import * as React from 'react'
|
|
112
|
+
import { format } from 'date-fns'
|
|
113
|
+
|
|
114
|
+
import { Button } from '@/components/ui/button'
|
|
115
|
+
import { Calendar } from '@/components/ui/calendar'
|
|
116
|
+
import { Field, FieldLabel } from '@/components/ui/field'
|
|
117
|
+
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
|
118
|
+
|
|
119
|
+
export function DatePickerSimple() {
|
|
120
|
+
const [date, setDate] = React.useState<Date>()
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<Field className="mx-auto w-44">
|
|
124
|
+
<FieldLabel htmlFor="date-picker-simple">Date</FieldLabel>
|
|
125
|
+
<Popover>
|
|
126
|
+
<PopoverTrigger
|
|
127
|
+
render={
|
|
128
|
+
<Button
|
|
129
|
+
variant="outline"
|
|
130
|
+
id="date-picker-simple"
|
|
131
|
+
className="justify-start font-normal"
|
|
132
|
+
/>
|
|
133
|
+
}
|
|
134
|
+
>
|
|
135
|
+
{date ? format(date, 'PPP') : <span>Pick a date</span>}
|
|
136
|
+
</PopoverTrigger>
|
|
137
|
+
<PopoverContent className="w-auto p-0" align="start">
|
|
138
|
+
<Calendar mode="single" selected={date} onSelect={setDate} defaultMonth={date} />
|
|
139
|
+
</PopoverContent>
|
|
140
|
+
</Popover>
|
|
141
|
+
</Field>
|
|
142
|
+
)
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Range Picker
|
|
147
|
+
|
|
148
|
+
A date picker component for selecting a range of dates.
|
|
149
|
+
|
|
150
|
+
```tsx
|
|
151
|
+
'use client'
|
|
152
|
+
|
|
153
|
+
import * as React from 'react'
|
|
154
|
+
import { addDays, format } from 'date-fns'
|
|
155
|
+
import { IconCalendar } from '@tabler/icons-react'
|
|
156
|
+
import { type DateRange } from 'react-day-picker'
|
|
157
|
+
|
|
158
|
+
import { Button } from '@/components/ui/button'
|
|
159
|
+
import { Calendar } from '@/components/ui/calendar'
|
|
160
|
+
import { Field, FieldLabel } from '@/components/ui/field'
|
|
161
|
+
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
|
162
|
+
|
|
163
|
+
export function DatePickerWithRange() {
|
|
164
|
+
const [date, setDate] = React.useState<DateRange | undefined>({
|
|
165
|
+
from: new Date(new Date().getFullYear(), 0, 20),
|
|
166
|
+
to: addDays(new Date(new Date().getFullYear(), 0, 20), 20)
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<Field className="mx-auto w-60">
|
|
171
|
+
<FieldLabel htmlFor="date-picker-range">Date Picker Range</FieldLabel>
|
|
172
|
+
<Popover>
|
|
173
|
+
<PopoverTrigger
|
|
174
|
+
render={
|
|
175
|
+
<Button
|
|
176
|
+
variant="outline"
|
|
177
|
+
id="date-picker-range"
|
|
178
|
+
className="justify-start px-2.5 font-normal"
|
|
179
|
+
/>
|
|
180
|
+
}
|
|
181
|
+
>
|
|
182
|
+
<IconCalendar stroke={1.5} data-icon="inline-start" />
|
|
183
|
+
{date?.from ? (
|
|
184
|
+
date.to ? (
|
|
185
|
+
<>
|
|
186
|
+
{format(date.from, 'LLL dd, y')} - {format(date.to, 'LLL dd, y')}
|
|
187
|
+
</>
|
|
188
|
+
) : (
|
|
189
|
+
format(date.from, 'LLL dd, y')
|
|
190
|
+
)
|
|
191
|
+
) : (
|
|
192
|
+
<span>Pick a date</span>
|
|
193
|
+
)}
|
|
194
|
+
</PopoverTrigger>
|
|
195
|
+
<PopoverContent className="w-auto p-0" align="start">
|
|
196
|
+
<Calendar
|
|
197
|
+
mode="range"
|
|
198
|
+
defaultMonth={date?.from}
|
|
199
|
+
selected={date}
|
|
200
|
+
onSelect={setDate}
|
|
201
|
+
numberOfMonths={2}
|
|
202
|
+
/>
|
|
203
|
+
</PopoverContent>
|
|
204
|
+
</Popover>
|
|
205
|
+
</Field>
|
|
206
|
+
)
|
|
207
|
+
}
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
## Date of Birth
|
|
211
|
+
|
|
212
|
+
A date picker component for selecting a date of birth. This component includes a dropdown caption layout for date and month selection.
|
|
213
|
+
|
|
214
|
+
```tsx
|
|
215
|
+
'use client'
|
|
216
|
+
|
|
217
|
+
import * as React from 'react'
|
|
218
|
+
|
|
219
|
+
import { Button } from '@/components/ui/button'
|
|
220
|
+
import { Calendar } from '@/components/ui/calendar'
|
|
221
|
+
import { Field, FieldLabel } from '@/components/ui/field'
|
|
222
|
+
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
|
223
|
+
|
|
224
|
+
export function DatePickerSimple() {
|
|
225
|
+
const [open, setOpen] = React.useState(false)
|
|
226
|
+
const [date, setDate] = React.useState<Date | undefined>(undefined)
|
|
227
|
+
|
|
228
|
+
return (
|
|
229
|
+
<Field className="mx-auto w-44">
|
|
230
|
+
<FieldLabel htmlFor="date">Date of birth</FieldLabel>
|
|
231
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
232
|
+
<PopoverTrigger
|
|
233
|
+
render={<Button variant="outline" id="date" className="justify-start font-normal" />}
|
|
234
|
+
>
|
|
235
|
+
{date ? date.toLocaleDateString() : 'Select date'}
|
|
236
|
+
</PopoverTrigger>
|
|
237
|
+
<PopoverContent className="w-auto overflow-hidden p-0" align="start">
|
|
238
|
+
<Calendar
|
|
239
|
+
mode="single"
|
|
240
|
+
selected={date}
|
|
241
|
+
defaultMonth={date}
|
|
242
|
+
captionLayout="dropdown"
|
|
243
|
+
onSelect={date => {
|
|
244
|
+
setDate(date)
|
|
245
|
+
setOpen(false)
|
|
246
|
+
}}
|
|
247
|
+
/>
|
|
248
|
+
</PopoverContent>
|
|
249
|
+
</Popover>
|
|
250
|
+
</Field>
|
|
251
|
+
)
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## Input
|
|
256
|
+
|
|
257
|
+
A date picker component with an input field for selecting a date.
|
|
258
|
+
|
|
259
|
+
```tsx
|
|
260
|
+
'use client'
|
|
261
|
+
|
|
262
|
+
import * as React from 'react'
|
|
263
|
+
import { IconCalendar } from '@tabler/icons-react'
|
|
264
|
+
|
|
265
|
+
import { Calendar } from '@/components/ui/calendar'
|
|
266
|
+
import { Field, FieldLabel } from '@/components/ui/field'
|
|
267
|
+
import {
|
|
268
|
+
InputGroup,
|
|
269
|
+
InputGroupAddon,
|
|
270
|
+
InputGroupButton,
|
|
271
|
+
InputGroupInput
|
|
272
|
+
} from '@/components/ui/input-group'
|
|
273
|
+
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
|
274
|
+
|
|
275
|
+
function formatDate(date: Date | undefined) {
|
|
276
|
+
if (!date) {
|
|
277
|
+
return ''
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
return date.toLocaleDateString('en-US', {
|
|
281
|
+
day: '2-digit',
|
|
282
|
+
month: 'long',
|
|
283
|
+
year: 'numeric'
|
|
284
|
+
})
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function isValidDate(date: Date | undefined) {
|
|
288
|
+
if (!date) {
|
|
289
|
+
return false
|
|
290
|
+
}
|
|
291
|
+
return !isNaN(date.getTime())
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
export function DatePickerInput() {
|
|
295
|
+
const [open, setOpen] = React.useState(false)
|
|
296
|
+
const [date, setDate] = React.useState<Date | undefined>(new Date('2025-06-01'))
|
|
297
|
+
const [month, setMonth] = React.useState<Date | undefined>(date)
|
|
298
|
+
const [value, setValue] = React.useState(formatDate(date))
|
|
299
|
+
|
|
300
|
+
return (
|
|
301
|
+
<Field className="mx-auto w-48">
|
|
302
|
+
<FieldLabel htmlFor="date-required">Subscription Date</FieldLabel>
|
|
303
|
+
<InputGroup>
|
|
304
|
+
<InputGroupInput
|
|
305
|
+
id="date-required"
|
|
306
|
+
value={value}
|
|
307
|
+
placeholder="June 01, 2025"
|
|
308
|
+
onChange={e => {
|
|
309
|
+
const date = new Date(e.target.value)
|
|
310
|
+
setValue(e.target.value)
|
|
311
|
+
if (isValidDate(date)) {
|
|
312
|
+
setDate(date)
|
|
313
|
+
setMonth(date)
|
|
314
|
+
}
|
|
315
|
+
}}
|
|
316
|
+
onKeyDown={e => {
|
|
317
|
+
if (e.key === 'ArrowDown') {
|
|
318
|
+
e.preventDefault()
|
|
319
|
+
setOpen(true)
|
|
320
|
+
}
|
|
321
|
+
}}
|
|
322
|
+
/>
|
|
323
|
+
<InputGroupAddon align="inline-end">
|
|
324
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
325
|
+
<PopoverTrigger
|
|
326
|
+
render={
|
|
327
|
+
<InputGroupButton
|
|
328
|
+
id="date-picker"
|
|
329
|
+
variant="ghost"
|
|
330
|
+
size="icon-xs"
|
|
331
|
+
aria-label="Select date"
|
|
332
|
+
/>
|
|
333
|
+
}
|
|
334
|
+
>
|
|
335
|
+
<IconCalendar stroke={1.5} />
|
|
336
|
+
<span className="sr-only">Select date</span>
|
|
337
|
+
</PopoverTrigger>
|
|
338
|
+
<PopoverContent
|
|
339
|
+
className="w-auto overflow-hidden p-0"
|
|
340
|
+
align="end"
|
|
341
|
+
alignOffset={-8}
|
|
342
|
+
sideOffset={10}
|
|
343
|
+
>
|
|
344
|
+
<Calendar
|
|
345
|
+
mode="single"
|
|
346
|
+
selected={date}
|
|
347
|
+
month={month}
|
|
348
|
+
onMonthChange={setMonth}
|
|
349
|
+
onSelect={date => {
|
|
350
|
+
setDate(date)
|
|
351
|
+
setValue(formatDate(date))
|
|
352
|
+
setOpen(false)
|
|
353
|
+
}}
|
|
354
|
+
/>
|
|
355
|
+
</PopoverContent>
|
|
356
|
+
</Popover>
|
|
357
|
+
</InputGroupAddon>
|
|
358
|
+
</InputGroup>
|
|
359
|
+
</Field>
|
|
360
|
+
)
|
|
361
|
+
}
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
## Time Picker
|
|
365
|
+
|
|
366
|
+
A date picker component with a time input field for selecting a time.
|
|
367
|
+
|
|
368
|
+
```tsx
|
|
369
|
+
'use client'
|
|
370
|
+
|
|
371
|
+
import * as React from 'react'
|
|
372
|
+
import { format } from 'date-fns'
|
|
373
|
+
import { IconChevronDown } from '@tabler/icons-react'
|
|
374
|
+
|
|
375
|
+
import { Button } from '@/components/ui/button'
|
|
376
|
+
import { Calendar } from '@/components/ui/calendar'
|
|
377
|
+
import { Field, FieldGroup, FieldLabel } from '@/components/ui/field'
|
|
378
|
+
import { Input } from '@/components/ui/input'
|
|
379
|
+
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
|
380
|
+
|
|
381
|
+
export function DatePickerTime() {
|
|
382
|
+
const [open, setOpen] = React.useState(false)
|
|
383
|
+
const [date, setDate] = React.useState<Date | undefined>(undefined)
|
|
384
|
+
|
|
385
|
+
return (
|
|
386
|
+
<FieldGroup className="mx-auto max-w-xs flex-row">
|
|
387
|
+
<Field>
|
|
388
|
+
<FieldLabel htmlFor="date-picker-optional">Date</FieldLabel>
|
|
389
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
390
|
+
<PopoverTrigger
|
|
391
|
+
render={
|
|
392
|
+
<Button
|
|
393
|
+
variant="outline"
|
|
394
|
+
id="date-picker-optional"
|
|
395
|
+
className="w-32 justify-between font-normal"
|
|
396
|
+
/>
|
|
397
|
+
}
|
|
398
|
+
>
|
|
399
|
+
{date ? format(date, 'PPP') : 'Select date'}
|
|
400
|
+
<IconChevronDown stroke={1.5} data-icon="inline-end" />
|
|
401
|
+
</PopoverTrigger>
|
|
402
|
+
<PopoverContent className="w-auto overflow-hidden p-0" align="start">
|
|
403
|
+
<Calendar
|
|
404
|
+
mode="single"
|
|
405
|
+
selected={date}
|
|
406
|
+
captionLayout="dropdown"
|
|
407
|
+
defaultMonth={date}
|
|
408
|
+
onSelect={date => {
|
|
409
|
+
setDate(date)
|
|
410
|
+
setOpen(false)
|
|
411
|
+
}}
|
|
412
|
+
/>
|
|
413
|
+
</PopoverContent>
|
|
414
|
+
</Popover>
|
|
415
|
+
</Field>
|
|
416
|
+
<Field className="w-32">
|
|
417
|
+
<FieldLabel htmlFor="time-picker-optional">Time</FieldLabel>
|
|
418
|
+
<Input
|
|
419
|
+
type="time"
|
|
420
|
+
id="time-picker-optional"
|
|
421
|
+
step="1"
|
|
422
|
+
defaultValue="10:30:00"
|
|
423
|
+
className="appearance-none bg-background [&::-webkit-calendar-picker-indicator]:hidden [&::-webkit-calendar-picker-indicator]:appearance-none"
|
|
424
|
+
/>
|
|
425
|
+
</Field>
|
|
426
|
+
</FieldGroup>
|
|
427
|
+
)
|
|
428
|
+
}
|
|
429
|
+
```
|
|
430
|
+
|
|
431
|
+
## Natural Language Picker
|
|
432
|
+
|
|
433
|
+
This component uses the `chrono-node` library to parse natural language dates.
|
|
434
|
+
|
|
435
|
+
```tsx
|
|
436
|
+
'use client'
|
|
437
|
+
|
|
438
|
+
import * as React from 'react'
|
|
439
|
+
import { parseDate } from 'chrono-node'
|
|
440
|
+
import { IconCalendar } from '@tabler/icons-react'
|
|
441
|
+
|
|
442
|
+
import { Calendar } from '@/components/ui/calendar'
|
|
443
|
+
import { Field, FieldLabel } from '@/components/ui/field'
|
|
444
|
+
import {
|
|
445
|
+
InputGroup,
|
|
446
|
+
InputGroupAddon,
|
|
447
|
+
InputGroupButton,
|
|
448
|
+
InputGroupInput
|
|
449
|
+
} from '@/components/ui/input-group'
|
|
450
|
+
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
|
451
|
+
|
|
452
|
+
function formatDate(date: Date | undefined) {
|
|
453
|
+
if (!date) {
|
|
454
|
+
return ''
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
return date.toLocaleDateString('en-US', {
|
|
458
|
+
day: '2-digit',
|
|
459
|
+
month: 'long',
|
|
460
|
+
year: 'numeric'
|
|
461
|
+
})
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
export function DatePickerNaturalLanguage() {
|
|
465
|
+
const [open, setOpen] = React.useState(false)
|
|
466
|
+
const [value, setValue] = React.useState('In 2 days')
|
|
467
|
+
const [date, setDate] = React.useState<Date | undefined>(parseDate(value) || undefined)
|
|
468
|
+
|
|
469
|
+
return (
|
|
470
|
+
<Field className="mx-auto max-w-xs">
|
|
471
|
+
<FieldLabel htmlFor="date-optional">Schedule Date</FieldLabel>
|
|
472
|
+
<InputGroup>
|
|
473
|
+
<InputGroupInput
|
|
474
|
+
id="date-optional"
|
|
475
|
+
value={value}
|
|
476
|
+
placeholder="Tomorrow or next week"
|
|
477
|
+
onChange={e => {
|
|
478
|
+
setValue(e.target.value)
|
|
479
|
+
const date = parseDate(e.target.value)
|
|
480
|
+
if (date) {
|
|
481
|
+
setDate(date)
|
|
482
|
+
}
|
|
483
|
+
}}
|
|
484
|
+
onKeyDown={e => {
|
|
485
|
+
if (e.key === 'ArrowDown') {
|
|
486
|
+
e.preventDefault()
|
|
487
|
+
setOpen(true)
|
|
488
|
+
}
|
|
489
|
+
}}
|
|
490
|
+
/>
|
|
491
|
+
<InputGroupAddon align="inline-end">
|
|
492
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
493
|
+
<PopoverTrigger
|
|
494
|
+
render={
|
|
495
|
+
<InputGroupButton
|
|
496
|
+
id="date-picker"
|
|
497
|
+
variant="ghost"
|
|
498
|
+
size="icon-xs"
|
|
499
|
+
aria-label="Select date"
|
|
500
|
+
/>
|
|
501
|
+
}
|
|
502
|
+
>
|
|
503
|
+
<IconCalendar stroke={1.5} />
|
|
504
|
+
<span className="sr-only">Select date</span>
|
|
505
|
+
</PopoverTrigger>
|
|
506
|
+
<PopoverContent className="w-auto overflow-hidden p-0" align="end" sideOffset={8}>
|
|
507
|
+
<Calendar
|
|
508
|
+
mode="single"
|
|
509
|
+
selected={date}
|
|
510
|
+
captionLayout="dropdown"
|
|
511
|
+
defaultMonth={date}
|
|
512
|
+
onSelect={date => {
|
|
513
|
+
setDate(date)
|
|
514
|
+
setValue(formatDate(date))
|
|
515
|
+
setOpen(false)
|
|
516
|
+
}}
|
|
517
|
+
/>
|
|
518
|
+
</PopoverContent>
|
|
519
|
+
</Popover>
|
|
520
|
+
</InputGroupAddon>
|
|
521
|
+
</InputGroup>
|
|
522
|
+
<div className="px-1 text-sm text-muted-foreground">
|
|
523
|
+
Your post will be published on <span className="font-medium">{formatDate(date)}</span>.
|
|
524
|
+
</div>
|
|
525
|
+
</Field>
|
|
526
|
+
)
|
|
527
|
+
}
|
|
528
|
+
```
|
|
529
|
+
|
|
530
|
+
## RTL
|
|
531
|
+
|
|
532
|
+
```tsx
|
|
533
|
+
'use client'
|
|
534
|
+
|
|
535
|
+
import * as React from 'react'
|
|
536
|
+
import { format } from 'date-fns'
|
|
537
|
+
import { arSA, he } from 'date-fns/locale'
|
|
538
|
+
import { IconChevronDown } from '@tabler/icons-react'
|
|
539
|
+
import { arSA as arSADayPicker, he as heDayPicker } from 'react-day-picker/locale'
|
|
540
|
+
|
|
541
|
+
import { useTranslation, type Translations } from '@/components/language-selector'
|
|
542
|
+
import { Button } from '@/components/ui/button'
|
|
543
|
+
import { Calendar } from '@/components/ui/calendar'
|
|
544
|
+
import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'
|
|
545
|
+
|
|
546
|
+
const translations: Translations = {
|
|
547
|
+
en: {
|
|
548
|
+
dir: 'ltr',
|
|
549
|
+
values: {
|
|
550
|
+
placeholder: 'Pick a date'
|
|
551
|
+
}
|
|
552
|
+
},
|
|
553
|
+
ar: {
|
|
554
|
+
dir: 'rtl',
|
|
555
|
+
values: {
|
|
556
|
+
placeholder: 'اختر تاريخًا'
|
|
557
|
+
}
|
|
558
|
+
},
|
|
559
|
+
he: {
|
|
560
|
+
dir: 'rtl',
|
|
561
|
+
values: {
|
|
562
|
+
placeholder: 'בחר תאריך'
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
|
|
567
|
+
const dayPickerLocales = {
|
|
568
|
+
ar: arSADayPicker,
|
|
569
|
+
he: heDayPicker
|
|
570
|
+
} as const
|
|
571
|
+
|
|
572
|
+
const dateFnsLocales = {
|
|
573
|
+
ar: arSA,
|
|
574
|
+
he: he
|
|
575
|
+
} as const
|
|
576
|
+
|
|
577
|
+
export function DatePickerRtl() {
|
|
578
|
+
const { dir, t, language } = useTranslation(translations, 'ar')
|
|
579
|
+
const [date, setDate] = React.useState<Date>()
|
|
580
|
+
|
|
581
|
+
const dateFnsLocale =
|
|
582
|
+
dir === 'rtl' ? dateFnsLocales[language as keyof typeof dateFnsLocales] : undefined
|
|
583
|
+
const dayPickerLocale =
|
|
584
|
+
dir === 'rtl' ? dayPickerLocales[language as keyof typeof dayPickerLocales] : undefined
|
|
585
|
+
|
|
586
|
+
return (
|
|
587
|
+
<Popover>
|
|
588
|
+
<PopoverTrigger
|
|
589
|
+
render={
|
|
590
|
+
<Button
|
|
591
|
+
variant={'outline'}
|
|
592
|
+
data-empty={!date}
|
|
593
|
+
className="w-[212px] justify-between text-left font-normal data-[empty=true]:text-muted-foreground"
|
|
594
|
+
dir={dir}
|
|
595
|
+
/>
|
|
596
|
+
}
|
|
597
|
+
>
|
|
598
|
+
{date ? format(date, 'PPP', { locale: dateFnsLocale }) : <span>{t.placeholder}</span>}
|
|
599
|
+
<IconChevronDown stroke={1.5} data-icon="inline-end" />
|
|
600
|
+
</PopoverTrigger>
|
|
601
|
+
<PopoverContent className="w-auto p-0" align="start" dir={dir}>
|
|
602
|
+
<Calendar
|
|
603
|
+
mode="single"
|
|
604
|
+
selected={date}
|
|
605
|
+
onSelect={setDate}
|
|
606
|
+
defaultMonth={date}
|
|
607
|
+
dir={dir}
|
|
608
|
+
locale={dayPickerLocale}
|
|
609
|
+
/>
|
|
610
|
+
</PopoverContent>
|
|
611
|
+
</Popover>
|
|
612
|
+
)
|
|
613
|
+
}
|
|
614
|
+
```
|