Tile Group

Tiles of any size on a grid, reordered by dragging while the others make room.

Tile Group follows the Start screen of Windows 8. Tiles of any size sit on a grid of cells. You drag a tile to a new place and the other tiles move out of its way.

ax-tile comes from @ax-design/tile, and is an ax-surface, so the layers, shapes and tilt of Surface work on it. A tile has a 2px border for the reveal light out of the box; any style of yours wins over it. A group lays out any children and reads the columns and rows of each one.

A tile is pressed only when it has an action: a link or a button in its light DOM with slot="action". Only then does it tilt and light up, and its action runs once the press has been seen (see the Tile page at /components/tile/). Most examples below have no action, so their tiles are static: they show the layout and the dragging, and nothing more. In the examples the cells are small, so a group fits next to this text.

The group also plays an entrance and a launch. The Start screen of the lab (/lab/start/) is built from tile groups in a boundary, with launches.

Installation

shell
npm install @ax-design/tile-group

and import it:

js
import { register } from '@ax-design/tile-group';
import { register as registerTile } from '@ax-design/tile';
register();
registerTile();

If you don't use a bundler, load the script instead:

html
<script src="https://unpkg.com/@ax-design/tile-group/build/main.js"></script>
<script>AxTileGroup.register();</script>
Apple

Tile sizes

The columns and rows attributes give the size of a tile in cells. A medium tile is two by two cells, which is also the size of any other element in the group that has no attributes.

Change the size of the first tile and the other tiles move. The order of the children is the order of the tiles: each tile takes the first free place after the one before it.

Try it

html
<ax-tile-group>
  <ax-tile columns="4" rows="2" layers="fill reveal">Apple</ax-tile>
  <ax-tile columns="2" rows="2" layers="fill reveal">Tea</ax-tile>
  <ax-tile columns="1" rows="1" layers="fill reveal"></ax-tile>
</ax-tile-group>
Apple

Cell size and gap

A cell is a small tile. Its size and the gap between cells are custom properties. The defaults are 70px and 10px; the group here uses much less.

The size of a tile is its cells plus the gaps between them, so a medium tile is two cells and one gap wide.

Try it

24 px
24 px
4 px
css
ax-tile-group {
  --tile-cell-width: 24px;
  --tile-cell-height: 24px;
  --tile-gap: 4px;
}
Apple

Rows and strips

A horizontal group has a fixed number of rows and grows to the right, like the Start screen. Fewer rows make a longer group.

The strip decides the order in which tiles fill the group. 4 fills columns four cells wide, row by row, so two medium tiles sit side by side. 1 fills column by column, top to bottom, as WinJS does; tiles jump around much more while you drag.

Try it

4
html
<ax-tile-group strip="4">...</ax-tile-group>
css
ax-tile-group {
  --tile-rows: 4;
}
Apple

Dragging

The drag attribute turns dragging on. With press, a tile follows the pointer as soon as it moves. With hold, it lifts after a press of hold-delay milliseconds, and a quick move scrolls the page instead. With cross-slide, it is the touch gesture of Windows 8 for a group in a horizontal scroller (see Scroll). Press Escape during a drag to put everything back.

The group fires events on the tile. Cancel tiledragstart to keep a tile in place, or cancel tilereorder to put it back.

Try it

500
html
<ax-tile-group drag="press" hold-delay="500" contextmenu>
  ...
</ax-tile-group>
js
group.addEventListener('tilereorder', (event) => {
  console.log(event.detail.from, event.detail.to);
});

group.addEventListener('tilecontextmenu', (event) => {
  // Show your own menu at event.detail.clientX, clientY.
});
Apple

Vertical group

With orientation="vertical" the group has a fixed number of columns and grows downward, like the groups of the Windows 10 Start menu. Use --tile-columns instead of --tile-rows. Everything else, dragging included, works the same.

In a vertical group the default strip is 2: it fills rows one medium tile tall, left to right.

Try it

6
html
<ax-tile-group orientation="vertical" drag="press">...</ax-tile-group>
css
ax-tile-group {
  --tile-columns: 6;
}

Entrance

Set --tile-entrance to desktop or mobile and the group plays an entrance the first time it comes into view. desktop is the entrance of the Windows 8 Start screen: the tiles enter in bands, each band growing and fading in. mobile is the turnstile of Windows Phone: each tile turns to face you.

Press Play to play it again: exit() plays the matching exit, and enter() plays the entrance once the exit is over. The controls below set the desktop entrance.

Try it

35 ms
0 ms
0.93
4
css
ax-tile-group {
  --tile-entrance: desktop;
  --tile-enter-stagger: 35ms;
  --tile-enter-delay: 0ms;
  --tile-enter-spread: 0.93;
  --tile-enter-band: 4;
}

@media (max-width: 600px) {
  ax-tile-group { --tile-entrance: mobile; }
}
js
await group.exit();
await group.enter();

Start screen boundary

Each group enters on its own by default, its bands growing about its own middle. Put groups in an ax-tile-bound and they enter as one: the bands of the second group go on from those of the first, and every band grows about the middle of all the groups.

The two groups here are small. They enter when the preview comes into view, and the boundary draws nothing itself.

html
<ax-tile-bound>
  <ax-tile-group>...</ax-tile-group>
  <ax-tile-group>...</ax-tile-group>
</ax-tile-bound>
css
ax-tile-bound {
  display: flex;
  --tile-entrance: desktop;
  --tile-enter-delay: 120ms;
}

Launch

When a tile is launched, the other tiles of every group shrink toward the middle of the screen and fade, as the Start screen of Windows does. The launched tile is left as it is, and the tiles come back when the launch ends.

The launch is the tile itself: see the Tile page (/components/tile/). This example holds the splash for 1.2 seconds, as an app does while it loads.

Try it

0.9
100 ms
html
<ax-tile class="app" layers="fill reveal">
  <a slot="action" href="/mail">Mail</a>
</ax-tile>
css
.app {
  --ax-tile-launch: flip;
}

ax-tile-group {
  --tile-launch-exit-scale: 0.9;
  --tile-launch-exit-duration: 100ms;
}
The preview in forced colors with a dark theme.The preview in forced colors with a light theme.

Accessibility

Keyboard: With drag set, Tab to the button of a tile, then hold Alt and Shift and press an arrow key. The tile moves to the next place in that direction, and holding the keys keeps it moving. Focus stays on the tile. Focus inside a group also ends its entrance at once.

Screen readers: After a move, the group says where the tile is in a live region, such as "Mail, moved to position 2 of 6". Set announce="off" to turn this off, or assign describeMove to word it in another language.

High contrast (forced colors): The group draws no color of its own. Its tiles follow the forced colors rules of Surface.

Reduced motion: enter() and exit() jump to their end state at once, and their promises resolve on the next frame.

Reduced transparency: The tiles are surfaces, so their reveal lights fall back as on the Surface page. Choose Fallback in the switch to see it live.

More contrast: Nothing changes by itself. The tiles follow the prefers-contrast rules of Surface.

Try it: in Chrome or Edge, open DevTools, then Rendering, and emulate the CSS media features prefers-reduced-motion, forced-colors or prefers-reduced-transparency. Or turn on the setting of your system: Show animations, Contrast themes and Transparency effects on Windows; Reduce motion, Increase contrast and Reduce transparency on macOS.

Try it

js
import { setAlwaysUseFallback } from '@ax-design/surface';

// Draw every effect with its solid fallback, as when transparency effects are off.
setAlwaysUseFallback(true);

Reference

columns attribute

<integer>, default 2

On a child of the group, usually an ax-tile: its width in cells. Change it and the other tiles move.

rows attribute

<integer>, default 2

On a child of the group: its height in cells.

drag attribute

press | hold | cross-slide | none, default none

On the group: how tiles are dragged. press follows the pointer at once, hold lifts after hold-delay, cross-slide is the Windows 8 touch gesture for a horizontal scroller.

hold-delay attribute

<number>, default 500

Milliseconds of a press before it counts as held.

contextmenu attribute

boolean

Fire tilecontextmenu on a right click, the context menu key, and a touch or pen press held for hold-delay milliseconds and released without moving. The group shows no menu.

orientation attribute

horizontal | vertical, default horizontal

horizontal: a fixed number of rows, the group grows to the right. vertical: a fixed number of columns, the group grows downward.

strip attribute

<integer>, default 4 (vertical: 2)

The order in which tiles fill the group. 4 fills columns four cells wide row by row, 1 fills column by column (WinJS). In a vertical group strips are rows.

grouping attribute

string

Reserved for dragging tiles onto each other to form groups. It fires no events yet.

--tile-cell-width, --tile-cell-height property

<length>, default 70px

The size of a cell, a small tile. A medium tile is two by two cells.

--tile-gap property

<length>, default 10px

