html.nix/css.nix
2022-07-30 12:42:09 +03:00

20 lines
607 B
Nix

{utils}: let
inherit (utils) mapAttrsToList concatStringsSep isList toString map;
evalCssValue = value:
if isList value
then concatStringsSep ", " (map toString value)
else toString value;
evalInner = inner: concatStringsSep " " (mapAttrsToList (name: value: "${name}: ${evalCssValue value};") inner);
css = maybeAttrs:
if isList maybeAttrs
then concatStringsSep " " maybeAttrs
else concatStringsSep " " (mapAttrsToList (name: inner: "${name} { ${evalInner inner} }") maybeAttrs);
in {
inherit css;
media = rule: inner: ''
@media (${rule}) { ${css inner} }
'';
}