Skip to content

Commit

Permalink
Fix TS errors on text components
Browse files Browse the repository at this point in the history
  • Loading branch information
kattylucy committed Aug 21, 2024
1 parent 95e4fae commit 1356f1c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
24 changes: 12 additions & 12 deletions fabric/src/components/Text/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<CSS.Property.TextTransform>
Expand All @@ -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<any>
}
const StyledText = styled('span').withConfig({
shouldForwardProp: (prop) => shouldForwardProp(prop),
})<StyledTextProps>({ margin: 0 }, compose(typographySystem, typography, color))
Expand All @@ -45,12 +45,13 @@ function useTextContext(): React.ContextType<typeof TextContext> {
return React.useContext(TextContext)
}

type TextProps = PropsOf<typeof StyledText> & {
interface TextProps extends StyledTextProps {
variant?: keyof DefaultTheme['typography']
textOverflow?: 'ellipsis'
as?: keyof JSX.IntrinsicElements | React.ComponentType<any>
children?: React.ReactNode
}

const Text = React.forwardRef<HTMLDivElement, TextProps>((props, ref) => {
const Text = React.forwardRef<HTMLDivElement | HTMLSpanElement, TextProps>((props, ref) => {
const isInText = useTextContext()
const theme = useTheme()

Expand All @@ -60,7 +61,6 @@ const Text = React.forwardRef<HTMLDivElement, TextProps>((props, ref) => {
}

const {
// variant,
children,
as = isInText ? 'span' : 'div',
color = isInText ? 'inherit' : 'textPrimary',
Expand All @@ -77,13 +77,13 @@ const Text = React.forwardRef<HTMLDivElement, TextProps>((props, ref) => {
<TextContext.Provider value>
<StyledText
as={as}
ref={ref as React.Ref<HTMLDivElement | HTMLSpanElement>}
color={color}
fontSize={fontSize}
fontWeight={fontWeight}
lineHeight={lineHeight}
fontFamily={fontFamily}
style={{ ...overflow }}
ref={ref}
{...rest}
>
{children}
Expand All @@ -92,4 +92,4 @@ const Text = React.forwardRef<HTMLDivElement, TextProps>((props, ref) => {
)
})

export { Text, TextProps, useTextContext, TextContext }
export { Text, TextContext, TextProps, useTextContext }
7 changes: 6 additions & 1 deletion fabric/src/components/TextWithPlaceholder/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ export function TextWithPlaceholder({
}: TextWithPlaceholderProps) {
const [rand] = React.useState(() => Math.random())
return (
<Text {...textProps} textOverflow="ellipsis" textDecoration={isLoading ? 'none' : textProps.textDecoration}>
<Text
as="span"
{...textProps}
textOverflow="ellipsis"
textDecoration={isLoading ? 'none' : textProps.textDecoration}
>
{isLoading ? (
<LoadingWrapper $lines={maxLines} $isLoading={isLoading}>
{Array.from({ length: words }, (_, i) => (
Expand Down

0 comments on commit 1356f1c

Please sign in to comment.