Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add types to layout/Title #4963

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import * as React from 'react';
import React from 'react';
import { cloneElement } from 'react';
import { createPortal } from 'react-dom';
import PropTypes from 'prop-types';
import { useTranslate, warning } from 'ra-core';
import { Record, useTranslate, warning } from 'ra-core';

const Title = ({ className, defaultTitle, locale, record, title, ...rest }) => {
const Title = <R extends Record, T>(
props: TitleProps<R, T>
): React.ReactElement<TitleProps<R, T>> => {
const { className, defaultTitle, locale, record, title, ...rest } = props;
const translate = useTranslate();
const container =
typeof document !== 'undefined'
Expand All @@ -27,6 +30,16 @@ const Title = ({ className, defaultTitle, locale, record, title, ...rest }) => {
return createPortal(titleElement, container);
};

export declare type TitleProp<T> = string | React.ReactElement<T>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need declare? exporting it should suffice.


export declare type TitleProps<R extends Record, T> = {
defaultTitle?: string;
className?: string;
locale?: string;
record?: R;
title?: TitleProp<T>;
} & T;

export const TitlePropType = PropTypes.oneOfType([
PropTypes.string,
PropTypes.element,
Expand Down