Skip to content

Commit

Permalink
feat: add the object plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
arlyon committed Nov 3, 2022
1 parent 6ea516d commit e420c5d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
10 changes: 10 additions & 0 deletions crates/tailwind-parse/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ mod plugin {
Grow,
Shrink,
Basis,
Object(Object),
Justify,
Items,
Leading,
Expand Down Expand Up @@ -106,6 +107,15 @@ mod plugin {
Y,
}

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum Object {
Contain,
Cover,
Fill,
None,
ScaleDown,
}

#[derive(Copy, Clone, Eq, PartialEq, Debug)]
pub enum Inset {
X,
Expand Down
1 change: 1 addition & 0 deletions src/parse/literal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub fn parse_literal<'a>(theme: &TailwindTheme, lit: Literal<'a>) -> Result<Obje
TextDecoration(td) => return plugin::text_decoration(td, lit.value, theme).ok_or(lit.full),
Flex(f) => return plugin::flex(f, lit.value, theme).ok_or(lit.full),
Grid(g) => return plugin::grid(g, lit.value, theme).ok_or(lit.full),
Object(o) => return plugin::object(o, lit.value, theme).ok_or(lit.full),

// all other plugins
Text => Required(plugin::text),
Expand Down
14 changes: 13 additions & 1 deletion src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ use swc_core::{
ecma::ast::{Expr, Ident, KeyValueProp, Lit, ObjectLit, Prop, PropName, PropOrSpread, Str},
};
use tailwind_parse::{
Border, Display, Flex, Grid, Position, Rounded, TextDecoration, TextTransform, Visibility,
Border, Display, Flex, Grid, Object, Position, Rounded, TextDecoration, TextTransform,
Visibility,
};

macro_rules! lookup_plugin {
Expand Down Expand Up @@ -513,6 +514,17 @@ pub fn grid(
Some(to_lit(&pair))
}

pub fn object(o: Object, _rest: Option<SubjectValue>, _theme: &TailwindTheme) -> Option<ObjectLit> {
let rule = match o {
Object::Contain => [("objectFit", "contain")],
Object::Cover => [("objectFit", "cover")],
Object::Fill => [("objectFit", "fill")],
Object::None => [("objectFit", "none")],
Object::ScaleDown => [("objectFit", "scale-down")],
};
Some(to_lit(&rule))
}

pub fn col(rest: &str, theme: &TailwindTheme) -> Option<ObjectLit> {
simple_lookup(&theme.grid_column, rest, "gridColumn").or_else(|| match rest.split_once('-') {
Some(("start", rest)) => simple_lookup(&theme.grid_column_start, rest, "gridColumnStart"),
Expand Down

0 comments on commit e420c5d

Please sign in to comment.