1
0
mirror of https://github.com/locomotivemtl/locomotive-boilerplate.git synced 2026-01-15 00:55:08 +08:00
Files
locomotive-boilerplate/_assets/styles/tools/_family.scss

353 lines
10 KiB
SCSS
Raw Normal View History

2022-05-12 16:15:44 +02:00
// ==========================================================================
// Tools / Family
// ==========================================================================
2017-12-07 11:16:46 -05:00
// DOCS : https://lukyvj.github.io/family.scss/
//
2022-05-12 16:15:44 +02:00
// Select all children from the first to `$num`.
// @group with-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
// @param {number} $num - id of the child
2017-12-07 11:16:46 -05:00
@mixin first($num) {
@if $num == 1 {
&:first-child {
@content;
}
} @else {
&:nth-child(-n + #{$num}) {
@content;
}
2017-12-07 11:16:46 -05:00
}
}
2022-05-12 16:15:44 +02:00
// Select all children from the last to `$num`.
// @group with-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
// @param {number} $num - id of the child
2017-12-07 11:16:46 -05:00
@mixin last($num) {
&:nth-last-child(-n + #{$num}) {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// Select all children after the first to `$num`.
// @group with-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
// @param {number} $num - id of the child
2017-12-07 11:16:46 -05:00
@mixin after-first($num) {
&:nth-child(n + #{$num + 1}) {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// Select all children before `$num` from the last.
// @group with-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
// @param {number} $num - id of the child
2017-12-07 11:16:46 -05:00
@mixin from-end($num) {
&:nth-last-child(#{$num}) {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// Select all children between `$first` and `$last`.
// @group with-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
2017-12-07 11:16:46 -05:00
@mixin between($first, $last) {
&:nth-child(n + #{$first}):nth-child(-n + #{$last}) {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// Select all even children between `$first` and `$last`.
// @group with-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
2017-12-07 11:16:46 -05:00
@mixin even-between($first, $last) {
&:nth-child(even):nth-child(n + #{$first}):nth-child(-n + #{$last}) {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// Select all odd children between `$first` and `$last`.
// @group with-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
2017-12-07 11:16:46 -05:00
@mixin odd-between($first, $last) {
&:nth-child(odd):nth-child(n + #{$first}):nth-child(-n + #{$last}) {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// Select all `$num` children between `$first` and `$last`.
// @group with-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
2017-12-07 11:16:46 -05:00
@mixin n-between($num, $first, $last) {
&:nth-child(#{$num}n):nth-child(n + #{$first}):nth-child(-n + #{$last}) {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// Select all children but `$num`.
// @group with-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
// @param {number} $num - id of the child
2017-12-07 11:16:46 -05:00
@mixin all-but($num) {
&:not(:nth-child(#{$num})) {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// Select children each `$num`.
// @group with-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
// @param {number} $num - id of the child
// @alias every
2017-12-07 11:16:46 -05:00
@mixin each($num) {
&:nth-child(#{$num}n) {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// Select children each `$num`.
// @group with-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
// @param {number} $num - id of the child
2017-12-07 11:16:46 -05:00
@mixin every($num) {
&:nth-child(#{$num}n) {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// Select the `$num` child from the start and the `$num` child from the last.
// @group with-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
// @param {number} $num - id of the child
2017-12-07 11:16:46 -05:00
@mixin from-first-last($num) {
&:nth-child(#{$num}),
&:nth-last-child(#{$num}) {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// Select the item in the middle of `$num` child. Only works with odd number
// chain.
// @group with-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
// @param {number} $num - id of the child
2017-12-07 11:16:46 -05:00
@mixin middle($num) {
&:nth-child(#{round(math.div($num, 2))}) {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// Select all children between the `$num` first and the `$num` last.
// @group with-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
// @param {number} $num - id of the child
2017-12-07 11:16:46 -05:00
@mixin all-but-first-last($num) {
&:nth-child(n + #{$num}):nth-last-child(n + #{$num}) {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// This quantity-query mixin will only select the first of `$limit` items. It will not
// work if there is not as much as item as you set in `$limit`.
// @group Quantity queries
// @param {number} $limit
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
2017-12-07 11:16:46 -05:00
@mixin first-of($limit) {
&:nth-last-child(#{$limit}):first-child {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// This quantity-query mixin will only select the last of `$limit` items. It will not
// if there is not as much as item as you set in `$limit`.
// @group Quantity queries
// @param {number} $limit
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
2017-12-07 11:16:46 -05:00
@mixin last-of($limit) {
&:nth-of-type(#{$limit}):nth-last-of-type(1) {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// This quantity-query mixin will select every items if there is at least `$num` items. It will not
// if there is not as much as item as you set in `$num`.
// @group Quantity queries
// @param {number} $limit
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
2017-12-07 11:16:46 -05:00
@mixin at-least($num) {
$selector: &;
$child: nth(nth($selector, -1), -1);
2017-12-07 11:16:46 -05:00
&:nth-last-child(n + #{$num}),
&:nth-last-child(n + #{$num}) ~ #{$child} {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// This quantity-query mixin will select every items if there is at most `$num` items. It will not
// if there is not as much as item as you set in `$num`.
// @group Quantity queries
// @param {number} $limit
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
2017-12-07 11:16:46 -05:00
@mixin at-most($num) {
$selector: &;
$child: nth(nth($selector, -1), -1);
2017-12-07 11:16:46 -05:00
&:nth-last-child(-n + #{$num}):first-child,
&:nth-last-child(-n + #{$num}):first-child ~ #{$child} {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// This quantity-query mixin will select every items only if there is between `$min` and `$max` items.
// @group Quantity queries
// @param {number} $limit
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
2017-12-07 11:16:46 -05:00
@mixin in-between($min, $max) {
$selector: &;
$child: nth(nth($selector, -1), -1);
2017-12-07 11:16:46 -05:00
&:nth-last-child(n + #{$min}):nth-last-child(-n + #{$max}):first-child,
&:nth-last-child(n + #{$min}):nth-last-child(-n + #{$max}):first-child ~ #{$child} {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// Select the first exact child
// @group no-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
2017-12-07 11:16:46 -05:00
@mixin first-child() {
&:first-of-type {
@content
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// Select the last exact child
// @group no-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
2017-12-07 11:16:46 -05:00
@mixin last-child() {
&:last-of-type {
@content
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// Select all even children.
// @group no-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
2017-12-07 11:16:46 -05:00
@mixin even() {
&:nth-child(even) {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// Select all odd children.
// @group no-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
2017-12-07 11:16:46 -05:00
@mixin odd() {
&:nth-child(odd) {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// Select only the first and last child.
// @group no-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
2017-12-07 11:16:46 -05:00
@mixin first-last() {
&:first-child,
&:last-child {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// Will only select the child if its unique.
// @group no-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
// @alias only
2017-12-07 11:16:46 -05:00
@mixin unique() {
&:only-child {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// Will only select the child if its unique.
// @group no-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
2017-12-07 11:16:46 -05:00
@mixin only() {
&:only-child {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// Will only select children if they are not unique. Meaning if there is at
// least 2 children, the style is applied.
// @group no-arguments
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
2017-12-07 11:16:46 -05:00
@mixin not-unique() {
&:not(:only-child) {
@content;
}
2017-12-07 11:16:46 -05:00
}
2022-05-12 16:15:44 +02:00
// This mixin is used to automatically sort z-index in numerical order. But it
// can also sort them in anti-numerical order, depending the parameters you use.
// @group using functions
// @content [Write the style you want to apply to the children, and it will be added within the @content directive]
// @param {number} $num - Number of children
// @param {string} $direction [forward] - Direction of the sort
// @param {number} $index [0] - Index of the sorting
2017-12-07 11:16:46 -05:00
@mixin child-index($num, $direction: 'forward', $index: 0) {
@for $i from 1 through $num {
@if ($direction == 'forward') {
&:nth-child(#{$i}) {
z-index: order-index($i, $index);
@content;
}
} @else if ($direction == 'backward') {
&:nth-last-child(#{$i}) {
z-index: order-index($i, $index);
@content;
}
}
2017-12-07 11:16:46 -05:00
}
}
2022-05-12 16:15:44 +02:00
// Used by the child-index mixin. It will returned the proper sorted numbers
// depending on the `$index` value.
// @access private
// @param {number} $num - Number of children
// @param {number} $index - Index of the sorting
2017-12-07 11:16:46 -05:00
@function order-index($i, $index) {
@return ($index + $i);
2017-12-07 11:16:46 -05:00
}