diff --git a/packages/sdk-components-react/src/xml-node.stories.tsx b/packages/sdk-components-react/src/xml-node.stories.tsx new file mode 100644 index 000000000000..75bc0e256acc --- /dev/null +++ b/packages/sdk-components-react/src/xml-node.stories.tsx @@ -0,0 +1,38 @@ +import { ReactSdkContext } from "@webstudio-is/react-sdk/runtime"; +import { XmlNode } from "./xml-node"; + +const Component = () => { + return ( + src, + resources: {}, + }} + > + + + Hi All Hi All Hi All Hi AllHi AllHi All Hi AllHi AllHi All + + + + + ); +}; + +export default { + title: "Components/XmlNode", +}; + +const Story = { + render() { + return ( + <> + + + ); + }, +}; + +export { Story as XmlNode }; diff --git a/packages/sdk-components-react/src/xml-node.tsx b/packages/sdk-components-react/src/xml-node.tsx index 8619c0ecf097..8e9e781d614f 100644 --- a/packages/sdk-components-react/src/xml-node.tsx +++ b/packages/sdk-components-react/src/xml-node.tsx @@ -57,29 +57,44 @@ export const XmlNode = forwardRef, Props>( childrenArray.length > 0 && childrenArray.every((child) => typeof child === "string"); - const attributes = attributeEntries.map( - ([key, value]) => `${key}=${JSON.stringify(value)}` - ); + const renderAttributes = (attrs: [string, string][]) => { + return attrs.map(([name, value], index) => { + return ( + + {" "} + {name} + = + "{value}" + + ); + }); + }; return (
- - <{[elementName, ...attributes].join(" ")}> + + <{elementName} + {attributeEntries.length > 0 && renderAttributes(attributeEntries)} + {childrenArray.length === 0 ? ( + /> + ) : ( + > + )} {childrenArray.length > 0 && ( -
- {children} -
+ <> +
+ {children} +
+ </{elementName}> + )} - - </{elementName}> -
); }