Brings Storybook's attribute handling closer in line with Drupal's attribute handling and closes #871 .
Stubs the create_attribute()Drupal Twig function so that it can be used in Storybook templates without errors. On the Storybook side, you'll get back the same object you put in. On the Drupal side, it will create an Attribute object from the specified attributes.
Also fixes the Storybook version of add_attributes() so that it will combine the attributes being added with any existing attributes variable (or variable of the name you give it, i.e. item.attributes). This already worked on the Drupal side, but Storybook was ignoring any attributes. Merging should work the same way it does with Drupal: classes are combined, but for attributes that don't take multiple values, what's added in add_attributes() will overwrite what was set previously.
This doesn't come up very often, but can be useful if you do have a use case where you want to set attributes in a component that's included inside another component. For example:
{% set extra_attributes = {
class: 'some_extra_class', {# In the case of class specifically though, you could just use `modifier_class` #}
'data-foo': 'bar'
} %}
{% include '@components/figure/figure.twig' with { attributes: create_attribute(extra_attributes) } %}
The outer markup on the Figure would then be:
<figure class="some_extra_class c-figure" data-foo="bar">
Brings Storybook's attribute handling closer in line with Drupal's attribute handling and closes #871 .
Stubs the
create_attribute()
Drupal Twig function so that it can be used in Storybook templates without errors. On the Storybook side, you'll get back the same object you put in. On the Drupal side, it will create anAttribute
object from the specified attributes.Also fixes the Storybook version of
add_attributes()
so that it will combine the attributes being added with any existingattributes
variable (or variable of the name you give it, i.e.item.attributes
). This already worked on the Drupal side, but Storybook was ignoring any attributes. Merging should work the same way it does with Drupal: classes are combined, but for attributes that don't take multiple values, what's added inadd_attributes()
will overwrite what was set previously.This doesn't come up very often, but can be useful if you do have a use case where you want to set attributes in a component that's included inside another component. For example:
The outer markup on the Figure would then be:
<figure class="some_extra_class c-figure" data-foo="bar">