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.
sides
attributeRequired | yes |
---|---|
Type | number (integer) |
Default value | none |
Minimum value | 3 |
Maximum value | none |
The number of sides the polygon should have.
idSuffix
attributeRequired | no |
---|---|
Type | string |
Default value | none |
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
attributeRequired | no |
---|---|
Type | number |
Default value | 0 |
Minimum value | 0 |
Maximum value | 50 |
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
attributeRequired | no |
---|---|
Type | number |
Default value | 0 |
Minimum value | 0 |
Maximum value | 50 |
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
attributeRequired | no |
---|---|
Type | string |
Default value | none |
The color of the polygon’s border. Any CSS color value will work.
borderStyle
attributeRequired | no |
---|---|
Type | string | 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 borderborderClass
attributeRequired | no |
---|---|
Type | string | object (Vue class binding) |
Default value | none |
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
attributeRequired | no |
---|---|
Type | number |
Default value | 0 |
Minimum value | 0 |
Maximum value | 50 |
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
attributeRequired | no |
---|---|
Type | number |
Default value | 0 |
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
attributeRequired | no |
---|---|
Type | boolean |
Default value | false |
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
attributeRequired | no |
---|---|
Type | object |
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
attributeRequired | no |
---|---|
Type | boolean |
Default value | false |
When true
, the debug
attribute adds additional styles and elements to the generated HTML in order to help visualise the code being generated.
ref
attributeRequired | no |
---|---|
Type | string |
Default value | none |
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.
The Polygon
component accepts standard Vue 3 event handlers like:
@mouseover
@mouseout
@mousedown
@mouseup
@click
The Polygon
component accepts all the standard ARIA attributes available in Vue 3, including the role
attribute.