summaryrefslogtreecommitdiffstats
path: root/core/css/functions.scss
diff options
context:
space:
mode:
authorMichael Weimann <mail@michael-weimann.eu>2018-08-30 20:00:13 +0200
committerRoeland Jago Douma <roeland@famdouma.nl>2018-10-02 08:37:55 +0200
commita45ec3d32430f40be93fa5f09832917b82c83f15 (patch)
treebdd333db314d26f5018217cb79c255cf9fac405d /core/css/functions.scss
parentc7e81e17c86a6e6beff433238a6923f5d931c22f (diff)
downloadnextcloud-server-a45ec3d32430f40be93fa5f09832917b82c83f15.tar.gz
nextcloud-server-a45ec3d32430f40be93fa5f09832917b82c83f15.zip
Refactors the scss svg functions
Signed-off-by: Michael Weimann <mail@michael-weimann.eu>
Diffstat (limited to 'core/css/functions.scss')
-rw-r--r--core/css/functions.scss52
1 files changed, 38 insertions, 14 deletions
diff --git a/core/css/functions.scss b/core/css/functions.scss
index 0815ba29ab6..5007c3bbe79 100644
--- a/core/css/functions.scss
+++ b/core/css/functions.scss
@@ -19,31 +19,55 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
-
+
+/**
+ * Removes the "#" from a color.
+ *
+ * @param string $color The color
+ * @return string The color without #
+ */
+@function remove-hash-from-color($color) {
+ $index: str-index(inspect($color), '#');
+ @if $index {
+ $color: str-slice(inspect($color), 2);
+ }
+ @return $color;
+}
+
+/**
+ * Calculates the URL to the svg under the SVG API.
+ *
+ * @param string $icon the icon filename
+ * @param string $dir the icon folder within /core/img if $core or app name
+ * @param string $color the desired color in hexadecimal
+ * @param int [$version] the version of the file
+ * @param bool [$core] search icon in core
+ * @return string The URL to the svg.
+ */
+@function icon-color-path($icon, $dir, $color, $version: 1, $core: false) {
+ $color: remove-hash-from-color($color);
+ @if $core {
+ @return '#{$webroot}/svg/core/#{$dir}/#{$icon}/#{$color}?v=#{$version}';
+ } @else {
+ @return '#{$webroot}/svg/#{$dir}/#{$icon}/#{$color}?v=#{$version}';
+ }
+}
+
/**
* SVG COLOR API
- *
+ *
* @param string $icon the icon filename
* @param string $dir the icon folder within /core/img if $core or app name
* @param string $color the desired color in hexadecimal
* @param int $version the version of the file
* @param bool [$core] search icon in core
*
- * @returns string the url to the svg api endpoint
+ * @returns A background image with the url to the set to the requested icon.
*/
@mixin icon-color($icon, $dir, $color, $version: 1, $core: false) {
- // remove # from color
- // inspect cast int to string
- $index: str-index(inspect($color), '#');
- @if $index {
- $color: str-slice(inspect($color), 2);
- }
+ $color: remove-hash-from-color($color);
$varName: "--icon-#{$icon}-#{$color}";
- @if $core {
- #{$varName}: url('#{$webroot}/svg/core/#{$dir}/#{$icon}/#{$color}?v=#{$version}');
- } @else {
- #{$varName}: url('#{$webroot}/svg/#{$dir}/#{$icon}/#{$color}?v=#{$version}');
- }
+ #{$varName}: url(icon-color-path($icon, $dir, $color, $version, $core));
background-image: var(#{$varName});
}