styled components custom behavior
This commit is contained in:
parent
8ee2707ce6
commit
9d0d54c2e4
|
@ -8,7 +8,9 @@ rec {
|
||||||
|
|
||||||
writeAttrs = attrs:
|
writeAttrs = attrs:
|
||||||
toString (builtins.attrValues (
|
toString (builtins.attrValues (
|
||||||
builtins.mapAttrs (key: value: ''${key}="${toString value}"'') attrs
|
builtins.mapAttrs (key: value:
|
||||||
|
if (builtins.substring 0 2 key) == "__" then ""
|
||||||
|
else ''${key}="${toString value}"'') attrs
|
||||||
));
|
));
|
||||||
|
|
||||||
tag = tag: attrs: child: {
|
tag = tag: attrs: child: {
|
||||||
|
|
|
@ -8,7 +8,7 @@ let
|
||||||
// {style = self.style + new.style;};
|
// {style = self.style + new.style;};
|
||||||
};
|
};
|
||||||
|
|
||||||
mkStyle = identifier: styles: ''
|
mkStyle = identifier: styles: if styles == {} then "" else ''
|
||||||
${identifier} {
|
${identifier} {
|
||||||
${toString (builtins.attrValues (
|
${toString (builtins.attrValues (
|
||||||
builtins.mapAttrs (
|
builtins.mapAttrs (
|
||||||
|
@ -34,8 +34,10 @@ let
|
||||||
+ id;
|
+ id;
|
||||||
in {
|
in {
|
||||||
styled = name: tag: cprops: styles:
|
styled = name: tag: cprops: styles:
|
||||||
{
|
let
|
||||||
${name} = props: child: (html.tag tag (props // cprops) child);
|
custom = cprops.__child or (child: child);
|
||||||
|
in{
|
||||||
|
${name} = props: child: (html.tag tag (props // cprops) (custom child));
|
||||||
|
|
||||||
style = mkStyle (mkIdentifier tag cprops) styles;
|
style = mkStyle (mkIdentifier tag cprops) styles;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,13 @@ let
|
||||||
})
|
})
|
||||||
(style.style "body" {
|
(style.style "body" {
|
||||||
foo = "bar";
|
foo = "bar";
|
||||||
});
|
})
|
||||||
|
(style.styled "list" "ul" {
|
||||||
|
__child = child:
|
||||||
|
assert builtins.isList child;
|
||||||
|
(map (html.tag "li" {}) child);
|
||||||
|
} {})
|
||||||
|
;
|
||||||
in [
|
in [
|
||||||
(it "makes a p component" {
|
(it "makes a p component" {
|
||||||
expected = html.tag "p" {} "yes";
|
expected = html.tag "p" {} "yes";
|
||||||
|
@ -42,6 +48,13 @@ in [
|
||||||
expected = html.tag "div" {class = ["foo" "bar"];} "foobar";
|
expected = html.tag "div" {class = ["foo" "bar"];} "foobar";
|
||||||
actual = my.foobar {} "foobar";
|
actual = my.foobar {} "foobar";
|
||||||
})
|
})
|
||||||
|
(it "does custom behavour" {
|
||||||
|
expected = toString (html.tag "ul" {} [
|
||||||
|
(html.tag "li" {} "1")
|
||||||
|
(html.tag "li" {} "2")
|
||||||
|
]);
|
||||||
|
actual = toString ( my.list {} ["1" "2"] );
|
||||||
|
})
|
||||||
(it "combines attrs" {
|
(it "combines attrs" {
|
||||||
expected = html.tag "div" {
|
expected = html.tag "div" {
|
||||||
id = "foo";
|
id = "foo";
|
||||||
|
|
Loading…
Reference in a new issue