Skip to content

Instantly share code, notes, and snippets.

@lateshift
Last active March 9, 2020 11:47
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 lateshift/76a6186d7548bcb3b0e1e316c73afec5 to your computer and use it in GitHub Desktop.
Save lateshift/76a6186d7548bcb3b0e1e316c73afec5 to your computer and use it in GitHub Desktop.
Generate grid-template-area definitions via SCSS
@use "sass:list";
@use "sass:string";
// Quick hack (tm) e.g. not cleaned-up/optimized but since it runs on compile time - who cares ;)
@function genAreas($prefix, $rows, $columns) {
$list: ();
$line: ();
$result: '';
@for $row from 1 through $rows {
$result: '';
@for $column from 1 through $columns {
$result: #{$prefix}#{$row} + '_' + #{$column};
$line: list.append($line, $result);
}
$result: '';
@if $line {
$str: list.join($line, (), 'space');
$str: '"' + $str + '"';
$list: list.append($list, string.unquote($str));
}
$line: ();
}
@return $list;
}
.grid {
display: grid;
grid-template-areas: list.join(genAreas('row', 30, 10), (), 'space');
@debug list.join(genAreas('row', 5, 3), (), 'space');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment