rexxars / react-hexagon

React component that renders a hexagon using SVG. Supports background images, links, SVG content, click handlers and more.
http://rexxars.github.io/react-hexagon/
MIT License
69 stars 21 forks source link

react-hexagon

react-hexagon

React component that renders a hexagon using SVG. Supports background images, links, SVG content, click handlers... Stylable with CSS.

Demos

See the demos page for some demos.

Installation

react-hexagon can be installed using npm:

npm install --save react-hexagon

Size of component is about ~1.5kB after gzip.

Basic usage

import React from 'react'
import Hexagon from 'react-hexagon'

React.render(
  <Hexagon
    style={{stroke: '#42873f'}}
    backgroundImage="img/red-panda.jpg"
    href="http://espen.codes/"
  />,
  document.getElementById('root')
);

Props

All properties are optional.

Background sizing

Sizing and aligning the background image can be slightly tricky. We recommend that you try to stick with images that has the same aspect ratio as a hexagon, or square images that can be slightly scaled.

By default, if you give the hexagon element a background image with a different aspect ratio, it'll try to center the image horizontally/vertically while maintaining the original image aspect ratio. For square images, this means you'll end up with a small border. If you instead want to upscale the image to fill the hexagon, use the backgroundScale property (see below).

Background sizing properties are resolved in the following order (first one defined wins):

Note: backgroundWidth, backgroundHeight and backgroundSize are relative to the diagonal, which defaults to 500.

License

Licensed under the MIT License, see LICENSE