1.0.2 • Published 5 years ago

tiled-hexagons v1.0.2

Weekly downloads
25
License
MIT
Repository
github
Last release
5 years ago

Tiled Hexagons

tiled-hexagons is a simple React button component set to help you render one or more multiple tessellated hexagon buttons.

Live Demo

Check out the live demo for usage examples!

Installation

npm install tiled-hexagons

Importing

//ES6 import
import { Hexagon, TiledHexagons } from 'tiled-hexagons'

OR

//CommonJS
const { Hexagon, TiledHexagons } from 'tiled-hexagons'

Basic Usage

<Hexagon/>

import { Hexagon } from 'tiled-hexagons'

//function that returns a simple hexagon button
const simpleButton = () => {
  return (
    <Hexagon
      sideLength={40}
      text="Hi"
      textStyle={{ fill: 'blue' }}
    />
  )
}

<TiledHexagons/>

import { TiledHexagons } from 'tiled-hexagons'

//function that returns simple tiled hexagon buttons
const simpleTiled = () => {
  return (
    <TiledHexagons
      tileSideLengths={40}
      tileTextStyles={{ fill: 'blue' }}
      tiles={[
        { text="Hi 1" },
        { text="Hi 2" },
        { text="Hi 3" }
      ]}
    />
  )
}

For more usage examples check out the live demo.

Props

<Hexagon/>

PropTypeDefaultDescription
sideLengthnumber100Length in pixels for each side of the hexagon
borderRadiusnumber12Radius of curvature for each corner of the hexagon
fillstringwhiteColour to fill the hexagon with (use standard CSS conventions)
⚠️strokestring#bbbOutline colour for the hexagon
⚠️strokeWidthnumber0Thickness of the outline
elevationnumber12Elevation of the hexagon in pixels
shadowstring#e2e2e2Colour of the shadow created by the elevation
imgstringURL to an image to be displayed (square-ish images work best)
textstringText to be displayed in the hexagon (font sizes similar to the side length work best)
textStyleobject{}Style to be applied to the text (use fill for text colour)
stylesobject{}Custom styles to be applied to the hexagon
hrefstringLink to be opened when hexagon is clicked
targetstringSpecifies where to open the href, one of _blank self _parent _top framename
onClickfunctionFunction to be called when the hexagon is clicked

<TiledHexagons/>

PropTypeDefaultDescription
tileSideLengthsnumber100Side length of each hexagon in the grid
tileBorderRadiinumber12Border radius of each hexagon in the grid
tileElevationsnumber12Elevation of each hexagon in the grid
⚠️tileStrokeWidthsnumber0Stroke width of each hexagon in the grid
tileGapnumber4Spacing in pixels between each adjacent hexagon
tileStylesobject{}Styling to be applied to all hexagons
tileTextStylesobject{}Styling to be applied to the text of all hexagons
maxHorizontalnumber5Maximum number of horizontals in a row
tilesarray[]Array of tile data objects to be used to generate hexagons

⚠️ currently experimental and may not work as intended

tile data objects

Not all properties of <Hexagon/> are to be placed into a tile data object to be used in <TiledHexagons/>. The properties that DO carry over and should be placed into a tile data object are: fill stroke shadow img text textStyle styles href target onClick.

tileStyles and tileTextStyles apply a general styling to all hexagons, however, they can be overwritten by individual hexagons using textStyle and styles.

Custom Styling

To customise a hexagon with CSS, pass through a textStyle or styles prop. The styles prop is an object consisting of 3 objects: normal hover and active. The styles defined in each of these 3 objects are applied when the hexagon is in it's normal state, hover state and active state respectively. For example, to make a yellow hexagon turn green when hovered and blue when clicked, you would pass the following object in the styles prop.

{
  normal: {
    fill: 'yellow'
  },
  hover: {
    fill: 'green'
  },
  active: {
    fill: 'blue'
  }
}