Skip to content

Commit 9f88dd2

Browse files
committed
fix: 修复box-shadow报错
1 parent c31592e commit 9f88dd2

File tree

2 files changed

+33
-40
lines changed

2 files changed

+33
-40
lines changed

__test__/fixure/pesudo.scss

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
.a {max-width: 100%;
2-
box-sizing: border-box;
3-
display: flex;
4-
margin-right: 5px;
5-
align-items: center;
6-
padding: 0 4px;
7-
background: rgba(255, 145, 27, 0.1);
8-
border-radius: 4px;
1+
.a {
2+
box-shadow: 0px 0px rgba(0, 0, 0, 0.04);
93
}

src/style_propetries/box_shadow.rs

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -52,42 +52,41 @@ impl BoxShadow {
5252

5353
impl ToExpr for BoxShadow {
5454
fn to_expr(&self) -> PropertyTuple {
55+
56+
let mut props = vec![];
57+
58+
if let Some(offset_x) = &self.offset_x {
59+
props.push(("offsetX".to_string(), generate_expr_by_length!(offset_x, Platform::Harmony)));
60+
}
61+
if let Some(offset_y) = &self.offset_y {
62+
props.push(("offsetY".to_string(), generate_expr_by_length!(offset_y, Platform::Harmony)));
63+
}
64+
if let Some(blur_radius) = &self.blur_radius {
65+
props.push(("radius".to_string(), generate_expr_by_length!(blur_radius, Platform::Harmony)));
66+
}
67+
if let Some(color) = &self.color {
68+
props.push(("color".to_string(), generate_string_by_css_color!(color)));
69+
}
70+
if let Some(inset) = &self.inset {
71+
props.push(("fill".to_string(), generate_expr_lit_bool!(*inset)));
72+
}
73+
74+
let object_list_props = props.into_iter().map(|(a, b)| {
75+
PropOrSpread::Prop(Box::new(Prop::KeyValue(
76+
KeyValueProp {
77+
key: generate_prop_name!(a),
78+
value: Box::new(b),
79+
}
80+
)))
81+
}).collect::<Vec<PropOrSpread>>();
82+
83+
84+
5585
PropertyTuple::One(
5686
"boxShadow".to_string(),
5787
Expr::Object(ObjectLit {
5888
span: DUMMY_SP,
59-
props: vec![
60-
PropOrSpread::Prop(Box::new(Prop::KeyValue(
61-
KeyValueProp {
62-
key: generate_prop_name!("radius"),
63-
value: Box::new(generate_expr_by_length!(self.offset_x.as_ref().unwrap(), Platform::Harmony)),
64-
}
65-
))),
66-
PropOrSpread::Prop(Box::new(Prop::KeyValue(
67-
KeyValueProp {
68-
key: generate_prop_name!("color"),
69-
value: Box::new(generate_string_by_css_color!(self.color.as_ref().unwrap())),
70-
}
71-
))),
72-
PropOrSpread::Prop(Box::new(Prop::KeyValue(
73-
KeyValueProp {
74-
key: generate_prop_name!("offsetX"),
75-
value: Box::new(generate_expr_by_length!(self.offset_x.as_ref().unwrap(), Platform::Harmony)),
76-
}
77-
))),
78-
PropOrSpread::Prop(Box::new(Prop::KeyValue(
79-
KeyValueProp {
80-
key: generate_prop_name!("offsetY"),
81-
value: Box::new(generate_expr_by_length!(self.offset_y.as_ref().unwrap(), Platform::Harmony)),
82-
}
83-
))),
84-
PropOrSpread::Prop(Box::new(Prop::KeyValue(
85-
KeyValueProp {
86-
key: generate_prop_name!("fill"),
87-
value: Box::new(generate_expr_lit_bool!(self.inset.unwrap())),
88-
}
89-
))),
90-
]
89+
props: object_list_props
9190
})
9291
)
9392
}

0 commit comments

Comments
 (0)