Giter VIP home page Giter VIP logo

Comments (18)

ellern avatar ellern commented on June 9, 2024

How do I set a custom class on the modal-dialog element?

from ngx-modialog.

shlomiassaf avatar shlomiassaf commented on June 9, 2024

It should look like this

modal.alert()
    .headerClass('modal-header')
    .title('Hello World')
    .body('A Customized Modal')
    .bodyClass('modal-body')
    .footerClass('modal-footer')
    .okBtnClass('btn')
    .open();

Play with the generator to see other options... http://shlomiassaf.github.io/angular2-modal#/customizeModals

from ngx-modialog.

shlomiassaf avatar shlomiassaf commented on June 9, 2024

Basically there is a 1 custom modal that I'v implemented (MessageModal) which represents a classic bootstrap modal - it replace the old ones (okOnly, yesNo)

I've built the alert,prompt and confirm presets around it which provides a lot of flexibility.

If a more advanced scenario is needed a custom modal is needed...

When I think about it, its quite generic because you can build your own modal + presets and have a modal supporting something other then bootstrap

from ngx-modialog.

ellern avatar ellern commented on June 9, 2024

I'm aware of the headerClass, bodyClass and footerClass, but that will not allow you to do any positioning. That why I wanted to see a way to add a class to the modal-dialog. It could be an optional .modalClass('my-custom-modal') in the fluent api

from ngx-modialog.

shlomiassaf avatar shlomiassaf commented on June 9, 2024

The problem with modal-dialog is that it hold the "size" css class.
So, What would you think is the best approach here?

Template:

    `<div class="modal-dialog"
         [class.modal-lg]="dialogInstance.config.size == \'lg\'"
         [class.modal-sm]="dialogInstance.config.size == \'sm\'">
         <div class="modal-content" (click)="onContainerClick($event)" style="display: block">
            <div style="display: none" #modalDialog></div>
         </div>
    </div>`

So having a custom css class should override the size, which then creates a weird behaviour...

from ngx-modialog.

ellern avatar ellern commented on June 9, 2024

Doing something like this will not override the size class

<div class="modal-dialog"
     [ngClass]="dialogInstance.config.modalDialogClass || ''"
     [class.modal-lg]="dialogInstance.config.size == \'lg\'"
     [class.modal-sm]="dialogInstance.config.size == \'sm\'">
     <div class="modal-content" (click)="onContainerClick($event)" style="display: block">
        <div style="display: none" #modalDialog></div>
     </div>
</div>

from ngx-modialog.

shlomiassaf avatar shlomiassaf commented on June 9, 2024

Yep I agrre but that doesn't solve my issue.
config.size has a default value, usually "lg".
So a user will have to do

modal.alert()
    .size('')
    .modalDialogClass('something')
    .open()

To get the class to be what he wanted...

Maybe setting modalDialogClass will also override size?

from ngx-modialog.

shlomiassaf avatar shlomiassaf commented on June 9, 2024

You know what, overriding make's sense, if someone wants to be explicit then by all means, all the way.

from ngx-modialog.

ellern avatar ellern commented on June 9, 2024

There should be room for both. In my current setup I use both lg and a custom class. The custom class is currently used to positioning the modal not changing its size.

Btw. don't know if modalDialogClass would be the best fit for a name. What about modalClass to keep it aligned with the headerClass

from ngx-modialog.

shlomiassaf avatar shlomiassaf commented on June 9, 2024

If u'r setting a custom modal-dialog class you will need to set "modal-lg" as a custom class.
e.g: modal.alert().dialogClass('my-cutom modal-lg')

I think it looks better then modal.alert().dialogClass('my-cutom').size('')

from ngx-modialog.

shlomiassaf avatar shlomiassaf commented on June 9, 2024

Btw. don't know if modalDialogClass would be the best fit for a name. What about modalClass to keep it aligned with the headerClass

The naming convention is xClass where x is the original class name without the modal (modal-x).
e.g: modal-header -> headerClass

So it will be dialogClass

from ngx-modialog.

ellern avatar ellern commented on June 9, 2024

Makes sense

from ngx-modialog.

shlomiassaf avatar shlomiassaf commented on June 9, 2024

BTW, you know that all xClass methods override the class, so setting dialogClass will remove the original class (modal-dialog), if it's addition you're after you will have to do modal-dialog my-css

There's no other option...

from ngx-modialog.

ellern avatar ellern commented on June 9, 2024

I'm not seeing that behaviour using beta12.

When I'm using [ngClass]="dialogInstance.config.modalDialogClass || ''" I get the value from the config added to the class list. My modal-dialog ends of with the following class list: modal-dialog lg custom

from ngx-modialog.

shlomiassaf avatar shlomiassaf commented on June 9, 2024

I talked about general behaviour of xClass in the preset's.

As for the expression dialogInstance.config.modalDialogClass it invalid because dialogInstance.config is not the preset API, it's an instance of ModalConfig which is build from the preset, but it's not the preset so dialogInstance.config.modalDialogClass will always be null.

The actual preset is injected into the Modal component itself.

The preset is wrapper that combine's the two, but when doing a manual implementation they are separate.

from ngx-modialog.

ellern avatar ellern commented on June 9, 2024

Okay, I misunderstood. Btw. the dialogInstance.config.modalDialogClass is just something I have in a local fork - switching to your new fluent api version when the dialogClass is implemented.

from ngx-modialog.

shlomiassaf avatar shlomiassaf commented on June 9, 2024

Cool 👍

It will probably end up (dialogClass) on the config object since it's a level above the modal component...

from ngx-modialog.

shlomiassaf avatar shlomiassaf commented on June 9, 2024

See latest commits, modal-dialog is enabled via dialogClass

You can verify it in the code generator.

If size is set it will not remove it, I left it as you requested originally

npm version 0.1.1

from ngx-modialog.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.