-
-
Save Raynos/a0e5175751b28da4d7cc to your computer and use it in GitHub Desktop.
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
module.exports = row | |
// row("1 3", ["div", "One fourth"], ["div", "Three fourths"]) | |
// row("1 1 1", ["div", "first column"], ["div", "second column"], ["div, "third column"]) | |
function row(pattern) { | |
var args = [].slice.call(arguments, 1) | |
var parts = pattern.split(" ").map(function (part) { | |
var number = parseInt(part, 10) | |
return !isNaN(number) ? number : part | |
}) | |
var total = parts.reduce(function (a, b) { return a + b }) | |
return grid(parts.map(function (part, index) { | |
return col(part, total, { | |
first: index === 0, | |
last: index === parts.length - 1, | |
content: args[index] | |
}) | |
})) | |
} | |
function grid(children) { | |
return ["div", { | |
style: { | |
background: "transparent", | |
margin: "0 0 15px 0" | |
} | |
}, children] | |
} | |
function col(part, total, opts) { | |
var width = String(100 * (part / total)) + "%" | |
return ["div", { | |
style: { | |
float: "left", | |
paddingLeft: opts.first || opts.last ? "0" : "7.5px", | |
paddingRight: opts.last ? "0" : "7.5px", | |
width: width | |
} | |
}, [ opts.content ]] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment