Skip to content

Commit

Permalink
fix: css classes and visibility for CMS layout element (#460)
Browse files Browse the repository at this point in the history
* fix(helpers): merging visibility and classes

* feat(cms-base): use css classes and visibility on cms layout level

* chore: changeset
  • Loading branch information
mkucmus committed Nov 20, 2023
1 parent 543d18d commit 729d03a
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/curvy-games-unite.md
@@ -0,0 +1,5 @@
---
"@shopware-pwa/helpers-next": patch
---

Proper visibility and css classes merging
5 changes: 5 additions & 0 deletions .changeset/plenty-dancers-live.md
@@ -0,0 +1,5 @@
---
"@shopware-pwa/cms-base": patch
---

Apply visibility and css classes for CMS layout
2 changes: 1 addition & 1 deletion packages/cms-base/components/public/cms/CmsPage.vue
Expand Up @@ -45,7 +45,7 @@ const DynamicRender = () => {
return h(componentObject.component, {
content: componentObject.section,
class: {
[cssClasses ?? ""]: true,
...cssClasses,
"max-w-screen-2xl mx-auto": layoutStyles?.sizingMode === "boxed",
},
style: {
Expand Down
@@ -1,13 +1,16 @@
<script setup lang="ts">
import type { CmsSectionDefault } from "@shopware-pwa/composables-next";
import { getCmsLayoutConfiguration } from "@shopware-pwa/helpers-next";
defineProps<{
const props = defineProps<{
content: CmsSectionDefault;
}>();
const { cssClasses, layoutStyles } = getCmsLayoutConfiguration(props.content);
</script>

<template>
<div class="cms-section-default">
<div class="cms-section-default" :class="cssClasses" :styles="layoutStyles">
<CmsGenericBlock
v-for="cmsBlock in content.blocks"
class="overflow-auto"
Expand Down
20 changes: 16 additions & 4 deletions packages/helpers/src/cms/getCmsLayoutConfiguration.ts
Expand Up @@ -19,7 +19,9 @@ export type LayoutConfiguration = {
marginRight?: string | null | undefined;
marginTop?: string | null | undefined;
};
cssClasses: string | null;
cssClasses: {
[cssClass: string]: boolean;
} | null;
};

// predicate types
Expand Down Expand Up @@ -94,11 +96,21 @@ export function getCmsLayoutConfiguration(
layoutStyles: {},
} as LayoutConfiguration;
}

const visibilityCssClasses = getVisibilityClasses(content);
// convert css classes string into object in format { "css-class-name": true }
const mappedCssClasses =
typeof content.cssClass === "string"
? {
...content.cssClass.split(" ").reduce((accumulator, cssClass) => {
return { ...accumulator, [cssClass]: true };
}, {}),
}
: {};

// append visibility classes to the css classes object
const cssClasses = Object.keys(visibilityCssClasses).length
? Object.assign({}, content.cssClass, visibilityCssClasses)
: content.cssClass;
? Object.assign({}, mappedCssClasses, visibilityCssClasses)
: mappedCssClasses;

return {
cssClasses,
Expand Down

2 comments on commit 729d03a

@vercel
Copy link

@vercel vercel bot commented on 729d03a Nov 20, 2023

Choose a reason for hiding this comment

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

@vercel
Copy link

@vercel vercel bot commented on 729d03a Nov 20, 2023

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

frontends-demo – ./templates/vue-demo-store

frontends-demo-shopware-frontends.vercel.app
frontends-demo.vercel.app
frontends-demo-git-main-shopware-frontends.vercel.app

Please sign in to comment.