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

[UI] Docs explaining how to use the accordion component #200

Open
wants to merge 9 commits into
base: 5.x
Choose a base branch
from
136 changes: 136 additions & 0 deletions docs/design/accordion.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
.. vale off

Accordion component

Check warning on line 3 in docs/design/accordion.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Mautic.FeatureList] Is this referring to a Mautic feature? If so, use 'Component' instead of 'component'. Raw Output: {"message": "[Mautic.FeatureList] Is this referring to a Mautic feature? If so, use 'Component' instead of 'component'.", "location": {"path": "docs/design/accordion.rst", "range": {"start": {"line": 3, "column": 11}}}, "severity": "INFO"}
===================

.. vale on

Introduction
------------

The Accordion Component allows developers to create collapsible sections within their Mautic templates. This Component is useful for organizing content into expandable and collapsible panels, enhancing the User experience by making large amounts of content more manageable.


Template structure
------------------

The ``accordion.html.twig`` template defines this accordion component. The template employs a list structure ``<ul>`` where each item ``<li>`` represents an accordion panel. Each panel consists of a heading and a collapsible content section.

Check warning on line 17 in docs/design/accordion.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Mautic.FeatureList] Is this referring to a Mautic feature? If so, use 'Component' instead of 'component'. Raw Output: {"message": "[Mautic.FeatureList] Is this referring to a Mautic feature? If so, use 'Component' instead of 'component'.", "location": {"path": "docs/design/accordion.rst", "range": {"start": {"line": 17, "column": 61}}}, "severity": "INFO"}

.. vale off

Key Features
^^^^^^^^^^^^

.. vale on

- Clicking on the heading expands or collapses each accordion item.
- The component includes ARIA attributes to improve accessibility.

Check warning on line 27 in docs/design/accordion.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Mautic.FeatureList] Is this referring to a Mautic feature? If so, use 'Component' instead of 'component'. Raw Output: {"message": "[Mautic.FeatureList] Is this referring to a Mautic feature? If so, use 'Component' instead of 'component'.", "location": {"path": "docs/design/accordion.rst", "range": {"start": {"line": 27, "column": 7}}}, "severity": "INFO"}

Check warning on line 27 in docs/design/accordion.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Google.Acronyms] Spell out 'ARIA', if it's unfamiliar to the audience. Raw Output: {"message": "[Google.Acronyms] Spell out 'ARIA', if it's unfamiliar to the audience.", "location": {"path": "docs/design/accordion.rst", "range": {"start": {"line": 27, "column": 26}}}, "severity": "INFO"}
- You can customize the content of each accordion panel using Twig variables.

.. vale off

Applying the Accordion Component
--------------------------------

.. vale on

To use the accordion component, include it in your template and pass the necessary data.

Check warning on line 37 in docs/design/accordion.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Mautic.FeatureList] Is this referring to a Mautic feature? If so, use 'Component' instead of 'component'. Raw Output: {"message": "[Mautic.FeatureList] Is this referring to a Mautic feature? If so, use 'Component' instead of 'component'.", "location": {"path": "docs/design/accordion.rst", "range": {"start": {"line": 37, "column": 22}}}, "severity": "INFO"}

Define the content you want to include in the accordion. For example, if you want to include a group of UTM tags fields, you can define the content as follows:

.. code-block:: twig

{% set utmTagsContent %}
{% for i, utmTag in form.utmTags %}
{{ form_row(utmTag) }}
{% endfor %}
{% endset %}

.. note::
For instance, you can loop over Form fields or any other data to generate the content dynamically.

Check warning on line 50 in docs/design/accordion.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Mautic.FeatureList] Is this referring to a Mautic feature? If so, use 'Form Fields' instead of 'Form fields'. Raw Output: {"message": "[Mautic.FeatureList] Is this referring to a Mautic feature? If so, use 'Form Fields' instead of 'Form fields'.", "location": {"path": "docs/design/accordion.rst", "range": {"start": {"line": 50, "column": 36}}}, "severity": "INFO"}

