Skip to content

Commit

Permalink
feat: add editable padding to menu plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelzinh3 committed Jun 5, 2024
1 parent 73598cf commit 1febe79
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 8 additions & 0 deletions app/contrib/ds/cms_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,14 @@ def render(self, context, instance, placeholder):
if gap_mobile:
ul_styles_mobile.append(f"gap:{gap_mobile}rem")

padding_top = attributes.get("padding_top")
if padding_top:
css_styles.append(f"padding-top:{padding_top}rem;")

padding_bottom = attributes.get("padding_bottom")
if padding_bottom:
css_styles.append(f"padding-bottom:{padding_bottom}rem;")

context["css_styles"] = ";".join(css_styles)
context["ul_styles"] = ";".join(ul_styles)
context["ul_styles_mobile"] = ";".join(ul_styles_mobile)
Expand Down
14 changes: 9 additions & 5 deletions app/contrib/ds/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from .models import Menu

GAP_CHOICES = [
SPACING = [
("0", "0"),
("1", "1"),
("2", "2"),
Expand All @@ -17,20 +17,24 @@
("auto", "auto"),
]

class GapFormMixin(EntangledModelFormMixin):
gap = forms.ChoiceField(choices=GAP_CHOICES, required=False)
gap_mobile = forms.ChoiceField(choices=GAP_CHOICES, required=False)
class SpacingFormMixin(EntangledModelFormMixin):
gap = forms.ChoiceField(choices=SPACING, required=False)
gap_mobile = forms.ChoiceField(choices=SPACING, required=False)
padding_top = forms.ChoiceField(choices=SPACING, required=False)
padding_bottom = forms.ChoiceField(choices=SPACING, required=False)

class Meta:
untangled_fields = ["color"]
entangled_fields = {
"attributes": [
"gap",
"gap_mobile",
"padding_top",
"padding_bottom"
]
}

class MenuForm(GapFormMixin, forms.ModelForm):
class MenuForm(SpacingFormMixin, forms.ModelForm):
class Meta:
model = Menu
fields = "__all__"

0 comments on commit 1febe79

Please sign in to comment.