Skip to content

Commit 641937a

Browse files
committed
Full port is done
1 parent a9a894b commit 641937a

16 files changed

Lines changed: 1124 additions & 6 deletions

Polished.net.sln

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ VisualStudioVersion = 16.0.28917.182
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Polished.net", "src\Polished.net\Polished.net.csproj", "{837A1FFD-D7C5-4EF4-BCA4-91CCB228201B}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Polished.net.tests", "src\Polished.net.tests\Polished.net.tests.csproj", "{53BA05F1-DDC6-4C6D-BF43-125E2F2CAC01}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Polished.net.tests", "src\Polished.net.tests\Polished.net.tests.csproj", "{53BA05F1-DDC6-4C6D-BF43-125E2F2CAC01}"
9+
EndProject
10+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7D0A702B-44A7-4929-AE59-78EBC74F7686}"
11+
ProjectSection(SolutionItems) = preProject
12+
readme.md = readme.md
13+
EndProjectSection
914
EndProject
1015
Global
1116
GlobalSection(SolutionConfigurationPlatforms) = preSolution

readme.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Polished.net
2+
============
3+
4+
_A lightweight toolset for writing styles in C#_
5+
6+
Polished.net is a port of https://github.com/styled-components/polished (version 3.4.0) to C#.
7+
8+
Docs
9+
====
10+
11+
There are no docs yet for this version but the polished js docs maybe helpful: https://polished.js.org/

src/Polished.net.tests/Mixins/LinearGradient.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,22 @@ public void Fallback()
3131
string expected = "background-color:#FFF;background-image:linear-gradient(to top right, #00FFFF 0%, rgba(0, 0, 255, 0) 50%, #0000FF 95%);";
3232
Assert.AreEqual(expected, actual);
3333
}
34+
35+
[TestMethod]
36+
public void ThrowsIfColorStopsAreNull()
37+
{
38+
Assert.ThrowsException<PolishedException>(
39+
() => _mixins.LinearGradient(null, "#FFF")
40+
);
41+
42+
}
43+
44+
[TestMethod]
45+
public void ThrowsIfColorStopsAreLessThan2()
46+
{
47+
Assert.ThrowsException<PolishedException>(
48+
() => _mixins.LinearGradient(new List<string> { "#fff" }, "#fff")
49+
);
50+
}
3451
}
3552
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
3+
namespace Polished.Tests.Mixins
4+
{
5+
[TestClass]
6+
public class Normalize
7+
{
8+
private readonly IMixins _mixins = new Polished.Mixins();
9+
10+
[TestMethod]
11+
public void NormalizeCss()
12+
{
13+
string actual = _mixins.Normalize();
14+
string expected = @"html { line-height: 1.15; -webkit-text-size-adjust: 100%; } body { margin: 0; } main { display: block; } h1 { font-size: 2em; margin: 0.67em 0; } hr { box-sizing: content-box; height: 0; overflow: visible; } pre { font-family: monospace, monospace; font-size: 1em; } a { background-color: transparent; } abbr[title] { border-bottom: none; text-decoration: underline; text-decoration: underline dotted; } b, strong { font-weight: bolder; } code, kbd, samp { font-family: monospace, monospace; font-size: 1em; } small { font-size: 80%; } sub, sup { font-size: 75%; line-height: 0; position: relative; vertical-align: baseline; } sub { bottom: -0.25em; } sup { top: -0.5em; } img { border-style: none; } button, input, optgroup, select, textarea { font-family: inherit; font-size: 100%; line-height: 1.15; margin: 0; } button, input { overflow: visible; } button, select { text-transform: none; } button, [type=""button""], [type=""reset""], [type=""submit""] { -webkit-appearance: button; } button::-moz-focus-inner, [type=""button""]::-moz-focus-inner, [type=""reset""]::-moz-focus-inner, [type=""submit""]::-moz-focus-inner { border-style: none; padding: 0; } button:-moz-focusring, [type=""button""]:-moz-focusring, [type=""reset""]:-moz-focusring, [type=""submit""]:-moz-focusring { outline: 1px dotted ButtonText; } fieldset { padding: 0.35em 0.75em 0.625em; } legend { box-sizing: border-box; color: inherit; display: table; max-width: 100%; padding: 0; white-space: normal; } progress { vertical-align: baseline; } textarea { overflow: auto; } [type=""checkbox""], [type=""radio""] { box-sizing: border-box; padding: 0; } [type=""number""]::-webkit-inner-spin-button, [type=""number""]::-webkit-outer-spin-button { height: auto; } [type=""search""] { -webkit-appearance: textfield; outline-offset: -2px; } [type=""search""]::-webkit-search-decoration { -webkit-appearance: none; } ::-webkit-file-upload-button { -webkit-appearance: button; font: inherit; } details { display: block; } summary { display: list-item; } template { display: none; } [hidden] { display: none; } ";
15+
Assert.AreEqual(expected, actual);
16+
}
17+
}
18+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
using System.Collections.Generic;
3+
4+
namespace Polished.Tests.Mixins
5+
{
6+
[TestClass]
7+
public class RadialGradient
8+
{
9+
private readonly IMixins _mixins = new Polished.Mixins();
10+
11+
[TestMethod]
12+
public void TwoColorStops()
13+
{
14+
string actual = _mixins.RadialGradient(new RadialGradientConfiguration { ColorStops = new List<string> { "#fff", "#000" } });
15+
string expected = "background-color:#fff;background-image:radial-gradient(#fff, #000);";
16+
Assert.AreEqual(expected, actual);
17+
}
18+
19+
[TestMethod]
20+
public void ExtentShapeAndPosition()
21+
{
22+
string actual = _mixins.RadialGradient(new RadialGradientConfiguration
23+
{
24+
ColorStops = new List<string> { "#00FFFF 0%", "rgba(0, 0, 255, 0) 50%", "#0000FF 95%" },
25+
Extent = "farthest-corner at 45px 45px",
26+
Position = "center",
27+
Shape = "ellipse"
28+
});
29+
string expected = "background-color:#00FFFF;background-image:radial-gradient(center ellipse farthest-corner at 45px 45px, #00FFFF 0%, rgba(0, 0, 255, 0) 50%, #0000FF 95%);";
30+
Assert.AreEqual(expected, actual);
31+
}
32+
33+
[TestMethod]
34+
public void ExtentAndShape()
35+
{
36+
string actual = _mixins.RadialGradient(new RadialGradientConfiguration
37+
{
38+
ColorStops = new List<string> { "#00FFFF 0%", "rgba(0, 0, 255, 0) 50%", "#0000FF 95%" },
39+
Extent = "farthest-corner at 45px 45px",
40+
Shape = "ellipse"
41+
});
42+
string expected = "background-color:#00FFFF;background-image:radial-gradient(ellipse farthest-corner at 45px 45px, #00FFFF 0%, rgba(0, 0, 255, 0) 50%, #0000FF 95%);";
43+
Assert.AreEqual(expected, actual);
44+
}
45+
46+
[TestMethod]
47+
public void Extent()
48+
{
49+
string actual = _mixins.RadialGradient(new RadialGradientConfiguration
50+
{
51+
ColorStops = new List<string> { "#00FFFF 0%", "rgba(0, 0, 255, 0) 50%", "#0000FF 95%" },
52+
Extent = "farthest-corner at 45px 45px"
53+
});
54+
string expected = "background-color:#00FFFF;background-image:radial-gradient(farthest-corner at 45px 45px, #00FFFF 0%, rgba(0, 0, 255, 0) 50%, #0000FF 95%);";
55+
Assert.AreEqual(expected, actual);
56+
}
57+
58+
[TestMethod]
59+
public void ExtentAndFallback()
60+
{
61+
string actual = _mixins.RadialGradient(new RadialGradientConfiguration
62+
{
63+
ColorStops = new List<string> { "#00FFFF 0%", "rgba(0, 0, 255, 0) 50%", "#0000FF 95%" },
64+
Extent = "farthest-corner at 45px 45px",
65+
Fallback = "#FFF"
66+
});
67+
string expected = "background-color:#FFF;background-image:radial-gradient(farthest-corner at 45px 45px, #00FFFF 0%, rgba(0, 0, 255, 0) 50%, #0000FF 95%);";
68+
Assert.AreEqual(expected, actual);
69+
}
70+
71+
[TestMethod]
72+
public void ThrowsIfColorStopsAreNull()
73+
{
74+
Assert.ThrowsException<PolishedException>(
75+
() => _mixins.RadialGradient(null, null, null, null, null)
76+
);
77+
78+
}
79+
80+
[TestMethod]
81+
public void ThrowsIfColorStopsAreLessThan2()
82+
{
83+
Assert.ThrowsException<PolishedException>(
84+
() => _mixins.RadialGradient(new List<string> { "#fff" }, null, null, null, null)
85+
);
86+
}
87+
}
88+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using Microsoft.VisualStudio.TestTools.UnitTesting;
2+
3+
namespace Polished.Tests.Mixins
4+
{
5+
[TestClass]
6+
public class RetinaImage
7+
{
8+
private readonly IMixins _mixins = new Polished.Mixins();
9+
10+
[TestMethod]
11+
public void ShowThrowIfNoFilename()
12+
{
13+
Assert.ThrowsException<PolishedException>(
14+
() => _mixins.RetinaImage(null, null)
15+
);
16+
}
17+
18+
[TestMethod]
19+
public void Filename()
20+
{
21+
string actual = _mixins.RetinaImage("img", null);
22+
string expected = "background-image:url(img.png);@media only screen and (-webkit-min-device-pixel-ratio: 1.3),only screen and (min--moz-device-pixel-ratio: 1.3),only screen and (-o-min-device-pixel-ratio: 1.3/1),only screen and (min-resolution: 125dpi),only screen and (min-resolution: 1.3dppx){background-image:url(img_2x.png);}";
23+
Assert.AreEqual(expected, actual);
24+
}
25+
26+
[TestMethod]
27+
public void FilenameAndCover()
28+
{
29+
string actual = _mixins.RetinaImage("img", "cover");
30+
string expected = "background-image:url(img.png);@media only screen and (-webkit-min-device-pixel-ratio: 1.3),only screen and (min--moz-device-pixel-ratio: 1.3),only screen and (-o-min-device-pixel-ratio: 1.3/1),only screen and (min-resolution: 125dpi),only screen and (min-resolution: 1.3dppx){background-image:url(img_2x.png);background-size:cover;}";
31+
Assert.AreEqual(expected, actual);
32+
}
33+
34+
[TestMethod]
35+
public void FilenameAndExtension()
36+
{
37+
string actual = _mixins.RetinaImage("img", null, "jpg");
38+
string expected = "background-image:url(img.jpg);@media only screen and (-webkit-min-device-pixel-ratio: 1.3),only screen and (min--moz-device-pixel-ratio: 1.3),only screen and (-o-min-device-pixel-ratio: 1.3/1),only screen and (min-resolution: 125dpi),only screen and (min-resolution: 1.3dppx){background-image:url(img_2x.jpg);}";
39+
Assert.AreEqual(expected, actual);
40+
}
41+
42+
[TestMethod]
43+
public void FilenameAndRetinaFilename()
44+
{
45+
string actual = _mixins.RetinaImage("img", null, null, "retina_img");
46+
string expected = "background-image:url(img.png);@media only screen and (-webkit-min-device-pixel-ratio: 1.3),only screen and (min--moz-device-pixel-ratio: 1.3),only screen and (-o-min-device-pixel-ratio: 1.3/1),only screen and (min-resolution: 125dpi),only screen and (min-resolution: 1.3dppx){background-image:url(retina_img.png);}";
47+
Assert.AreEqual(expected, actual);
48+
}
49+
50+
[TestMethod]
51+
public void FilenameAndSuffix()
52+
{
53+
string actual = _mixins.RetinaImage("img", null, null, null, "_5x");
54+
string expected = "background-image:url(img.png);@media only screen and (-webkit-min-device-pixel-ratio: 1.3),only screen and (min--moz-device-pixel-ratio: 1.3),only screen and (-o-min-device-pixel-ratio: 1.3/1),only screen and (min-resolution: 125dpi),only screen and (min-resolution: 1.3dppx){background-image:url(img_5x.png);}";
55+
Assert.AreEqual(expected, actual);
56+
}
57+
}
58+
}

0 commit comments

Comments
 (0)