Skip to content

Commit

Permalink
fix(text-input): use JSX instead of createElement
Browse files Browse the repository at this point in the history
  • Loading branch information
stipsan committed Jun 7, 2024
1 parent 3efc565 commit 1285b27
Showing 1 changed file with 13 additions and 21 deletions.
34 changes: 13 additions & 21 deletions src/core/primitives/textInput/textInput.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import {CloseIcon} from '@sanity/icons'
import {ThemeFontWeightKey} from '@sanity/ui/theme'
import {
createElement,
forwardRef,
isValidElement,
useCallback,
useImperativeHandle,
useMemo,
useRef,
} from 'react'
import {forwardRef, isValidElement, useCallback, useImperativeHandle, useMemo, useRef} from 'react'
import {isValidElementType} from 'react-is'
import {styled} from 'styled-components'
import {EMPTY_RECORD} from '../../constants'
Expand Down Expand Up @@ -167,8 +159,8 @@ export const TextInput = forwardRef(function TextInput(
clearButton,
disabled = false,
fontSize: fontSizeProp = 2,
icon,
iconRight,
icon: IconComponent,
iconRight: IconRightComponent,
onClear,
padding: paddingProp = 3,
prefix,
Expand All @@ -192,8 +184,8 @@ export const TextInput = forwardRef(function TextInput(

// Transient properties
const $hasClearButton = Boolean(clearButton)
const $hasIcon = Boolean(icon)
const $hasIconRight = Boolean(iconRight)
const $hasIcon = Boolean(IconComponent)
const $hasIconRight = Boolean(IconRightComponent)
const $hasSuffix = Boolean(suffix)
const $hasPrefix = Boolean(prefix)

Expand Down Expand Up @@ -248,20 +240,20 @@ export const TextInput = forwardRef(function TextInput(
data-scheme={rootTheme.scheme}
data-tone={rootTheme.tone}
>
{icon && (
{IconComponent && (
<LeftBox padding={padding}>
<Text size={fontSize}>
{isValidElement(icon) && icon}
{isValidElementType(icon) && createElement(icon)}
{isValidElement(IconComponent) && IconComponent}
{isValidElementType(IconComponent) && <IconComponent />}
</Text>
</LeftBox>
)}

{!$hasClearButton && iconRight && (
{!$hasClearButton && IconRightComponent && (
<RightBox padding={padding}>
<Text size={fontSize}>
{isValidElement(iconRight) && iconRight}
{isValidElementType(iconRight) && createElement(iconRight)}
{isValidElement(IconRightComponent) && IconRightComponent}
{isValidElementType(IconRightComponent) && <IconRightComponent />}
</Text>
</RightBox>
)}
Expand All @@ -271,8 +263,8 @@ export const TextInput = forwardRef(function TextInput(
__unstable_disableFocusRing,
border,
fontSize,
icon,
iconRight,
IconComponent,
IconRightComponent,
padding,
radius,
rootTheme,
Expand Down

0 comments on commit 1285b27

Please sign in to comment.