diff --git a/.tooling/components/ui/calendar.tsx b/.tooling/components/ui/calendar.tsx index 334849a..50d4290 100644 --- a/.tooling/components/ui/calendar.tsx +++ b/.tooling/components/ui/calendar.tsx @@ -12,12 +12,14 @@ type CalendarSingleProps = CalendarBaseProps & { mode: "single"; selected?: Date; onSelect?: (date: Date | undefined) => void; + initialFocus?: boolean; }; type CalendarRangeProps = CalendarBaseProps & { mode: "range"; selected?: CalendarDateRange; onSelect?: (range: CalendarDateRange | undefined) => void; + initialFocus?: boolean; }; export type CalendarProps = CalendarSingleProps | CalendarRangeProps; diff --git a/.tooling/components/ui/scroll-area.tsx b/.tooling/components/ui/scroll-area.tsx new file mode 100644 index 0000000..c31fc13 --- /dev/null +++ b/.tooling/components/ui/scroll-area.tsx @@ -0,0 +1,14 @@ +import type { HTMLAttributes } from "react"; +import { cn } from "@/lib/utils"; + +export function ScrollArea({ className, ...props }: HTMLAttributes) { + return
; +} + +export function ScrollBar({ + className, + orientation, + ...props +}: HTMLAttributes & { orientation?: "horizontal" | "vertical" }) { + return
; +} diff --git a/README.md b/README.md index 1c79ed6..4d7805f 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,7 @@ kri-select kri-date-range-picker kri-date-picker kri-date-time-picker +kri-time-picker kri-password kri-auto-complete kri-data-table @@ -46,6 +47,7 @@ npx shadcn@latest add https://ui-registry.kric.com/r/kri-password.json npx shadcn@latest add https://ui-registry.kric.com/r/kri-date-range-picker.json npx shadcn@latest add https://ui-registry.kric.com/r/kri-date-picker.json npx shadcn@latest add https://ui-registry.kric.com/r/kri-date-time-picker.json +npx shadcn@latest add https://ui-registry.kric.com/r/kri-time-picker.json npx shadcn@latest add https://ui-registry.kric.com/r/kri-auto-complete.json npx shadcn@latest add https://ui-registry.kric.com/r/kri-data-table.json npx shadcn@latest add https://ui-registry.kric.com/r/kri-loading-overlay.json diff --git a/package.json b/package.json index a7dbeb3..7dafa7e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kri-ui-registry", - "version": "0.3.1", + "version": "0.4.0", "private": true, "description": "KRI internal shadcn UI registry", "scripts": { diff --git a/registry/components/KriDateTimePicker.tsx b/registry/components/KriDateTimePicker.tsx index bacf888..ffa1c0c 100644 --- a/registry/components/KriDateTimePicker.tsx +++ b/registry/components/KriDateTimePicker.tsx @@ -1,10 +1,11 @@ 'use client' +import * as React from 'react' import { CalendarIcon, X } from 'lucide-react' import { Button } from '@/components/ui/button' import { Calendar } from '@/components/ui/calendar' -import { Input } from '@/components/ui/input' import { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover' +import { KriTimePicker } from '@/components/common/KriTimePicker' import { cn } from '@/lib/utils' export type KriDateTimePickerProps = { @@ -17,7 +18,6 @@ export type KriDateTimePickerProps = { disabled?: boolean } -// value는 과 동일한 'yyyy-MM-ddTHH:mm' 포맷을 쓴다 const parseDateTime = (value: string): { date: Date | undefined; time: string } => { if (!value) return { date: undefined, time: '' } @@ -33,14 +33,28 @@ const parseDateTime = (value: string): { date: Date | undefined; time: string } return { date, time: timePart } } -const toValue = (date: Date | undefined, time: string): string => { +const formatDate = (date: Date | undefined) => { if (!date) return '' const year = date.getFullYear() const month = String(date.getMonth() + 1).padStart(2, '0') const day = String(date.getDate()).padStart(2, '0') - return `${year}-${month}-${day}T${time || '00:00'}` + return `${year}-${month}-${day}` +} + +const toValue = (date: Date | undefined, time: string): string => { + const dateText = formatDate(date) + if (!dateText) return '' + + return `${dateText}T${time || '00:00'}` +} + +const toDisplayText = (date: Date | undefined, time: string, placeholder: string) => { + const dateText = formatDate(date) + if (!dateText) return placeholder + + return `${dateText} ${time || '00:00'}` } export function KriDateTimePicker({ @@ -52,45 +66,63 @@ export function KriDateTimePicker({ contentClassName, disabled = false, }: KriDateTimePickerProps) { + const [open, setOpen] = React.useState(false) const { date, time } = parseDateTime(value) const hasValue = date !== undefined + const handleDateSelect = (nextDate: Date | undefined) => { + if (!nextDate) return + onChange(toValue(nextDate, time || '00:00')) + } + + const handleTimeChange = (nextTime: string) => { + if (!date) return + onChange(toValue(date, nextTime)) + } + return ( -
- +
+ - onChange(toValue(nextDate, time || '00:00'))} /> +
+ + +
- onChange(toValue(date, event.target.value))} - /> - {hasValue && !disabled ? ( + ))} +
+ + + + +
+ {minutes.map((minute) => ( + + ))} +
+ +
+
+ ) +} + +export default KriTimePicker diff --git a/registry/components/registry.json b/registry/components/registry.json index f31e74a..7cc8d8e 100644 --- a/registry/components/registry.json +++ b/registry/components/registry.json @@ -67,8 +67,8 @@ "registryDependencies": [ "button", "calendar", - "input", - "popover" + "popover", + "scroll-area" ], "dependencies": [ "lucide-react" @@ -78,6 +78,28 @@ "path": "KriDateTimePicker.tsx", "type": "registry:component", "target": "@components/common/KriDateTimePicker.tsx" + }, + { + "path": "KriTimePicker.tsx", + "type": "registry:component", + "target": "@components/common/KriTimePicker.tsx" + } + ] + }, + { + "name": "kri-time-picker", + "type": "registry:component", + "title": "KRI Time Picker", + "description": "KRI common 24-hour time picker component.", + "registryDependencies": [ + "button", + "scroll-area" + ], + "files": [ + { + "path": "KriTimePicker.tsx", + "type": "registry:component", + "target": "@components/common/KriTimePicker.tsx" } ] },