_mixins.scss 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. // Mixins
  2. // Bootstrap Mixins
  3. @function breakpoint-next($name, $breakpoints: $grid-breakpoints, $breakpoint-names: map-keys($breakpoints)) {
  4. $n: index($breakpoint-names, $name);
  5. @return if($n < length($breakpoint-names), nth($breakpoint-names, $n + 1), null);
  6. }
  7. @function breakpoint-min($name, $breakpoints: $grid-breakpoints) {
  8. $min: map-get($breakpoints, $name);
  9. @return if($min !=0, $min, null);
  10. }
  11. @function breakpoint-max($name, $breakpoints: $grid-breakpoints) {
  12. $next: breakpoint-next($name, $breakpoints);
  13. @return if($next, breakpoint-min($next, $breakpoints) - .02px, null);
  14. }
  15. // Media of at least the minimum breakpoint width. No query for the smallest breakpoint.
  16. // Makes the @content apply to the given breakpoint and wider.
  17. @mixin media-breakpoint-up($name, $breakpoints: $grid-breakpoints) {
  18. $min: breakpoint-min($name, $breakpoints);
  19. @if $min {
  20. @media (min-width: $min) {
  21. @content;
  22. }
  23. }
  24. @else {
  25. @content;
  26. }
  27. }
  28. // Media of at most the maximum breakpoint width. No query for the largest breakpoint.
  29. // Makes the @content apply to the given breakpoint and narrower.
  30. @mixin media-breakpoint-down($name, $breakpoints: $grid-breakpoints) {
  31. $max: breakpoint-max($name, $breakpoints);
  32. @if $max {
  33. @media (max-width: $max) {
  34. @content;
  35. }
  36. }
  37. @else {
  38. @content;
  39. }
  40. }
  41. // Media that spans multiple breakpoint widths.
  42. // Makes the @content apply between the min and max breakpoints
  43. @mixin media-breakpoint-between($lower, $upper, $breakpoints: $grid-breakpoints) {
  44. $min: breakpoint-min($lower, $breakpoints);
  45. $max: breakpoint-max($upper, $breakpoints);
  46. @if $min !=null and $max !=null {
  47. @media (min-width: $min) and (max-width: $max) {
  48. @content;
  49. }
  50. }
  51. @else if $max==null {
  52. @include media-breakpoint-up($lower, $breakpoints) {
  53. @content;
  54. }
  55. }
  56. @else if $min==null {
  57. @include media-breakpoint-down($upper, $breakpoints) {
  58. @content;
  59. }
  60. }
  61. }
  62. // Media between the breakpoint's minimum and maximum widths.
  63. // No minimum for the smallest breakpoint, and no maximum for the largest one.
  64. // Makes the @content apply only to the given breakpoint, not viewports any wider or narrower.
  65. @mixin media-breakpoint-only($name, $breakpoints: $grid-breakpoints) {
  66. $min: breakpoint-min($name, $breakpoints);
  67. $max: breakpoint-max($name, $breakpoints);
  68. @if $min !=null and $max !=null {
  69. @media (min-width: $min) and (max-width: $max) {
  70. @content;
  71. }
  72. }
  73. @else if $max==null {
  74. @include media-breakpoint-up($name, $breakpoints) {
  75. @content;
  76. }
  77. }
  78. @else if $min==null {
  79. @include media-breakpoint-down($name, $breakpoints) {
  80. @content;
  81. }
  82. }
  83. }
  84. @function breakpoint-infix($name, $breakpoints: $grid-breakpoints) {
  85. @return if(breakpoint-min($name, $breakpoints)==null, "", "-#{$name}");
  86. }
  87. @mixin hover-focus {
  88. &:hover,
  89. &:focus {
  90. @content;
  91. }
  92. }
  93. // Background color
  94. @mixin bg-variant($parent, $color) {
  95. #{$parent} {
  96. background-color: $color !important;
  97. }
  98. a#{$parent},
  99. button#{$parent} {
  100. @include hover-focus {
  101. background-color: darken($color, 10%) !important;
  102. }
  103. }
  104. }
  105. // Typography
  106. @mixin text-emphasis-variant($parent, $color) {
  107. #{$parent} {
  108. color: $color !important;
  109. }
  110. a#{$parent} {
  111. @include hover-focus {
  112. color: darken($color, 10%) !important;
  113. }
  114. }
  115. }
  116. // Placeholder
  117. @mixin placeholder {
  118. &::placeholder {
  119. @content;
  120. }
  121. }
  122. /// Grid system
  123. //
  124. // Generate semantic grid columns with these mixins.
  125. @mixin make-container($gutter: $grid-gutter-width) {
  126. width: 100%;
  127. padding-right: $gutter / 2;
  128. padding-left: $gutter / 2;
  129. margin-right: auto;
  130. margin-left: auto;
  131. }
  132. // For each breakpoint, define the maximum width of the container in a media query
  133. @mixin make-container-max-widths($max-widths: $container-max-widths, $breakpoints: $grid-breakpoints) {
  134. @each $breakpoint,
  135. $container-max-width in $max-widths {
  136. @include media-breakpoint-up($breakpoint, $breakpoints) {
  137. max-width: $container-max-width;
  138. }
  139. }
  140. }
  141. @mixin make-row() {
  142. display: flex;
  143. flex-wrap: wrap;
  144. margin-right: ($grid-gutter-width / -2);
  145. margin-left: ($grid-gutter-width / -2);
  146. }
  147. @mixin make-col-ready() {
  148. position: relative;
  149. // Prevent columns from becoming too narrow when at smaller grid tiers by
  150. // always setting `width: 100%;`. This works because we use `flex` values
  151. // later on to override this initial width.
  152. width: 100%;
  153. min-height: 1px; // Prevent collapsing
  154. padding-right: ($grid-gutter-width / 2);
  155. padding-left: ($grid-gutter-width / 2);
  156. }
  157. @mixin make-col($size, $columns: $grid-columns) {
  158. flex: 0 0 percentage($size / $columns);
  159. // Add a `max-width` to ensure content within each column does not blow out
  160. // the width of the column. Applies to IE10+ and Firefox. Chrome and Safari
  161. // do not appear to require this.
  162. max-width: percentage($size / $columns);
  163. }
  164. @mixin make-col-offset($size, $columns: $grid-columns) {
  165. $num: $size / $columns;
  166. margin-left: if($num==0, 0, percentage($num));
  167. }
  168. @mixin clearfix() {
  169. &::after {
  170. display: block;
  171. clear: both;
  172. content: "";
  173. }
  174. }
  175. @mixin float-left {
  176. float: left !important;
  177. }
  178. @mixin float-right {
  179. float: right !important;
  180. }
  181. @mixin float-none {
  182. float: none !important;
  183. }
  184. // CSS image replacement
  185. @mixin text-hide($ignore-warning: false) {
  186. // stylelint-disable-next-line font-family-no-missing-generic-family-keyword
  187. font: 0/0 a;
  188. color: transparent;
  189. text-shadow: none;
  190. background-color: transparent;
  191. border: 0;
  192. @if ($ignore-warning !=true) {
  193. @warn "The `text-hide()` mixin has been deprecated as of v4.1.0. It will be removed entirely in v5.";
  194. }
  195. }
  196. // Only display content to screen readers
  197. //
  198. // See: https://a11yproject.com/posts/how-to-hide-content/
  199. // See: https://hugogiraudel.com/2016/10/13/css-hide-and-seek/
  200. @mixin sr-only {
  201. position: absolute;
  202. width: 1px;
  203. height: 1px;
  204. padding: 0;
  205. overflow: hidden;
  206. clip: rect(0, 0, 0, 0);
  207. white-space: nowrap;
  208. border: 0;
  209. }
  210. // Use in conjunction with .sr-only to only display content when it's focused.
  211. //
  212. // Useful for "Skip to main content" links; see https://www.w3.org/TR/2013/NOTE-WCAG20-TECHS-20130905/G1
  213. //
  214. // Credit: HTML5 Boilerplate
  215. @mixin sr-only-focusable {
  216. &:active,
  217. &:focus {
  218. position: static;
  219. width: auto;
  220. height: auto;
  221. overflow: visible;
  222. clip: auto;
  223. white-space: normal;
  224. }
  225. }
  226. @mixin invisible($visibility) {
  227. visibility: $visibility !important;
  228. }
  229. // MDB Mixins
  230. // Set the color of the button and badge
  231. @function set-notification-text-color($color) {
  232. @if (lightness($color) > 80) {
  233. @return $black-base; // Lighter backgorund, return dark color
  234. }
  235. @else {
  236. @return $white-base; // Darker background, return light color
  237. }
  238. }
  239. // Make button
  240. @mixin make-button ($name, $color) {
  241. .btn-#{$name} {
  242. background-color: $color !important;
  243. color: set-notification-text-color($color);
  244. &:hover {
  245. background-color: lighten($color, 5%);
  246. color: set-notification-text-color($color);
  247. }
  248. &:focus,
  249. &.focus {
  250. box-shadow: $z-depth-1-half;
  251. }
  252. &:focus,
  253. &:active,
  254. &.active {
  255. background-color: darken($color, 20%);
  256. }
  257. &.dropdown-toggle {
  258. background-color: $color !important;
  259. &:hover,
  260. &:focus {
  261. background-color: lighten($color, 5%) !important;
  262. }
  263. }
  264. &:not([disabled]):not(.disabled):active,
  265. &:not([disabled]):not(.disabled).active,
  266. .show>&.dropdown-toggle {
  267. box-shadow: $z-depth-1-half;
  268. background-color: darken($color, 20%) !important;
  269. }
  270. &:not([disabled]):not(.disabled):active:focus,
  271. &:not([disabled]):not(.disabled).active:focus,
  272. .show>&.dropdown-toggle:focus {
  273. box-shadow: $z-depth-1-half;
  274. }
  275. }
  276. .#{$name}-ic {
  277. color: $color !important;
  278. &:hover,
  279. &:focus {
  280. color: $color;
  281. }
  282. }
  283. a.btn:not([href]):not([tabindex]),
  284. a.btn:not([href]):not([tabindex]):focus,
  285. a.btn:not([href]):not([tabindex]):hover {
  286. color: set-notification-text-color($color);
  287. }
  288. table {
  289. &.table {
  290. a {
  291. &.btn {
  292. &.btn-#{$name} {
  293. color: set-notification-text-color($color);
  294. }
  295. }
  296. }
  297. }
  298. }
  299. }
  300. // Make outline button
  301. @mixin make-outline-button ($name, $color) {
  302. .btn-outline-#{$name} {
  303. border: 2px solid $color !important;
  304. background-color: transparent !important;
  305. color: $color !important;
  306. &:hover,
  307. &:focus,
  308. &:active,
  309. &:active:focus,
  310. &.active {
  311. border-color: $color !important;
  312. background-color: transparent !important;
  313. color: $color !important;
  314. }
  315. &:not([disabled]):not(.disabled):active,
  316. &:not([disabled]):not(.disabled).active,
  317. .show>&.dropdown-toggle {
  318. box-shadow: $z-depth-1-half;
  319. background-color: transparent !important;
  320. border-color: $color !important;
  321. }
  322. &:not([disabled]):not(.disabled):active:focus,
  323. &:not([disabled]):not(.disabled).active:focus,
  324. .show>&.dropdown-toggle:focus {
  325. box-shadow: $z-depth-1-half;
  326. }
  327. }
  328. }
  329. // Make gradient
  330. @mixin make-gradient($name, $value) {
  331. .#{$name}-gradient {
  332. background: linear-gradient(40deg, map-get($value, start), map-get($value, end)) !important;
  333. }
  334. }
  335. $opacity: .9;
  336. // Make gradient
  337. @mixin make-gradient-rgba($name, $value) {
  338. .#{$name}-gradient-rgba {
  339. background: linear-gradient(40deg, map-get($value, start), map-get($value, end)) !important;
  340. }
  341. }
  342. // Make gradient button
  343. @mixin make-gradient-button($name, $value) {
  344. .btn {
  345. &.#{$name}-gradient {
  346. transition: .5s ease;
  347. color: $white-base;
  348. &:hover,
  349. &:focus,
  350. &:active,
  351. &:active:focus &.active {
  352. background: linear-gradient(lighten(map-get($value, start), 5%), lighten(map-get($value, end), 5%));
  353. }
  354. }
  355. }
  356. }
  357. // Button size
  358. @mixin button-size($padding-y, $padding-x, $font-size) {
  359. padding: $padding-y $padding-x;
  360. font-size: $font-size;
  361. }
  362. @mixin make-badge($name, $color) {
  363. .badge-#{$name} {
  364. background-color: $color !important;
  365. color: set-notification-text-color($color) !important;
  366. }
  367. }
  368. // Make input
  369. @mixin make-input($margin-bottom, $label-font-size, $label-active-font-size, $top, $prefix-font-size, $margin-left, $width, $margin-left-2) {
  370. .validate {
  371. margin-bottom: $margin-bottom;
  372. }
  373. label {
  374. font-size: $label-font-size;
  375. &.active {
  376. font-size: $label-active-font-size;
  377. }
  378. }
  379. .prefix {
  380. top: $top;
  381. font-size: $prefix-font-size;
  382. ~input,
  383. ~textarea {
  384. margin-left: $margin-left;
  385. width: $width;
  386. }
  387. ~label {
  388. margin-left: $margin-left;
  389. }
  390. ~.form-text {
  391. margin-left: $margin-left-2;
  392. }
  393. }
  394. }
  395. // Make navbar
  396. @mixin make-navbar($color-0, $background-image, $color, $color-2, $color-3) {
  397. .navbar-nav {
  398. .nav-item {
  399. .nav-link {
  400. &.disbled {
  401. color: $color-0;
  402. &:hover {
  403. color: $color-0;
  404. }
  405. }
  406. }
  407. }
  408. }
  409. .navbar-toggler-icon {
  410. background-image: $background-image;
  411. cursor: pointer;
  412. }
  413. .breadcrumb,
  414. .navbar-nav {
  415. .nav-item {
  416. .nav-link {
  417. color: $color;
  418. transition: $navbar-nav-transition;
  419. &:hover {
  420. color: $color-2;
  421. }
  422. }
  423. &.active>.nav-link {
  424. background-color: $color-3;
  425. &:hover {
  426. color: $color;
  427. }
  428. }
  429. }
  430. }
  431. .navbar-toggler {
  432. color: $color;
  433. }
  434. form {
  435. .md-form {
  436. input {
  437. border-bottom: 1px solid $color;
  438. &:focus:not([readonly]) {
  439. border-color: $input-md-focus-color;
  440. }
  441. }
  442. .form-control {
  443. color: $color;
  444. @include placeholder {
  445. color: $color;
  446. font-weight: $navbar-font-weight;
  447. }
  448. }
  449. }
  450. }
  451. }
  452. // Make floating button
  453. @mixin make-btn-floating($width, $height, $font-size, $line-height) {
  454. width: $width;
  455. height: $height;
  456. i {
  457. font-size: $font-size;
  458. line-height: $line-height;
  459. }
  460. }
  461. // Keyframes
  462. @mixin keyframes($animation-name) {
  463. @keyframes #{$animation-name} {
  464. @content;
  465. }
  466. }
  467. // Scroll bar and scroll spy width and height
  468. @mixin scroll-width($scrollbar-width) {
  469. width: $scrollbar-width;
  470. }
  471. @mixin scroll-height($scrollbar-height) {
  472. height: $scrollbar-height;
  473. }
  474. // Scroll spy font-weight
  475. @mixin scrollspy-font-weight($scrollspy-font-weight) {
  476. font-weight: $scrollspy-font-weight;
  477. }
  478. // Switch width and height
  479. @mixin switch-width-height($switchWidth, $switchHeight) {
  480. width: $switchWidth;
  481. height: $switchHeight;
  482. }
  483. // Make Box-shadows
  484. @mixin box-shadows($shadow...) {
  485. box-shadow: $shadow;
  486. }
  487. // Make Transition
  488. @mixin transition-main($transition...) {
  489. transition: $transition;
  490. }
  491. // Make border-radius scrollspy
  492. @mixin scrollspy-border-radius($scrollspy-radius) {
  493. border-radius: $scrollspy-radius;
  494. }
  495. // Make border-radius scrollspy 4rows
  496. @mixin scrollspy-border-radius-4rows($top-left, $top-right, $bottom-right, $bottom-left) {
  497. border-radius: $top-left $top-right $bottom-right $bottom-left;
  498. }
  499. //Make animation for progresss
  500. @mixin progress-animation-default($animation...) {
  501. animation: $animation;
  502. }
  503. //Make transform
  504. @mixin transform($transform...) {
  505. transform: $transform;
  506. }