-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
76 additions
and
102 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,73 +1,64 @@ | ||
import React from 'react' | ||
|
||
export default class IconSwitch extends React.Component { | ||
constructor (props) { | ||
super(props) | ||
export const IconSwitch = (props) => { | ||
const { | ||
activeClass, | ||
inactiveClass, | ||
startIconClass, | ||
endIconClass, | ||
startText, | ||
endText, | ||
startID, | ||
endID, | ||
startAria, | ||
endAria, | ||
showStartObject, | ||
showEndObject, | ||
displayStartObject | ||
} = props | ||
|
||
this.state = { | ||
showObject: false | ||
} | ||
} | ||
|
||
handleStartActive () { | ||
this.setState({ showObject: false }) | ||
} | ||
|
||
handleEndActive () { | ||
this.setState({ showObject: true }) | ||
} | ||
|
||
render () { | ||
const selectedClass = this.props.activeClass | ||
const unselectedClass = this.props.inactiveClass | ||
const startIconClass = this.props.startIconClass | ||
const endIconClass = this.props.endIconClass | ||
const startText = this.props.startText | ||
const endText = this.props.endText | ||
const startID = this.props.startID | ||
const endID = this.props.endID | ||
|
||
return ( | ||
<div> | ||
<div className="switch-btn-group-container"> | ||
<div className="btn-group switch-btn-group" role="group"> | ||
<label | ||
htmlFor={startID} | ||
className={!this.state.showObject ? selectedClass : unselectedClass} | ||
> | ||
<input | ||
className="radio__input" | ||
type="radio" | ||
value={startID} | ||
id={startID} | ||
aria-label={startText} | ||
checked={this.state.showObject} | ||
onClick={(e) => this.handleStartActive(e)} | ||
onKeyDown={(e) => this.handleStartActive(e)} | ||
/> | ||
<i className={startIconClass} /> | ||
<span>{startText}</span> | ||
</label> | ||
<label | ||
htmlFor={endID} | ||
className={this.state.showObject ? selectedClass : unselectedClass} | ||
> | ||
<input | ||
className="radio__input" | ||
type="radio" | ||
id={endID} | ||
value={endID} | ||
aria-label={endText} | ||
checked={!this.state.showObject} | ||
onClick={(e) => this.handleEndActive(e)} | ||
onKeyDown={(e) => this.handleEndActive(e)} | ||
/> | ||
<i className={endIconClass} /> | ||
<span>{endText}</span> | ||
</label> | ||
</div> | ||
return ( | ||
<div> | ||
<div className="switch-btn-group-container"> | ||
<div className="btn-group switch-btn-group" role="group"> | ||
<label | ||
htmlFor={startID} | ||
className={!displayStartObject ? activeClass : inactiveClass} | ||
> | ||
<input | ||
className="radio__input" | ||
type="radio" | ||
value={startID} | ||
id={startID} | ||
aria-label={startAria} | ||
checked={displayStartObject} | ||
onChange={showStartObject} | ||
onClick={showStartObject} | ||
onKeyDown={showStartObject} | ||
/> | ||
<i className={startIconClass} /> | ||
<span>{startText}</span> | ||
</label> | ||
<label | ||
htmlFor={endID} | ||
className={displayStartObject ? activeClass : inactiveClass} | ||
> | ||
<input | ||
className="radio__input" | ||
type="radio" | ||
id={endID} | ||
value={endID} | ||
aria-label={endAria} | ||
checked={!displayStartObject} | ||
onChange={showEndObject} | ||
onClick={showEndObject} | ||
onKeyDown={showEndObject} | ||
/> | ||
<i className={endIconClass} /> | ||
<span>{endText}</span> | ||
</label> | ||
</div> | ||
</div> | ||
) | ||
} | ||
</div> | ||
) | ||
} |
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