/** * TODO: we should be using the FormRenderer from the admin to do this, * but the CTB has no tests or types, so we can't refactor it safely. * So we're just adding this to the tech debt. */ import * as React from 'react'; import { type MessageDescriptor, type PrimitiveType } from 'react-intl'; import type { Schema } from '@strapi/types'; /** * Input types `GenericInput` renders itself, one per `case` of its `switch`. * Any other type needs an entry in `customInputs`, or renders as "Not supported". * * Both directions are checked: the `switch` runs on a `GenericInputType`, so a `case` missing * from this list fails the type check, and `GenericInputs.test.tsx` renders every entry, so an * entry without a `case` fails the test. */ declare const GENERIC_INPUT_TYPES: readonly ["json", "bool", "checkbox", "datetime", "date", "number", "email", "timestamp", "text", "string", "password", "select", "textarea", "time"]; type GenericInputType = (typeof GENERIC_INPUT_TYPES)[number]; interface TranslationMessage extends MessageDescriptor { values?: Record; } interface InputOption { metadatas: { intlLabel: TranslationMessage; disabled: boolean; hidden: boolean; }; key: string; value: string; } type ConditionField = { name: string; type: string; enum?: string[]; }; interface CustomInputProps { attribute?: TAttribute; autoComplete?: string; description?: TranslationMessage; disabled?: boolean; error?: string; hint?: string | React.JSX.Element | (string | React.JSX.Element)[]; intlLabel: TranslationMessage; labelAction?: React.ReactNode; name: string; onChange: (payload: { target: { name: string; value?: unknown; type?: string; }; }, shouldSetInitialValue?: boolean) => void; onDelete?: () => void; options?: InputOption[]; placeholder?: TranslationMessage; required?: boolean; step?: number; type: string; value?: unknown; autoFocus?: boolean; attributeName?: string; conditionFields?: ConditionField[]; } interface GenericInputProps { attribute?: TAttribute; autoComplete?: string; customInputs?: Record>>; description?: TranslationMessage; disabled?: boolean; error?: string | TranslationMessage; intlLabel: TranslationMessage; labelAction?: React.ReactNode; name: string; onChange: (payload: { target: { name: string; value?: unknown; type?: string; }; }, shouldSetInitialValue?: boolean) => void; onDelete?: () => void; options?: InputOption[]; placeholder?: TranslationMessage; required?: boolean; step?: number; type: string; value?: unknown; isNullable?: boolean; autoFocus?: boolean; attributeName?: string; conditionFields?: ConditionField[]; } /** * we've memoized this component because we use a context to store all the data in our form in the content-manager. * This then causes _every_ component to re-render because there are no selects incurring performance issues * in content-types as the content-type gets more complicated. */ declare const MemoizedGenericInput: React.MemoExoticComponent<({ autoComplete, customInputs, description, disabled, intlLabel, labelAction, error, name, onChange, onDelete, options, placeholder, required, step, type, value: defaultValue, isNullable: _isNullable, autoFocus, attribute, attributeName, conditionFields, ...rest }: GenericInputProps) => import("react/jsx-runtime").JSX.Element>; export type { GenericInputProps, CustomInputProps, GenericInputType }; export { MemoizedGenericInput as GenericInput, GENERIC_INPUT_TYPES };