forked from elastic/eui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Convert
EuiSwitch
to TS (elastic#2243)"
This reverts commit 39dbcf6.
- Loading branch information
1 parent
b859ad0
commit 25c4635
Showing
8 changed files
with
113 additions
and
105 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { CommonProps } from '../../common'; | ||
|
||
import { FunctionComponent, ButtonHTMLAttributes, ReactNode } from 'react'; | ||
|
||
declare module '@elastic/eui' { | ||
/** | ||
* @see './switch.js' | ||
*/ | ||
export type EuiSwitchProps = CommonProps & | ||
ButtonHTMLAttributes<HTMLButtonElement> & { | ||
label: ReactNode; | ||
checked: boolean; | ||
onChange: ( | ||
event: React.FormEvent<HTMLButtonElement & { checked: boolean }> | ||
) => void; | ||
disabled?: boolean; | ||
compressed?: boolean; | ||
}; | ||
|
||
export const EuiSwitch: FunctionComponent<EuiSwitchProps>; | ||
} |
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 { EuiSwitch } from './switch'; |
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,86 @@ | ||
import React, { Component } from 'react'; | ||
|
||
import PropTypes from 'prop-types'; | ||
import classNames from 'classnames'; | ||
|
||
import makeId from '../../form/form_row/make_id'; | ||
import { EuiIcon } from '../../icon'; | ||
|
||
export class EuiSwitch extends Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.state = { | ||
switchId: props.id || makeId(), | ||
}; | ||
} | ||
|
||
onClick = e => { | ||
e.target.checked = !this.props.checked; | ||
this.props.onChange(e); | ||
}; | ||
|
||
render() { | ||
const { | ||
label, | ||
id, | ||
name, | ||
checked, | ||
disabled, | ||
compressed, | ||
onChange, | ||
className, | ||
...rest | ||
} = this.props; | ||
|
||
const { switchId } = this.state; | ||
|
||
const classes = classNames( | ||
'euiSwitch', | ||
{ | ||
'euiSwitch--compressed': compressed, | ||
}, | ||
className | ||
); | ||
|
||
return ( | ||
<div className={classes}> | ||
<button | ||
id={switchId} | ||
aria-checked={checked} | ||
className="euiSwitch__button" | ||
role="switch" | ||
disabled={disabled} | ||
onClick={this.onClick} | ||
{...rest}> | ||
<span className="euiSwitch__body"> | ||
<span className="euiSwitch__thumb" /> | ||
<span className="euiSwitch__track"> | ||
<EuiIcon type="cross" size="m" className="euiSwitch__icon" /> | ||
|
||
<EuiIcon | ||
type="check" | ||
size="m" | ||
className="euiSwitch__icon euiSwitch__icon--checked" | ||
/> | ||
</span> | ||
</span> | ||
</button> | ||
|
||
<label className="euiSwitch__label" htmlFor={switchId}> | ||
{label} | ||
</label> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
EuiSwitch.propTypes = { | ||
name: PropTypes.string, | ||
id: PropTypes.string, | ||
label: PropTypes.node, | ||
checked: PropTypes.bool, | ||
onChange: PropTypes.func, | ||
disabled: PropTypes.bool, | ||
compressed: PropTypes.bool, | ||
}; |
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 was deleted.
Oops, something went wrong.