import { Create, SimpleForm, BooleanInput, DateInput, TextInput, email, NumberInput, ReferenceInput, SelectInput, PasswordInput, TimeInput, } from "react-admin"; import { createPortal } from "react-dom"; import { AdminStoryContext } from "../../../utils"; import { MemoryRouter } from "react-router"; import { useArgs } from "@storybook/preview-api"; import { StoryContext } from "@storybook/react"; import React from "react"; import { Paper } from "@mui/material"; import { JSX } from "react/jsx-runtime"; const FIELD_STORIES_MAP: Record JSX.Element> = { BooleanInput: () => { return ; }, DateInput: () => { return ; }, EmailInput: () => { return ; }, NumberInput: () => { return ; }, PasswordInput: () => { return ; }, ReferenceInput: () => { return ; }, SelectInput: () => { const choices: { id: string; name: string }[] = [ { id: "Moscow", name: "Moscow" }, { id: "Samara", name: "Samara" }, { id: "Tokyo", name: "Tokyo" }, ]; return ; }, TextInput: () => { return ; }, TimeInput: () => { return ; }, }; export const adminContextDecorator = (Story: () => React.JSX.Element) => { return ( ); }; export const listDecorator = ( Story: () => React.JSX.Element, context: StoryContext ) => { const activeStoryId = context.title.split("/").pop(); const activeIndex = activeStoryId ? Object.keys(FIELD_STORIES_MAP).findIndex( (story) => story === activeStoryId ) : undefined; return ( {Object.entries(FIELD_STORIES_MAP).map(([id, Component]) => { if (context.title.match(id)) { return Story(); } return Component(); })} ); }; export const shadowArgsDecorator = (Story: () => React.JSX.Element) => { const [args, updateArgs, resetArgs] = useArgs(); if (!("sortable" in args)) { updateArgs({ ...args, sortable: false }); } return ; }; export const AdditionalInfoWrapper = ({ children, }: { children: string | JSX.Element | JSX.Element[]; }) => { return createPortal( {children} , document.body ); }; export const inputDecorators = [ (Story: () => React.JSX.Element, context: StoryContext) => listDecorator(Story, context), (Story: () => React.JSX.Element) => adminContextDecorator(Story), (Story: () => React.JSX.Element) => shadowArgsDecorator(Story), ];