Skip to content

Instantly share code, notes, and snippets.

@manabuyasuda
Created February 2, 2022 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save manabuyasuda/0abb829e3ca8e2142a46c49c66d8ec90 to your computer and use it in GitHub Desktop.
Save manabuyasuda/0abb829e3ca8e2142a46c49c66d8ec90 to your computer and use it in GitHub Desktop.
//- @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