_mixins.scss 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. @use "sass:math";
  2. @function divide($number1, $number2) {
  3. @return math.div($number1, $number2);
  4. }
  5. @function theme-darken($color) {
  6. @return darken($color, 20%);
  7. }
  8. @function theme-lighten($color) {
  9. @return rgba($color, .08);
  10. }
  11. @function str-replace($string, $search, $replace: '') {
  12. $index: str-index($string, $search);
  13. @if $index {
  14. @return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
  15. }
  16. @return $string;
  17. }
  18. @function url-svg($svg) {
  19. $svg: str-replace($svg, '#', '%23');
  20. $svg: str-replace($svg, '<svg', '<svg xmlns="http://www.w3.org/2000/svg"');
  21. @return url('data:image/svg+xml;charset=UTF-8,#{$svg}');
  22. }
  23. @function add($value1, $value2, $return-calc: true) {
  24. @if $value1 == null {
  25. @return $value2;
  26. }
  27. @if $value2 == null {
  28. @return $value1;
  29. }
  30. @if type-of($value1) == number and type-of($value2) == number and comparable($value1, $value2) {
  31. @return $value1 + $value2;
  32. }
  33. @return if($return-calc == true, calc(#{$value1} + #{$value2}), $value1 + unquote(" + ") + $value2);
  34. }
  35. @function subtract($value1, $value2, $return-calc: true) {
  36. @if $value1 == null and $value2 == null {
  37. @return null;
  38. }
  39. @if $value1 == null {
  40. @return -$value2;
  41. }
  42. @if $value2 == null {
  43. @return $value1;
  44. }
  45. @if type-of($value1) == number and type-of($value2) == number and comparable($value1, $value2) {
  46. @return $value1 - $value2;
  47. }
  48. @return if($return-calc == true, calc(#{$value1} - #{$value2}), $value1 + unquote(" - ") + $value2);
  49. }
  50. @function px2rem($px) {
  51. @return divide($px, 16px) * 1rem;
  52. }
  53. @function str-replace($string, $search, $replace: '') {
  54. $index: str-index($string, $search);
  55. @if $index {
  56. @return str-slice($string, 1, $index - 1) + $replace + str-replace(str-slice($string, $index + str-length($search)), $search, $replace);
  57. }
  58. @return $string;
  59. }
  60. @function to-rgb($color) {
  61. @return "#{red($color)}, #{green($color)}, #{blue($color)}";
  62. }
  63. @function breakpoint-prefix($name) {
  64. @return media-prefix(if(media-breakpoint-min($name), $name, ''));
  65. }
  66. @function media-breakpoint-min($name, $breakpoints: $grid-breakpoints) {
  67. $min: map-get($breakpoints, $name);
  68. @return if($min != 0, $min, null);
  69. }
  70. @function media-prefix($name) {
  71. @return if($name == '', "", "#{$name}\\:");
  72. }
  73. @function breakpoint-min($name) {
  74. $min: map-get($grid-breakpoints, $name);
  75. @return if($min != 0, $min, null);
  76. }
  77. @function breakpoint-max($name, $breakpoints: $grid-breakpoints) {
  78. $max: map-get($breakpoints, $name);
  79. @return if($max and $max > 0, $max - .02, null);
  80. }
  81. @mixin media-breakpoint-up($name) {
  82. $min: breakpoint-min($name);
  83. @if type-of($name) == 'number' and $name != 0 {
  84. $min: $name;
  85. }
  86. @if $min {
  87. @media (min-width: $min) {
  88. @content;
  89. }
  90. } @else {
  91. @content;
  92. }
  93. }
  94. @mixin media-breakpoint-down($name, $breakpoints: $grid-breakpoints) {
  95. $max: breakpoint-max($name, $breakpoints);
  96. @if $max {
  97. @media (max-width: $max) {
  98. @content;
  99. }
  100. } @else {
  101. @content;
  102. }
  103. }
  104. @mixin media-retina {
  105. @media
  106. only screen and (-webkit-min-device-pixel-ratio: 2) and (min-width: 320px),
  107. only screen and ( min--moz-device-pixel-ratio: 2) and (min-width: 320px),
  108. only screen and ( -o-min-device-pixel-ratio: 2/1) and (min-width: 320px),
  109. only screen and ( min-device-pixel-ratio: 2) and (min-width: 320px),
  110. only screen and ( min-resolution: 192dpi) and (min-width: 320px),
  111. only screen and ( min-resolution: 2dppx) and (min-width: 320px) {
  112. @content;
  113. }
  114. }
  115. @mixin generate-utility($utility, $breakpoint, $breakpoint-prefix: null) {
  116. $values: map-get($utility, values);
  117. $media-prefix: media-prefix($breakpoint-prefix);
  118. @if ($breakpoint) {
  119. $media-prefix: breakpoint-prefix($breakpoint);
  120. }
  121. @if type-of($values) == "string" or type-of(nth($values, 1)) != "list" {
  122. $values: zip($values, $values);
  123. }
  124. @each $key, $value in $values {
  125. $properties: map-get($utility, property);
  126. @if type-of($properties) == "string" {
  127. $properties: append((), $properties);
  128. }
  129. $property-class: if(map-has-key($utility, class), map-get($utility, class), nth($properties, 1));
  130. $property-class: if($property-class == null, "", $property-class);
  131. $property-class-modifier: if($key, if($property-class == "" and $breakpoint-prefix == "", "", "-") + $key, "");
  132. @if $value != null {
  133. .#{$media-prefix + $property-class + $property-class-modifier} {
  134. @each $property in $properties {
  135. #{$property}: $value !important;
  136. @if map-get($utility, extra) {
  137. @each $extra-prop, $extra-value in map-get($utility, extra) {
  138. #{$extra-prop}: $extra-value !important;
  139. }
  140. }
  141. }
  142. }
  143. }
  144. }
  145. }
  146. @mixin make-row($gutter: $grid-padding) {
  147. --gutter-x: #{$gutter};
  148. --gutter-y: #{$gutter};
  149. display: flex;
  150. flex-wrap: wrap;
  151. margin-top: calc(var(--gutter-y) * -1);
  152. margin-right: calc(var(--gutter-x) / -2);
  153. margin-left: calc(var(--gutter-x) / -2);
  154. }
  155. @mixin make-col-ready($gutter: $grid-padding) {
  156. flex-shrink: 0;
  157. width: 100%;
  158. max-width: 100%;
  159. padding-right: calc(var(--gutter-x) / 2);
  160. padding-left: calc(var(--gutter-x) / 2);
  161. margin-top: var(--gutter-y);
  162. }
  163. @mixin make-col($size, $columns: $grid-columns) {
  164. flex: 0 0 auto;
  165. width: percentage(divide($size, $columns));
  166. }
  167. @mixin make-col-auto() {
  168. flex: 0 0 auto;
  169. width: auto;
  170. }
  171. @mixin make-col-offset($size, $columns: $grid-columns) {
  172. $num: divide($size, $columns);
  173. margin-left: if($num == 0, 0, percentage($num));
  174. }
  175. @mixin row-cols($count) {
  176. > * {
  177. flex: 0 0 auto;
  178. width: 100% / $count;
  179. }
  180. }
  181. @mixin make-grid-columns($columns: $grid-columns, $gutter: $grid-padding, $breakpoints: $grid-breakpoints) {
  182. @each $breakpoint in map-keys($breakpoints) {
  183. $prefix: breakpoint-prefix($breakpoint);
  184. @include media-breakpoint-up($breakpoint) {
  185. .#{$prefix}col {
  186. flex: 1 0 0%;
  187. }
  188. //.row-cols#{$prefix}-auto > * {
  189. // @include make-col-auto();
  190. //}
  191. //@if $grid-row-columns > 0 {
  192. // @for $i from 1 through $grid-row-columns {
  193. // .row-cols#{$infix}-#{$i} {
  194. // @include row-cols($i);
  195. // }
  196. // }
  197. //}
  198. .#{$prefix}col-auto {
  199. @include make-col-auto();
  200. }
  201. .#{$prefix}col-side {
  202. flex: 0 0 auto;
  203. width: 12rem;
  204. }
  205. .#{$prefix}col-slim {
  206. flex: 0 0 auto;
  207. width: calc(#{$container-slim-max-width} + var(--gutter-x))
  208. }
  209. .#{$prefix}col-narrow {
  210. flex: 0 0 auto;
  211. width: calc(#{$container-narrow-max-width} + var(--gutter-x));
  212. }
  213. @if $columns > 0 {
  214. @for $i from 1 through $columns {
  215. .#{$prefix}col-#{$i} {
  216. @include make-col($i, $columns);
  217. }
  218. }
  219. @for $i from 0 through ($columns - 1) {
  220. @if not ($prefix == "" and $i == 0) {
  221. .#{$prefix}offset-#{$i} {
  222. @include make-col-offset($i, $columns);
  223. }
  224. .#{$prefix}offset-n#{$i} {
  225. @include make-col-offset(-$i, $columns);
  226. }
  227. }
  228. }
  229. }
  230. .#{$prefix}gy {
  231. --gutter-y: #{$grid-padding};
  232. }
  233. .#{$prefix}gx {
  234. --gutter-x: #{$grid-padding};
  235. }
  236. .#{$prefix}g {
  237. --gutter-y: #{$grid-padding};
  238. --gutter-x: #{$grid-padding};
  239. }
  240. @each $key, $value in $gaps {
  241. .#{$prefix}g-#{$key},
  242. .#{$prefix}gx-#{$key} {
  243. --gutter-x: #{$value};
  244. }
  245. .#{$prefix}g-#{$key},
  246. .#{$prefix}gy-#{$key} {
  247. --gutter-y: #{$value};
  248. }
  249. }
  250. }
  251. }
  252. }
  253. @mixin text-truncate($size: 100%) {
  254. max-width: $size;
  255. white-space: nowrap;
  256. text-overflow: ellipsis;
  257. overflow: hidden;
  258. }
  259. @function contrast-color($color, $dark: $color-primary, $light: $color-white) {
  260. $threshold: 55%;
  261. @return if(lightness($color) < $threshold, $light, $dark)
  262. }
  263. @mixin css-variables() {
  264. @each $name, $value in $css-variables {
  265. @if type-of($value) == 'map' {
  266. @each $variant-name, $variant-value in $value {
  267. --#{$name}#{if($variant-name != null, '-#{$variant-name}', '')}: #{$variant-value};
  268. }
  269. } @else {
  270. --#{$name}: #{$value};
  271. }
  272. }
  273. }
  274. @mixin scrollbar($color: $color-text) {
  275. &::-webkit-scrollbar {
  276. width: 16px;
  277. cursor: pointer;
  278. }
  279. &::-webkit-scrollbar-track {
  280. background: transparent;
  281. border: 3px solid transparent
  282. }
  283. &::-webkit-scrollbar-thumb {
  284. background: rgba($color, .1);
  285. border-radius: 100vh;
  286. background-clip: padding-box;
  287. border: 5px solid transparent;
  288. box-shadow: inset 0 0 15px 15px transparent;
  289. transition: $transition-duration box-shadow;
  290. &:hover {
  291. box-shadow: inset 0 0 15px 15px rgba($color, .4)
  292. }
  293. }
  294. &:hover {
  295. &::-webkit-scrollbar-thumb {
  296. box-shadow: inset 0 0 15px 15px rgba($color, .2)
  297. }
  298. }
  299. }
  300. @mixin scrollbar-dark {
  301. @include scrollbar($color-white);
  302. }