Include the ``accordion.html.twig`` template in your main template and pass an array of items. Each item should have:

- ``id``: a unique identifier.
- ``title``: the title of the accordion item.
- ``padding_inline``: (Optional) boolean to control padding within the content. Defaults to true if not defined.

Check warning on line 56 in docs/design/accordion.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Google.Parens] Use parentheses judiciously. Raw Output: {"message": "[Google.Parens] Use parentheses judiciously.", "location": {"path": "docs/design/accordion.rst", "range": {"start": {"line": 56, "column": 23}}}, "severity": "INFO"}
- ``content``: the content displays when the item expands.

Example:

.. code-block:: twig

{% include '@MauticCore/Helper/accordion.html.twig' with {
'items': [
{
'id': 'UTM',
'title': 'mautic.email.utm_tags',
'padding_inline': false,
'content': utmTagsContent,
}
]
} %}

While defining a ``set`` block separately isn't strictly necessary, it can be helpful to ensure that operations relying on Twig functions keep working correctly. The ``set`` block allows you to predefine complex content or operations, making your template cleaner and more maintainable.

.. vale off

Example without the ``set`` Block
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. vale on

If your content is simple, you can directly include it within the ``items`` array without using a ``set`` block. Here's an example:

.. code-block:: twig

{% include '@MauticCore/Helper/accordion.html.twig' with {
'items': [
{
'id': 'Example',
'title': 'Example Title',
'padding_inline': true,
'content': '<p>This is a simple content example.</p>',
}
]
} %}

This flexibility allows you to choose the best approach based on each case.

Automatic CSS handling

Check warning on line 100 in docs/design/accordion.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Google.Headings] 'Automatic CSS handling' should use sentence-style capitalization. Raw Output: {"message": "[Google.Headings] 'Automatic CSS handling' should use sentence-style capitalization.", "location": {"path": "docs/design/accordion.rst", "range": {"start": {"line": 100, "column": 1}}}, "severity": "WARNING"}
----------------------

When using the Component, all necessary CSS styles are automatically handled for you. This means that the Component comes pre-styled with classes such as ``accordion-heading``, ``accordion-wrapper``, and ``accordion-content``, ensuring a consistent and visually appealing appearance out of the box.

- The Component includes predefined CSS classes that manage the layout, spacing, and interactive elements of the accordion.
- You don't need to add any extra CSS to make the accordion function and look visually appealing.
- It uses the existing Bootstrap function for collapsing panels.
- Avoid overriding these classes in your own CSS.

The design of the accordion makes it easy to implement, with all essential CSS styles already in place. This allows you to focus on integrating and using the component without worrying about additional styling.

Check warning on line 110 in docs/design/accordion.rst

View workflow job for this annotation

GitHub Actions / prose

[vale] reported by reviewdog 🐶 [Mautic.FeatureList] Is this referring to a Mautic feature? If so, use 'Component' instead of 'component'. Raw Output: {"message": "[Mautic.FeatureList] Is this referring to a Mautic feature? If so, use 'Component' instead of 'component'.", "location": {"path": "docs/design/accordion.rst", "range": {"start": {"line": 110, "column": 159}}}, "severity": "INFO"}

Complete example
----------------

Here is a complete example that demonstrates how to use the accordion Component in a Mautic template:

.. code-block:: twig

{% set utmTagsContent %}
{% for i, utmTag in form.utmTags %}
{{ form_row(utmTag) }}
{% endfor %}
{% endset %}

{% include '@MauticCore/Helper/accordion.html.twig' with {
'items': [
{
'id': 'UTM',
'title': 'mautic.email.utm_tags',
'padding_inline': false,
'content': utmTagsContent,
}
]
} %}

For more complex structures, with dozens of accordion items, you might prefer to copy the structure and build something unique, but the best approach would be to place each content under a set block.
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ There are several ways to support Mautic other than contributing with code.
:caption: Design and UX
:hidden:

design/retrieving_system_information
design/accordion
design/retrieving_system_settings

.. toctree::
:maxdepth: 2
Expand Down
Loading