html.nix/css.nix

20 lines
607 B
Nix
Raw Normal View History

2022-07-30 12:42:09 +03:00
{utils}: let
2021-05-16 02:56:54 +03:00
inherit (utils) mapAttrsToList concatStringsSep isList toString map;
2022-07-30 12:42:09 +03:00
evalCssValue = value:
if isList value
then concatStringsSep ", " (map toString value)
else toString value;
2021-05-17 18:41:37 +03:00
evalInner = inner: concatStringsSep " " (mapAttrsToList (name: value: "${name}: ${evalCssValue value};") inner);
2021-05-16 02:56:54 +03:00
css = maybeAttrs:
if isList maybeAttrs
2021-05-17 18:41:37 +03:00
then concatStringsSep " " maybeAttrs
else concatStringsSep " " (mapAttrsToList (name: inner: "${name} { ${evalInner inner} }") maybeAttrs);
2022-07-30 12:42:09 +03:00
in {
2021-05-16 02:56:54 +03:00
inherit css;
media = rule: inner: ''
2021-05-17 18:41:37 +03:00
@media (${rule}) { ${css inner} }
2021-05-16 02:56:54 +03:00
'';
}