Created
February 2, 2022 02:48
-
-
Save manabuyasuda/0abb829e3ca8e2142a46c49c66d8ec90 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
//- @param {Object} params | |
//- @param {String} params.width [null] セルの横幅 | |
//- @param {String} params.parentWidth [null] テーブル全体の横幅 | |
//- | |
//- @examples Input | |
//- colgroup | |
//- +Col({ width: 300, parentWidth: 900 }) | |
//- +Col({ width: "300", parentWidth: "900" }) | |
//- +Col({ width: "300px", parentWidth: "900px" }) | |
//- | |
//- @examples Output | |
//- <colgroup> | |
//- <col style="width: 33.333%" /> | |
//- <col style="width: 33.333%" /> | |
//- <col style="width: NaN%" /> | |
//- </colgroup> | |
mixin Col(params={}) | |
- | |
const props = Object.assign({ | |
width : null, | |
parentWidth : null, | |
}, params) | |
- | |
function percentage(width, parentWidth) { | |
const division = Number(width) / Number(parentWidth) * 100; | |
return String(Math.round(division * 1000) / 1000) + "%" | |
} | |
col(style=`width: ${ percentage(props.width, props.parentWidth)}`)&attributes(attributes) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment