"use client"; import { getTranslation } from "@payloadcms/translations"; import { Collapsible, GroupField, useTranslation } from "@payloadcms/ui"; import type { GroupFieldClientProps } from "payload"; import React from "react"; type CollapsibleGroupFieldProps = GroupFieldClientProps & { /** Passed via `admin.components.Field` `clientProps` (groups don't support `admin.initCollapsed`). */ initCollapsed?: boolean; }; /** * Wraps Payload's stock group field in a Collapsible so named groups can be * collapsed in the admin panel (group fields have no built-in collapse UI). * Purely a presentation wrapper — the data shape is unchanged. * * Usage on a group field: * admin: { * components: { * Field: { * path: "@/components/admin/groups/CollapsibleGroupField", * clientProps: { initCollapsed: true }, * }, * }, * } */ export const CollapsibleGroupField = (props: CollapsibleGroupFieldProps) => { const { field, initCollapsed = false } = props; const { i18n } = useTranslation(); const title = getTranslation(field.label ?? ("name" in field ? field.name : "") ?? "", i18n); return ( {title}} initCollapsed={initCollapsed}> ); }; export default CollapsibleGroupField;