cabin_tailwind/utilities/
outline.rs

1//! Control the style of an element's outline (`outline-style`).
2//!
3//! <https://developer.mozilla.org/en-US/docs/Web/CSS/outline-style>
4
5use std::fmt;
6
7use crate::{Length, Property, Utility};
8
9const OUTLINE_STYLE: &str = "outline-style";
10const OUTLINE_WIDTH: &str = "outline-width";
11const OUTLINE_OFFSET: &str = "outline-offset";
12const OUTLINE_COLOR: &str = "outline-color";
13
14include!(concat!(env!("OUT_DIR"), "/outline-color.rs"));
15
16/// Hide the default browser outline on focused elements.
17/// ```css
18/// outline: 2px solid transparent;
19/// outline-offset: 2px;
20/// ```
21pub const NONE: OutlineNone = OutlineNone;
22
23/// ```css
24/// outline-style: solid;
25/// ```
26pub const SOLID: Property = Property(OUTLINE_STYLE, "solid");
27
28/// ```css
29/// outline-style: dashed;
30/// ```
31pub const DASHED: Property = Property(OUTLINE_STYLE, "dashed");
32
33/// ```css
34/// outline-style: dotted;
35/// ```
36pub const DOTTED: Property = Property(OUTLINE_STYLE, "dotted");
37
38/// ```css
39/// outline-style: double;
40/// ```
41pub const DOUBLE: Property = Property(OUTLINE_STYLE, "double");
42
43/// ```css
44/// outline-offset: {x}px;
45/// ```
46pub fn offset(x: i16) -> Property<Length> {
47    Property(OUTLINE_OFFSET, Length::Px(f32::from(x)))
48}
49
50/// ```css
51/// outline-offset: {x}px;
52/// ```
53pub fn offsetf(x: f32) -> Property<Length> {
54    Property(OUTLINE_OFFSET, Length::Px(x))
55}
56
57/// ```css
58/// outline-width: {x}px;
59/// ```
60pub fn width(x: i16) -> Property<Length> {
61    Property(OUTLINE_WIDTH, Length::Px(f32::from(x)))
62}
63
64/// ```css
65/// outline-width: {x}px;
66/// ```
67pub fn widthf(x: f32) -> Property<Length> {
68    Property(OUTLINE_WIDTH, Length::Px(x))
69}
70
71pub struct OutlineNone;
72
73impl Utility for OutlineNone {
74    fn declarations(&self, f: &mut dyn fmt::Write) -> fmt::Result {
75        writeln!(f, "outline: 2px solid transparent;")?;
76        writeln!(f, "outline-offset: 2px;")?;
77        Ok(())
78    }
79}