Inspired by Apple's summary slides and bento.me
<script type="module">
import BentoGrid from "https://cdn.jsdelivr.net/npm/@bentogrid/core@1.1.1/BentoGrid.min.js";
</script>
npm i @bentogrid/core
import BentoGrid from "@bentogrid/core";
<div class="bentogrid">
<div data-bento="1x1"></div>
<div data-bento="2x2"></div>
<div data-bento="2x1"></div>
<!-- Add elements or fillers -->
</div>
const myBento = new BentoGrid({
// Add configuration options
});
data-bento="2x3"
.
data-bento
attribute. They
are automatically cloned in a loop.
divs
will be created.
.bento-filler
when they are visible so
you can style them individually.
In this example fillers are automatically created, but they are not styled and therefore invisible.
#bentogrid > *[data-bento] {
@apply bg-sand-200;
}
In this example, fillers are automatically created and styled via CSS.
#bentogrid > * {
@apply bg-sand-200;
}
#bentogrid .bento-filler {
@apply bg-black;
}
<div id='bentogrid'>
<div data-bento='2x2'></div>
...
<div class='bg-water-300'></div>
<div class='bg-water-600'></div>
<div class='bg-water-900'></div>
</div>
target
string | HTMLElement
'.bentogrid'
In this example the element with the ID `bentogrid-config-target` is targeted to initialize BentoGrid.
new BentoGrid({
target: "#bentogrid-config-target",
cellGap: 6,
columns: 8,
aspectRatio: 1,
});
As an alternative you can also pass the element directly to the `target` option.
new BentoGrid({
target: document.getElementById("bentogrid-config-target-element"),
cellGap: 6,
columns: 8,
aspectRatio: 1,
});
cellGap
number
0
In this example the cellGap is set to 24
.
new BentoGrid({
cellGap: 24,
target: "#bentogrid-config-cell-gap",
columns: 8,
aspectRatio: 1,
});
aspectRatio
number
1/1
In this example the cellGap is set to 9 / 16
, which means that
a single cell in the grid has a ratio of 9 / 16
. An element
taking up 2 columns and 1 row will have a ratio of about 18 / 16
.
new BentoGrid({
aspectRatio: 9 / 16,
cellGap: 6,
target: "#bentogrid-config-aspect-ratio,
columns: 8,
});
balanceFillers
boolean
new BentoGrid({
balanceFillers: true,
cellGap: 6,
target: "#bentogrid-config-balance-fillers,
aspectRatio: 1,
columns: 8,
});
minCellWidth
number
new BentoGrid({
minCellWidth: 50,
balanceFillers: true,
cellGap: 6,
target: "#bentogrid-config-min-cell-width,
aspectRatio: 1
});
columns
number
new BentoGrid({
columns: 5,
balanceFillers: true,
cellGap: 6,
target: "#bentogrid-config-columns,
aspectRatio: 1,
});
breakpoints
Object.<number, Breakpoint>
breakpointReference
string
'target'
cellGap
number
aspectRatio
number
minCellWidth
number
columns
number
Hint: Further documentation is coming soon.