Skip to content

Commit

Permalink
feat: add grid plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed Aug 19, 2022
1 parent 6780341 commit 5e3470e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/config.rs
Expand Up @@ -51,6 +51,11 @@ pub struct TailwindTheme<'a> {
#[serde(borrow, rename = "zIndex")]
pub z_index: HashMap<&'a str, &'a str>,

#[serde(borrow, rename = "gridTemplateRows")]
pub grid_template_rows: HashMap<&'a str, &'a str>,
#[serde(borrow, rename = "gridTemplateColumns")]
pub grid_template_columns: HashMap<&'a str, &'a str>,

#[serde(borrow, rename = "transitionDelay")]
pub transition_delay: HashMap<&'a str, &'a str>,
#[serde(borrow, rename = "transitionDuration")]
Expand Down
1 change: 1 addition & 0 deletions src/parse/literal.rs
Expand Up @@ -22,6 +22,7 @@ pub fn parse_literal<'a>(theme: &TailwindTheme, s: &'a str) -> Result<ObjectLit,
"border" => plugin::border,
"rounded" => plugin::rounded,
"flex" => plugin::flex,
"grid" => plugin::grid,
"grow" => plugin::grow,
"shrink" => plugin::shrink,
"basis" => plugin::basis,
Expand Down
21 changes: 21 additions & 0 deletions src/plugin.rs
Expand Up @@ -101,6 +101,27 @@ pub fn flex(rest: &str, theme: &TailwindTheme) -> Option<ObjectLit> {
.or_else(|| simple_lookup(&theme.flex, rest, "flex"))
}

pub fn grid(rest: &str, theme: &TailwindTheme) -> Option<ObjectLit> {
let (cmd, rest) = rest.split_once('-')?;
match cmd {
"cols" => simple_lookup(&theme.grid_template_columns, rest, "gridTemplateColumns"),
"rows" => simple_lookup(&theme.grid_template_rows, rest, "gridTemplateRows"),
"flow" => {
let x = match rest {
"row" => "row",
"col" => "column",
"dense" => "dense",
"row-dense" => "row dense",
"col-dense" => "column dense",
_ => return None,
};

Some(to_lit(&[("gridAutoFlow", x)]))
}
_ => None,
}
}

pub fn basis(rest: &str, theme: &TailwindTheme) -> Option<ObjectLit> {
simple_lookup(&theme.flex_basis, rest, "flexBasis")
}
Expand Down

0 comments on commit 5e3470e

Please sign in to comment.