npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@atrox/react-hexagon

v1.2.1

Published

React component that renders a hexagon using SVG

Downloads

11

Readme

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.

  • className - Class name of SVG element.
  • href - Link target, if any. Hexagon will only be wrapped in an anchor if this is set.
  • target - Target of link. Same role as in regular HTML.
  • flatTop - Switches hexagon style to have a flat top (basically, rotate the hexagon by 90°). Default: false
  • backgroundImage - URL to a background image. Recommend that the image has the same aspect ratio as a hexagon. See background sizing notes below.
  • style - Styles for the hexagon element.
  • children - Children nodes to put inside SVG element.
  • hexProps - Arbitrary properties to apply to the hexagon element (the actual polygon, not the outer SVG). Useful to apply event listeners, class names or similar.
  • diagonal - Size of diagonal. Affects sizing of elements within the SVG, and can usually be left as-is. Instead, scale the SVG element using CSS width/height. Default: 500

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):

  • backgroundScale - Used to upscale the image, usually in order to fill the entire hexagon if the aspect ratio does not match. 0.5 mean scale to 50% of the hexagon, 1.5 means scale to 150%. For square images, 1.05 is usually a good number to use.
  • backgroundWidth / backgroundHeight - Used to manually adjust the size of the background image.
  • backgroundSize - Can be used if the image has a square ratio.

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

License

Licensed under the MIT License, see LICENSE