Skip to content

Commit

Permalink
Merge pull request #54 from sitegeist/feature/genericAttributesSupport
Browse files Browse the repository at this point in the history
FEATURE: Add generic attributes support
  • Loading branch information
mficzel committed Apr 27, 2022
2 parents 75c3463 + 30a91e8 commit e968089
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ Props:
- `height`: (optional) the base height, will be applied to the `imageSource`
- `alt`: alt-attribute for the img tag (default "")
- `title`: title attribute for the img tag
- `class`: class attribute for the img tag
- `class`: class attribute for the img tag (deprecated in favor of attributes.class)
- `attributes`: tag-attributes, will override any automatically rendered ones
- `renderDimensionAttributes`: render dimension attributes (width/height) when the data is available from the imageSource. Enabled by default

#### Image with srcset in multiple resolutions:
Expand Down Expand Up @@ -143,7 +144,9 @@ Props:
- `loading`: (optional, default "lazy") loading attribute for the img tag
- `alt`: alt-attribute for the img tag
- `title`: title attribute for the img tag
- `class`: class attribute for the picture tag
- `attributes`: picture-tag-attributes, will override any automatically rendered ones
- `imgAttributes`: img-tag-attributes, will override any automatically rendered ones
- `class`: class attribute for the picture tag (deprecated in favor of attributes.class)
- `renderDimensionAttributes`: render dimension attributes (width/height) for the img-tag when the data is available from the imageSource
if not specified renderDimensionAttributes will be enabled automatically for pictures that only use the `formats` options.

Expand Down
11 changes: 11 additions & 0 deletions Resources/Private/Fusion/Prototypes/Image.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ prototype(Sitegeist.Kaleidoscope:Image) < prototype(Neos.Fusion:Component) {
}
}

withAttributes {
attributes = Neos.Fusion:DataStructure {
data-foo="bar"
style="border: 5px solid pink;"
}
}

multires_array {
srcset = ${['1x', '1.5x', '2x']}
}
Expand Down Expand Up @@ -101,11 +108,13 @@ prototype(Sitegeist.Kaleidoscope:Image) < prototype(Neos.Fusion:Component) {
sizes = null
alt = null
title = null
// class is deprecated in favor of attributes.class
class = null
loading = 'lazy'
width = null
height = null
format = null
attributes = Neos.Fusion:DataStructure
renderDimensionAttributes = true

renderer = Neos.Fusion:Component {
Expand All @@ -123,6 +132,7 @@ prototype(Sitegeist.Kaleidoscope:Image) < prototype(Neos.Fusion:Component) {
alt = ${props.alt}
title = ${props.title}
class = ${props.class}
attributes = ${props.attributes}
renderDimensionAttributes = ${props.renderDimensionAttributes}

renderer = afx`
Expand All @@ -138,6 +148,7 @@ prototype(Sitegeist.Kaleidoscope:Image) < prototype(Neos.Fusion:Component) {
title={props.title || props.imageSource.title()}
width={props.renderDimensionAttributes ? props.imageSource.width() : null}
height={props.renderDimensionAttributes ? props.imageSource.height() : null}
{...props.attributes}
/>
`
}
Expand Down
21 changes: 20 additions & 1 deletion Resources/Private/Fusion/Prototypes/Picture.fusion
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ prototype(Sitegeist.Kaleidoscope:Picture) < prototype(Neos.Fusion:Component) {
}
alt = 'Elva dressed as a fairy'
}

propSets {
withAttributes {
attributes = Neos.Fusion:DataStructure {
data-foo="bar"
style="border: 5px solid green;"
}
imgAttributes = Neos.Fusion:DataStructure {
data-foo="baz"
style="border: 5px solid pink;"
}
}
}
}

imageSource = null
Expand All @@ -45,7 +58,10 @@ prototype(Sitegeist.Kaleidoscope:Picture) < prototype(Neos.Fusion:Component) {
height = null
alt = ''
title = null
// class is deprecated in favor of attributes.class
class = null
attributes = Neos.Fusion:DataStructure
imgAttributes = Neos.Fusion:DataStructure
content = ''
renderDimensionAttributes = true

Expand Down Expand Up @@ -79,11 +95,13 @@ prototype(Sitegeist.Kaleidoscope:Picture) < prototype(Neos.Fusion:Component) {
alt = ${props.alt}
title = ${props.title}
class = ${props.class}
attributes = ${props.attributes}
imgAttributes = ${props.imgAttributes}
content = ${props.content}
renderDimensionAttributes = ${props.renderDimensionAttributes}

renderer = afx`
<picture class={props.class}>
<picture class={props.class} {...props.attributes}>
{props.content}
<Neos.Fusion:Collection collection={props.sources} itemName="source" @if.has={props.sources}>
<Sitegeist.Kaleidoscope:Source
Expand Down Expand Up @@ -112,6 +130,7 @@ prototype(Sitegeist.Kaleidoscope:Picture) < prototype(Neos.Fusion:Component) {
loading={props.loading}
alt={props.alt}
title={props.title}
attributes={props.imgAttributes}
renderDimensionAttributes={props.renderDimensionAttributes}
/>
</picture>
Expand Down

0 comments on commit e968089

Please sign in to comment.