|
1 | | -import {omit, pick} from '@styled-system/props' |
2 | 1 | import classnames from 'classnames' |
3 | 2 | import React from 'react' |
4 | 3 | import styled, {css} from 'styled-components' |
5 | 4 | import {maxWidth, MaxWidthProps, minWidth, MinWidthProps, variant, width, WidthProps} from 'styled-system' |
6 | | -import {COMMON, get, SystemCommonProps} from './constants' |
| 5 | +import {get} from './constants' |
7 | 6 | import sx, {SxProp} from './sx' |
8 | 7 | import {ComponentProps} from './utils/types' |
9 | 8 |
|
@@ -43,8 +42,7 @@ type StyledWrapperProps = { |
43 | 42 | block?: boolean |
44 | 43 | contrast?: boolean |
45 | 44 | variant?: 'small' | 'large' |
46 | | -} & SystemCommonProps & |
47 | | - WidthProps & |
| 45 | +} & WidthProps & |
48 | 46 | MinWidthProps & |
49 | 47 | MaxWidthProps & |
50 | 48 | SxProp |
@@ -113,38 +111,60 @@ const Wrapper = styled.span<StyledWrapperProps>` |
113 | 111 | @media (min-width: ${get('breakpoints.1')}) { |
114 | 112 | font-size: ${get('fontSizes.1')}; |
115 | 113 | } |
116 | | - ${COMMON} |
117 | 114 | ${width} |
118 | 115 | ${minWidth} |
119 | 116 | ${maxWidth} |
120 | 117 | ${sizeVariants} |
121 | 118 | ${sx}; |
122 | 119 | ` |
123 | 120 |
|
124 | | -type TextInputInternalProps = { |
125 | | - // eslint-disable-next-line @typescript-eslint/no-explicit-any |
126 | | - as?: any // This is a band-aid fix until we have better type support for the `as` prop |
| 121 | +// Props that are not passed through to Input: |
| 122 | +type NonPassthroughProps = { |
| 123 | + className?: string |
127 | 124 | icon?: React.ComponentType<{className?: string}> |
128 | | -} & ComponentProps<typeof Wrapper> & |
129 | | - ComponentProps<typeof Input> |
| 125 | +} & Pick< |
| 126 | + ComponentProps<typeof Wrapper>, |
| 127 | + 'block' | 'contrast' | 'disabled' | 'sx' | 'theme' | 'width' | 'maxWidth' | 'minWidth' | 'variant' |
| 128 | +> |
| 129 | + |
| 130 | +type TextInputInternalProps = NonPassthroughProps & |
| 131 | + // Note: using ComponentProps instead of ComponentPropsWithoutRef here would cause a type issue where `css` is a required prop. |
| 132 | + Omit<React.ComponentPropsWithoutRef<typeof Input>, keyof NonPassthroughProps> |
130 | 133 |
|
131 | 134 | // using forwardRef is important so that other components (ex. SelectMenu) can autofocus the input |
132 | 135 | const TextInput = React.forwardRef<HTMLInputElement, TextInputInternalProps>( |
133 | | - ({icon: IconComponent, contrast, className, block, disabled, theme, sx: sxProp, ...rest}, ref) => { |
| 136 | + ( |
| 137 | + { |
| 138 | + icon: IconComponent, |
| 139 | + block, |
| 140 | + className, |
| 141 | + contrast, |
| 142 | + disabled, |
| 143 | + sx: sxProp, |
| 144 | + theme, |
| 145 | + width: widthProp, |
| 146 | + minWidth: minWidthProp, |
| 147 | + maxWidth: maxWidthProp, |
| 148 | + variant: variantProp, |
| 149 | + ...inputProps |
| 150 | + }, |
| 151 | + ref |
| 152 | + ) => { |
134 | 153 | // this class is necessary to style FilterSearch, plz no touchy! |
135 | 154 | const wrapperClasses = classnames(className, 'TextInput-wrapper') |
136 | | - const wrapperProps = pick(rest) |
137 | | - const inputProps = omit(rest) |
138 | 155 | return ( |
139 | 156 | <Wrapper |
140 | | - className={wrapperClasses} |
141 | | - hasIcon={!!IconComponent} |
142 | 157 | block={block} |
143 | | - theme={theme} |
144 | | - disabled={disabled} |
| 158 | + className={wrapperClasses} |
145 | 159 | contrast={contrast} |
| 160 | + disabled={disabled} |
| 161 | + hasIcon={!!IconComponent} |
146 | 162 | sx={sxProp} |
147 | | - {...wrapperProps} |
| 163 | + theme={theme} |
| 164 | + width={widthProp} |
| 165 | + minWidth={minWidthProp} |
| 166 | + maxWidth={maxWidthProp} |
| 167 | + variant={variantProp} |
148 | 168 | > |
149 | 169 | {IconComponent && <IconComponent className="TextInput-icon" />} |
150 | 170 | <Input ref={ref} disabled={disabled} {...inputProps} /> |
|
0 commit comments