functions.scss 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * @copyright Copyright (c) 2018, John Molakvoæ (skjnldsv@protonmail.com)
  3. *
  4. * @author John Molakvoæ (skjnldsv) <skjnldsv@protonmail.com>
  5. *
  6. * @license GNU AGPL version 3 or any later version
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU Affero General Public License as
  10. * published by the Free Software Foundation, either version 3 of the
  11. * License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU Affero General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * Removes the "#" from a color.
  24. *
  25. * @param string $color The color
  26. * @return string The color without #
  27. */
  28. @function remove-hash-from-color($color) {
  29. $color: unquote($color);
  30. $index: str-index(inspect($color), '#');
  31. @if $index {
  32. $color: str-slice(inspect($color), 2);
  33. }
  34. @return $color;
  35. }
  36. /**
  37. * Calculates the URL to the svg under the SVG API.
  38. *
  39. * @param string $icon the icon filename
  40. * @param string $dir the icon folder within /core/img if $core or app name
  41. * @param string $color the desired color in hexadecimal
  42. * @param int [$version] the version of the file
  43. * @param bool [$core] search icon in core
  44. * @return string The URL to the svg.
  45. */
  46. @function icon-color-path($icon, $dir, $color, $version: 1, $core: false) {
  47. $color: remove-hash-from-color($color);
  48. @if $core {
  49. @return '#{$webroot}/svg/core/#{$dir}/#{$icon}?color=#{$color}&v=#{$version}';
  50. } @else {
  51. @return '#{$webroot}/svg/#{$dir}/#{$icon}?color=#{$color}&v=#{$version}';
  52. }
  53. }
  54. /**
  55. * SVG COLOR API
  56. *
  57. * @param string $icon the icon filename
  58. * @param string $dir the icon folder within /core/img if $core or app name
  59. * @param string $color the desired color in hexadecimal
  60. * @param int $version the version of the file
  61. * @param bool [$core] search icon in core
  62. *
  63. * @returns A background image with the url to the set to the requested icon.
  64. */
  65. @mixin icon-color($icon, $dir, $color, $version: 1, $core: false) {
  66. $color: remove-hash-from-color($color);
  67. /* $dir is the app name, so we add this to the icon var to avoid conflicts between apps */
  68. $varName: "--icon-#{$dir}-#{$icon}-#{$color}";
  69. @if $core {
  70. $varName: "--icon-#{$icon}-#{$color}";
  71. }
  72. #{$varName}: url(icon-color-path($icon, $dir, $color, $version, $core));
  73. background-image: var(#{$varName});
  74. }
  75. /**
  76. * Create black and white icons
  77. * This will add a default black version of and an additional white version when .icon-white is applied
  78. */
  79. @mixin icon-black-white($icon, $dir, $version, $core: false) {
  80. .icon-#{$icon} {
  81. @include icon-color($icon, $dir, $color-black, $version, $core);
  82. }
  83. .icon-#{$icon}-white,
  84. .icon-#{$icon}.icon-white {
  85. @include icon-color($icon, $dir, $color-white, $version, $core);
  86. }
  87. }
  88. @mixin position($value) {
  89. @if $value == 'sticky' {
  90. position: -webkit-sticky; // Safari support
  91. position: sticky;
  92. } @else {
  93. position: $value;
  94. }
  95. }