block-lab icon indicating copy to clipboard operation
block-lab copied to clipboard

“Icon” control type

Open pagelab opened this issue 5 years ago • 7 comments

Using icon fonts or, preferably, SVG.

pagelab avatar Mar 15 '19 13:03 pagelab

This would be tough, since presumably every site would need a different set of icons.

A workaround would be to create a select dropdown with the icon names.

lukecarbis avatar Mar 17 '19 09:03 lukecarbis

Specifically for icon fonts, an option is to load the icons from a json file generated by Fontello or Icomoon, as this plugin here does.

pagelab avatar Mar 20 '19 20:03 pagelab

Suppose you were using Font Awesome in your theme, you could create an Icon select dropdown that had these values:

apple-alt : Apple bacon : Bacon bone : Bone bread-slice : Bread candy-cane : Candy Cane carrot: Carrot cheese : Cheese cookie : Cookie pizza-slice: Pizza

Then in your template, you could output the icon like so:

<i class="fas fa-<?php block_field( 'icon' ); ?>"></i>

lukecarbis avatar Mar 21 '19 03:03 lukecarbis

Nice workaround. It would be difficult to use a select if there's too many icons, though.

Usually there's lots of icons in these libraries, so a search field would be also quite important to have.

image

pagelab avatar Apr 18 '19 17:04 pagelab

It would be great if the Textarea field type allowed inputting SVG code... or if there were an SVG/HTML input field type.

x5hwuk7nc6jsudcc avatar May 22 '19 04:05 x5hwuk7nc6jsudcc

We have a preference to use inline SVG for graphics and so finding a suitable workaround for this has been fairly important to us. This is what we are doing:

  1. Use the "Image" input field type in your block (note you need to allow SVG uploads within WordPress)

  2. In your block PHP, use:

<?php 
    $svg_url = get_attached_file( block_value( 'image' ) ); 
    if (substr($svg_url, -3) == 'svg') {         
        echo file_get_contents( $svg_url );
    }
    else {
        echo 'Error: File is not an SVG';  
    };
?>

x5hwuk7nc6jsudcc avatar Jun 18 '19 00:06 x5hwuk7nc6jsudcc

Nice @strayguevara – field validation would come in handy in this case.

lukecarbis avatar Jun 18 '19 10:06 lukecarbis