Skip to content

React ​

bash
npm install @andamento/core @andamento/react

<TileLayout>: any content, clipped to the tiles ​

tsx
import { TileLayout, coverStyle } from "@andamento/react";
import { hexagonal } from "@andamento/core";

<TileLayout
  options={{ region: { x: 0, y: 0, width: 240, height: 150 }, tiling: hexagonal({ size: 26 }), gap: 2 }}
  background="#f4f1ea"
>
  <img src="beach.jpg" alt="" style={coverStyle} />
  <video src="clip.mp4" autoPlay muted loop style={coverStyle} />
  <Card title="Anything" />
  <button onClick={…}>Clickable</button>
</TileLayout>
  • Children: each top-level child fills one tile, in reading order. null and false children are skipped, and children beyond the number of tiles aren't rendered.
  • Tiles: absolutely positioned <div>s with a CSS clip-path, sized in percentages, so the layout scales with its container's width. Its height follows from aspect-ratio.
  • Pointer events: clipping applies to them too, so hover and clicks follow the tile shapes.
  • State: children keep their state (a video's position, a form's input) when the layout options change. Give them keys.
  • Server rendering: tiles render in place, with nothing to measure (except with virtualize).

Props ​

Prop
optionsLayout options, as for createLayout. Or pass layout.
layoutA layout made already (e.g. with useTileLayout).
childrenOne per tile, in reading order.
renderCell(cell, { slot })Render each tile from its cell instead of children.
contentCellsWhich tiles take children: "all", "whole" or a test. More
placement"reading", "center" or "spread". More
fitSize the tiles to the number of children: true, "atLeast" or "nearest".
aspectsWidth / height of each child, to match it to a tile of its shape. More
chooseWith aspects: "shape" also chooses which tiles get content.
safeAreatrue, "tile" or "visible": put content in the largest rectangle inside each tile.
focalPoints{ x, y, aspect? } per child: what to keep in view.
weightsTiles each child spans. More
fillColor of empty tiles: a color, palette or function. Defaults to neutralPalette.
fallbackWhat to render in empty tiles (fixed, or per cell).
backdropOne element shown across all the tiles. More
backgroundThe grout: any CSS background.
reliefRaised tiles: true or { bevel, light, strength, shadow, … }.
navigableArrow-key navigation, one tab stop. More
onCellActivate(cell, { slot, empty })Enter, Space or a click on a tile.
cellLabelAccessible name per tile.
focusRingFocus ring color, or false to style it yourself.
animatetrue or { duration, easing }. More
virtualizetrue or { overscan }. More
cellClassName, cellStylePer tile, fixed or a function (cell, { empty, slot }).
Any <div> attributeclassName, style, aria-label, onPointerMove, … go on the layout element.

Tile wrappers carry data-cell-id, data-empty and data-boundary; the layout carries data-andamento.

<SvgTileLayout>: a single <svg> ​

Use it when you need a single <svg>: to export, print or embed. It takes the options of renderToString as props: images, imageAspects, imageFit, imageFocus, imageWeights, imageAlts, fill, stroke, strokeWidth, relief, backdrop, background, title, contentCells, placement, choose, fit. renderCell(cell, ctx) renders SVG per cell, with ctx.path, ctx.clipPath, ctx.fill, ctx.image and ctx.slot. <SvgCellImage cell href /> draws an image clipped to a cell.

tsx
<SvgTileLayout options={options} images={photos} imageAspects={aspects} relief title="Photos" />

Hooks ​

Hook
useTileLayout(options)A layout, worked out again only when the options change by value.
useFitCount(options, count, fit)A layout sized to count items.
useImageAspects(srcs)Loads images and returns their width / height.
useImageFocus(srcs)Loads images and guesses each one's focal point (estimateFocus).
useImageFill(src, options)Loads an image and returns an imageFill for it.

cellFromPointer(layout, event, options) finds the cell under a pointer event; see Hit testing.

Hat tiling and isohedral tilings after Craig S. Kaplan's hatviz and Tactile (BSD 3-Clause).