merge styles with attrs in styled components
This commit is contained in:
parent
234c629e66
commit
a7c1a1c7de
7 changed files with 68 additions and 39 deletions
|
@ -1,5 +1,8 @@
|
|||
let
|
||||
keyvalue = key: value: ''${key}="${toString value}"'';
|
||||
keyvalue = key: value:
|
||||
assert builtins.isString key;
|
||||
if value == "" || value == [] || value == {} then "" else
|
||||
''${key}="${toString value}"'';
|
||||
in rec {
|
||||
toHTML = elem:
|
||||
if builtins.typeOf elem == "string"
|
||||
|
@ -9,15 +12,16 @@ in rec {
|
|||
else ''<${elem.tag} ${writeAttrs elem.attrs}>${toHTML elem.child}</${elem.tag}>'';
|
||||
|
||||
writeAttrs = attrs:
|
||||
toString (builtins.attrValues (
|
||||
toString (builtins.filter (value: value != "") (builtins.attrValues (
|
||||
builtins.mapAttrs (key: value:
|
||||
if (builtins.isPath value)
|
||||
then keyvalue key (baseNameOf value)
|
||||
else if (builtins.substring 0 2 key) == "__"
|
||||
else
|
||||
if (builtins.substring 0 2 key) == "__"
|
||||
then ""
|
||||
else keyvalue key value)
|
||||
attrs
|
||||
));
|
||||
)));
|
||||
|
||||
tag = tag: attrs: child: {
|
||||
inherit tag attrs child;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue