Skip to content
Components, switch product

Icons

The components don’t ship icons. An icon attribute takes the class names of an icon, and the element renders an empty element with those classes for your CSS to draw. Any icon font, icon library or image works.

icon="icon-search" renders:

<span
class="gui-widget-icon icon-search"
data-icon="icon-search"
aria-hidden="true"
></span>
HookWhat it is
gui-widget-iconOn every icon. The stylesheet places and sizes it.
Your classes (icon-search)The value of the attribute, as classes: several are fine.
data-icon="icon-search"The same value, for a rule that reads it with attr().

The icon is decorative: aria-hidden hides it from assistive technology, so the field’s label and the button’s text carry the meaning.

ElementAttributes
gui-textinput, gui-select, gui-currencyicon
gui-passwordicon, show-password-icon, hide-password-icon
gui-buttonicon, icon-position (left or right)
gui-tags, gui-multi-select-triggericon, remove-icon
gui-pillsremove-icon
gui-file-upload, gui-multi-file-uploadicon, remove-icon, retry-icon
gui-date, gui-time, gui-date-timeicon
gui-range-date, gui-range-time, gui-range-date-timeicon
gui-time-picker, gui-range-time-pickericon
gui-date-picker, gui-date-time-picker, gui-range-date-picker, gui-range-date-time-pickericon, prev-month-icon, next-month-icon
gui-calendar, gui-date-time-calendar, gui-range-calendar, gui-range-date-time-calendarprev-month-icon, next-month-icon

The month buttons of the calendars show a caret without prev-month-icon and next-month-icon.

Give the classes a ligature or a glyph. With Material Icons, one rule draws every icon from its data-icon value:

@import url('https://fonts.googleapis.com/icon?family=Material+Icons');
.gui-widget-icon[data-icon]::before {
content: attr(data-icon);
font-family: 'Material Icons';
font-size: var(--gui-font-lg);
}
<gui-textinput label="Search" icon="search"></gui-textinput>

Or draw one icon per class, as this example does:

Code of the example above
TextInputIcon.tsx
import { GuiTextinput } from '@golemui/gui-components/react';
import '@golemui/gui-components/index.css';
// Any icon font works: icon sets these classes on the icon element.
// This one draws a Material Icons ligature.
const iconStyles = `
.icon-search::before {
content: 'search';
font-family: 'Material Icons';
}
`;
export function TextInputIcon() {
return (
<>
<GuiTextinput
label="Search"
icon="icon-search"
placeholder="Search the docs"
/>
<style>{iconStyles}</style>
</>
);
}

A library that draws its icons from classes, such as Font Awesome, works as it is: pass its classes, and load its stylesheet.

<gui-textinput label="Website" icon="fa-solid fa-globe"></gui-textinput>

Draw a file with mask-image, so the icon takes the color of the text around it:

.gui-widget-icon.icon-pin::before {
content: '';
width: 20px;
height: 20px;
background-color: currentColor;
mask: url('/icons/pin.svg') center / contain no-repeat;
}
<gui-textinput label="Address" icon="icon-pin"></gui-textinput>

An SVG in a data: URL needs img-src data: in your Content Security Policy. A file on your own origin needs only img-src 'self'.

Icons take the text color, --gui-text-default. Change it, or the size, with a rule on the icon:

gui-textinput .gui-widget-icon {
color: var(--gui-intent-primary);
}
.gui-widget-icon[data-icon]::before {
font-size: var(--gui-font-xl);
}