HTML Polygon for Vue 3

  • NPM package version
  • Lint with ESLint

Installation

Install the @html-polygon/vue NPM package:

# NPM
npm install @html-polygon/vue

# Yarn
yarn add @html-polygon/vue

# PNPM
pnpm add @html-polygon/vue

Then import the Polygon component into your Vue 3 project:

import { Polygon } from '@html-polygon/vue'

There are also “named” components available like: Pentagon, Hexagon, and Enneadecagon:

import { Pentagon, Enneadecagon } from '@html-polygon/vue'

These work just like the Polygon component, except they don’t accept the sides attribute. You can find the complete list of named components in the code.

Usage

sides attribute

Requiredyes
Typenumber (integer)
Default valuenone
Minimum value3
Maximum valuenone

The number of sides the polygon should have.

idSuffix attribute

Requiredno
Typestring
Default valuenone

Adds a suffix to generated HTML elements built by the Polygon component. Useful if you need to address multiple polygons in a single document by their HTML id atribute.

margin attribute

Requiredno
Typenumber
Default value0
Minimum value0
Maximum value50

The polygon that is constructed will be built inside an HTML element which is defined by both the containing HTML and any style that is passed to the Polygon component.

This margin is a percentage from 0% to 50% of the height and width of this containing element.

That means that if you specify or inherit unequal height and width for the Polygon component, you will get uneven margin applied in proportion.

borderWidth attribute

Requiredno
Typenumber
Default value0
Minimum value0
Maximum value50

The polygon that is constructed will be built inside an HTML element which is defined by both the containing HTML and any style that is passed to the Polygon component.

The width of the border is a percentage from 0% to 50% of the height and width of this containing element.

That means that if you specify or inherit unequal height and width for the Polygon component, you will get uneven border width applied in proportion.

borderColor attribute

Requiredno
Typestring
Default valuenone

The color of the polygon’s border. Any CSS color value will work.

borderStyle attribute

Requiredno
Typestring | object | array (Vue StyleValue)
Default value{}

CSS properties to be applied to the Polygon border. Keep in mind when applying styles that the border is actually an HTML div element. So the effect of certain styles may be unexpected. For example, setting backgroundColor here will override the borderColor attribute.

Some CSS properties should not be set as they will replace internal styles, these are:

  • position - always absolute
  • height - always 100%
  • width - always 100%
  • clipPath - always the calculated polygon shape for the border

borderClass attribute

Requiredno
Typestring | object (Vue class binding)
Default valuenone

Adds a class name to the border HTML element built by the Polygon component. You can use Vue's class binding capabilities if desired.

padding attribute

Requiredno
Typenumber
Default value0
Minimum value0
Maximum value50

The padding applied to text or HTML elements inside the polygon itself.

The polygon that is constructed will be built inside an HTML element which is defined by both the containing HTML and any style that is passed to the Polygon component.

This padding is a percentage from 0% to 50% of the height and width of this containing element.

That means that if you specify or inherit unequal height and width for the Polygon component, you will get uneven padding applied in proportion.

rotate attribute

Requiredno
Typenumber
Default value0

Rotates the polygon shape by the given number of degrees, without rotating the contents of the polygon.

To rotate the entire polygon including its contents you can use basic CSS transform properties applied using the style attribute.

stable attribute

Requiredno
Typeboolean
Default valuefalse

When true, the stable attribute applies a rotation to the polygon which places one side flat at the bottom of the polygon.

Any further rotation applied via the rotate attribute is additive to this pre-applied rotation.

center attribute

Requiredno
Typeobject
Default value{ x: 50, y: 50 }

Sets the center point of the polygon within the containing element. The values are a percentage of the containing element’s height and width.

debug attribute

Requiredno
Typeboolean
Default valuefalse

When true, the debug attribute adds additional styles and elements to the generated HTML in order to help visualise the code being generated.

ref attribute

Requiredno
Typestring
Default valuenone

You can pass a ref ID to the Polygon component that will be applied to the root HTML element. See the Vue documentation on template refs for more information.

Event handlers

The Polygon component accepts standard Vue 3 event handlers like:

  • @mouseover
  • @mouseout
  • @mousedown
  • @mouseup
  • @click

Accessibility attributes

The Polygon component accepts all the standard ARIA attributes available in Vue 3, including the role attribute.