From 33d2faa8f5aa1cd7e4a9e26d0f8b322135c98bb0 Mon Sep 17 00:00:00 2001 From: Thomas Daniellou Date: Fri, 26 Mar 2021 17:34:17 +0100 Subject: [PATCH] Export TS types --- .../src/button/RefreshIconButton.tsx | 4 +- .../src/button/SaveButton.tsx | 2 +- packages/ra-ui-materialui/src/button/index.ts | 46 +++++++++----- packages/ra-ui-materialui/src/form/index.tsx | 6 +- .../src/input/BooleanInput.tsx | 8 +-- .../ra-ui-materialui/src/input/DateInput.tsx | 7 ++- .../src/input/DateTimeInput.tsx | 7 ++- .../ra-ui-materialui/src/input/ImageInput.tsx | 4 +- .../src/input/InputHelperText.tsx | 4 +- .../src/input/RadioButtonGroupInput.tsx | 7 ++- .../src/input/ResettableTextField.tsx | 8 +-- .../src/input/SearchInput.tsx | 7 ++- .../src/input/SelectArrayInput.tsx | 2 +- .../src/input/SelectInput.tsx | 8 +-- packages/ra-ui-materialui/src/input/index.ts | 62 +++++++++++++------ 15 files changed, 117 insertions(+), 65 deletions(-) diff --git a/packages/ra-ui-materialui/src/button/RefreshIconButton.tsx b/packages/ra-ui-materialui/src/button/RefreshIconButton.tsx index 04d694c50c7..8dd63d4543f 100644 --- a/packages/ra-ui-materialui/src/button/RefreshIconButton.tsx +++ b/packages/ra-ui-materialui/src/button/RefreshIconButton.tsx @@ -7,7 +7,7 @@ import IconButton, { IconButtonProps } from '@material-ui/core/IconButton'; import NavigationRefresh from '@material-ui/icons/Refresh'; import { refreshView, useTranslate } from 'ra-core'; -const RefreshIconButton: FC = ({ +const RefreshIconButton: FC = ({ label = 'ra.action.refresh', icon = defaultIcon, onClick, @@ -51,7 +51,7 @@ interface Props { onClick?: (e: MouseEvent) => void; } -export type RefreshIconProps = Props & IconButtonProps; +export type RefreshIconButtonProps = Props & IconButtonProps; RefreshIconButton.propTypes = { className: PropTypes.string, diff --git a/packages/ra-ui-materialui/src/button/SaveButton.tsx b/packages/ra-ui-materialui/src/button/SaveButton.tsx index 6d2e0e7a0a0..18b6d1d6478 100644 --- a/packages/ra-ui-materialui/src/button/SaveButton.tsx +++ b/packages/ra-ui-materialui/src/button/SaveButton.tsx @@ -217,7 +217,7 @@ interface Props { undoable?: boolean; } -type SaveButtonProps = Props & ButtonProps; +export type SaveButtonProps = Props & ButtonProps; SaveButton.propTypes = { className: PropTypes.string, diff --git a/packages/ra-ui-materialui/src/button/index.ts b/packages/ra-ui-materialui/src/button/index.ts index d48224d852b..9fb3a03922d 100644 --- a/packages/ra-ui-materialui/src/button/index.ts +++ b/packages/ra-ui-materialui/src/button/index.ts @@ -1,10 +1,14 @@ -import BulkDeleteButton from './BulkDeleteButton'; -import BulkDeleteWithConfirmButton from './BulkDeleteWithConfirmButton'; -import BulkDeleteWithUndoButton from './BulkDeleteWithUndoButton'; -import BulkExportButton from './BulkExportButton'; +import BulkDeleteButton, { BulkDeleteButtonProps } from './BulkDeleteButton'; +import BulkDeleteWithConfirmButton, { + BulkDeleteWithConfirmButtonProps, +} from './BulkDeleteWithConfirmButton'; +import BulkDeleteWithUndoButton, { + BulkDeleteWithUndoButtonProps, +} from './BulkDeleteWithUndoButton'; +import BulkExportButton, { BulkExportButtonProps } from './BulkExportButton'; import Button, { ButtonProps } from './Button'; -import CloneButton from './CloneButton'; -import CreateButton from './CreateButton'; +import CloneButton, { CloneButtonProps } from './CloneButton'; +import CreateButton, { CreateButtonProps } from './CreateButton'; import DeleteButton, { DeleteButtonProps } from './DeleteButton'; import DeleteWithConfirmButton, { DeleteWithConfirmButtonProps, @@ -12,20 +16,34 @@ import DeleteWithConfirmButton, { import DeleteWithUndoButton, { DeleteWithUndoButtonProps, } from './DeleteWithUndoButton'; -import EditButton from './EditButton'; -import ExportButton from './ExportButton'; -import ListButton from './ListButton'; -import SaveButton from './SaveButton'; -import ShowButton from './ShowButton'; -import SortButton from './SortButton'; -import RefreshButton from './RefreshButton'; -import RefreshIconButton from './RefreshIconButton'; +import EditButton, { EditButtonProps } from './EditButton'; +import ExportButton, { ExportButtonProps } from './ExportButton'; +import ListButton, { ListButtonProps } from './ListButton'; +import SaveButton, { SaveButtonProps } from './SaveButton'; +import ShowButton, { ShowButtonProps } from './ShowButton'; +import SortButton, { SortButtonProps } from './SortButton'; +import RefreshButton, { RefreshButtonProps } from './RefreshButton'; +import RefreshIconButton, { RefreshIconButtonProps } from './RefreshIconButton'; export type { + BulkDeleteButtonProps, + BulkDeleteWithConfirmButtonProps, + BulkDeleteWithUndoButtonProps, + BulkExportButtonProps, ButtonProps, + CloneButtonProps, + CreateButtonProps, DeleteButtonProps, DeleteWithConfirmButtonProps, DeleteWithUndoButtonProps, + EditButtonProps, + ExportButtonProps, + ListButtonProps, + SaveButtonProps, + ShowButtonProps, + SortButtonProps, + RefreshButtonProps, + RefreshIconButtonProps, }; export { diff --git a/packages/ra-ui-materialui/src/form/index.tsx b/packages/ra-ui-materialui/src/form/index.tsx index 8782131152d..1c414079041 100644 --- a/packages/ra-ui-materialui/src/form/index.tsx +++ b/packages/ra-ui-materialui/src/form/index.tsx @@ -1,9 +1,9 @@ -import FormInput from './FormInput'; +import FormInput, { FormInputProps } from './FormInput'; import SimpleForm, { SimpleFormProps } from './SimpleForm'; import SimpleFormIterator, { SimpleFormIteratorProps, } from './SimpleFormIterator'; -import TabbedFormTabs from './TabbedFormTabs'; +import TabbedFormTabs, { TabbedFormTabsProps } from './TabbedFormTabs'; import Toolbar, { ToolbarProps } from './Toolbar'; import getFormInitialValues from './getFormInitialValues'; import { SimpleFormView, SimpleFormViewProps } from './SimpleFormView'; @@ -14,8 +14,10 @@ export * from './FormTab'; export * from './FormTabHeader'; export type { + FormInputProps, SimpleFormProps, SimpleFormIteratorProps, + TabbedFormTabsProps, SimpleFormViewProps, TabbedFormViewProps, ToolbarProps, diff --git a/packages/ra-ui-materialui/src/input/BooleanInput.tsx b/packages/ra-ui-materialui/src/input/BooleanInput.tsx index 3c4ac035741..a808d139568 100644 --- a/packages/ra-ui-materialui/src/input/BooleanInput.tsx +++ b/packages/ra-ui-materialui/src/input/BooleanInput.tsx @@ -11,10 +11,7 @@ import sanitizeInputRestProps from './sanitizeInputRestProps'; import InputHelperText from './InputHelperText'; import InputPropTypes from './InputPropTypes'; -const BooleanInput: FunctionComponent< - InputProps & - Omit -> = ({ +const BooleanInput: FunctionComponent = ({ format, label, fullWidth, @@ -99,4 +96,7 @@ BooleanInput.defaultProps = { options: {}, }; +export type BooleanInputProps = InputProps & + Omit; + export default BooleanInput; diff --git a/packages/ra-ui-materialui/src/input/DateInput.tsx b/packages/ra-ui-materialui/src/input/DateInput.tsx index e7c49229032..258b403d941 100644 --- a/packages/ra-ui-materialui/src/input/DateInput.tsx +++ b/packages/ra-ui-materialui/src/input/DateInput.tsx @@ -44,9 +44,7 @@ const getStringFromDate = (value: string | Date) => { return convertDateToString(new Date(value)); }; -const DateInput: FunctionComponent< - InputProps & Omit -> = ({ +const DateInput: FunctionComponent = ({ format = getStringFromDate, label, options, @@ -120,4 +118,7 @@ DateInput.defaultProps = { options: {}, }; +export type DateInputProps = InputProps & + Omit; + export default DateInput; diff --git a/packages/ra-ui-materialui/src/input/DateTimeInput.tsx b/packages/ra-ui-materialui/src/input/DateTimeInput.tsx index c3c8a2f60f6..3634c151060 100644 --- a/packages/ra-ui-materialui/src/input/DateTimeInput.tsx +++ b/packages/ra-ui-materialui/src/input/DateTimeInput.tsx @@ -65,9 +65,7 @@ const parseDateTime = (value: string) => new Date(value); /** * Input component for entering a date and a time with timezone, using the browser locale */ -const DateTimeInput: FunctionComponent< - InputProps & Omit -> = ({ +const DateTimeInput: FunctionComponent = ({ format = formatDateTime, label, helperText, @@ -141,4 +139,7 @@ DateTimeInput.defaultProps = { options: {}, }; +export type DateTimeInputProps = InputProps & + Omit; + export default DateTimeInput; diff --git a/packages/ra-ui-materialui/src/input/ImageInput.tsx b/packages/ra-ui-materialui/src/input/ImageInput.tsx index fb4b3f6e891..1061515d813 100644 --- a/packages/ra-ui-materialui/src/input/ImageInput.tsx +++ b/packages/ra-ui-materialui/src/input/ImageInput.tsx @@ -38,7 +38,7 @@ const useStyles = makeStyles( { name: 'RaImageInput' } ); -const ImageInput = (props: FileInputProps & InputProps) => { +const ImageInput = (props: ImageInputProps) => { const classes = useStyles(props); return ( @@ -51,4 +51,6 @@ const ImageInput = (props: FileInputProps & InputProps) => { ); }; +export type ImageInputProps = FileInputProps & InputProps; + export default ImageInput; diff --git a/packages/ra-ui-materialui/src/input/InputHelperText.tsx b/packages/ra-ui-materialui/src/input/InputHelperText.tsx index 9a37db5017a..62329504961 100644 --- a/packages/ra-ui-materialui/src/input/InputHelperText.tsx +++ b/packages/ra-ui-materialui/src/input/InputHelperText.tsx @@ -2,13 +2,13 @@ import * as React from 'react'; import { FunctionComponent } from 'react'; import { useTranslate, ValidationError, ValidationErrorMessage } from 'ra-core'; -interface Props { +export interface InputHelperTextProps { helperText?: string | boolean; error?: ValidationErrorMessage; touched: boolean; } -const InputHelperText: FunctionComponent = ({ +const InputHelperText: FunctionComponent = ({ helperText, touched, error, diff --git a/packages/ra-ui-materialui/src/input/RadioButtonGroupInput.tsx b/packages/ra-ui-materialui/src/input/RadioButtonGroupInput.tsx index 6778df26d48..58e9ac998eb 100644 --- a/packages/ra-ui-materialui/src/input/RadioButtonGroupInput.tsx +++ b/packages/ra-ui-materialui/src/input/RadioButtonGroupInput.tsx @@ -88,9 +88,7 @@ const useStyles = makeStyles( * * The object passed as `options` props is passed to the material-ui component */ -const RadioButtonGroupInput: FunctionComponent< - ChoicesInputProps & FormControlProps -> = props => { +const RadioButtonGroupInput: FunctionComponent = props => { const { choices = [], classes: classesOverride, @@ -219,4 +217,7 @@ RadioButtonGroupInput.defaultProps = { translateChoice: true, }; +export type RadioButtonGroupInputProps = ChoicesInputProps & + FormControlProps; + export default RadioButtonGroupInput; diff --git a/packages/ra-ui-materialui/src/input/ResettableTextField.tsx b/packages/ra-ui-materialui/src/input/ResettableTextField.tsx index 8b1df44cf21..fd114f8a1da 100644 --- a/packages/ra-ui-materialui/src/input/ResettableTextField.tsx +++ b/packages/ra-ui-materialui/src/input/ResettableTextField.tsx @@ -16,9 +16,7 @@ import { ClassesOverride } from '../types'; /** * An override of the default Material-UI TextField which is resettable */ -function ResettableTextField( - props: InputProps -) { +function ResettableTextField(props: ResettableTextFieldProps) { const { classes: classesOverride, clearAlwaysVisible, @@ -213,10 +211,12 @@ ResettableTextField.propTypes = { value: PropTypes.any.isRequired, }; -interface ResettableTextFieldProps { +interface Props { classes?: ClassesOverride; clearAlwaysVisible?: boolean; resettable?: boolean; } +export type ResettableTextFieldProps = InputProps; + export default ResettableTextField; diff --git a/packages/ra-ui-materialui/src/input/SearchInput.tsx b/packages/ra-ui-materialui/src/input/SearchInput.tsx index 22f733c7588..020734bb8b7 100644 --- a/packages/ra-ui-materialui/src/input/SearchInput.tsx +++ b/packages/ra-ui-materialui/src/input/SearchInput.tsx @@ -18,9 +18,7 @@ const useStyles = makeStyles( { name: 'RaSearchInput' } ); -const SearchInput: FunctionComponent< - InputProps & Omit -> = props => { +const SearchInput: FunctionComponent = props => { const { classes: classesOverride, ...rest } = props; const translate = useTranslate(); const classes = useStyles(props); @@ -53,4 +51,7 @@ SearchInput.propTypes = { classes: PropTypes.object, }; +export type SearchInputProps = InputProps & + Omit; + export default SearchInput; diff --git a/packages/ra-ui-materialui/src/input/SelectArrayInput.tsx b/packages/ra-ui-materialui/src/input/SelectArrayInput.tsx index da561832d3f..b5af44deb78 100644 --- a/packages/ra-ui-materialui/src/input/SelectArrayInput.tsx +++ b/packages/ra-ui-materialui/src/input/SelectArrayInput.tsx @@ -291,7 +291,7 @@ const SelectArrayInput: FunctionComponent = props => { ); }; -interface SelectArrayInputProps +export interface SelectArrayInputProps extends Omit, Omit, 'source'>, Omit< diff --git a/packages/ra-ui-materialui/src/input/SelectInput.tsx b/packages/ra-ui-materialui/src/input/SelectInput.tsx index 9cab4b70745..6a817feabd2 100644 --- a/packages/ra-ui-materialui/src/input/SelectInput.tsx +++ b/packages/ra-ui-materialui/src/input/SelectInput.tsx @@ -137,10 +137,7 @@ const useStyles = makeStyles( * * */ -const SelectInput: FunctionComponent< - ChoicesInputProps & - Omit -> = props => { +const SelectInput: FunctionComponent = props => { const { allowEmpty, choices = [], @@ -313,4 +310,7 @@ SelectInput.defaultProps = { disableValue: 'disabled', }; +export type SelectInputProps = ChoicesInputProps & + Omit; + export default SelectInput; diff --git a/packages/ra-ui-materialui/src/input/index.ts b/packages/ra-ui-materialui/src/input/index.ts index fba4e7f05b5..741c558300a 100644 --- a/packages/ra-ui-materialui/src/input/index.ts +++ b/packages/ra-ui-materialui/src/input/index.ts @@ -1,4 +1,4 @@ -import ArrayInput from './ArrayInput'; +import ArrayInput, { ArrayInputProps } from './ArrayInput'; import AutocompleteArrayInput, { AutocompleteArrayInputProps, } from './AutocompleteArrayInput'; @@ -7,24 +7,32 @@ import BooleanInput from './BooleanInput'; import CheckboxGroupInput, { CheckboxGroupInputProps, } from './CheckboxGroupInput'; -import DateInput from './DateInput'; -import DateTimeInput from './DateTimeInput'; -import FileInput from './FileInput'; -import ImageInput from './ImageInput'; -import InputHelperText from './InputHelperText'; +import DateInput, { DateInputProps } from './DateInput'; +import DateTimeInput, { DateTimeInputProps } from './DateTimeInput'; +import FileInput, { FileInputProps } from './FileInput'; +import ImageInput, { ImageInputProps } from './ImageInput'; +import InputHelperText, { InputHelperTextProps } from './InputHelperText'; import InputPropTypes from './InputPropTypes'; -import Labeled from './Labeled'; -import NullableBooleanInput from './NullableBooleanInput'; -import NumberInput from './NumberInput'; -import PasswordInput from './PasswordInput'; -import RadioButtonGroupInput from './RadioButtonGroupInput'; -import ReferenceArrayInput from './ReferenceArrayInput'; -import ReferenceInput from './ReferenceInput'; -import ResettableTextField from './ResettableTextField'; -import SearchInput from './SearchInput'; -import SelectArrayInput from './SelectArrayInput'; -import SelectInput from './SelectInput'; -import TextInput from './TextInput'; +import Labeled, { LabeledProps } from './Labeled'; +import NullableBooleanInput, { + NullableBooleanInputProps, +} from './NullableBooleanInput'; +import NumberInput, { NumberInputProps } from './NumberInput'; +import PasswordInput, { PasswordInputProps } from './PasswordInput'; +import RadioButtonGroupInput, { + RadioButtonGroupInputProps, +} from './RadioButtonGroupInput'; +import ReferenceArrayInput, { + ReferenceArrayInputProps, +} from './ReferenceArrayInput'; +import ReferenceInput, { ReferenceInputProps } from './ReferenceInput'; +import ResettableTextField, { + ResettableTextFieldProps, +} from './ResettableTextField'; +import SearchInput, { SearchInputProps } from './SearchInput'; +import SelectArrayInput, { SelectArrayInputProps } from './SelectArrayInput'; +import SelectInput, { SelectInputProps } from './SelectInput'; +import TextInput, { TextInputProps } from './TextInput'; import sanitizeInputRestProps from './sanitizeInputRestProps'; export * from './TranslatableInputs'; export * from './TranslatableInputsTabContent'; @@ -59,7 +67,25 @@ export { }; export type { + ArrayInputProps, AutocompleteInputProps, AutocompleteArrayInputProps, CheckboxGroupInputProps, + DateInputProps, + DateTimeInputProps, + FileInputProps, + ImageInputProps, + InputHelperTextProps, + LabeledProps, + NullableBooleanInputProps, + NumberInputProps, + PasswordInputProps, + RadioButtonGroupInputProps, + ReferenceArrayInputProps, + ReferenceInputProps, + ResettableTextFieldProps, + SearchInputProps, + SelectArrayInputProps, + SelectInputProps, + TextInputProps, };