-
Notifications
You must be signed in to change notification settings - Fork 843
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EuiFieldNumber: converted to Typescript (#2685)
* Converts EuiFieldNumber to Typescript * Adds PR number * Removes unnecessary function * Fixes what was requested in the PR's review
- Loading branch information
1 parent
6a2ef63
commit 7276c77
Showing
9 changed files
with
109 additions
and
167 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import React, { InputHTMLAttributes, Ref, FunctionComponent } from 'react'; | ||
import { CommonProps } from '../../common'; | ||
import classNames from 'classnames'; | ||
|
||
import { EuiFormControlLayout } from '../form_control_layout'; | ||
|
||
import { EuiValidatableControl } from '../validatable_control'; | ||
|
||
export type EuiFieldNumberProps = InputHTMLAttributes<HTMLInputElement> & | ||
CommonProps & { | ||
value?: number | ''; | ||
icon?: string; | ||
isInvalid?: boolean; | ||
fullWidth?: boolean; | ||
isLoading?: boolean; | ||
readOnly?: boolean; | ||
min?: number; | ||
max?: number; | ||
step?: number; | ||
inputRef?: Ref<HTMLInputElement>; | ||
|
||
/** | ||
* Creates an input group with element(s) coming before input | ||
*/ | ||
prepend?: JSX.Element | JSX.Element[]; | ||
|
||
/** | ||
* Creates an input group with element(s) coming after input | ||
*/ | ||
append?: string; | ||
|
||
/** | ||
* Completely removes form control layout wrapper and ignores | ||
* icon, prepend, and append. Best used inside EuiFormControlLayoutDelimited. | ||
*/ | ||
controlOnly?: boolean; | ||
|
||
/** | ||
* when `true` creates a shorter height input | ||
*/ | ||
compressed?: boolean; | ||
}; | ||
|
||
export const EuiFieldNumber: FunctionComponent<EuiFieldNumberProps> = ({ | ||
className, | ||
icon, | ||
id, | ||
placeholder, | ||
name, | ||
min, | ||
max, | ||
value, | ||
isInvalid, | ||
fullWidth = false, | ||
isLoading = false, | ||
compressed = false, | ||
prepend, | ||
append, | ||
inputRef, | ||
readOnly, | ||
controlOnly, | ||
...rest | ||
}) => { | ||
const classes = classNames('euiFieldNumber', className, { | ||
'euiFieldNumber--withIcon': icon, | ||
'euiFieldNumber--fullWidth': fullWidth, | ||
'euiFieldNumber--compressed': compressed, | ||
'euiFieldNumber--inGroup': prepend || append, | ||
'euiFieldNumber-isLoading': isLoading, | ||
}); | ||
|
||
const control = ( | ||
<EuiValidatableControl isInvalid={isInvalid}> | ||
<input | ||
type="number" | ||
id={id} | ||
min={min} | ||
max={max} | ||
name={name} | ||
value={value} | ||
placeholder={placeholder} | ||
readOnly={readOnly} | ||
className={classes} | ||
ref={inputRef} | ||
{...rest} | ||
/> | ||
</EuiValidatableControl> | ||
); | ||
|
||
if (controlOnly) { | ||
return control; | ||
} | ||
|
||
return ( | ||
<EuiFormControlLayout | ||
icon={icon} | ||
fullWidth={fullWidth} | ||
isLoading={isLoading} | ||
compressed={compressed} | ||
readOnly={readOnly} | ||
prepend={prepend} | ||
append={append} | ||
inputId={id}> | ||
{control} | ||
</EuiFormControlLayout> | ||
); | ||
}; |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { EuiFieldNumber, EuiFieldNumberProps } from './field_number'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters