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

feat(modal): dynamic modal content #1774

Merged
merged 5 commits into from
Nov 22, 2020

Conversation

lubber-de
Copy link
Member

@lubber-de lubber-de commented Nov 19, 2020

Description

This PR adds the same dynamic functionality like toast to create a modal just out of properties or reuse a DOM node modal as a template with its content being dynamically set via js properties.
Everything is optional and backward compatible 🙂
Most of the code is copied /adopted from the toast component so the usage is equal.

This goes along with @prudho fui-alert plugin approach (#1716) which could be more simplified then

Create a temporary modal just by JS properties

By providing new properties to the modal module and targeting to body you create temporary modals without the need to create markup on your own. The modal is temporary and will be removed from the DOM once closed.

$('body').modal({
  title: 'Important Notice',
  class: 'mini',
  closeIcon: true,
  content: 'You will be logged out in 5 Minutes',
  actions: [{
    	text: 'Alright, got it',
        class: 'green'
  }]
}).modal('show');

Reuse an existing modal

Also, you can still prepare a modal markup in your domtree as usual, but set the related content via js properties to reuse the general style

$('.ui.modal').modal({
  title: 'Chat rules',
  content: '<div>You can put HTML content right here</div>',
  class: 'inverted fullscreen',
  classContent: 'scrolling',
  actions: [{
    	text: 'That is awesome',
        class: 'green',
        icon: 'exclamation',
        click: function() {
            // do something. return false to prevent closing the modal
        }
  }]
}).modal('show');

Testcase

https://jsfiddle.net/lubber/eo8bdyp3/48/

Screenshot

dynamicmodal

Closes

#1407

@lubber-de lubber-de added type/feat Any feature requests or improvements lang/javascript Anything involving JavaScript state/awaiting-reviews Pull requests which are waiting for reviews labels Nov 19, 2020
@lubber-de lubber-de added this to the 2.8.8 milestone Nov 19, 2020
@lubber-de lubber-de added the state/awaiting-docs Pull requests which need doc changes/additions label Nov 19, 2020
src/definitions/modules/modal.js Outdated Show resolved Hide resolved
Copy link
Contributor

@prudho prudho left a comment

Choose a reason for hiding this comment

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

LGTM !

Copy link
Member

@ko2in ko2in left a comment

Choose a reason for hiding this comment

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

LGTM. Nice feature 🥇

@lubber-de lubber-de changed the title [Modal] Create dynamic modals out of pure JS properties, use DOM modals as template with dynamic content feat(modal): dynamic modal content Nov 22, 2020
@lubber-de lubber-de merged commit 7e3e450 into fomantic:develop Nov 22, 2020
@lubber-de lubber-de deleted the feat/dynamicModal branch November 22, 2020 17:55
@lubber-de lubber-de removed the state/awaiting-reviews Pull requests which are waiting for reviews label Nov 22, 2020
lubber-de added a commit that referenced this pull request Feb 25, 2021
This PR adds the possibility of using JS config templates for the modal module.
That means you can declare a reusable dynamic template function which returns predefined config settings (modified depending of your input to the template function) as the modal is already prepared to create dynamic content out of pure js since #1774

For this reason modal now also has an optional autoshow option, which enables you to immediatly show the modal on instantiation time, so no more need for $(.ui.modal).modal({closable:false}).modal('show') but $(.ui.modal).modal({closable:false, autoShow:true})

Modal now also can use the transition methods for show/hide individually (backwards compatible) (just like in toast and for dimmer in #1867)
lubber-de added a commit that referenced this pull request Jun 23, 2021
While preparing the docs for #1774 , i recognized that modal

does not create action buttons at all when the actions container is not available in the DOM
does always stack action buttons on DOM modals when reused

Co-authored-by: TATSUNO Yasuhiro <[email protected]>
@lubber-de
Copy link
Member Author

Docs added by fomantic/Fomantic-UI-Docs#287

@lubber-de lubber-de added state/has-docs A issue/PR which requires documentation changes and has the corresponding PR open in the docs repo and removed state/awaiting-docs Pull requests which need doc changes/additions labels Jun 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lang/javascript Anything involving JavaScript state/has-docs A issue/PR which requires documentation changes and has the corresponding PR open in the docs repo type/feat Any feature requests or improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants