icons

Methods

(static) Icon(icon, props)

Description:
  • Icon( anything, {size, ...props} )

    Create a HTMLElement to display a small (1em by default) image. The value of 'size' is a 'style' value and applies to 'width' and 'height', for example '16px', '2.5em', '60%' or 'inherit'.

    First argument is

    • a key to an image registered with setIcon like 'MOON'
    • a UTF-8 char like '🌙'
    • a SVG string
    • a object with property 'src' to a image url and optional props 'alt', 'size', class...
    • a HTMLElement
    • a function like props=>Icon('MOON', props)
    • a Font Awesome class like 'fa-solid fa-house'
Source:
See:
  • setIcon
Examples
key of icon in iconMap
Icon( 'key' )
UTF-8 char
Icon( '🗺️' )
SVG string
Icon( '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 10 10"><circle cx="5" cy="5" r="3"/></svg>' )
SVG string with extra attributes
Icon( 
  '<svg viewBox="0 0 10 10"><circle cx="5" cy="5" r="3"/></svg>',
  {class: 'ms-3 border', size: '2.2em', onclick:()=>console.log('smile')}
)
Image URL
Icon( {src: "https://avatars.githubusercontent.com/u/25134550"), {class: "rounded-4"} )
VanJs function
const {circle, path, svg} = van.tags
const Smiley = (props) => svg({width: "16px", viewBox: "0 0 50 50", ...props},
 circle({cx: "25", cy: "25", "r": "20", stroke: "black", "stroke-width": "2", fill: "yellow"}),
 circle({cx: "16", cy: "20", "r": "2", stroke: "black", "stroke-width": "2", fill: "black"}),
 circle({cx: "34", cy: "20", "r": "2", stroke: "black", "stroke-width": "2", fill: "black"}),
 path({"d": "M 15 30 Q 25 40, 35 30", stroke: "black", "stroke-width": "2", fill: "transparent"}),
)

setIcon('Smiley', Smiley)
Icon('Smiley', {width: '2.5em'})
Font Awesome class
Icon( "fa-solid fa-beer-mug-empty" )
Parameters:
Name Type Description
icon *

see examples

props Object

optional properties

(static) getIcon(key) → {*}

Description:
  • fetch a icon by name from iconMap.

Source:
Parameters:
Name Type Description
key string

icon name the key in iconMap

Returns:
Type
*

(static) setIcon(key, value)

Description:
  • Registers an icon under a key in iconMap.

Source:
Parameters:
Name Type Description
key string
value *

(static) setSvgAttributes(svgString, attributes) → {string}

Source:
Parameters:
Name Type Description
svgString string

<svg ..

attributes object

{size: "42", ..

Returns:
Type
string

(static) spriteify(options) → {string}

Description:
  • The function returns a sprite containing all the SVGs defined in the iconMap and converts the registered SVGs into references. This sprite can then be appended to the document.body element.

Source:
Parameters:
Name Type Description
options object

optional

Properties
Name Type Description
idPrefix string

idPrefix + key builds the use reference. Default = 'icon-'

svgClass string

extra class added to the reference. Default = ''

spriteId string

optianal id for the generated sprite

prettify boolean

formated output. Default = false

toDOM boolean

append sprite to document.body, Default false

map Map

Map with svg strings. Default is iconMap

Returns:
  • sprite string
Type
string