Usage
import { TileGroup } from 'nr1'
Examples
Basic tile group
<TileGroup> <Tile onClick={console.log}>Tile 1</Tile> <Tile onClick={console.log}>Tile 2</Tile> <Tile onClick={console.log}>Tile 3</Tile></TileGroup>
Tile group with small gap type
<TileGroup gapType={TileGroup.GAP_TYPE.SMALL}> <Tile onClick={console.log}>Tile 1</Tile> <Tile onClick={console.log}>Tile 2</Tile> <Tile onClick={console.log}>Tile 3</Tile></TileGroup>
Tile group with 3 columns
<TileGroup tileWidth="4fr"> {Array.from({ length: 12 }).map((_, index) => ( <Tile onClick={console.log}>Tile {index + 1}</Tile> ))}</TileGroup>
Tile group with custom tile width
<TileGroup tileWidth={120}> {Array.from({ length: 12 }).map((_, index) => ( <Tile onClick={console.log}>Tile {index + 1}</Tile> ))}</TileGroup>
Selectable tiles
<TileGroup selectionType={TileGroup.SELECTION_TYPE.SINGLE} tileWidth={120}> {Array.from({ length: 12 }).map((_, index) => ( <Tile onClick={console.log}>Tile {index + 1}</Tile> ))}</TileGroup>
Selectable tiles with default tile checked
<TileGroup defaultValue="tile-0" selectionType={TileGroup.SELECTION_TYPE.SINGLE} tileWidth={120}> {Array.from({ length: 12 }).map((_, index) => ( <Tile value={`tile-${index}`} onClick={console.log}> Tile {index + 1} </Tile> ))}</TileGroup>
Controlled selectable tiles
class MyComponent extends React.PureComponent { constructor() { super(...arguments); this.state = { checkedTile: 'tile-0', }; this._onChange = this._onChange.bind(this); } _onChange(evt, tileValue) { this.setState({ checkedTile: tileValue }); } render() { const { checkedTile } = this.state; return ( <TileGroup value={checkedTile} onChange={this._onChange} tileWidth={120} selectionType={TileGroup.SELECTION_TYPE.SINGLE} > {Array.from({ length: 12 }).map((_, index) => ( <Tile sizeType={Tile.SIZE_TYPE.SMALL} value={`tile-${index}`} key={index} onClick={console.log} > Tile {index + 1} </Tile> ))} </TileGroup> ); }}
Multi-select tiles
<TileGroup selectionType={TileGroup.SELECTION_TYPE.MULTIPLE} tileWidth={120}> {Array.from({ length: 12 }).map((_, index) => ( <Tile onClick={console.log}>Tile {index + 1}</Tile> ))}</TileGroup>
Controlled multi-select tiles
class MyComponent extends React.PureComponent { constructor() { super(...arguments); this.state = { checkedTiles: [], }; this._onChange = this._onChange.bind(this); } _onChange(evt, tileValue, checked) { this.setState((state) => { return { checkedTiles: checked ? [...state.checkedTiles, tileValue] : state.checkedTiles.filter((value) => value !== tileValue), }; }); } render() { const { checkedTiles } = this.state; return ( <TileGroup value={checkedTiles} onChange={this._onChange} tileWidth={120} selectionType={TileGroup.SELECTION_TYPE.MULTIPLE} > {Array.from({ length: 12 }).map((_, index) => ( <Tile sizeType={Tile.SIZE_TYPE.SMALL} value={`tile-${index}`} key={index} onClick={console.log} > Tile {index + 1} </Tile> ))} </TileGroup> ); }}
Props
REQUIREDnode | Tiles to display. |
string | Appends class names to the component.Should be used only for positioning and spacing purposes. |
string|number|string[]|number[] | The initial tile that should be checked. |
enum | Size of the gap between tiles. |
function | Function called when a tile is checked or unchecked. function ( |
enum | <One of |
enum[] | Spacing property. Spacing is defined as a tuple of zero to four values, which follow the same conventions as CSS properties like <Array of |
object | Inline style for custom styling.Should be used only for positioning and spacing purposes. |
string | Adds a Note: You might not see |
string|number | Represents the width of the columns. Columns always have the same width. It can be one of the following types:
|
string|number|string[]|number[] | The tile or tiles with the matching value will be checked. Can be a single value or an array of values when the selection type is |