New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Move styles inline for React progress components #8756
Changes from 6 commits
65e68b5
a55cd4a
041f58f
c7cfd34
c92e97f
96fc1d7
5841c42
1b01f55
8e1efcc
98cbd22
04b030b
4f0f20a
a028c6b
6d6e7d0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,29 +2,47 @@ | |
import React from 'react'; | ||
import { STAGE_TYPE } from './types'; | ||
import StageProgress from './stage_progress.jsx'; | ||
import color from '../../color'; | ||
|
||
var style = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: could be const. also our convention has been to call this variable styles rather than style. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in c149942cf4e47f8b6c9508cc71a2d89bb899558a. |
||
row: { | ||
borderBottom: `2px solid ${color.lighter_gray}`, | ||
display: 'table', | ||
tableLayout: 'fixed', | ||
padding: '10px', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: could be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in c149942cf4e47f8b6c9508cc71a2d89bb899558a. |
||
width: '100%' | ||
}, | ||
stageName: { | ||
display: 'table-cell', | ||
width: '200px', | ||
verticalAlign: 'middle', | ||
paddingRight: '10px' | ||
} | ||
}; | ||
|
||
/** | ||
* Stage progress component used in level header and course overview. | ||
*/ | ||
var CourseProgressRow = React.createClass({ | ||
propTypes: { | ||
currentLevelId: React.PropTypes.string, | ||
stage: STAGE_TYPE | ||
}, | ||
|
||
render() { | ||
var stage = this.props.stage; | ||
|
||
return ( | ||
<div className='game-group'> | ||
<div className='stage'> | ||
<div style={style.row}> | ||
<div style={style.stageName}> | ||
{stage.title} | ||
<div className='stage-lesson-plan-link' style={{display: 'none'}}> | ||
<a target='_blank' href={stage.lesson_plan_html_url}> | ||
{dashboard.i18n.t('view_lesson_plan')} | ||
</a> | ||
</div> | ||
</div> | ||
<StageProgress levels={stage.levels} largeDots={true} saveAnswersFirst={false} /> | ||
<StageProgress levels={stage.levels} currentLevelId={this.props.currentLevelId} largeDots={true} saveAnswersFirst={false} /> | ||
</div> | ||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,103 @@ | ||
import Radium from 'radium'; | ||
import React from 'react'; | ||
import { STAGE_PROGRESS_TYPE } from './types'; | ||
import { saveAnswersAndNavigate } from '../../levels/saveAnswers'; | ||
import color from '../../color'; | ||
|
||
var style = { | ||
overviewContainer: { | ||
display: 'table-cell', | ||
verticalAlign: 'middle', | ||
paddingRight: '10px' | ||
}, | ||
headerContainer: { | ||
padding: '5px 8px', | ||
backgroundColor: color.lightest_gray, | ||
border: `1px solid ${color.lighter_gray}`, | ||
borderRadius: '5px' | ||
}, | ||
dot: { | ||
puzzle: { | ||
display: 'inline-block', | ||
width: '24px', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. would it make sense to use variables for some of these values that are repeated a few times? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. also many of them can be numbers instead of strings with px There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unit-less numbers will always have 'px' appended, even things like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a shorthand for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anything not in the list from your link will automatically get px. The one that's gotten me a few times is idk about shorthand. Could try There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
height: '24px', | ||
fontSize: '14px', | ||
textAlign: 'center', | ||
lineHeight: '24px', | ||
borderRadius: '24px', | ||
borderWidth: '2px', | ||
borderStyle: 'solid', | ||
borderColor: color.lighter_gray, | ||
margin: '0 -1px', | ||
transition: 'background-color .2s ease-out, border-color .2s ease-out, color .2s ease-out', | ||
':hover': { | ||
textDecoration: 'none', | ||
color: color.white, | ||
backgroundColor: color.level_current | ||
} | ||
}, | ||
unplugged: { | ||
width: 'auto', | ||
fontSize: '13px', | ||
padding: '0 10px' | ||
}, | ||
assessment: { | ||
borderColor: color.assessment | ||
}, | ||
small: { | ||
width: '7px', | ||
height: '7px', | ||
borderRadius: '7px', | ||
lineHeight: 'inherit', | ||
fontSize: 0 | ||
}, | ||
overview: { | ||
height: '30px', | ||
width: '30px', | ||
margin: '2px', | ||
fontSize: '16px', | ||
lineHeight: '32px' | ||
} | ||
}, | ||
status: { | ||
submitted: { | ||
color: color.white, | ||
backgroundColor: color.level_submitted | ||
}, | ||
perfect: { | ||
color: color.white, | ||
backgroundColor: color.level_perfect | ||
}, | ||
passed: { | ||
color: color.white, | ||
backgroundColor: color.level_passed | ||
}, | ||
attempted: { | ||
color: color.charcoal, | ||
backgroundColor: color.level_attempted | ||
}, | ||
not_tried: { | ||
color: color.charcoal, | ||
backgroundColor: color.level_not_tried | ||
}, | ||
review_rejected: { | ||
color: color.white, | ||
backgroundColor: color.level_review_rejected | ||
}, | ||
review_accepted: { | ||
color: color.white, | ||
backgroundColor: color.level_review_accepted | ||
} | ||
} | ||
}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the neat thing about having these styles in .js is that we can hoist them up to a more common component if we end up using them elsewhere. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. though it is amusing to see the end of .css/.scss and the return of putting styles near the rendering itself. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also wonder if dot has enough complexity that it deserves its own component? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Extracted a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Re: CSS, I miss the "Cascading" part of Cascading Style Sheets. It used to be that we could set one class on a root element and easily apply a totally different set of styles for many elements (e.g. I like that components own all their styles and can be included with no extra dependencies, but it seems like we've lost some of the power of CSS. Outside CSS can still have unintended effects on components. Maybe Shadow DOM will make this better in the future? |
||
|
||
/** | ||
* Stage progress component used in level header and course overview. | ||
*/ | ||
var StageProgress = React.createClass({ | ||
propTypes: { | ||
levels: STAGE_PROGRESS_TYPE, | ||
currentLevelIndex: React.PropTypes.number, | ||
currentLevelId: React.PropTypes.string, | ||
largeDots: React.PropTypes.bool, | ||
saveAnswersFirst: React.PropTypes.bool.isRequired | ||
}, | ||
|
@@ -20,24 +109,26 @@ var StageProgress = React.createClass({ | |
}, | ||
|
||
render() { | ||
var progressDots = this.props.levels.map((level, index) => { | ||
var progressDots = this.props.levels.map(level => { | ||
var uid = level.uid || level.id.toString(); | ||
|
||
var innerClass = 'level_link ' + (level.status || 'not_tried'); | ||
if (level.kind === 'unplugged') { | ||
innerClass += ' unplugged_level'; | ||
var dotStyle = Object.assign({}, style.dot.puzzle); | ||
if (level.kind === 'assessment') { | ||
Object.assign(dotStyle, style.dot.assessment); | ||
} | ||
|
||
var outerClass = (level.kind === 'assessment') ? 'puzzle_outer_assessment' : 'puzzle_outer_level'; | ||
outerClass = (index === this.props.currentLevelIndex) ? 'puzzle_outer_current' : outerClass; | ||
|
||
var isUnplugged = isNaN(level.title); | ||
var dotStyle = {}; | ||
if (this.props.largeDots) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe a comment somewhere explaining what large dots vs. small dots are? must admit i'm not quite sure what the difference is. |
||
if (isUnplugged) { | ||
dotStyle = {fontSize: '13px', padding: '4px 10px', margin: '1px'}; | ||
} else { | ||
dotStyle = {padding: '5px 4px 3px 4px', margin: '1px'}; | ||
Object.assign(dotStyle, style.dot.overview); | ||
if (uid === this.props.currentLevelId) { | ||
Object.assign(dotStyle, {borderColor: color.level_current}); | ||
} | ||
} else if (uid !== this.props.currentLevelId) { | ||
Object.assign(dotStyle, style.dot.small); | ||
} | ||
|
||
var isUnplugged = isNaN(level.title); | ||
if (isUnplugged) { | ||
Object.assign(dotStyle, style.dot.unplugged); | ||
} | ||
|
||
var onClick = null; | ||
|
@@ -47,24 +138,23 @@ var StageProgress = React.createClass({ | |
} | ||
|
||
return ([ | ||
<div className={outerClass}> | ||
<a | ||
href={level.url} | ||
onClick={onClick} | ||
className={innerClass + ' level-' + level.id} | ||
style={dotStyle}> | ||
{level.title} | ||
</a> | ||
</div>, | ||
<a | ||
key={uid} | ||
className={`level-${level.id}`} | ||
href={level.url} | ||
onClick={onClick} | ||
style={[dotStyle, style.status[level.status || 'not_tried']]}> | ||
{level.title} | ||
</a>, | ||
' ' | ||
]); | ||
}); | ||
|
||
return ( | ||
<div className={this.props.largeDots ? 'games' : 'progress_container'}> | ||
<div className='react_stage' style={this.props.largeDots ? style.overviewContainer : style.headerContainer}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is overview vs. header the difference between drop-down view and in-header stage view, or something else? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep! I'll rename these to something better. |
||
{progressDots} | ||
</div> | ||
); | ||
} | ||
}); | ||
module.exports = StageProgress; | ||
module.exports = Radium(StageProgress); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could use const/let vs. var throughout (tho not a requirement that you change it) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in c149942cf4e47f8b6c9508cc71a2d89bb899558a. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, dumb question.. is it normal to use these kinds of custom tags in react?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@breville This is how you pass props to child components (i.e. The CourseProgressRow component will now have a prop named
currentLevelId
set to the same value as this component'scurrentLevelId