@squadbase/vantage 0.6.2-dev1.9d91dda → 0.6.2-dev1.ac99e02
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/dist/add-4GHF2TX2.js +6 -0
- package/dist/add-4GHF2TX2.js.map +1 -0
- package/dist/{build-TVKFIVFQ.js → build-MFWRPYKW.js} +7 -7
- package/dist/{build-TVKFIVFQ.js.map → build-MFWRPYKW.js.map} +1 -1
- package/dist/{check-3KHZXZMQ.js → check-ZBIH422T.js} +5 -5
- package/dist/{check-3KHZXZMQ.js.map → check-ZBIH422T.js.map} +1 -1
- package/dist/{chunk-P7W4LR3Z.js → chunk-7DZGJQ3P.js} +3 -3
- package/dist/{chunk-P7W4LR3Z.js.map → chunk-7DZGJQ3P.js.map} +1 -1
- package/dist/{chunk-U2M6HGKQ.js → chunk-AABMKHEU.js} +4 -4
- package/dist/{chunk-U2M6HGKQ.js.map → chunk-AABMKHEU.js.map} +1 -1
- package/dist/{chunk-NKFBFDRZ.js → chunk-AG6RZ2RR.js} +981 -14
- package/dist/chunk-AG6RZ2RR.js.map +1 -0
- package/dist/{chunk-QI3XQKHS.js → chunk-GNXCX4WE.js} +10 -3
- package/dist/chunk-GNXCX4WE.js.map +1 -0
- package/dist/chunk-IBGOCWJB.js +1716 -0
- package/dist/chunk-IBGOCWJB.js.map +1 -0
- package/dist/{chunk-RPZAALCX.js → chunk-OB6UBJXF.js} +153 -153
- package/dist/{chunk-RPZAALCX.js.map → chunk-OB6UBJXF.js.map} +1 -1
- package/dist/{chunk-LMUACBMA.js → chunk-QEWCYW3I.js} +43 -8
- package/dist/chunk-QEWCYW3I.js.map +1 -0
- package/dist/{chunk-ZVANIULZ.js → chunk-RNTDBX6S.js} +4 -4
- package/dist/{chunk-ZVANIULZ.js.map → chunk-RNTDBX6S.js.map} +1 -1
- package/dist/{chunk-PVTHHV7X.js → chunk-V3LF7BE7.js} +27 -5
- package/dist/chunk-V3LF7BE7.js.map +1 -0
- package/dist/{chunk-DTDVSFRY.js → chunk-XQUSGIDG.js} +17 -3
- package/dist/chunk-XQUSGIDG.js.map +1 -0
- package/dist/cli.js +12 -11
- package/dist/cli.js.map +1 -1
- package/dist/client/index.d.ts +32 -3
- package/dist/client/index.js +205 -12
- package/dist/client/index.js.map +1 -1
- package/dist/components/index.d.ts +216 -1
- package/dist/components/index.js +2 -2
- package/dist/{dev-GDKATCC7.js → dev-DCTOHQ6W.js} +8 -8
- package/dist/dev-DCTOHQ6W.js.map +1 -0
- package/dist/{docs-EJJ3BECT.js → docs-JVP4RPKT.js} +3 -3
- package/dist/{docs-EJJ3BECT.js.map → docs-JVP4RPKT.js.map} +1 -1
- package/dist/{doctor-WQXPXP6K.js → doctor-5E2VEZPK.js} +5 -5
- package/dist/{doctor-WQXPXP6K.js.map → doctor-5E2VEZPK.js.map} +1 -1
- package/dist/{preview-OGMCNQUO.js → preview-T6CLSQVX.js} +3 -3
- package/dist/{preview-OGMCNQUO.js.map → preview-T6CLSQVX.js.map} +1 -1
- package/dist/query/index.d.ts +0 -11
- package/dist/query/index.js +2 -2
- package/dist/{routes-MWBWWOJ2.js → routes-3SGAFDMC.js} +4 -4
- package/dist/{routes-MWBWWOJ2.js.map → routes-3SGAFDMC.js.map} +1 -1
- package/dist/{search-6Y422SV6.js → search-5LC4XPB5.js} +3 -3
- package/dist/{search-6Y422SV6.js.map → search-5LC4XPB5.js.map} +1 -1
- package/dist/table/index.js +7 -6
- package/dist/table/index.js.map +1 -1
- package/dist/ui/index.d.ts +140 -10
- package/dist/ui/index.js +1405 -63
- package/dist/ui/index.js.map +1 -1
- package/dist/{upgrade-HCANX4GQ.js → upgrade-DBBE6GIR.js} +6 -6
- package/dist/{upgrade-HCANX4GQ.js.map → upgrade-DBBE6GIR.js.map} +1 -1
- package/dist/vite/index.d.ts +10 -0
- package/dist/vite/index.js +3 -3
- package/docs/index.json +291 -61
- package/docs/ja/changelog.md +26 -0
- package/docs/ja/components.md +33 -89
- package/docs/ja/page-types/csv.md +83 -0
- package/docs/ja/page-types/doc.md +83 -0
- package/docs/ja/page-types/excel.md +82 -0
- package/docs/ja/page-types/slide.md +132 -0
- package/docs/ja/page-types.md +47 -0
- package/docs/ja/parts/area-chart.md +61 -0
- package/docs/ja/parts/bar-chart.md +69 -0
- package/docs/ja/parts/bar-list.md +35 -0
- package/docs/ja/parts/category-bar.md +36 -0
- package/docs/ja/parts/donut-chart.md +47 -0
- package/docs/ja/parts/echart.md +3 -0
- package/docs/ja/parts/line-chart.md +58 -0
- package/docs/ja/parts/progress-circle.md +34 -0
- package/docs/ja/parts/sparkline.md +1 -1
- package/docs/ja/parts/tracker.md +32 -0
- package/docs/ja/routing.md +8 -86
- package/docs/ja/ui/alert-dialog.md +41 -0
- package/docs/ja/ui/avatar.md +31 -0
- package/docs/ja/ui/combobox.md +74 -0
- package/docs/ja/ui/drawer.md +41 -0
- package/docs/ja/ui/field.md +42 -0
- package/docs/ja/ui/hover-card.md +21 -0
- package/docs/ja/ui/kbd.md +16 -0
- package/docs/ja/ui/pagination.md +36 -0
- package/docs/ja/ui/radio-group.md +21 -0
- package/docs/ja/ui/toast.md +46 -0
- package/docs/ja/ui-and-theming.md +14 -7
- package/package.json +21 -13
- package/registry/ui/accordion.tsx +74 -0
- package/registry/ui/alert-dialog.tsx +189 -0
- package/registry/ui/alert.tsx +78 -0
- package/registry/ui/app-shell.tsx +281 -0
- package/registry/ui/area-chart.tsx +1015 -0
- package/registry/ui/avatar.tsx +110 -0
- package/registry/ui/badge.tsx +54 -0
- package/registry/ui/bar-chart.tsx +1013 -0
- package/registry/ui/bar-list.tsx +302 -0
- package/registry/ui/breadcrumb.tsx +126 -0
- package/registry/ui/button.tsx +60 -0
- package/registry/ui/calendar.tsx +221 -0
- package/registry/ui/card.tsx +105 -0
- package/registry/ui/category-bar.tsx +281 -0
- package/registry/ui/checkbox.tsx +28 -0
- package/registry/ui/collapsible.tsx +21 -0
- package/registry/ui/combobox.tsx +310 -0
- package/registry/ui/command.tsx +196 -0
- package/registry/ui/dashboard-card.tsx +174 -0
- package/registry/ui/data-table.tsx +16 -91
- package/registry/ui/date-range-picker.tsx +209 -0
- package/registry/ui/dialog.tsx +159 -0
- package/registry/ui/donut-chart.tsx +1004 -0
- package/registry/ui/drawer.tsx +229 -0
- package/registry/ui/dropdown-menu.tsx +272 -0
- package/registry/ui/echart.tsx +486 -0
- package/registry/ui/field.tsx +240 -0
- package/registry/ui/filter-bar.tsx +365 -0
- package/registry/ui/funnel-steps.tsx +274 -0
- package/registry/ui/hover-card.tsx +52 -0
- package/registry/ui/input-group.tsx +158 -0
- package/registry/ui/input.tsx +22 -0
- package/registry/ui/kbd.tsx +28 -0
- package/registry/ui/label.tsx +20 -0
- package/registry/ui/line-chart.tsx +1007 -0
- package/registry/ui/metric-value.tsx +54 -0
- package/registry/ui/multi-select.tsx +226 -0
- package/registry/ui/page-shell.tsx +227 -0
- package/registry/ui/pagination.tsx +138 -0
- package/registry/ui/placeholder.tsx +30 -0
- package/registry/ui/popover.tsx +90 -0
- package/registry/ui/progress-circle.tsx +272 -0
- package/registry/ui/progress.tsx +83 -0
- package/registry/ui/radio-group.tsx +39 -0
- package/registry/ui/scroll-area.tsx +55 -0
- package/registry/ui/searchable-select.tsx +209 -0
- package/registry/ui/section-header.tsx +41 -0
- package/registry/ui/segmented-control.tsx +71 -0
- package/registry/ui/select.tsx +253 -0
- package/registry/ui/separator.tsx +25 -0
- package/registry/ui/sheet.tsx +137 -0
- package/registry/ui/sidebar.tsx +723 -0
- package/registry/ui/skeleton.tsx +15 -0
- package/registry/ui/slider.tsx +54 -0
- package/registry/ui/sparkline.tsx +155 -0
- package/registry/ui/spinner.tsx +12 -0
- package/registry/ui/states.tsx +61 -0
- package/registry/ui/status-badge.tsx +79 -0
- package/registry/ui/switch.tsx +32 -0
- package/registry/ui/table.tsx +116 -0
- package/registry/ui/tabs.tsx +82 -0
- package/registry/ui/textarea.tsx +20 -0
- package/registry/ui/toast.tsx +250 -0
- package/registry/ui/toggle-group.tsx +89 -0
- package/registry/ui/toggle.tsx +45 -0
- package/registry/ui/tooltip.tsx +66 -0
- package/registry/ui/tracker.tsx +236 -0
- package/registry/ui/trend-indicator.tsx +62 -0
- package/skills/vantage-add-feature/SKILL.md +9 -7
- package/skills/vantage-pitfalls/SKILL.md +5 -1
- package/templates/AGENTS.md +10 -1
- package/templates/agents/csv.md +2 -1
- package/templates/agents/doc.md +4 -3
- package/templates/agents/page.md +22 -8
- package/templates/agents/xlsx.md +2 -1
- package/dist/add-DY4AXANK.js +0 -6
- package/dist/add-DY4AXANK.js.map +0 -1
- package/dist/chunk-DTDVSFRY.js.map +0 -1
- package/dist/chunk-LMUACBMA.js.map +0 -1
- package/dist/chunk-NKFBFDRZ.js.map +0 -1
- package/dist/chunk-PVTHHV7X.js.map +0 -1
- package/dist/chunk-QI3XQKHS.js.map +0 -1
- package/dist/chunk-VA776YE5.js +0 -316
- package/dist/chunk-VA776YE5.js.map +0 -1
- package/dist/dev-GDKATCC7.js.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// Copied by `vantage add ui data-table`. This file is yours to edit.
|
|
2
|
+
// Generated from @squadbase/vantage src/components/data-table.tsx by `npm run registry` (in Vantage, edit src/, not registry/).
|
|
2
3
|
/**
|
|
3
4
|
* DataTable — a compound table over TanStack Table. `<DataTable>` owns the
|
|
4
5
|
* table instance and publishes it on context; the toolbar, body, pagination and
|
|
@@ -39,28 +40,18 @@ import {
|
|
|
39
40
|
} from "@tanstack/react-table"
|
|
40
41
|
import { ArrowDown, ArrowUp, ArrowUpDown, Columns3, Search } from "lucide-react"
|
|
41
42
|
|
|
43
|
+
import { cn } from "@squadbase/vantage/ui"
|
|
44
|
+
import { Button } from "@squadbase/vantage/ui"
|
|
45
|
+
import { Checkbox } from "@squadbase/vantage/ui"
|
|
42
46
|
import {
|
|
43
|
-
Button,
|
|
44
|
-
Checkbox,
|
|
45
47
|
DropdownMenu,
|
|
46
48
|
DropdownMenuCheckboxItem,
|
|
47
49
|
DropdownMenuContent,
|
|
48
50
|
DropdownMenuTrigger,
|
|
49
|
-
Input,
|
|
50
|
-
Select,
|
|
51
|
-
SelectContent,
|
|
52
|
-
SelectItem,
|
|
53
|
-
SelectTrigger,
|
|
54
|
-
SelectValue,
|
|
55
|
-
Table,
|
|
56
|
-
TableBody,
|
|
57
|
-
TableCell,
|
|
58
|
-
TableHead,
|
|
59
|
-
TableHeader,
|
|
60
|
-
TableRow,
|
|
61
|
-
cn,
|
|
62
51
|
} from "@squadbase/vantage/ui"
|
|
63
|
-
|
|
52
|
+
import { Input } from "@squadbase/vantage/ui"
|
|
53
|
+
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@squadbase/vantage/ui"
|
|
54
|
+
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@squadbase/vantage/ui"
|
|
64
55
|
|
|
65
56
|
/* ------------------------------------------------------------------- types */
|
|
66
57
|
|
|
@@ -152,40 +143,17 @@ export interface DataTableColumnVisibilityProps {
|
|
|
152
143
|
className?: string
|
|
153
144
|
}
|
|
154
145
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
sorting?: SortingState
|
|
161
|
-
onSortingChange?: OnChangeFn<SortingState>
|
|
162
|
-
|
|
163
|
-
enableFiltering?: boolean
|
|
164
|
-
columnFilters?: ColumnFiltersState
|
|
165
|
-
onColumnFiltersChange?: OnChangeFn<ColumnFiltersState>
|
|
166
|
-
globalFilter?: string
|
|
167
|
-
onGlobalFilterChange?: OnChangeFn<string>
|
|
168
|
-
|
|
169
|
-
enablePagination?: boolean
|
|
170
|
-
pagination?: PaginationState
|
|
171
|
-
onPaginationChange?: OnChangeFn<PaginationState>
|
|
172
|
-
pageCount?: number
|
|
173
|
-
|
|
174
|
-
enableRowSelection?: boolean
|
|
175
|
-
rowSelection?: RowSelectionState
|
|
176
|
-
onRowSelectionChange?: OnChangeFn<RowSelectionState>
|
|
177
|
-
|
|
146
|
+
/** The preset takes every `DataTable` prop except `children`, plus a few slots. */
|
|
147
|
+
export type DataTablePresetProps<TData, TValue> = Omit<
|
|
148
|
+
DataTableProps<TData, TValue>,
|
|
149
|
+
"children"
|
|
150
|
+
> & {
|
|
178
151
|
enableColumnVisibility?: boolean
|
|
179
|
-
columnVisibility?: VisibilityState
|
|
180
|
-
onColumnVisibilityChange?: OnChangeFn<VisibilityState>
|
|
181
152
|
columnLabels?: Record<string, string>
|
|
182
153
|
|
|
183
154
|
/** Extension slots */
|
|
184
155
|
toolbar?: ReactNode
|
|
185
156
|
bulkActions?: (selectedRows: TData[]) => ReactNode
|
|
186
|
-
|
|
187
|
-
meta?: TableMeta<TData>
|
|
188
|
-
className?: string
|
|
189
157
|
}
|
|
190
158
|
|
|
191
159
|
/* ------------------------------------------------------------------ helper */
|
|
@@ -532,7 +500,6 @@ export const DataTablePagination = forwardRef<HTMLDivElement, DataTablePaginatio
|
|
|
532
500
|
{totalRows}件中 {rangeStart} - {rangeEnd} を表示
|
|
533
501
|
</span>
|
|
534
502
|
<Select
|
|
535
|
-
items={Object.fromEntries(pageSizeOptions.map((size) => [String(size), `${size}件`]))}
|
|
536
503
|
value={String(currentPageSize)}
|
|
537
504
|
onValueChange={(value) => table.setPageSize(Number(value))}
|
|
538
505
|
>
|
|
@@ -635,31 +602,11 @@ DataTableColumnVisibility.displayName = "DataTableColumnVisibility"
|
|
|
635
602
|
|
|
636
603
|
/** The usual arrangement — toolbar, body and pagination — in one component. */
|
|
637
604
|
export function DataTablePreset<TData, TValue>({
|
|
638
|
-
columns,
|
|
639
|
-
data,
|
|
640
|
-
enableSorting,
|
|
641
|
-
sorting,
|
|
642
|
-
onSortingChange,
|
|
643
|
-
enableFiltering,
|
|
644
|
-
columnFilters,
|
|
645
|
-
onColumnFiltersChange,
|
|
646
|
-
globalFilter,
|
|
647
|
-
onGlobalFilterChange,
|
|
648
|
-
enablePagination,
|
|
649
|
-
pagination,
|
|
650
|
-
onPaginationChange,
|
|
651
|
-
pageCount,
|
|
652
|
-
enableRowSelection,
|
|
653
|
-
rowSelection,
|
|
654
|
-
onRowSelectionChange,
|
|
655
605
|
enableColumnVisibility = false,
|
|
656
|
-
columnVisibility,
|
|
657
|
-
onColumnVisibilityChange,
|
|
658
606
|
columnLabels,
|
|
659
607
|
toolbar,
|
|
660
608
|
bulkActions,
|
|
661
|
-
|
|
662
|
-
className,
|
|
609
|
+
...tableProps
|
|
663
610
|
}: DataTablePresetProps<TData, TValue>) {
|
|
664
611
|
const toolbarSlot =
|
|
665
612
|
toolbar || enableColumnVisibility ? (
|
|
@@ -670,36 +617,14 @@ export function DataTablePreset<TData, TValue>({
|
|
|
670
617
|
) : undefined
|
|
671
618
|
|
|
672
619
|
return (
|
|
673
|
-
<DataTable<TData, TValue>
|
|
674
|
-
columns={columns}
|
|
675
|
-
data={data}
|
|
676
|
-
enableSorting={enableSorting}
|
|
677
|
-
sorting={sorting}
|
|
678
|
-
onSortingChange={onSortingChange}
|
|
679
|
-
enableFiltering={enableFiltering}
|
|
680
|
-
columnFilters={columnFilters}
|
|
681
|
-
onColumnFiltersChange={onColumnFiltersChange}
|
|
682
|
-
globalFilter={globalFilter}
|
|
683
|
-
onGlobalFilterChange={onGlobalFilterChange}
|
|
684
|
-
enablePagination={enablePagination}
|
|
685
|
-
pagination={pagination}
|
|
686
|
-
onPaginationChange={onPaginationChange}
|
|
687
|
-
pageCount={pageCount}
|
|
688
|
-
enableRowSelection={enableRowSelection}
|
|
689
|
-
rowSelection={rowSelection}
|
|
690
|
-
onRowSelectionChange={onRowSelectionChange}
|
|
691
|
-
columnVisibility={columnVisibility}
|
|
692
|
-
onColumnVisibilityChange={onColumnVisibilityChange}
|
|
693
|
-
meta={meta}
|
|
694
|
-
className={className}
|
|
695
|
-
>
|
|
620
|
+
<DataTable<TData, TValue> {...tableProps}>
|
|
696
621
|
<DataTableToolbar
|
|
697
|
-
showSearch={enableFiltering}
|
|
622
|
+
showSearch={tableProps.enableFiltering}
|
|
698
623
|
toolbar={toolbarSlot}
|
|
699
624
|
bulkActions={bulkActions as ((selectedRows: unknown[]) => ReactNode) | undefined}
|
|
700
625
|
/>
|
|
701
626
|
<DataTableContent />
|
|
702
|
-
{enablePagination && <DataTablePagination />}
|
|
627
|
+
{tableProps.enablePagination && <DataTablePagination />}
|
|
703
628
|
</DataTable>
|
|
704
629
|
)
|
|
705
630
|
}
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
// Copied by `vantage add ui date-range-picker`. This file is yours to edit.
|
|
2
|
+
// Generated from @squadbase/vantage src/components/date-range-picker.tsx by `npm run registry` (in Vantage, edit src/, not registry/).
|
|
3
|
+
/**
|
|
4
|
+
* DateRangePicker — a range calendar in a popover with quick presets down the
|
|
5
|
+
* side. On mobile the presets stack above a single month; on desktop they sit
|
|
6
|
+
* beside a two-month view.
|
|
7
|
+
*/
|
|
8
|
+
import { forwardRef, useCallback, useState } from "react"
|
|
9
|
+
import { CalendarIcon } from "lucide-react"
|
|
10
|
+
import { endOfDay, endOfMonth, format, startOfDay, startOfMonth, subDays, subMonths } from "date-fns"
|
|
11
|
+
import { ja } from "date-fns/locale"
|
|
12
|
+
import type { DateRange as RdpDateRange } from "react-day-picker"
|
|
13
|
+
|
|
14
|
+
import { cn } from "@squadbase/vantage/ui"
|
|
15
|
+
import { useIsMobile } from "@squadbase/vantage/ui"
|
|
16
|
+
import { Button } from "@squadbase/vantage/ui"
|
|
17
|
+
import { Calendar } from "@squadbase/vantage/ui"
|
|
18
|
+
import { Popover, PopoverContent, PopoverTrigger } from "@squadbase/vantage/ui"
|
|
19
|
+
import type { DateRange, PresetItem } from "@squadbase/vantage/components"
|
|
20
|
+
|
|
21
|
+
export const defaultPresets: PresetItem[] = [
|
|
22
|
+
{
|
|
23
|
+
label: "Today",
|
|
24
|
+
getValue: () => {
|
|
25
|
+
const today = new Date()
|
|
26
|
+
return { from: startOfDay(today), to: endOfDay(today) }
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
label: "Yesterday",
|
|
31
|
+
getValue: () => {
|
|
32
|
+
const yesterday = subDays(new Date(), 1)
|
|
33
|
+
return { from: startOfDay(yesterday), to: endOfDay(yesterday) }
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
label: "Last 7 days",
|
|
38
|
+
getValue: () => {
|
|
39
|
+
const today = new Date()
|
|
40
|
+
return { from: startOfDay(subDays(today, 6)), to: endOfDay(today) }
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
label: "Last 14 days",
|
|
45
|
+
getValue: () => {
|
|
46
|
+
const today = new Date()
|
|
47
|
+
return { from: startOfDay(subDays(today, 13)), to: endOfDay(today) }
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
label: "Last 30 days",
|
|
52
|
+
getValue: () => {
|
|
53
|
+
const today = new Date()
|
|
54
|
+
return { from: startOfDay(subDays(today, 29)), to: endOfDay(today) }
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
label: "Last 90 days",
|
|
59
|
+
getValue: () => {
|
|
60
|
+
const today = new Date()
|
|
61
|
+
return { from: startOfDay(subDays(today, 89)), to: endOfDay(today) }
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
label: "This month",
|
|
66
|
+
getValue: () => {
|
|
67
|
+
const today = new Date()
|
|
68
|
+
return { from: startOfMonth(today), to: endOfDay(today) }
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
label: "Last month",
|
|
73
|
+
getValue: () => {
|
|
74
|
+
const lastMonth = subMonths(new Date(), 1)
|
|
75
|
+
return { from: startOfMonth(lastMonth), to: endOfMonth(lastMonth) }
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
]
|
|
79
|
+
|
|
80
|
+
export interface DateRangePickerProps {
|
|
81
|
+
/**
|
|
82
|
+
* 選択中の日付範囲。型は Vantage 独自の `DateRange`。
|
|
83
|
+
* react-day-picker の `DateRange` とは別物なので注意 — そちらが必要なら
|
|
84
|
+
* このファイルの末尾で re-export している `RdpDateRange` を使う。
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* import type { DateRange } from "@squadbase/vantage/components"
|
|
88
|
+
*
|
|
89
|
+
* const [range, setRange] = useState<DateRange | undefined>()
|
|
90
|
+
* <DateRangePicker value={range} onChange={setRange} />
|
|
91
|
+
*/
|
|
92
|
+
value?: DateRange
|
|
93
|
+
onChange?: (range: DateRange) => void
|
|
94
|
+
presets?: PresetItem[]
|
|
95
|
+
showPresets?: boolean
|
|
96
|
+
maxDate?: Date
|
|
97
|
+
minDate?: Date
|
|
98
|
+
placeholder?: string
|
|
99
|
+
disabled?: boolean
|
|
100
|
+
className?: string
|
|
101
|
+
align?: "start" | "center" | "end"
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
export const DateRangePicker = forwardRef<HTMLDivElement, DateRangePickerProps>(
|
|
105
|
+
function DateRangePicker(
|
|
106
|
+
{
|
|
107
|
+
value,
|
|
108
|
+
onChange,
|
|
109
|
+
presets = defaultPresets,
|
|
110
|
+
showPresets = true,
|
|
111
|
+
maxDate,
|
|
112
|
+
minDate,
|
|
113
|
+
placeholder = "Select date range",
|
|
114
|
+
disabled = false,
|
|
115
|
+
className,
|
|
116
|
+
align = "start",
|
|
117
|
+
},
|
|
118
|
+
ref,
|
|
119
|
+
) {
|
|
120
|
+
const [open, setOpen] = useState(false)
|
|
121
|
+
const isMobile = useIsMobile()
|
|
122
|
+
|
|
123
|
+
const handleCalendarSelect = useCallback(
|
|
124
|
+
(range: RdpDateRange | undefined) => {
|
|
125
|
+
onChange?.({ from: range?.from, to: range?.to })
|
|
126
|
+
},
|
|
127
|
+
[onChange],
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
const handlePresetClick = useCallback(
|
|
131
|
+
(preset: PresetItem) => {
|
|
132
|
+
onChange?.(preset.getValue())
|
|
133
|
+
setOpen(false)
|
|
134
|
+
},
|
|
135
|
+
[onChange],
|
|
136
|
+
)
|
|
137
|
+
|
|
138
|
+
const formatDateRange = () => {
|
|
139
|
+
if (!value?.from) return placeholder
|
|
140
|
+
if (!value.to) return format(value.from, "yyyy/MM/dd", { locale: ja })
|
|
141
|
+
return `${format(value.from, "yyyy/MM/dd", { locale: ja })} - ${format(value.to, "yyyy/MM/dd", { locale: ja })}`
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const calendarSelected: RdpDateRange | undefined = value?.from
|
|
145
|
+
? { from: value.from, to: value.to ?? undefined }
|
|
146
|
+
: undefined
|
|
147
|
+
|
|
148
|
+
return (
|
|
149
|
+
<div ref={ref} data-slot="date-range-picker">
|
|
150
|
+
<Popover open={open} onOpenChange={setOpen}>
|
|
151
|
+
<PopoverTrigger
|
|
152
|
+
render={
|
|
153
|
+
<Button
|
|
154
|
+
variant="outline"
|
|
155
|
+
disabled={disabled}
|
|
156
|
+
className={cn(
|
|
157
|
+
"w-auto justify-start text-left font-normal",
|
|
158
|
+
!value?.from && "text-muted-foreground",
|
|
159
|
+
className,
|
|
160
|
+
)}
|
|
161
|
+
/>
|
|
162
|
+
}
|
|
163
|
+
aria-label={formatDateRange()}
|
|
164
|
+
aria-expanded={open}
|
|
165
|
+
>
|
|
166
|
+
<CalendarIcon className="size-4" aria-hidden="true" />
|
|
167
|
+
<span>{formatDateRange()}</span>
|
|
168
|
+
</PopoverTrigger>
|
|
169
|
+
<PopoverContent
|
|
170
|
+
align={align}
|
|
171
|
+
className={cn("w-auto p-0", isMobile ? "flex flex-col" : "flex")}
|
|
172
|
+
>
|
|
173
|
+
{showPresets && (
|
|
174
|
+
<div className={cn("flex flex-col gap-1 p-3", isMobile ? "border-b" : "border-r")}>
|
|
175
|
+
{presets.map((preset) => (
|
|
176
|
+
<Button
|
|
177
|
+
key={preset.label}
|
|
178
|
+
variant="ghost"
|
|
179
|
+
size="sm"
|
|
180
|
+
className="justify-start text-xs"
|
|
181
|
+
onClick={() => handlePresetClick(preset)}
|
|
182
|
+
>
|
|
183
|
+
{preset.label}
|
|
184
|
+
</Button>
|
|
185
|
+
))}
|
|
186
|
+
</div>
|
|
187
|
+
)}
|
|
188
|
+
<div className="p-3">
|
|
189
|
+
<Calendar
|
|
190
|
+
mode="range"
|
|
191
|
+
numberOfMonths={isMobile ? 1 : 2}
|
|
192
|
+
selected={calendarSelected}
|
|
193
|
+
onSelect={handleCalendarSelect}
|
|
194
|
+
disabled={(date) => {
|
|
195
|
+
if (maxDate && date > maxDate) return true
|
|
196
|
+
if (minDate && date < minDate) return true
|
|
197
|
+
return false
|
|
198
|
+
}}
|
|
199
|
+
/>
|
|
200
|
+
</div>
|
|
201
|
+
</PopoverContent>
|
|
202
|
+
</Popover>
|
|
203
|
+
</div>
|
|
204
|
+
)
|
|
205
|
+
},
|
|
206
|
+
)
|
|
207
|
+
DateRangePicker.displayName = "DateRangePicker"
|
|
208
|
+
|
|
209
|
+
export type { DateRange as RdpDateRange } from "react-day-picker"
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
// Copied by `vantage add ui dialog`. This file is yours to edit.
|
|
2
|
+
// Generated from @squadbase/vantage src/ui/dialog.tsx by `npm run registry` (in Vantage, edit src/, not registry/).
|
|
3
|
+
import * as React from "react"
|
|
4
|
+
import { Dialog as DialogPrimitive } from "@base-ui/react/dialog"
|
|
5
|
+
|
|
6
|
+
import { cn } from "@squadbase/vantage/ui"
|
|
7
|
+
import { Button } from "@squadbase/vantage/ui"
|
|
8
|
+
import { XIcon } from "lucide-react"
|
|
9
|
+
|
|
10
|
+
function Dialog({ ...props }: DialogPrimitive.Root.Props) {
|
|
11
|
+
return <DialogPrimitive.Root data-slot="dialog" {...props} />
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
function DialogTrigger({ ...props }: DialogPrimitive.Trigger.Props) {
|
|
15
|
+
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function DialogPortal({ ...props }: DialogPrimitive.Portal.Props) {
|
|
19
|
+
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function DialogClose({ ...props }: DialogPrimitive.Close.Props) {
|
|
23
|
+
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function DialogOverlay({
|
|
27
|
+
className,
|
|
28
|
+
...props
|
|
29
|
+
}: DialogPrimitive.Backdrop.Props) {
|
|
30
|
+
return (
|
|
31
|
+
<DialogPrimitive.Backdrop
|
|
32
|
+
data-slot="dialog-overlay"
|
|
33
|
+
className={cn(
|
|
34
|
+
"fixed inset-0 isolate z-50 bg-black/10 duration-100 supports-backdrop-filter:backdrop-blur-xs data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0",
|
|
35
|
+
className
|
|
36
|
+
)}
|
|
37
|
+
{...props}
|
|
38
|
+
/>
|
|
39
|
+
)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function DialogContent({
|
|
43
|
+
className,
|
|
44
|
+
children,
|
|
45
|
+
showCloseButton = true,
|
|
46
|
+
...props
|
|
47
|
+
}: DialogPrimitive.Popup.Props & {
|
|
48
|
+
showCloseButton?: boolean
|
|
49
|
+
}) {
|
|
50
|
+
return (
|
|
51
|
+
<DialogPortal>
|
|
52
|
+
<DialogOverlay />
|
|
53
|
+
<DialogPrimitive.Popup
|
|
54
|
+
data-slot="dialog-content"
|
|
55
|
+
className={cn(
|
|
56
|
+
"fixed top-1/2 left-1/2 z-50 grid w-full max-w-[calc(100%-2rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-sm text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95",
|
|
57
|
+
className
|
|
58
|
+
)}
|
|
59
|
+
{...props}
|
|
60
|
+
>
|
|
61
|
+
{children}
|
|
62
|
+
{showCloseButton && (
|
|
63
|
+
<DialogPrimitive.Close
|
|
64
|
+
data-slot="dialog-close"
|
|
65
|
+
render={
|
|
66
|
+
<Button
|
|
67
|
+
variant="ghost"
|
|
68
|
+
className="absolute top-2 right-2"
|
|
69
|
+
size="icon-sm"
|
|
70
|
+
/>
|
|
71
|
+
}
|
|
72
|
+
>
|
|
73
|
+
<XIcon />
|
|
74
|
+
<span className="sr-only">Close</span>
|
|
75
|
+
</DialogPrimitive.Close>
|
|
76
|
+
)}
|
|
77
|
+
</DialogPrimitive.Popup>
|
|
78
|
+
</DialogPortal>
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function DialogHeader({ className, ...props }: React.ComponentProps<"div">) {
|
|
83
|
+
return (
|
|
84
|
+
<div
|
|
85
|
+
data-slot="dialog-header"
|
|
86
|
+
className={cn("flex flex-col gap-2", className)}
|
|
87
|
+
{...props}
|
|
88
|
+
/>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function DialogFooter({
|
|
93
|
+
className,
|
|
94
|
+
showCloseButton = false,
|
|
95
|
+
children,
|
|
96
|
+
...props
|
|
97
|
+
}: React.ComponentProps<"div"> & {
|
|
98
|
+
showCloseButton?: boolean
|
|
99
|
+
}) {
|
|
100
|
+
return (
|
|
101
|
+
<div
|
|
102
|
+
data-slot="dialog-footer"
|
|
103
|
+
className={cn(
|
|
104
|
+
"-mx-4 -mb-4 flex flex-col-reverse gap-2 rounded-b-xl border-t bg-muted/50 p-4 sm:flex-row sm:justify-end",
|
|
105
|
+
className
|
|
106
|
+
)}
|
|
107
|
+
{...props}
|
|
108
|
+
>
|
|
109
|
+
{children}
|
|
110
|
+
{showCloseButton && (
|
|
111
|
+
<DialogPrimitive.Close render={<Button variant="outline" />}>
|
|
112
|
+
Close
|
|
113
|
+
</DialogPrimitive.Close>
|
|
114
|
+
)}
|
|
115
|
+
</div>
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function DialogTitle({ className, ...props }: DialogPrimitive.Title.Props) {
|
|
120
|
+
return (
|
|
121
|
+
<DialogPrimitive.Title
|
|
122
|
+
data-slot="dialog-title"
|
|
123
|
+
className={cn(
|
|
124
|
+
"cn-font-heading text-base leading-none font-medium",
|
|
125
|
+
className
|
|
126
|
+
)}
|
|
127
|
+
{...props}
|
|
128
|
+
/>
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function DialogDescription({
|
|
133
|
+
className,
|
|
134
|
+
...props
|
|
135
|
+
}: DialogPrimitive.Description.Props) {
|
|
136
|
+
return (
|
|
137
|
+
<DialogPrimitive.Description
|
|
138
|
+
data-slot="dialog-description"
|
|
139
|
+
className={cn(
|
|
140
|
+
"text-sm text-muted-foreground *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground",
|
|
141
|
+
className
|
|
142
|
+
)}
|
|
143
|
+
{...props}
|
|
144
|
+
/>
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export {
|
|
149
|
+
Dialog,
|
|
150
|
+
DialogClose,
|
|
151
|
+
DialogContent,
|
|
152
|
+
DialogDescription,
|
|
153
|
+
DialogFooter,
|
|
154
|
+
DialogHeader,
|
|
155
|
+
DialogOverlay,
|
|
156
|
+
DialogPortal,
|
|
157
|
+
DialogTitle,
|
|
158
|
+
DialogTrigger,
|
|
159
|
+
}
|