Skip to content

Commit

Permalink
Unit extension, elements selector
Browse files Browse the repository at this point in the history
  • Loading branch information
tib committed Jul 24, 2021
1 parent 6e7c5cb commit 581082d
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 12 deletions.
4 changes: 4 additions & 0 deletions Sources/SwiftCss/Components/Selector+Types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public func Element(_ name: HTMLElement, @PropertyBuilder _ builder: () -> [Prop
Selector(name.rawValue, builder)
}

public func Elements(_ names: [HTMLElement], @PropertyBuilder _ builder: () -> [Property]) -> Selector {
Selector(names.map(\.rawValue).joined(separator: ","), builder)
}

public func Id(_ name: String, @PropertyBuilder _ builder: () -> [Property]) -> Selector {
Selector("#" + name, builder)
}
Expand Down
48 changes: 36 additions & 12 deletions Sources/SwiftCss/Components/Unit.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,15 +78,39 @@ public enum Unit {
}
}

//
//extension Int {
// var px: Unit {
// Unit.px(Double(self))
// }
//}
//
//extension Double {
// var px: Unit {
// Unit.px(self)
// }
//}

public extension Int {
var cm: Unit { Unit.cm(Double(self)) }
var mm: Unit { Unit.mm(Double(self)) }
var `in`: Unit { Unit.in(Double(self)) }
var px: Unit { Unit.px(Double(self)) }
var pt: Unit { Unit.pt(Double(self)) }
var pc: Unit { Unit.pc(Double(self)) }
var em: Unit { Unit.em(Double(self)) }
var ex: Unit { Unit.ex(Double(self)) }
var ch: Unit { Unit.ch(Double(self)) }
var rem: Unit { Unit.rem(Double(self)) }
var vw: Unit { Unit.vw(Double(self)) }
var vh: Unit { Unit.vh(Double(self)) }
var vmin: Unit { Unit.vmin(Double(self)) }
var vmax: Unit { Unit.vmax(Double(self)) }
var percent: Unit { Unit.percent(Double(self)) }
}

public extension Double {
var cm: Unit { Unit.cm(self) }
var mm: Unit { Unit.mm(self) }
var `in`: Unit { Unit.in(self) }
var px: Unit { Unit.px(self) }
var pt: Unit { Unit.pt(self) }
var pc: Unit { Unit.pc(self) }
var em: Unit { Unit.em(self) }
var ex: Unit { Unit.ex(self) }
var ch: Unit { Unit.ch(self) }
var rem: Unit { Unit.rem(self) }
var vw: Unit { Unit.vw(self) }
var vh: Unit { Unit.vh(self) }
var vmin: Unit { Unit.vmin(self) }
var vmax: Unit { Unit.vmax(self) }
var percent: Unit { Unit.percent(self) }
}

0 comments on commit 581082d

Please sign in to comment.