Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
64 lines
1.8 KiB
Plaintext
64 lines
1.8 KiB
Plaintext
'use client';
|
|
|
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
import { getTranslation } from '@payloadcms/translations';
|
|
import { Button } from '../../elements/Button/index.js';
|
|
import { Popup, PopupList } from '../Popup/index.js';
|
|
export const AddNewButton = ({
|
|
allowCreate,
|
|
baseClass,
|
|
buttonStyle,
|
|
className,
|
|
collections,
|
|
i18n,
|
|
icon,
|
|
label,
|
|
onClick,
|
|
permissions,
|
|
relationTo
|
|
}) => {
|
|
if (!allowCreate) {
|
|
return null;
|
|
}
|
|
const isPolymorphic = Array.isArray(relationTo);
|
|
if (!isPolymorphic) {
|
|
return /*#__PURE__*/_jsx(Button, {
|
|
buttonStyle: buttonStyle,
|
|
className: className,
|
|
onClick: () => onClick(),
|
|
children: label
|
|
});
|
|
}
|
|
return /*#__PURE__*/_jsx("div", {
|
|
className: `${baseClass}__add-new-polymorphic-wrapper`,
|
|
children: /*#__PURE__*/_jsx(Popup, {
|
|
button: /*#__PURE__*/_jsx(Button, {
|
|
buttonStyle: buttonStyle,
|
|
className: className,
|
|
icon: icon,
|
|
children: label
|
|
}),
|
|
buttonType: "custom",
|
|
horizontalAlign: "center",
|
|
render: ({
|
|
close: closePopup
|
|
}) => /*#__PURE__*/_jsx(PopupList.ButtonGroup, {
|
|
children: relationTo.map(relatedCollection => {
|
|
if (permissions.collections[relatedCollection]?.create) {
|
|
return /*#__PURE__*/_jsx(PopupList.Button, {
|
|
className: `${baseClass}__relation-button--${relatedCollection}`,
|
|
onClick: () => {
|
|
closePopup();
|
|
onClick(relatedCollection);
|
|
},
|
|
children: getTranslation(collections.find(each => each.slug === relatedCollection).labels.singular, i18n)
|
|
}, relatedCollection);
|
|
}
|
|
return null;
|
|
})
|
|
}),
|
|
size: "medium"
|
|
})
|
|
});
|
|
};
|
|
//# sourceMappingURL=AddNewButton.js.map |