-
Notifications
You must be signed in to change notification settings - Fork 842
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TypeScript]: EuiToggle, EuiButtonGroup, EuiButtonToggle, EuiFilterBu…
…tton, EuiFilterGroup, EuiFilterSelectItem (#1570) * convert toggle to typescript * add EuiButtonGroup and EuiButtonToggle type definitions * add filter_group type definitions * import direct from required_props * #1570 changelog entry * fewer extensions; more explicit properties * buttonGroup onChange signature
- Loading branch information
1 parent
274df7d
commit 1da5c71
Showing
11 changed files
with
193 additions
and
115 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
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
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
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,38 @@ | ||
import { CommonProps } from '../common'; | ||
import { IconType, IconSize } from '../icon' | ||
/// <reference path="../button/index.d.ts" /> | ||
|
||
import { SFC, ButtonHTMLAttributes, HTMLAttributes } from 'react'; | ||
|
||
declare module '@elastic/eui' { | ||
/** | ||
* Filter button type defs | ||
* | ||
* @see './filter_button.js' | ||
*/ | ||
|
||
export const EuiFilterButton: SFC<EuiButtonEmptyProps>; | ||
|
||
/** | ||
* Filter group type defs | ||
* | ||
* @see './filter_group.js' | ||
*/ | ||
|
||
export const EuiFilterGroup: SFC<CommonProps & HTMLAttributes<HTMLDivElement>>; | ||
|
||
/** | ||
* Filter select item type defs | ||
* | ||
* @see './filter_select_item.js' | ||
*/ | ||
|
||
export type FilterChecked = 'on' | 'off'; | ||
export interface EuiFilterSelectItemProps { | ||
checked?: FilterChecked | ||
} | ||
|
||
export const EuiFilterSelectItem: SFC<CommonProps & | ||
ButtonHTMLAttributes<HTMLButtonElement> & EuiFilterSelectItemProps | ||
>; | ||
} |
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.
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 { EuiToggle, ToggleType, TYPES as TOGGLE_TYPES } from './toggle'; |
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
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,88 @@ | ||
import React from 'react'; | ||
import classNames from 'classnames'; | ||
import { ChangeEventHandler, HTMLAttributes } from 'react'; | ||
import { CommonProps } from '../common'; | ||
|
||
const typeToInputTypeMap = { | ||
single: 'radio', | ||
multi: 'checkbox', | ||
}; | ||
|
||
export const TYPES = Object.keys(typeToInputTypeMap); | ||
|
||
export type ToggleType = keyof typeof typeToInputTypeMap; | ||
|
||
export type EuiToggleProps = HTMLAttributes<HTMLDivElement> & | ||
CommonProps & { | ||
id?: string; | ||
/** | ||
* Initial state of the toggle | ||
*/ | ||
checked?: boolean; | ||
/** | ||
* For handling the onChange event of the input | ||
*/ | ||
onChange?: ChangeEventHandler<HTMLInputElement>; | ||
isDisabled?: boolean; | ||
name?: string; | ||
/** | ||
* Determines the input type based on multiple or single item(s) | ||
*/ | ||
type?: ToggleType; | ||
/** | ||
* What would typically be the input's label. Required for accessibility. | ||
*/ | ||
label: string; | ||
/** | ||
* Additional classNames for the input itself | ||
*/ | ||
inputClassName?: string; | ||
value?: string | number; | ||
}; | ||
|
||
export const EuiToggle: React.SFC<EuiToggleProps> = ({ | ||
id, | ||
className, | ||
checked, | ||
children, | ||
inputClassName, | ||
isDisabled, | ||
label, | ||
name, | ||
onChange, | ||
title, | ||
type, | ||
value, | ||
...rest | ||
}) => { | ||
const classes = classNames( | ||
'euiToggle', | ||
{ 'euiToggle--checked': checked }, | ||
className | ||
); | ||
|
||
const inputClasses = classNames('euiToggle__input', inputClassName); | ||
|
||
return ( | ||
<div className={classes} {...rest}> | ||
<input | ||
id={id} | ||
className={inputClasses} | ||
aria-label={label} | ||
checked={checked} | ||
disabled={isDisabled} | ||
name={name} | ||
onChange={onChange} | ||
title={title} | ||
type={type ? typeToInputTypeMap[type] : undefined} | ||
value={value} | ||
/> | ||
|
||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
EuiToggle.defaultProps = { | ||
type: 'multi', | ||
}; |