首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自定义wicket中的ModalDialog组件

自定义wicket中的ModalDialog组件
EN

Stack Overflow用户
提问于 2020-11-26 08:19:40
回答 1查看 658关注 0票数 1

我在一个页面上有多个ModalDialogs,每个页面都应该有不同的宽度。每个模式对话框的定制可以在.modal-dialog类覆盖的.CSS中进行。

我想知道如何在不接触.CSS的情况下为每个模态对话框设置不同的宽度大小,因为每个模态窗口都有. modal对话框类,而且我不能更改名称,因为它将用模态窗口创建。

有什么办法可以使用AttributeModifier吗?

代码语言:javascript
复制
public class MainPanel extends Panel {

    private final ModalDialog modalDialog;

    public MainPanel(String id, IModel<String> headingIdx, IModel<String> collapseIdx) {
        super(id);
        setOutputMarkupId(true);
        modalDialog = new ModalDialog("modalDialog");
        modalDialog.add(new DefaultTheme());
        modalDialog.trapFocus();
        modalDialog.closeOnEscape();
        add(modalDialog);

        add(new AjaxLink<Void>("showModalDialog") {
            @Override
            public void onClick(AjaxRequestTarget target) {
                modalDialog.setContent(new ModalPanel("content", MainPanel.this){
                    @Override
                    protected void close(AjaxRequestTarget target) {
                        modalDialog.close(target);
                    }
                });
                modalDialog.open(target);
            }
        });
        add(modalDialog);
    }
}        
代码语言:javascript
复制
.modal-header {
    font-weight: bold;
    border: none;
}

.modal-dialog {
    border-radius: 5px;
    pointer-events: all;
}

.modal-dialog .modal-dialog-content {
    /* flex children */
    display: flex;
    flex-direction: column;
}

.modal-dialog-overlay.current-focus-trap .modal-dialog-content {
    /* resize the dialog with current focus only, otherwise the resize handle shows through on Firefox */
    resize: both;
}

.modal-dialog .modal-dialog-form {
    /* size */
    margin: 0;
    padding: 0;
    overflow: hidden;

    /* flex in parent */
    flex: 1;

    /* flex children */
    display: flex;
    flex-direction: column;
}

.modal-dialog .modal-dialog-header {
    border-radius: 5px 5px 0px 0px;
    background: #ffb158;
    margin: 0;
    padding-top: 4px;
    text-align: center;
}

.modal-dialog .modal-dialog-body {
    /* size */
    flex: 1;
    overflow-y: auto;

    padding: 20px;
}

.modal-dialog .modal-dialog-footer {
    padding: 5px;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-26 08:36:12

您可以向每个ModalWindow添加一个自定义CSS类:

代码语言:javascript
复制
modalDialog.add(AttributeAppender.append("class", "custom-1"));

然后在.css文件中可以添加CSS规则,例如:

代码语言:javascript
复制
.modal-dialog.custom-1 {
   width: 1234px;
}

代码语言:javascript
复制
.modal-dialog.custom-1 .modal-dialog-content {
   width: 1234px;
}

这取决于您需要修改的模态窗口的哪个元素。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65018312

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档