Last active
March 10, 2016 00:23
-
-
Save bassettsj/a2b15c1ba90d82feb1f1 to your computer and use it in GitHub Desktop.
Flow Causing Problems
This file contains hidden or 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
| /* @flow */ | |
| import { autobind } from 'core-decorators'; | |
| import React, { Component } from 'react'; | |
| import ListItem from 'apps/shared/dev/view/components/ProgressTracker/ListItem'; | |
| type ListItemData = { | |
| label: string, | |
| status: number, | |
| completed: boolean | |
| } | |
| type Props = { | |
| onSelectStep: Function, | |
| list: Array<ListItemData> | |
| }; | |
| class ProgressTracker extends Component<any, Props, any> { | |
| static get StepStatus() { | |
| return { | |
| past: 0, | |
| current: 1, | |
| future: 2, | |
| error: 3 | |
| }; | |
| } | |
| @autobind | |
| onClick(e: SyntheticEvent): void { | |
| e.preventDefault(); | |
| const $target = $(e.currentTarget); | |
| // only allow steps that are in the past to be edited | |
| if ($target.hasClass('c--past')) { | |
| const stepID = parseInt($target.data('id'), 10); | |
| this.props.onSelectStep(stepID); | |
| } | |
| } | |
| /** | |
| * @method getListItem | |
| * @param listValue | |
| * @returns {XML} | |
| */ | |
| getListItem(listValue: ListItemData, index: number): React$Element { | |
| const label = listValue.label; | |
| const status = ['c--past', 'c--current', '', 'c--error'][listValue.status]; | |
| let completion; | |
| switch (listValue.status) { | |
| case this.StepStatus.error: { | |
| completion = 'c--error'; | |
| break; | |
| } | |
| case this.StepStatus.future: { | |
| completion = ''; | |
| break; | |
| } | |
| default: { | |
| completion = 'c--completed'; | |
| } | |
| } | |
| return ( | |
| <ListItem | |
| key={index} | |
| id={index} | |
| classStatus={status} | |
| label={label} | |
| classCompletion={completion} | |
| onClick={this.onClick} | |
| /> | |
| ); | |
| } | |
| /** | |
| * @method StepStatus | |
| * @returns {*} | |
| * @constructor | |
| */ | |
| get StepStatus() { | |
| return this.constructor.StepStatus; | |
| } | |
| props: Props; | |
| render(): React$Element { | |
| return ( | |
| <ul className="c-progress-tracker"> | |
| {this.props.list.map((listValue: ListItemData, index: number) => this.getListItem(listValue, index))} | |
| </ul> | |
| ); | |
| } | |
| } | |
| export default ProgressTracker; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment