Skip to content

Commit

Permalink
#10
Browse files Browse the repository at this point in the history
  • Loading branch information
chanan committed Jul 17, 2019
1 parent 1e7b6a4 commit f056b1f
Show file tree
Hide file tree
Showing 17 changed files with 131 additions and 15 deletions.
Binary file modified docs/_framework/_bin/BlazorStyled.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/BlazorStyled.pdb
Binary file not shown.
Binary file modified docs/_framework/_bin/Mono.Security.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/Sample.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/Sample.pdb
Binary file not shown.
Binary file modified docs/_framework/_bin/System.Core.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/System.Data.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/System.Net.Http.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/System.Numerics.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/System.Runtime.Serialization.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/System.Xml.Linq.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/System.Xml.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/System.dll
Binary file not shown.
Binary file modified docs/_framework/_bin/mscorlib.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion src/BlazorStyled/BlazorStyled.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<RazorLangVersion>3.0</RazorLangVersion>
<AddRazorSupportForMvc>true</AddRazorSupportForMvc>
<PackageId>BlazorStyled</PackageId>
<Version>1.0.0-preview6-06</Version>
<Version>1.0.0-preview6-07</Version>
<Authors>Chanan Braunstein</Authors>
<Title>BlazorStyled</Title>
<Description>CSS in Blazor Components</Description>
Expand Down
129 changes: 128 additions & 1 deletion src/BlazorStyled/Internal/Styled.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ public async Task<string> Css(string className, string css)
else
{
rule = ParsePredefinedRuleSet(className, css);
await AddUniqueRuleSetToStyleSheet(rule);
if(_elements.Contains(className))
{
await AddNonUniqueRuleSetToStyleSheet(rule);
}
else
{
await AddUniqueRuleSetToStyleSheet(rule);
}
}
return rule.Selector;
}
Expand Down Expand Up @@ -286,5 +293,125 @@ private async Task AddUniqueRuleSetToStyleSheet(IRule rule)
await _styledJsInterop.InsertRule(rule.ToString());
}
}

private async Task AddNonUniqueRuleSetToStyleSheet(IRule rule)
{
_styleSheet.Classes.Add(rule);
await _styledJsInterop.InsertRule(rule.ToString());
}

private List<string> _elements = new List<string>
{
"a",
"abbr",
"address",
"area",
"article",
"aside",
"audio",
"b",
"base",
"bdi",
"bdo",
"blockquote",
"body",
"br",
"button",
"canvas",
"caption",
"cite",
"code",
"col",
"colgroup",
"data",
"datalist",
"dd",
"del",
"details",
"dfn",
"dialog",
"div",
"dl",
"dt",
"em",
"embed",
"fieldset",
"figcaption",
"figure",
"footer",
"form",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"head",
"header",
"hr",
"html",
"i",
"iframe",
"img",
"input",
"ins",
"kbd",
"label",
"legend",
"li",
"link",
"main",
"map",
"mark",
"meta",
"meter",
"nav",
"noscript",
"object",
"ol",
"optgroup",
"option",
"output",
"p",
"param",
"picture",
"pre",
"progress",
"q",
"rp",
"rt",
"ruby",
"s",
"samp",
"script",
"section",
"select",
"small",
"source",
"span",
"strong",
"style",
"sub",
"summary",
"sup",
"svg",
"table",
"tbody",
"td",
"template",
"textarea",
"tfoot",
"th",
"thead",
"time",
"title",
"tr",
"track",
"u",
"ul",
"var",
"video",
"wbr"
};
}
}
15 changes: 2 additions & 13 deletions src/Sample/Pages/Test.razor
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,7 @@
@code {
protected override async Task OnInitAsync()
{
await Styled.Css(new List<string>
{
"h1",
"h2"
}, @"
margin-left: 0;
margin-right: 0;
margin-top: 0;
padding-bottom: 0;
padding-left: 0;
padding-right: 0;
padding-top: 0;"
);
await Styled.Css("html", "color: red;");
await Styled.Css("html", "background-color: yellow;");
}
}

0 comments on commit f056b1f

Please sign in to comment.