Initial commit
[editorial.git] / assets / main / sass / libs / _functions.scss
diff --git a/assets/main/sass/libs/_functions.scss b/assets/main/sass/libs/_functions.scss
new file mode 100644 (file)
index 0000000..f563aab
--- /dev/null
@@ -0,0 +1,90 @@
+/// Removes a specific item from a list.\r
+/// @author Hugo Giraudel\r
+/// @param {list} $list List.\r
+/// @param {integer} $index Index.\r
+/// @return {list} Updated list.\r
+@function remove-nth($list, $index) {\r
+\r
+       $result: null;\r
+\r
+       @if type-of($index) != number {\r
+               @warn "$index: #{quote($index)} is not a number for `remove-nth`.";\r
+       }\r
+       @else if $index == 0 {\r
+               @warn "List index 0 must be a non-zero integer for `remove-nth`.";\r
+       }\r
+       @else if abs($index) > length($list) {\r
+               @warn "List index is #{$index} but list is only #{length($list)} item long for `remove-nth`.";\r
+       }\r
+       @else {\r
+\r
+               $result: ();\r
+               $index: if($index < 0, length($list) + $index + 1, $index);\r
+\r
+               @for $i from 1 through length($list) {\r
+\r
+                       @if $i != $index {\r
+                               $result: append($result, nth($list, $i));\r
+                       }\r
+\r
+               }\r
+\r
+       }\r
+\r
+       @return $result;\r
+\r
+}\r
+\r
+/// Gets a value from a map.\r
+/// @author Hugo Giraudel\r
+/// @param {map} $map Map.\r
+/// @param {string} $keys Key(s).\r
+/// @return {string} Value.\r
+@function val($map, $keys...) {\r
+\r
+       @if nth($keys, 1) == null {\r
+               $keys: remove-nth($keys, 1);\r
+       }\r
+\r
+       @each $key in $keys {\r
+               $map: map-get($map, $key);\r
+       }\r
+\r
+       @return $map;\r
+\r
+}\r
+\r
+/// Gets a duration value.\r
+/// @param {string} $keys Key(s).\r
+/// @return {string} Value.\r
+@function _duration($keys...) {\r
+       @return val($duration, $keys...);\r
+}\r
+\r
+/// Gets a font value.\r
+/// @param {string} $keys Key(s).\r
+/// @return {string} Value.\r
+@function _font($keys...) {\r
+       @return val($font, $keys...);\r
+}\r
+\r
+/// Gets a misc value.\r
+/// @param {string} $keys Key(s).\r
+/// @return {string} Value.\r
+@function _misc($keys...) {\r
+       @return val($misc, $keys...);\r
+}\r
+\r
+/// Gets a palette value.\r
+/// @param {string} $keys Key(s).\r
+/// @return {string} Value.\r
+@function _palette($keys...) {\r
+       @return val($palette, $keys...);\r
+}\r
+\r
+/// Gets a size value.\r
+/// @param {string} $keys Key(s).\r
+/// @return {string} Value.\r
+@function _size($keys...) {\r
+       @return val($size, $keys...);\r
+}
\ No newline at end of file