Wraps Payload's group field in a Collapsible so long groups (e.g. profile minigames) can start collapsed in the admin panel; refreshes the import map. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
40 lines
1.4 KiB
TypeScript
40 lines
1.4 KiB
TypeScript
"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 (
|
|
<Collapsible header={<h3 className="group-field__title">{title}</h3>} initCollapsed={initCollapsed}>
|
|
<GroupField {...props} field={{ ...field, label: undefined }} />
|
|
</Collapsible>
|
|
);
|
|
};
|
|
|
|
export default CollapsibleGroupField;
|