From e51eb593e3fa9200185df61c64d0b4f62b12daba Mon Sep 17 00:00:00 2001 From: Pavithran Gridharan Date: Sat, 20 Jun 2020 11:06:03 +0200 Subject: [PATCH 1/4] Add types to layout/Title --- .../src/layout/{Title.js => Title.tsx} | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) rename packages/ra-ui-materialui/src/layout/{Title.js => Title.tsx} (78%) diff --git a/packages/ra-ui-materialui/src/layout/Title.js b/packages/ra-ui-materialui/src/layout/Title.tsx similarity index 78% rename from packages/ra-ui-materialui/src/layout/Title.js rename to packages/ra-ui-materialui/src/layout/Title.tsx index ae56c310e90..c4f8a7b9de1 100644 --- a/packages/ra-ui-materialui/src/layout/Title.js +++ b/packages/ra-ui-materialui/src/layout/Title.tsx @@ -1,10 +1,11 @@ -import * as React from 'react'; +import React, { FC } from 'react'; import { cloneElement } from 'react'; import { createPortal } from 'react-dom'; import PropTypes from 'prop-types'; import { useTranslate, warning } from 'ra-core'; -const Title = ({ className, defaultTitle, locale, record, title, ...rest }) => { +const Title: FC = props => { + const { className, defaultTitle, locale, record, title, ...rest } = props; const translate = useTranslate(); const container = typeof document !== 'undefined' @@ -27,6 +28,14 @@ const Title = ({ className, defaultTitle, locale, record, title, ...rest }) => { return createPortal(titleElement, container); }; +export interface TitleProps { + defaultTitle?: string; + className?: string; + locale?: string; + record?: R; + title?: string | React.ReactElement; +} + export const TitlePropType = PropTypes.oneOfType([ PropTypes.string, PropTypes.element, From 74c17af2409f2f322ff73bb062b47307e449fa77 Mon Sep 17 00:00:00 2001 From: Pavithran Gridharan Date: Sat, 20 Jun 2020 11:33:55 +0200 Subject: [PATCH 2/4] Adds better generics --- packages/ra-ui-materialui/src/layout/Title.tsx | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/ra-ui-materialui/src/layout/Title.tsx b/packages/ra-ui-materialui/src/layout/Title.tsx index c4f8a7b9de1..4231790318a 100644 --- a/packages/ra-ui-materialui/src/layout/Title.tsx +++ b/packages/ra-ui-materialui/src/layout/Title.tsx @@ -2,9 +2,11 @@ import React, { FC } 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: FC = props => { +const Title = ( + props: TitleProps +): React.ReactElement> => { const { className, defaultTitle, locale, record, title, ...rest } = props; const translate = useTranslate(); const container = @@ -28,13 +30,13 @@ const Title: FC = props => { return createPortal(titleElement, container); }; -export interface TitleProps { +export declare type TitleProps = { defaultTitle?: string; className?: string; locale?: string; record?: R; - title?: string | React.ReactElement; -} + title?: string | React.ReactElement; +} & T; export const TitlePropType = PropTypes.oneOfType([ PropTypes.string, From 6ea9c929252c9781b8ee61fdfb80f888c07d4d76 Mon Sep 17 00:00:00 2001 From: Pavithran Gridharan Date: Sat, 20 Jun 2020 13:56:16 +0200 Subject: [PATCH 3/4] Export TitleProp for reuse --- packages/ra-ui-materialui/src/layout/Title.tsx | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/ra-ui-materialui/src/layout/Title.tsx b/packages/ra-ui-materialui/src/layout/Title.tsx index 4231790318a..94bd20de6d9 100644 --- a/packages/ra-ui-materialui/src/layout/Title.tsx +++ b/packages/ra-ui-materialui/src/layout/Title.tsx @@ -30,12 +30,14 @@ const Title = ( return createPortal(titleElement, container); }; +export declare type TitleProp = string | React.ReactElement; + export declare type TitleProps = { defaultTitle?: string; className?: string; locale?: string; record?: R; - title?: string | React.ReactElement; + title?: TitleProp; } & T; export const TitlePropType = PropTypes.oneOfType([ From 902f405b95fe25a15fb551fa26e45fff7f29d9ae Mon Sep 17 00:00:00 2001 From: Pavithran Gridharan Date: Sun, 21 Jun 2020 10:16:57 +0200 Subject: [PATCH 4/4] Fix linting issue --- packages/ra-ui-materialui/src/layout/Title.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/ra-ui-materialui/src/layout/Title.tsx b/packages/ra-ui-materialui/src/layout/Title.tsx index 94bd20de6d9..7af44f612c1 100644 --- a/packages/ra-ui-materialui/src/layout/Title.tsx +++ b/packages/ra-ui-materialui/src/layout/Title.tsx @@ -1,4 +1,4 @@ -import React, { FC } from 'react'; +import React from 'react'; import { cloneElement } from 'react'; import { createPortal } from 'react-dom'; import PropTypes from 'prop-types';