Skip to content

Commit d1469d6

Browse files
committed
feat: add t, b, l, r, and inset arbitrary css support
1 parent cd8f1a2 commit d1469d6

File tree

2 files changed

+27
-14
lines changed

2 files changed

+27
-14
lines changed

crates/tailwind-parse/src/eval/plugin.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,19 @@ macro_rules! merge_plugins {
102102
};
103103
}
104104

105+
macro_rules! merge_plugins_arbitrary {
106+
($def:ident, $closure_a:expr, $closure_b:expr) => {
107+
pub fn $def(rest: &SubjectValue, theme: &TailwindTheme) -> Option<ObjectLit> {
108+
match ($closure_a(rest, theme), $closure_b(rest, theme)) {
109+
(None, None) => None,
110+
(None, Some(a)) => Some(a),
111+
(Some(b), None) => Some(b),
112+
(Some(a), Some(b)) => Some(merge_literals(a, b)),
113+
}
114+
}
115+
};
116+
}
117+
105118
macro_rules! merge_plugins_opt {
106119
($def:ident, $closure_a:expr, $closure_b:expr) => {
107120
pub fn $def(rest: Option<&Value>, theme: &TailwindTheme) -> Option<ObjectLit> {
@@ -150,14 +163,14 @@ lookup_plugin_opt!(invert, invert, "filter", |s| format!("invert({s})"));
150163
lookup_plugin!(basis, flex_basis, "flexBasis");
151164
lookup_plugin_opt!(grow, flex_grow, "flexGrow");
152165
lookup_plugin_opt!(shrink, flex_shrink, "flexShrink");
153-
lookup_plugin!(top, height, "top");
166+
lookup_plugin_arbitrary!(top, height, "top");
154167
lookup_plugin!(opacity, opacity, "opacity");
155168
lookup_plugin!(animation, animation, "animation");
156169
lookup_plugin!(order, order, "order");
157-
lookup_plugin!(bottom, height, "bottom");
170+
lookup_plugin_arbitrary!(bottom, height, "bottom");
158171
lookup_plugin!(fill, colors, "fill");
159-
lookup_plugin!(left, width, "left");
160-
lookup_plugin!(right, width, "right");
172+
lookup_plugin_arbitrary!(left, width, "left");
173+
lookup_plugin_arbitrary!(right, width, "right");
161174
lookup_plugin_arbitrary!(tracking, letter_spacing, "letterSpacing");
162175
lookup_plugin_arbitrary!(h, height, "height");
163176
lookup_plugin!(to, colors, "--tw-gradient-to");
@@ -501,9 +514,9 @@ merge_plugins_arbitrary_opt!(border_y, border_t, border_b);
501514
merge_plugins_arbitrary_opt!(border_cw, border_color, border_width);
502515
merge_plugins_arbitrary_opt!(border_inner, border_cw, border_style);
503516

504-
merge_plugins!(inset_x, left, right);
505-
merge_plugins!(inset_y, top, bottom);
506-
merge_plugins!(inset, inset_x, inset_y);
517+
merge_plugins_arbitrary!(inset_x, left, right);
518+
merge_plugins_arbitrary!(inset_y, top, bottom);
519+
merge_plugins_arbitrary!(inset, inset_x, inset_y);
507520

508521
pub fn from(Value(rest): &Value, theme: &TailwindTheme) -> Option<ObjectLit> {
509522
theme.colors.get(rest).map(|c| {

crates/tailwind-parse/src/literal.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,10 @@ impl<'a> Literal<'a> {
160160
Box => Required(plugin::box_),
161161
Select => Required(plugin::select),
162162
Overflow => Required(plugin::overflow),
163-
Top => Required(plugin::top),
164-
Bottom => Required(plugin::bottom),
165-
Left => Required(plugin::left),
166-
Right => Required(plugin::right),
163+
Top => RequiredArbitrary(plugin::top),
164+
Bottom => RequiredArbitrary(plugin::bottom),
165+
Left => RequiredArbitrary(plugin::left),
166+
Right => RequiredArbitrary(plugin::right),
167167
Translate => Required(plugin::translate),
168168
Tracking => RequiredArbitrary(plugin::tracking),
169169
Invert => Optional(plugin::invert),
@@ -198,9 +198,9 @@ impl<'a> Literal<'a> {
198198
Max(Max::H) => RequiredArbitrary(plugin::max_h),
199199
Max(Max::W) => RequiredArbitrary(plugin::max_w),
200200
Fill => Required(plugin::fill),
201-
Inset(None) => Required(plugin::inset),
202-
Inset(Some(Inset::X)) => Required(plugin::inset_x),
203-
Inset(Some(Inset::Y)) => Required(plugin::inset_y),
201+
Inset(None) => RequiredArbitrary(plugin::inset),
202+
Inset(Some(Inset::X)) => RequiredArbitrary(plugin::inset_x),
203+
Inset(Some(Inset::Y)) => RequiredArbitrary(plugin::inset_y),
204204
Leading => Required(plugin::leading),
205205
Truncate => Optional(plugin::truncate),
206206
Animate => Required(plugin::animation),

0 commit comments

Comments
 (0)