Skip to content

Commit

Permalink
set cover the default value of fit
Browse files Browse the repository at this point in the history
  • Loading branch information
harshdoesdev committed Sep 13, 2023
1 parent 8c54270 commit 0fdffc6
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 267 deletions.
3 changes: 1 addition & 2 deletions ftd/src/interpreter/things/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9562,8 +9562,7 @@ pub fn image_function() -> ftd::interpreter::ComponentDefinition {
ftd::interpreter::Argument::default(
"fit",
ftd::interpreter::Kind::or_type(ftd::interpreter::FTD_IMAGE_FIT)
.into_kind_data()
.into_optional(),
.into_kind_data(),
),
ftd::interpreter::Argument::default(
"alt",
Expand Down
32 changes: 11 additions & 21 deletions ftd/src/js/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -612,7 +612,7 @@ impl Code {
#[derive(Debug)]
pub struct Image {
pub src: ftd::js::Value,
pub fit: Option<ftd::js::Value>,
pub fit: ftd::js::Value,
pub alt: Option<ftd::js::Value>,
pub common: Common,
}
Expand All @@ -632,10 +632,11 @@ impl Image {
component_definition.arguments.as_slice(),
)
.unwrap(),
fit: ftd::js::value::get_optional_js_value(
fit: ftd::js::value::get_js_value_with_default(
"fit",
component.properties.as_slice(),
component_definition.arguments.as_slice(),
ftd::js::Value::from_str_value("cover"),
),
alt: ftd::js::value::get_optional_js_value(
"alt",
Expand Down Expand Up @@ -669,6 +670,14 @@ impl Image {
inherited: rdata.inherited_variable_name.to_string(),
},
));
component_statements.push(fastn_js::ComponentStatement::SetProperty(
fastn_js::SetProperty {
kind: fastn_js::PropertyKind::Fit,
value: self.fit.to_set_property_value(doc, rdata),
element_name: kernel.name.to_string(),
inherited: rdata.inherited_variable_name.to_string(),
},
));
if let Some(ref alt) = self.alt {
component_statements.push(fastn_js::ComponentStatement::SetProperty(
alt.to_set_property(
Expand All @@ -679,25 +688,6 @@ impl Image {
),
));
}
if let Some(ref fit) = self.fit {
component_statements.push(fastn_js::ComponentStatement::SetProperty(
fit.to_set_property(
fastn_js::PropertyKind::Fit,
doc,
kernel.name.as_str(),
rdata,
),
));
} else if self.common.width.is_some() && self.common.height.is_some() {
component_statements.push(fastn_js::ComponentStatement::SetProperty(
ftd::js::Value::from_str_value("cover").to_set_property(
fastn_js::PropertyKind::Fit,
doc,
kernel.name.as_str(),
rdata,
),
));
}
component_statements.extend(self.common.to_set_properties(
kernel.name.as_str(),
doc,
Expand Down
30 changes: 16 additions & 14 deletions ftd/t/js/13-non-style-properties.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 20 additions & 18 deletions ftd/t/js/43-image-object-fit.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 0 additions & 58 deletions ftd/t/js/59-image-fit-cover-when-width-height-defined.ftd

This file was deleted.

Loading

0 comments on commit 0fdffc6

Please sign in to comment.