diff --git a/lib/component/input/date/DateInput.tsx b/lib/component/input/date/DateInput.tsx new file mode 100644 index 0000000..57f78bc --- /dev/null +++ b/lib/component/input/date/DateInput.tsx @@ -0,0 +1,26 @@ +import type { DateInputProps } from "$/types/Input"; +import clsx from "clsx"; +import moment from "moment"; + + +export default function DateInput({ + id, + className, + defaultValue, + value, + onChange +}: DateInputProps){ + return ( + onChange?.(new Date(moment(e.target.value, "YYYY-MM-DD").toDate()))} + /> + ); +} diff --git a/lib/component/input/date/DateTimeInput.tsx b/lib/component/input/date/DateTimeInput.tsx new file mode 100644 index 0000000..0c1b3d5 --- /dev/null +++ b/lib/component/input/date/DateTimeInput.tsx @@ -0,0 +1,26 @@ +import type { DateInputProps } from "$/types/Input"; +import clsx from "clsx"; +import moment from "moment"; + + +export default function DateTimeInput({ + id, + className, + defaultValue, + value, + onChange +}: DateInputProps){ + return ( + onChange?.(new Date(moment(e.target.value, "YYYY-MM-DDTHH:mm").toDate()))} + /> + ); +} diff --git a/lib/component/input/date/TimeInput.tsx b/lib/component/input/date/TimeInput.tsx new file mode 100644 index 0000000..0104d4c --- /dev/null +++ b/lib/component/input/date/TimeInput.tsx @@ -0,0 +1,26 @@ +import type { DateInputProps } from "$/types/Input"; +import clsx from "clsx"; +import moment from "moment"; + + +export default function TimeInput({ + id, + className, + defaultValue, + value, + onChange +}: DateInputProps){ + return ( + onChange?.(new Date(moment(e.target.value, "YYYY-MM-DDTHH:mm").toDate()))} + /> + ); +} diff --git a/lib/types/Input.d.ts b/lib/types/Input.d.ts index 81ad384..82214d5 100644 --- a/lib/types/Input.d.ts +++ b/lib/types/Input.d.ts @@ -149,3 +149,12 @@ export interface RadioListProps { direction?: "vertical" | "horizontal"; children?: React.ReactNode; } + + +export interface DateInputProps { + id?: string; + className?: string; + defaultValue?: Date; + value?: Date; + onChange?: (newValue: Date) => void; +} diff --git a/package-lock.json b/package-lock.json index aceddf0..6621869 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,7 @@ "@tanstack/react-router-devtools": "^1.124.0", "@types/node": "^24.0.4", "clsx": "^2.1.1", + "moment": "^2.30.1", "react": "^19.1.0", "react-dom": "^19.1.0", "react-icons": "^5.5.0", @@ -4773,6 +4774,15 @@ "pathe": "^2.0.1" } }, + "node_modules/moment": { + "version": "2.30.1", + "resolved": "https://registry.npmjs.org/moment/-/moment-2.30.1.tgz", + "integrity": "sha512-uEmtNhbDOrWPFS+hdjFCBfy9f2YoyzRpwcl+DqpC6taX21FzsTLQVbMV/W7PzNSX6x/bhC1zA3c2UQ5NzH6how==", + "license": "MIT", + "engines": { + "node": "*" + } + }, "node_modules/ms": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz", diff --git a/package.json b/package.json index 687383d..10eafe5 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,7 @@ "@tanstack/react-router-devtools": "^1.124.0", "@types/node": "^24.0.4", "clsx": "^2.1.1", + "moment": "^2.30.1", "react": "^19.1.0", "react-dom": "^19.1.0", "react-icons": "^5.5.0", diff --git a/src/routes/input/index.tsx b/src/routes/input/index.tsx index e935a43..489004b 100644 --- a/src/routes/input/index.tsx +++ b/src/routes/input/index.tsx @@ -1,6 +1,6 @@ import { MattrixwvTabGroup } from "$/component/tab"; import type { TabGroupContent } from "$/types/Tab"; -import { CheckboxContent, FileContent, RadioContent, SwitchContent, TextContent } from "@/util/InputUtils"; +import { CheckboxContent, DateContent, FileContent, RadioContent, SwitchContent, TextContent } from "@/util/InputUtils"; import { createFileRoute } from "@tanstack/react-router"; @@ -13,6 +13,7 @@ function InputPage(){ const tabs: TabGroupContent[] = [ { tab: "Checkbox", content: }, { tab: "Radio", content: }, + { tab: "Date", content: }, { tab: "File", content: }, { tab: "Switch", content: }, { tab: "Text", content: } diff --git a/src/util/InputUtils.tsx b/src/util/InputUtils.tsx index aae5e40..c5f27e2 100644 --- a/src/util/InputUtils.tsx +++ b/src/util/InputUtils.tsx @@ -11,6 +11,9 @@ import SecondaryCheckbox from "$/component/input/checkbox/SecondaryCheckbox"; import SuccessCheckbox from "$/component/input/checkbox/SuccessCheckbox"; import TertiaryCheckbox from "$/component/input/checkbox/TertiaryCheckbox"; import WarningCheckbox from "$/component/input/checkbox/WarningCheckbox"; +import DateInput from "$/component/input/date/DateInput"; +import DateTimeInput from "$/component/input/date/DateTimeInput"; +import TimeInput from "$/component/input/date/TimeInput"; import DangerRadioButton from "$/component/input/radio/DangerRadioButton"; import DarkRadioButton from "$/component/input/radio/DarkRadioButton"; import InfoRadioButton from "$/component/input/radio/InfoRadioButton"; @@ -743,3 +746,18 @@ function RadioDisplay({ ); } + +export function DateContent(){ + return ( +
+ + + +
+ ); +}