From 87a6e6e7659dad6db2af064d3742b29992237aef Mon Sep 17 00:00:00 2001 From: Lero Date: Wed, 7 Oct 2026 20:22:40 +0300 Subject: [PATCH] feat: let a date node pick a time --- .../src/components/JsonBuilderSettings.tsx | 28 +++++++++++++------ .../src/components/JsonInput.tsx | 5 ++++ .../src/components/JsonNode.tsx | 1 + .../src/field/checks.ts | 1 + .../src/field/typedJson.ts | 1 + 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/packages/payload-plugin-json-form-builder/src/components/JsonBuilderSettings.tsx b/packages/payload-plugin-json-form-builder/src/components/JsonBuilderSettings.tsx index afa85898..b0f0455b 100644 --- a/packages/payload-plugin-json-form-builder/src/components/JsonBuilderSettings.tsx +++ b/packages/payload-plugin-json-form-builder/src/components/JsonBuilderSettings.tsx @@ -6,7 +6,7 @@ import { toWords } from "payload/shared"; import { IconButton } from "./IconButton.js"; import { JsonInput } from "./JsonInput.js"; import { holdsFields } from "../field/typedJson.js"; -import type { TypedNode } from "../field/typedJson.js"; +import type { Leaf, TypedNode } from "../field/typedJson.js"; type Settings = { node: TypedNode; onChange: (node: TypedNode) => void }; @@ -19,13 +19,25 @@ const put = (node: TypedNode, key: string, value: unknown) => ({ ...node, [key]: value }) as TypedNode; const Starts = ({ node, onChange }: Settings) => ( - onChange(put(node, "value", next))} - value={"value" in node ? node.value : undefined} - /> + <> + + onChange((node as Leaf).time ? without(node, "time") : put(node, "time", true)) + } + /> + onChange(put(node, "value", next))} + time={(node as Leaf).time} + value={"value" in node ? node.value : undefined} + /> + ); const Limit = ({ node, onChange, name }: Settings & { name: string }) => ( diff --git a/packages/payload-plugin-json-form-builder/src/components/JsonInput.tsx b/packages/payload-plugin-json-form-builder/src/components/JsonInput.tsx index cae902f9..d873bd77 100644 --- a/packages/payload-plugin-json-form-builder/src/components/JsonInput.tsx +++ b/packages/payload-plugin-json-form-builder/src/components/JsonInput.tsx @@ -15,6 +15,7 @@ export const JsonInput = ({ onChange, readOnly, required, + time, value, }: { fault?: string; @@ -26,6 +27,7 @@ export const JsonInput = ({ onChange: (value: string | number | null) => void; readOnly?: boolean; required?: boolean; + time?: boolean; value: unknown; }) => { if (kind === "number") { @@ -62,9 +64,12 @@ export const JsonInput = ({ return (
{label ? : null} + {/* Payload's "default" appearance overwrites whatever time was picked with noon, so a date + node holds a time only while the picker is told to show one. */} onChange(next ? next.toISOString() : null)} + pickerAppearance={time ? "dayAndTime" : "default"} readOnly={readOnly} value={value ? String(value) : undefined} /> diff --git a/packages/payload-plugin-json-form-builder/src/components/JsonNode.tsx b/packages/payload-plugin-json-form-builder/src/components/JsonNode.tsx index 78a15c36..34eb74a3 100644 --- a/packages/payload-plugin-json-form-builder/src/components/JsonNode.tsx +++ b/packages/payload-plugin-json-form-builder/src/components/JsonNode.tsx @@ -229,6 +229,7 @@ export const JsonNode = ({ onChange={set} readOnly={readOnly} required={node.required} + time={node.time} value={value} /> ) : node.type === "checkbox" ? ( diff --git a/packages/payload-plugin-json-form-builder/src/field/checks.ts b/packages/payload-plugin-json-form-builder/src/field/checks.ts index cc9cc979..f6cf03de 100644 --- a/packages/payload-plugin-json-form-builder/src/field/checks.ts +++ b/packages/payload-plugin-json-form-builder/src/field/checks.ts @@ -123,6 +123,7 @@ const KEYS: Record = { rows: { kind: "array", needed: ["array"], only: ["array"] }, showIf: { kind: "object" }, source: { kind: "string" }, + time: { kind: "boolean", only: ["date"] }, type: { kind: "string" }, value: { kind: "any", needed: LEAVES, only: LEAVES, reads: "a field, not a group or a list" }, }; diff --git a/packages/payload-plugin-json-form-builder/src/field/typedJson.ts b/packages/payload-plugin-json-form-builder/src/field/typedJson.ts index 6f4431a7..dadb4d16 100644 --- a/packages/payload-plugin-json-form-builder/src/field/typedJson.ts +++ b/packages/payload-plugin-json-form-builder/src/field/typedJson.ts @@ -24,6 +24,7 @@ export type Leaf = Base & { options?: string[]; min?: number; max?: number; + time?: boolean; }; export type Container = Base & { type: "group" | "collapsible" | "tabs" | "tab";