Last active
September 7, 2023 20:06
-
-
Save satya164/43950a19b23b6e2d7484 to your computer and use it in GitHub Desktop.
Quantity Queries in Sass
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
@mixin quantity-query($selector, $type, $amount, $max: null) { | |
@if $type == at-least { | |
#{$selector}:nth-last-child(n+#{$amount}), | |
#{$selector}:nth-last-child(n+#{$amount}) ~ #{$selector} { @content; } | |
} @else if $type == at-most { | |
#{$selector}:nth-last-child(-n+#{$amount}):first-child, | |
#{$selector}:nth-last-child(-n+#{$amount}):first-child ~ #{$selector} { @content; } | |
} @else if $type == between { | |
@if type-of($max) != "number" { | |
@error "Max value must be a number for quantity-query."; | |
} | |
#{$selector}:nth-last-child(n+#{$amount}):nth-last-child(-n+#{$max}):first-child, | |
#{$selector}:nth-last-child(-n+#{$amount}):nth-last-child(-n+#{$max}):first-child ~ #{$selector} { @content; } | |
} @else { | |
@error "Invalid type `#{$type}` for quantity-query. Allowed types - at-least, at-most, between."; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: