I am trying to wrap components in a Salesforce Lightning tab. It seems like a fairly simple task. I want items (which are dynamically created lightning components) to be arranged in (for example) four columns on normal computer screens, and if someone shrinks the window (or loads the tab on mobile), the number of columns should be reduced, and all elements should rearrange themselves to adapt to the smaller number of columns.
I've looked at trying this with a grid, but but there doesn't seem to be an obvious way of changing the row and column of the dynamic elements.
EDIT: added my current code below.
Here is the way I am currently trying to do this. Here is the .cmp file:
<aura:component implements="force:appHostable">
<lightning:button label="Get posts" onclick="{!c.handleComponent}"/>
<div>
{!v.body}
</div>
</aura:component>
And here is the actual create components step in the Javascript controller code:
$A.createComponent(
"c:dsPostViewer",
{
"itemTitle": post.title,
"itemImageUrl": img,
"itemContent": post.content,
"float": "left",
"margin": "20px 0"
},
function(newInp, status, errorMessage){
if (status === "SUCCESS") {
var body = component.get("v.body");
body.push(newInp);
component.set("v.body", body);
}
else if (status === "INCOMPLETE") {
console.log("No response from server or client is offline.")
}
else if (status === "ERROR") {
console.log("Error: " + errorMessage);
}
}
);
As you can see, I'm first trying to do it by floating the components left, which appears to do nothing.