-
-
Notifications
You must be signed in to change notification settings - Fork 161
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
Lost center fraction #365
Merged
peterramsing
merged 3 commits into
peterramsing:develop
from
steve-holland:lost-center-fraction
Apr 7, 2017
Merged
Lost center fraction #365
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,10 +1,13 @@ | ||
var newBlock = require('./new-block.js'); | ||
|
||
var lgLogic = require('./_lg-logic'); | ||
|
||
/** | ||
* lost-center: Horizontally center a container element and apply padding | ||
* to it. | ||
* | ||
* @param {length} [max-width] - A max-width to assign. Can be any unit. | ||
* @param {length} [max-width|fraction] - Either a max-width to assign (can be | ||
* any unit). Or, a simple fraction of the containing element's width. | ||
* | ||
* @param {length} [padding] - Padding on the left and right of the element. | ||
* Can be any unit. | ||
|
@@ -19,14 +22,34 @@ var newBlock = require('./new-block.js'); | |
* | ||
* @example | ||
* section { | ||
* lost-center: 3/12; | ||
* } | ||
* | ||
* @example | ||
* section { | ||
* lost-center: 1140px 30px flex; | ||
* } | ||
* | ||
* @example | ||
* section { | ||
* lost-center: 2/6 30px flex; | ||
* } | ||
*/ | ||
module.exports = function lostCenterDecl(css, settings) { | ||
module.exports = function lostCenterDecl(css, settings, result) { | ||
css.walkDecls('lost-center', function lostCenterFunction(decl) { | ||
var declArr = []; | ||
var lostCenterPadding; | ||
var lostCenterMaxWidth; | ||
var lostCenterFlexbox = settings.flexbox; | ||
var lostUnit = settings.gridUnit; | ||
var lostColumnRounder = settings.rounder; | ||
var lostColumnGutter = 0; | ||
var validUnits = ['%', 'vw']; | ||
|
||
var isFractionValue = (value) => { | ||
var lostFractionPattern = /^\d+\/\d+$/; | ||
return lostFractionPattern.test(value); | ||
}; | ||
|
||
declArr = decl.value.split(' '); | ||
|
||
|
@@ -42,23 +65,27 @@ module.exports = function lostCenterDecl(css, settings) { | |
lostCenterFlexbox = 'no-flex'; | ||
} | ||
|
||
decl.parent.nodes.forEach(function lostCenterPaddingFunction(declaration) { | ||
if (declaration.prop === 'lost-center-padding') { | ||
lostCenterPadding = declaration.value; | ||
lostCenterPadding = lgLogic.parseLostProperty(decl.parent.nodes, 'lost-center-padding', lostCenterPadding); | ||
lostColumnRounder = lgLogic.parseLostProperty(decl.parent.nodes, 'lost-column-rounder', lostColumnRounder); | ||
|
||
declaration.remove(); | ||
} | ||
}); | ||
lostUnit = lgLogic.parseLostProperty(decl.parent.nodes, 'lost-unit', lostUnit); | ||
|
||
decl.parent.nodes.forEach(function lostCenterFlexboxFunction(declaration) { | ||
if (declaration.prop === 'lost-center-flexbox') { | ||
if (declaration.value === 'flex') { | ||
lostCenterFlexbox = declaration.value; | ||
} | ||
if (!lgLogic.validateUnit(lostUnit, validUnits)) { | ||
decl.warn(result, `${lostUnit} is not a valid unit for lost-center`); | ||
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. @codebysubtract 🕺 🎆 |
||
lostUnit = settings.gridUnit; | ||
} | ||
|
||
declaration.remove(); | ||
} | ||
}); | ||
lostCenterFlexbox = lgLogic.parseLostProperty(decl.parent.nodes, 'lost-center-flexbox', lostCenterFlexbox); | ||
|
||
if(lostCenterFlexbox !== 'flex') { | ||
lostCenterFlexbox = settings.flexbox; | ||
} | ||
|
||
if(declArr[0] !== undefined && isFractionValue(declArr[0])) { | ||
lostCenterMaxWidth = lgLogic.calcValue(declArr[0], lostColumnGutter, lostColumnRounder, lostUnit); | ||
} else { | ||
lostCenterMaxWidth = declArr[0]; | ||
} | ||
|
||
if (lostCenterFlexbox === 'no-flex') { | ||
newBlock( | ||
|
@@ -88,7 +115,7 @@ module.exports = function lostCenterDecl(css, settings) { | |
|
||
decl.cloneBefore({ | ||
prop: 'max-width', | ||
value: declArr[0] | ||
value: lostCenterMaxWidth | ||
}); | ||
|
||
decl.cloneBefore({ | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@codebysubtract With these edits here, do you have any thoughts on: #364