Coder Social home page Coder Social logo

thatdudejbob / tiled-hexagons Goto Github PK

View Code? Open in Web Editor NEW

This project forked from josephsurin/tiled-hexagons

0.0 1.0 0.0 2.52 MB

๐Ÿ“ฆ๐Ÿ’ป Simple React single or tessellated 2D/3D hexagon buttons

Home Page: https://josephsurin.github.io/tiled-hexagons

License: MIT License

JavaScript 100.00%

tiled-hexagons's Introduction

Tiled Hexagons

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

NPM

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/>

Prop Type Default Description
sideLength number 100 Length in pixels for each side of the hexagon
borderRadius number 12 Radius of curvature for each corner of the hexagon
fill string white Colour to fill the hexagon with (use standard CSS conventions)
โš ๏ธstroke string #bbb Outline colour for the hexagon
โš ๏ธstrokeWidth number 0 Thickness of the outline
elevation number 12 Elevation of the hexagon in pixels
shadow string #e2e2e2 Colour of the shadow created by the elevation
img string URL to an image to be displayed (square-ish images work best)
text string Text to be displayed in the hexagon (font sizes similar to the side length work best)
textStyle object {} Style to be applied to the text (use fill for text colour)
styles object {} Custom styles to be applied to the hexagon
href string Link to be opened when hexagon is clicked
target string Specifies where to open the href, one of _blank self _parent _top framename
onClick function Function to be called when the hexagon is clicked

<TiledHexagons/>

Prop Type Default Description
tileSideLengths number 100 Side length of each hexagon in the grid
tileBorderRadii number 12 Border radius of each hexagon in the grid
tileElevations number 12 Elevation of each hexagon in the grid
โš ๏ธtileStrokeWidths number 0 Stroke width of each hexagon in the grid
tileGap number 4 Spacing in pixels between each adjacent hexagon
tileStyles object {} Styling to be applied to all hexagons
tileTextStyles object {} Styling to be applied to the text of all hexagons
maxHorizontal number 5 Maximum number of horizontals in a row
tiles array [] 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'
  }
}

tiled-hexagons's People

Contributors

josephsurin avatar dependabot[bot] avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.