Font Awesome

From Documentation
Revision as of 07:47, 6 March 2024 by Hawk (talk | contribs) (→‎Basic Usage)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Font Awesome Bundled

Since 7.0.0

Starting from ZK 7.0.0 integrates Font Awesome 4.0.1 with the prefix z-icon. You don't need to manually include Font Awesome CSS because it's already packaged with ZK jar.

Basic Usage

To use it, just specify a built-in CSS class at the iconSclass attribute. All subclasses of LabelImageElement (e.g. button) and some components with an icon (e.g. combobox, bandbox) support iconSclass. Some components have attributes that contain "iconSclass" e.g. errorboxIconSclass or overflowPopupIconSclass For a complete list of icon CSS classes, please refer to FontAwesome Cheatsheet.

For example, to add a home icon on a Button,

    <button iconSclass="z-icon-home" />

If you want to use other Font Awesome functions such as the animation icon, you can include the external Font Awesome CSS link and add the CSS class to iconSclass. For example,

<?link href="http://netdna.bootstrapcdn.com/font-awesome/4.0.1/css/font-awesome.css" rel="stylesheet"?>
    <button iconSclass="z-icon-bell fa-spin" />
    <button iconSclass="z-icon-home fa-2x fa-rotate-90" />

Since 8.0.0

ZK 8.0.0 integrates Font Awesome 4.3.0. Also, with ZK 8 there is no need to include an external font awesome CSS link to use an animation icon. Therefore the example above becomes

    <button iconSclass="z-icon-bell z-icon-spin" />
    <button iconSclass="z-icon-home z-icon-2x z-icon-rotate-90" />

Since 8.5.2

ZK 8.5.2 integrates Font Awesome 4.7.0.

Since 10.0.0

ZK 10.0.0 integrates Font Awesome 6.4.2 free icons and supports both Font Awesome 4 syntax and Font Awesome 6 syntax with styles specified:

    <!--Font Awesome 4 syntax-->
    <button iconSclass="z-icon-bell" />
    <!--Font Awesome 6 syntax-->
    <button iconSclass="z-icon-bell z-icon-solid" />
    <button iconSclass="z-icon-bell z-icon-regular" />

IconTooltip

Since 10.0.0 The iconTooltip attribute is introduced for adding a tooltip to an icon.

    <button iconSclass="z-icon-home" iconTooltip="home"/>

Multiple icons and tooltips

Since 10.0.0 One LabelImageElement can have multiple icons and tooltips set using Java API:

    e.setIconSclasses(new String[] {"z-icon-home", "z-icon-podcast"});
    e.setIconTooltips(new String[] {"tooltip1", "tooltip2"});

Please note that this is only supported through Java API but not Zul attributes.

Not Supported Usages

The following usages mentioned in Font Awesome official document are not supported:

  • Duotone
  • Stacking icons
  • Layering Text & Counters
  • Power Transforms

Use Other Icons

The iconSclass not only applies to font awesome icons ("z-icon-" classes): Any css class can be applied to customize. Notice you need to manually include related CSS or font file. For example, the bootstrap glyphicons can be used here too:

    <button iconSclass="glyphicon glyphicon-envelope" />

Since the web font is loaded after the character is being displayed if there is no cache, ZK doesn't know if the web font is ready when initializing. Therefore using hflex="min" with iconSclass may not get the desired result. Moreover, the final width of icons might not be the same. To make the width of icons always be fixed, add z-icon-fw.

    <button iconSclass="z-icon-fw z-icon-home" />
    <button iconSclass="z-icon-fw z-icon-bell z-icon-spin" />


Last Update : 2024/03/06

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.