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

How to add a custom class without replacing 'toast'? #594

Closed
ghost opened this issue Dec 7, 2018 · 16 comments · Fixed by #970
Closed

How to add a custom class without replacing 'toast'? #594

ghost opened this issue Dec 7, 2018 · 16 comments · Fixed by #970
Labels

Comments

@ghost
Copy link

ghost commented Dec 7, 2018

Sorry if this is answered somewhere, but I want to add some custom styles to an individual toast popup (e.g. increase width). I see the toastClass config option - but this replaces the toast class which has essential styles applied to it (from bootstrap styles).

Is the only way to copy all the styles attached to .toast into my own custom class?

@trevor-hackett
Copy link
Collaborator

In CSS you can add your own .toast class and add/override any CSS properties that you want.

@ghost
Copy link
Author

ghost commented Dec 7, 2018

@yarrgh Thanks, but that would apply to all my toasts. I'm wondering if I can target one specific toast (that is displaying HTML content) without affecting other toasts and without having to copy all the styles that are attached to the toast class.

@keljoundi
Copy link

I 2nd this. it would be very convenient to simply add styling in addition to the defaults. Copying all styles to a custom class still introduces errors for me such as the onTap and onAction events no longer firing

@umaqs
Copy link

umaqs commented May 10, 2019

This is a much-needed feature.
I need to show popups of different colours and one way to do that is, extend Toast component like in pink toast example but in my case, I would have to create 10 different custom components.

if there is any other way please let me know.

Thank you

@scttcper
Copy link
Owner

scttcper commented May 10, 2019

put 'yourclass ngx-toastr' for toastClass?

@umaqs
Copy link

umaqs commented May 11, 2019

@scttcper Thank you for the quick reply.

I tried adding my class with the property of background-color and toast class but it shows a toast with transparent background with no padding also close button and onTap action are not working.

However, if I use toastClass: my-class ngx-toastr`` it gives me a black toast but the rest of the properties are what I want.

Can you please suggest how can I use it in the correct manner.

Thank you very much in advance :)

@scttcper
Copy link
Owner

i had success by being more specific with the classes. could also try !important.

.yourclass.toast-success {
  background-color: blue;
}

@umaqs
Copy link

umaqs commented May 11, 2019

Thank you very much 👍

I have this working with the css you provided and then specifying toastClass: 'ngx-toastr toast-success yourclass'

As you can see I had to use both ngx-toasts and toast-success to make it work.

One more quick question, please.

I have to put my class in styles.css. I would want to move it to the component level css file, its the place I am calling toasterService.show() from. Is it possible to do so?

Once again thank you for the help!

@scttcper
Copy link
Owner

scttcper commented May 11, 2019

the toast is not inside the context of your component so scoped css would not be applied. custom toasts would be the closest you could get but would still require positioning styles applied globally

@axell9641
Copy link

Is there any way I can change the position of the toastr from within a component? I see the toastClass gets applied to the content, not the container.

@sami-colon
Copy link

i had success by being more specific with the classes. could also try !important.

.yourclass.toast-success {
  background-color: blue;
}

This worked like charm.

@lvilca-tekton
Copy link

I can't get this to work, I am trying this in my .ts file
I have imported the toastrService to it, then I use

this._toastrService.success('test','test',{toastClass:'yourclass ngx-toastr'})

In the same dir, I have an css file

.yourclass .toast-message {
    background-color: blue;
}

I don't see it blue, am I doing smth wrong?

@scttcper
Copy link
Owner

scttcper commented Jan 4, 2023

🎉 This issue has been resolved in version 16.0.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Ashish-rajpoot
Copy link

node_modules/ngx-toastr/toastr/toast.directive.d.ts:8:18 - error TS2707: Generic type 'ɵɵDirectiveDeclaration' requires between 6 and 8 type arguments.

@SagarStake
Copy link

My requirement is to show a countdown timer in the toastr message, is there any way to do this?
Is there a way for the toastr to use templateRef element to show in the message. That way I can use an observable value in the templateRef to show the dynamic value of the observable at any given time.

@shubham-bajaj
Copy link

shubham-bajaj commented Jan 22, 2024

.yourclass.toast-error{
background-color: blue !important;
}
const toastrConfig: Partial = {
closeButton: true,
progressBar: true,
timeOut: 10000,
toastClass: 'yourclass ngx-toastr'
};
can you please explain me why this is not working?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants