-
Notifications
You must be signed in to change notification settings - Fork 617
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(app-page-builder): sort properties as defined in the element plugin
- Loading branch information
Showing
4 changed files
with
47 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
40 changes: 38 additions & 2 deletions
40
packages/app-page-builder/src/editor/defaultConfig/Sidebar/StyleSettings/StyleProperties.tsx
This file contains 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 |
---|---|---|
@@ -1,6 +1,42 @@ | ||
import React from "react"; | ||
import React, { useMemo } from "react"; | ||
import { ElementProperties, ElementProperty } from "~/editor/config/ElementProperty"; | ||
import { useElementPlugin } from "~/editor/contexts/EditorPageElementsProvider/useElementPlugin"; | ||
import { useActiveElement } from "~/editor"; | ||
import { Element } from "@webiny/app-page-builder-elements/types"; | ||
import { getPropertyName } from "../BackwardsCompatibility/StyleSettingsAdapter"; | ||
|
||
export const StyleProperties = () => { | ||
return <ElementProperties group={ElementProperty.STYLE} />; | ||
const [element] = useActiveElement<Element>(); | ||
if (!element) { | ||
return null; | ||
} | ||
|
||
return <ElementStyleProperties element={element} />; | ||
}; | ||
|
||
const ElementStyleProperties = ({ element }: { element: Element }) => { | ||
const plugin = useElementPlugin(element); | ||
if (!plugin) { | ||
return null; | ||
} | ||
|
||
const names = (plugin.settings || []) as string[] | string[][]; | ||
|
||
const settings = useMemo(() => { | ||
return names | ||
.map(config => (Array.isArray(config) ? config[0] : config)) | ||
.filter(name => name.startsWith("pb-editor-page-element-style-settings-")) | ||
.map(name => getPropertyName(name)); | ||
}, [element.type]); | ||
|
||
return ( | ||
<ElementProperties | ||
group={ElementProperty.STYLE} | ||
transform={elements => { | ||
return ["property", ...settings] | ||
.map(name => elements.find(element => element.name === name)) | ||
.filter(Boolean) as typeof elements; | ||
}} | ||
/> | ||
); | ||
}; |