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
|
@ -7,38 +7,47 @@ in
|
|||
(it "makes a p tag" {
|
||||
expected = html.tag "p" {class = ["p"];} "foobar";
|
||||
actual = p {} "foobar";
|
||||
asString = true;
|
||||
})
|
||||
(it "makes a div tag" {
|
||||
expected = html.tag "div" {class = ["div"];} "foobar";
|
||||
actual = div {} "foobar";
|
||||
asString = true;
|
||||
})
|
||||
(it "makes a section tag" {
|
||||
expected = html.tag "section" {class = ["section"];} "foobar";
|
||||
actual = section {} "foobar";
|
||||
asString = true;
|
||||
})
|
||||
(it "makes a span tag" {
|
||||
expected = html.tag "span" {class = ["span"];} "foobar";
|
||||
actual = span {} "foobar";
|
||||
asString = true;
|
||||
})
|
||||
(it "makes a main tag" {
|
||||
expected = html.tag "main" {class = ["main"];} ["yeet"];
|
||||
actual = main {} ["yeet"];
|
||||
asString = true;
|
||||
})
|
||||
(it "makes an h1 tag" {
|
||||
expected = html.tag "h1" {} "foobar";
|
||||
actual = h 1 "foobar";
|
||||
asString = true;
|
||||
})
|
||||
(it "makes an h2 tag" {
|
||||
expected = html.tag "h2" {} "foobar";
|
||||
actual = h 2 "foobar";
|
||||
asString = true;
|
||||
})
|
||||
(it "makes a title tag" {
|
||||
expected = html.tag "title" {class = [];} "foobar";
|
||||
actual = title {} "foobar";
|
||||
asString = true;
|
||||
})
|
||||
(it "makes an a tag" {
|
||||
expected = html.tag "a" {href = "https://example.com";} "example";
|
||||
actual = link "https://example.com" "example";
|
||||
asString = true;
|
||||
})
|
||||
(it "makes a stylesheet link" {
|
||||
expected = html.tag "link" {
|
||||
|
@ -46,9 +55,10 @@ in
|
|||
rel = "stylesheet";
|
||||
} "";
|
||||
actual = stylesheet "/style";
|
||||
asString = true;
|
||||
})
|
||||
(it "makes a list" {
|
||||
expected = toString (html.tag "ul" {
|
||||
expected = (html.tag "ul" {
|
||||
__ = "";
|
||||
class = ["list"];
|
||||
} [
|
||||
|
@ -56,10 +66,11 @@ in
|
|||
(html.tag "li" {} "bar")
|
||||
(html.tag "li" {} "baz")
|
||||
]);
|
||||
actual = toString (list {} ["foo" "bar" "baz"]);
|
||||
actual = (list {} ["foo" "bar" "baz"]);
|
||||
asString = true;
|
||||
})
|
||||
(it "makes an html doc" {
|
||||
expected = toString (html.tag "html" {
|
||||
expected = (html.tag "html" {
|
||||
__child = "";
|
||||
class = [];
|
||||
lang = "en";
|
||||
|
@ -67,6 +78,7 @@ in
|
|||
(html.tag "head" {} ["foo"])
|
||||
(html.tag "body" {} "bar")
|
||||
]);
|
||||
actual = toString (doc {} [["foo"] "bar"]);
|
||||
actual = (doc {} [["foo"] "bar"]);
|
||||
asString = true;
|
||||
})
|
||||
]
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
msg: {
|
||||
actual,
|
||||
expected,
|
||||
asString ? false,
|
||||
}:
|
||||
if actual == expected
|
||||
if (
|
||||
if asString then toString actual == toString expected
|
||||
else actual == expected )
|
||||
then ''
|
||||
echo 'it ${msg}'
|
||||
''
|
||||
|
|
|
@ -4,40 +4,46 @@ let
|
|||
it = import ./it.nix;
|
||||
|
||||
my =
|
||||
(style.styled "p" "p" {} {
|
||||
(style.styled "p" "p" {style = {
|
||||
some-style = "some value";
|
||||
})
|
||||
(style.styled "div" "div" {class = ["something"];} {
|
||||
};})
|
||||
(style.styled "div" "div" {class = ["something"]; style = {
|
||||
this = "that";
|
||||
})
|
||||
};})
|
||||
(style.styled "s" "div" {
|
||||
id = "s";
|
||||
class = ["something"];
|
||||
} {
|
||||
s = "yes";
|
||||
})
|
||||
(style.styled "foobar" "div" {class = ["foo" "bar"];} {
|
||||
something = "something";
|
||||
})
|
||||
style = {
|
||||
s = "yes";
|
||||
};})
|
||||
(style.styled "foobar" "div" {
|
||||
class = ["foo" "bar"];
|
||||
style = {
|
||||
something = "something";
|
||||
};
|
||||
} )
|
||||
(style.style "body" {
|
||||
foo = "bar";
|
||||
})
|
||||
(style.styled "list" "ul" {
|
||||
__child = child:
|
||||
assert builtins.isList child; (map (html.tag "li" {}) child);
|
||||
} {});
|
||||
});
|
||||
in [
|
||||
(it "makes a p component" {
|
||||
expected = html.tag "p" {class = ["p"];} "yes";
|
||||
actual = my.p {} "yes";
|
||||
asString = true;
|
||||
})
|
||||
(it "does not error without attrs" {
|
||||
expected = html.tag "p" {class = ["p"];} "yes";
|
||||
actual = my.p "yes";
|
||||
asString = true;
|
||||
})
|
||||
(it "makes a component" {
|
||||
expected = html.tag "div" {class = ["something"];} "foobar";
|
||||
actual = my.div {} "foobar";
|
||||
asString = true;
|
||||
})
|
||||
(it "makes special components" {
|
||||
expected = html.tag "div" {
|
||||
|
@ -45,20 +51,23 @@ in [
|
|||
class = ["something"];
|
||||
} "foobar";
|
||||
actual = my.s {} "foobar";
|
||||
asString = true;
|
||||
})
|
||||
(it "works on many classes" {
|
||||
expected = html.tag "div" {class = ["foo" "bar"];} "foobar";
|
||||
actual = my.foobar {} "foobar";
|
||||
asString = true;
|
||||
})
|
||||
(it "does custom behavour" {
|
||||
expected = toString (html.tag "ul" {
|
||||
expected = (html.tag "ul" {
|
||||
__ = "";
|
||||
class = ["list"];
|
||||
} [
|
||||
(html.tag "li" {} "1")
|
||||
(html.tag "li" {} "2")
|
||||
]);
|
||||
actual = toString (my.list {} ["1" "2"]);
|
||||
actual = (my.list {} ["1" "2"]);
|
||||
asString = true;
|
||||
})
|
||||
(it "combines attrs" {
|
||||
expected = html.tag "div" {
|
||||
|
@ -66,6 +75,7 @@ in [
|
|||
class = ["something"];
|
||||
} "foobar";
|
||||
actual = my.div {id = "foo";} "foobar";
|
||||
asString = true;
|
||||
})
|
||||
(it "makes a style" {
|
||||
expected = ''
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue