Skip to content

Commit d7cb3c1

Browse files
authored
Merge pull request #149 from lee-m/box-sizing
Add in support for "box-sizing" property
2 parents c6cdc57 + fc9e2a9 commit d7cb3c1

4 files changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Xunit;
2+
3+
namespace ExCSS.Tests.PropertyTests
4+
{
5+
public class BoxSizingPropertyTests : CssConstructionFunctions
6+
{
7+
[Fact]
8+
public void BoxSizingContentBoxLegal()
9+
{
10+
var snippet = "box-sizing: content-box";
11+
var property = ParseDeclaration(snippet);
12+
Assert.Equal("box-sizing", property.Name);
13+
Assert.False(property.IsImportant);
14+
Assert.IsType<BoxSizingProperty>(property);
15+
var concrete = (BoxSizingProperty)property;
16+
Assert.False(concrete.IsInherited);
17+
Assert.True(concrete.HasValue);
18+
Assert.Equal("content-box", concrete.Value);
19+
}
20+
21+
[Fact]
22+
public void BoxSizingBorderBoxLegal()
23+
{
24+
var snippet = "box-sizing: border-box";
25+
var property = ParseDeclaration(snippet);
26+
Assert.Equal("box-sizing", property.Name);
27+
Assert.False(property.IsImportant);
28+
Assert.IsType<BoxSizingProperty>(property);
29+
var concrete = (BoxSizingProperty)property;
30+
Assert.False(concrete.IsInherited);
31+
Assert.True(concrete.HasValue);
32+
Assert.Equal("border-box", concrete.Value);
33+
}
34+
}
35+
}

src/ExCSS/Factories/PropertyFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ private PropertyFactory()
6161

6262
AddLonghand(PropertyNames.BorderSpacing, () => new BorderSpacingProperty());
6363
AddLonghand(PropertyNames.BorderCollapse, () => new BorderCollapseProperty());
64+
AddLonghand(PropertyNames.BoxSizing, () => new BoxSizingProperty());
6465
AddLonghand(PropertyNames.BoxShadow, () => new BoxShadowProperty(), true);
6566
AddLonghand(PropertyNames.BoxDecorationBreak, () => new BoxDecorationBreak());
6667
AddLonghand(PropertyNames.BreakAfter, () => new BreakAfterProperty());

src/ExCSS/Model/Converters.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,7 @@ public static readonly IValueConverter
442442
public static readonly IValueConverter BoxDecorationConverter = Toggle(Keywords.Clone, Keywords.Slice);
443443
public static readonly IValueConverter ColumnSpanConverter = Toggle(Keywords.All, Keywords.None);
444444
public static readonly IValueConverter ColumnFillConverter = Toggle(Keywords.Balance, Keywords.Auto);
445+
public static readonly IValueConverter BoxSizingConverter = Toggle(Keywords.ContentBox, Keywords.BorderBox);
445446

446447
#endregion
447448

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
namespace ExCSS
2+
{
3+
internal class BoxSizingProperty : Property
4+
{
5+
private static readonly IValueConverter StyleConverter = Converters.BoxSizingConverter.OrDefault(Keywords.ContentBox);
6+
7+
public BoxSizingProperty()
8+
: base(PropertyNames.BoxSizing, PropertyFlags.None)
9+
{ }
10+
11+
internal override IValueConverter Converter => StyleConverter;
12+
}
13+
}

0 commit comments

Comments
 (0)