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

Refactoring alert() macro #90

Merged
merged 3 commits into from
Jun 1, 2022

Conversation

cavasinf
Copy link
Collaborator

@cavasinf cavasinf commented May 31, 2022

Description

Related to #89

Usage

{% from '@Tabler/components/alert.html.twig' import alert %}

<div class="row">
    <div class="col-6">
        {{ alert('danger', 'Description' ,'Title', 'fas fa-exclamation-triangle', true) }}
        {{ alert('danger', 'Description' ,'Title', 'fas fa-exclamation-triangle') }}
        {{ alert('danger', 'Description' ,'Title', 'fas fa-exclamation-triangle') }} {# Error here #}
        {{ alert('warning', 'Description' ,'Title') }}
        {{ alert('warning', null ,'Title') }}
        {{ alert('warning', null ,'Title', 'fas fa-exclamation-triangle') }}
        {{ alert('success', 'Description') }}
        {{ alert('success', 'Description', null, 'fas fa-exclamation-triangle') }}
        {{ alert('primary') }}
    </div>

    <div class="col-6">
        {{ alert({title : 'Title V2', description: 'Description V2', icon : 'warning', dismissible : true}) }}
        {{ alert({title : 'Title V2', description: 'Description V2', icon : 'warning'}) }}
        {{ alert({title : 'Title V2', description: 'Description V2', icon : 'warning', important: true}) }} {# Looks good now #}
        {{ alert({title : 'Title V2', description: 'Description V2', type : 'warning'}) }}
        {{ alert({title : 'Title V2', type : 'warning'}) }}
        {{ alert({title : 'Title V2', icon : 'warning', type : 'warning'}) }}
        {{ alert({description : 'Description V2', type : 'success'}) }}
        {{ alert({description : 'Description V2', type : 'success', icon : 'warning'}) }}
        {{ alert({type : 'primary'}) }}
    </div>
</div>

Preview

image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I updated the documentation (see here)
  • I agree that this code will be published under the MIT license

@cavasinf cavasinf linked an issue May 31, 2022 that may be closed by this pull request
Copy link
Owner

@kevinpapst kevinpapst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make the raw filter optional by a setting like in my example.
This filter can easily lead to CSRF issues if you pass user generated values to it.
Better activate it per case, instead of "blindly" using unescaped data.

templates/components/alert.html.twig Outdated Show resolved Hide resolved
templates/components/alert.html.twig Outdated Show resolved Hide resolved
@cavasinf
Copy link
Collaborator Author

Sure 👍

@kevinpapst
Copy link
Owner

nice 👍 ready for merge from your end?

@cavasinf
Copy link
Collaborator Author

cavasinf commented May 31, 2022 via email

@kevinpapst kevinpapst merged commit da494e8 into kevinpapst:main Jun 1, 2022
@kevinpapst
Copy link
Owner

I will add your examples to the demo application. Thanks you @cavasinf 👍

@cavasinf cavasinf deleted the feature/alert branch June 1, 2022 07:18
@cavasinf
Copy link
Collaborator Author

cavasinf commented Jun 1, 2022

Yeah I haven't seen a doc for that kind of feature.
We can maybe add the doc of that component is this repo like others 🤔

@kevinpapst
Copy link
Owner

This is what I see after the merge:
Bildschirmfoto 2022-06-01 um 09 38 27
Can you confirm that is still looks as in your screenshot?

@kevinpapst
Copy link
Owner

Sorry, the icon warning wasn't configured.
Bildschirmfoto 2022-06-01 um 09 40 25

@kevinpapst
Copy link
Owner

Yeah I haven't seen a doc for that kind of feature.

Because you still don't use the demo app, do you 😁

@kevinpapst
Copy link
Owner

Okay, there is one BC break which is not matching the Tabler docs: https://preview.tabler.io/docs/alerts.html

Before:
Bildschirmfoto 2022-06-01 um 09 45 33

After:
Bildschirmfoto 2022-06-01 um 09 51 29

Could you have a look while I work on the docs?

@cavasinf
Copy link
Collaborator Author

cavasinf commented Jun 3, 2022

@kevinpapst Looks like it's coming from the icon class again.

Tabler user SVG, we use FontAwesome.
Can you try with false param at tabler_icon twig function.

{{ tabler_icon(_icon, true) }}

I remember it was "odd" without this class, but if it's okay for you, we can switch that 👍

@cavasinf
Copy link
Collaborator Author

cavasinf commented Jun 3, 2022

I'll check for title color + description => new PR ?

@kevinpapst
Copy link
Owner

I don't mind the icon size/positioning, bigger looks better and I didn't even recognize it before you mentioned it ;-)

I was only talking about the colors, which worked before. New PR sounds good :)

@cavasinf cavasinf added the Feature Feature requested label Jun 3, 2022
@kevinpapst
Copy link
Owner

Going through my deprecations log, I saw that we missed one:
https://github.com/kevinpapst/TablerBundle/blob/main/templates/components/callout.html.twig#L3

callout is calling alert with single params 🙄

@cavasinf
Copy link
Collaborator Author

cavasinf commented Jun 7, 2022

What do you want to do ?
Add the deprecated message and change multi params into one object param.

Also, why it has 6 parameters for a macro that can only have 5 ?

@kevinpapst
Copy link
Owner

kevinpapst commented Jun 7, 2022

Because important is the 6 param and it got lost somewhere in the refactoring process.
To have a consistent API we should change the signature as well:

{% from '@theme/components/alert.html.twig' import alert %}
{% if type is iterable %}
    {{ alert(type) }}
{% else %}
    {% deprecated "Passing multiple parameters to 'callout()' Tabler macro is deprecated, use options object syntax." %}
    {{ alert({type: type|default('danger'), description: description, title: title|trans, icon: icon, dismissible: false, important: true}) }}
{% else %}

What do you think ?

@cavasinf
Copy link
Collaborator Author

cavasinf commented Jun 7, 2022

NVM

@cavasinf
Copy link
Collaborator Author

cavasinf commented Jun 7, 2022

  • Missing the trans of description (like OLD alert macro)
  • icon is required in callout macro ?
  • description is required ?
  • Maybe add {% set options = type %} inside if condition (if devs looks at code).
  • Careful at "end if" block 😉

@kevinpapst kevinpapst mentioned this pull request Jun 9, 2022
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature Feature requested
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Alert macro and alert-important class
2 participants