Skip to content

Commit

Permalink
add visibility, opacity, z-index
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartaccent committed May 25, 2024
1 parent 48d5bb0 commit c389468
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ Added new props:
- list-style-position
- list-style-type
- vertical-align
- z-index
- visibility
- opacity

### v0.0.5

Expand Down
13 changes: 13 additions & 0 deletions props/visibility.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package props

type Visibility string

const (
VisibilityVisible Visibility = "visible"
VisibilityHidden Visibility = "hidden"
VisibilityCollapse Visibility = "collapse"
)

func (v Visibility) String() string {
return string(v)
}
3 changes: 3 additions & 0 deletions style.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type (
MarginTop props.Unit `css:"margin-top"`
MaxWidth props.Unit `css:"max-width"`
MinWidth props.Unit `css:"min-width"`
Opacity props.Unit `css:"opacity"`
Overflow props.Overflow `css:"overflow"`
OverflowX props.Overflow `css:"overflow-x"`
OverflowY props.Overflow `css:"overflow-y"`
Expand All @@ -80,6 +81,8 @@ type (
VerticalAlign props.VerticalAlign `css:"vertical-align"`
WhiteSpace props.WhiteSpace `css:"white-space"`
Width props.Unit `css:"width"`
Visibility props.Visibility `css:"visibility"`
ZIndex props.Unit `css:"z-index"`
}
// CustomProp represents an additional CSS property that is not covered by the Props struct.
CustomProp struct {
Expand Down
44 changes: 44 additions & 0 deletions style_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -955,6 +955,21 @@ func TestStyle_MinWidth(t *testing.T) {
}
}

func TestStyle_Opacity(t *testing.T) {
testCases := map[props.Unit]string{
props.UnitRaw(0): "0",
props.UnitRaw(0.33): "0.33",
props.UnitPercent(90): "90.00%",
props.UnitRaw("initial"): "initial",
}

for prop, expected := range testCases {
st := &Style{Selector: ".test", Props: Props{Opacity: prop}}
css := fmt.Sprintf(".test{opacity:%s;}", expected)
runTest(t, st, css)
}
}

func TestStyle_Overflow(t *testing.T) {
testCases := map[props.Overflow]string{
props.OverflowVisible: "visible",
Expand Down Expand Up @@ -1238,3 +1253,32 @@ func TestStyle_Width(t *testing.T) {
runTest(t, st, css)
}
}

func TestStyle_Visibility(t *testing.T) {
testCases := map[props.Visibility]string{
props.VisibilityVisible: "visible",
props.VisibilityHidden: "hidden",
props.VisibilityCollapse: "collapse",
props.Visibility("initial"): "initial",
}

for prop, expected := range testCases {
st := &Style{Selector: ".test", Props: Props{Visibility: prop}}
css := fmt.Sprintf(".test{visibility:%s;}", expected)
runTest(t, st, css)
}
}

func TestStyle_ZIndex(t *testing.T) {
testCases := map[props.Unit]string{
props.UnitRaw(1): "1",
props.UnitRaw(10): "10",
props.UnitAuto(): "auto",
}

for prop, expected := range testCases {
st := &Style{Selector: ".test", Props: Props{ZIndex: prop}}
css := fmt.Sprintf(".test{z-index:%s;}", expected)
runTest(t, st, css)
}
}

0 comments on commit c389468

Please sign in to comment.