The space between cells.

--tile-rows property

<number> | auto, default 6

The rows of cells in a horizontal group. With auto, the group takes as many rows as its height holds.

--tile-columns property

<number> | auto, default 6

The columns of cells in a vertical group. With auto, the group takes as many columns as its width holds.

--tile-drag-opacity property

<number>, default 0.65

The opacity of a dragged tile. It is inherited, so set it on the group or on one tile. Set it to 1 for tiles with acrylic or another backdrop-filter: an element with an opacity below 1 is a backdrop root, so the filter inside it sees nothing behind the tile and the glass turns clear while the tile is dragged.

tiledragstart event

CustomEvent

A drag starts. Fired on the tile, bubbles. Cancel it to keep the tile in place.

tilereorder event

CustomEvent<{ from, to }>

A tile was dropped at a new place. Cancel it to put the tile back.

tiledragend event

CustomEvent<{ from, to }>

The drag is over. from and to are equal when nothing moved.

tilecontextmenu event

CustomEvent<{ clientX, clientY, pointerType }>

pointerType is mouse, touch, pen or keyboard.

refresh() method

() => void

Reads the custom properties again, for changes nothing reports.

--tile-entrance property

desktop | mobile | none, default none

The entrance the group plays the first time it is visible, and on a restore after a launch. desktop is the Start screen of Windows 8, mobile the turnstile of Windows Phone. Inherited; a media query may switch it.

--tile-enter-band property

<integer>, default 4 (the strip)

The columns in a band of the desktop entrance. With orientation="vertical" it counts rows.

--tile-enter-spread property

<number>, default 0.93

Where the bands start, as a share of their distance from the middle of the viewport.

--tile-enter-offset property

<length>, default 1% of the width of the viewport

How much further to the right the bands of the desktop entrance start.

--tile-enter-duration property

<time>, default 530ms

The move of a band in the desktop entrance.

--tile-enter-easing property

<timing function>, default cubic-bezier(0.17, 0.55, 0.3, 0.95)

The curve of the move of a band.

--tile-enter-scale property

<number>, default 0.8

The scale a band starts at, before it grows to full size.

--tile-enter-scale-duration property

<time>, default 450ms

The growth of a band to its full size.

--tile-enter-scale-easing property

<timing function>, default cubic-bezier(0.1, 0.9, 0.2, 1)

The curve of the growth of a band.

--tile-enter-fade property

<time>, default 133ms

The fade in of a band. Linear.

--tile-enter-stagger property

<time>, default 35ms

The delay between two bands.

--tile-enter-delay property

<time>, default 0ms

The delay before the first band. In an ax-tile-bound, set it once on the boundary: it is inherited, and each group reads it as its own.

--tile-exit-duration property

<time>, default 200ms

The fade of the exit of the desktop entrance, which does not move.

--tile-turnstile-perspective property

<length>, default 1000px

The perspective of the turn of a tile in the mobile entrance.

--tile-turnstile-origin property

<length>, default 0px

How far to the left of the viewport's left edge the axis of the turn is. WinJS uses 40px.

--tile-turnstile-duration property

<time>, default 600ms

The turn of each tile in the mobile entrance.

--tile-turnstile-easing property

<timing function>, default cubic-bezier(0.22, 1, 0.36, 1)

The curve of the turn: easeOutQuint.

--tile-launch-exit-scale property

<number>, default 0.9

The scale the other tiles shrink to when a tile is launched.

--tile-launch-exit-duration property

<time>, default 100ms

The shrink and fade of the other tiles when a tile is launched.

enter(options?) method

({ variant?: desktop | mobile }) => Promise<void>

Plays the entrance by hand. Resolves when the last tile has arrived. variant overrides --tile-entrance; without it the property decides, and desktop is used when it is none.

exit(options?) method

({ variant?: desktop | mobile }) => Promise<void>

Plays the matching exit. Resolves when the last tile has gone. The tiles stay invisible until the next enter() or a re-layout.

ax-tile-bound attribute

element

Couples the groups inside it, at any depth, so that their desktop entrances run as one wave. It draws nothing and has no styles of its own.

tilelaunchstart event

CustomEvent

Fired by the launching tile (see the Tile page). The other tiles of every group shrink and fade. Cancel it and the launch stops.

tilelaunchend event

CustomEvent<{ reason }>

Fired by the launching tile when the launch is over. The groups restore the tiles at once, and play the entrance again when --tile-entrance sets a variant.