Skip to content

Commit 4706ad6

Browse files
refactor(Input): simplify typing of rightIcon prop
1 parent 6199abd commit 4706ad6

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

src/components/Input/Input.stories.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ type Story = StoryObj<InputType>
1818
export const Sizes: Story = {
1919
render: () => (
2020
<VStack width="154px">
21-
<Input rightIcon={BsSlashSquare} placeholder="Search" />
22-
<Input rightIcon={BsSlashSquare} placeholder="Search" size="sm" />
21+
<Input rightIcon={<BsSlashSquare />} placeholder="Search" />
22+
<Input rightIcon={<BsSlashSquare />} placeholder="Search" size="sm" />
2323
</VStack>
2424
),
2525
}
@@ -28,8 +28,12 @@ export const ElementVariations: Story = {
2828
render: () => (
2929
<VStack width="258px" spacing={4}>
3030
<Input placeholder="input text" />
31-
<Input rightIcon={BsSlashSquare} placeholder="input text" />
32-
<Input rightIcon={BsSlashSquare} placeholder="input text" isDisabled />
31+
<Input rightIcon={<BsSlashSquare />} placeholder="input text" />
32+
<Input
33+
rightIcon={<BsSlashSquare />}
34+
placeholder="input text"
35+
isDisabled
36+
/>
3337
</VStack>
3438
),
3539
}

src/components/Input/index.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import * as React from "react"
22
import {
3-
Icon,
43
Input as ChakraInput,
54
InputGroup,
65
InputGroupProps,
76
InputProps as ChakraInputProps,
87
InputRightElement,
98
} from "@chakra-ui/react"
10-
import { IconType } from "react-icons/lib"
11-
12-
type RightIconType = IconType | typeof Icon
139

1410
type CommonProps = ChakraInputProps
1511

@@ -19,7 +15,7 @@ type WithIconProps = CommonProps & {
1915
/**
2016
* The Icon used to render `InputRightElement` on the right side of the input
2117
*/
22-
rightIcon: RightIconType
18+
rightIcon?: JSX.Element
2319
/**
2420
* Primarily for style props to be applied to the wrapper
2521
*/
@@ -36,7 +32,7 @@ function Input(props: InputProps) {
3632
return (
3733
<InputGroup size={size} {...inputGroupProps}>
3834
<ChakraInput data-peer {...rest} />
39-
<InputRightElement children={<Icon />} />
35+
<InputRightElement children={Icon} />
4036
</InputGroup>
4137
)
4238
}

0 commit comments

Comments
 (0)