Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default value for fit property set to cover #1304

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
23 changes: 11 additions & 12 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,16 +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,
),
));
}
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.

8 changes: 5 additions & 3 deletions ftd/t/js/19-image.html

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

40 changes: 22 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.

Loading