Skip to content

Instantly share code, notes, and snippets.

@tylerpaige
Created May 19, 2020 16:04
Show Gist options
  • Save tylerpaige/a51af9e7bbef5d1aa9388414748c7327 to your computer and use it in GitHub Desktop.
Save tylerpaige/a51af9e7bbef5d1aa9388414748c7327 to your computer and use it in GitHub Desktop.
/*
Sets a global variable $prop-at-breakpoint and calls your content block
for any breakpoint in which the request property is present in the preset's configuration.
*/
@mixin via-type-preset-property($preset-name, $property-name) {
@if not map-has-key($type-sizes, $preset-name) {
@warn "No typestyles for '#{$preset-name}'. Available options: #{map-keys($type-sizes)}";
}
$preset: map-get($type-sizes, $preset-name);
@each $breakpoint, $rules in $preset {
// $breakpoint like "base", "2col", etc
// $rules like the all styles and rules associated with that breakpoint
@if map-has-key($rules, $property-name) {
$prop-at-breakpoint: map-get($rules, $property-name) !global;
@if $breakpoint == 'base' {
@content;
}
@else {
@include breakpoint($breakpoint) {
@content;
}
}
}
}
}
.my-selector {
@include via-type-preset-property(body, font-size) {
height: $prop-at-breakpoint * 3;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment