-
Notifications
You must be signed in to change notification settings - Fork 26
feat: Adds BS5 modal components #234
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
Open
mavoIn
wants to merge
22
commits into
django-cms:master
Choose a base branch
from
mavoIn:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
000d62e
Add djangocms_frontend.contrib.modal
mavoIn 05b28bf
Add documatation
mavoIn aabd64b
fix pre-commit.ci
mavoIn dcc7bf9
fix pre-commit.ci
mavoIn e9bac3e
fix pre-commit.ci
mavoIn bc44590
fix pre-commit.ci
mavoIn 2039580
use ruff and add test
mavoIn 46ab763
add migrations
mavoIn 8179a08
Parents and children elements defined more restrictively
mavoIn b81ec6d
Add documentation for component and screenshots
mavoIn 2e18404
Update tests/modal/test_models.py
mavoIn dd2359d
Merge branch 'master' into master
fsbraun cac6683
Merge branch 'master' into master
fsbraun 2d6b0e8
Merge branch 'master' into master
mavoIn a108304
fix flake8 messages
pincy 70cef54
Merge branch 'master' into master
pincy 956771a
Merge branch 'master' into master
mavoIn 20074d4
Update djangocms_frontend/contrib/modal/forms.py
mavoIn 3df3b0c
Update djangocms_frontend/contrib/modal/forms.py
mavoIn 80fab0f
Update cms_plugins.py
mavoIn cad3e66
adds an option for an additional footer
mavoIn 5aaf335
adds an option for an additional footer
mavoIn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
from cms.plugin_pool import plugin_pool | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from ... import settings | ||
from ...cms_plugins import CMSUIPlugin | ||
from ...common.attributes import AttributesMixin | ||
from .. import modal | ||
from . import forms, models | ||
|
||
mixin_factory = settings.get_renderer(modal) | ||
|
||
|
||
@plugin_pool.register_plugin | ||
class ModalPlugin(mixin_factory("Modal"), AttributesMixin, CMSUIPlugin): | ||
""" | ||
Component > "Modal" Plugin | ||
https://getbootstrap.com/docs/5.0/components/modal/ | ||
""" | ||
|
||
name = _("Modal") | ||
module = _("Frontend") | ||
model = models.Modal | ||
form = forms.ModalForm | ||
change_form_template = "djangocms_frontend/admin/modal.html" | ||
allow_children = True | ||
child_classes = [ | ||
"ModalTriggerPlugin", | ||
"ModalContainerPlugin", | ||
"LinkPlugin", | ||
"CardPlugin", | ||
"SpacingPlugin", | ||
"GridRowPlugin", | ||
] | ||
|
||
fieldsets = [ | ||
(None, {"fields": ("modal_siblings",)}), | ||
] | ||
|
||
|
||
@plugin_pool.register_plugin | ||
class ModalTriggerPlugin(mixin_factory("ModalTrigger"), AttributesMixin, CMSUIPlugin): | ||
""" | ||
Component > "Modal" Plugin | ||
https://getbootstrap.com/docs/5.0/components/modal/ | ||
""" | ||
|
||
name = _("Modal trigger") | ||
module = _("Frontend") | ||
model = models.ModalTrigger | ||
form = forms.ModalTriggerForm | ||
allow_children = True | ||
parent_classes = [ | ||
"CardPlugin", | ||
"CardInnerPlugin", | ||
"ModalPlugin", | ||
"GridColumnPlugin", | ||
] | ||
|
||
fieldsets = [ | ||
(None, {"fields": ("trigger_identifier",)}), | ||
] | ||
|
||
|
||
@plugin_pool.register_plugin | ||
class ModalContainerPlugin(mixin_factory("ModalContainer"), CMSUIPlugin): | ||
""" | ||
Component > "Modal Container" Plugin | ||
https://getbootstrap.com/docs/5.0/components/modal/ | ||
""" | ||
|
||
name = _("Modal container") | ||
module = _("Frontend") | ||
model = models.ModalContainer | ||
form = forms.ModalContainerForm | ||
allow_children = True | ||
child_classes = [ | ||
"ModalInnerPlugin", | ||
|
||
] | ||
fieldsets = [ | ||
( | ||
None, | ||
{ | ||
"fields": ( | ||
"container_identifier", | ||
("modal_centered"), | ||
("modal_static", "modal_scrollable"), | ||
("modal_size", "modal_fullscreen"), | ||
) | ||
} | ||
), | ||
] | ||
|
||
|
||
@plugin_pool.register_plugin | ||
class ModalInnerPlugin( | ||
mixin_factory("ModalInner"), | ||
CMSUIPlugin, | ||
): | ||
""" | ||
Component > "Modal Container" Plugin | ||
https://getbootstrap.com/docs/5.0/components/modal/ | ||
""" | ||
name = _("Modal inner") | ||
module = _("Frontend") | ||
model = models.ModalInner | ||
form = forms.ModalInnerForm | ||
allow_children = True | ||
parent_classes = [ | ||
"ModalContainerPlugin", | ||
] | ||
|
||
fieldsets = [ | ||
( | ||
None, | ||
{ | ||
"fields": ( | ||
"inner_type", | ||
"attributes", | ||
) | ||
}, | ||
), | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
MODAL_CENTERED_CHOICES = ( | ||
("modal-dialog-centered", _("Vertically centered")), | ||
("modal-dialog-centered modal-dialog-scrollable", _("Vertically centered scrollable")), | ||
) | ||
|
||
MODAL_SIZE_CHOICES = ( | ||
("modal-sm", _("Small")), | ||
("modal-lg", _("Large")), | ||
("modal-xl", _("Extra Large")), | ||
) | ||
|
||
MODAL_FULLSCREEN_CHOICES = ( | ||
("modal-fullscreen", _("Allways")), | ||
("modal-fullscreen-sm-down", _("Fullscreen below sm")), | ||
("modal-fullscreen-md-down", _("Fullscreen below md")), | ||
("modal-fullscreen-lg-down", _("Fullscreen below lg")), | ||
("modal-fullscreen-xl-down", _("Fullscreen below xl")), | ||
("modal-fullscreen-xxl-down", _("Fullscreen below xxl")), | ||
) | ||
|
||
MODAL_INNER_TYPE_CHOICES = ( | ||
("modal-body", _("Body")), | ||
("modal-header", _("Header")), | ||
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
from django import forms | ||
from django.utils.translation import gettext_lazy as _ | ||
from entangled.forms import EntangledModelForm | ||
|
||
from ... import settings | ||
from ...fields import AttributesFormField, ButtonGroup, TagTypeFormField | ||
from ...helpers import first_choice | ||
from ...models import FrontendUIItem | ||
from .. import modal | ||
from .constants import ( | ||
MODAL_CENTERED_CHOICES, | ||
MODAL_FULLSCREEN_CHOICES, | ||
MODAL_INNER_TYPE_CHOICES, | ||
MODAL_SIZE_CHOICES, | ||
) | ||
|
||
# TODO leaving this comment for now | ||
# data-bs-toggle="modal" data-bs-target="#modalExample" | ||
# aria-expanded="false" aria-controls="modalExample"> | ||
# data-bs-target can also be classes | ||
# data-bs-parent links to the wrapper modal | ||
# <div class="modal" id="modalExample"> | ||
|
||
mixin_factory = settings.get_forms(modal) | ||
|
||
|
||
class ModalForm(mixin_factory("Modal"), EntangledModelForm): | ||
""" | ||
Component > "Modal" Plugin | ||
https://getbootstrap.com/docs/5.0/components/modal/ | ||
""" | ||
|
||
class Meta: | ||
model = FrontendUIItem | ||
entangled_fields = { | ||
"config": [ | ||
"modal_siblings", | ||
"attributes", | ||
] | ||
} | ||
untangled_fields = ("tag_type",) | ||
|
||
modal_siblings = forms.CharField( | ||
label=_("Siblings"), | ||
initial=".card", | ||
required=False, | ||
help_text=_("Element to be used to create accordions."), | ||
) | ||
attributes = AttributesFormField() | ||
tag_type = TagTypeFormField() | ||
|
||
|
||
class ModalTriggerForm(mixin_factory("ModalTrigger"), EntangledModelForm): | ||
""" | ||
Component > "Modal Trigger" Plugin | ||
https://getbootstrap.com/docs/5.0/components/modal/ | ||
""" | ||
|
||
class Meta: | ||
model = FrontendUIItem | ||
entangled_fields = { | ||
"config": [ | ||
"trigger_identifier", | ||
"attributes", | ||
] | ||
} | ||
untangled_fields = ("tag_type",) | ||
|
||
trigger_identifier = forms.SlugField( | ||
label=_("Unique identifier"), | ||
required=True, | ||
help_text=_("Identifier to connect trigger with container."), | ||
) | ||
attributes = AttributesFormField() | ||
tag_type = TagTypeFormField() | ||
|
||
|
||
class ModalContainerForm(mixin_factory("ModalContainer"), EntangledModelForm): | ||
""" | ||
Component > "Modal Container" Plugin | ||
https://getbootstrap.com/docs/5.0/components/modal/ | ||
""" | ||
|
||
class Meta: | ||
model = FrontendUIItem | ||
entangled_fields = { | ||
"config": [ | ||
"container_identifier", | ||
"attributes", | ||
"modal_centered", | ||
"modal_static", | ||
"modal_scrollable", | ||
"modal_size", | ||
"modal_fullscreen", | ||
] | ||
} | ||
untangled_fields = ("tag_type",) | ||
|
||
container_identifier = forms.SlugField( | ||
label=_("Unique identifier"), | ||
required=True, | ||
help_text=_("Identifier to connect trigger with container."), | ||
) | ||
|
||
modal_centered = forms.ChoiceField( | ||
label=_("Centered"), | ||
choices=settings.EMPTY_CHOICE + MODAL_CENTERED_CHOICES, | ||
required=False, | ||
) | ||
|
||
modal_static = forms.BooleanField( | ||
label=_("Static"), | ||
required=False, | ||
help_text=_("Disable scrolling in the container."), | ||
mavoIn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
modal_scrollable = forms.BooleanField( | ||
label=_("Scrollable"), | ||
required=False, | ||
help_text=_("Enable scrolling in the container."), | ||
) | ||
|
||
modal_size = forms.ChoiceField( | ||
label=_("Size"), | ||
choices=settings.EMPTY_CHOICE + MODAL_SIZE_CHOICES, | ||
required=False, | ||
) | ||
|
||
modal_fullscreen = forms.ChoiceField( | ||
label=_("Fullscreen"), | ||
choices=settings.EMPTY_CHOICE + MODAL_FULLSCREEN_CHOICES, | ||
required=False, | ||
) | ||
|
||
attributes = AttributesFormField() | ||
tag_type = TagTypeFormField() | ||
|
||
|
||
class ModalInnerForm(mixin_factory("ModalInner"), EntangledModelForm): | ||
""" | ||
Component > "Modal Container" Plugin | ||
https://getbootstrap.com/docs/5.0/components/modal/ | ||
""" | ||
|
||
class Meta: | ||
model = FrontendUIItem | ||
entangled_fields = { | ||
"config": [ | ||
"inner_type", | ||
] | ||
} | ||
untangled_fields = ("tag_type",) | ||
|
||
inner_type = forms.ChoiceField( | ||
label=_("Type"), | ||
choices=settings.EMPTY_CHOICE + MODAL_INNER_TYPE_CHOICES, | ||
required=True, | ||
) | ||
|
||
inner_type = forms.ChoiceField( | ||
label=_("Inner type"), | ||
choices=MODAL_INNER_TYPE_CHOICES, | ||
initial=first_choice(MODAL_INNER_TYPE_CHOICES), | ||
help_text=_("Define the structure of the plugin."), | ||
widget=ButtonGroup(attrs=dict(label_class="btn-secondary")), | ||
) | ||
attributes = AttributesFormField() |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class ModalRenderMixin: | ||
render_template = "djangocms_frontend/bootstrap5/modal.html" | ||
|
||
|
||
class ModalContainerRenderMixin: | ||
render_template = "djangocms_frontend/bootstrap5/modal-container.html" | ||
|
||
def render(self, context, instance, placeholder): | ||
return super().render(context, instance, placeholder) | ||
|
||
|
||
class ModalInnerRenderMixin: | ||
render_template = "djangocms_frontend/bootstrap5/modal-inner.html" | ||
|
||
def render(self, context, instance, placeholder): | ||
instance.add_classes(instance.inner_type) | ||
return super().render(context, instance, placeholder) | ||
|
||
|
||
class ModalTriggerRenderMixin: | ||
render_template = "djangocms_frontend/bootstrap5/modal-trigger.html" |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.