@@ -5,7 +5,6 @@ import React, {
55 useState ,
66 forwardRef ,
77 ReactNode ,
8- FC ,
98 ComponentProps ,
109 MutableRefObject ,
1110} from 'react' ;
@@ -18,15 +17,15 @@ import WithTooltip from './tooltip/WithTooltip';
1817import { TooltipMessage } from './tooltip/TooltipMessage' ;
1918
2019// prettier-ignore
21- const Label = styled . label < Pick < Props , 'appearance' > > `
20+ const Label = styled . label < Pick < PureInputProps , 'appearance' > > `
2221 font-weight: ${ props => props . appearance !== 'code' && typography . weight . bold } ;
2322 font-family: ${ props => props . appearance === 'code' && typography . type . code } ;
2423 font-size: ${ props => props . appearance === 'code' ? typography . size . s1 - 1 : typography . size . s2 } px;
2524 line-height: ${ props => props . appearance === 'code' ? 16 : 20 } px;
2625` ;
2726
2827// prettier-ignore
29- const LabelWrapper = styled . div < Pick < Props , 'hideLabel' > > `
28+ const LabelWrapper = styled . div < Pick < PureInputProps , 'hideLabel' > > `
3029 margin-bottom: 8px;
3130
3231 ${ props => props . hideLabel && css `
@@ -64,7 +63,7 @@ const InputEl = styled.input`
6463 &:-webkit-autofill { -webkit-box-shadow: 0 0 0 3em ${ color . lightest } inset; }
6564` ;
6665
67- const getStackLevelStyling = ( props : Pick < Props , 'error' | 'stackLevel' > ) => {
66+ const getStackLevelStyling = ( props : Pick < PureInputProps , 'error' | 'stackLevel' > ) => {
6867 const radius = 4 ;
6968 const stackLevelDefinedStyling = css `
7069 position: relative;
@@ -107,7 +106,7 @@ const getStackLevelStyling = (props: Pick<Props, 'error' | 'stackLevel'>) => {
107106
108107// prettier-ignore
109108const InputWrapper = styled . div <
110- Pick < Props , 'error' | 'stackLevel' | 'appearance' | 'startingType' | 'icon' >
109+ Pick < PureInputProps , 'error' | 'stackLevel' | 'appearance' | 'startingType' | 'icon' >
111110> `
112111 display: inline-block;
113112 position: relative;
@@ -228,7 +227,7 @@ const InputWrapper = styled.div<
228227 ` }
229228` ;
230229// prettier-ignore
231- const InputContainer = styled . div < Pick < Props , 'orientation' > > `
230+ const InputContainer = styled . div < Pick < PureInputProps , 'orientation' > > `
232231 ${ props => props . orientation === 'horizontal' && css `
233232 display: table-row;
234233
@@ -272,7 +271,7 @@ const getErrorMessage = ({
272271 error,
273272 value,
274273 lastErrorValue,
275- } : Pick < Props , 'error' | 'value' | 'lastErrorValue' > ) => {
274+ } : Pick < PureInputProps , 'error' | 'value' | 'lastErrorValue' > ) => {
276275 let errorMessage = typeof error === 'function' ? error ( value ) : error ;
277276 if ( lastErrorValue ) {
278277 if ( value !== lastErrorValue ) {
@@ -282,8 +281,30 @@ const getErrorMessage = ({
282281 return errorMessage ;
283282} ;
284283
285- // FC<Props & ComponentProps<typeof InputEl>>
286- export const PureInput = forwardRef < HTMLInputElement , Props & ComponentProps < typeof InputEl > > (
284+ interface PureInputProps {
285+ id : string ;
286+ value ?: string ;
287+ appearance ?: 'default' | 'pill' | 'code' | 'tertiary' ;
288+ errorTooltipPlacement ?: ComponentProps < typeof WithTooltip > [ 'placement' ] ;
289+ stackLevel ?: 'top' | 'middle' | 'bottom' ;
290+ label : string ;
291+ hideLabel ?: boolean ;
292+ orientation ?: 'vertical' | 'horizontal' ;
293+ icon ?: ComponentProps < typeof Icon > [ 'icon' ] ;
294+ error ?: ReactNode | ( ( value : PureInputProps [ 'value' ] ) => ReactNode ) ;
295+ suppressErrorMessage ?: boolean ;
296+ className ?: string ;
297+ lastErrorValue ?: string ;
298+ startingType ?: string ;
299+ type ?: string ;
300+ onActionClick ?: ( ev : React . MouseEvent < HTMLElement > ) => void ;
301+ startFocused ?: boolean ;
302+ }
303+
304+ export const PureInput = forwardRef <
305+ HTMLInputElement ,
306+ PureInputProps & ComponentProps < typeof InputEl >
307+ > (
287308 (
288309 {
289310 id,
@@ -379,26 +400,7 @@ export const PureInput = forwardRef<HTMLInputElement, Props & ComponentProps<typ
379400 ) ;
380401 }
381402) ;
382-
383- interface Props {
384- id : string ;
385- value ?: string ;
386- appearance ?: 'default' | 'pill' | 'code' | 'tertiary' ;
387- errorTooltipPlacement ?: ComponentProps < typeof WithTooltip > [ 'placement' ] ;
388- stackLevel ?: 'top' | 'middle' | 'bottom' ;
389- label : string ;
390- hideLabel ?: boolean ;
391- orientation ?: 'vertical' | 'horizontal' ;
392- icon ?: ComponentProps < typeof Icon > [ 'icon' ] ;
393- error ?: ReactNode | Function ;
394- suppressErrorMessage ?: boolean ;
395- className ?: string ;
396- lastErrorValue ?: string ;
397- startingType ?: string ;
398- type ?: string ;
399- onActionClick ?: ( ev : React . MouseEvent < HTMLElement > ) => void ;
400- startFocused ?: boolean ;
401- }
403+ PureInput . displayName = 'PureInput' ;
402404
403405export const Input = forwardRef < HTMLInputElement , ComponentProps < typeof PureInput > > (
404406 ( { type : startingType , startFocused, ...rest } , ref ) => {
@@ -427,7 +429,7 @@ export const Input = forwardRef<HTMLInputElement, ComponentProps<typeof PureInpu
427429 inputRef . current . focus ( ) ;
428430 didFocusOnStart . current = true ;
429431 }
430- } , [ inputRef , didFocusOnStart ] ) ;
432+ } , [ inputRef , startFocused , didFocusOnStart ] ) ;
431433
432434 return (
433435 < PureInput
@@ -440,3 +442,4 @@ export const Input = forwardRef<HTMLInputElement, ComponentProps<typeof PureInpu
440442 ) ;
441443 }
442444) ;
445+ Input . displayName = 'Input' ;
0 commit comments