UNPKG

ra-core

Version:

Core components of react-admin, a frontend Framework for building admin applications on top of REST services, using ES6, React

69 lines 2.68 kB
var __rest = (this && this.__rest) || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; import * as React from 'react'; import { useCreateController, } from "./useCreateController.js"; import { CreateContextProvider } from "./CreateContextProvider.js"; import { OptionalResourceContextProvider } from "../../core/index.js"; import { useIsAuthPending } from "../../auth/index.js"; /** * Call useCreateController and put the value in a CreateContext * * Base class for <Create> components, without UI. * * Accepts any props accepted by useCreateController: * - id: The record identifier * - resource: The resource * * @example // Custom edit layout * * const PostCreate = () => ( * <CreateBase> * <Grid container> * <Grid item xs={8}> * <SimpleForm> * ... * </SimpleForm> * </Grid> * <Grid item xs={4}> * Create instructions... * </Grid> * </Grid> * <div> * Post related links... * </div> * </CreateBase> * ); */ export var CreateBase = function (_a) { var children = _a.children, render = _a.render, loading = _a.loading, _b = _a.authLoading, authLoading = _b === void 0 ? loading : _b, props = __rest(_a, ["children", "render", "loading", "authLoading"]); var controllerProps = useCreateController(props); var isAuthPending = useIsAuthPending({ resource: controllerProps.resource, action: 'create', }); if (!render && !children) { throw new Error('<CreateBase> requires either a `render` prop or `children` prop'); } var showAuthLoading = isAuthPending && !props.disableAuthentication && authLoading !== false && authLoading !== undefined; return ( // We pass props.resource here as we don't need to create a new ResourceContext if the props is not provided React.createElement(OptionalResourceContextProvider, { value: props.resource }, React.createElement(CreateContextProvider, { value: controllerProps }, showAuthLoading ? authLoading : render ? render(controllerProps) : children))); }; //# sourceMappingURL=CreateBase.js.map