use crate::css::Css;
use crate::data_type::LengthPercentage;
use crate::data_type_ext::Integer;
use crate::keyword::PositionKind;
impl Css {
pub fn position(self, v: PositionKind) -> Self {
self.push("position", v)
}
pub fn top(self, v: impl Into<LengthPercentage>) -> Self {
self.push("top", v.into())
}
pub fn right(self, v: impl Into<LengthPercentage>) -> Self {
self.push("right", v.into())
}
pub fn bottom(self, v: impl Into<LengthPercentage>) -> Self {
self.push("bottom", v.into())
}
pub fn left(self, v: impl Into<LengthPercentage>) -> Self {
self.push("left", v.into())
}
pub fn inset_inline_start(self, v: impl Into<LengthPercentage>) -> Self {
self.push("inset-inline-start", v.into())
}
pub fn inset_inline_end(self, v: impl Into<LengthPercentage>) -> Self {
self.push("inset-inline-end", v.into())
}
pub fn z_index(self, v: i32) -> Self {
self.push("z-index", Integer(v))
}
}
#[cfg(test)]
mod tests {
use crate::ext::*;
use crate::keyword::PositionKind;
use crate::Css;
#[test]
fn position_absolute_with_offsets() {
let s = Css::new()
.position(PositionKind::Absolute)
.top(px(10))
.right(0.percent())
.bottom(px(10))
.left(0.percent());
assert_eq!(
s.to_string(),
"position: absolute; top: 10px; right: 0%; bottom: 10px; left: 0%;"
);
}
#[test]
fn z_index_negative_allowed() {
let s = Css::new().z_index(-1);
assert_eq!(s.to_string(), "z-index: -1;");
}
#[test]
fn inset_inline_logical_edges() {
let s = Css::new().inset_inline_start(px(4)).inset_inline_end(px(8));
assert_eq!(
s.to_string(),
"inset-inline-start: 4px; inset-inline-end: 8px;"
);
}
#[test]
fn all_position_keywords() {
let cases = [
(PositionKind::Relative, "relative"),
(PositionKind::Absolute, "absolute"),
(PositionKind::Fixed, "fixed"),
(PositionKind::Sticky, "sticky"),
];
for (k, expected) in cases {
let s = Css::new().position(k);
assert_eq!(s.to_string(), format!("position: {expected};"));
}
}
}