From 1356f1c0518ee65ac68bd40ab0f45701e95ecffc Mon Sep 17 00:00:00 2001 From: katty barroso Date: Wed, 21 Aug 2024 08:51:12 -0500 Subject: [PATCH] Fix TS errors on text components --- fabric/src/components/Text/index.tsx | 24 +++++++++---------- .../components/TextWithPlaceholder/index.tsx | 7 +++++- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/fabric/src/components/Text/index.tsx b/fabric/src/components/Text/index.tsx index c6fa0c8b46..31e6138ebe 100644 --- a/fabric/src/components/Text/index.tsx +++ b/fabric/src/components/Text/index.tsx @@ -3,15 +3,14 @@ import * as CSS from 'csstype' import * as React from 'react' import styled, { DefaultTheme, useTheme } from 'styled-components' import { - color, ColorProps, - compose, ResponsiveValue, + TypographyProps as TypographySystemProps, + color, + compose, system, typography as typographySystem, - TypographyProps as TypographySystemProps, } from 'styled-system' -import { PropsOf } from '../../utils/types' interface TypographyProps { textTransform?: ResponsiveValue @@ -33,8 +32,9 @@ const typography = system({ interface SystemProps extends TypographySystemProps, ColorProps, TypographyProps {} -interface StyledTextProps extends SystemProps {} - +interface StyledTextProps extends SystemProps { + as?: keyof JSX.IntrinsicElements | React.ComponentType +} const StyledText = styled('span').withConfig({ shouldForwardProp: (prop) => shouldForwardProp(prop), })({ margin: 0 }, compose(typographySystem, typography, color)) @@ -45,12 +45,13 @@ function useTextContext(): React.ContextType { return React.useContext(TextContext) } -type TextProps = PropsOf & { +interface TextProps extends StyledTextProps { variant?: keyof DefaultTheme['typography'] textOverflow?: 'ellipsis' + as?: keyof JSX.IntrinsicElements | React.ComponentType + children?: React.ReactNode } - -const Text = React.forwardRef((props, ref) => { +const Text = React.forwardRef((props, ref) => { const isInText = useTextContext() const theme = useTheme() @@ -60,7 +61,6 @@ const Text = React.forwardRef((props, ref) => { } const { - // variant, children, as = isInText ? 'span' : 'div', color = isInText ? 'inherit' : 'textPrimary', @@ -77,13 +77,13 @@ const Text = React.forwardRef((props, ref) => { } color={color} fontSize={fontSize} fontWeight={fontWeight} lineHeight={lineHeight} fontFamily={fontFamily} style={{ ...overflow }} - ref={ref} {...rest} > {children} @@ -92,4 +92,4 @@ const Text = React.forwardRef((props, ref) => { ) }) -export { Text, TextProps, useTextContext, TextContext } +export { Text, TextContext, TextProps, useTextContext } diff --git a/fabric/src/components/TextWithPlaceholder/index.tsx b/fabric/src/components/TextWithPlaceholder/index.tsx index 5b9d312ded..d8e7454305 100644 --- a/fabric/src/components/TextWithPlaceholder/index.tsx +++ b/fabric/src/components/TextWithPlaceholder/index.tsx @@ -47,7 +47,12 @@ export function TextWithPlaceholder({ }: TextWithPlaceholderProps) { const [rand] = React.useState(() => Math.random()) return ( - + {isLoading ? ( {Array.from({ length: words }, (_, i) => (