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

Custom View #1

Closed
jrean opened this issue Jul 22, 2015 · 2 comments
Closed

Custom View #1

jrean opened this issue Jul 22, 2015 · 2 comments

Comments

@jrean
Copy link
Contributor

jrean commented Jul 22, 2015

Hi,

First let me say congratulation for that package! Well done!!

I published the vendor view and I try to simply override the confirmButtonColor option.
So by default your view is as following:

@if (Session::has('sweet_alert.alert'))
    <script>
        swal(
            {!! Session::get('sweet_alert.alert') !!}
        );
    </script>
@endif

I tried several time but...

@if (Session::has('sweet_alert.alert'))
    <script>
        swal({
            text: '{!! Session::get('sweet_alert.text') !!}',
            title: '{!! Session::get('sweet_alert.title') !!}',
            timer: {!! Session::get('sweet_alert.timer') !!},
            type: '{!! Session::get('sweet_alert.type') !!}'
            // more options
        });
    </script>
@endif

The problem is I loose the context ->persistent() or ->autoclose() for showConfirmButton, it displays the button when it should not because I can't properly set the option...

It's like I'm missing a {!! Session::get('sweet_alert.showConfirmButton') !!} to dynamically get the boolean :)

I'm probably missing something but, could you please be kind and provide me a sample code exemple on how you would simply keep your perfect work but customise the confirmButtonColor?

Regards,

:)

@uxweb
Copy link
Owner

uxweb commented Jul 22, 2015

Thank you so much for being interested in this package.

I left out some options to configure the js sweet alert function.

I think those options are more related to be set from the frontend part, like the color of the button and such.

The current options the package puts into the session are these:

  • text
  • type
  • title
  • confirmButtonText
  • showConfirmButton
  • allowOutsideClick
  • timer

If you want to change the color of the confirm button, you can by:

@if (Session::has('sweet_alert.alert'))
    <script>
        swal({
            text: '{!! Session::get('sweet_alert.text') !!}',
            title: '{!! Session::get('sweet_alert.title') !!}',
            timer: {!! Session::get('sweet_alert.timer') !!},
            type: '{!! Session::get('sweet_alert.type') !!}',
            showConfirmButton: '{!! Session::get('sweet_alert.showConfirmButton') !!}',
            confirmButtonText: '{!! Session::get('sweet_alert. confirmButtonText') !!}',
            confirmButtonColor: '#AEDEF4'
        });
    </script>
@endif

As you can see, the only property value that is not coming from the package is confirmButtonColor.
If we implement that, our facade will look like this:

Alert::message('Hello World')->persistent('Ok', '#AEDEF4');

I think that part of the color belongs to the frontend, otherwise i think it will be coupled and when you need to change a color you'll have to edit your controller.

Ok, but, what if i want a different color for my button based on the type of alert?

In that case you can do a check for the type:

@if (Session::has('sweet_alert.alert'))
    @if(Session::get('sweet_alert.type') == 'error')
        <script>
            swal({
                text: '{!! Session::get('sweet_alert.text') !!}',
                title: '{!! Session::get('sweet_alert.title') !!}',
                timer: {!! Session::get('sweet_alert.timer') !!},
                type: '{!! Session::get('sweet_alert.type') !!}',
                showConfirmButton: '{!! Session::get('sweet_alert.showConfirmButton') !!}',
                confirmButtonText: '{!! Session::get('sweet_alert. confirmButtonText') !!}',
                confirmButtonColor: 'a red hex color'
            });
        </script>
    @endif

    @if(Session::get('sweet_alert.type') == 'success')
        <script>
            swal({
                text: '{!! Session::get('sweet_alert.text') !!}',
                title: '{!! Session::get('sweet_alert.title') !!}',
                timer: {!! Session::get('sweet_alert.timer') !!},
                type: '{!! Session::get('sweet_alert.type') !!}',
                showConfirmButton: '{!! Session::get('sweet_alert.showConfirmButton') !!}',
                confirmButtonText: '{!! Session::get('sweet_alert. confirmButtonText') !!}',
                confirmButtonColor: 'a green hex color'
            });
        </script>
    @endif
@endif

This way you can have a different button colors for the type of alert or other custom check you want to do.

If you need different kinds of alerts with colors, you can create a partial for each one and include them in the main sweet alert template:

@if (Session::has('sweet_alert.alert'))
    @if(Session::get('sweet_alert.type') == 'error')
        @include('partials.alerts.error')
    @endif

    @if(Session::get('sweet_alert.type') == 'success')
        @include('partials.alerts.success')
    @endif
@endif

This way you can have any customizable alerts.

Hope this helps you!.

I would like to know what you think about it!

Thank you so much again.

@jrean
Copy link
Contributor Author

jrean commented Jul 22, 2015

Awesome! Smart!
I totally agree with you to not add the color option available trough the Facade or the helper. It would become coupled as you mentioned.

Nothing more, your answer and what you provided as code sample is just awesome!

I'll try to submit a PR tomorow for the documentation to include some details I think could be useful.

Thank you :)

@jrean jrean closed this as completed Jul 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants