add __self to styled
This commit is contained in:
parent
a7c1a1c7de
commit
ccc6b53b91
|
@ -27,16 +27,21 @@ in
|
||||||
lang = "en";
|
lang = "en";
|
||||||
class = [];
|
class = [];
|
||||||
})
|
})
|
||||||
|
(s.styled "link" "a" {
|
||||||
|
__self = self: attrs: child:
|
||||||
|
if builtins.isString attrs then
|
||||||
|
self {href = attrs;} child else
|
||||||
|
self attrs child;
|
||||||
|
})
|
||||||
|
(s.styled "stylesheet" "link" {
|
||||||
|
rel = "stylesheet";
|
||||||
|
class = [];
|
||||||
|
__self = self: attrs:
|
||||||
|
if builtins.isString attrs then
|
||||||
|
self {href = attrs;} "" else
|
||||||
|
self attrs "";
|
||||||
|
})
|
||||||
// {
|
// {
|
||||||
h = v: child:
|
h = v: child:
|
||||||
html.tag "h${toString v}" {} child;
|
html.tag "h${toString v}" {} child;
|
||||||
|
|
||||||
link = href: child:
|
|
||||||
html.tag "a" {inherit href;} child;
|
|
||||||
|
|
||||||
stylesheet = path:
|
|
||||||
html.tag "link" {
|
|
||||||
rel = "stylesheet";
|
|
||||||
href = path;
|
|
||||||
} "";
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,15 +37,22 @@ let
|
||||||
+ id;
|
+ id;
|
||||||
in {
|
in {
|
||||||
styled = name: tag: cprops: let
|
styled = name: tag: cprops: let
|
||||||
custom = cprops.__child or (child: child);
|
__child = cprops.__child or (child: child);
|
||||||
|
|
||||||
|
self = props:
|
||||||
|
html.tag tag (props // {class = [name];} // cprops // {style = "";});
|
||||||
|
|
||||||
|
__self = (cprops.__self or (self: props:
|
||||||
|
if builtins.isAttrs props
|
||||||
|
then (child: ( self props (__child child) ))
|
||||||
|
else if builtins.isString props || builtins.isList props
|
||||||
|
then (self {} (__child props))
|
||||||
|
else throw "Call element with attributes and child."
|
||||||
|
)) self;
|
||||||
|
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
${name} = props:
|
${name} = __self;
|
||||||
if builtins.isAttrs props
|
|
||||||
then (child: (html.tag tag (props // {class = [name];} // cprops // {style = "";}) (custom child)))
|
|
||||||
else if builtins.isString props || builtins.isList props
|
|
||||||
then (html.tag tag ({class = [name];} // cprops // {style = "";}) (custom props))
|
|
||||||
else throw "Call element with attributes and child.";
|
|
||||||
|
|
||||||
style = mkStyle (mkIdentifier name tag cprops) ( cprops.style or {} );
|
style = mkStyle (mkIdentifier name tag cprops) ( cprops.style or {} );
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ in
|
||||||
asString = true;
|
asString = true;
|
||||||
})
|
})
|
||||||
(it "makes an a tag" {
|
(it "makes an a tag" {
|
||||||
expected = html.tag "a" {href = "https://example.com";} "example";
|
expected = html.tag "a" {class = ["link"]; href = "https://example.com";} "example";
|
||||||
actual = link "https://example.com" "example";
|
actual = link "https://example.com" "example";
|
||||||
asString = true;
|
asString = true;
|
||||||
})
|
})
|
||||||
|
@ -54,7 +54,7 @@ in
|
||||||
href = "/style";
|
href = "/style";
|
||||||
rel = "stylesheet";
|
rel = "stylesheet";
|
||||||
} "";
|
} "";
|
||||||
actual = stylesheet "/style";
|
actual = stylesheet {href = "/style"; };
|
||||||
asString = true;
|
asString = true;
|
||||||
})
|
})
|
||||||
(it "makes a list" {
|
(it "makes a list" {
|
||||||
|
|
Loading…
Reference in a new issue