From 6cf22217ba262ff55f2d8fa797b53b1866fbc87c Mon Sep 17 00:00:00 2001 From: Stuart George Date: Wed, 22 May 2024 10:50:59 +0100 Subject: [PATCH] added column and row gap --- CHANGELOG.md | 7 +++++++ style.go | 2 ++ style_test.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dda0a9..2b4e383 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ All notable changes to this project will be documented in this file. +### v0.0.6 + +Added new props: + +- column-gap +- row-gap + ### v0.0.5 Added explicit CustomProp type and make CustomProps a slice to preserve ordering. diff --git a/style.go b/style.go index 055b272..7a089b4 100644 --- a/style.go +++ b/style.go @@ -33,6 +33,7 @@ type ( Bottom props.Unit `css:"bottom"` CaptionSide props.CaptionSide `css:"caption-side"` Color props.Color `css:"color"` + ColumnGap props.Unit `css:"column-gap"` Cursor props.Cursor `css:"cursor"` Display props.Display `css:"display"` FlexBasis props.Unit `css:"flex-basis"` @@ -69,6 +70,7 @@ type ( Position props.Position `css:"position"` PrintColorAdjust props.PrintColorAdjust `css:"print-color-adjust"` Right props.Unit `css:"right"` + RowGap props.Unit `css:"row-gap"` TextAlign props.TextAlign `css:"text-align"` TextOverflow props.TextOverflow `css:"text-overflow"` Top props.Unit `css:"top"` diff --git a/style_test.go b/style_test.go index 79e8ab4..4898786 100644 --- a/style_test.go +++ b/style_test.go @@ -717,6 +717,29 @@ func TestStyle_Color(t *testing.T) { } } +func TestStyle_ColumnGap(t *testing.T) { + testCases := map[props.Unit]string{ + props.UnitPx(10): "10px", + props.UnitPercent(50): "50.00%", + props.UnitRem(10): "10.000rem", + } + + for prop, expected := range testCases { + t.Run(expected, func(t *testing.T) { + st := &Style{Selector: ".test", Props: Props{ColumnGap: prop}} + var buf bytes.Buffer + err := st.CSS(&buf) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + css := fmt.Sprintf(".test{column-gap:%s;}", expected) + if buf.String() != css { + t.Errorf("expected %q, got %q", css, buf.String()) + } + }) + } +} + func TestStyle_Cursor(t *testing.T) { testCases := map[props.Cursor]string{ props.CursorAuto: "auto", @@ -1607,6 +1630,29 @@ func TestStyle_Right(t *testing.T) { } } +func TestStyle_RowGap(t *testing.T) { + testCases := map[props.Unit]string{ + props.UnitPx(10): "10px", + props.UnitPercent(50): "50.00%", + props.UnitRem(10): "10.000rem", + } + + for prop, expected := range testCases { + t.Run(expected, func(t *testing.T) { + st := &Style{Selector: ".test", Props: Props{RowGap: prop}} + var buf bytes.Buffer + err := st.CSS(&buf) + if err != nil { + t.Errorf("unexpected error: %v", err) + } + css := fmt.Sprintf(".test{row-gap:%s;}", expected) + if buf.String() != css { + t.Errorf("expected %q, got %q", css, buf.String()) + } + }) + } +} + func TestStyle_TextAlign(t *testing.T) { testCases := map[props.TextAlign]string{ props.TextAlignLeft: "left",